diff --git a/bridges/primitives/chain-bridge-hub-wococo/src/lib.rs b/bridges/primitives/chain-bridge-hub-wococo/src/lib.rs index 2b0dc344f14d..a2c3f2ad37a3 100644 --- a/bridges/primitives/chain-bridge-hub-wococo/src/lib.rs +++ b/bridges/primitives/chain-bridge-hub-wococo/src/lib.rs @@ -24,7 +24,7 @@ // Re-export only what is really needed pub use bp_bridge_hub_rococo::{ - account_info_storage_key, AccountId, AccountPublic, AccountSigner, Address, Balance, + AccountId, AccountInfoStorageMapKeyProvider, AccountPublic, AccountSigner, Address, Balance, BlockLength, BlockNumber, BlockWeights, Hash, Hasher, Hashing, Header, Index, Nonce, SS58Prefix, Signature, SignedBlock, SignedExtensions, UncheckedExtrinsic, WeightToFee, MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, diff --git a/bridges/primitives/polkadot-core/src/lib.rs b/bridges/primitives/polkadot-core/src/lib.rs index 878c3dc38ebc..9e1f4b0452f9 100644 --- a/bridges/primitives/polkadot-core/src/lib.rs +++ b/bridges/primitives/polkadot-core/src/lib.rs @@ -17,7 +17,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use bp_messages::MessageNonce; -use bp_runtime::{Chain, EncodedOrDecodedCall}; +use bp_runtime::{Chain, EncodedOrDecodedCall, StorageMapKeyProvider}; use codec::Compact; use frame_support::{ dispatch::{DispatchClass, Dispatchable}, @@ -26,11 +26,11 @@ use frame_support::{ constants::{BlockExecutionWeight, WEIGHT_PER_SECOND}, Weight, }, - Blake2_128Concat, RuntimeDebug, StorageHasher, Twox128, + Blake2_128Concat, RuntimeDebug, }; use frame_system::limits; use scale_info::{StaticTypeInfo, TypeInfo}; -use sp_core::Hasher as HasherT; +use sp_core::{storage::StorageKey, Hasher as HasherT}; use sp_runtime::{ generic, traits::{BlakeTwo256, DispatchInfoOf, IdentifyAccount, Verify}, @@ -346,26 +346,28 @@ impl Chain for PolkadotLike { } } -/// Return a storage key for account data. +/// Provides a storage key for account data. /// -/// This is based on FRAME storage-generation code from Substrate: -/// [link](https://github.com/paritytech/substrate/blob/c939ceba381b6313462d47334f775e128ea4e95d/frame/support/src/storage/generator/map.rs#L74) +/// We need to use this approach when we don't have access to the runtime. /// The equivalent command to invoke in case full `Runtime` is known is this: /// `let key = frame_system::Account::::storage_map_final_key(&account_id);` -pub fn account_info_storage_key(id: &AccountId) -> Vec { - let module_prefix_hashed = Twox128::hash(b"System"); - let storage_prefix_hashed = Twox128::hash(b"Account"); - let key_hashed = codec::Encode::using_encoded(id, Blake2_128Concat::hash); - - let mut final_key = Vec::with_capacity( - module_prefix_hashed.len() + storage_prefix_hashed.len() + key_hashed.len(), - ); +pub struct AccountInfoStorageMapKeyProvider; + +impl StorageMapKeyProvider for AccountInfoStorageMapKeyProvider { + const MAP_NAME: &'static str = "Account"; + type Hasher = Blake2_128Concat; + type Key = AccountId; + // This should actually be `AccountInfo`, but we don't use this property in order to decode the + // data. So we use `Vec` as if we would work with encoded data. + type Value = Vec; +} - final_key.extend_from_slice(&module_prefix_hashed[..]); - final_key.extend_from_slice(&storage_prefix_hashed[..]); - final_key.extend_from_slice(&key_hashed); +impl AccountInfoStorageMapKeyProvider { + const PALLET_NAME: &'static str = "System"; - final_key + pub fn final_key(id: &AccountId) -> StorageKey { + ::final_key(Self::PALLET_NAME, id) + } } #[cfg(test)] @@ -379,7 +381,7 @@ mod tests { 25, 26, 27, 28, 29, 30, 31, 32, ] .into(); - let key = account_info_storage_key(&acc); + let key = AccountInfoStorageMapKeyProvider::final_key(&acc); assert_eq!(hex::encode(key), "26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da92dccd599abfe1920a1cff8a7358231430102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"); } } diff --git a/bridges/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs b/bridges/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs index 509cbf70db16..8b208712db5d 100644 --- a/bridges/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs +++ b/bridges/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs @@ -16,7 +16,7 @@ //! Wococo-to-Rococo parachains sync entrypoint. -use crate::cli::bridge::{CliBridgeBase, ParachainToRelayHeadersCliBridge}; +use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge}; use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId}; use parachains_relay::ParachainsPipeline; use relay_substrate_client::{CallOf, HeaderIdOf}; @@ -76,3 +76,10 @@ impl CliBridgeBase for BridgeHubRococoToBridgeHubWococoCliBridge { type Source = relay_bridge_hub_rococo_client::BridgeHubRococo; type Target = relay_bridge_hub_wococo_client::BridgeHubWococo; } + +impl MessagesCliBridge for BridgeHubRococoToBridgeHubWococoCliBridge { + const ESTIMATE_MESSAGE_FEE_METHOD: &'static str = + bp_bridge_hub_wococo::TO_BRIDGE_HUB_WOCOCO_ESTIMATE_MESSAGE_FEE_METHOD; + type MessagesLane = + crate::chains::bridge_hub_rococo_messages_to_bridge_hub_wococo::BridgeHubRococoMessagesToBridgeHubWococoMessageLane; +} diff --git a/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs b/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs index d4fbf095df48..453455a7b561 100644 --- a/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs +++ b/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs @@ -16,7 +16,7 @@ //! Rococo-to-Wococo parachains sync entrypoint. -use crate::cli::bridge::{CliBridgeBase, ParachainToRelayHeadersCliBridge}; +use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge}; use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId}; use parachains_relay::ParachainsPipeline; use relay_substrate_client::{CallOf, HeaderIdOf}; @@ -76,3 +76,10 @@ impl CliBridgeBase for BridgeHubWococoToBridgeHubRococoCliBridge { type Source = relay_bridge_hub_wococo_client::BridgeHubWococo; type Target = relay_bridge_hub_rococo_client::BridgeHubRococo; } + +impl MessagesCliBridge for BridgeHubWococoToBridgeHubRococoCliBridge { + const ESTIMATE_MESSAGE_FEE_METHOD: &'static str = + bp_bridge_hub_rococo::TO_BRIDGE_HUB_ROCOCO_ESTIMATE_MESSAGE_FEE_METHOD; + type MessagesLane = + crate::chains::bridge_hub_wococo_messages_to_bridge_hub_rococo::BridgeHubWococoMessagesToBridgeHubRococoMessageLane; +} diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs index bdc92f984daf..f84174563e14 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs @@ -44,6 +44,8 @@ use crate::{ millau_headers_to_rialto_parachain::MillauToRialtoParachainCliBridge, rialto_headers_to_millau::RialtoToMillauCliBridge, rialto_parachains_to_millau::RialtoParachainToMillauCliBridge, + rococo_parachains_to_bridge_hub_wococo::BridgeHubRococoToBridgeHubWococoCliBridge, + wococo_parachains_to_bridge_hub_rococo::BridgeHubWococoToBridgeHubRococoCliBridge, }, cli::{ bridge::{ @@ -51,6 +53,7 @@ use crate::{ RelayToRelayHeadersCliBridge, }, chain_schema::*, + relay_headers_and_messages::parachain_to_parachain::ParachainToParachainBridge, CliChain, HexLaneId, PrometheusParams, }, declare_chain_cli_schema, @@ -190,14 +193,29 @@ where declare_chain_cli_schema!(Millau, millau); declare_chain_cli_schema!(Rialto, rialto); declare_chain_cli_schema!(RialtoParachain, rialto_parachain); +declare_chain_cli_schema!(Rococo, rococo); +declare_chain_cli_schema!(BridgeHubRococo, bridge_hub_rococo); +declare_chain_cli_schema!(Wococo, wococo); +declare_chain_cli_schema!(BridgeHubWococo, bridge_hub_wococo); // Means to override signers of different layer transactions. declare_chain_cli_schema!(MillauHeadersToRialto, millau_headers_to_rialto); declare_chain_cli_schema!(MillauHeadersToRialtoParachain, millau_headers_to_rialto_parachain); declare_chain_cli_schema!(RialtoHeadersToMillau, rialto_headers_to_millau); declare_chain_cli_schema!(RialtoParachainsToMillau, rialto_parachains_to_millau); +declare_chain_cli_schema!(RococoHeadersToBridgeHubWococo, rococo_headers_to_bridge_hub_wococo); +declare_chain_cli_schema!( + RococoParachainsToBridgeHubWococo, + rococo_parachains_to_bridge_hub_wococo +); +declare_chain_cli_schema!(WococoHeadersToBridgeHubRococo, wococo_headers_to_bridge_hub_rococo); +declare_chain_cli_schema!( + WococoParachainsToBridgeHubRococo, + wococo_parachains_to_bridge_hub_rococo +); // All supported bridges. declare_relay_to_relay_bridge_schema!(Millau, Rialto); declare_relay_to_parachain_bridge_schema!(Millau, RialtoParachain, Rialto); +declare_parachain_to_parachain_bridge_schema!(BridgeHubRococo, Rococo, BridgeHubWococo, Wococo); /// Base portion of the bidirectional complex relay. /// @@ -410,6 +428,32 @@ impl Full2WayBridge for MillauRialtoParachainFull2WayBridge { } } +/// BridgeHubRococo <> BridgeHubWococo complex relay. +pub struct BridgeHubRococoBridgeHubWococoFull2WayBridge { + base: ::Base, +} + +#[async_trait] +impl Full2WayBridge for BridgeHubRococoBridgeHubWococoFull2WayBridge { + type Base = ParachainToParachainBridge; + type Left = relay_bridge_hub_rococo_client::BridgeHubRococo; + type Right = relay_bridge_hub_wococo_client::BridgeHubWococo; + type L2R = BridgeHubRococoToBridgeHubWococoCliBridge; + type R2L = BridgeHubWococoToBridgeHubRococoCliBridge; + + fn new(base: Self::Base) -> anyhow::Result { + Ok(Self { base }) + } + + fn base(&self) -> &Self::Base { + &self.base + } + + fn mut_base(&mut self) -> &mut Self::Base { + &mut self.base + } +} + /// Complex headers+messages relay. #[derive(Debug, PartialEq, StructOpt)] pub enum RelayHeadersAndMessages { @@ -417,6 +461,8 @@ pub enum RelayHeadersAndMessages { MillauRialto(MillauRialtoHeadersAndMessages), /// Millau <> RialtoParachain relay. MillauRialtoParachain(MillauRialtoParachainHeadersAndMessages), + /// BridgeHubRococo <> BridgeHubWococo relay. + BridgeHubRococoBridgeHubWococo(BridgeHubRococoBridgeHubWococoHeadersAndMessages), } impl RelayHeadersAndMessages { @@ -429,6 +475,10 @@ impl RelayHeadersAndMessages { MillauRialtoParachainFull2WayBridge::new(params.into_bridge().await?)? .run() .await, + RelayHeadersAndMessages::BridgeHubRococoBridgeHubWococo(params) => + BridgeHubRococoBridgeHubWococoFull2WayBridge::new(params.into_bridge().await?)? + .run() + .await, } } } diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs index 9adc8fd66243..e7328a837eb9 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs @@ -118,7 +118,7 @@ macro_rules! declare_parachain_to_parachain_bridge_schema { left_parachains_to_right_sign_override: [<$left_chain ParachainsTo $right_parachain SigningParams>], } - impl [<$left_chain $right_parachain HeadersAndMessages>] { + impl [<$left_parachain $right_parachain HeadersAndMessages>] { async fn into_bridge< Left: ChainWithTransactions + CliChain>, LeftRelay: CliChain, @@ -132,7 +132,7 @@ macro_rules! declare_parachain_to_parachain_bridge_schema { + ParachainToRelayHeadersCliBridge, >( self, - ) -> anyhow::Result> { + ) -> anyhow::Result> { Ok(ParachainToParachainBridge { common: Full2WayBridgeCommonParams::new::( self.shared, @@ -151,7 +151,7 @@ macro_rules! declare_parachain_to_parachain_bridge_schema { accounts: vec![], }, )?, - left_relay: self.left_relay.into_client::().await?, + left_relay: self.left_relay.into_client::().await?, right_relay: self.right_relay.into_client::().await?, right_headers_to_left_transaction_params: self .right_relay_headers_to_left_sign_override diff --git a/bridges/relays/client-bridge-hub-rococo/src/lib.rs b/bridges/relays/client-bridge-hub-rococo/src/lib.rs index e4740490cb5d..1de0e26d4366 100644 --- a/bridges/relays/client-bridge-hub-rococo/src/lib.rs +++ b/bridges/relays/client-bridge-hub-rococo/src/lib.rs @@ -19,10 +19,10 @@ use bp_messages::{MessageNonce, Weight}; use codec::Encode; use relay_substrate_client::{ - Chain, ChainBase, ChainWithMessages, ChainWithTransactions, Error as SubstrateError, SignParam, - UnsignedTransaction, + Chain, ChainBase, ChainWithBalances, ChainWithMessages, ChainWithTransactions, + Error as SubstrateError, SignParam, UnsignedTransaction, }; -use sp_core::Pair; +use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; use std::time::Duration; @@ -65,6 +65,12 @@ impl Chain for BridgeHubRococo { type Call = runtime::Call; } +impl ChainWithBalances for BridgeHubRococo { + fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { + bp_bridge_hub_rococo::AccountInfoStorageMapKeyProvider::final_key(account_id) + } +} + impl ChainWithTransactions for BridgeHubRococo { type AccountKeyPair = sp_core::sr25519::Pair; type SignedTransaction = runtime::UncheckedExtrinsic; diff --git a/bridges/relays/client-bridge-hub-wococo/src/lib.rs b/bridges/relays/client-bridge-hub-wococo/src/lib.rs index 3199b3b4fc1c..46bac2e826e3 100644 --- a/bridges/relays/client-bridge-hub-wococo/src/lib.rs +++ b/bridges/relays/client-bridge-hub-wococo/src/lib.rs @@ -19,10 +19,10 @@ use bp_messages::{MessageNonce, Weight}; use codec::Encode; use relay_substrate_client::{ - Chain, ChainBase, ChainWithMessages, ChainWithTransactions, Error as SubstrateError, SignParam, - UnsignedTransaction, + Chain, ChainBase, ChainWithBalances, ChainWithMessages, ChainWithTransactions, + Error as SubstrateError, SignParam, UnsignedTransaction, }; -use sp_core::Pair; +use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; use std::time::Duration; @@ -65,6 +65,12 @@ impl Chain for BridgeHubWococo { type Call = runtime::Call; } +impl ChainWithBalances for BridgeHubWococo { + fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { + bp_bridge_hub_wococo::AccountInfoStorageMapKeyProvider::final_key(account_id) + } +} + impl ChainWithTransactions for BridgeHubWococo { type AccountKeyPair = sp_core::sr25519::Pair; type SignedTransaction = runtime::UncheckedExtrinsic; diff --git a/bridges/relays/client-kusama/src/lib.rs b/bridges/relays/client-kusama/src/lib.rs index 355f26b84966..25d7bb76e59b 100644 --- a/bridges/relays/client-kusama/src/lib.rs +++ b/bridges/relays/client-kusama/src/lib.rs @@ -16,6 +16,7 @@ //! Types used to connect to the Kusama chain. +use bp_kusama::AccountInfoStorageMapKeyProvider; use frame_support::weights::Weight; use relay_substrate_client::{Chain, ChainBase, ChainWithBalances, ChainWithGrandpa}; use sp_core::storage::StorageKey; @@ -65,7 +66,7 @@ impl ChainWithGrandpa for Kusama { impl ChainWithBalances for Kusama { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { - StorageKey(bp_kusama::account_info_storage_key(account_id)) + AccountInfoStorageMapKeyProvider::final_key(account_id) } } diff --git a/bridges/relays/client-polkadot/src/lib.rs b/bridges/relays/client-polkadot/src/lib.rs index 101b62b9c35e..8bba686cfe9e 100644 --- a/bridges/relays/client-polkadot/src/lib.rs +++ b/bridges/relays/client-polkadot/src/lib.rs @@ -16,6 +16,7 @@ //! Types used to connect to the Polkadot chain. +use bp_polkadot::AccountInfoStorageMapKeyProvider; use frame_support::weights::Weight; use relay_substrate_client::{Chain, ChainBase, ChainWithBalances, ChainWithGrandpa}; use sp_core::storage::StorageKey; @@ -66,7 +67,7 @@ impl ChainWithGrandpa for Polkadot { impl ChainWithBalances for Polkadot { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { - StorageKey(bp_polkadot::account_info_storage_key(account_id)) + AccountInfoStorageMapKeyProvider::final_key(account_id) } } diff --git a/bridges/relays/client-rococo/src/lib.rs b/bridges/relays/client-rococo/src/lib.rs index fc3aa76eb449..38a95042ff3b 100644 --- a/bridges/relays/client-rococo/src/lib.rs +++ b/bridges/relays/client-rococo/src/lib.rs @@ -68,7 +68,7 @@ impl ChainWithGrandpa for Rococo { impl ChainWithBalances for Rococo { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { - StorageKey(bp_rococo::account_info_storage_key(account_id)) + bp_rococo::AccountInfoStorageMapKeyProvider::final_key(account_id) } } diff --git a/bridges/relays/client-westend/src/lib.rs b/bridges/relays/client-westend/src/lib.rs index 6a2944629bed..9132a38710a1 100644 --- a/bridges/relays/client-westend/src/lib.rs +++ b/bridges/relays/client-westend/src/lib.rs @@ -75,7 +75,7 @@ impl ChainWithGrandpa for Westend { impl ChainWithBalances for Westend { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { - StorageKey(bp_westend::account_info_storage_key(account_id)) + bp_westend::AccountInfoStorageMapKeyProvider::final_key(account_id) } } diff --git a/bridges/relays/client-wococo/src/lib.rs b/bridges/relays/client-wococo/src/lib.rs index 04b5193afd33..6fc3714f6670 100644 --- a/bridges/relays/client-wococo/src/lib.rs +++ b/bridges/relays/client-wococo/src/lib.rs @@ -68,7 +68,7 @@ impl ChainWithGrandpa for Wococo { impl ChainWithBalances for Wococo { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { - StorageKey(bp_wococo::account_info_storage_key(account_id)) + bp_wococo::AccountInfoStorageMapKeyProvider::final_key(account_id) } }