ethereum / go-ethereum

Go implementation of the Ethereum protocol
https://geth.ethereum.org
GNU Lesser General Public License v3.0
47.27k stars 20.01k forks source link

Simulated backend `Fork` & blockchain `SetHead` don't emit removed logs event #30448

Open dahu33 opened 1 week ago

dahu33 commented 1 week ago

System information

Geth version: 1.14.8

Expected behaviour

When the simulated backend Fork(parentHash common.Hash) is called, the necessary removed logs event should be emitted has it would on non-simulated backend.

On the old simulated backend (before #28202 was merged) we were using (bc *BlockChain) InsertChain(chain types.Blocks) to simulate chain reorgs under similar conditions, and did not face this issue. However, in the new simulated backend we don't have access anymore to the blockchain (it's not exported) and can only use the Fork function.

Note that the Fork function call the BlockChain.SetHead(head uint64) function which may be the source of the issue.

Actual behaviour

Removed logs event are not emitted.

Steps to reproduce the behaviour

Create a simulated backend Deploy a contract that can emit logs Subscribe to logs Call a function that emit logs Call the Fork(parentHash common.Hash) to the block before the last event was emitted The logs subscription will not yield any removed logs event.

holiman commented 1 week ago

Triage discussion, simulated_beaon.go Fork(..) method

    return c.eth.BlockChain().SetHead(parent.NumberU64())

Should invoke SetCanonical instead