Skip to content

Commit a2980ab

Browse files
authored
More cleanup + benchmarks + XCM nits and renamings (#45)
* typos * More clean up * Messags benchmarks * More XCM nits
1 parent c28412b commit a2980ab

File tree

9 files changed

+387
-430
lines changed

9 files changed

+387
-430
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ The Bulletin chain consists of a customized node implementation and a single run
44

55
## Node implementation
66

7-
The Bulletin chain node implements IPFS support on top of a regualar Substrate node. Only work with `litep2p` network backend is supported (enabled by default), and in order to use IPFS functionality `--ipfs-server` flag must be passed to the node binary.
7+
The Bulletin chain node implements IPFS support on top of a regular Substrate node. Only work with `litep2p` network backend is supported (enabled by default), and in order to use IPFS functionality `--ipfs-server` flag must be passed to the node binary.
88

99
IPFS support comes in two parts:
1010

1111
1. Bitswap protocol implementation. Wire protocol for transferring chunks stored in transaction storage to IPFS clients. This is implemented in `litep2p` networking library and `litep2p` network backend in `sc-network` crate.
12-
2. IPFS Kademlia DHT support. We publish content provider records for our node for CIDs (content identifiers) of transactions stored in transaction storage. Content provider records are only kept for transactions included in the chain during last two weeks, what should agree with block pruning period of the Bulletin nodes. DHT support is provided by `litep2p` networking library and `sc-network` crate. The implementation in the Bulletin node ensures we register as content providers for transactions during last two weeks.
12+
2. IPFS Kademlia DHT support. We publish content provider records for our node for CIDs (content identifiers) of transactions stored in transaction storage. Content provider records are only kept for transactions included in the chain during last two weeks, what should agree with block pruning period of the Bulletin nodes. DHT support is provided by `litep2p` networking library and `sc-network` crate. The implementation in the Bulletin node ensures we register as content providers for transactions during the last two weeks.
1313

14-
Bulletin node also has idle connection timeout set to 1 hour instead of default 10 seconds to allow manually adding the node to the swarm of an IPFS client and ensuring we don't disconnect the IPFS client. This is done to allow IPFS clients to query data over Bitswap protocol before IPFS Kademlia DHT support is implemented (DHT support is planned to be ready by the end of August 2025).
14+
Bulletin node also has an idle connection timeout set to 1 hour instead of the default 10 seconds to allow manually adding the node to the swarm of an IPFS client and ensuring we don't disconnect the IPFS client. This is done to allow IPFS clients to query data over Bitswap protocol before IPFS Kademlia DHT support is implemented (DHT support is planned to be ready by the end of August 2025).
1515

16-
TODO: clarify if we need to store transactiond for two weeks or other period.
16+
TODO: clarify if we need to store transactions for two weeks or another period.
1717

1818
## Runtime functionality
1919

2020
The Bulletin chain runtime is a standard BaBE + GRANDPA chain with a custom validator set pallet which is (currently) controlled by root call (TODO: clarify whether this should be sudo, governance, etc).
21-
It functions to store transactions for a given period of time (currently set at 2 weeks) and provide proofs of storage.
21+
It functions to store transactions for a given period of time (currently set at 2 weeks) and provide proof of storage.
2222

2323
### Core functionality
2424

2525
The main purpose of the Bulletin chain is to provide storage for the People Chain over the bridge.
2626

2727
#### Storage
28-
The core functionality of the bulletin chain is in the transaction-storage pallet, which indexes transcations and manages storage proofs for arbitrary data.
28+
The core functionality of the bulletin chain is in the transaction-storage pallet, which indexes transactions and manages storage proofs for arbitrary data.
2929

3030
Data is added via the `transactionStorage.store` extrinsic, provided the storage of the data is authorized by root call. Authorization is granted either for a specific account via authorize_account or for data with a specific preimage via authorize_preimage. Once data is stored, it can be retrieved from IPFS with the Blake2B hash of the data.
3131

pallets/transaction-storage/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ pub mod pallet {
367367
Ok(().into())
368368
}
369369

370-
/// Check storage proof for block number `block_number() - StoragePeriod`. If such block
371-
/// does not exist the proof is expected to be `None`.
370+
/// Check storage proof for block number `block_number() - StoragePeriod`. If such a block
371+
/// does not exist, the proof is expected to be `None`.
372372
///
373373
/// ## Complexity
374374
///

runtimes/bulletin-polkadot/src/lib.rs

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,20 +642,110 @@ mod benches {
642642
[pallet_relayer_set, RelayerSet]
643643

644644
[pallet_bridge_grandpa, BridgePolkadotGrandpa]
645-
// [pallet_bridge_parachains, BridgeParachainsBench::<Runtime, bridge_config::WithPolkadotBridgeParachainsInstance>]
646-
// [pallet_bridge_messages, BridgeMessagesBench::<Runtime, bridge_config::WithPeoplePolkadotMessagesInstance>]
645+
[pallet_bridge_parachains, PolkadotParachains]
646+
[pallet_bridge_messages, PolkadotMessages]
647647
);
648648

649649
pub use frame_benchmarking::{baseline::Pallet as Baseline, BenchmarkBatch, BenchmarkList};
650650
pub use frame_system_benchmarking::Pallet as SystemBench;
651651

652652
pub use frame_support::traits::{StorageInfoTrait, WhitelistedStorageKeys};
653-
pub use pallet_bridge_messages::benchmarking::Pallet as BridgeMessagesBench;
654-
pub use pallet_bridge_parachains::benchmarking::Pallet as BridgeParachainsBench;
655653
pub use sp_storage::TrackedStorageKey;
656654

657655
impl frame_system_benchmarking::Config for Runtime {}
658656
impl frame_benchmarking::baseline::Config for Runtime {}
657+
658+
use bridge_runtime_common::parachains_benchmarking::prepare_parachain_heads_proof;
659+
use pallet_bridge_parachains::benchmarking::Config as BridgeParachainsConfig;
660+
661+
impl BridgeParachainsConfig<bridge_config::WithPolkadotBridgeParachainsInstance> for Runtime {
662+
fn parachains() -> Vec<bp_polkadot_core::parachains::ParaId> {
663+
use bp_runtime::Parachain;
664+
vec![bp_polkadot_core::parachains::ParaId(
665+
bridge_config::bp_people_polkadot::PeoplePolkadot::PARACHAIN_ID,
666+
)]
667+
}
668+
669+
fn prepare_parachain_heads_proof(
670+
parachains: &[bp_polkadot_core::parachains::ParaId],
671+
parachain_head_size: u32,
672+
proof_params: bp_runtime::UnverifiedStorageProofParams,
673+
) -> (
674+
bp_parachains::RelayBlockNumber,
675+
bp_parachains::RelayBlockHash,
676+
bp_polkadot_core::parachains::ParaHeadsProof,
677+
Vec<(bp_polkadot_core::parachains::ParaId, bp_polkadot_core::parachains::ParaHash)>,
678+
) {
679+
prepare_parachain_heads_proof::<
680+
Runtime,
681+
bridge_config::WithPolkadotBridgeParachainsInstance,
682+
>(parachains, parachain_head_size, proof_params)
683+
}
684+
}
685+
686+
use bridge_runtime_common::messages_benchmarking::{
687+
generate_xcm_builder_bridge_message_sample, prepare_message_delivery_proof_from_parachain,
688+
prepare_message_proof_from_parachain,
689+
};
690+
use pallet_bridge_messages::{
691+
benchmarking::{
692+
Config as BridgeMessagesConfig, MessageDeliveryProofParams, MessageProofParams,
693+
},
694+
LaneIdOf,
695+
};
696+
697+
impl BridgeMessagesConfig<bridge_config::WithPeoplePolkadotMessagesInstance> for Runtime {
698+
fn is_relayer_rewarded(_relayer: &Self::AccountId) -> bool {
699+
// TODO:
700+
// no rewards, so we don't care
701+
true
702+
}
703+
704+
fn prepare_message_proof(
705+
params: MessageProofParams<
706+
LaneIdOf<Runtime, bridge_config::WithPeoplePolkadotMessagesInstance>,
707+
>,
708+
) -> (bridge_config::benchmarking::FromPeoplePolkadotMessagesProof, Weight) {
709+
prepare_message_proof_from_parachain::<
710+
Runtime,
711+
bridge_config::WithPolkadotBridgeGrandpaInstance,
712+
bridge_config::WithPeoplePolkadotMessagesInstance,
713+
>(
714+
params,
715+
generate_xcm_builder_bridge_message_sample(
716+
bridge_config::PeoplePolkadotLocation::get().interior().clone(),
717+
),
718+
)
719+
}
720+
721+
fn prepare_message_delivery_proof(
722+
params: MessageDeliveryProofParams<
723+
AccountId,
724+
LaneIdOf<Runtime, bridge_config::WithPeoplePolkadotMessagesInstance>,
725+
>,
726+
) -> bridge_config::benchmarking::ToPeoplePolkadotMessagesDeliveryProof {
727+
prepare_message_delivery_proof_from_parachain::<
728+
Runtime,
729+
bridge_config::WithPolkadotBridgeGrandpaInstance,
730+
bridge_config::WithPeoplePolkadotMessagesInstance,
731+
>(params)
732+
}
733+
734+
fn is_message_successfully_dispatched(_nonce: bp_messages::MessageNonce) -> bool {
735+
// TODO:
736+
// currently we have no means to detect that
737+
true
738+
}
739+
}
740+
741+
pub type PolkadotParachains = pallet_bridge_parachains::benchmarking::Pallet<
742+
Runtime,
743+
bridge_config::WithPolkadotBridgeParachainsInstance,
744+
>;
745+
pub type PolkadotMessages = pallet_bridge_messages::benchmarking::Pallet<
746+
Runtime,
747+
bridge_config::WithPeoplePolkadotMessagesInstance,
748+
>;
659749
}
660750

