Track required gas for executing a transaction

This commit is contained in:
Shane Bammel 2022-02-15 21:06:28 -06:00
parent 6424b258b0
commit f6ce963881

View File

@ -83,7 +83,8 @@ type Message interface {
// ExecutionResult includes all output after executing given evm
// message no matter the execution itself is successful or not.
type ExecutionResult struct {
UsedGas uint64 // Total used gas but include the refunded gas
RequiredGas uint64 // The total gas required to run the transaction (before any state refunds)
UsedGas uint64 // Total used gas (minus any state refunds applied after the transaction)
Err error // Any error encountered during the execution(listed in core/vm/errors.go)
ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)
}
@ -317,6 +318,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
var (
ret []byte
vmerr error // vm errors do not effect consensus and are therefore not assigned to err
requiredGas uint64
)
if contractCreation {
ret, _, st.gas, vmerr = st.evm.Create(sender, st.data, st.gas, st.value)
@ -326,6 +328,9 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
ret, st.gas, vmerr = st.evm.Call(sender, st.to(), st.data, st.gas, st.value)
}
// capture the required gas prior to state refunds
requiredGas = st.gasUsed()
if !london {
// Before EIP-3529: refunds were capped to gasUsed / 2
st.refundGas(params.RefundQuotient)
@ -345,6 +350,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
}
return &ExecutionResult{
RequiredGas: requiredGas,
UsedGas: st.gasUsed(),
Err: vmerr,
ReturnData: ret,