Skip to content

Commit 9515d2e

Browse files
sonhv0212trantienduchn
authored andcommitted
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 16895e2 commit 9515d2e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

core/state/statedb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,13 @@ func (s *StateDB) SelfDestruct(addr common.Address) bool {
548548
s.journal.append(selfDestructChange{
549549
account: &addr,
550550
prev: stateObject.selfDestructed,
551-
prevbalance: new(big.Int).Set(stateObject.Balance()),
551+
prevbalance: prev,
552552
})
553553
if s.logger != nil && s.logger.OnBalanceChange != nil && prev.Sign() > 0 {
554554
s.logger.OnBalanceChange(addr, prev, n, tracing.BalanceDecreaseSelfdestruct)
555555
}
556556
stateObject.markSelfdestructed()
557-
stateObject.data.Balance = new(big.Int)
557+
stateObject.data.Balance = n
558558

559559
return true
560560
}

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)