Skip to content

Commit 014e2b0

Browse files
authored
core/vm/runtime: invoke tx-end hook (#30711)
When using the `core/vm/runtime` helpers to execute code, callbacks for the tx end were not invoked. This change fixes it by invoking them.
1 parent 7d6e153 commit 014e2b0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/vm/runtime/runtime.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,16 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
142142
// set the receiver's (the executing contract) code for execution.
143143
cfg.State.SetCode(address, code)
144144
// Call the code with the given configuration.
145-
ret, _, err := vmenv.Call(
145+
ret, leftOverGas, err := vmenv.Call(
146146
sender,
147147
common.BytesToAddress([]byte("contract")),
148148
input,
149149
cfg.GasLimit,
150150
uint256.MustFromBig(cfg.Value),
151151
)
152+
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxEnd != nil {
153+
cfg.EVMConfig.Tracer.OnTxEnd(&types.Receipt{GasUsed: cfg.GasLimit - leftOverGas}, err)
154+
}
152155
return ret, cfg.State, err
153156
}
154157

@@ -181,6 +184,9 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
181184
cfg.GasLimit,
182185
uint256.MustFromBig(cfg.Value),
183186
)
187+
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxEnd != nil {
188+
cfg.EVMConfig.Tracer.OnTxEnd(&types.Receipt{GasUsed: cfg.GasLimit - leftOverGas}, err)
189+
}
184190
return code, address, leftOverGas, err
185191
}
186192

@@ -214,5 +220,8 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er
214220
cfg.GasLimit,
215221
uint256.MustFromBig(cfg.Value),
216222
)
223+
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxEnd != nil {
224+
cfg.EVMConfig.Tracer.OnTxEnd(&types.Receipt{GasUsed: cfg.GasLimit - leftOverGas}, err)
225+
}
217226
return ret, leftOverGas, err
218227
}

0 commit comments

Comments
 (0)