From f89e690bdf8e34f24279d7d934f7e54524015a23 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Wed, 24 Nov 2021 14:50:59 +0200 Subject: [PATCH 01/16] Add Beefy pallet to Rialto runtime --- Cargo.lock | 3 +++ bin/rialto/node/Cargo.toml | 1 + bin/rialto/node/src/chain_spec.rs | 16 +++++++++++----- bin/rialto/runtime/Cargo.toml | 4 ++++ bin/rialto/runtime/src/lib.rs | 13 +++++++++++++ 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 43988571e19..55f8bdb63ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8141,6 +8141,7 @@ checksum = "448296241d034b96c11173591deaa1302f2c17b56092106c1f92c1bc0183a8c9" name = "rialto-bridge-node" version = "0.1.0" dependencies = [ + "beefy-primitives", "bp-rialto", "bp-runtime", "frame-benchmarking", @@ -8338,6 +8339,7 @@ dependencies = [ name = "rialto-runtime" version = "0.1.0" dependencies = [ + "beefy-primitives", "bp-header-chain", "bp-message-dispatch", "bp-messages", @@ -8356,6 +8358,7 @@ dependencies = [ "pallet-authority-discovery", "pallet-babe", "pallet-balances", + "pallet-beefy", "pallet-bridge-dispatch", "pallet-bridge-grandpa", "pallet-bridge-messages", diff --git a/bin/rialto/node/Cargo.toml b/bin/rialto/node/Cargo.toml index fd76fbf9a61..5072606f0c1 100644 --- a/bin/rialto/node/Cargo.toml +++ b/bin/rialto/node/Cargo.toml @@ -28,6 +28,7 @@ rialto-runtime = { path = "../runtime" } # Substrate Dependencies +beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bin/rialto/node/src/chain_spec.rs b/bin/rialto/node/src/chain_spec.rs index cadacad72da..fb18a35a6af 100644 --- a/bin/rialto/node/src/chain_spec.rs +++ b/bin/rialto/node/src/chain_spec.rs @@ -14,12 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . +use beefy_primitives::crypto::AuthorityId as BeefyId; use bp_rialto::derive_account_from_millau_id; use polkadot_primitives::v1::{AssignmentId, ValidatorId}; use rialto_runtime::{ - AccountId, BabeConfig, BalancesConfig, BridgeMillauMessagesConfig, ConfigurationConfig, - GenesisConfig, GrandpaConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig, - WASM_BINARY, + AccountId, BabeConfig, BalancesConfig, BeefyConfig, BridgeMillauMessagesConfig, + ConfigurationConfig, GenesisConfig, GrandpaConfig, SessionConfig, SessionKeys, Signature, + SudoConfig, SystemConfig, WASM_BINARY, }; use serde_json::json; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; @@ -62,10 +63,11 @@ where /// Helper function to generate authority keys. pub fn get_authority_keys_from_seed( s: &str, -) -> (AccountId, BabeId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) { +) -> (AccountId, BabeId, BeefyId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) { ( get_account_id_from_seed::(s), get_from_seed::(s), + get_from_seed::(s), get_from_seed::(s), get_from_seed::(s), get_from_seed::(s), @@ -183,18 +185,20 @@ impl Alternative { fn session_keys( babe: BabeId, + beefy: BeefyId, grandpa: GrandpaId, para_validator: ValidatorId, para_assignment: AssignmentId, authority_discovery: AuthorityDiscoveryId, ) -> SessionKeys { - SessionKeys { babe, grandpa, para_validator, para_assignment, authority_discovery } + SessionKeys { babe, beefy, grandpa, para_validator, para_assignment, authority_discovery } } fn testnet_genesis( initial_authorities: Vec<( AccountId, BabeId, + BeefyId, GrandpaId, ValidatorId, AssignmentId, @@ -215,6 +219,7 @@ fn testnet_genesis( authorities: Vec::new(), epoch_config: Some(rialto_runtime::BABE_GENESIS_EPOCH_CONFIG), }, + beefy: BeefyConfig { authorities: Vec::new() }, grandpa: GrandpaConfig { authorities: Vec::new() }, sudo: SudoConfig { key: root_key }, session: SessionConfig { @@ -230,6 +235,7 @@ fn testnet_genesis( x.3.clone(), x.4.clone(), x.5.clone(), + x.6.clone(), ), ) }) diff --git a/bin/rialto/runtime/Cargo.toml b/bin/rialto/runtime/Cargo.toml index 36dc436ddca..ce41bb3498f 100644 --- a/bin/rialto/runtime/Cargo.toml +++ b/bin/rialto/runtime/Cargo.toml @@ -31,6 +31,7 @@ pallet-shift-session-manager = { path = "../../../modules/shift-session-manager" # Substrate Dependencies +beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } frame-executive = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -39,6 +40,7 @@ frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate" pallet-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-babe = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -76,6 +78,7 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran [features] default = ["std"] std = [ + "beefy-primitives/std", "bp-header-chain/std", "bp-message-dispatch/std", "bp-messages/std", @@ -93,6 +96,7 @@ std = [ "pallet-authority-discovery/std", "pallet-babe/std", "pallet-balances/std", + "pallet-beefy/std", "pallet-bridge-dispatch/std", "pallet-bridge-grandpa/std", "pallet-bridge-messages/std", diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index 5e7e47490d5..f3f37d3f9f5 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -35,6 +35,7 @@ pub mod parachains; use crate::millau_messages::{ToMillauMessagePayload, WithMillauMessageBridge}; +use beefy_primitives::{crypto::AuthorityId as BeefyId, ValidatorSet}; use bridge_runtime_common::messages::{ source::estimate_message_dispatch_and_delivery_fee, MessageBridge, }; @@ -122,6 +123,7 @@ impl_opaque_keys! { pub struct SessionKeys { pub babe: Babe, pub grandpa: Grandpa, + pub beefy: Beefy, pub para_validator: Initializer, pub para_assignment: SessionInfo, pub authority_discovery: AuthorityDiscovery, @@ -242,6 +244,10 @@ impl pallet_babe::Config for Runtime { type WeightInfo = (); } +impl pallet_beefy::Config for Runtime { + type BeefyId = BeefyId; +} + impl pallet_bridge_dispatch::Config for Runtime { type Event = Event; type BridgeMessageId = (bp_messages::LaneId, bp_messages::MessageNonce); @@ -461,6 +467,7 @@ construct_runtime!( AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config}, Session: pallet_session::{Pallet, Call, Storage, Event, Config}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, + Beefy: pallet_beefy::{Pallet, Call, Storage, Config}, ShiftSessionManager: pallet_shift_session_manager::{Pallet}, // Millau bridge modules. @@ -572,6 +579,12 @@ impl_runtime_apis! { } } + impl beefy_primitives::BeefyApi for Runtime { + fn validator_set() -> ValidatorSet { + Beefy::validator_set() + } + } + impl bp_millau::MillauFinalityApi for Runtime { fn best_finalized() -> (bp_millau::BlockNumber, bp_millau::Hash) { let header = BridgeMillauGrandpa::best_finalized(); From 6ede1a0bfc7698c389aa262ece582b52eef4160f Mon Sep 17 00:00:00 2001 From: acatangiu Date: Wed, 24 Nov 2021 17:03:52 +0200 Subject: [PATCH 02/16] Add Beefy gadget to Rialto node --- Cargo.lock | 2 ++ bin/rialto/node/Cargo.toml | 2 ++ bin/rialto/node/src/service.rs | 40 ++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55f8bdb63ab..f6c2acbe117 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8141,6 +8141,8 @@ checksum = "448296241d034b96c11173591deaa1302f2c17b56092106c1f92c1bc0183a8c9" name = "rialto-bridge-node" version = "0.1.0" dependencies = [ + "beefy-gadget", + "beefy-gadget-rpc", "beefy-primitives", "bp-rialto", "bp-runtime", diff --git a/bin/rialto/node/Cargo.toml b/bin/rialto/node/Cargo.toml index 5072606f0c1..15f3aadcee4 100644 --- a/bin/rialto/node/Cargo.toml +++ b/bin/rialto/node/Cargo.toml @@ -29,6 +29,8 @@ rialto-runtime = { path = "../runtime" } # Substrate Dependencies beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } +beefy-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" } +beefy-gadget-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bin/rialto/node/src/service.rs b/bin/rialto/node/src/service.rs index fb774d86cca..67e5201219b 100644 --- a/bin/rialto/node/src/service.rs +++ b/bin/rialto/node/src/service.rs @@ -184,7 +184,12 @@ pub fn new_partial( sc_rpc::DenyUnsafe, sc_rpc::SubscriptionTaskExecutor, ) -> Result, sc_service::Error>, - (FullBabeBlockImport, FullGrandpaLink, FullBabeLink), + ( + FullBabeBlockImport, + FullGrandpaLink, + FullBabeLink, + beefy_gadget::notification::BeefySignedCommitmentSender, + ), sc_finality_grandpa::SharedVoterState, std::time::Duration, Option, @@ -282,7 +287,10 @@ where let shared_authority_set = grandpa_link.shared_authority_set().clone(); let shared_voter_state = sc_finality_grandpa::SharedVoterState::empty(); - let import_setup = (block_import, grandpa_link, babe_link); + let (signed_commitment_sender, signed_commitment_stream) = + beefy_gadget::notification::BeefySignedCommitmentStream::channel(); + + let import_setup = (block_import, grandpa_link, babe_link, signed_commitment_sender); let rpc_setup = shared_voter_state.clone(); let slot_duration = babe_config.slot_duration(); @@ -321,9 +329,15 @@ where shared_authority_set.clone(), shared_voter_state, justification_stream.clone(), - subscription_executor, + subscription_executor.clone(), finality_proof_provider, ))); + io.extend_with(beefy_gadget_rpc::BeefyApi::to_delegate( + beefy_gadget_rpc::BeefyRpcHandler::new( + signed_commitment_stream.clone(), + subscription_executor, + ), + )); Ok(io) } @@ -442,6 +456,8 @@ where // Substrate nodes. config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config()); + config.network.extra_sets.push(beefy_gadget::beefy_peers_set_config()); + { use polkadot_network_bridge::{peer_sets_info, IsAuthority}; let is_authority = if role.is_authority() { IsAuthority::Yes } else { IsAuthority::No }; @@ -536,7 +552,7 @@ where telemetry: telemetry.as_mut(), })?; - let (block_import, link_half, babe_link) = import_setup; + let (block_import, link_half, babe_link, signed_commitment_sender) = import_setup; let overseer_client = client.clone(); let spawner = task_manager.spawn_handle(); @@ -713,6 +729,22 @@ where let keystore_opt = if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None }; + let beefy_params = beefy_gadget::BeefyParams { + client: client.clone(), + backend: backend.clone(), + key_store: keystore_opt.clone(), + network: network.clone(), + signed_commitment_sender, + min_block_delta: 4, + prometheus_registry: prometheus_registry.clone(), + }; + + // Start the BEEFY bridge gadget. + task_manager.spawn_essential_handle().spawn_blocking( + "beefy-gadget", + beefy_gadget::start_beefy_gadget::<_, _, _, _>(beefy_params), + ); + let config = sc_finality_grandpa::Config { // FIXME substrate#1578 make this available through chainspec gossip_duration: Duration::from_millis(1000), From deaa8b8a83ab088c757c54b25a52bba4c17ccd79 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Wed, 24 Nov 2021 18:20:13 +0200 Subject: [PATCH 03/16] Add MMR pallet to Rialto runtime --- Cargo.lock | 1 + bin/rialto/runtime/Cargo.toml | 2 ++ bin/rialto/runtime/src/lib.rs | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f6c2acbe117..6e1bab45c69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8365,6 +8365,7 @@ dependencies = [ "pallet-bridge-grandpa", "pallet-bridge-messages", "pallet-grandpa", + "pallet-mmr", "pallet-session", "pallet-shift-session-manager", "pallet-sudo", diff --git a/bin/rialto/runtime/Cargo.toml b/bin/rialto/runtime/Cargo.toml index ce41bb3498f..af44f777156 100644 --- a/bin/rialto/runtime/Cargo.toml +++ b/bin/rialto/runtime/Cargo.toml @@ -42,6 +42,7 @@ pallet-babe = { git = "https://github.com/paritytech/substrate", branch = "maste pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -101,6 +102,7 @@ std = [ "pallet-bridge-grandpa/std", "pallet-bridge-messages/std", "pallet-grandpa/std", + "pallet-mmr/std", "pallet-shift-session-manager/std", "pallet-sudo/std", "pallet-timestamp/std", diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index f3f37d3f9f5..a0e383a9831 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -48,7 +48,7 @@ use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdLookup, Block as BlockT, NumberFor, OpaqueKeys}, + traits::{AccountIdLookup, Block as BlockT, Keccak256, NumberFor, OpaqueKeys}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, MultiSignature, MultiSigner, Perquintill, }; @@ -276,6 +276,32 @@ impl pallet_grandpa::Config for Runtime { type WeightInfo = (); } +type MmrHash = ::Output; + +// TODO: use `pallet_beefy_mmr::DepositBeefyDigest` instead of `DepositLog` below. + +/// A BEEFY consensus digest item with MMR root hash. +pub struct DepositLog; +impl pallet_mmr::primitives::OnNewRoot for DepositLog { + fn on_new_root(root: &Hash) { + let digest = DigestItem::Consensus( + beefy_primitives::BEEFY_ENGINE_ID, + codec::Encode::encode(&beefy_primitives::ConsensusLog::::MmrRoot(*root)), + ); + >::deposit_log(digest); + } +} + +/// Configure Merkle Mountain Range pallet. +impl pallet_mmr::Config for Runtime { + const INDEXING_PREFIX: &'static [u8] = b"mmr"; + type Hashing = Keccak256; + type Hash = MmrHash; + type OnNewRoot = DepositLog; + type WeightInfo = (); + type LeafData = frame_system::Pallet; +} + parameter_types! { pub const MinimumPeriod: u64 = bp_rialto::SLOT_DURATION / 2; } @@ -467,9 +493,12 @@ construct_runtime!( AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config}, Session: pallet_session::{Pallet, Call, Storage, Event, Config}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, - Beefy: pallet_beefy::{Pallet, Call, Storage, Config}, ShiftSessionManager: pallet_shift_session_manager::{Pallet}, + // Bridges support. + Beefy: pallet_beefy::{Pallet, Storage, Config}, + Mmr: pallet_mmr::{Pallet, Storage}, + // Millau bridge modules. BridgeMillauGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage}, BridgeDispatch: pallet_bridge_dispatch::{Pallet, Event}, From d7ae7b0c49adbe531c0cf95a25ee795b7fd702ee Mon Sep 17 00:00:00 2001 From: acatangiu Date: Wed, 24 Nov 2021 19:53:28 +0200 Subject: [PATCH 04/16] Add Beefy pallet to Millau runtime --- Cargo.lock | 3 +++ bin/millau/node/Cargo.toml | 1 + bin/millau/node/src/chain_spec.rs | 21 +++++++++++++-------- bin/millau/runtime/Cargo.toml | 4 ++++ bin/millau/runtime/src/lib.rs | 16 ++++++++++++++++ 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e1bab45c69..7e48a179934 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4580,6 +4580,7 @@ dependencies = [ name = "millau-bridge-node" version = "0.1.0" dependencies = [ + "beefy-primitives", "bp-millau", "bp-runtime", "frame-benchmarking", @@ -4618,6 +4619,7 @@ dependencies = [ name = "millau-runtime" version = "0.1.0" dependencies = [ + "beefy-primitives", "bp-header-chain", "bp-messages", "bp-millau", @@ -4633,6 +4635,7 @@ dependencies = [ "hex-literal", "pallet-aura", "pallet-balances", + "pallet-beefy", "pallet-bridge-dispatch", "pallet-bridge-grandpa", "pallet-bridge-messages", diff --git a/bin/millau/node/Cargo.toml b/bin/millau/node/Cargo.toml index b650bd478a6..b391166f664 100644 --- a/bin/millau/node/Cargo.toml +++ b/bin/millau/node/Cargo.toml @@ -23,6 +23,7 @@ pallet-bridge-messages = { path = "../../../modules/messages" } # Substrate Dependencies +beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bin/millau/node/src/chain_spec.rs b/bin/millau/node/src/chain_spec.rs index 05496bb64f6..fbfca8692fc 100644 --- a/bin/millau/node/src/chain_spec.rs +++ b/bin/millau/node/src/chain_spec.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . +use beefy_primitives::crypto::AuthorityId as BeefyId; use bp_millau::derive_account_from_rialto_id; use millau_runtime::{ - AccountId, AuraConfig, BalancesConfig, BridgeRialtoMessagesConfig, BridgeWestendGrandpaConfig, - GenesisConfig, GrandpaConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig, - WASM_BINARY, + AccountId, AuraConfig, BalancesConfig, BeefyConfig, BridgeRialtoMessagesConfig, + BridgeWestendGrandpaConfig, GenesisConfig, GrandpaConfig, SessionConfig, SessionKeys, + Signature, SudoConfig, SystemConfig, WASM_BINARY, }; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{sr25519, Pair, Public}; @@ -57,10 +58,11 @@ where } /// Helper function to generate an authority key for Aura -pub fn get_authority_keys_from_seed(s: &str) -> (AccountId, AuraId, GrandpaId) { +pub fn get_authority_keys_from_seed(s: &str) -> (AccountId, AuraId, BeefyId, GrandpaId) { ( get_account_id_from_seed::(s), get_from_seed::(s), + get_from_seed::(s), get_from_seed::(s), ) } @@ -173,12 +175,12 @@ impl Alternative { } } -fn session_keys(aura: AuraId, grandpa: GrandpaId) -> SessionKeys { - SessionKeys { aura, grandpa } +fn session_keys(aura: AuraId, beefy: BeefyId, grandpa: GrandpaId) -> SessionKeys { + SessionKeys { aura, beefy, grandpa } } fn testnet_genesis( - initial_authorities: Vec<(AccountId, AuraId, GrandpaId)>, + initial_authorities: Vec<(AccountId, AuraId, BeefyId, GrandpaId)>, root_key: AccountId, endowed_accounts: Vec, _enable_println: bool, @@ -191,12 +193,15 @@ fn testnet_genesis( balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 50)).collect(), }, aura: AuraConfig { authorities: Vec::new() }, + beefy: BeefyConfig { authorities: Vec::new() }, grandpa: GrandpaConfig { authorities: Vec::new() }, sudo: SudoConfig { key: root_key }, session: SessionConfig { keys: initial_authorities .iter() - .map(|x| (x.0.clone(), x.0.clone(), session_keys(x.1.clone(), x.2.clone()))) + .map(|x| { + (x.0.clone(), x.0.clone(), session_keys(x.1.clone(), x.2.clone(), x.3.clone())) + }) .collect::>(), }, bridge_westend_grandpa: BridgeWestendGrandpaConfig { diff --git a/bin/millau/runtime/Cargo.toml b/bin/millau/runtime/Cargo.toml index c8d7f0a1595..ac7e3f0eb27 100644 --- a/bin/millau/runtime/Cargo.toml +++ b/bin/millau/runtime/Cargo.toml @@ -30,6 +30,7 @@ pallet-shift-session-manager = { path = "../../../modules/shift-session-manager" # Substrate Dependencies +beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } frame-executive = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -37,6 +38,7 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "mast frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -64,6 +66,7 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran [features] default = ["std"] std = [ + "beefy-primitives/std", "bp-header-chain/std", "bp-messages/std", "bp-millau/std", @@ -78,6 +81,7 @@ std = [ "frame-system/std", "pallet-aura/std", "pallet-balances/std", + "pallet-beefy/std", "pallet-bridge-dispatch/std", "pallet-bridge-grandpa/std", "pallet-bridge-messages/std", diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index b713211b1e4..644ce511607 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -34,6 +34,7 @@ pub mod rialto_messages; use crate::rialto_messages::{ToRialtoMessagePayload, WithRialtoMessageBridge}; +use beefy_primitives::{crypto::AuthorityId as BeefyId, ValidatorSet}; use bridge_runtime_common::messages::{ source::estimate_message_dispatch_and_delivery_fee, MessageBridge, }; @@ -120,6 +121,7 @@ pub mod opaque { impl_opaque_keys! { pub struct SessionKeys { pub aura: Aura, + pub beefy: Beefy, pub grandpa: Grandpa, } } @@ -212,6 +214,11 @@ impl pallet_aura::Config for Runtime { type MaxAuthorities = MaxAuthorities; type DisabledValidators = (); } + +impl pallet_beefy::Config for Runtime { + type BeefyId = BeefyId; +} + impl pallet_bridge_dispatch::Config for Runtime { type Event = Event; type BridgeMessageId = (bp_messages::LaneId, bp_messages::MessageNonce); @@ -459,6 +466,9 @@ construct_runtime!( ShiftSessionManager: pallet_shift_session_manager::{Pallet}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, + // Bridges support. + Beefy: pallet_beefy::{Pallet, Storage, Config}, + // Rialto bridge modules. BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage}, BridgeDispatch: pallet_bridge_dispatch::{Pallet, Event}, @@ -603,6 +613,12 @@ impl_runtime_apis! { } } + impl beefy_primitives::BeefyApi for Runtime { + fn validator_set() -> ValidatorSet { + Beefy::validator_set() + } + } + impl fg_primitives::GrandpaApi for Runtime { fn current_set_id() -> fg_primitives::SetId { Grandpa::current_set_id() From f10a090d744155cf8271d066ffaa1b0e48a13033 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Wed, 24 Nov 2021 20:26:44 +0200 Subject: [PATCH 05/16] Add Beefy gadget to Millau node --- Cargo.lock | 2 ++ bin/millau/node/Cargo.toml | 2 ++ bin/millau/node/src/service.rs | 31 ++++++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e48a179934..8ca17681209 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4580,6 +4580,8 @@ dependencies = [ name = "millau-bridge-node" version = "0.1.0" dependencies = [ + "beefy-gadget", + "beefy-gadget-rpc", "beefy-primitives", "bp-millau", "bp-runtime", diff --git a/bin/millau/node/Cargo.toml b/bin/millau/node/Cargo.toml index b391166f664..c16adba4fd5 100644 --- a/bin/millau/node/Cargo.toml +++ b/bin/millau/node/Cargo.toml @@ -24,6 +24,8 @@ pallet-bridge-messages = { path = "../../../modules/messages" } # Substrate Dependencies beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } +beefy-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" } +beefy-gadget-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bin/millau/node/src/service.rs b/bin/millau/node/src/service.rs index 4085982494b..df1f731dbb2 100644 --- a/bin/millau/node/src/service.rs +++ b/bin/millau/node/src/service.rs @@ -209,6 +209,7 @@ pub fn new_full(mut config: Configuration) -> Result } config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config()); + config.network.extra_sets.push(beefy_gadget::beefy_peers_set_config()); let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new( backend.clone(), grandpa_link.shared_authority_set().clone(), @@ -242,6 +243,8 @@ pub fn new_full(mut config: Configuration) -> Result let enable_grandpa = !config.disable_grandpa; let prometheus_registry = config.prometheus_registry().cloned(); let shared_voter_state = SharedVoterState::empty(); + let (signed_commitment_sender, signed_commitment_stream) = + beefy_gadget::notification::BeefySignedCommitmentStream::channel(); let rpc_extensions_builder = { use sc_finality_grandpa::FinalityProofProvider as GrandpaFinalityProofProvider; @@ -264,7 +267,7 @@ pub fn new_full(mut config: Configuration) -> Result Some(shared_authority_set.clone()), ); - Box::new(move |_, subscription_executor| { + Box::new(move |_, subscription_executor: sc_rpc::SubscriptionTaskExecutor| { let mut io = jsonrpc_core::IoHandler::default(); io.extend_with(SystemApi::to_delegate(FullSystem::new( client.clone(), @@ -278,9 +281,15 @@ pub fn new_full(mut config: Configuration) -> Result shared_authority_set.clone(), shared_voter_state.clone(), justification_stream.clone(), - subscription_executor, + subscription_executor.clone(), finality_proof_provider.clone(), ))); + io.extend_with(beefy_gadget_rpc::BeefyApi::to_delegate( + beefy_gadget_rpc::BeefyRpcHandler::new( + signed_commitment_stream.clone(), + subscription_executor, + ), + )); Ok(io) }) }; @@ -292,7 +301,7 @@ pub fn new_full(mut config: Configuration) -> Result task_manager: &mut task_manager, transaction_pool: transaction_pool.clone(), rpc_extensions_builder, - backend, + backend: backend.clone(), system_rpc_tx, config, telemetry: telemetry.as_mut(), @@ -355,6 +364,22 @@ pub fn new_full(mut config: Configuration) -> Result let keystore = if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None }; + let beefy_params = beefy_gadget::BeefyParams { + client, + backend, + key_store: keystore.clone(), + network: network.clone(), + signed_commitment_sender, + min_block_delta: 4, + prometheus_registry: prometheus_registry.clone(), + }; + + // Start the BEEFY bridge gadget. + task_manager.spawn_essential_handle().spawn_blocking( + "beefy-gadget", + beefy_gadget::start_beefy_gadget::<_, _, _, _>(beefy_params), + ); + let grandpa_config = sc_finality_grandpa::Config { // FIXME #1578 make this available through chainspec gossip_duration: Duration::from_millis(333), From d3d21ee20b0d0ca725f96ec784855db9de0ed8e8 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Thu, 25 Nov 2021 11:30:10 +0200 Subject: [PATCH 06/16] Add MMR pallet to Millau runtime --- Cargo.lock | 1 + bin/millau/runtime/Cargo.toml | 2 ++ bin/millau/runtime/src/lib.rs | 29 ++++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 8ca17681209..a7cf32bc2fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4643,6 +4643,7 @@ dependencies = [ "pallet-bridge-messages", "pallet-bridge-token-swap", "pallet-grandpa", + "pallet-mmr", "pallet-randomness-collective-flip", "pallet-session", "pallet-shift-session-manager", diff --git a/bin/millau/runtime/Cargo.toml b/bin/millau/runtime/Cargo.toml index ac7e3f0eb27..c68f774843a 100644 --- a/bin/millau/runtime/Cargo.toml +++ b/bin/millau/runtime/Cargo.toml @@ -40,6 +40,7 @@ pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "maste pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -87,6 +88,7 @@ std = [ "pallet-bridge-messages/std", "pallet-bridge-token-swap/std", "pallet-grandpa/std", + "pallet-mmr/std", "pallet-randomness-collective-flip/std", "pallet-session/std", "pallet-shift-session-manager/std", diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index 644ce511607..a8446ce0358 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -47,7 +47,7 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{Block as BlockT, IdentityLookup, NumberFor, OpaqueKeys}, + traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, MultiSignature, MultiSigner, Perquintill, }; @@ -247,6 +247,32 @@ impl pallet_grandpa::Config for Runtime { type MaxAuthorities = MaxAuthorities; } +type MmrHash = bp_millau::Hash; + +// TODO: use `pallet_beefy_mmr::DepositBeefyDigest` instead of `DepositLog` below. + +/// A BEEFY consensus digest item with MMR root hash. +pub struct DepositLog; +impl pallet_mmr::primitives::OnNewRoot for DepositLog { + fn on_new_root(root: &Hash) { + let digest = DigestItem::Consensus( + beefy_primitives::BEEFY_ENGINE_ID, + codec::Encode::encode(&beefy_primitives::ConsensusLog::::MmrRoot(*root)), + ); + >::deposit_log(digest); + } +} + +/// Configure Merkle Mountain Range pallet. +impl pallet_mmr::Config for Runtime { + const INDEXING_PREFIX: &'static [u8] = b"mmr"; + type Hashing = Hashing; + type Hash = Hash; + type OnNewRoot = DepositLog; + type WeightInfo = (); + type LeafData = frame_system::Pallet; +} + parameter_types! { pub const MinimumPeriod: u64 = bp_millau::SLOT_DURATION / 2; } @@ -468,6 +494,7 @@ construct_runtime!( // Bridges support. Beefy: pallet_beefy::{Pallet, Storage, Config}, + Mmr: pallet_mmr::{Pallet, Storage}, // Rialto bridge modules. BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage}, From 21a1aeeafc9d1b645d8f9781c49eec65c76f54de Mon Sep 17 00:00:00 2001 From: acatangiu Date: Thu, 25 Nov 2021 12:30:30 +0200 Subject: [PATCH 07/16] Add pallet_beefy_mmr to Millau runtime --- Cargo.lock | 1 + bin/millau/runtime/Cargo.toml | 2 ++ bin/millau/runtime/src/lib.rs | 51 ++++++++++++++++++++--------------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7cf32bc2fd..f212f3ccd3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4638,6 +4638,7 @@ dependencies = [ "pallet-aura", "pallet-balances", "pallet-beefy", + "pallet-beefy-mmr", "pallet-bridge-dispatch", "pallet-bridge-grandpa", "pallet-bridge-messages", diff --git a/bin/millau/runtime/Cargo.toml b/bin/millau/runtime/Cargo.toml index c68f774843a..083fd15bc60 100644 --- a/bin/millau/runtime/Cargo.toml +++ b/bin/millau/runtime/Cargo.toml @@ -39,6 +39,7 @@ frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate" pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-beefy-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -83,6 +84,7 @@ std = [ "pallet-aura/std", "pallet-balances/std", "pallet-beefy/std", + "pallet-beefy-mmr/std", "pallet-bridge-dispatch/std", "pallet-bridge-grandpa/std", "pallet-bridge-messages/std", diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index a8446ce0358..3d201265577 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -34,7 +34,7 @@ pub mod rialto_messages; use crate::rialto_messages::{ToRialtoMessagePayload, WithRialtoMessageBridge}; -use beefy_primitives::{crypto::AuthorityId as BeefyId, ValidatorSet}; +use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet}; use bridge_runtime_common::messages::{ source::estimate_message_dispatch_and_delivery_fee, MessageBridge, }; @@ -247,30 +247,36 @@ impl pallet_grandpa::Config for Runtime { type MaxAuthorities = MaxAuthorities; } -type MmrHash = bp_millau::Hash; - -// TODO: use `pallet_beefy_mmr::DepositBeefyDigest` instead of `DepositLog` below. - -/// A BEEFY consensus digest item with MMR root hash. -pub struct DepositLog; -impl pallet_mmr::primitives::OnNewRoot for DepositLog { - fn on_new_root(root: &Hash) { - let digest = DigestItem::Consensus( - beefy_primitives::BEEFY_ENGINE_ID, - codec::Encode::encode(&beefy_primitives::ConsensusLog::::MmrRoot(*root)), - ); - >::deposit_log(digest); - } -} - -/// Configure Merkle Mountain Range pallet. impl pallet_mmr::Config for Runtime { const INDEXING_PREFIX: &'static [u8] = b"mmr"; - type Hashing = Hashing; - type Hash = Hash; - type OnNewRoot = DepositLog; + type Hashing = Keccak256; + type Hash = ::Output; + type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest; type WeightInfo = (); - type LeafData = frame_system::Pallet; + type LeafData = pallet_beefy_mmr::Pallet; +} + +parameter_types! { + /// Version of the produced MMR leaf. + /// + /// The version consists of two parts; + /// - `major` (3 bits) + /// - `minor` (5 bits) + /// + /// `major` should be updated only if decoding the previous MMR Leaf format from the payload + /// is not possible (i.e. backward incompatible change). + /// `minor` should be updated if fields are added to the previous MMR Leaf, which given SCALE + /// encoding does not prevent old leafs from being decoded. + /// + /// Hence we expect `major` to be changed really rarely (think never). + /// See [`MmrLeafVersion`] type documentation for more details. + pub LeafVersion: MmrLeafVersion = MmrLeafVersion::new(0, 0); +} + +impl pallet_beefy_mmr::Config for Runtime { + type LeafVersion = LeafVersion; + type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum; + type ParachainHeads = (); } parameter_types! { @@ -495,6 +501,7 @@ construct_runtime!( // Bridges support. Beefy: pallet_beefy::{Pallet, Storage, Config}, Mmr: pallet_mmr::{Pallet, Storage}, + MmrLeaf: pallet_beefy_mmr::{Pallet, Storage}, // Rialto bridge modules. BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage}, From 7d04195cdce088493a1acba33edf0c6c1e1a5eb7 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Thu, 25 Nov 2021 17:50:56 +0200 Subject: [PATCH 08/16] Add pallet_beefy_mmr to Rialto runtime --- Cargo.lock | 1 + bin/rialto/runtime/Cargo.toml | 2 ++ bin/rialto/runtime/src/lib.rs | 49 ++++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f212f3ccd3f..f00c4ed1656 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8368,6 +8368,7 @@ dependencies = [ "pallet-babe", "pallet-balances", "pallet-beefy", + "pallet-beefy-mmr", "pallet-bridge-dispatch", "pallet-bridge-grandpa", "pallet-bridge-messages", diff --git a/bin/rialto/runtime/Cargo.toml b/bin/rialto/runtime/Cargo.toml index af44f777156..ed5ee703aaf 100644 --- a/bin/rialto/runtime/Cargo.toml +++ b/bin/rialto/runtime/Cargo.toml @@ -41,6 +41,7 @@ pallet-authority-discovery = { git = "https://github.com/paritytech/substrate", pallet-babe = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-beefy-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -98,6 +99,7 @@ std = [ "pallet-babe/std", "pallet-balances/std", "pallet-beefy/std", + "pallet-beefy-mmr/std", "pallet-bridge-dispatch/std", "pallet-bridge-grandpa/std", "pallet-bridge-messages/std", diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index a0e383a9831..04e5cb9a5ab 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -35,7 +35,7 @@ pub mod parachains; use crate::millau_messages::{ToMillauMessagePayload, WithMillauMessageBridge}; -use beefy_primitives::{crypto::AuthorityId as BeefyId, ValidatorSet}; +use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet}; use bridge_runtime_common::messages::{ source::estimate_message_dispatch_and_delivery_fee, MessageBridge, }; @@ -276,30 +276,36 @@ impl pallet_grandpa::Config for Runtime { type WeightInfo = (); } -type MmrHash = ::Output; - -// TODO: use `pallet_beefy_mmr::DepositBeefyDigest` instead of `DepositLog` below. - -/// A BEEFY consensus digest item with MMR root hash. -pub struct DepositLog; -impl pallet_mmr::primitives::OnNewRoot for DepositLog { - fn on_new_root(root: &Hash) { - let digest = DigestItem::Consensus( - beefy_primitives::BEEFY_ENGINE_ID, - codec::Encode::encode(&beefy_primitives::ConsensusLog::::MmrRoot(*root)), - ); - >::deposit_log(digest); - } -} - -/// Configure Merkle Mountain Range pallet. impl pallet_mmr::Config for Runtime { const INDEXING_PREFIX: &'static [u8] = b"mmr"; type Hashing = Keccak256; - type Hash = MmrHash; - type OnNewRoot = DepositLog; + type Hash = ::Output; + type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest; type WeightInfo = (); - type LeafData = frame_system::Pallet; + type LeafData = pallet_beefy_mmr::Pallet; +} + +parameter_types! { + /// Version of the produced MMR leaf. + /// + /// The version consists of two parts; + /// - `major` (3 bits) + /// - `minor` (5 bits) + /// + /// `major` should be updated only if decoding the previous MMR Leaf format from the payload + /// is not possible (i.e. backward incompatible change). + /// `minor` should be updated if fields are added to the previous MMR Leaf, which given SCALE + /// encoding does not prevent old leafs from being decoded. + /// + /// Hence we expect `major` to be changed really rarely (think never). + /// See [`MmrLeafVersion`] type documentation for more details. + pub LeafVersion: MmrLeafVersion = MmrLeafVersion::new(0, 0); +} + +impl pallet_beefy_mmr::Config for Runtime { + type LeafVersion = LeafVersion; + type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum; + type ParachainHeads = (); } parameter_types! { @@ -498,6 +504,7 @@ construct_runtime!( // Bridges support. Beefy: pallet_beefy::{Pallet, Storage, Config}, Mmr: pallet_mmr::{Pallet, Storage}, + MmrLeaf: pallet_beefy_mmr::{Pallet, Storage}, // Millau bridge modules. BridgeMillauGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage}, From 7bf74bd51c68894dad18d37476b8c4e247625e9d Mon Sep 17 00:00:00 2001 From: acatangiu Date: Wed, 24 Nov 2021 20:05:17 +0200 Subject: [PATCH 09/16] Implement MMR and BEEFY APIs in Rialto --- Cargo.lock | 2 ++ bin/rialto/node/Cargo.toml | 1 + bin/rialto/node/src/service.rs | 9 ++++++--- bin/rialto/runtime/Cargo.toml | 2 ++ bin/rialto/runtime/src/lib.rs | 36 ++++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f00c4ed1656..06771d062ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8163,6 +8163,7 @@ dependencies = [ "lru 0.7.0", "node-inspect", "pallet-bridge-messages", + "pallet-mmr-primitives", "pallet-transaction-payment-rpc", "pallet-transaction-payment-rpc-runtime-api", "polkadot-approval-distribution", @@ -8374,6 +8375,7 @@ dependencies = [ "pallet-bridge-messages", "pallet-grandpa", "pallet-mmr", + "pallet-mmr-primitives", "pallet-session", "pallet-shift-session-manager", "pallet-sudo", diff --git a/bin/rialto/node/Cargo.toml b/bin/rialto/node/Cargo.toml index 15f3aadcee4..a2c6420c9fe 100644 --- a/bin/rialto/node/Cargo.toml +++ b/bin/rialto/node/Cargo.toml @@ -35,6 +35,7 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bin/rialto/node/src/service.rs b/bin/rialto/node/src/service.rs index 67e5201219b..f5f825e484a 100644 --- a/bin/rialto/node/src/service.rs +++ b/bin/rialto/node/src/service.rs @@ -117,8 +117,7 @@ type FullGrandpaLink = sc_finality_grandpa::LinkHalf + sp_api::ApiExt @@ -131,10 +130,12 @@ pub trait RequiredApiCollection: bp_rialto::AccountId, rialto_runtime::Index, > + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi + + pallet_mmr_primitives::MmrApi::Hash> + sp_api::Metadata + sp_offchain::OffchainWorkerApi + sp_session::SessionKeys + sp_authority_discovery::AuthorityDiscoveryApi + + beefy_primitives::BeefyApi where >::StateBackend: sp_api::StateBackend, { @@ -153,10 +154,12 @@ where bp_rialto::AccountId, rialto_runtime::Index, > + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi + + pallet_mmr_primitives::MmrApi::Hash> + sp_api::Metadata + sp_offchain::OffchainWorkerApi + sp_session::SessionKeys - + sp_authority_discovery::AuthorityDiscoveryApi, + + sp_authority_discovery::AuthorityDiscoveryApi + + beefy_primitives::BeefyApi, >::StateBackend: sp_api::StateBackend, { } diff --git a/bin/rialto/runtime/Cargo.toml b/bin/rialto/runtime/Cargo.toml index ed5ee703aaf..3c4ec1ebce1 100644 --- a/bin/rialto/runtime/Cargo.toml +++ b/bin/rialto/runtime/Cargo.toml @@ -44,6 +44,7 @@ pallet-beefy = { git = "https://github.com/paritytech/substrate", branch = "mast pallet-beefy-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -105,6 +106,7 @@ std = [ "pallet-bridge-messages/std", "pallet-grandpa/std", "pallet-mmr/std", + "pallet-mmr-primitives/std", "pallet-shift-session-manager/std", "pallet-sudo/std", "pallet-timestamp/std", diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index 04e5cb9a5ab..a2201c4a32b 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -42,6 +42,9 @@ use bridge_runtime_common::messages::{ use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; +use pallet_mmr_primitives::{ + DataOrHash, EncodableOpaqueLeaf, Error as MmrError, LeafDataProvider, Proof as MmrProof, +}; use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo}; use sp_api::impl_runtime_apis; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; @@ -621,6 +624,39 @@ impl_runtime_apis! { } } + impl pallet_mmr_primitives::MmrApi for Runtime { + fn generate_proof(leaf_index: u64) + -> Result<(EncodableOpaqueLeaf, MmrProof), MmrError> + { + Mmr::generate_proof(leaf_index) + .map(|(leaf, proof)| (EncodableOpaqueLeaf::from_leaf(&leaf), proof)) + } + + fn verify_proof(leaf: EncodableOpaqueLeaf, proof: MmrProof) + -> Result<(), MmrError> + { + pub type Leaf = < + ::LeafData as LeafDataProvider + >::LeafData; + + let leaf: Leaf = leaf + .into_opaque_leaf() + .try_decode() + .ok_or(MmrError::Verify)?; + Mmr::verify_leaf(leaf, proof) + } + + fn verify_proof_stateless( + root: Hash, + leaf: EncodableOpaqueLeaf, + proof: MmrProof + ) -> Result<(), MmrError> { + type MmrHashing = ::Hashing; + let node = DataOrHash::Data(leaf.into_opaque_leaf()); + pallet_mmr::verify_leaf_proof::(root, node, proof) + } + } + impl bp_millau::MillauFinalityApi for Runtime { fn best_finalized() -> (bp_millau::BlockNumber, bp_millau::Hash) { let header = BridgeMillauGrandpa::best_finalized(); From 5e046ea040482c13ebeea9702eac2a728c6d6488 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Thu, 25 Nov 2021 18:57:07 +0200 Subject: [PATCH 10/16] fix unit tests - should_encode_bridge_send_message_call() tests for new runtime encoding resulted from newly added pallets. - runtime size_of::() slightly increased from newly added pallets. --- bin/rialto/runtime/src/lib.rs | 2 +- relays/bin-substrate/src/cli/encode_call.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index a2201c4a32b..d73272c4577 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -1232,7 +1232,7 @@ mod tests { #[test] fn call_size() { - const MAX_CALL_SIZE: usize = 230; // value from polkadot-runtime tests + const MAX_CALL_SIZE: usize = 232; // slightly bigger than polkadot-runtime tests assert!(core::mem::size_of::() <= MAX_CALL_SIZE); } } diff --git a/relays/bin-substrate/src/cli/encode_call.rs b/relays/bin-substrate/src/cli/encode_call.rs index ca0e6dd8abf..e17854662e5 100644 --- a/relays/bin-substrate/src/cli/encode_call.rs +++ b/relays/bin-substrate/src/cli/encode_call.rs @@ -345,7 +345,7 @@ mod tests { // then assert!(format!("{:?}", call_hex).starts_with( - "0x0c030000000001000000381409000000000001d43593c715fdd31c61141abd04a99fd6822c8558854cc\ + "0x0f030000000001000000381409000000000001d43593c715fdd31c61141abd04a99fd6822c8558854cc\ de39a5684e7a56da27d01d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01" )) } From 28fa2d6c34e7ab34692b215e004a593a83c58ffe Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 30 Nov 2021 11:58:41 +0200 Subject: [PATCH 11/16] fix grumbles --- bin/millau/node/src/service.rs | 7 ++++--- bin/rialto/node/src/service.rs | 2 +- bin/rialto/runtime/src/lib.rs | 7 +++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/millau/node/src/service.rs b/bin/millau/node/src/service.rs index df1f731dbb2..fb94af40f49 100644 --- a/bin/millau/node/src/service.rs +++ b/bin/millau/node/src/service.rs @@ -21,9 +21,10 @@ // ===================================================================================== // UPDATE GUIDE: // 1) replace everything with node-template/src/service.rs contents (found in main Substrate repo); -// 2) the only thing to keep from old code, is `rpc_extensions_builder` - we use our own custom -// RPCs; 3) fix compilation errors; -// 4) test :) +// 2) from old code keep `rpc_extensions_builder` - we use our own custom RPCs; +// 3) from old code keep the Beefy gadget; +// 4) fix compilation errors; +// 5) test :) // ===================================================================================== // ===================================================================================== // ===================================================================================== diff --git a/bin/rialto/node/src/service.rs b/bin/rialto/node/src/service.rs index f5f825e484a..8f3b5a99e6e 100644 --- a/bin/rialto/node/src/service.rs +++ b/bin/rialto/node/src/service.rs @@ -17,7 +17,7 @@ //! Rialto chain node service. //! //! The code is mostly copy of `service/src/lib.rs` file from Polkadot repository -//! without optional functions. +//! without optional functions, and with BEEFY added on top. // this warning comes from Error enum (sc_cli::Error in particular) && it isn't easy to use box // there diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index d73272c4577..73a89e96748 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -1232,7 +1232,10 @@ mod tests { #[test] fn call_size() { - const MAX_CALL_SIZE: usize = 232; // slightly bigger than polkadot-runtime tests - assert!(core::mem::size_of::() <= MAX_CALL_SIZE); + const DOT_MAX_CALL_SZ: usize = 230; + assert!(core::mem::size_of::>() <= DOT_MAX_CALL_SZ); + // FIXME: get this down to 230. https://github.com/paritytech/grandpa-bridge-gadget/issues/359 + const BEEFY_MAX_CALL_SZ: usize = 232; + assert!(core::mem::size_of::>() <= BEEFY_MAX_CALL_SZ); } } From 42e52a2392ffd7341484b2e622daa4e6378b0a4f Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 30 Nov 2021 12:39:25 +0200 Subject: [PATCH 12/16] tighten clippy allowances --- bin/rialto/node/src/service.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bin/rialto/node/src/service.rs b/bin/rialto/node/src/service.rs index 8f3b5a99e6e..135ac7976cc 100644 --- a/bin/rialto/node/src/service.rs +++ b/bin/rialto/node/src/service.rs @@ -19,12 +19,6 @@ //! The code is mostly copy of `service/src/lib.rs` file from Polkadot repository //! without optional functions, and with BEEFY added on top. -// this warning comes from Error enum (sc_cli::Error in particular) && it isn't easy to use box -// there -#![allow(clippy::large_enum_variant)] -// this warning comes from `sc_service::PartialComponents` type -#![allow(clippy::type_complexity)] - use crate::overseer::{OverseerGen, OverseerGenArgs}; use polkadot_node_core_approval_voting::Config as ApprovalVotingConfig; @@ -173,6 +167,8 @@ fn set_prometheus_registry(config: &mut Configuration) -> Result<(), Error> { Ok(()) } +// Needed here for complex return type while `impl Trait` in type aliases is unstable. +#[allow(clippy::type_complexity)] pub fn new_partial( config: &mut Configuration, ) -> Result< From afcb21846addc90edf7d3fdcdac7973bdb15a24f Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 30 Nov 2021 13:31:16 +0200 Subject: [PATCH 13/16] fix more grumbles --- bin/millau/node/Cargo.toml | 2 +- bin/millau/runtime/src/lib.rs | 2 +- bin/rialto/node/Cargo.toml | 2 +- bin/rialto/node/src/service.rs | 2 +- bin/rialto/runtime/src/lib.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/millau/node/Cargo.toml b/bin/millau/node/Cargo.toml index c16adba4fd5..7846292b96e 100644 --- a/bin/millau/node/Cargo.toml +++ b/bin/millau/node/Cargo.toml @@ -23,9 +23,9 @@ pallet-bridge-messages = { path = "../../../modules/messages" } # Substrate Dependencies -beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } beefy-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" } beefy-gadget-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } +beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index 3d201265577..1d983b21374 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -498,7 +498,7 @@ construct_runtime!( ShiftSessionManager: pallet_shift_session_manager::{Pallet}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, - // Bridges support. + // BEEFY Bridges support. Beefy: pallet_beefy::{Pallet, Storage, Config}, Mmr: pallet_mmr::{Pallet, Storage}, MmrLeaf: pallet_beefy_mmr::{Pallet, Storage}, diff --git a/bin/rialto/node/Cargo.toml b/bin/rialto/node/Cargo.toml index a2c6420c9fe..3178e09ff04 100644 --- a/bin/rialto/node/Cargo.toml +++ b/bin/rialto/node/Cargo.toml @@ -28,9 +28,9 @@ rialto-runtime = { path = "../runtime" } # Substrate Dependencies -beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } beefy-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" } beefy-gadget-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } +beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bin/rialto/node/src/service.rs b/bin/rialto/node/src/service.rs index 135ac7976cc..0731d02056d 100644 --- a/bin/rialto/node/src/service.rs +++ b/bin/rialto/node/src/service.rs @@ -734,7 +734,7 @@ where key_store: keystore_opt.clone(), network: network.clone(), signed_commitment_sender, - min_block_delta: 4, + min_block_delta: 2, prometheus_registry: prometheus_registry.clone(), }; diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index 73a89e96748..0987184c73a 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -504,7 +504,7 @@ construct_runtime!( Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, ShiftSessionManager: pallet_shift_session_manager::{Pallet}, - // Bridges support. + // BEEFY Bridges support. Beefy: pallet_beefy::{Pallet, Storage, Config}, Mmr: pallet_mmr::{Pallet, Storage}, MmrLeaf: pallet_beefy_mmr::{Pallet, Storage}, From d7b8c21e4bcd7f36a1e40fcd057fb013d33b042e Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 30 Nov 2021 15:52:48 +0200 Subject: [PATCH 14/16] Add MMR RPC to Rialto and Millau nodes Also implement MmrApi in Millau runtime. --- Cargo.lock | 3 +++ bin/millau/node/Cargo.toml | 1 + bin/millau/node/src/service.rs | 3 +++ bin/millau/runtime/Cargo.toml | 1 + bin/millau/runtime/src/lib.rs | 40 +++++++++++++++++++++++++++++++++- bin/rialto/node/Cargo.toml | 1 + bin/rialto/node/src/service.rs | 5 ++++- 7 files changed, 52 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06771d062ca..53d260fc8ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4591,6 +4591,7 @@ dependencies = [ "millau-runtime", "node-inspect", "pallet-bridge-messages", + "pallet-mmr-rpc", "pallet-transaction-payment-rpc", "sc-basic-authorship", "sc-cli", @@ -4645,6 +4646,7 @@ dependencies = [ "pallet-bridge-token-swap", "pallet-grandpa", "pallet-mmr", + "pallet-mmr-primitives", "pallet-randomness-collective-flip", "pallet-session", "pallet-shift-session-manager", @@ -8164,6 +8166,7 @@ dependencies = [ "node-inspect", "pallet-bridge-messages", "pallet-mmr-primitives", + "pallet-mmr-rpc", "pallet-transaction-payment-rpc", "pallet-transaction-payment-rpc-runtime-api", "polkadot-approval-distribution", diff --git a/bin/millau/node/Cargo.toml b/bin/millau/node/Cargo.toml index 7846292b96e..c4438d0cef3 100644 --- a/bin/millau/node/Cargo.toml +++ b/bin/millau/node/Cargo.toml @@ -29,6 +29,7 @@ beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = " frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-mmr-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] } diff --git a/bin/millau/node/src/service.rs b/bin/millau/node/src/service.rs index fb94af40f49..3fd0f02ed4e 100644 --- a/bin/millau/node/src/service.rs +++ b/bin/millau/node/src/service.rs @@ -291,6 +291,9 @@ pub fn new_full(mut config: Configuration) -> Result subscription_executor, ), )); + io.extend_with(pallet_mmr_rpc::MmrApi::to_delegate(pallet_mmr_rpc::Mmr::new( + client.clone(), + ))); Ok(io) }) }; diff --git a/bin/millau/runtime/Cargo.toml b/bin/millau/runtime/Cargo.toml index 083fd15bc60..13195b95194 100644 --- a/bin/millau/runtime/Cargo.toml +++ b/bin/millau/runtime/Cargo.toml @@ -42,6 +42,7 @@ pallet-beefy = { git = "https://github.com/paritytech/substrate", branch = "mast pallet-beefy-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index 1d983b21374..288ff9a47d6 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -41,6 +41,9 @@ use bridge_runtime_common::messages::{ use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; +use pallet_mmr_primitives::{ + DataOrHash, EncodableOpaqueLeaf, Error as MmrError, LeafDataProvider, Proof as MmrProof, +}; use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo}; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -247,10 +250,12 @@ impl pallet_grandpa::Config for Runtime { type MaxAuthorities = MaxAuthorities; } +type MmrHash = ::Output; + impl pallet_mmr::Config for Runtime { const INDEXING_PREFIX: &'static [u8] = b"mmr"; type Hashing = Keccak256; - type Hash = ::Output; + type Hash = MmrHash; type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest; type WeightInfo = (); type LeafData = pallet_beefy_mmr::Pallet; @@ -653,6 +658,39 @@ impl_runtime_apis! { } } + impl pallet_mmr_primitives::MmrApi for Runtime { + fn generate_proof(leaf_index: u64) + -> Result<(EncodableOpaqueLeaf, MmrProof), MmrError> + { + Mmr::generate_proof(leaf_index) + .map(|(leaf, proof)| (EncodableOpaqueLeaf::from_leaf(&leaf), proof)) + } + + fn verify_proof(leaf: EncodableOpaqueLeaf, proof: MmrProof) + -> Result<(), MmrError> + { + pub type Leaf = < + ::LeafData as LeafDataProvider + >::LeafData; + + let leaf: Leaf = leaf + .into_opaque_leaf() + .try_decode() + .ok_or(MmrError::Verify)?; + Mmr::verify_leaf(leaf, proof) + } + + fn verify_proof_stateless( + root: MmrHash, + leaf: EncodableOpaqueLeaf, + proof: MmrProof + ) -> Result<(), MmrError> { + type MmrHashing = ::Hashing; + let node = DataOrHash::Data(leaf.into_opaque_leaf()); + pallet_mmr::verify_leaf_proof::(root, node, proof) + } + } + impl fg_primitives::GrandpaApi for Runtime { fn current_set_id() -> fg_primitives::SetId { Grandpa::current_set_id() diff --git a/bin/rialto/node/Cargo.toml b/bin/rialto/node/Cargo.toml index 3178e09ff04..e6ce3ae99c6 100644 --- a/bin/rialto/node/Cargo.toml +++ b/bin/rialto/node/Cargo.toml @@ -36,6 +36,7 @@ frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", bran frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-mmr-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bin/rialto/node/src/service.rs b/bin/rialto/node/src/service.rs index 0731d02056d..df39abf4d44 100644 --- a/bin/rialto/node/src/service.rs +++ b/bin/rialto/node/src/service.rs @@ -323,7 +323,9 @@ where pool, deny_unsafe, ))); - io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client))); + io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new( + client.clone(), + ))); io.extend_with(GrandpaApi::to_delegate(GrandpaRpcHandler::new( shared_authority_set.clone(), shared_voter_state, @@ -337,6 +339,7 @@ where subscription_executor, ), )); + io.extend_with(pallet_mmr_rpc::MmrApi::to_delegate(pallet_mmr_rpc::Mmr::new(client))); Ok(io) } From 5333f9b5ca7709b18de8e194469a268d408ed313 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 30 Nov 2021 16:44:50 +0200 Subject: [PATCH 15/16] rialto: use upstream polkadot_client::RuntimeApiCollection --- Cargo.lock | 1 + bin/rialto/node/Cargo.toml | 4 +++ bin/rialto/node/src/service.rs | 58 +++------------------------------- 3 files changed, 10 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53d260fc8ff..8db4fe90d8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8173,6 +8173,7 @@ dependencies = [ "polkadot-availability-bitfield-distribution", "polkadot-availability-distribution", "polkadot-availability-recovery", + "polkadot-client", "polkadot-collator-protocol", "polkadot-dispute-distribution", "polkadot-gossip-support", diff --git a/bin/rialto/node/Cargo.toml b/bin/rialto/node/Cargo.toml index e6ce3ae99c6..2795f2eecae 100644 --- a/bin/rialto/node/Cargo.toml +++ b/bin/rialto/node/Cargo.toml @@ -75,6 +75,10 @@ sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "mast substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "master" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" } +# Polkadot Dependencies + +polkadot-client = { git = "https://github.com/paritytech/polkadot", branch = "master" } + # Polkadot (parachain) Dependencies polkadot-approval-distribution = { git = "https://github.com/paritytech/polkadot", branch = "master" } diff --git a/bin/rialto/node/src/service.rs b/bin/rialto/node/src/service.rs index df39abf4d44..915b00334da 100644 --- a/bin/rialto/node/src/service.rs +++ b/bin/rialto/node/src/service.rs @@ -21,6 +21,7 @@ use crate::overseer::{OverseerGen, OverseerGenArgs}; +use polkadot_client::RuntimeApiCollection; use polkadot_node_core_approval_voting::Config as ApprovalVotingConfig; use polkadot_node_core_av_store::Config as AvailabilityConfig; use polkadot_node_core_candidate_validation::Config as CandidateValidationConfig; @@ -37,7 +38,7 @@ use sc_service::{config::PrometheusConfig, Configuration, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; use sp_api::{ConstructRuntimeApi, HeaderT}; use sp_consensus::SelectChain; -use sp_runtime::traits::{BlakeTwo256, Block as BlockT}; +use sp_runtime::traits::Block as BlockT; use std::{sync::Arc, time::Duration}; use substrate_prometheus_endpoint::Registry; @@ -109,55 +110,6 @@ type FullBabeBlockImport = type FullBabeLink = sc_consensus_babe::BabeLink; type FullGrandpaLink = sc_finality_grandpa::LinkHalf; -/// A set of APIs that polkadot-like runtimes must implement. -/// -/// This is a copy of `polkadot_service::RuntimeApiCollection`. -pub trait RequiredApiCollection: - sp_transaction_pool::runtime_api::TaggedTransactionQueue - + sp_api::ApiExt - + sp_consensus_babe::BabeApi - + sp_finality_grandpa::GrandpaApi - + polkadot_primitives::v1::ParachainHost - + sp_block_builder::BlockBuilder - + frame_system_rpc_runtime_api::AccountNonceApi< - Block, - bp_rialto::AccountId, - rialto_runtime::Index, - > + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi - + pallet_mmr_primitives::MmrApi::Hash> - + sp_api::Metadata - + sp_offchain::OffchainWorkerApi - + sp_session::SessionKeys - + sp_authority_discovery::AuthorityDiscoveryApi - + beefy_primitives::BeefyApi -where - >::StateBackend: sp_api::StateBackend, -{ -} - -impl RequiredApiCollection for Api -where - Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue - + sp_api::ApiExt - + sp_consensus_babe::BabeApi - + sp_finality_grandpa::GrandpaApi - + polkadot_primitives::v1::ParachainHost - + sp_block_builder::BlockBuilder - + frame_system_rpc_runtime_api::AccountNonceApi< - Block, - bp_rialto::AccountId, - rialto_runtime::Index, - > + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi - + pallet_mmr_primitives::MmrApi::Hash> - + sp_api::Metadata - + sp_offchain::OffchainWorkerApi - + sp_session::SessionKeys - + sp_authority_discovery::AuthorityDiscoveryApi - + beefy_primitives::BeefyApi, - >::StateBackend: sp_api::StateBackend, -{ -} - // If we're using prometheus, use a registry with a prefix of `polkadot`. fn set_prometheus_registry(config: &mut Configuration) -> Result<(), Error> { if let Some(PrometheusConfig { registry, .. }) = config.prometheus_config.as_mut() { @@ -199,7 +151,7 @@ pub fn new_partial( where RuntimeApi: ConstructRuntimeApi + Send + Sync + 'static, >::RuntimeApi: - RequiredApiCollection>, + RuntimeApiCollection>, ExecutorDispatch: NativeExecutionDispatch + 'static, { set_prometheus_registry(config)?; @@ -377,7 +329,7 @@ async fn active_leaves( where RuntimeApi: ConstructRuntimeApi + Send + Sync + 'static, >::RuntimeApi: - RequiredApiCollection>, + RuntimeApiCollection>, ExecutorDispatch: NativeExecutionDispatch + 'static, { let best_block = select_chain.best_chain().await?; @@ -422,7 +374,7 @@ pub fn new_full( where RuntimeApi: ConstructRuntimeApi + Send + Sync + 'static, >::RuntimeApi: - RequiredApiCollection>, + RuntimeApiCollection>, ExecutorDispatch: NativeExecutionDispatch + 'static, { let is_collator = false; From b2d8e5a369212904c1aba0a081eade60bd470944 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 30 Nov 2021 17:39:10 +0200 Subject: [PATCH 16/16] fix after rebase Signed-off-by: acatangiu --- bin/millau/node/src/service.rs | 1 + bin/rialto/node/src/service.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/bin/millau/node/src/service.rs b/bin/millau/node/src/service.rs index 3fd0f02ed4e..b01c0bfca90 100644 --- a/bin/millau/node/src/service.rs +++ b/bin/millau/node/src/service.rs @@ -381,6 +381,7 @@ pub fn new_full(mut config: Configuration) -> Result // Start the BEEFY bridge gadget. task_manager.spawn_essential_handle().spawn_blocking( "beefy-gadget", + None, beefy_gadget::start_beefy_gadget::<_, _, _, _>(beefy_params), ); diff --git a/bin/rialto/node/src/service.rs b/bin/rialto/node/src/service.rs index 915b00334da..3349b09edb9 100644 --- a/bin/rialto/node/src/service.rs +++ b/bin/rialto/node/src/service.rs @@ -696,6 +696,7 @@ where // Start the BEEFY bridge gadget. task_manager.spawn_essential_handle().spawn_blocking( "beefy-gadget", + None, beefy_gadget::start_beefy_gadget::<_, _, _, _>(beefy_params), );