fix remaining broken legacy tests

This commit is contained in:
Jared Wasinger 2025-10-05 15:54:20 +08:00
parent 12311ee59e
commit 047b2569f6
3 changed files with 25 additions and 1 deletions

View file

@ -27,6 +27,7 @@ type BlockAccessListTracer struct {
balIdx uint16 balIdx uint16
accessListBuilder *bal.AccessListBuilder accessListBuilder *bal.AccessListBuilder
// mutations and state reads from currently-executing bal index
idxMutations *bal.StateDiff idxMutations *bal.StateDiff
idxReads bal.StateAccesses idxReads bal.StateAccesses
} }
@ -39,8 +40,9 @@ func NewBlockAccessListTracer(startIdx int) (*BlockAccessListTracer, *tracing.Ho
accessListBuilder: bal.NewAccessListBuilder(), accessListBuilder: bal.NewAccessListBuilder(),
} }
hooks := &tracing.Hooks{ hooks := &tracing.Hooks{
OnTxEnd: balTracer.TxEndHook, OnTxExecutionEnd: balTracer.OnTxExecutionEnd,
OnTxStart: balTracer.TxStartHook, OnTxStart: balTracer.TxStartHook,
OnTxEnd: balTracer.TxEndHook,
OnEnter: balTracer.OnEnter, OnEnter: balTracer.OnEnter,
OnExit: balTracer.OnExit, OnExit: balTracer.OnExit,
OnCodeChangeV2: balTracer.OnCodeChange, OnCodeChangeV2: balTracer.OnCodeChange,
@ -112,6 +114,21 @@ func (a *BlockAccessListTracer) OnSelfDestruct(addr common.Address) {
a.accessListBuilder.SelfDestruct(addr) a.accessListBuilder.SelfDestruct(addr)
} }
func (a *BlockAccessListTracer) OnTxExecutionEnd() {
// this is a terrible hack: in the case where the block has zero txs, we need
// a way to signal that the post-tx block operations are being executed (set the
// bal idx to a correct value).
//
// if the block had transactions, the end of the last tx would have bumped the balIdx
// to the correct value.
if a.balIdx == 0 {
diff, reads := a.accessListBuilder.FinaliseIdxChanges()
a.accessList.Apply(a.balIdx, diff, reads)
a.accessListBuilder = bal.NewAccessListBuilder()
a.balIdx++
}
}
func (a *BlockAccessListTracer) OnBalanceChange(addr common.Address, prevBalance, newBalance *big.Int, _ tracing.BalanceChangeReason) { func (a *BlockAccessListTracer) OnBalanceChange(addr common.Address, prevBalance, newBalance *big.Int, _ tracing.BalanceChangeReason) {
newU256 := new(uint256.Int).SetBytes(newBalance.Bytes()) newU256 := new(uint256.Int).SetBytes(newBalance.Bytes())
prevU256 := new(uint256.Int).SetBytes(prevBalance.Bytes()) prevU256 := new(uint256.Int).SetBytes(prevBalance.Bytes())

View file

@ -105,6 +105,12 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
allLogs = append(allLogs, receipt.Logs...) allLogs = append(allLogs, receipt.Logs...)
} }
if hooks := cfg.Tracer; hooks != nil {
hooks.OnTxExecutionEnd()
}
// TODO: how do we signal to the BAL tracer that we are computing post-tx state changes here?
// if there are no txs in the block, then it will just record these state diffs at idx 0
// Read requests if Prague is enabled. // Read requests if Prague is enabled.
var requests [][]byte var requests [][]byte
if p.config.IsPrague(block.Number(), block.Time()) { if p.config.IsPrague(block.Number(), block.Time()) {

View file

@ -217,6 +217,7 @@ type Hooks struct {
OnSystemCallStart OnSystemCallStartHook OnSystemCallStart OnSystemCallStartHook
OnSystemCallStartV2 OnSystemCallStartHookV2 OnSystemCallStartV2 OnSystemCallStartHookV2
OnSystemCallEnd OnSystemCallEndHook OnSystemCallEnd OnSystemCallEndHook
OnTxExecutionEnd func()
// State events // State events
OnBalanceChange BalanceChangeHook OnBalanceChange BalanceChangeHook