refactor(p2p): split message processing from libp2p networking#23754
Open
PhilWindle wants to merge 2 commits into
Open
refactor(p2p): split message processing from libp2p networking#23754PhilWindle wants to merge 2 commits into
PhilWindle wants to merge 2 commits into
Conversation
Extract received-message handling (validation, persistence, consensus callbacks, and the reqresp data handlers) out of LibP2PService into a new P2PMessageProcessor. The processor is built in the factory (the composition root) and injected into both the libp2p service and the P2PClient; consensus callbacks now register directly on the processor rather than on the networking service. LibP2PService is reduced to the networking layer. No behaviour change. This draws the boundary along the already-mostly-async P2PService interface in preparation for moving the libp2p stack onto a worker thread.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Splits the P2P stack into two pieces along the existing
P2PServiceboundary, with no behaviour change:LibP2PService— the networking layer (libp2p node, gossipsub, reqresp transport, peer manager, discovery, message dedup, report-to-pubsub).P2PMessageProcessor(new) — received-message handling that depends on main-thread node state: the message validators, the six consensus callbacks (+ theirregister*methods), validate/store/process for txs, block proposals, checkpoint proposals and attestations, the tx-validation pipeline,validateRequestedBlockTxsConsistency, and the reqresp data handlers (status/tx/block-txs). It calls back into the network through a narrowP2PNetworkinterface (propagate+penalizePeer).The processor is built in the factory (the composition root) and injected into both the libp2p service and the
P2PClient. Consensus callbacks now register directly on the processor viaP2PClient, not on the networking service — so registration no longer routes throughLibP2PService/P2PService. Theregister*methods were removed from theP2PServiceinterface,LibP2PService, andDummyP2PService.Why
This is the first step toward running the libp2p stack on a worker thread so its synchronous CPU (gossipsub, snappy, signature verification, peer scoring) stops blocking the main event loop. The split lands the boundary exactly where the worker edge will be: message-handling and callback registration stay on the main thread (the processor, owned/registered by
P2PClient), whileLibP2PServicebecomes the networking layer that will move into the worker and hold only an injected reference it calls into. No worker thread is introduced in this PR.Verification
yarn formatandyarn lintclean.libp2p_service(48),p2p_client(20), and the broader p2p services + client suite (~552), including the block-txs integration test.