Skip to content

Conversation

@StephenButtolph
Copy link
Contributor

Why this should be merged

  1. IsSubscribed is a testing only function that really indicates that the implementation is inherently racy. The subscription should be synchronous while the handling of the subscription should be async.
  2. SubscribeTransactions currently takes in false. This isn't a bug, because the bool is ignored for the legacy pool... But if it weren't ignored, then this would violate the invariant that the bloom filter is a superset of the inner set. So now it is set to true.

How this works

imo, the code would be cleaner if there was a Close or Shutdown function on the mempool with the goroutine started in NewGossipEthTxPool... But that seemed to be a bigger refactor involving node shutdown.

How this was tested

existing CI

Need to be documented in RELEASES.md?

no

Copilot AI review requested due to automatic review settings November 26, 2025 16:19
@StephenButtolph StephenButtolph requested a review from a team as a code owner November 26, 2025 16:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the GossipEthTxPool to eliminate race conditions and improve code safety. The main goal is to make the subscription to the mempool synchronous at initialization while keeping the event handling asynchronous, and to correct the subscription parameters to maintain proper bloom filter invariants.

Key changes:

  • Moved mempool subscription from asynchronous Subscribe() to synchronous initialization in NewGossipEthTxPool
  • Renamed Subscribe() to UpdateBloomFilter() to better reflect its actual purpose
  • Fixed subscription parameter from false to true to maintain bloom filter invariants

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
graft/coreth/plugin/evm/vm.go Updated function call from Subscribe to UpdateBloomFilter
graft/coreth/plugin/evm/gossip_test.go Replaced test subscription logic with direct UpdateBloomFilter call, removing race-prone IsSubscribed check
graft/coreth/plugin/evm/eth_gossiper.go Refactored to move subscription to constructor, renamed method, removed testing-only IsSubscribed, added channel close handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// UpdateBloomFilter continuously listens for new pending transactions from the
// mempool and adds them to the bloom filter. If the bloom filter reaches its
// capacity, it is reset and all pending transactions are re-added.
func (g *GossipEthTxPool) UpdateBloomFilter(ctx context.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe can be renamedBloomFilterUpdateLoop or DispatchBloomUpdater etc etc to indicate the continous loop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or really Subscribe haha

case pendingTxs := <-g.pendingTxs:
case pendingTxs, ok := <-g.pendingTxs:
if !ok {
log.Debug("pending txs channel closed, shutting down subscription")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think this channel closes normally, should this be a warn/error log?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants