Skip to content

Commit 1e23c63

Browse files
authored
core: minor cleanup in stateDB and Call (#96)
* core/vm/runtime: call OnTxStart before prepare state DB in Call * core/state: simplify state selfdestruct
1 parent 3ded425 commit 1e23c63

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

core/state/statedb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,13 @@ func (s *StateDB) SelfDestruct(addr common.Address) bool {
493493
s.journal.append(selfDestructChange{
494494
account: &addr,
495495
prev: stateObject.selfDestructed,
496-
prevbalance: new(big.Int).Set(stateObject.Balance()),
496+
prevbalance: prev,
497497
})
498498
if s.logger != nil && s.logger.OnBalanceChange != nil && prev.Sign() > 0 {
499499
s.logger.OnBalanceChange(addr, prev, n, tracing.BalanceDecreaseSelfdestruct)
500500
}
501501
stateObject.markSelfdestructed()
502-
stateObject.data.Balance = new(big.Int)
502+
stateObject.data.Balance = n
503503

504504
return true
505505
}

core/vm/runtime/runtime.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er
194194
statedb = cfg.State
195195
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber)
196196
)
197+
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxStart != nil {
198+
cfg.EVMConfig.Tracer.OnTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{To: &address, Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
199+
}
197200
// Execute the preparatory steps for state transition which includes:
198201
// - prepare accessList(post-berlin)
199202
// - reset transient storage(eip 1153)
200203
statedb.Prepare(rules, cfg.Origin, cfg.Coinbase, &address, vm.ActivePrecompiles(rules), nil)
201-
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxStart != nil {
202-
cfg.EVMConfig.Tracer.OnTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{To: &address, Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
203-
}
204204

205205
// Call the code with the given configuration.
206206
ret, leftOverGas, err := vmenv.Call(

0 commit comments

Comments
 (0)