From ae006030c6706f1f817b8cf023b8d5ce47d2d424 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Fri, 11 Jul 2025 10:53:48 +0800 Subject: [PATCH] core: fill blockNumber in logs #26345 (#1215) --- core/state/statedb.go | 5 ++++- core/state/statedb_test.go | 4 ++-- core/state_processor.go | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 9012f336cf..d3f436acf9 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -163,9 +163,12 @@ func (s *StateDB) AddLog(log *types.Log) { s.logSize++ } -func (s *StateDB) GetLogs(hash common.Hash, blockHash common.Hash) []*types.Log { +// GetLogs returns the logs matching the specified transaction hash, and annotates +// them with the given blockNumber and blockHash. +func (s *StateDB) GetLogs(hash common.Hash, blockNumber uint64, blockHash common.Hash) []*types.Log { logs := s.logs[hash] for _, l := range logs { + l.BlockNumber = blockNumber l.BlockHash = blockHash } return logs diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index b8eb8e5d53..f762e31d47 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -474,9 +474,9 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error { return fmt.Errorf("got GetRefund() == %d, want GetRefund() == %d", state.GetRefund(), checkstate.GetRefund()) } - if !reflect.DeepEqual(state.GetLogs(common.Hash{}, common.Hash{}), checkstate.GetLogs(common.Hash{}, common.Hash{})) { + if !reflect.DeepEqual(state.GetLogs(common.Hash{}, 0, common.Hash{}), checkstate.GetLogs(common.Hash{}, 0, common.Hash{})) { return fmt.Errorf("got GetLogs(common.Hash{}) == %v, want GetLogs(common.Hash{}) == %v", - state.GetLogs(common.Hash{}, common.Hash{}), checkstate.GetLogs(common.Hash{}, common.Hash{})) + state.GetLogs(common.Hash{}, 0, common.Hash{}), checkstate.GetLogs(common.Hash{}, 0, common.Hash{})) } return nil } diff --git a/core/state_processor.go b/core/state_processor.go index c1ebd4e84b..c4812d39cd 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -435,7 +435,7 @@ func applyTransaction(config *params.ChainConfig, tokensFee map[common.Address]* } // Set the receipt logs and create the bloom filter. - receipt.Logs = statedb.GetLogs(tx.Hash(), blockHash) + receipt.Logs = statedb.GetLogs(tx.Hash(), blockNumber.Uint64(), blockHash) receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) receipt.BlockHash = blockHash receipt.BlockNumber = blockNumber @@ -500,7 +500,7 @@ func ApplySignTransaction(config *params.ChainConfig, statedb *state.StateDB, bl log.Address = common.BlockSignersBinary log.BlockNumber = blockNumber.Uint64() statedb.AddLog(log) - receipt.Logs = statedb.GetLogs(tx.Hash(), blockHash) + receipt.Logs = statedb.GetLogs(tx.Hash(), blockNumber.Uint64(), blockHash) receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) receipt.BlockHash = blockHash receipt.BlockNumber = blockNumber @@ -527,7 +527,7 @@ func ApplyEmptyTransaction(config *params.ChainConfig, statedb *state.StateDB, b log.Address = *tx.To() log.BlockNumber = blockNumber.Uint64() statedb.AddLog(log) - receipt.Logs = statedb.GetLogs(tx.Hash(), blockHash) + receipt.Logs = statedb.GetLogs(tx.Hash(), blockNumber.Uint64(), blockHash) receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) receipt.BlockHash = blockHash receipt.BlockNumber = blockNumber