661751
#[cfg(feature = "runtime-benchmarks")]

runtimes/bulletin-polkadot/src/polkadot_bridge_config.rs

Lines changed: 26 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ parameter_types! {
157157
1,
158158
[GlobalConsensus(PolkadotGlobalConsensusNetwork::get())]
159159
);
160+
/// Location of the PeoplePolkadot parachain, relative to this runtime.
161+
pub PeoplePolkadotLocation: Location = Location::new(1, [
162+
GlobalConsensus(BridgedNetwork::get()),
163+
Parachain(bp_people_polkadot::PEOPLE_POLKADOT_PARACHAIN_ID),
164+
]);
160165

161166
/// A number of Polkadot mandatory headers that are accepted for free at every
162167
/// **this chain** block.
@@ -213,7 +218,7 @@ impl pallet_bridge_grandpa::Config<WithPolkadotBridgeGrandpaInstance> for Runtim
213218
pub type WithPolkadotBridgeParachainsInstance = ();
214219
impl pallet_bridge_parachains::Config<WithPolkadotBridgeParachainsInstance> for Runtime {
215220
type RuntimeEvent = RuntimeEvent;
216-
type WeightInfo = crate::weights::bridge_polkadot_parachains::WeightInfo<Runtime>;
221+
type WeightInfo = crate::weights::pallet_bridge_parachains::WeightInfo<Runtime>;
217222

218223
type BridgesGrandpaPalletInstance = WithPolkadotBridgeGrandpaInstance;
219224
type ParasPalletName = AtPolkadotParasPalletName;
@@ -319,7 +324,7 @@ impl<BlobDispatcher: DispatchBlob, Weights: pallet_bridge_messages::WeightInfoEx
319324
pub type WithPeoplePolkadotMessagesInstance = ();
320325
impl pallet_bridge_messages::Config<WithPeoplePolkadotMessagesInstance> for Runtime {
321326
type RuntimeEvent = RuntimeEvent;
322-
type WeightInfo = crate::weights::bridge_polkadot_messages::WeightInfo<Runtime>;
327+
type WeightInfo = crate::weights::pallet_bridge_messages::WeightInfo<Runtime>;
323328

324329
type ThisChain = bp_polkadot_bulletin::PolkadotBulletin;
325330
type BridgedChain = bp_people_polkadot::PeoplePolkadot;
@@ -430,97 +435,28 @@ where
430435
pub type ToBridgeHaulBlobExporter = HaulBlobExporter<
431436
XcmBlobHauler<Runtime, WithPeoplePolkadotMessagesInstance>,
432437
PolkadotGlobalConsensusNetworkLocation,
433-
AlwaysV4,
438+
AlwaysV5,
434439
(),
435440
>;
436441

437-
// #[cfg(feature = "runtime-benchmarks")]
438-
// pub mod benchmarking {
439-
// use super::*;
440-
//
441-
// /// Proof of messages, coming from BridgeHubPolkadot.
442-
// pub type FromBridgeHubPolkadotMessagesProof =
443-
// bridge_runtime_common::messages::target::FromBridgedChainMessagesProof<
444-
// bp_people_polkadot::Hash,
445-
// >;
446-
//
447-
// /// Message delivery proof for `BridgeHubPolkadot` messages.
448-
// pub type ToBridgeHubPolkadotMessagesDeliveryProof =
449-
// bridge_runtime_common::messages::source::FromBridgedChainMessagesDeliveryProof<
450-
// bp_people_polkadot::Hash,
451-
// >;
452-
//
453-
// use bridge_runtime_common::messages_benchmarking::{
454-
// generate_xcm_builder_bridge_message_sample, prepare_message_delivery_proof_from_parachain,
455-
// prepare_message_proof_from_parachain,
456-
// };
457-
// use pallet_bridge_messages::benchmarking::{
458-
// Config as BridgeMessagesConfig, MessageDeliveryProofParams, MessageProofParams,
459-
// };
460-
//
461-
// impl BridgeMessagesConfig<WithBridgeHubPolkadotMessagesInstance> for Runtime {
462-
// fn is_relayer_rewarded(_relayer: &Self::AccountId) -> bool {
463-
// // no rewards, so we don't care
464-
// true
465-
// }
466-
//
467-
// fn prepare_message_proof(
468-
// params: MessageProofParams,
469-
// ) -> (FromBridgeHubPolkadotMessagesProof, Weight) {
470-
// prepare_message_proof_from_parachain::<
471-
// Runtime,
472-
// WithPolkadotBridgeGrandpaInstance,
473-
// WithBridgeHubPolkadotMessageBridge,
474-
// >(
475-
// params,
476-
// generate_xcm_builder_bridge_message_sample(
477-
// *crate::xcm_config::KawabungaLocation::get().interior(),
478-
// ),
479-
// )
480-
// }
481-
//
482-
// fn prepare_message_delivery_proof(
483-
// params: MessageDeliveryProofParams<AccountId>,
484-
// ) -> ToBridgeHubPolkadotMessagesDeliveryProof {
485-
// prepare_message_delivery_proof_from_parachain::<
486-
// Runtime,
487-
// WithPolkadotBridgeGrandpaInstance,
488-
// WithBridgeHubPolkadotMessageBridge,
489-
// >(params)
490-
// }
491-
//
492-
// fn is_message_successfully_dispatched(_nonce: bp_messages::MessageNonce) -> bool {
493-
// // currently we have no means to detect that
494-
// true
495-
// }
496-
// }
497-
//
498-
// use bridge_runtime_common::parachains_benchmarking::prepare_parachain_heads_proof;
499-
// use pallet_bridge_parachains::benchmarking::Config as BridgeParachainsConfig;
500-
// impl BridgeParachainsConfig<WithPolkadotBridgeParachainsInstance> for Runtime {
501-
// fn parachains() -> Vec<bp_polkadot::parachains::ParaId> {
502-
// use bp_runtime::Parachain;
503-
// vec![bp_polkadot::parachains::ParaId(BridgeHubPolkadotOrPolkadot::PARACHAIN_ID)]
504-
// }
505-
//
506-
// fn prepare_parachain_heads_proof(
507-
// parachains: &[bp_polkadot::parachains::ParaId],
508-
// parachain_head_size: u32,
509-
// proof_size: bp_runtime::StorageProofSize,
510-
// ) -> (
511-
// pallet_bridge_parachains::RelayBlockNumber,
512-
// pallet_bridge_parachains::RelayBlockHash,
513-
// bp_polkadot::parachains::ParaHeadsProof,
514-
// Vec<(bp_polkadot::parachains::ParaId, bp_polkadot::parachains::ParaHash)>,
515-
// ) {
516-
// prepare_parachain_heads_proof::<Runtime, WithPolkadotBridgeParachainsInstance>(
517-
// parachains,
518-
// parachain_head_size,
519-
// proof_size,
520-
// )
521-
// }
522-
// }
523-
// }
442+
#[cfg(feature = "runtime-benchmarks")]
443+
pub mod benchmarking {
444+
use super::*;
445+
446+
/// Proof of messages, coming from PeoplePolkadot.
447+
pub type FromPeoplePolkadotMessagesProof =
448+
bp_messages::target_chain::FromBridgedChainMessagesProof<
449+
bp_people_polkadot::Hash,
450+
pallet_bridge_messages::LaneIdOf<Runtime, WithPeoplePolkadotMessagesInstance>,
451+
>;
452+
453+
/// Message delivery proof for `PeoplePolkadot` messages.
454+
pub type ToPeoplePolkadotMessagesDeliveryProof =
455+
bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof<
456+
bp_people_polkadot::Hash,
457+
pallet_bridge_messages::LaneIdOf<Runtime, WithPeoplePolkadotMessagesInstance>,
458+
>;
459+
}
524460
//
525461
// #[cfg(test)]
526462
// pub(crate) mod tests {

0 commit comments

Comments
 (0)