diff --git a/bridges/relays/bin-substrate/src/cli/estimate_fee.rs b/bridges/relays/bin-substrate/src/cli/estimate_fee.rs index 4e39ad351e..129699c269 100644 --- a/bridges/relays/bin-substrate/src/cli/estimate_fee.rs +++ b/bridges/relays/bin-substrate/src/cli/estimate_fee.rs @@ -18,7 +18,7 @@ use crate::cli::bridge::FullBridge; use crate::cli::{Balance, CliChain, HexBytes, HexLaneId, SourceConnectionParams}; use crate::select_full_bridge; use codec::{Decode, Encode}; -use relay_substrate_client::{Chain, ChainWithBalances}; +use relay_substrate_client::Chain; use structopt::StructOpt; /// Estimate Delivery & Dispatch Fee command. @@ -52,7 +52,7 @@ impl EstimateFee { let lane = lane.into(); let payload = Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?; - let fee: ::NativeBalance = + let fee: ::Balance = estimate_message_delivery_and_dispatch_fee(&source_client, ESTIMATE_MESSAGE_FEE_METHOD, lane, payload) .await?; diff --git a/bridges/relays/bin-substrate/src/cli/send_message.rs b/bridges/relays/bin-substrate/src/cli/send_message.rs index abca740472..f6338dea65 100644 --- a/bridges/relays/bin-substrate/src/cli/send_message.rs +++ b/bridges/relays/bin-substrate/src/cli/send_message.rs @@ -130,11 +130,12 @@ impl SendMessage { let fee = match self.fee { Some(fee) => fee, None => Balance( - estimate_message_delivery_and_dispatch_fee::< - ::NativeBalance, - _, - _, - >(&source_client, ESTIMATE_MESSAGE_FEE_METHOD, lane, payload.clone()) + estimate_message_delivery_and_dispatch_fee::<::Balance, _, _>( + &source_client, + ESTIMATE_MESSAGE_FEE_METHOD, + lane, + payload.clone(), + ) .await? as _, ), }; diff --git a/bridges/relays/client-kusama/src/lib.rs b/bridges/relays/client-kusama/src/lib.rs index 3c3b1cd4c5..f2fba32dc1 100644 --- a/bridges/relays/client-kusama/src/lib.rs +++ b/bridges/relays/client-kusama/src/lib.rs @@ -41,6 +41,7 @@ impl Chain for Kusama { type Index = bp_kusama::Nonce; type SignedBlock = bp_kusama::SignedBlock; type Call = (); + type Balance = bp_kusama::Balance; } /// Kusama header type used in headers sync. diff --git a/bridges/relays/client-millau/src/lib.rs b/bridges/relays/client-millau/src/lib.rs index 1708a8efa1..8597d9e592 100644 --- a/bridges/relays/client-millau/src/lib.rs +++ b/bridges/relays/client-millau/src/lib.rs @@ -44,11 +44,10 @@ impl Chain for Millau { type Index = millau_runtime::Index; type SignedBlock = millau_runtime::SignedBlock; type Call = millau_runtime::Call; + type Balance = millau_runtime::Balance; } impl ChainWithBalances for Millau { - type NativeBalance = millau_runtime::Balance; - fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { use frame_support::storage::generator::StorageMap; StorageKey(frame_system::Account::::storage_map_final_key( diff --git a/bridges/relays/client-polkadot/src/lib.rs b/bridges/relays/client-polkadot/src/lib.rs index 2c117c6d3d..e502463187 100644 --- a/bridges/relays/client-polkadot/src/lib.rs +++ b/bridges/relays/client-polkadot/src/lib.rs @@ -41,6 +41,7 @@ impl Chain for Polkadot { type Index = bp_polkadot::Nonce; type SignedBlock = bp_polkadot::SignedBlock; type Call = (); + type Balance = bp_polkadot::Balance; } /// Polkadot header type used in headers sync. diff --git a/bridges/relays/client-rialto/src/lib.rs b/bridges/relays/client-rialto/src/lib.rs index 0ddc03681d..4a0023a87c 100644 --- a/bridges/relays/client-rialto/src/lib.rs +++ b/bridges/relays/client-rialto/src/lib.rs @@ -44,11 +44,10 @@ impl Chain for Rialto { type Index = rialto_runtime::Index; type SignedBlock = rialto_runtime::SignedBlock; type Call = rialto_runtime::Call; + type Balance = rialto_runtime::Balance; } impl ChainWithBalances for Rialto { - type NativeBalance = rialto_runtime::Balance; - fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { use frame_support::storage::generator::StorageMap; StorageKey(frame_system::Account::::storage_map_final_key( diff --git a/bridges/relays/client-rococo/src/lib.rs b/bridges/relays/client-rococo/src/lib.rs index 09d205f06e..fe9448d19c 100644 --- a/bridges/relays/client-rococo/src/lib.rs +++ b/bridges/relays/client-rococo/src/lib.rs @@ -47,11 +47,10 @@ impl Chain for Rococo { type Index = bp_rococo::Index; type SignedBlock = bp_rococo::SignedBlock; type Call = bp_rococo::Call; + type Balance = bp_rococo::Balance; } impl ChainWithBalances for Rococo { - type NativeBalance = bp_rococo::Balance; - fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { StorageKey(bp_rococo::account_info_storage_key(account_id)) } diff --git a/bridges/relays/client-substrate/src/chain.rs b/bridges/relays/client-substrate/src/chain.rs index 64c0d6af52..ba3634fb6f 100644 --- a/bridges/relays/client-substrate/src/chain.rs +++ b/bridges/relays/client-substrate/src/chain.rs @@ -54,14 +54,16 @@ pub trait Chain: ChainBase + Clone { type SignedBlock: Member + Serialize + DeserializeOwned + BlockWithJustification; /// The aggregated `Call` type. type Call: Dispatchable + Debug; + /// Balance of an account in native tokens. + /// + /// The chain may suport 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: Parameter + Member + DeserializeOwned + Clone + Copy + CheckedSub + PartialOrd + Zero; } /// Substrate-based chain with `frame_system::Config::AccountData` set to -/// the `pallet_balances::AccountData`. +/// the `pallet_balances::AccountData`. pub trait ChainWithBalances: Chain { - /// Balance of an account in native tokens. - type NativeBalance: Parameter + Member + DeserializeOwned + Clone + Copy + CheckedSub + PartialOrd + Zero; - /// Return runtime storage key for getting `frame_system::AccountInfo` of given account. fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey; } diff --git a/bridges/relays/client-substrate/src/client.rs b/bridges/relays/client-substrate/src/client.rs index ec4220158e..f0b7158ecb 100644 --- a/bridges/relays/client-substrate/src/client.rs +++ b/bridges/relays/client-substrate/src/client.rs @@ -208,7 +208,7 @@ impl Client { } /// Return native tokens balance of the account. - pub async fn free_native_balance(&self, account: C::AccountId) -> Result + pub async fn free_native_balance(&self, account: C::AccountId) -> Result where C: ChainWithBalances, { @@ -217,7 +217,7 @@ impl Client { .await? .ok_or(Error::AccountDoesNotExist)?; let decoded_account_data = - AccountInfo::>::decode(&mut &encoded_account_data.0[..]) + AccountInfo::>::decode(&mut &encoded_account_data.0[..]) .map_err(Error::ResponseParseFailed)?; Ok(decoded_account_data.data.free) } diff --git a/bridges/relays/client-substrate/src/guard.rs b/bridges/relays/client-substrate/src/guard.rs index 68fef1c4c9..c6e191ce07 100644 --- a/bridges/relays/client-substrate/src/guard.rs +++ b/bridges/relays/client-substrate/src/guard.rs @@ -33,7 +33,7 @@ pub trait Environment: Send + Sync + 'static { /// Return current runtime version. async fn runtime_version(&mut self) -> Result; /// Return free native balance of the account on the chain. - async fn free_native_balance(&mut self, account: C::AccountId) -> Result; + async fn free_native_balance(&mut self, account: C::AccountId) -> Result; /// Return current time. fn now(&self) -> Instant { @@ -85,7 +85,7 @@ pub fn abort_on_spec_version_change(mut env: impl Environm pub fn abort_when_account_balance_decreased( mut env: impl Environment, account_id: C::AccountId, - maximal_decrease: C::NativeBalance, + maximal_decrease: C::Balance, ) { const DAY: Duration = Duration::from_secs(60 * 60 * 24); @@ -155,7 +155,7 @@ impl Environment for Client { Client::::runtime_version(self).await.map_err(|e| e.to_string()) } - async fn free_native_balance(&mut self, account: C::AccountId) -> Result { + async fn free_native_balance(&mut self, account: C::AccountId) -> Result { Client::::free_native_balance(self, account) .await .map_err(|e| e.to_string()) @@ -191,11 +191,10 @@ mod tests { type SignedBlock = sp_runtime::generic::SignedBlock>; type Call = (); + type Balance = u32; } impl ChainWithBalances for TestChain { - type NativeBalance = u32; - fn account_info_storage_key(_account_id: &u32) -> sp_core::storage::StorageKey { unreachable!() } diff --git a/bridges/relays/client-westend/src/lib.rs b/bridges/relays/client-westend/src/lib.rs index 417938ccf5..6768b81f10 100644 --- a/bridges/relays/client-westend/src/lib.rs +++ b/bridges/relays/client-westend/src/lib.rs @@ -47,11 +47,10 @@ impl Chain for Westend { type Index = bp_westend::Nonce; type SignedBlock = bp_westend::SignedBlock; type Call = bp_westend::Call; + type Balance = bp_westend::Balance; } impl ChainWithBalances for Westend { - type NativeBalance = bp_westend::Balance; - fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { StorageKey(bp_westend::account_info_storage_key(account_id)) } diff --git a/bridges/relays/client-wococo/src/lib.rs b/bridges/relays/client-wococo/src/lib.rs index be2f872b7d..76ecf5b0a5 100644 --- a/bridges/relays/client-wococo/src/lib.rs +++ b/bridges/relays/client-wococo/src/lib.rs @@ -47,11 +47,10 @@ impl Chain for Wococo { type Index = bp_wococo::Index; type SignedBlock = bp_wococo::SignedBlock; type Call = bp_wococo::Call; + type Balance = bp_wococo::Balance; } impl ChainWithBalances for Wococo { - type NativeBalance = bp_wococo::Balance; - fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { StorageKey(bp_wococo::account_info_storage_key(account_id)) }