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,9 +83,10 @@ type Message interface {
// ExecutionResult includes all output after executing given evm // ExecutionResult includes all output after executing given evm
// message no matter the execution itself is successful or not. // message no matter the execution itself is successful or not.
type ExecutionResult struct { 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)
Err error // Any error encountered during the execution(listed in core/vm/errors.go) UsedGas uint64 // Total used gas (minus any state refunds applied after the transaction)
ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode) 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)
} }
// Unwrap returns the internal evm error which allows us for further // Unwrap returns the internal evm error which allows us for further
@ -315,8 +316,9 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
st.state.PrepareAccessList(msg.From(), msg.To(), vm.ActivePrecompiles(rules), msg.AccessList()) st.state.PrepareAccessList(msg.From(), msg.To(), vm.ActivePrecompiles(rules), msg.AccessList())
} }
var ( var (
ret []byte ret []byte
vmerr error // vm errors do not effect consensus and are therefore not assigned to err vmerr error // vm errors do not effect consensus and are therefore not assigned to err
requiredGas uint64
) )
if contractCreation { if contractCreation {
ret, _, st.gas, vmerr = st.evm.Create(sender, st.data, st.gas, st.value) 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) 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 { if !london {
// Before EIP-3529: refunds were capped to gasUsed / 2 // Before EIP-3529: refunds were capped to gasUsed / 2
st.refundGas(params.RefundQuotient) st.refundGas(params.RefundQuotient)
@ -345,9 +350,10 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
} }
return &ExecutionResult{ return &ExecutionResult{
UsedGas: st.gasUsed(), RequiredGas: requiredGas,
Err: vmerr, UsedGas: st.gasUsed(),
ReturnData: ret, Err: vmerr,
ReturnData: ret,
}, nil }, nil
} }