diff --git a/core/state/journal.go b/core/state/journal.go index 13332dbd79..854497a531 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -448,7 +448,6 @@ func (ch addLogChange) revert(s *StateDB) { } else { s.logs[ch.txhash] = logs[:len(logs)-1] } - s.logSize-- } func (ch addLogChange) dirtied() *common.Address { diff --git a/core/state/statedb.go b/core/state/statedb.go index f09356e403..53a7932753 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -119,7 +119,6 @@ type StateDB struct { thash common.Hash txIndex int logs map[common.Hash][]*types.Log - logSize uint // Preimages occurred seen by VM in the scope of block. preimages map[common.Hash][]byte @@ -243,11 +242,7 @@ func (s *StateDB) Error() error { func (s *StateDB) AddLog(log *types.Log) { s.journal.logChange(s.thash) - log.TxHash = s.thash - log.TxIndex = uint(s.txIndex) - log.Index = s.logSize s.logs[s.thash] = append(s.logs[s.thash], log) - s.logSize++ } // GetLogs returns the logs matching the specified transaction hash. @@ -669,7 +664,6 @@ func (s *StateDB) Copy() *StateDB { thash: s.thash, txIndex: s.txIndex, logs: make(map[common.Hash][]*types.Log, len(s.logs)), - logSize: s.logSize, preimages: maps.Clone(s.preimages), // Do we need to copy the access list and transient storage? diff --git a/core/state/statedb_hooked_test.go b/core/state/statedb_hooked_test.go index f319b0e63c..47b0b7e2ab 100644 --- a/core/state/statedb_hooked_test.go +++ b/core/state/statedb_hooked_test.go @@ -80,7 +80,6 @@ func TestBurn(t *testing.T) { // TestHooks is a basic sanity-check of all hooks func TestHooks(t *testing.T) { inner, _ := New(types.EmptyRootHash, NewDatabaseForTesting()) - inner.SetTxContext(common.Hash{0x11}, 100) // For the log var result []string var wants = []string{ "0xaa00000000000000000000000000000000000000.balance: 0->100 (Unspecified)", @@ -89,7 +88,7 @@ func TestHooks(t *testing.T) { "0xaa00000000000000000000000000000000000000.code: (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) ->0x1325 (0xa12ae05590de0c93a00bc7ac773c2fdb621e44f814985e72194f921c0050f728)", "0xaa00000000000000000000000000000000000000.storage slot 0x0000000000000000000000000000000000000000000000000000000000000001: 0x0000000000000000000000000000000000000000000000000000000000000000 ->0x0000000000000000000000000000000000000000000000000000000000000011", "0xaa00000000000000000000000000000000000000.storage slot 0x0000000000000000000000000000000000000000000000000000000000000001: 0x0000000000000000000000000000000000000000000000000000000000000011 ->0x0000000000000000000000000000000000000000000000000000000000000022", - "log 100", + "log 0xbb00000000000000000000000000000000000000", } emitF := func(format string, a ...any) { result = append(result, fmt.Sprintf(format, a...)) @@ -108,7 +107,7 @@ func TestHooks(t *testing.T) { emitF("%v.storage slot %v: %v ->%v", addr, slot, prev, new) }, OnLog: func(log *types.Log) { - emitF("log %v", log.TxIndex) + emitF("log %v", log.Address) }, }) sdb.AddBalance(common.Address{0xaa}, uint256.NewInt(100), tracing.BalanceChangeUnspecified) diff --git a/core/state_processor.go b/core/state_processor.go index 7b394bb9cd..6dd114def2 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -206,8 +206,11 @@ func deriveFullReceipt(receipt *types.Receipt, evm *vm.EVM, result *ExecutionRes receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce()) } - // Annotate the logs with blockhash and blocknumber. - for _, log := range receipt.Logs { + // Annotate the logs + for index, log := range receipt.Logs { + log.TxHash = tx.Hash() + log.TxIndex = uint(statedb.TxIndex()) + log.Index = uint(index) log.BlockHash = blockHash log.BlockNumber = blockNumber.Uint64() }