diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index 1eb77ed75e..7469ebfec1 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -89,7 +89,7 @@ pub type AccountIndex = u32; pub type Balance = bp_millau::Balance; /// Index of a transaction in the chain. -pub type Index = u32; +pub type Index = bp_millau::Index; /// A hash of some data used by the chain. pub type Hash = bp_millau::Hash; diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index c13c0d78a1..8b46020a1b 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -95,7 +95,7 @@ pub type AccountIndex = u32; pub type Balance = bp_rialto::Balance; /// Index of a transaction in the chain. -pub type Index = u32; +pub type Index = bp_rialto::Index; /// A hash of some data used by the chain. pub type Hash = bp_rialto::Hash; diff --git a/modules/grandpa/src/mock.rs b/modules/grandpa/src/mock.rs index 20f5ea7bdf..363594c35f 100644 --- a/modules/grandpa/src/mock.rs +++ b/modules/grandpa/src/mock.rs @@ -22,7 +22,7 @@ use frame_support::{construct_runtime, parameter_types, weights::Weight}; use sp_runtime::{ testing::{Header, H256}, traits::{BlakeTwo256, IdentityLookup}, - Perbill, + AnySignature, Perbill, }; pub type AccountId = u64; @@ -101,6 +101,11 @@ impl Chain for TestBridgedChain { type Hash = ::Hash; type Hasher = ::Hashing; type Header = ::Header; + + type AccountId = AccountId; + type Balance = u64; + type Index = u64; + type Signature = AnySignature; } pub fn run_test(test: impl FnOnce() -> T) -> T { diff --git a/modules/token-swap/src/lib.rs b/modules/token-swap/src/lib.rs index dde25d8cb2..206f040b96 100644 --- a/modules/token-swap/src/lib.rs +++ b/modules/token-swap/src/lib.rs @@ -122,25 +122,30 @@ pub mod pallet { /// Converter from raw hash (derived from swap) to This chain account. type FromSwapToThisAccountIdConverter: Convert; - /// Tokens balance type at the Bridged chain. - type BridgedBalance: Parameter; - /// Account identifier type at the Bridged chain. - type BridgedAccountId: Parameter; - /// Account public key type at the Bridged chain. - type BridgedAccountPublic: Parameter; - /// Account signature type at the Bridged chain. - type BridgedAccountSignature: Parameter; + /// The chain we're bridged to. + type BridgedChain: bp_runtime::Chain; /// Converter from raw hash (derived from Bridged chain account) to This chain account. type FromBridgedToThisAccountIdConverter: Convert; } + /// Type of the Bridged chain. + pub type BridgedChainOf = >::BridgedChain; + /// Tokens balance type at the Bridged chain. + pub type BridgedBalanceOf = bp_runtime::BalanceOf>; + /// Account identifier type at the Bridged chain. + pub type BridgedAccountIdOf = bp_runtime::AccountIdOf>; + /// Account public key type at the Bridged chain. + pub type BridgedAccountPublicOf = bp_runtime::AccountPublicOf>; + /// Account signature type at the Bridged chain. + pub type BridgedAccountSignatureOf = bp_runtime::SignatureOf>; + /// SCALE-encoded `Currency::transfer` call on the bridged chain. pub type RawBridgedTransferCall = Vec; /// Bridge message payload used by the pallet. pub type MessagePayloadOf = bp_message_dispatch::MessagePayload< ::AccountId, - >::BridgedAccountPublic, - >::BridgedAccountSignature, + BridgedAccountPublicOf, + BridgedAccountSignatureOf, RawBridgedTransferCall, >; /// Type of `TokenSwap` used by the pallet. @@ -148,8 +153,8 @@ pub mod pallet { BlockNumberFor, <>::ThisCurrency as Currency<::AccountId>>::Balance, ::AccountId, - >::BridgedBalance, - >::BridgedAccountId, + BridgedBalanceOf, + BridgedAccountIdOf, >; #[pallet::pallet] @@ -160,7 +165,10 @@ pub mod pallet { impl, I: 'static> Hooks> for Pallet {} #[pallet::call] - impl, I: 'static> Pallet { + impl, I: 'static> Pallet + where + BridgedAccountPublicOf: Parameter, + { /// Start token swap procedure. /// /// The dispatch origin for this call must be exactly the `swap.source_account_at_this_chain` account. @@ -194,11 +202,11 @@ pub mod pallet { pub fn create_swap( origin: OriginFor, swap: TokenSwapOf, - target_public_at_bridged_chain: T::BridgedAccountPublic, + target_public_at_bridged_chain: BridgedAccountPublicOf, bridged_chain_spec_version: u32, bridged_currency_transfer: RawBridgedTransferCall, bridged_currency_transfer_weight: Weight, - bridged_currency_transfer_signature: T::BridgedAccountSignature, + bridged_currency_transfer_signature: BridgedAccountSignatureOf, ) -> DispatchResultWithPostInfo { // ensure that the `origin` is the same account that is mentioned in the `swap` intention let origin_account = ensure_signed(origin)?; @@ -541,12 +549,18 @@ mod tests { const CAN_START_BLOCK_NUMBER: u64 = 10; const CAN_CLAIM_BLOCK_NUMBER: u64 = CAN_START_BLOCK_NUMBER + 1; - const BRIDGED_CHAIN_ACCOUNT_PUBLIC: BridgedAccountPublic = 1; - const BRIDGED_CHAIN_ACCOUNT_SIGNATURE: BridgedAccountSignature = 2; const BRIDGED_CHAIN_ACCOUNT: BridgedAccountId = 3; const BRIDGED_CHAIN_SPEC_VERSION: u32 = 4; const BRIDGED_CHAIN_CALL_WEIGHT: Balance = 5; + fn bridged_chain_account_public() -> BridgedAccountPublic { + 1.into() + } + + fn bridged_chain_account_signature() -> BridgedAccountSignature { + sp_runtime::testing::TestSignature(2, Vec::new()) + } + fn test_swap() -> TokenSwapOf { bp_token_swap::TokenSwap { swap_type: TokenSwapType::LockClaimUntilBlock(CAN_START_BLOCK_NUMBER, 0.into()), @@ -569,11 +583,11 @@ mod tests { assert_ok!(Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), )); } @@ -591,11 +605,11 @@ mod tests { Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT + 1), test_swap(), - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), ), Error::::MismatchedSwapSourceOrigin ); @@ -611,11 +625,11 @@ mod tests { Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT), swap, - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), ), Error::::TooLowBalanceOnThisChain ); @@ -631,11 +645,11 @@ mod tests { Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT), swap, - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), ), Error::::FailedToTransferToSwapAccount ); @@ -651,11 +665,11 @@ mod tests { Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, transfer, BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), ), Error::::FailedToSendTransferMessage ); @@ -668,22 +682,22 @@ mod tests { assert_ok!(Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), )); assert_noop!( Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), ), Error::::SwapAlreadyStarted ); @@ -698,11 +712,11 @@ mod tests { Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), ), Error::::SwapPeriodIsFinished ); @@ -716,11 +730,11 @@ mod tests { assert_ok!(Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), )); }); } @@ -734,11 +748,11 @@ mod tests { assert_ok!(Pallet::::create_swap( Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), - BRIDGED_CHAIN_ACCOUNT_PUBLIC, + bridged_chain_account_public(), BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, - BRIDGED_CHAIN_ACCOUNT_SIGNATURE, + bridged_chain_account_signature(), )); let swap_hash = test_swap_hash(); diff --git a/modules/token-swap/src/mock.rs b/modules/token-swap/src/mock.rs index c91933cce4..603db2adec 100644 --- a/modules/token-swap/src/mock.rs +++ b/modules/token-swap/src/mock.rs @@ -31,8 +31,8 @@ pub type AccountId = u64; pub type Balance = u64; pub type Block = frame_system::mocking::MockBlock; pub type BridgedAccountId = u64; -pub type BridgedAccountPublic = u64; -pub type BridgedAccountSignature = u64; +pub type BridgedAccountPublic = sp_runtime::testing::UintAuthorityId; +pub type BridgedAccountSignature = sp_runtime::testing::TestSignature; pub type BridgedBalance = u64; pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; @@ -122,13 +122,24 @@ impl pallet_bridge_token_swap::Config for TestRuntime { type ThisCurrency = pallet_balances::Pallet; type FromSwapToThisAccountIdConverter = TestAccountConverter; - type BridgedBalance = BridgedBalance; - type BridgedAccountId = BridgedAccountId; - type BridgedAccountPublic = BridgedAccountPublic; - type BridgedAccountSignature = BridgedAccountSignature; + type BridgedChain = BridgedChain; type FromBridgedToThisAccountIdConverter = TestAccountConverter; } +pub struct BridgedChain; + +impl bp_runtime::Chain for BridgedChain { + type BlockNumber = u64; + type Hash = H256; + type Hasher = BlakeTwo256; + type Header = sp_runtime::generic::Header; + + type AccountId = BridgedAccountId; + type Balance = BridgedBalance; + type Index = u64; + type Signature = BridgedAccountSignature; +} + pub struct TestMessagesBridge; impl MessagesBridge> for TestMessagesBridge { diff --git a/primitives/chain-millau/src/lib.rs b/primitives/chain-millau/src/lib.rs index cb732bccfa..b2bf5cf0b1 100644 --- a/primitives/chain-millau/src/lib.rs +++ b/primitives/chain-millau/src/lib.rs @@ -149,6 +149,9 @@ pub type AccountSigner = MultiSigner; /// Balance of an account. pub type Balance = u64; +/// Index of a transaction in the chain. +pub type Index = u32; + /// Weight-to-Fee type used by Millau. pub type WeightToFee = IdentityFee; @@ -161,6 +164,11 @@ impl Chain for Millau { type Hash = Hash; type Hasher = Hasher; type Header = Header; + + type AccountId = AccountId; + type Balance = Balance; + type Index = Index; + type Signature = Signature; } /// Millau Hasher (Blake2-256 ++ Keccak-256) implementation. diff --git a/primitives/chain-rialto/src/lib.rs b/primitives/chain-rialto/src/lib.rs index 14edd1c227..b7b382f52b 100644 --- a/primitives/chain-rialto/src/lib.rs +++ b/primitives/chain-rialto/src/lib.rs @@ -148,6 +148,9 @@ pub type Balance = u128; /// An instant or duration in time. pub type Moment = u64; +/// Index of a transaction in the chain. +pub type Index = u32; + /// Weight-to-Fee type used by Rialto. pub type WeightToFee = IdentityFee; @@ -160,6 +163,11 @@ impl Chain for Rialto { type Hash = Hash; type Hasher = Hasher; type Header = Header; + + type AccountId = AccountId; + type Balance = Balance; + type Index = Index; + type Signature = Signature; } /// Convert a 256-bit hash into an AccountId. diff --git a/primitives/polkadot-core/src/lib.rs b/primitives/polkadot-core/src/lib.rs index 3083112316..9e8726734e 100644 --- a/primitives/polkadot-core/src/lib.rs +++ b/primitives/polkadot-core/src/lib.rs @@ -342,6 +342,11 @@ impl Chain for PolkadotLike { type Hash = Hash; type Hasher = Hasher; type Header = Header; + + type AccountId = AccountId; + type Balance = Balance; + type Index = Index; + type Signature = Signature; } /// Convert a 256-bit hash into an AccountId. diff --git a/primitives/runtime/src/chain.rs b/primitives/runtime/src/chain.rs index 270e2d7b2f..2d7325641b 100644 --- a/primitives/runtime/src/chain.rs +++ b/primitives/runtime/src/chain.rs @@ -15,12 +15,15 @@ // along with Parity Bridges Common. If not, see . use frame_support::Parameter; -use num_traits::AsPrimitive; -use sp_runtime::traits::{ - AtLeast32BitUnsigned, Hash as HashT, Header as HeaderT, MaybeDisplay, MaybeMallocSizeOf, MaybeSerializeDeserialize, - Member, SimpleBitOps, +use num_traits::{AsPrimitive, Bounded, CheckedSub, SaturatingAdd, Zero}; +use sp_runtime::{ + traits::{ + AtLeast32Bit, AtLeast32BitUnsigned, Hash as HashT, Header as HeaderT, MaybeDisplay, MaybeMallocSizeOf, + MaybeSerialize, MaybeSerializeDeserialize, Member, SimpleBitOps, Verify, + }, + FixedPointOperand, }; -use sp_std::str::FromStr; +use sp_std::{convert::TryFrom, fmt::Debug, hash::Hash, str::FromStr}; /// Minimal Substrate-based chain representation that may be used from no_std environment. pub trait Chain: Send + Sync + 'static { @@ -34,7 +37,7 @@ pub trait Chain: Send + Sync + 'static { type BlockNumber: Parameter + Member + MaybeSerializeDeserialize - + sp_std::hash::Hash + + Hash + Copy + Default + MaybeDisplay @@ -54,7 +57,7 @@ pub trait Chain: Send + Sync + 'static { type Hash: Parameter + Member + MaybeSerializeDeserialize - + sp_std::hash::Hash + + Hash + Ord + Copy + MaybeDisplay @@ -75,6 +78,39 @@ pub trait Chain: Send + Sync + 'static { // See here for more info: // https://crates.parity.io/sp_runtime/traits/trait.Header.html type Header: Parameter + HeaderT + MaybeSerializeDeserialize; + + /// The user account identifier type for the runtime. + type AccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord + Default; + /// Balance of an account in native tokens. + /// + /// The chain may support multiple tokens, but this particular type is for token that is used + /// to pay for transaction dispatch, to reward different relayers (headers, messages), etc. + type Balance: AtLeast32BitUnsigned + + FixedPointOperand + + Parameter + + Parameter + + Member + + MaybeSerializeDeserialize + + Clone + + Copy + + Bounded + + CheckedSub + + PartialOrd + + SaturatingAdd + + Zero + + TryFrom; + /// Index of a transaction used by the chain. + type Index: Parameter + + Member + + MaybeSerialize + + Debug + + Default + + MaybeDisplay + + MaybeSerializeDeserialize + + AtLeast32Bit + + Copy; + /// Signature type, used on this chain. + type Signature: Parameter + Verify; } /// Block number used by the chain. @@ -89,5 +125,20 @@ pub type HasherOf = ::Hasher; /// Header type used by the chain. pub type HeaderOf = ::Header; +/// Account id type used by the chain. +pub type AccountIdOf = ::AccountId; + +/// Balance type used by the chain. +pub type BalanceOf = ::Balance; + +/// Transaction index type used by the chain. +pub type IndexOf = ::Index; + +/// Signature type used by the chain. +pub type SignatureOf = ::Signature; + +/// Account public type used by the chain. +pub type AccountPublicOf = as Verify>::Signer; + /// Transaction era used by the chain. pub type TransactionEraOf = crate::TransactionEra, HashOf>; diff --git a/primitives/runtime/src/lib.rs b/primitives/runtime/src/lib.rs index fa1586c792..659d5c0aac 100644 --- a/primitives/runtime/src/lib.rs +++ b/primitives/runtime/src/lib.rs @@ -24,7 +24,10 @@ use sp_core::hash::H256; use sp_io::hashing::blake2_256; use sp_std::convert::TryFrom; -pub use chain::{BlockNumberOf, Chain, HashOf, HasherOf, HeaderOf, TransactionEraOf}; +pub use chain::{ + AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, Chain, HashOf, HasherOf, HeaderOf, IndexOf, SignatureOf, + TransactionEraOf, +}; pub use storage_proof::{Error as StorageProofError, StorageProofChecker}; #[cfg(feature = "std")] diff --git a/relays/bin-substrate/src/chains/millau_headers_to_rialto.rs b/relays/bin-substrate/src/chains/millau_headers_to_rialto.rs index 4fa9d83e58..fa51200b6f 100644 --- a/relays/bin-substrate/src/chains/millau_headers_to_rialto.rs +++ b/relays/bin-substrate/src/chains/millau_headers_to_rialto.rs @@ -22,7 +22,7 @@ use sp_core::{Bytes, Pair}; use bp_header_chain::justification::GrandpaJustification; use relay_millau_client::{Millau, SyncHeader as MillauSyncHeader}; use relay_rialto_client::{Rialto, SigningParams as RialtoSigningParams}; -use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction}; +use relay_substrate_client::{Client, IndexOf, TransactionSignScheme, UnsignedTransaction}; use substrate_relay_helper::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate}; /// Millau-to-Rialto finality sync pipeline. @@ -55,7 +55,7 @@ impl SubstrateFinalitySyncPipeline for MillauFinalityToRialto { fn make_submit_finality_proof_transaction( &self, era: bp_runtime::TransactionEraOf, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, header: MillauSyncHeader, proof: GrandpaJustification, ) -> Bytes { diff --git a/relays/bin-substrate/src/chains/millau_messages_to_rialto.rs b/relays/bin-substrate/src/chains/millau_messages_to_rialto.rs index a4dedaed1e..b0c63ff088 100644 --- a/relays/bin-substrate/src/chains/millau_messages_to_rialto.rs +++ b/relays/bin-substrate/src/chains/millau_messages_to_rialto.rs @@ -28,7 +28,7 @@ use frame_support::weights::Weight; use messages_relay::message_lane::MessageLane; use relay_millau_client::{HeaderId as MillauHeaderId, Millau, SigningParams as MillauSigningParams}; use relay_rialto_client::{HeaderId as RialtoHeaderId, Rialto, SigningParams as RialtoSigningParams}; -use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction}; +use relay_substrate_client::{Chain, Client, IndexOf, TransactionSignScheme, UnsignedTransaction}; use relay_utils::metrics::MetricsParams; use substrate_relay_helper::messages_lane::{ select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane, @@ -76,7 +76,7 @@ impl SubstrateMessageLane for MillauMessagesToRialto { fn make_messages_receiving_proof_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, _generated_at_block: RialtoHeaderId, proof: ::MessagesReceivingProof, ) -> Bytes { @@ -108,7 +108,7 @@ impl SubstrateMessageLane for MillauMessagesToRialto { fn make_messages_delivery_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, _generated_at_header: MillauHeaderId, _nonces: RangeInclusive, proof: ::MessagesProof, diff --git a/relays/bin-substrate/src/chains/rialto_headers_to_millau.rs b/relays/bin-substrate/src/chains/rialto_headers_to_millau.rs index d2e0f5e663..4f649702b7 100644 --- a/relays/bin-substrate/src/chains/rialto_headers_to_millau.rs +++ b/relays/bin-substrate/src/chains/rialto_headers_to_millau.rs @@ -22,7 +22,7 @@ use sp_core::{Bytes, Pair}; use bp_header_chain::justification::GrandpaJustification; use relay_millau_client::{Millau, SigningParams as MillauSigningParams}; use relay_rialto_client::{Rialto, SyncHeader as RialtoSyncHeader}; -use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction}; +use relay_substrate_client::{Client, IndexOf, TransactionSignScheme, UnsignedTransaction}; use substrate_relay_helper::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate}; /// Rialto-to-Millau finality sync pipeline. @@ -56,7 +56,7 @@ impl SubstrateFinalitySyncPipeline for RialtoFinalityToMillau { fn make_submit_finality_proof_transaction( &self, era: bp_runtime::TransactionEraOf, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, header: RialtoSyncHeader, proof: GrandpaJustification, ) -> Bytes { diff --git a/relays/bin-substrate/src/chains/rialto_messages_to_millau.rs b/relays/bin-substrate/src/chains/rialto_messages_to_millau.rs index 2e91c99488..0196329fb8 100644 --- a/relays/bin-substrate/src/chains/rialto_messages_to_millau.rs +++ b/relays/bin-substrate/src/chains/rialto_messages_to_millau.rs @@ -28,7 +28,7 @@ use frame_support::weights::Weight; use messages_relay::message_lane::MessageLane; use relay_millau_client::{HeaderId as MillauHeaderId, Millau, SigningParams as MillauSigningParams}; use relay_rialto_client::{HeaderId as RialtoHeaderId, Rialto, SigningParams as RialtoSigningParams}; -use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction}; +use relay_substrate_client::{Chain, Client, IndexOf, TransactionSignScheme, UnsignedTransaction}; use relay_utils::metrics::MetricsParams; use substrate_relay_helper::messages_lane::{ select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane, @@ -76,7 +76,7 @@ impl SubstrateMessageLane for RialtoMessagesToMillau { fn make_messages_receiving_proof_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, _generated_at_block: MillauHeaderId, proof: ::MessagesReceivingProof, ) -> Bytes { @@ -108,7 +108,7 @@ impl SubstrateMessageLane for RialtoMessagesToMillau { fn make_messages_delivery_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, _generated_at_header: RialtoHeaderId, _nonces: RangeInclusive, proof: ::MessagesProof, diff --git a/relays/bin-substrate/src/chains/rococo_headers_to_wococo.rs b/relays/bin-substrate/src/chains/rococo_headers_to_wococo.rs index 32eb988c89..5d8cf25539 100644 --- a/relays/bin-substrate/src/chains/rococo_headers_to_wococo.rs +++ b/relays/bin-substrate/src/chains/rococo_headers_to_wococo.rs @@ -21,7 +21,7 @@ use sp_core::{Bytes, Pair}; use bp_header_chain::justification::GrandpaJustification; use relay_rococo_client::{Rococo, SyncHeader as RococoSyncHeader}; -use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction}; +use relay_substrate_client::{Client, IndexOf, TransactionSignScheme, UnsignedTransaction}; use relay_utils::metrics::MetricsParams; use relay_wococo_client::{SigningParams as WococoSigningParams, Wococo}; use substrate_relay_helper::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate}; @@ -78,7 +78,7 @@ impl SubstrateFinalitySyncPipeline for RococoFinalityToWococo { fn make_submit_finality_proof_transaction( &self, era: bp_runtime::TransactionEraOf, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, header: RococoSyncHeader, proof: GrandpaJustification, ) -> Bytes { diff --git a/relays/bin-substrate/src/chains/rococo_messages_to_wococo.rs b/relays/bin-substrate/src/chains/rococo_messages_to_wococo.rs index 78ed93372d..de2d8c7263 100644 --- a/relays/bin-substrate/src/chains/rococo_messages_to_wococo.rs +++ b/relays/bin-substrate/src/chains/rococo_messages_to_wococo.rs @@ -26,7 +26,7 @@ use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof; use frame_support::weights::Weight; use messages_relay::message_lane::MessageLane; use relay_rococo_client::{HeaderId as RococoHeaderId, Rococo, SigningParams as RococoSigningParams}; -use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction}; +use relay_substrate_client::{Chain, Client, IndexOf, TransactionSignScheme, UnsignedTransaction}; use relay_utils::metrics::MetricsParams; use relay_wococo_client::{HeaderId as WococoHeaderId, SigningParams as WococoSigningParams, Wococo}; use substrate_relay_helper::messages_lane::{ @@ -75,7 +75,7 @@ impl SubstrateMessageLane for RococoMessagesToWococo { fn make_messages_receiving_proof_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, _generated_at_block: WococoHeaderId, proof: ::MessagesReceivingProof, ) -> Bytes { @@ -109,7 +109,7 @@ impl SubstrateMessageLane for RococoMessagesToWococo { fn make_messages_delivery_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, _generated_at_header: RococoHeaderId, _nonces: RangeInclusive, proof: ::MessagesProof, diff --git a/relays/bin-substrate/src/chains/westend_headers_to_millau.rs b/relays/bin-substrate/src/chains/westend_headers_to_millau.rs index cb81e20699..8501ff4186 100644 --- a/relays/bin-substrate/src/chains/westend_headers_to_millau.rs +++ b/relays/bin-substrate/src/chains/westend_headers_to_millau.rs @@ -21,7 +21,7 @@ use sp_core::{Bytes, Pair}; use bp_header_chain::justification::GrandpaJustification; use relay_millau_client::{Millau, SigningParams as MillauSigningParams}; -use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction}; +use relay_substrate_client::{Client, IndexOf, TransactionSignScheme, UnsignedTransaction}; use relay_utils::metrics::MetricsParams; use relay_westend_client::{SyncHeader as WestendSyncHeader, Westend}; use substrate_relay_helper::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate}; @@ -64,7 +64,7 @@ impl SubstrateFinalitySyncPipeline for WestendFinalityToMillau { fn make_submit_finality_proof_transaction( &self, era: bp_runtime::TransactionEraOf, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, header: WestendSyncHeader, proof: GrandpaJustification, ) -> Bytes { diff --git a/relays/bin-substrate/src/chains/wococo_headers_to_rococo.rs b/relays/bin-substrate/src/chains/wococo_headers_to_rococo.rs index 883e54c983..b3e98d6542 100644 --- a/relays/bin-substrate/src/chains/wococo_headers_to_rococo.rs +++ b/relays/bin-substrate/src/chains/wococo_headers_to_rococo.rs @@ -21,7 +21,7 @@ use sp_core::{Bytes, Pair}; use bp_header_chain::justification::GrandpaJustification; use relay_rococo_client::{Rococo, SigningParams as RococoSigningParams}; -use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction}; +use relay_substrate_client::{Client, IndexOf, TransactionSignScheme, UnsignedTransaction}; use relay_utils::metrics::MetricsParams; use relay_wococo_client::{SyncHeader as WococoSyncHeader, Wococo}; use substrate_relay_helper::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate}; @@ -83,7 +83,7 @@ impl SubstrateFinalitySyncPipeline for WococoFinalityToRococo { fn make_submit_finality_proof_transaction( &self, era: bp_runtime::TransactionEraOf, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, header: WococoSyncHeader, proof: GrandpaJustification, ) -> Bytes { diff --git a/relays/bin-substrate/src/chains/wococo_messages_to_rococo.rs b/relays/bin-substrate/src/chains/wococo_messages_to_rococo.rs index f02e2da1e6..035c8f3948 100644 --- a/relays/bin-substrate/src/chains/wococo_messages_to_rococo.rs +++ b/relays/bin-substrate/src/chains/wococo_messages_to_rococo.rs @@ -26,7 +26,7 @@ use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof; use frame_support::weights::Weight; use messages_relay::message_lane::MessageLane; use relay_rococo_client::{HeaderId as RococoHeaderId, Rococo, SigningParams as RococoSigningParams}; -use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction}; +use relay_substrate_client::{Chain, Client, IndexOf, TransactionSignScheme, UnsignedTransaction}; use relay_utils::metrics::MetricsParams; use relay_wococo_client::{HeaderId as WococoHeaderId, SigningParams as WococoSigningParams, Wococo}; use substrate_relay_helper::messages_lane::{ @@ -74,7 +74,7 @@ impl SubstrateMessageLane for WococoMessagesToRococo { fn make_messages_receiving_proof_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, _generated_at_block: RococoHeaderId, proof: ::MessagesReceivingProof, ) -> Bytes { @@ -108,7 +108,7 @@ impl SubstrateMessageLane for WococoMessagesToRococo { fn make_messages_delivery_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, _generated_at_header: WococoHeaderId, _nonces: RangeInclusive, proof: ::MessagesProof, diff --git a/relays/bin-substrate/src/cli/estimate_fee.rs b/relays/bin-substrate/src/cli/estimate_fee.rs index 2fa7918faf..7e4cbf5b6b 100644 --- a/relays/bin-substrate/src/cli/estimate_fee.rs +++ b/relays/bin-substrate/src/cli/estimate_fee.rs @@ -17,6 +17,7 @@ use crate::cli::bridge::FullBridge; use crate::cli::{Balance, CliChain, HexBytes, HexLaneId, SourceConnectionParams}; use crate::select_full_bridge; +use bp_runtime::BalanceOf; use codec::{Decode, Encode}; use relay_substrate_client::Chain; use structopt::StructOpt; @@ -53,7 +54,7 @@ impl EstimateFee { let lane = lane.into(); let payload = Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?; - let fee: ::Balance = + let fee: BalanceOf = estimate_message_delivery_and_dispatch_fee(&source_client, ESTIMATE_MESSAGE_FEE_METHOD, lane, payload) .await?; diff --git a/relays/bin-substrate/src/cli/send_message.rs b/relays/bin-substrate/src/cli/send_message.rs index ad02e126b0..66c2f17755 100644 --- a/relays/bin-substrate/src/cli/send_message.rs +++ b/relays/bin-substrate/src/cli/send_message.rs @@ -22,6 +22,7 @@ use crate::cli::{ TargetSigningParams, }; use bp_message_dispatch::{CallOrigin, MessagePayload}; +use bp_runtime::BalanceOf; use codec::Encode; use frame_support::weights::Weight; use relay_substrate_client::{Chain, TransactionSignScheme, UnsignedTransaction}; @@ -159,7 +160,7 @@ impl SendMessage { let fee = match self.fee { Some(fee) => fee, None => Balance( - estimate_message_delivery_and_dispatch_fee::<::Balance, _, _>( + estimate_message_delivery_and_dispatch_fee::, _, _>( &source_client, ESTIMATE_MESSAGE_FEE_METHOD, lane, diff --git a/relays/client-kusama/src/lib.rs b/relays/client-kusama/src/lib.rs index 0c94e73aec..95a8596c97 100644 --- a/relays/client-kusama/src/lib.rs +++ b/relays/client-kusama/src/lib.rs @@ -31,6 +31,11 @@ impl ChainBase for Kusama { type Hash = bp_kusama::Hash; type Hasher = bp_kusama::Hasher; type Header = bp_kusama::Header; + + type AccountId = bp_kusama::AccountId; + type Balance = bp_kusama::Balance; + type Index = bp_kusama::Nonce; + type Signature = bp_kusama::Signature; } impl Chain for Kusama { @@ -39,11 +44,8 @@ impl Chain for Kusama { const STORAGE_PROOF_OVERHEAD: u32 = bp_kusama::EXTRA_STORAGE_PROOF_SIZE; const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_kusama::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; - type AccountId = bp_kusama::AccountId; - type Index = bp_kusama::Nonce; type SignedBlock = bp_kusama::SignedBlock; type Call = (); - type Balance = bp_kusama::Balance; type WeightToFee = bp_kusama::WeightToFee; } diff --git a/relays/client-millau/src/lib.rs b/relays/client-millau/src/lib.rs index eaf677634e..aa20fe76cb 100644 --- a/relays/client-millau/src/lib.rs +++ b/relays/client-millau/src/lib.rs @@ -18,7 +18,8 @@ use codec::{Compact, Decode, Encode}; use relay_substrate_client::{ - Chain, ChainBase, ChainWithBalances, TransactionEraOf, TransactionSignScheme, UnsignedTransaction, + BalanceOf, Chain, ChainBase, ChainWithBalances, IndexOf, TransactionEraOf, TransactionSignScheme, + UnsignedTransaction, }; use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; @@ -36,6 +37,11 @@ impl ChainBase for Millau { type Hash = millau_runtime::Hash; type Hasher = millau_runtime::Hashing; type Header = millau_runtime::Header; + + type AccountId = millau_runtime::AccountId; + type Balance = millau_runtime::Balance; + type Index = millau_runtime::Index; + type Signature = millau_runtime::Signature; } impl Chain for Millau { @@ -44,11 +50,8 @@ impl Chain for Millau { const STORAGE_PROOF_OVERHEAD: u32 = bp_millau::EXTRA_STORAGE_PROOF_SIZE; const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_millau::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; - type AccountId = millau_runtime::AccountId; - type Index = millau_runtime::Index; type SignedBlock = millau_runtime::SignedBlock; type Call = millau_runtime::Call; - type Balance = millau_runtime::Balance; type WeightToFee = bp_millau::WeightToFee; } @@ -115,10 +118,10 @@ impl TransactionSignScheme for Millau { let extra = &tx.signature.as_ref()?.2; Some(UnsignedTransaction { call: tx.function, - nonce: Compact::<::Index>::decode(&mut &extra.4.encode()[..]) + nonce: Compact::>::decode(&mut &extra.4.encode()[..]) .ok()? .into(), - tip: Compact::<::Balance>::decode(&mut &extra.6.encode()[..]) + tip: Compact::>::decode(&mut &extra.6.encode()[..]) .ok()? .into(), }) diff --git a/relays/client-polkadot/src/lib.rs b/relays/client-polkadot/src/lib.rs index dc5564cc17..5882d917bf 100644 --- a/relays/client-polkadot/src/lib.rs +++ b/relays/client-polkadot/src/lib.rs @@ -31,6 +31,11 @@ impl ChainBase for Polkadot { type Hash = bp_polkadot::Hash; type Hasher = bp_polkadot::Hasher; type Header = bp_polkadot::Header; + + type AccountId = bp_polkadot::AccountId; + type Balance = bp_polkadot::Balance; + type Index = bp_polkadot::Nonce; + type Signature = bp_polkadot::Signature; } impl Chain for Polkadot { @@ -39,11 +44,8 @@ impl Chain for Polkadot { const STORAGE_PROOF_OVERHEAD: u32 = bp_polkadot::EXTRA_STORAGE_PROOF_SIZE; const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_polkadot::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; - type AccountId = bp_polkadot::AccountId; - type Index = bp_polkadot::Nonce; type SignedBlock = bp_polkadot::SignedBlock; type Call = (); - type Balance = bp_polkadot::Balance; type WeightToFee = bp_polkadot::WeightToFee; } diff --git a/relays/client-rialto/src/lib.rs b/relays/client-rialto/src/lib.rs index 459ea5bc4e..ed0cec314a 100644 --- a/relays/client-rialto/src/lib.rs +++ b/relays/client-rialto/src/lib.rs @@ -18,7 +18,8 @@ use codec::{Compact, Decode, Encode}; use relay_substrate_client::{ - Chain, ChainBase, ChainWithBalances, TransactionEraOf, TransactionSignScheme, UnsignedTransaction, + BalanceOf, Chain, ChainBase, ChainWithBalances, IndexOf, TransactionEraOf, TransactionSignScheme, + UnsignedTransaction, }; use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; @@ -36,6 +37,11 @@ impl ChainBase for Rialto { type Hash = rialto_runtime::Hash; type Hasher = rialto_runtime::Hashing; type Header = rialto_runtime::Header; + + type AccountId = rialto_runtime::AccountId; + type Balance = rialto_runtime::Balance; + type Index = rialto_runtime::Index; + type Signature = rialto_runtime::Signature; } impl Chain for Rialto { @@ -44,11 +50,8 @@ impl Chain for Rialto { const STORAGE_PROOF_OVERHEAD: u32 = bp_rialto::EXTRA_STORAGE_PROOF_SIZE; const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_rialto::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; - type AccountId = rialto_runtime::AccountId; - type Index = rialto_runtime::Index; type SignedBlock = rialto_runtime::SignedBlock; type Call = rialto_runtime::Call; - type Balance = rialto_runtime::Balance; type WeightToFee = bp_rialto::WeightToFee; } @@ -115,10 +118,10 @@ impl TransactionSignScheme for Rialto { let extra = &tx.signature.as_ref()?.2; Some(UnsignedTransaction { call: tx.function, - nonce: Compact::<::Index>::decode(&mut &extra.4.encode()[..]) + nonce: Compact::>::decode(&mut &extra.4.encode()[..]) .ok()? .into(), - tip: Compact::<::Balance>::decode(&mut &extra.6.encode()[..]) + tip: Compact::>::decode(&mut &extra.6.encode()[..]) .ok()? .into(), }) diff --git a/relays/client-rococo/src/lib.rs b/relays/client-rococo/src/lib.rs index 5694d183d7..4d6e3b969c 100644 --- a/relays/client-rococo/src/lib.rs +++ b/relays/client-rococo/src/lib.rs @@ -41,6 +41,11 @@ impl ChainBase for Rococo { type Hash = bp_rococo::Hash; type Hasher = bp_rococo::Hashing; type Header = bp_rococo::Header; + + type AccountId = bp_rococo::AccountId; + type Balance = bp_rococo::Balance; + type Index = bp_rococo::Nonce; + type Signature = bp_rococo::Signature; } impl Chain for Rococo { @@ -49,11 +54,8 @@ impl Chain for Rococo { const STORAGE_PROOF_OVERHEAD: u32 = bp_rococo::EXTRA_STORAGE_PROOF_SIZE; const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_rococo::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; - type AccountId = bp_rococo::AccountId; - type Index = bp_rococo::Index; type SignedBlock = bp_rococo::SignedBlock; type Call = crate::runtime::Call; - type Balance = bp_rococo::Balance; type WeightToFee = bp_rococo::WeightToFee; } diff --git a/relays/client-substrate/src/chain.rs b/relays/client-substrate/src/chain.rs index 627c01eb0e..711cfd12f1 100644 --- a/relays/client-substrate/src/chain.rs +++ b/relays/client-substrate/src/chain.rs @@ -16,17 +16,14 @@ use bp_runtime::{Chain as ChainBase, TransactionEraOf}; use codec::{Codec, Encode}; -use frame_support::{weights::WeightToFeePolynomial, Parameter}; +use frame_support::weights::WeightToFeePolynomial; use jsonrpsee_ws_client::{DeserializeOwned, Serialize}; -use num_traits::{Bounded, CheckedSub, SaturatingAdd, Zero}; +use num_traits::Zero; use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{ generic::SignedBlock, - traits::{ - AtLeast32Bit, AtLeast32BitUnsigned, Block as BlockT, Dispatchable, MaybeDisplay, MaybeSerialize, - MaybeSerializeDeserialize, Member, - }, - EncodedJustification, FixedPointOperand, + traits::{Block as BlockT, Dispatchable, Member}, + EncodedJustification, }; use std::{fmt::Debug, time::Duration}; @@ -44,49 +41,15 @@ pub trait Chain: ChainBase + Clone { /// Maximal size (in bytes) of SCALE-encoded account id on this chain. const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32; - /// The user account identifier type for the runtime. - type AccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord + Default; - /// Index of a transaction used by the chain. - type Index: Parameter - + Member - + MaybeSerialize - + Debug - + Default - + MaybeDisplay - + DeserializeOwned - + AtLeast32Bit - + Copy; /// Block type. type SignedBlock: Member + Serialize + DeserializeOwned + BlockWithJustification; /// The aggregated `Call` type. type Call: Clone + Dispatchable + Debug; - /// Balance of an account in native tokens. - /// - /// The chain may support multiple tokens, but this particular type is for token that is used - /// to pay for transaction dispatch, to reward different relayers (headers, messages), etc. - type Balance: AtLeast32BitUnsigned - + FixedPointOperand - + Parameter - + Parameter - + Member - + DeserializeOwned - + Clone - + Copy - + Bounded - + CheckedSub - + PartialOrd - + SaturatingAdd - + Zero - + std::convert::TryFrom; /// Type that is used by the chain, to convert from weight to fee. type WeightToFee: WeightToFeePolynomial; } -/// Balance type used by the chain -pub type BalanceOf = ::Balance; -/// Index type used by the chain -pub type IndexOf = ::Index; /// Weight-to-Fee type used by the chain pub type WeightToFeeOf = ::WeightToFee; diff --git a/relays/client-substrate/src/guard.rs b/relays/client-substrate/src/guard.rs index f7df7dbb05..6c5bf16baa 100644 --- a/relays/client-substrate/src/guard.rs +++ b/relays/client-substrate/src/guard.rs @@ -165,6 +165,7 @@ impl Environment for Client { #[cfg(test)] mod tests { use super::*; + use frame_support::weights::IdentityFee; use futures::{ channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender}, future::FutureExt, @@ -180,6 +181,11 @@ mod tests { type Hash = sp_core::H256; type Hasher = sp_runtime::traits::BlakeTwo256; type Header = sp_runtime::generic::Header; + + type AccountId = u32; + type Balance = u32; + type Index = u32; + type Signature = sp_runtime::testing::TestSignature; } impl Chain for TestChain { @@ -188,13 +194,10 @@ mod tests { const STORAGE_PROOF_OVERHEAD: u32 = 0; const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = 0; - type AccountId = u32; - type Index = u32; type SignedBlock = sp_runtime::generic::SignedBlock>; type Call = (); - type Balance = u32; - type WeightToFee = frame_support::weights::IdentityFee; + type WeightToFee = IdentityFee; } impl ChainWithBalances for TestChain { diff --git a/relays/client-substrate/src/lib.rs b/relays/client-substrate/src/lib.rs index b607b68f8b..07cf7d88f8 100644 --- a/relays/client-substrate/src/lib.rs +++ b/relays/client-substrate/src/lib.rs @@ -32,13 +32,14 @@ pub mod metrics; use std::time::Duration; pub use crate::chain::{ - BalanceOf, BlockWithJustification, Chain, ChainWithBalances, IndexOf, TransactionSignScheme, UnsignedTransaction, - WeightToFeeOf, + BlockWithJustification, Chain, ChainWithBalances, TransactionSignScheme, UnsignedTransaction, WeightToFeeOf, }; pub use crate::client::{Client, JustificationsSubscription, OpaqueGrandpaAuthoritiesSet}; pub use crate::error::{Error, Result}; pub use crate::sync_header::SyncHeader; -pub use bp_runtime::{BlockNumberOf, Chain as ChainBase, HashOf, HeaderOf, TransactionEra, TransactionEraOf}; +pub use bp_runtime::{ + BalanceOf, BlockNumberOf, Chain as ChainBase, HashOf, HeaderOf, IndexOf, TransactionEra, TransactionEraOf, +}; /// Header id used by the chain. pub type HeaderIdOf = relay_utils::HeaderId, BlockNumberOf>; diff --git a/relays/client-westend/src/lib.rs b/relays/client-westend/src/lib.rs index 726a699e3c..c719d6ea55 100644 --- a/relays/client-westend/src/lib.rs +++ b/relays/client-westend/src/lib.rs @@ -35,6 +35,11 @@ impl ChainBase for Westend { type Hash = bp_westend::Hash; type Hasher = bp_westend::Hasher; type Header = bp_westend::Header; + + type AccountId = bp_westend::AccountId; + type Balance = bp_westend::Balance; + type Index = bp_westend::Nonce; + type Signature = bp_westend::Signature; } impl Chain for Westend { @@ -43,11 +48,8 @@ impl Chain for Westend { const STORAGE_PROOF_OVERHEAD: u32 = bp_westend::EXTRA_STORAGE_PROOF_SIZE; const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_westend::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; - type AccountId = bp_westend::AccountId; - type Index = bp_westend::Nonce; type SignedBlock = bp_westend::SignedBlock; type Call = bp_westend::Call; - type Balance = bp_westend::Balance; type WeightToFee = bp_westend::WeightToFee; } diff --git a/relays/client-wococo/src/lib.rs b/relays/client-wococo/src/lib.rs index eac2aa841b..e6a0c0649b 100644 --- a/relays/client-wococo/src/lib.rs +++ b/relays/client-wococo/src/lib.rs @@ -41,6 +41,11 @@ impl ChainBase for Wococo { type Hash = bp_wococo::Hash; type Hasher = bp_wococo::Hashing; type Header = bp_wococo::Header; + + type AccountId = bp_wococo::AccountId; + type Balance = bp_wococo::Balance; + type Index = bp_wococo::Nonce; + type Signature = bp_wococo::Signature; } impl Chain for Wococo { @@ -49,11 +54,8 @@ impl Chain for Wococo { const STORAGE_PROOF_OVERHEAD: u32 = bp_wococo::EXTRA_STORAGE_PROOF_SIZE; const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_wococo::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; - type AccountId = bp_wococo::AccountId; - type Index = bp_wococo::Index; type SignedBlock = bp_wococo::SignedBlock; type Call = crate::runtime::Call; - type Balance = bp_wococo::Balance; type WeightToFee = bp_wococo::WeightToFee; } diff --git a/relays/lib-substrate-relay/src/finality_pipeline.rs b/relays/lib-substrate-relay/src/finality_pipeline.rs index 73a346f217..684aafa023 100644 --- a/relays/lib-substrate-relay/src/finality_pipeline.rs +++ b/relays/lib-substrate-relay/src/finality_pipeline.rs @@ -19,6 +19,7 @@ use crate::finality_target::SubstrateFinalityTarget; use bp_header_chain::justification::GrandpaJustification; +use bp_runtime::AccountIdOf; use finality_relay::{FinalitySyncParams, FinalitySyncPipeline}; use relay_substrate_client::{finality_source::FinalitySource, BlockNumberOf, Chain, Client, HashOf, SyncHeader}; use relay_utils::{metrics::MetricsParams, BlockNumberBase}; @@ -63,13 +64,13 @@ pub trait SubstrateFinalitySyncPipeline: 'static + Clone + Debug + Send + Sync { fn start_relay_guards(&self) {} /// Returns id of account that we're using to sign transactions at target chain. - fn transactions_author(&self) -> ::AccountId; + fn transactions_author(&self) -> AccountIdOf; /// Make submit header transaction. fn make_submit_finality_proof_transaction( &self, era: bp_runtime::TransactionEraOf, - transaction_nonce: ::Index, + transaction_nonce: bp_runtime::IndexOf, header: ::Header, proof: ::FinalityProof, ) -> Bytes; diff --git a/relays/lib-substrate-relay/src/messages_lane.rs b/relays/lib-substrate-relay/src/messages_lane.rs index 4614a50883..f1f67d6c6e 100644 --- a/relays/lib-substrate-relay/src/messages_lane.rs +++ b/relays/lib-substrate-relay/src/messages_lane.rs @@ -22,6 +22,7 @@ use crate::on_demand_headers::OnDemandHeadersRelay; use async_trait::async_trait; use bp_messages::{LaneId, MessageNonce}; +use bp_runtime::{AccountIdOf, IndexOf}; use frame_support::weights::Weight; use messages_relay::message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf}; use relay_substrate_client::{ @@ -101,24 +102,24 @@ pub trait SubstrateMessageLane: 'static + Clone + Send + Sync { type TargetChain: Chain; /// Returns id of account that we're using to sign transactions at target chain (messages proof). - fn target_transactions_author(&self) -> ::AccountId; + fn target_transactions_author(&self) -> AccountIdOf; /// Make messages delivery transaction. fn make_messages_delivery_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, generated_at_header: SourceHeaderIdOf, nonces: RangeInclusive, proof: ::MessagesProof, ) -> Bytes; /// Returns id of account that we're using to sign transactions at source chain (delivery proof). - fn source_transactions_author(&self) -> ::AccountId; + fn source_transactions_author(&self) -> AccountIdOf; /// Make messages receiving proof transaction. fn make_messages_receiving_proof_transaction( &self, - transaction_nonce: ::Index, + transaction_nonce: IndexOf, generated_at_header: TargetHeaderIdOf, proof: ::MessagesReceivingProof, ) -> Bytes; diff --git a/relays/lib-substrate-relay/src/messages_target.rs b/relays/lib-substrate-relay/src/messages_target.rs index 20eb7a54b3..ddf2282792 100644 --- a/relays/lib-substrate-relay/src/messages_target.rs +++ b/relays/lib-substrate-relay/src/messages_target.rs @@ -108,7 +108,7 @@ where BlockNumber = ::SourceHeaderNumber, Balance = ::SourceChainBalance, >, - BalanceOf: TryFrom<::Balance> + Bounded, + BalanceOf: TryFrom> + Bounded, P::TargetChain: Chain< Hash = ::TargetHeaderHash, BlockNumber = ::TargetHeaderNumber, @@ -454,7 +454,7 @@ mod tests { fn make_messages_receiving_proof_transaction( &self, - _transaction_nonce: ::Index, + _transaction_nonce: IndexOf, _generated_at_block: TargetHeaderIdOf, _proof: ::MessagesReceivingProof, ) -> Bytes { @@ -467,7 +467,7 @@ mod tests { fn make_messages_delivery_transaction( &self, - _transaction_nonce: ::Index, + _transaction_nonce: IndexOf, _generated_at_header: SourceHeaderIdOf, _nonces: RangeInclusive, _proof: ::MessagesProof,