-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PubSub Mechanism - Follow up on #9994 #10679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
metricaez
wants to merge
63
commits into
paritytech:master
Choose a base branch
from
blockdeep:feat/pubsub-rev1225
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
This was referenced Dec 17, 2025
21d5add to
a783730
Compare
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.
This PR evolves from #9994
The redesign addresses prior feedback by eliminating the forced inclusion of all data and publisher roots, moving subscription logic from the relay chain to the parachain (enabling selective data access), and introducing reusable, generic APIs (KeyToIncludeInRelayProofApi) that allow runtimes to request additional proofs to be included in the relay chain state beyond pub-sub use cases. Data is then extracted from the verified proof within the inherent execution flow.
The resulting pattern consists of published data passing via verified proof delivery followed by parachain-side extraction.
Therefore this PR implements a publish mechanism for parachains to efficiently share data through relay chain storage, addressing issue #606 and following up on feedback obtained from the initial design proposal in #9994.
Context:
The original issue identified expensive and complex inter-parachain information exchange. Current methods (XCM messages, off-chain protocols) are inefficient when data needs to be disseminated across many parachains.
Implementation Flow based on #9994 feedback
The design provides generic APIs (relay proof requests, proof processing) reusable beyond pub-sub, with handler-based patterns for flexible runtime integration.
Architecture Overview
Components Implemented
1. XCM v5 Publish Instruction
Location:
polkadot/xcm/src/v5/mod.rsPublish { data: PublishData }Allows parachains to publish bounded key-value data to the relay chain.
Type:
PublishData = BoundedVec<(PublishKey, BoundedVec<u8, MaxPublishValueLength>), MaxPublishItems>PublishKey: Fixed 32-byte hash ([u8; 32])XCM Error Addition: Added PublishFailed error to xcm::v5::Error and pallet_xcm::errors::ExecutionError.
XCM v4 Compatibility: The instruction is not supported in XCM v4. Downgrades from v5 to v4 return an error for Publish instructions.
Note: The instruction is being back ported to xcm v5.
The instruction is intended to be called via pallet-xcm send with proper fee payment instructions.
2. Broadcaster Pallet (Relay Chain)
Location:
polkadot/runtime/parachains/src/broadcaster/V1 of the core relay chain pallet managing published data with registration-based access control.
Registration System:
Deposits held via HoldReason::PublisherDeposit using fungible traits
Storage Architecture:
ChildInfo::new_default((b"pubsub", para_id).encode())MaxValueLength(1024 bytes)MaxTotalStorageSizeper publisher (sum of all 32-byte keys + value lengths)Storage Maps:
RegisteredPublishers: Publisher info (manager account, deposit amount)PublisherExists: Tracks active publishers with child triesPublishedKeys: Enumerates all keys per publisher (bounded byMaxStoredKeys)TotalStorageSize: Current storage usage per publisher in bytesExtrinsics:
register_publisher(para_id): Register with standard depositforce_register_publisher(manager, deposit, para_id): Root registration with custom depositcleanup_published_data(para_id): Remove all key-value pairs (manager only, required before deregister)deregister_publisher(para_id): Release deposit after cleanup (manager only)force_deregister_publisher(para_id): Root-only immediate cleanup and deposit releaseIntegrity Checks: Runtime integrity tests ensure
MaxPublishItemsandMaxValueLengthdon't exceed XCM v5 bounds.Trait:
Integration:
OnNewSessionOutgoingtrait ininitializer3. Initializer Pallet Extension (Session Change Hook)
Location:
polkadot/runtime/parachains/src/initializer.rsAdded new trait for handling session changes when parachains are being offboarded. This enables operations or automatic cleanup of parachain-specific state during session transitions.
Config Extension:
type OnNewSessionOutgoing: OnNewSessionOutgoing<BlockNumberFor<Self>>;The initializer pallet now calls
OnNewSessionOutgoing::on_new_session_outgoing(¬ification, &outgoing_paras)during session changes, passing the list of offboarded parachains.Intended Broadcaster Integration: The broadcaster pallet implements
OnNewSessionOutgoingto automatically cleanup published data when parachains are offboarded, preventing orphaned data on the relay chain.4. BroadcastHandler Trait & Adapter
Location:
polkadot/xcm/xcm-executor/src/traits/broadcast_handler.rs, polkadot/xcm/xcm-builder/src/broadcast_adapter.rsParachainBroadcastAdapter:
XCM Executor Integration:
XCM Benchmarking: Added Publish instruction benchmarking to
pallet-xcm-benchmarks::genericas weight consumption for each runtime will depend on handler implementation.5. Relay Proof Request System
Location:
cumulus/primitives/core/src/lib.rsKeyToIncludeInRelayProofApi:
fn keys_to_prove() -> RelayProofRequest;Allows parachains to request both top-level and child trie storage proofs. Collators generate proofs for requested keys and include them in
ParachainInherentData::relay_chain_state.Dedicated PR: #10678
6. Collator Integration
Location:
cumulus/client/parachain-inherent/src/lib.rsCollators call
keys_to_prove()runtime API to retrieve RelayProofRequest from the parachain runtime.The
collect_additional_storage_proofsfunction processes bothRelayStorageKey::TopandRelayStorageKey::Childentries, generating proofs viaRelayChainInterface.All proofs are included in the relay chain state proof passed to the parachain runtime through
ParachainInherentData.Relay Chain Interface Extension:
RelayChainInterfaceextended with child trie proof supportRelayChainInProcessInterfaceRelayChainRpcInterfaceDedicated PR: #10678
7. Parachain System Integration
Location:
cumulus/pallets/parachain-system/src/Config Extension:
Integration Point: During
set_validation_data, after verifying the relay chain state proof, the pallet callsRelayProofKeysProcessor::process_relay_proof_keys(&relay_state_proof).The returned weight is accumulated into the inherent's total weight.
This is the critical hook that enables pallet-subscriber and other pallets to securely access relay chain data within the verified context.
Dedicated PR: #10678
8. Subscriber Pallet (Parachain)
Location:
cumulus/pallets/subscriber/Generic pallet for processing child trie data from relay chain proofs.
Implements
ProcessRelayProofKeysto integrate with parachain-system.Defines
SubscriptionHandlertrait:Runtime implements this trait to define subscription logic and data processing.
Integration Flow:
get_relay_proof_requests()transforms subscriptions into child trie proof requests forkeys_to_prove()APIProcessRelayProofKeys::process_relay_proof_keys()reads child trie roots from verified proofPreviousPublishedDataRootsstorage (change detection)Storage:
PreviousPublishedDataRoots: Maps ParaId to child trie root hash (32 bytes), bounded byMaxPublishersExtrinsics:
clear_stored_roots(publisher): Root-only call to force reprocessing in next block (recovery scenarios)Change Detection: Only publishers with changed child trie roots trigger data extraction and handler calls, significantly reducing storage writes and computation.
Provides
no_stdbench_proof_builderfor benchmarking.Testing
Rococo Integration (Testing Purposes)
Relay - Location:
polkadot/runtime/rococo/src/Parachain - Location:
cumulus/parachains/runtimes/testing/rococo-parachain/(RIP)Handlers and API's have been setup plus a simple
pubsubConsumerpallet has been provided to demo a potential integration withSubscriberA full demo integration of config can be found at:
https://github.com/blockdeep/polkadot-sdk/tree/feat/pubsub-rev1225-dev
Rationale: Enables reviewers to test the complete flow using Zombienet (config provided in pubsub-dev/zombienet.toml).
It is recommended to run this test on the testing branch as it has both tooling and setups and it can be used as reference on any other integration. It also showcases benchmarking setup.
Local Testing with Zombienet
A Zombienet configuration is provided in pubsub-dev/ for local testing:
cd pubsub-dev./build.sh # Build polkadot and polkadot-parachainzombienet spawn zombienet.tomlThis spins up:
Extrinsics:
[Relay] Fund Parachain's
Sovereign Account:0x04030070617261e80300000000000000000000000000000000000000000000000000000b00407a10f35a[Relay] Force register Parachain 1000:
0xff004101d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d00000000000000000000000000000000e8030000[Parachain] Publish some Data via
pallet-xcmsendcall:0x02003300050100050c000400000002286bee1300000002286bee00340800000000000000000000000000000000000000000000000000000000000000010812340000000000000000000000000000000000000000000000000000000000000002084321Closure
Please share any concerns, suggestions, or alternative approaches.
Related original issue