Skip to content

refactor(p2p): split mempool client, replace register callbacks, extract gossip message processor#24589

Draft
AztecBot wants to merge 3 commits into
nextfrom
cb/p2p-mempool-registrar-refactor
Draft

refactor(p2p): split mempool client, replace register callbacks, extract gossip message processor#24589
AztecBot wants to merge 3 commits into
nextfrom
cb/p2p-mempool-registrar-refactor

Conversation

@AztecBot

@AztecBot AztecBot commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Implements the three p2p refactors proposed by @spalladino (santiago) in the yarn-project refactor-audit thread, one commit each:

  1. refactor(p2p): extract MempoolClient collaborator from P2PClient — P2PClient's public surface was dominated by thin pass-throughs to the tx/attestation pools, plus the L2 block-stream reactions (mined/finalized/pruned) that mutate them. All pool access moves into an internal MempoolClient collaborator; the public P2P interface and behavior (including the 'protected''pending' tx-status remap and pool-write-before-propagate ordering in the broadcast methods) are unchanged.

  2. refactor(p2p): replace register callbacks with proposal handler interface and typed events — the six registerXCallback/registerXHandler methods threading callbacks from validator-client through P2PClient into LibP2PService (the leaky abstraction tracked in chore(vc): remove the p2p client validator callback #7963, flagged in three separate code comments) collapse into:

    • a single P2PProposalHandler interface set via setProposalHandler() for the three request/response callbacks (block proposal, validator checkpoint proposal, all-nodes checkpoint proposal), with merge semantics preserving the old per-slot registration behavior between ProposalHandler.register() and ValidatorClient.registerHandlers();
    • typed events (P2PServiceEvents: duplicateProposal, duplicateAttestation, checkpointAttestation) for the three fire-and-forget notifications, emitted by the service and forwarded by the client.

    Default handler behaviors and the first-duplicate-only (count === 2) emission points are unchanged.

  3. refactor(p2p): extract GossipMessageProcessor from LibP2PService — the domain-side processing of gossiped consensus messages (validation, mempool writes, equivocation detection, proposal-handler invocation — including the method an existing REFACTOR(palla) comment flagged as misplaced) moves into a new GossipMessageProcessor that the service delegates to inline. Delegation rather than relocation on purpose: gossipsub topic validation must return Accept/Reject/Ignore within the message-cache window, so the processor is called synchronously from the same paths. Method bodies, ordering, and trace span names are unchanged, and the service keeps thin protected wrappers with the same signatures so subclasses and tests are unaffected.

All three are intended to be behavior-preserving; no wire format, timing, or consensus behavior changes. Marked ci-no-squash to keep the three commits separate for review.

Closes #7963


Created by claudebox · group: slackbot

@AztecBot AztecBot added ci-draft Run CI on draft PRs. ci-no-fail-fast Sets NO_FAIL_FAST in the CI so the run is not aborted on the first failure ci-no-squash claudebox Owned by claudebox. it can push to this PR. labels Jul 7, 2026
AztecBot added 3 commits July 7, 2026 19:46
P2PClient's public surface was dominated by thin pass-throughs to the tx
pool and attestation pool (getPendingTxs, tryAddBlockProposal, block-stream
reactions to mined/finalized/pruned blocks, etc), mixing mempool bookkeeping
with the client's actual job of peer/gossip/reqresp orchestration.

Move all pool access and the L2BlockStream reactions that mutate the pools
into a new internal MempoolClient collaborator that P2PClient composes. The
public P2P interface, method names, and behavior (including the
'protected'->'pending' tx-status remap and pool-write-before-propagate
ordering in broadcastProposal/broadcastCheckpointProposal) are unchanged.
…face and typed events

The P2P client and service exposed six imperative register methods, each
threading a callback down through P2PClient into LibP2PService, a pattern
the code itself flagged as a leaky abstraction (#7963). Collapse them:

- The three request/response callbacks (block proposal, validator
  checkpoint proposal, all-nodes checkpoint proposal) become a single
  P2PProposalHandler interface set via setProposalHandler(). Handlers
  merge over the current ones, preserving the old per-slot registration
  semantics where the validator client fulfills its handlers without
  disturbing the all-nodes handler set by the standalone ProposalHandler.
- The three fire-and-forget notifications (duplicate proposal, duplicate
  attestation, accepted checkpoint attestation) become typed events
  (P2PServiceEvents) emitted by the service and forwarded by the client.

Default handler behaviors in LibP2PService (warn-and-accept block
proposals, throw on unregistered all-nodes checkpoint handler) and the
first-duplicate-only emission points are unchanged.

Closes #7963
LibP2PService mixed gossip transport with domain processing: mempool
writes, equivocation detection, and proposal-handler invocation lived
inside the service (an existing REFACTOR(palla) comment already flagged
processValidBlockProposal as misplaced). Move the five domain methods
(validateAndStoreBlockProposal, validateAndStoreCheckpointProposal,
validateAndStoreCheckpointAttestation, processValidBlockProposal,
processValidCheckpointProposal) and the proposal-handler state into a
new GossipMessageProcessor that the service delegates to inline.

Delegation, not relocation, on purpose: gossipsub topic validation must
return Accept/Reject/Ignore within the message-cache window, so the
processor is called synchronously from the same paths as before. Method
bodies, ordering, first-duplicate-only (count === 2) equivocation
emission, and trace span names are unchanged; the service keeps thin
protected wrappers with the same signatures so subclasses and tests are
unaffected.
@AztecBot AztecBot force-pushed the cb/p2p-mempool-registrar-refactor branch from bf6239e to 5a8f806 Compare July 7, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on draft PRs. ci-no-fail-fast Sets NO_FAIL_FAST in the CI so the run is not aborted on the first failure ci-no-squash claudebox Owned by claudebox. it can push to this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(vc): remove the p2p client validator callback

1 participant