diff --git a/bridges/bin/millau/node/Cargo.toml b/bridges/bin/millau/node/Cargo.toml index 28bd9ed0564fc..e83f3c4f564c7 100644 --- a/bridges/bin/millau/node/Cargo.toml +++ b/bridges/bin/millau/node/Cargo.toml @@ -10,7 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] clap = { version = "3.1", features = ["derive"] } -jsonrpc-core = "18.0" +jsonrpsee = { version = "0.15.1", features = ["server"] } serde_json = "1.0.79" # Bridge dependencies diff --git a/bridges/bin/millau/node/src/service.rs b/bridges/bin/millau/node/src/service.rs index 5ac5917f16583..5b4461f3ca642 100644 --- a/bridges/bin/millau/node/src/service.rs +++ b/bridges/bin/millau/node/src/service.rs @@ -16,19 +16,7 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. -// ===================================================================================== -// ===================================================================================== -// ===================================================================================== -// UPDATE GUIDE: -// 1) replace everything with node-template/src/service.rs contents (found in main Substrate repo); -// 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 :) -// ===================================================================================== -// ===================================================================================== -// ===================================================================================== - +use jsonrpsee::RpcModule; use millau_runtime::{self, opaque::Block, RuntimeApi}; use sc_client_api::{BlockBackend, ExecutorProvider}; use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; @@ -83,6 +71,8 @@ pub fn new_partial( FullSelectChain, >, sc_finality_grandpa::LinkHalf, + beefy_gadget::BeefyVoterLinks, + beefy_gadget::BeefyRPCLinks, Option, ), >, @@ -140,11 +130,18 @@ pub fn new_partial( telemetry.as_ref().map(|x| x.handle()), )?; + let (beefy_block_import, beefy_voter_links, beefy_rpc_links) = + beefy_gadget::beefy_block_import_and_links( + grandpa_block_import.clone(), + backend.clone(), + client.clone(), + ); + let slot_duration = sc_consensus_aura::slot_duration(&*client)?; let import_queue = sc_consensus_aura::import_queue::(ImportQueueParams { - block_import: grandpa_block_import.clone(), + block_import: beefy_block_import, justification_import: Some(Box::new(grandpa_block_import.clone())), client: client.clone(), create_inherent_data_providers: move |_, ()| async move { @@ -175,7 +172,7 @@ pub fn new_partial( keystore_container, select_chain, transaction_pool, - other: (grandpa_block_import, grandpa_link, telemetry), + other: (grandpa_block_import, grandpa_link, beefy_voter_links, beefy_rpc_links, telemetry), }) } @@ -196,7 +193,7 @@ pub fn new_full(mut config: Configuration) -> Result mut keystore_container, select_chain, transaction_pool, - other: (block_import, grandpa_link, mut telemetry), + other: (block_import, grandpa_link, beefy_voter_links, beefy_rpc_links, mut telemetry), } = new_partial(&config)?; if let Some(url) = &config.keystore_remote { @@ -264,18 +261,16 @@ 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 (beefy_commitment_link, beefy_commitment_stream) = - beefy_gadget::notification::BeefySignedCommitmentStream::::channel(); - let (beefy_best_block_link, beefy_best_block_stream) = - beefy_gadget::notification::BeefyBestBlockStream::::channel(); let rpc_extensions_builder = { use sc_finality_grandpa::FinalityProofProvider as GrandpaFinalityProofProvider; - use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; - use sc_finality_grandpa_rpc::{GrandpaApi, GrandpaRpcHandler}; + use beefy_gadget_rpc::{Beefy, BeefyApiServer}; + use pallet_mmr_rpc::{Mmr, MmrApiServer}; + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; + use sc_finality_grandpa_rpc::{Grandpa, GrandpaApiServer}; use sc_rpc::DenyUnsafe; - use substrate_frame_rpc_system::{FullSystem, SystemApi}; + use substrate_frame_rpc_system::{System, SystemApiServer}; let backend = backend.clone(); let client = client.clone(); @@ -291,33 +286,33 @@ pub fn new_full(mut config: Configuration) -> Result ); 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(), - pool.clone(), - DenyUnsafe::No, - ))); - 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.clone(), - justification_stream.clone(), - subscription_executor.clone(), - finality_proof_provider.clone(), - ))); - io.extend_with(beefy_gadget_rpc::BeefyApi::to_delegate( - beefy_gadget_rpc::BeefyRpcHandler::::new( - beefy_commitment_stream.clone(), - beefy_best_block_stream.clone(), + let mut io = RpcModule::new(()); + let map_err = |e| sc_service::Error::Other(format!("{}", e)); + io.merge(System::new(client.clone(), pool.clone(), DenyUnsafe::No).into_rpc()) + .map_err(map_err)?; + io.merge(TransactionPayment::new(client.clone()).into_rpc()).map_err(map_err)?; + io.merge( + Grandpa::new( + subscription_executor.clone(), + shared_authority_set.clone(), + shared_voter_state.clone(), + justification_stream.clone(), + finality_proof_provider.clone(), + ) + .into_rpc(), + ) + .map_err(map_err)?; + io.merge( + Beefy::::new( + beefy_rpc_links.from_voter_justif_stream.clone(), + beefy_rpc_links.from_voter_best_beefy_stream.clone(), subscription_executor, ) - .map_err(|e| sc_service::Error::Other(format!("{}", e)))?, - )); - io.extend_with(pallet_mmr_rpc::MmrApi::to_delegate(pallet_mmr_rpc::Mmr::new( - client.clone(), - ))); + .map_err(|e| sc_service::Error::Other(format!("{}", e)))? + .into_rpc(), + ) + .map_err(map_err)?; + io.merge(Mmr::new(client.clone()).into_rpc()).map_err(map_err)?; Ok(io) }) }; @@ -328,7 +323,7 @@ pub fn new_full(mut config: Configuration) -> Result keystore: keystore_container.sync_keystore(), task_manager: &mut task_manager, transaction_pool: transaction_pool.clone(), - rpc_extensions_builder, + rpc_builder: rpc_extensions_builder.clone(), backend: backend.clone(), system_rpc_tx, config, @@ -397,11 +392,10 @@ pub fn new_full(mut config: Configuration) -> Result runtime: client, key_store: keystore.clone(), network: network.clone(), - signed_commitment_sender: beefy_commitment_link, - beefy_best_block_sender: beefy_best_block_link, min_block_delta: 2, prometheus_registry: prometheus_registry.clone(), protocol_name: beefy_protocol_name, + links: beefy_voter_links, }; // Start the BEEFY bridge gadget. diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index 59f2a08177c62..66f454a0ecc9e 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -52,9 +52,7 @@ use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo}; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; -use sp_mmr_primitives::{ - DataOrHash, EncodableOpaqueLeaf, Error as MmrError, LeafDataProvider, Proof as MmrProof, -}; +use sp_mmr_primitives::{DataOrHash, EncodableOpaqueLeaf, Error as MmrError, Proof as MmrProof}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys}, @@ -238,6 +236,8 @@ impl pallet_aura::Config for Runtime { impl pallet_beefy::Config for Runtime { type BeefyId = BeefyId; + type MaxAuthorities = MaxAuthorities; + type OnNewValidatorSet = MmrLeaf; } impl pallet_grandpa::Config for Runtime { @@ -256,12 +256,21 @@ impl pallet_grandpa::Config for Runtime { type MaxAuthorities = MaxAuthorities; } -type MmrHash = ::Output; +/// MMR helper types. +mod mmr { + use super::Runtime; + pub use pallet_mmr::primitives::*; + use sp_runtime::traits::Keccak256; + + pub type Leaf = <::LeafData as LeafDataProvider>::LeafData; + pub type Hash = ::Output; + pub type Hashing = ::Hashing; +} impl pallet_mmr::Config for Runtime { const INDEXING_PREFIX: &'static [u8] = b"mmr"; type Hashing = Keccak256; - type Hash = MmrHash; + type Hash = mmr::Hash; type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest; type WeightInfo = (); type LeafData = pallet_beefy_mmr::Pallet; @@ -355,6 +364,7 @@ impl pallet_transaction_payment::Config for Runtime { AdjustmentVariable, MinimumMultiplier, >; + type Event = Event; } impl pallet_sudo::Config for Runtime { @@ -562,7 +572,7 @@ construct_runtime!( Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - TransactionPayment: pallet_transaction_payment::{Pallet, Storage}, + TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event}, // Consensus support. Session: pallet_session::{Pallet, Call, Storage, Event, Config}, @@ -744,41 +754,69 @@ impl_runtime_apis! { } } - impl sp_mmr_primitives::MmrApi for Runtime { + impl sp_mmr_primitives::MmrApi for Runtime { fn generate_proof(leaf_index: u64) - -> Result<(EncodableOpaqueLeaf, MmrProof), MmrError> + -> Result<(EncodableOpaqueLeaf, MmrProof), MmrError> { - Mmr::generate_proof(leaf_index) - .map(|(leaf, proof)| (EncodableOpaqueLeaf::from_leaf(&leaf), proof)) + Mmr::generate_batch_proof(vec![leaf_index]) + .and_then(|(leaves, proof)| Ok(( + mmr::EncodableOpaqueLeaf::from_leaf(&leaves[0]), + mmr::BatchProof::into_single_leaf_proof(proof)? + ))) } - fn verify_proof(leaf: EncodableOpaqueLeaf, proof: MmrProof) + fn verify_proof(leaf: EncodableOpaqueLeaf, proof: MmrProof) -> Result<(), MmrError> { - pub type Leaf = < - ::LeafData as LeafDataProvider - >::LeafData; - - let leaf: Leaf = leaf + let leaf: mmr::Leaf = leaf .into_opaque_leaf() .try_decode() .ok_or(MmrError::Verify)?; - Mmr::verify_leaf(leaf, proof) + Mmr::verify_leaves(vec![leaf], mmr::Proof::into_batch_proof(proof)) } fn verify_proof_stateless( - root: MmrHash, + root: mmr::Hash, leaf: EncodableOpaqueLeaf, - proof: MmrProof + proof: MmrProof ) -> Result<(), MmrError> { - type MmrHashing = ::Hashing; let node = DataOrHash::Data(leaf.into_opaque_leaf()); - pallet_mmr::verify_leaf_proof::(root, node, proof) + pallet_mmr::verify_leaves_proof::( + root, + vec![node], + pallet_mmr::primitives::Proof::into_batch_proof(proof), + ) } - fn mmr_root() -> Result { + fn mmr_root() -> Result { Ok(Mmr::mmr_root()) } + + fn generate_batch_proof(leaf_indices: Vec) + -> Result<(Vec, mmr::BatchProof), mmr::Error> + { + Mmr::generate_batch_proof(leaf_indices) + .map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof)) + } + + fn verify_batch_proof(leaves: Vec, proof: mmr::BatchProof) + -> Result<(), mmr::Error> + { + let leaves = leaves.into_iter().map(|leaf| + leaf.into_opaque_leaf() + .try_decode() + .ok_or(mmr::Error::Verify)).collect::, mmr::Error>>()?; + Mmr::verify_leaves(leaves, proof) + } + + fn verify_batch_proof_stateless( + root: mmr::Hash, + leaves: Vec, + proof: mmr::BatchProof + ) -> Result<(), mmr::Error> { + let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect(); + pallet_mmr::verify_leaves_proof::(root, nodes, proof) + } } impl fg_primitives::GrandpaApi for Runtime { diff --git a/bridges/bin/millau/runtime/src/xcm_config.rs b/bridges/bin/millau/runtime/src/xcm_config.rs index 57f28e1404444..88398345d4ad0 100644 --- a/bridges/bin/millau/runtime/src/xcm_config.rs +++ b/bridges/bin/millau/runtime/src/xcm_config.rs @@ -156,6 +156,7 @@ impl xcm_executor::Config for XcmConfig { type FeeManager = (); type MessageExporter = (); type UniversalAliases = Nothing; + type CallDispatcher = Call; } /// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior @@ -270,7 +271,7 @@ mod tests { fn xcm_messages_are_sent_using_bridge_router() { new_test_ext().execute_with(|| { let xcm: Xcm<()> = vec![Instruction::Trap(42)].into(); - let expected_fee = MultiAssets::from((Here, 4_345_002_552_u64)); + let expected_fee = MultiAssets::from((Here, 4_259_858_152_u64)); let expected_hash = ([0u8, 0u8, 0u8, 0u8], 1u64).using_encoded(sp_io::hashing::blake2_256); diff --git a/bridges/bin/rialto-parachain/node/Cargo.toml b/bridges/bin/rialto-parachain/node/Cargo.toml index 75a7297f3f099..109be667c4cd3 100644 --- a/bridges/bin/rialto-parachain/node/Cargo.toml +++ b/bridges/bin/rialto-parachain/node/Cargo.toml @@ -30,7 +30,7 @@ bp-rialto-parachain = { path = "../../../primitives/chain-rialto-parachain" } pallet-bridge-messages = { path = "../../../modules/messages" } # RPC related Dependencies -jsonrpc-core = '18.0' +jsonrpsee = { version = "0.15.1", features = ["server"] } # Local Dependencies rialto-parachain-runtime = { path = '../runtime' } diff --git a/bridges/bin/rialto-parachain/node/src/cli.rs b/bridges/bin/rialto-parachain/node/src/cli.rs index daf6739daa3ff..bd45db9758cba 100644 --- a/bridges/bin/rialto-parachain/node/src/cli.rs +++ b/bridges/bin/rialto-parachain/node/src/cli.rs @@ -59,7 +59,7 @@ pub enum Subcommand { #[derive(Debug, Parser)] pub struct ExportGenesisStateCommand { /// Output file name or stdout if unspecified. - #[clap(parse(from_os_str))] + #[clap(action)] pub output: Option, /// Id of the parachain this state is for. @@ -81,7 +81,7 @@ pub struct ExportGenesisStateCommand { #[derive(Debug, Parser)] pub struct ExportGenesisWasmCommand { /// Output file name or stdout if unspecified. - #[clap(parse(from_os_str))] + #[clap(action)] pub output: Option, /// Write output in binary. Default is to write in hex. diff --git a/bridges/bin/rialto-parachain/node/src/command.rs b/bridges/bin/rialto-parachain/node/src/command.rs index 20278b5767e41..6afae824a74ce 100644 --- a/bridges/bin/rialto-parachain/node/src/command.rs +++ b/bridges/bin/rialto-parachain/node/src/command.rs @@ -20,11 +20,10 @@ use crate::{ service::{new_partial, ParachainRuntimeExecutor}, }; use codec::Encode; -use cumulus_client_service::genesis::generate_genesis_block; +use cumulus_client_cli::generate_genesis_block; use cumulus_primitives_core::ParaId; use frame_benchmarking_cli::BenchmarkCmd; use log::info; -use polkadot_parachain::primitives::AccountIdConversion; use rialto_parachain_runtime::{Block, RuntimeApi}; use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, @@ -32,7 +31,7 @@ use sc_cli::{ }; use sc_service::config::{BasePath, PrometheusConfig}; use sp_core::hexdisplay::HexDisplay; -use sp_runtime::traits::Block as BlockT; +use sp_runtime::traits::{AccountIdConversion, Block as BlockT}; use std::{io::Write, net::SocketAddr}; fn load_spec( @@ -219,7 +218,7 @@ pub fn run() -> Result<()> { params.parachain_id.expect("Missing ParaId").into(), )?; let state_version = Cli::native_runtime_version(&spec).state_version(); - let block: Block = generate_genesis_block(&spec, state_version)?; + let block: Block = generate_genesis_block(&*spec, state_version)?; let raw_header = block.header().encode(); let output_buf = if params.raw { raw_header @@ -288,11 +287,11 @@ pub fn run() -> Result<()> { let id = ParaId::from(cli.parachain_id.or(para_id).expect("Missing ParaId")); let parachain_account = - AccountIdConversion::::into_account(&id); + AccountIdConversion::::into_account_truncating(&id); let state_version = RelayChainCli::native_runtime_version(&config.chain_spec).state_version(); - let block: Block = generate_genesis_block(&config.chain_spec, state_version) + let block: Block = generate_genesis_block(&*config.chain_spec, state_version) .map_err(|e| format!("{:?}", e))?; let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode())); @@ -402,12 +401,8 @@ impl CliConfiguration for RelayChainCli { self.base.base.role(is_dev) } - fn transaction_pool(&self) -> Result { - self.base.base.transaction_pool() - } - - fn state_cache_child_ratio(&self) -> Result> { - self.base.base.state_cache_child_ratio() + fn transaction_pool(&self, is_dev: bool) -> Result { + self.base.base.transaction_pool(is_dev) } fn rpc_methods(&self) -> Result { diff --git a/bridges/bin/rialto-parachain/node/src/service.rs b/bridges/bin/rialto-parachain/node/src/service.rs index a2299e17457d9..e55f89bacf70a 100644 --- a/bridges/bin/rialto-parachain/node/src/service.rs +++ b/bridges/bin/rialto-parachain/node/src/service.rs @@ -42,8 +42,8 @@ use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface}; // Substrate Imports use sc_client_api::ExecutorProvider; use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch}; -use sc_network::NetworkService; -use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager}; +use sc_network::{NetworkBlock, NetworkService}; +use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; use sp_api::ConstructRuntimeApi; use sp_keystore::SyncCryptoStorePtr; @@ -229,8 +229,9 @@ where TFullClient>, >, >, - ) -> jsonrpc_core::IoHandler + ) -> Result, sc_service::Error> + Send + + Clone + 'static, BIQ: FnOnce( Arc>>, @@ -261,10 +262,6 @@ where bool, ) -> Result>, sc_service::Error>, { - if matches!(parachain_config.role, Role::Light) { - return Err("Light client not supported!".into()) - } - let parachain_config = prepare_node_config(parachain_config); let params = new_partial::(¶chain_config, build_import_queue)?; @@ -276,6 +273,7 @@ where ¶chain_config, telemetry_worker_handle, &mut task_manager, + None, ) .map_err(|e| match e { RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x, @@ -307,11 +305,11 @@ where let rpc_client = client.clone(); let rpc_transaction_pool = transaction_pool.clone(); let rpc_extensions_builder = Box::new(move |deny_unsafe, _| { - Ok(rpc_ext_builder(deny_unsafe, rpc_client.clone(), rpc_transaction_pool.clone())) + rpc_ext_builder(deny_unsafe, rpc_client.clone(), rpc_transaction_pool.clone()) }); sc_service::spawn_tasks(sc_service::SpawnTasksParams { - rpc_extensions_builder, + rpc_builder: rpc_extensions_builder.clone(), client: client.clone(), transaction_pool: transaction_pool.clone(), task_manager: &mut task_manager, @@ -441,18 +439,17 @@ pub async fn start_node( polkadot_config, collator_options, id, - |deny_unsafe, client, pool| { - use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; - use substrate_frame_rpc_system::{FullSystem, SystemApi}; - - let mut io = jsonrpc_core::IoHandler::default(); - io.extend_with(SystemApi::to_delegate(FullSystem::new( - client.clone(), - pool, - deny_unsafe, - ))); - io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client))); - io + |_deny_unsafe, client, pool| { + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; + use sc_rpc::DenyUnsafe; + use substrate_frame_rpc_system::{System, SystemApiServer}; + + let mut io = jsonrpsee::RpcModule::new(()); + let map_err = |e| sc_service::Error::Other(format!("{}", e)); + io.merge(System::new(client.clone(), pool, DenyUnsafe::No).into_rpc()) + .map_err(map_err)?; + io.merge(TransactionPayment::new(client).into_rpc()).map_err(map_err)?; + Ok(io) }, parachain_build_import_queue, |client, diff --git a/bridges/bin/rialto-parachain/runtime/src/lib.rs b/bridges/bin/rialto-parachain/runtime/src/lib.rs index 5cc577281fdaa..885688d683d37 100644 --- a/bridges/bin/rialto-parachain/runtime/src/lib.rs +++ b/bridges/bin/rialto-parachain/runtime/src/lib.rs @@ -34,6 +34,7 @@ use bridge_runtime_common::messages::{ source::{estimate_message_dispatch_and_delivery_fee, XcmBridge, XcmBridgeAdapter}, MessageBridge, }; +use cumulus_pallet_parachain_system::AnyRelayNumber; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -274,6 +275,7 @@ impl pallet_transaction_payment::Config for Runtime { type WeightToFee = IdentityFee; type LengthToFee = IdentityFee; type FeeMultiplierUpdate = (); + type Event = Event; } impl pallet_sudo::Config for Runtime { @@ -295,6 +297,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedDmpWeight = ReservedDmpWeight; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; + type CheckAssociatedRelayNumber = AnyRelayNumber; } impl parachain_info::Config for Runtime {} @@ -419,6 +422,7 @@ impl Config for XcmConfig { type FeeManager = (); type MessageExporter = (); type UniversalAliases = Nothing; + type CallDispatcher = Call; } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -596,7 +600,7 @@ construct_runtime!( Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Sudo: pallet_sudo::{Pallet, Call, Storage, Config, Event}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, - TransactionPayment: pallet_transaction_payment::{Pallet, Storage}, + TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event}, ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event} = 20, ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21, @@ -860,7 +864,7 @@ mod tests { let xcm: Xcm<()> = vec![Instruction::Trap(42)].into(); let send_result = send_xcm::(dest.into(), xcm); - let expected_fee = MultiAssets::from((Here, Fungibility::Fungible(4_345_002_552_u128))); + let expected_fee = MultiAssets::from((Here, Fungibility::Fungible(4_259_858_152_u128))); let expected_hash = ([0u8, 0u8, 0u8, 0u8], 1u64).using_encoded(sp_io::hashing::blake2_256); assert_eq!(send_result, Ok((expected_hash, expected_fee)),); diff --git a/bridges/bin/rialto/node/src/command.rs b/bridges/bin/rialto/node/src/command.rs index 385a88ca065d3..852acb5955311 100644 --- a/bridges/bin/rialto/node/src/command.rs +++ b/bridges/bin/rialto/node/src/command.rs @@ -17,7 +17,7 @@ use crate::cli::{Cli, Subcommand}; use frame_benchmarking_cli::BenchmarkCmd; use rialto_runtime::{Block, RuntimeApi}; -use sc_cli::{ChainSpec, Role, RuntimeVersion, SubstrateCli}; +use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli}; impl SubstrateCli for Cli { fn impl_name() -> String { @@ -186,34 +186,30 @@ pub fn run() -> sc_cli::Result<()> { // let is_collator = crate::service::IsCollator::No; let overseer_gen = polkadot_service::overseer::RealOverseerGen; runner.run_node_until_exit(|config| async move { - match config.role { - Role::Light => Err(sc_cli::Error::Service(sc_service::Error::Other( - "Light client is not supported by this node".into(), - ))), - _ => { - let is_collator = polkadot_service::IsCollator::No; - let grandpa_pause = None; - let enable_beefy = true; - let jaeger_agent = None; - let telemetry_worker_handle = None; - let program_path = None; - let overseer_enable_anyways = false; - - polkadot_service::new_full::( - config, - is_collator, - grandpa_pause, - enable_beefy, - jaeger_agent, - telemetry_worker_handle, - program_path, - overseer_enable_anyways, - overseer_gen, - ) - .map(|full| full.task_manager) - .map_err(service_error) - }, - } + let is_collator = polkadot_service::IsCollator::No; + let grandpa_pause = None; + let enable_beefy = true; + let jaeger_agent = None; + let telemetry_worker_handle = None; + let program_path = None; + let overseer_enable_anyways = false; + + polkadot_service::new_full::( + config, + is_collator, + grandpa_pause, + enable_beefy, + jaeger_agent, + telemetry_worker_handle, + program_path, + overseer_enable_anyways, + overseer_gen, + None, + None, + None, + ) + .map(|full| full.task_manager) + .map_err(service_error) }) }, } diff --git a/bridges/bin/rialto/runtime/src/lib.rs b/bridges/bin/rialto/runtime/src/lib.rs index acca140d325d4..3729ab78630e7 100644 --- a/bridges/bin/rialto/runtime/src/lib.rs +++ b/bridges/bin/rialto/runtime/src/lib.rs @@ -42,6 +42,7 @@ use bridge_runtime_common::messages::{ use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; +use pallet_mmr::primitives as mmr; use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo}; use sp_api::impl_runtime_apis; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; @@ -252,6 +253,8 @@ impl pallet_babe::Config for Runtime { impl pallet_beefy::Config for Runtime { type BeefyId = BeefyId; + type MaxAuthorities = MaxAuthorities; + type OnNewValidatorSet = MmrLeaf; } impl pallet_grandpa::Config for Runtime { @@ -270,6 +273,9 @@ impl pallet_grandpa::Config for Runtime { type WeightInfo = (); } +type MmrHash = ::Output; +type MmrHashing = ::Hashing; + impl pallet_mmr::Config for Runtime { const INDEXING_PREFIX: &'static [u8] = b"mmr"; type Hashing = Keccak256; @@ -367,6 +373,7 @@ impl pallet_transaction_payment::Config for Runtime { AdjustmentVariable, MinimumMultiplier, >; + type Event = Event; } impl pallet_sudo::Config for Runtime { @@ -484,7 +491,7 @@ construct_runtime!( Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - TransactionPayment: pallet_transaction_payment::{Pallet, Storage}, + TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event}, // Consensus support. AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config}, @@ -620,8 +627,11 @@ impl_runtime_apis! { fn generate_proof(leaf_index: u64) -> Result<(EncodableOpaqueLeaf, MmrProof), MmrError> { - Mmr::generate_proof(leaf_index) - .map(|(leaf, proof)| (EncodableOpaqueLeaf::from_leaf(&leaf), proof)) + Mmr::generate_batch_proof(vec![leaf_index]) + .and_then(|(leaves, proof)| Ok(( + mmr::EncodableOpaqueLeaf::from_leaf(&leaves[0]), + mmr::BatchProof::into_single_leaf_proof(proof)? + ))) } fn verify_proof(leaf: EncodableOpaqueLeaf, proof: MmrProof) @@ -635,7 +645,7 @@ impl_runtime_apis! { .into_opaque_leaf() .try_decode() .ok_or(MmrError::Verify)?; - Mmr::verify_leaf(leaf, proof) + Mmr::verify_leaves(vec![leaf], mmr::Proof::into_batch_proof(proof)) } fn verify_proof_stateless( @@ -643,14 +653,46 @@ impl_runtime_apis! { 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) + pallet_mmr::verify_leaves_proof::( + root, + vec![node], + pallet_mmr::primitives::Proof::into_batch_proof(proof), + ) } fn mmr_root() -> Result { Ok(Mmr::mmr_root()) } + + fn generate_batch_proof(leaf_indices: Vec) + -> Result<(Vec, mmr::BatchProof), mmr::Error> + { + Mmr::generate_batch_proof(leaf_indices) + .map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof)) + } + + fn verify_batch_proof(leaves: Vec, proof: mmr::BatchProof) + -> Result<(), mmr::Error> + { + type Leaf = < + ::LeafData as LeafDataProvider + >::LeafData; + let leaves = leaves.into_iter().map(|leaf| + leaf.into_opaque_leaf() + .try_decode() + .ok_or(mmr::Error::Verify)).collect::, mmr::Error>>()?; + Mmr::verify_leaves(leaves, proof) + } + + fn verify_batch_proof_stateless( + root: MmrHash, + leaves: Vec, + proof: mmr::BatchProof + ) -> Result<(), mmr::Error> { + let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect(); + pallet_mmr::verify_leaves_proof::(root, nodes, proof) + } } impl bp_millau::MillauFinalityApi for Runtime { diff --git a/bridges/bin/rialto/runtime/src/parachains.rs b/bridges/bin/rialto/runtime/src/parachains.rs index 20a9aeb28c0df..d6267bca23735 100644 --- a/bridges/bin/rialto/runtime/src/parachains.rs +++ b/bridges/bin/rialto/runtime/src/parachains.rs @@ -18,7 +18,7 @@ use crate::{ AccountId, Babe, Balance, Balances, BlockNumber, Call, Event, Origin, Registrar, Runtime, - Slots, UncheckedExtrinsic, + ShiftSessionManager, Slots, UncheckedExtrinsic, }; use frame_support::{parameter_types, weights::Weight}; @@ -95,7 +95,9 @@ impl parachains_paras_inherent::Config for Runtime { impl parachains_scheduler::Config for Runtime {} -impl parachains_session_info::Config for Runtime {} +impl parachains_session_info::Config for Runtime { + type ValidatorSet = ShiftSessionManager; +} impl parachains_shared::Config for Runtime {} diff --git a/bridges/bin/rialto/runtime/src/xcm_config.rs b/bridges/bin/rialto/runtime/src/xcm_config.rs index dbe8ad81c4fe1..ab0029302abd4 100644 --- a/bridges/bin/rialto/runtime/src/xcm_config.rs +++ b/bridges/bin/rialto/runtime/src/xcm_config.rs @@ -146,6 +146,7 @@ impl xcm_executor::Config for XcmConfig { type FeeManager = (); type MessageExporter = (); type UniversalAliases = Nothing; + type CallDispatcher = Call; } /// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior @@ -237,7 +238,7 @@ mod tests { let xcm: Xcm<()> = vec![Instruction::Trap(42)].into(); let send_result = send_xcm::(dest.into(), xcm); - let expected_fee = MultiAssets::from((Here, 4_345_002_552_u128)); + let expected_fee = MultiAssets::from((Here, 4_259_858_152_u128)); let expected_hash = ([0u8, 0u8, 0u8, 0u8], 1u64).using_encoded(sp_io::hashing::blake2_256); assert_eq!(send_result, Ok((expected_hash, expected_fee)),); diff --git a/bridges/bin/runtime-common/src/messages_benchmarking.rs b/bridges/bin/runtime-common/src/messages_benchmarking.rs index 865b55f57ccdf..68f58d76b8780 100644 --- a/bridges/bin/runtime-common/src/messages_benchmarking.rs +++ b/bridges/bin/runtime-common/src/messages_benchmarking.rs @@ -27,7 +27,7 @@ use crate::messages::{ }; use bp_messages::{storage_keys, MessageData, MessageKey, MessagePayload}; -use bp_runtime::StorageProofSize; +use bp_runtime::{record_all_trie_keys, StorageProofSize}; use codec::Encode; use frame_support::weights::{GetDispatchInfo, Weight}; use pallet_bridge_messages::benchmarking::{ @@ -36,7 +36,7 @@ use pallet_bridge_messages::benchmarking::{ use sp_core::Hasher; use sp_runtime::traits::{Header, IdentifyAccount, MaybeSerializeDeserialize, Zero}; use sp_std::{fmt::Debug, prelude::*}; -use sp_trie::{record_all_keys, trie_types::TrieDBMutV1, LayoutV1, MemoryDB, Recorder, TrieMut}; +use sp_trie::{trie_types::TrieDBMutBuilderV1, LayoutV1, MemoryDB, Recorder, TrieMut}; /// Prepare outbound message for the `send_message` call. pub fn prepare_outbound_message( @@ -117,7 +117,7 @@ where let mut root = Default::default(); let mut mdb = MemoryDB::default(); { - let mut trie = TrieDBMutV1::::new(&mut mdb, &mut root); + let mut trie = TrieDBMutBuilderV1::::new(&mut mdb, &mut root).build(); trie.insert(&storage_key, ¶ms.inbound_lane_data.encode()) .map_err(|_| "TrieMut::insert has failed") .expect("TrieMut::insert should not fail in benchmarks"); @@ -125,10 +125,10 @@ where root = grow_trie(root, &mut mdb, params.size); // generate storage proof to be delivered to This chain - let mut proof_recorder = Recorder::::new(); - record_all_keys::, _>(&mdb, &root, &mut proof_recorder) - .map_err(|_| "record_all_keys has failed") - .expect("record_all_keys should not fail in benchmarks"); + let mut proof_recorder = Recorder::>::new(); + record_all_trie_keys::, _>(&mdb, &root, &mut proof_recorder) + .map_err(|_| "record_all_trie_keys has failed") + .expect("record_all_trie_keys should not fail in benchmarks"); let storage_proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect(); // finally insert header with given state root to our storage @@ -160,7 +160,7 @@ where let mut root = Default::default(); let mut mdb = MemoryDB::default(); { - let mut trie = TrieDBMutV1::::new(&mut mdb, &mut root); + let mut trie = TrieDBMutBuilderV1::::new(&mut mdb, &mut root).build(); // insert messages for nonce in params.message_nonces.clone() { @@ -195,10 +195,10 @@ where root = grow_trie(root, &mut mdb, params.size); // generate storage proof to be delivered to This chain - let mut proof_recorder = Recorder::::new(); - record_all_keys::, _>(&mdb, &root, &mut proof_recorder) - .map_err(|_| "record_all_keys has failed") - .expect("record_all_keys should not fail in benchmarks"); + let mut proof_recorder = Recorder::>::new(); + record_all_trie_keys::, _>(&mdb, &root, &mut proof_recorder) + .map_err(|_| "record_all_trie_keys has failed") + .expect("record_all_trie_keys should not fail in benchmarks"); let storage_proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect(); (root, storage_proof) @@ -241,18 +241,16 @@ pub fn grow_trie( let mut key_index = 0; loop { // generate storage proof to be delivered to This chain - let mut proof_recorder = Recorder::::new(); - record_all_keys::, _>(mdb, &root, &mut proof_recorder) - .map_err(|_| "record_all_keys has failed") - .expect("record_all_keys should not fail in benchmarks"); + let mut proof_recorder = Recorder::>::new(); + record_all_trie_keys::, _>(mdb, &root, &mut proof_recorder) + .map_err(|_| "record_all_trie_keys has failed") + .expect("record_all_trie_keys should not fail in benchmarks"); let size: usize = proof_recorder.drain().into_iter().map(|n| n.data.len()).sum(); if size > minimal_trie_size as _ { return root } - let mut trie = TrieDBMutV1::::from_existing(mdb, &mut root) - .map_err(|_| "TrieDBMutV1::from_existing has failed") - .expect("TrieDBMutV1::from_existing should not fail in benchmarks"); + let mut trie = TrieDBMutBuilderV1::::from_existing(mdb, &mut root).build(); for _ in 0..iterations { trie.insert(&key_index.encode(), &vec![42u8; leaf_size as _]) .map_err(|_| "TrieMut::insert has failed") diff --git a/bridges/bin/runtime-common/src/messages_extension.rs b/bridges/bin/runtime-common/src/messages_extension.rs index 95a8b947e74be..bcaadd60ca035 100644 --- a/bridges/bin/runtime-common/src/messages_extension.rs +++ b/bridges/bin/runtime-common/src/messages_extension.rs @@ -52,7 +52,7 @@ impl< .. }) => { let inbound_lane_data = - pallet_bridge_messages::InboundLanes::::get(&proof.lane); + pallet_bridge_messages::InboundLanes::::get(proof.lane); if proof.nonces_end <= inbound_lane_data.last_delivered_nonce() { log::trace!( target: pallet_bridge_messages::LOG_TARGET, @@ -74,7 +74,7 @@ impl< let latest_delivered_nonce = relayers_state.last_delivered_nonce; let outbound_lane_data = - pallet_bridge_messages::OutboundLanes::::get(&proof.lane); + pallet_bridge_messages::OutboundLanes::::get(proof.lane); if latest_delivered_nonce <= outbound_lane_data.latest_received_nonce { log::trace!( target: pallet_bridge_messages::LOG_TARGET, diff --git a/bridges/bin/runtime-common/src/parachains_benchmarking.rs b/bridges/bin/runtime-common/src/parachains_benchmarking.rs index 97a1cd3ee7d9f..59e2ef6962c83 100644 --- a/bridges/bin/runtime-common/src/parachains_benchmarking.rs +++ b/bridges/bin/runtime-common/src/parachains_benchmarking.rs @@ -22,12 +22,12 @@ use crate::messages_benchmarking::{grow_trie, insert_header_to_grandpa_pallet}; use bp_parachains::parachain_head_storage_key_at_source; use bp_polkadot_core::parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId}; -use bp_runtime::StorageProofSize; +use bp_runtime::{record_all_trie_keys, StorageProofSize}; use codec::Encode; use frame_support::traits::Get; use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber}; use sp_std::prelude::*; -use sp_trie::{record_all_keys, trie_types::TrieDBMutV1, LayoutV1, MemoryDB, Recorder, TrieMut}; +use sp_trie::{trie_types::TrieDBMutBuilderV1, LayoutV1, MemoryDB, Recorder, TrieMut}; /// Prepare proof of messages for the `receive_messages_proof` call. /// @@ -53,7 +53,8 @@ where let mut state_root = Default::default(); let mut mdb = MemoryDB::default(); { - let mut trie = TrieDBMutV1::::new(&mut mdb, &mut state_root); + let mut trie = + TrieDBMutBuilderV1::::new(&mut mdb, &mut state_root).build(); // insert parachain heads for parachain in parachains { @@ -69,10 +70,10 @@ where state_root = grow_trie(state_root, &mut mdb, size); // generate heads storage proof - let mut proof_recorder = Recorder::::new(); - record_all_keys::, _>(&mdb, &state_root, &mut proof_recorder) - .map_err(|_| "record_all_keys has failed") - .expect("record_all_keys should not fail in benchmarks"); + let mut proof_recorder = Recorder::>::new(); + record_all_trie_keys::, _>(&mdb, &state_root, &mut proof_recorder) + .map_err(|_| "record_all_trie_keys has failed") + .expect("record_all_trie_keys should not fail in benchmarks"); let proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect(); let (relay_block_number, relay_block_hash) = diff --git a/bridges/modules/grandpa/Cargo.toml b/bridges/modules/grandpa/Cargo.toml index 645f2b72a8180..55022d7e5c439 100644 --- a/bridges/modules/grandpa/Cargo.toml +++ b/bridges/modules/grandpa/Cargo.toml @@ -9,7 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } -finality-grandpa = { version = "0.15.0", default-features = false } +finality-grandpa = { version = "0.16.0", default-features = false } log = { version = "0.4.17", default-features = false } num-traits = { version = "0.2", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index 6e87c51ca986f..c2e4dce9b2d0d 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -741,7 +741,7 @@ pub mod pallet { #[pallet::genesis_build] impl, I: 'static> GenesisBuild for GenesisConfig { fn build(&self) { - PalletOperatingMode::::put(&self.operating_mode); + PalletOperatingMode::::put(self.operating_mode); if let Some(ref owner) = self.owner { PalletOwner::::put(owner); } @@ -1022,7 +1022,7 @@ impl, I: 'static> InboundLaneStorage for RuntimeInboundLaneStorage< Some(data) => data, None => { let data: InboundLaneData = - InboundLanes::::get(&self.lane_id).into(); + InboundLanes::::get(self.lane_id).into(); *self.cached_data.try_borrow_mut().expect( "we're in the single-threaded environment;\ we have no recursive borrows; qed", @@ -1037,7 +1037,7 @@ impl, I: 'static> InboundLaneStorage for RuntimeInboundLaneStorage< "we're in the single-threaded environment;\ we have no recursive borrows; qed", ) = Some(data.clone()); - InboundLanes::::insert(&self.lane_id, StoredInboundLaneData::(data)) + InboundLanes::::insert(self.lane_id, StoredInboundLaneData::(data)) } } @@ -1055,11 +1055,11 @@ impl, I: 'static> OutboundLaneStorage for RuntimeOutboundLaneStorag } fn data(&self) -> OutboundLaneData { - OutboundLanes::::get(&self.lane_id) + OutboundLanes::::get(self.lane_id) } fn set_data(&mut self, data: OutboundLaneData) { - OutboundLanes::::insert(&self.lane_id, data) + OutboundLanes::::insert(self.lane_id, data) } #[cfg(test)] @@ -1134,7 +1134,7 @@ mod tests { fn inbound_unrewarded_relayers_state( lane: bp_messages::LaneId, ) -> bp_messages::UnrewardedRelayersState { - let inbound_lane_data = InboundLanes::::get(&lane).0; + let inbound_lane_data = InboundLanes::::get(lane).0; let last_delivered_nonce = inbound_lane_data.last_delivered_nonce(); let relayers = inbound_lane_data.relayers; bp_messages::UnrewardedRelayersState { @@ -1656,7 +1656,7 @@ mod tests { receive_messages_delivery_proof(); assert_eq!( - OutboundLanes::::get(&TEST_LANE_ID).latest_received_nonce, + OutboundLanes::::get(TEST_LANE_ID).latest_received_nonce, 1, ); }); @@ -1839,7 +1839,7 @@ mod tests { 0, // weight may be zero in this case (all messages are improperly encoded) ),); - assert_eq!(InboundLanes::::get(&TEST_LANE_ID).last_delivered_nonce(), 1,); + assert_eq!(InboundLanes::::get(TEST_LANE_ID).last_delivered_nonce(), 1,); }); } @@ -1860,7 +1860,7 @@ mod tests { REGULAR_PAYLOAD.declared_weight + REGULAR_PAYLOAD.declared_weight, ),); - assert_eq!(InboundLanes::::get(&TEST_LANE_ID).last_delivered_nonce(), 3,); + assert_eq!(InboundLanes::::get(TEST_LANE_ID).last_delivered_nonce(), 3,); }); } diff --git a/bridges/modules/parachains/src/lib.rs b/bridges/modules/parachains/src/lib.rs index 604ac5df0562c..bf07cdc9e6730 100644 --- a/bridges/modules/parachains/src/lib.rs +++ b/bridges/modules/parachains/src/lib.rs @@ -258,7 +258,7 @@ pub mod pallet { target: LOG_TARGET, "The head of parachain {:?} is None. {}", parachain, - if ParasInfo::::contains_key(¶chain) { + if ParasInfo::::contains_key(parachain) { "Looks like it is not yet registered at the source relay chain" } else { "Looks like it has been deregistered from the source relay chain" @@ -514,7 +514,7 @@ pub mod pallet { #[pallet::genesis_build] impl, I: 'static> GenesisBuild for GenesisConfig { fn build(&self) { - PalletOperatingMode::::put(&self.operating_mode); + PalletOperatingMode::::put(self.operating_mode); if let Some(ref owner) = self.owner { PalletOwner::::put(owner); } @@ -532,8 +532,8 @@ mod tests { use bp_parachains::{BestParaHeadHash, ImportedParaHeadsKeyProvider, ParasInfoKeyProvider}; use bp_runtime::{ - BasicOperatingMode, OwnedBridgeModuleError, StorageDoubleMapKeyProvider, - StorageMapKeyProvider, + record_all_trie_keys, BasicOperatingMode, OwnedBridgeModuleError, + StorageDoubleMapKeyProvider, StorageMapKeyProvider, }; use bp_test_utils::{ authority_list, generate_owned_bridge_module_tests, make_default_justification, @@ -546,9 +546,7 @@ mod tests { weights::Weight, }; use sp_runtime::DispatchError; - use sp_trie::{ - record_all_keys, trie_types::TrieDBMutV1, LayoutV1, MemoryDB, Recorder, TrieMut, - }; + use sp_trie::{trie_types::TrieDBMutBuilderV1, LayoutV1, MemoryDB, Recorder, TrieMut}; type BridgesGrandpaPalletInstance = pallet_bridge_grandpa::Instance1; type WeightInfo = ::WeightInfo; @@ -590,7 +588,7 @@ mod tests { let mut root = Default::default(); let mut mdb = MemoryDB::default(); { - let mut trie = TrieDBMutV1::::new(&mut mdb, &mut root); + let mut trie = TrieDBMutBuilderV1::::new(&mut mdb, &mut root).build(); for (parachain, head) in heads { let storage_key = parachain_head_storage_key_at_source(PARAS_PALLET_NAME, ParaId(parachain)); @@ -602,10 +600,10 @@ mod tests { } // generate storage proof to be delivered to This chain - let mut proof_recorder = Recorder::::new(); - record_all_keys::, _>(&mdb, &root, &mut proof_recorder) - .map_err(|_| "record_all_keys has failed") - .expect("record_all_keys should not fail in benchmarks"); + let mut proof_recorder = Recorder::>::new(); + record_all_trie_keys::, _>(&mdb, &root, &mut proof_recorder) + .map_err(|_| "record_all_trie_keys has failed") + .expect("record_all_trie_keys should not fail in benchmarks"); let storage_proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect(); (root, ParaHeadsProof(storage_proof), parachains) diff --git a/bridges/modules/relayers/src/payment_adapter.rs b/bridges/modules/relayers/src/payment_adapter.rs index 46a7ad94d4af2..f027ab6429024 100644 --- a/bridges/modules/relayers/src/payment_adapter.rs +++ b/bridges/modules/relayers/src/payment_adapter.rs @@ -148,8 +148,8 @@ mod tests { run_test(|| { register_relayers_rewards::(&RELAYER_2, relayers_rewards(), 10); - assert_eq!(RelayerRewards::::get(&RELAYER_1), Some(80)); - assert_eq!(RelayerRewards::::get(&RELAYER_2), Some(120)); + assert_eq!(RelayerRewards::::get(RELAYER_1), Some(80)); + assert_eq!(RelayerRewards::::get(RELAYER_2), Some(120)); }); } @@ -158,9 +158,9 @@ mod tests { run_test(|| { register_relayers_rewards::(&RELAYER_3, relayers_rewards(), 10); - assert_eq!(RelayerRewards::::get(&RELAYER_1), Some(80)); - assert_eq!(RelayerRewards::::get(&RELAYER_2), Some(70)); - assert_eq!(RelayerRewards::::get(&RELAYER_3), Some(50)); + assert_eq!(RelayerRewards::::get(RELAYER_1), Some(80)); + assert_eq!(RelayerRewards::::get(RELAYER_2), Some(70)); + assert_eq!(RelayerRewards::::get(RELAYER_3), Some(50)); }); } @@ -169,9 +169,9 @@ mod tests { run_test(|| { register_relayers_rewards::(&RELAYER_3, relayers_rewards(), 1000); - assert_eq!(RelayerRewards::::get(&RELAYER_1), None); - assert_eq!(RelayerRewards::::get(&RELAYER_2), None); - assert_eq!(RelayerRewards::::get(&RELAYER_3), Some(200)); + assert_eq!(RelayerRewards::::get(RELAYER_1), None); + assert_eq!(RelayerRewards::::get(RELAYER_2), None); + assert_eq!(RelayerRewards::::get(RELAYER_3), Some(200)); }); } } diff --git a/bridges/modules/shift-session-manager/src/lib.rs b/bridges/modules/shift-session-manager/src/lib.rs index 9cf84412575a8..f8475851bb9a7 100644 --- a/bridges/modules/shift-session-manager/src/lib.rs +++ b/bridges/modules/shift-session-manager/src/lib.rs @@ -19,6 +19,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +use frame_support::traits::{ValidatorSet, ValidatorSetWithIdentification}; use sp_std::prelude::*; pub use pallet::*; @@ -49,6 +50,24 @@ pub mod pallet { pub(super) type InitialValidators = StorageValue<_, Vec>; } +impl ValidatorSet for Pallet { + type ValidatorId = T::ValidatorId; + type ValidatorIdOf = T::ValidatorIdOf; + + fn session_index() -> sp_staking::SessionIndex { + pallet_session::Pallet::::current_index() + } + + fn validators() -> Vec { + pallet_session::Pallet::::validators() + } +} + +impl ValidatorSetWithIdentification for Pallet { + type Identification = (); + type IdentificationOf = (); +} + impl pallet_session::SessionManager for Pallet { fn end_session(_: sp_staking::SessionIndex) {} fn start_session(_: sp_staking::SessionIndex) {} diff --git a/bridges/primitives/header-chain/Cargo.toml b/bridges/primitives/header-chain/Cargo.toml index 3a423292277ce..be87cce460e38 100644 --- a/bridges/primitives/header-chain/Cargo.toml +++ b/bridges/primitives/header-chain/Cargo.toml @@ -8,7 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } -finality-grandpa = { version = "0.15.0", default-features = false } +finality-grandpa = { version = "0.16.0", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } serde = { version = "1.0", optional = true } @@ -25,7 +25,6 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [dev-dependencies] -assert_matches = "1.5" bp-test-utils = { path = "../test-utils" } hex = "0.4" hex-literal = "0.3" diff --git a/bridges/primitives/header-chain/tests/implementation_match.rs b/bridges/primitives/header-chain/tests/implementation_match.rs index 51275bbd645e5..aaa19d4b918bb 100644 --- a/bridges/primitives/header-chain/tests/implementation_match.rs +++ b/bridges/primitives/header-chain/tests/implementation_match.rs @@ -20,7 +20,6 @@ //! Some of tests in this module may partially duplicate tests from `justification.rs`, //! but their purpose is different. -use assert_matches::assert_matches; use bp_header_chain::justification::{verify_justification, Error, GrandpaJustification}; use bp_test_utils::{ header_id, make_justification_for_header, signed_precommit, test_header, Account, @@ -106,7 +105,7 @@ pub fn make_default_justification(header: &TestHeader) -> GrandpaJustification( @@ -222,21 +233,26 @@ fn same_result_when_authority_equivocates_once_in_a_round() { ), Ok(()), ); - // original implementation returns non-empty GHOST - assert_matches!( - finality_grandpa::validate_commit( - &justification.commit, - &full_voter_set(), - &AncestryChain::new(&justification.votes_ancestries), - ) - .map(|result| result.ghost().cloned()), - Ok(Some(_)) - ); + // original implementation returns `Ok(validation_result)` + // with `validation_result.is_valid() == true`. + let result = finality_grandpa::validate_commit( + &justification.commit, + &full_voter_set(), + &AncestryChain::new(&justification.votes_ancestries), + ) + .unwrap(); + + assert!(result.is_valid()); } #[test] fn same_result_when_authority_equivocates_twice_in_a_round() { - let mut justification = make_default_justification(&test_header(1)); + let mut justification = make_justification_for_header(JustificationGeneratorParams { + header: test_header(1), + authorities: minimal_accounts_set(), + ancestors: 0, + ..Default::default() + }); // there's some code in the original implementation that should return an error when // same authority submits more than two different votes in a single round: // https://github.com/paritytech/finality-grandpa/blob/6aeea2d1159d0f418f0b86e70739f2130629ca09/src/lib.rs#L473 @@ -266,16 +282,16 @@ fn same_result_when_authority_equivocates_twice_in_a_round() { ), Ok(()), ); - // original implementation returns non-empty GHOST - assert_matches!( - finality_grandpa::validate_commit( - &justification.commit, - &full_voter_set(), - &AncestryChain::new(&justification.votes_ancestries), - ) - .map(|result| result.ghost().cloned()), - Ok(Some(_)) - ); + // original implementation returns `Ok(validation_result)` + // with `validation_result.is_valid() == true`. + let result = finality_grandpa::validate_commit( + &justification.commit, + &full_voter_set(), + &AncestryChain::new(&justification.votes_ancestries), + ) + .unwrap(); + + assert!(result.is_valid()); } #[test] @@ -299,14 +315,14 @@ fn same_result_when_there_are_not_enough_cumulative_weight_to_finalize_commit_ta ), Err(Error::TooLowCumulativeWeight), ); - // original implementation returns empty GHOST - assert_matches!( - finality_grandpa::validate_commit( - &justification.commit, - &full_voter_set(), - &AncestryChain::new(&justification.votes_ancestries), - ) - .map(|result| result.ghost().cloned()), - Ok(None) - ); + // original implementation returns `Ok(validation_result)` + // with `validation_result.is_valid() == false`. + let result = finality_grandpa::validate_commit( + &justification.commit, + &full_voter_set(), + &AncestryChain::new(&justification.votes_ancestries), + ) + .unwrap(); + + assert!(!result.is_valid()); } diff --git a/bridges/primitives/runtime/Cargo.toml b/bridges/primitives/runtime/Cargo.toml index db0b730f81b58..79f2b9fe03c5c 100644 --- a/bridges/primitives/runtime/Cargo.toml +++ b/bridges/primitives/runtime/Cargo.toml @@ -23,6 +23,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +trie-db = { version = "0.24.0", default-features = false } [dev-dependencies] hex-literal = "0.3" @@ -43,4 +44,5 @@ std = [ "sp-std/std", "sp-state-machine/std", "sp-trie/std", + "trie-db/std", ] diff --git a/bridges/primitives/runtime/src/lib.rs b/bridges/primitives/runtime/src/lib.rs index 87779195552b3..d775e09c47a00 100644 --- a/bridges/primitives/runtime/src/lib.rs +++ b/bridges/primitives/runtime/src/lib.rs @@ -37,7 +37,8 @@ pub use frame_support::storage::storage_prefix as storage_value_final_key; use num_traits::{CheckedSub, One}; use sp_runtime::transaction_validity::TransactionValidity; pub use storage_proof::{ - Error as StorageProofError, ProofSize as StorageProofSize, StorageProofChecker, + record_all_keys as record_all_trie_keys, Error as StorageProofError, + ProofSize as StorageProofSize, StorageProofChecker, }; #[cfg(feature = "std")] diff --git a/bridges/primitives/runtime/src/storage_proof.rs b/bridges/primitives/runtime/src/storage_proof.rs index 8236c0f2232c7..277456709f97c 100644 --- a/bridges/primitives/runtime/src/storage_proof.rs +++ b/bridges/primitives/runtime/src/storage_proof.rs @@ -19,8 +19,11 @@ use codec::Decode; use hash_db::{HashDB, Hasher, EMPTY_PREFIX}; use sp_runtime::RuntimeDebug; -use sp_std::vec::Vec; -use sp_trie::{read_trie_value, LayoutV1, MemoryDB, StorageProof}; +use sp_std::{boxed::Box, vec::Vec}; +use sp_trie::{ + read_trie_value, LayoutV1, MemoryDB, Recorder, StorageProof, Trie, TrieConfiguration, + TrieDBBuilder, TrieError, TrieHash, +}; /// Storage proof size requirements. /// @@ -70,7 +73,7 @@ where /// incomplete or otherwise invalid proof, this function returns an error. pub fn read_value(&self, key: &[u8]) -> Result>, Error> { // LayoutV1 or LayoutV0 is identical for proof that only read values. - read_trie_value::, _>(&self.db, &self.root, key) + read_trie_value::, _>(&self.db, &self.root, key, None, None) .map_err(|_| Error::StorageValueUnavailable) } @@ -124,6 +127,24 @@ pub fn craft_valid_storage_proof() -> (sp_core::H256, StorageProof) { (root, proof) } +/// Record all keys for a given root. +pub fn record_all_keys( + db: &DB, + root: &TrieHash, + recorder: &mut Recorder, +) -> Result<(), Box>> +where + DB: hash_db::HashDBRef, +{ + let trie = TrieDBBuilder::::new(db, root).with_recorder(recorder).build(); + for x in trie.iter()? { + let (key, _) = x?; + trie.get(&key)?; + } + + Ok(()) +} + #[cfg(test)] pub mod tests { use super::*; diff --git a/bridges/primitives/test-utils/Cargo.toml b/bridges/primitives/test-utils/Cargo.toml index 70a8fa6bd94f6..0a591334577af 100644 --- a/bridges/primitives/test-utils/Cargo.toml +++ b/bridges/primitives/test-utils/Cargo.toml @@ -9,7 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" bp-header-chain = { path = "../header-chain", default-features = false } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } ed25519-dalek = { version = "1.0", default-features = false, features = ["u64_backend"] } -finality-grandpa = { version = "0.15.0", default-features = false } +finality-grandpa = { version = "0.16.0", default-features = false } sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/bridges/relays/bin-substrate/Cargo.toml b/bridges/relays/bin-substrate/Cargo.toml index 8f984925cea76..2a463fff60e6a 100644 --- a/bridges/relays/bin-substrate/Cargo.toml +++ b/bridges/relays/bin-substrate/Cargo.toml @@ -70,4 +70,4 @@ bp-test-utils = { path = "../../primitives/test-utils" } hex-literal = "0.3" sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } tempfile = "3.2" -finality-grandpa = { version = "0.15.0" } +finality-grandpa = { version = "0.16.0" } diff --git a/bridges/relays/client-substrate/src/chain.rs b/bridges/relays/client-substrate/src/chain.rs index 132b86ad0b7bd..9562d68d4611b 100644 --- a/bridges/relays/client-substrate/src/chain.rs +++ b/bridges/relays/client-substrate/src/chain.rs @@ -19,7 +19,7 @@ use bp_runtime::{ Chain as ChainBase, EncodedOrDecodedCall, HashOf, TransactionEra, TransactionEraOf, }; use codec::{Codec, Encode}; -use frame_support::weights::{Weight, WeightToFeePolynomial}; +use frame_support::weights::{Weight, WeightToFee}; use jsonrpsee::core::{DeserializeOwned, Serialize}; use num_traits::Zero; use sc_transaction_pool_api::TransactionStatus; @@ -61,7 +61,7 @@ pub trait Chain: ChainBase + Clone { type Call: Clone + Codec + Dispatchable + Debug + Send; /// Type that is used by the chain, to convert from weight to fee. - type WeightToFee: WeightToFeePolynomial; + type WeightToFee: WeightToFee; } /// Substrate-based relay chain that supports parachains. diff --git a/bridges/relays/lib-substrate-relay/Cargo.toml b/bridges/relays/lib-substrate-relay/Cargo.toml index cd8cb51739399..bdf49d42eab44 100644 --- a/bridges/relays/lib-substrate-relay/Cargo.toml +++ b/bridges/relays/lib-substrate-relay/Cargo.toml @@ -22,7 +22,7 @@ bp-parachains = { path = "../../primitives/parachains" } bp-polkadot-core = { path = "../../primitives/polkadot-core" } bridge-runtime-common = { path = "../../bin/runtime-common" } -finality-grandpa = { version = "0.15.0" } +finality-grandpa = { version = "0.16.0" } finality-relay = { path = "../finality" } parachains-relay = { path = "../parachains" } relay-utils = { path = "../utils" } diff --git a/bridges/relays/lib-substrate-relay/src/messages_lane.rs b/bridges/relays/lib-substrate-relay/src/messages_lane.rs index 18e150e3617dd..f69ebc347d72c 100644 --- a/bridges/relays/lib-substrate-relay/src/messages_lane.rs +++ b/bridges/relays/lib-substrate-relay/src/messages_lane.rs @@ -510,7 +510,7 @@ mod tests { // i.e. weight reserved for messages dispatch allows dispatch of non-trivial messages. // // Any significant change in this values should attract additional attention. - (1024, 216_583_333_334), + (1024, 216_609_134_667), ); } } diff --git a/bridges/relays/lib-substrate-relay/src/messages_target.rs b/bridges/relays/lib-substrate-relay/src/messages_target.rs index d88b0539153dd..29d80bc2c5ee1 100644 --- a/bridges/relays/lib-substrate-relay/src/messages_target.rs +++ b/bridges/relays/lib-substrate-relay/src/messages_target.rs @@ -36,7 +36,7 @@ use bridge_runtime_common::messages::{ source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, }; use codec::Encode; -use frame_support::weights::{Weight, WeightToFeePolynomial}; +use frame_support::weights::{Weight, WeightToFee}; use messages_relay::{ message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf}, message_lane_loop::{TargetClient, TargetClientState}, @@ -502,8 +502,8 @@ fn compute_fee_multiplier( ) -> FixedU128 { let adjusted_weight_fee_difference = larger_adjusted_weight_fee.saturating_sub(smaller_adjusted_weight_fee); - let smaller_tx_unadjusted_weight_fee = WeightToFeeOf::::calc(&smaller_tx_weight); - let larger_tx_unadjusted_weight_fee = WeightToFeeOf::::calc(&larger_tx_weight); + let smaller_tx_unadjusted_weight_fee = WeightToFeeOf::::weight_to_fee(&smaller_tx_weight); + let larger_tx_unadjusted_weight_fee = WeightToFeeOf::::weight_to_fee(&larger_tx_weight); FixedU128::saturating_from_rational( adjusted_weight_fee_difference, larger_tx_unadjusted_weight_fee.saturating_sub(smaller_tx_unadjusted_weight_fee), @@ -516,7 +516,7 @@ fn compute_prepaid_messages_refund( total_prepaid_nonces: MessageNonce, fee_multiplier: FixedU128, ) -> BalanceOf { - fee_multiplier.saturating_mul_int(WeightToFeeOf::::calc( + fee_multiplier.saturating_mul_int(WeightToFeeOf::::weight_to_fee( &C::PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN.saturating_mul(total_prepaid_nonces), )) } @@ -560,16 +560,15 @@ mod tests { #[test] fn compute_fee_multiplier_returns_sane_results() { - let multiplier = FixedU128::saturating_from_rational(1, 1000); + let multiplier: FixedU128 = bp_rococo::WeightToFee::weight_to_fee(&1).into(); let smaller_weight = 1_000_000; let smaller_adjusted_weight_fee = - multiplier.saturating_mul_int(WeightToFeeOf::::calc(&smaller_weight)); + multiplier.saturating_mul_int(WeightToFeeOf::::weight_to_fee(&smaller_weight)); let larger_weight = smaller_weight + 200_000; let larger_adjusted_weight_fee = - multiplier.saturating_mul_int(WeightToFeeOf::::calc(&larger_weight)); - + multiplier.saturating_mul_int(WeightToFeeOf::::weight_to_fee(&larger_weight)); assert_eq!( compute_fee_multiplier::( smaller_adjusted_weight_fee,