core: fill blockNumber in logs #26345 (#1215)

This commit is contained in:
Daniel Liu 2025-07-11 10:53:48 +08:00 committed by GitHub
parent 6f84f67a15
commit ae006030c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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