Skip to content

p2p: block propagation is delayed by index and wallet sync #35023

Open

Description

@mzumsande

When we connect a new block, we send two validation signals in ActivateBestChain(): First BlockConnected() (used by the indexes and wallet), then UpdateBlockTip() (adds to m_blocks_for_header_relay for p2p).

Since these are processed sequentially by one thread, this means that a node which has optional indexes activated (which involves some non-trivial work in particular for coinstatsindex and blockfilterindex) will first index the block before scheduling to send the header to peers in UpdateBlockTip(). Ditto for wallets.

This is not great, because fast block propagation is much more important than fast index or wallet sync.

Fortunately, hb compact block relay is not affected by this and most nodes don't have work-heavy indexes enabled.

Note that the current behavior, even if setting wrong priorities, is beneficial for the blockfilterindex (see #29655 (comment)) because it avoids races with BIP157-compliant clients. If we'd change the order we should also keep that in mind.

Opening this as a brainstorming issue what (if anything) should be done about this.

Activity

  1. MrSuddenJoy commented on Apr 10, 2026

    @MrSuddenJoy
  2. ajtowns commented on Apr 28, 2026

    @ajtowns
    Contributor

    An idea to address this is for the p2p thread to be a bit more async, that is when a block B comes from peer X on the msghand thread, we pass that block to a separate validation thread and pause peer X, while still continuing to do work for other peers. I think we could potentially extend that so that if peer Y sends a bip157 query related to pending block B, we also pause peer Y.

  3. randomlogin commented on Nov 27, 2026

    @randomlogin

    Right now we process block from msghand which takes cs_main. If we move validation into its own thread which takes cs_main and sometimes releases it, it would allow msghand to continue its work, thus we could introduce more contention points which eventually could lead to a slower block validation.

    I mean right now msghand does not compete for cs_main with validation (as validation is inside msghand), but it would do so if there is a separate validation thread (for example from msghand's ProcessTransaction). I am not sure how significant is that and perhaps we could have some kind of prioritization of who takes the lock (validation instead of msghand).

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions