mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 01:41:03 +00:00
Match substrate's fmt (#1148)
* Alter gitlab. * Use substrate's rustfmt.toml * cargo +nightly fmt --all * Fix spellcheck. * cargo +nightly fmt --all * format. * Fix spellcheck and fmt * fmt? * Fix spellcheck Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
This commit is contained in:
@@ -14,8 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::cli::{bridge::FullBridge, AccountId};
|
||||
use crate::select_full_bridge;
|
||||
use crate::{
|
||||
cli::{bridge::FullBridge, AccountId},
|
||||
select_full_bridge,
|
||||
};
|
||||
use relay_substrate_client::Chain;
|
||||
use structopt::StructOpt;
|
||||
use strum::VariantNames;
|
||||
@@ -55,11 +57,7 @@ impl DeriveAccount {
|
||||
select_full_bridge!(self.bridge, {
|
||||
let (account, derived_account) = self.derive_account();
|
||||
println!("Source address:\n{} ({})", account, Source::NAME);
|
||||
println!(
|
||||
"->Corresponding (derived) address:\n{} ({})",
|
||||
derived_account,
|
||||
Target::NAME,
|
||||
);
|
||||
println!("->Corresponding (derived) address:\n{} ({})", derived_account, Target::NAME,);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
||||
@@ -14,9 +14,12 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::cli::bridge::FullBridge;
|
||||
use crate::cli::{AccountId, Balance, CliChain, ExplicitOrMaximal, HexBytes, HexLaneId};
|
||||
use crate::select_full_bridge;
|
||||
use crate::{
|
||||
cli::{
|
||||
bridge::FullBridge, AccountId, Balance, CliChain, ExplicitOrMaximal, HexBytes, HexLaneId,
|
||||
},
|
||||
select_full_bridge,
|
||||
};
|
||||
use frame_support::weights::DispatchInfo;
|
||||
use relay_substrate_client::Chain;
|
||||
use structopt::StructOpt;
|
||||
@@ -126,31 +129,30 @@ pub(crate) fn preprocess_call<Source: CliEncodeCall + CliChain, Target: CliEncod
|
||||
bridge_instance: u8,
|
||||
) {
|
||||
match *call {
|
||||
Call::Raw { .. } => {}
|
||||
Call::Remark {
|
||||
ref remark_size,
|
||||
ref mut remark_payload,
|
||||
} => {
|
||||
Call::Raw { .. } => {},
|
||||
Call::Remark { ref remark_size, ref mut remark_payload } =>
|
||||
if remark_payload.is_none() {
|
||||
*remark_payload = Some(HexBytes(generate_remark_payload(
|
||||
remark_size,
|
||||
compute_maximal_message_arguments_size(Source::max_extrinsic_size(), Target::max_extrinsic_size()),
|
||||
compute_maximal_message_arguments_size(
|
||||
Source::max_extrinsic_size(),
|
||||
Target::max_extrinsic_size(),
|
||||
),
|
||||
)));
|
||||
}
|
||||
}
|
||||
},
|
||||
Call::Transfer { ref mut recipient, .. } => {
|
||||
recipient.enforce_chain::<Source>();
|
||||
}
|
||||
Call::BridgeSendMessage {
|
||||
ref mut bridge_instance_index,
|
||||
..
|
||||
} => {
|
||||
},
|
||||
Call::BridgeSendMessage { ref mut bridge_instance_index, .. } => {
|
||||
*bridge_instance_index = bridge_instance;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
fn generate_remark_payload(remark_size: &Option<ExplicitOrMaximal<usize>>, maximal_allowed_size: u32) -> Vec<u8> {
|
||||
fn generate_remark_payload(
|
||||
remark_size: &Option<ExplicitOrMaximal<usize>>,
|
||||
maximal_allowed_size: u32,
|
||||
) -> Vec<u8> {
|
||||
match remark_size {
|
||||
Some(ExplicitOrMaximal::Explicit(remark_size)) => vec![0; *remark_size],
|
||||
Some(ExplicitOrMaximal::Maximal) => vec![0; maximal_allowed_size as _],
|
||||
@@ -172,9 +174,11 @@ pub(crate) fn compute_maximal_message_arguments_size(
|
||||
) -> u32 {
|
||||
// assume that both signed extensions and other arguments fit 1KB
|
||||
let service_tx_bytes_on_source_chain = 1024;
|
||||
let maximal_source_extrinsic_size = maximal_source_extrinsic_size - service_tx_bytes_on_source_chain;
|
||||
let maximal_call_size =
|
||||
bridge_runtime_common::messages::target::maximal_incoming_message_size(maximal_target_extrinsic_size);
|
||||
let maximal_source_extrinsic_size =
|
||||
maximal_source_extrinsic_size - service_tx_bytes_on_source_chain;
|
||||
let maximal_call_size = bridge_runtime_common::messages::target::maximal_incoming_message_size(
|
||||
maximal_target_extrinsic_size,
|
||||
);
|
||||
let maximal_call_size = if maximal_call_size > maximal_source_extrinsic_size {
|
||||
maximal_source_extrinsic_size
|
||||
} else {
|
||||
@@ -217,7 +221,8 @@ mod tests {
|
||||
#[test]
|
||||
fn should_encode_remark_with_default_payload() {
|
||||
// given
|
||||
let mut encode_call = EncodeCall::from_iter(vec!["encode-call", "rialto-to-millau", "remark"]);
|
||||
let mut encode_call =
|
||||
EncodeCall::from_iter(vec!["encode-call", "rialto-to-millau", "remark"]);
|
||||
|
||||
// when
|
||||
let hex = encode_call.encode().unwrap();
|
||||
@@ -247,8 +252,13 @@ mod tests {
|
||||
#[test]
|
||||
fn should_encode_remark_with_size() {
|
||||
// given
|
||||
let mut encode_call =
|
||||
EncodeCall::from_iter(vec!["encode-call", "rialto-to-millau", "remark", "--remark-size", "12"]);
|
||||
let mut encode_call = EncodeCall::from_iter(vec![
|
||||
"encode-call",
|
||||
"rialto-to-millau",
|
||||
"remark",
|
||||
"--remark-size",
|
||||
"12",
|
||||
]);
|
||||
|
||||
// when
|
||||
let hex = encode_call.encode().unwrap();
|
||||
@@ -275,7 +285,10 @@ mod tests {
|
||||
assert_eq!(err.kind, structopt::clap::ErrorKind::ArgumentConflict);
|
||||
|
||||
let info = err.info.unwrap();
|
||||
assert!(info.contains(&"remark-payload".to_string()) | info.contains(&"remark-size".to_string()))
|
||||
assert!(
|
||||
info.contains(&"remark-payload".to_string()) |
|
||||
info.contains(&"remark-size".to_string())
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::cli::{bridge::FullBridge, AccountId, CliChain, HexBytes};
|
||||
use crate::select_full_bridge;
|
||||
use crate::{
|
||||
cli::{bridge::FullBridge, AccountId, CliChain, HexBytes},
|
||||
select_full_bridge,
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
use strum::VariantNames;
|
||||
|
||||
@@ -52,7 +54,8 @@ impl EncodeMessage {
|
||||
/// Run the command.
|
||||
pub fn encode(self) -> anyhow::Result<HexBytes> {
|
||||
select_full_bridge!(self.bridge, {
|
||||
let payload = Source::encode_message(self.payload).map_err(|e| anyhow::format_err!("{}", e))?;
|
||||
let payload =
|
||||
Source::encode_message(self.payload).map_err(|e| anyhow::format_err!("{}", e))?;
|
||||
Ok(HexBytes::encode(&payload))
|
||||
})
|
||||
}
|
||||
@@ -74,7 +77,8 @@ mod tests {
|
||||
fn should_encode_raw_message() {
|
||||
// given
|
||||
let msg = "01000000e88514000000000002d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003c040130000000000000000000000000";
|
||||
let encode_message = EncodeMessage::from_iter(vec!["encode-message", "rialto-to-millau", "raw", msg]);
|
||||
let encode_message =
|
||||
EncodeMessage::from_iter(vec!["encode-message", "rialto-to-millau", "raw", msg]);
|
||||
|
||||
// when
|
||||
let hex = encode_message.encode().unwrap();
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::cli::bridge::FullBridge;
|
||||
use crate::cli::{Balance, CliChain, HexBytes, HexLaneId, SourceConnectionParams};
|
||||
use crate::select_full_bridge;
|
||||
use crate::{
|
||||
cli::{bridge::FullBridge, Balance, CliChain, HexBytes, HexLaneId, SourceConnectionParams},
|
||||
select_full_bridge,
|
||||
};
|
||||
use bp_runtime::BalanceOf;
|
||||
use codec::{Decode, Encode};
|
||||
use relay_substrate_client::Chain;
|
||||
@@ -42,21 +43,21 @@ pub struct EstimateFee {
|
||||
impl EstimateFee {
|
||||
/// Run the command.
|
||||
pub async fn run(self) -> anyhow::Result<()> {
|
||||
let Self {
|
||||
source,
|
||||
bridge,
|
||||
lane,
|
||||
payload,
|
||||
} = self;
|
||||
let Self { source, bridge, lane, payload } = self;
|
||||
|
||||
select_full_bridge!(bridge, {
|
||||
let source_client = source.to_client::<Source>().await?;
|
||||
let lane = lane.into();
|
||||
let payload = Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?;
|
||||
let payload =
|
||||
Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?;
|
||||
|
||||
let fee: BalanceOf<Source> =
|
||||
estimate_message_delivery_and_dispatch_fee(&source_client, ESTIMATE_MESSAGE_FEE_METHOD, lane, payload)
|
||||
.await?;
|
||||
let fee: BalanceOf<Source> = estimate_message_delivery_and_dispatch_fee(
|
||||
&source_client,
|
||||
ESTIMATE_MESSAGE_FEE_METHOD,
|
||||
lane,
|
||||
payload,
|
||||
)
|
||||
.await?;
|
||||
|
||||
log::info!(target: "bridge", "Fee: {:?}", Balance(fee as _));
|
||||
println!("{}", fee);
|
||||
@@ -74,10 +75,11 @@ pub(crate) async fn estimate_message_delivery_and_dispatch_fee<Fee: Decode, C: C
|
||||
let encoded_response = client
|
||||
.state_call(estimate_fee_method.into(), (lane, payload).encode().into(), None)
|
||||
.await?;
|
||||
let decoded_response: Option<Fee> =
|
||||
Decode::decode(&mut &encoded_response.0[..]).map_err(relay_substrate_client::Error::ResponseParseFailed)?;
|
||||
let fee = decoded_response
|
||||
.ok_or_else(|| anyhow::format_err!("Unable to decode fee from: {:?}", HexBytes(encoded_response.to_vec())))?;
|
||||
let decoded_response: Option<Fee> = Decode::decode(&mut &encoded_response.0[..])
|
||||
.map_err(relay_substrate_client::Error::ResponseParseFailed)?;
|
||||
let fee = decoded_response.ok_or_else(|| {
|
||||
anyhow::format_err!("Unable to decode fee from: {:?}", HexBytes(encoded_response.to_vec()))
|
||||
})?;
|
||||
Ok(fee)
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ macro_rules! select_bridge {
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
InitBridgeName::RialtoToMillau => {
|
||||
type Source = relay_rialto_client::Rialto;
|
||||
type Target = relay_millau_client::Millau;
|
||||
@@ -83,7 +83,7 @@ macro_rules! select_bridge {
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
InitBridgeName::WestendToMillau => {
|
||||
type Source = relay_westend_client::Westend;
|
||||
type Target = relay_millau_client::Millau;
|
||||
@@ -91,9 +91,10 @@ macro_rules! select_bridge {
|
||||
fn encode_init_bridge(
|
||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||
) -> <Target as Chain>::Call {
|
||||
// at Westend -> Millau initialization we're not using sudo, because otherwise our deployments
|
||||
// may fail, because we need to initialize both Rialto -> Millau and Westend -> Millau bridge.
|
||||
// => since there's single possible sudo account, one of transaction may fail with duplicate nonce error
|
||||
// at Westend -> Millau initialization we're not using sudo, because otherwise
|
||||
// our deployments may fail, because we need to initialize both Rialto -> Millau
|
||||
// and Westend -> Millau bridge. => since there's single possible sudo account,
|
||||
// one of transaction may fail with duplicate nonce error
|
||||
millau_runtime::BridgeGrandpaWestendCall::<
|
||||
millau_runtime::Runtime,
|
||||
millau_runtime::WestendGrandpaInstance,
|
||||
@@ -102,7 +103,7 @@ macro_rules! select_bridge {
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
InitBridgeName::RococoToWococo => {
|
||||
type Source = relay_rococo_client::Rococo;
|
||||
type Target = relay_wococo_client::Wococo;
|
||||
@@ -111,12 +112,14 @@ macro_rules! select_bridge {
|
||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||
) -> <Target as Chain>::Call {
|
||||
relay_wococo_client::runtime::Call::BridgeGrandpaRococo(
|
||||
relay_wococo_client::runtime::BridgeGrandpaRococoCall::initialize(init_data),
|
||||
relay_wococo_client::runtime::BridgeGrandpaRococoCall::initialize(
|
||||
init_data,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
InitBridgeName::WococoToRococo => {
|
||||
type Source = relay_wococo_client::Wococo;
|
||||
type Target = relay_rococo_client::Rococo;
|
||||
@@ -125,12 +128,14 @@ macro_rules! select_bridge {
|
||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||
) -> <Target as Chain>::Call {
|
||||
relay_rococo_client::runtime::Call::BridgeGrandpaWococo(
|
||||
relay_rococo_client::runtime::BridgeGrandpaWococoCall::initialize(init_data),
|
||||
relay_rococo_client::runtime::BridgeGrandpaWococoCall::initialize(
|
||||
init_data,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
InitBridgeName::KusamaToPolkadot => {
|
||||
type Source = relay_kusama_client::Kusama;
|
||||
type Target = relay_polkadot_client::Polkadot;
|
||||
@@ -139,12 +144,14 @@ macro_rules! select_bridge {
|
||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||
) -> <Target as Chain>::Call {
|
||||
relay_polkadot_client::runtime::Call::BridgeKusamaGrandpa(
|
||||
relay_polkadot_client::runtime::BridgeKusamaGrandpaCall::initialize(init_data),
|
||||
relay_polkadot_client::runtime::BridgeKusamaGrandpaCall::initialize(
|
||||
init_data,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
InitBridgeName::PolkadotToKusama => {
|
||||
type Source = relay_polkadot_client::Polkadot;
|
||||
type Target = relay_kusama_client::Kusama;
|
||||
@@ -153,12 +160,14 @@ macro_rules! select_bridge {
|
||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||
) -> <Target as Chain>::Call {
|
||||
relay_kusama_client::runtime::Call::BridgePolkadotGrandpa(
|
||||
relay_kusama_client::runtime::BridgePolkadotGrandpaCall::initialize(init_data),
|
||||
relay_kusama_client::runtime::BridgePolkadotGrandpaCall::initialize(
|
||||
init_data,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -181,7 +190,10 @@ impl InitBridge {
|
||||
*target_client.genesis_hash(),
|
||||
&target_sign,
|
||||
relay_substrate_client::TransactionEra::immortal(),
|
||||
UnsignedTransaction::new(encode_init_bridge(initialization_data), transaction_nonce),
|
||||
UnsignedTransaction::new(
|
||||
encode_init_bridge(initialization_data),
|
||||
transaction_nonce,
|
||||
),
|
||||
)
|
||||
.encode(),
|
||||
)
|
||||
|
||||
@@ -86,7 +86,8 @@ pub enum Command {
|
||||
EncodeMessage(encode_message::EncodeMessage),
|
||||
/// Estimate Delivery and Dispatch Fee required for message submission to messages pallet.
|
||||
EstimateFee(estimate_fee::EstimateFee),
|
||||
/// Given a source chain `AccountId`, derive the corresponding `AccountId` for the target chain.
|
||||
/// Given a source chain `AccountId`, derive the corresponding `AccountId` for the target
|
||||
/// chain.
|
||||
DeriveAccount(derive_account::DeriveAccount),
|
||||
/// Resubmit transactions with increased tip if they are stalled.
|
||||
ResubmitTransactions(resubmit_transactions::ResubmitTransactions),
|
||||
@@ -100,12 +101,15 @@ impl Command {
|
||||
use relay_utils::initialize::{initialize_logger, initialize_relay};
|
||||
|
||||
match self {
|
||||
Self::RelayHeaders(_) | Self::RelayMessages(_) | Self::RelayHeadersAndMessages(_) | Self::InitBridge(_) => {
|
||||
Self::RelayHeaders(_) |
|
||||
Self::RelayMessages(_) |
|
||||
Self::RelayHeadersAndMessages(_) |
|
||||
Self::InitBridge(_) => {
|
||||
initialize_relay();
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
initialize_logger(false);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,10 +199,7 @@ const SS58_FORMAT_PROOF: &str = "u16 -> Ss58Format is infallible; qed";
|
||||
impl AccountId {
|
||||
/// Create new SS58-formatted address from raw account id.
|
||||
pub fn from_raw<T: CliChain>(account: sp_runtime::AccountId32) -> Self {
|
||||
Self {
|
||||
account,
|
||||
ss58_format: T::ss58_format().try_into().expect(SS58_FORMAT_PROOF),
|
||||
}
|
||||
Self { account, ss58_format: T::ss58_format().try_into().expect(SS58_FORMAT_PROOF) }
|
||||
}
|
||||
|
||||
/// Enforces formatting account to be for given [`CliChain`] type.
|
||||
@@ -236,7 +237,7 @@ pub trait CliChain: relay_substrate_client::Chain {
|
||||
/// Chain's current version of the runtime.
|
||||
const RUNTIME_VERSION: sp_version::RuntimeVersion;
|
||||
|
||||
/// Crypto keypair type used to send messages.
|
||||
/// Crypto KeyPair type used to send messages.
|
||||
///
|
||||
/// In case of chains supporting multiple cryptos, pick one used by the CLI.
|
||||
type KeyPair: sp_core::crypto::Pair;
|
||||
@@ -250,7 +251,9 @@ pub trait CliChain: relay_substrate_client::Chain {
|
||||
fn ss58_format() -> u16;
|
||||
|
||||
/// Construct message payload to be sent over the bridge.
|
||||
fn encode_message(message: crate::cli::encode_message::MessagePayload) -> Result<Self::MessagePayload, String>;
|
||||
fn encode_message(
|
||||
message: crate::cli::encode_message::MessagePayload,
|
||||
) -> Result<Self::MessagePayload, String>;
|
||||
|
||||
/// Maximal extrinsic weight (from the runtime).
|
||||
fn max_extrinsic_weight() -> Weight;
|
||||
@@ -352,7 +355,7 @@ where
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
if s.to_lowercase() == "max" {
|
||||
return Ok(ExplicitOrMaximal::Maximal);
|
||||
return Ok(ExplicitOrMaximal::Maximal)
|
||||
}
|
||||
|
||||
V::from_str(s)
|
||||
@@ -531,10 +534,7 @@ mod tests {
|
||||
let expected = vec![rialto1, rialto2, millau1, millau2];
|
||||
|
||||
// when
|
||||
let parsed = expected
|
||||
.iter()
|
||||
.map(|s| AccountId::from_str(s).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
let parsed = expected.iter().map(|s| AccountId::from_str(s).unwrap()).collect::<Vec<_>>();
|
||||
|
||||
let actual = parsed.iter().map(|a| format!("{}", a)).collect::<Vec<_>>();
|
||||
|
||||
@@ -563,7 +563,8 @@ mod tests {
|
||||
|
||||
let alice = sp_core::sr25519::Pair::from_string(ALICE, Some(ALICE_PASSWORD)).unwrap();
|
||||
let bob = sp_core::sr25519::Pair::from_string(BOB, Some(BOB_PASSWORD)).unwrap();
|
||||
let bob_with_alice_password = sp_core::sr25519::Pair::from_string(BOB, Some(ALICE_PASSWORD)).unwrap();
|
||||
let bob_with_alice_password =
|
||||
sp_core::sr25519::Pair::from_string(BOB, Some(ALICE_PASSWORD)).unwrap();
|
||||
|
||||
let temp_dir = tempdir::TempDir::new("reads_suri_from_file").unwrap();
|
||||
let mut suri_file_path = temp_dir.path().to_path_buf();
|
||||
|
||||
@@ -19,7 +19,9 @@ use strum::{EnumString, EnumVariantNames, VariantNames};
|
||||
|
||||
use substrate_relay_helper::finality_pipeline::SubstrateFinalitySyncPipeline;
|
||||
|
||||
use crate::cli::{PrometheusParams, SourceConnectionParams, TargetConnectionParams, TargetSigningParams};
|
||||
use crate::cli::{
|
||||
PrometheusParams, SourceConnectionParams, TargetConnectionParams, TargetSigningParams,
|
||||
};
|
||||
|
||||
/// Start headers relayer process.
|
||||
#[derive(StructOpt)]
|
||||
@@ -27,7 +29,8 @@ pub struct RelayHeaders {
|
||||
/// A bridge instance to relay headers for.
|
||||
#[structopt(possible_values = RelayHeadersBridge::VARIANTS, case_insensitive = true)]
|
||||
bridge: RelayHeadersBridge,
|
||||
/// If passed, only mandatory headers (headers that are changing the GRANDPA authorities set) are relayed.
|
||||
/// If passed, only mandatory headers (headers that are changing the GRANDPA authorities set)
|
||||
/// are relayed.
|
||||
#[structopt(long)]
|
||||
only_mandatory_headers: bool,
|
||||
#[structopt(flatten)]
|
||||
@@ -62,49 +65,49 @@ macro_rules! select_bridge {
|
||||
type Finality = crate::chains::millau_headers_to_rialto::MillauFinalityToRialto;
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
RelayHeadersBridge::RialtoToMillau => {
|
||||
type Source = relay_rialto_client::Rialto;
|
||||
type Target = relay_millau_client::Millau;
|
||||
type Finality = crate::chains::rialto_headers_to_millau::RialtoFinalityToMillau;
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
RelayHeadersBridge::WestendToMillau => {
|
||||
type Source = relay_westend_client::Westend;
|
||||
type Target = relay_millau_client::Millau;
|
||||
type Finality = crate::chains::westend_headers_to_millau::WestendFinalityToMillau;
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
RelayHeadersBridge::RococoToWococo => {
|
||||
type Source = relay_rococo_client::Rococo;
|
||||
type Target = relay_wococo_client::Wococo;
|
||||
type Finality = crate::chains::rococo_headers_to_wococo::RococoFinalityToWococo;
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
RelayHeadersBridge::WococoToRococo => {
|
||||
type Source = relay_wococo_client::Wococo;
|
||||
type Target = relay_rococo_client::Rococo;
|
||||
type Finality = crate::chains::wococo_headers_to_rococo::WococoFinalityToRococo;
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
RelayHeadersBridge::KusamaToPolkadot => {
|
||||
type Source = relay_kusama_client::Kusama;
|
||||
type Target = relay_polkadot_client::Polkadot;
|
||||
type Finality = crate::chains::kusama_headers_to_polkadot::KusamaFinalityToPolkadot;
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
RelayHeadersBridge::PolkadotToKusama => {
|
||||
type Source = relay_polkadot_client::Polkadot;
|
||||
type Target = relay_kusama_client::Kusama;
|
||||
type Finality = crate::chains::polkadot_headers_to_kusama::PolkadotFinalityToKusama;
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,14 +27,20 @@ use structopt::StructOpt;
|
||||
use strum::VariantNames;
|
||||
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{AccountIdOf, Chain, Client, TransactionSignScheme, UnsignedTransaction};
|
||||
use relay_substrate_client::{
|
||||
AccountIdOf, Chain, Client, TransactionSignScheme, UnsignedTransaction,
|
||||
};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use sp_core::{Bytes, Pair};
|
||||
use substrate_relay_helper::messages_lane::{MessagesRelayParams, SubstrateMessageLane};
|
||||
use substrate_relay_helper::on_demand_headers::OnDemandHeadersRelay;
|
||||
use substrate_relay_helper::{
|
||||
messages_lane::{MessagesRelayParams, SubstrateMessageLane},
|
||||
on_demand_headers::OnDemandHeadersRelay,
|
||||
};
|
||||
|
||||
use crate::cli::{relay_messages::RelayerMode, CliChain, HexLaneId, PrometheusParams};
|
||||
use crate::declare_chain_options;
|
||||
use crate::{
|
||||
cli::{relay_messages::RelayerMode, CliChain, HexLaneId, PrometheusParams},
|
||||
declare_chain_options,
|
||||
};
|
||||
|
||||
/// Maximal allowed conversion rate error ratio (abs(real - stored) / stored) that we allow.
|
||||
///
|
||||
@@ -63,16 +69,17 @@ pub struct HeadersAndMessagesSharedParams {
|
||||
/// Create relayers fund accounts on both chains, if it does not exists yet.
|
||||
#[structopt(long)]
|
||||
create_relayers_fund_accounts: bool,
|
||||
/// If passed, only mandatory headers (headers that are changing the GRANDPA authorities set) are relayed.
|
||||
/// If passed, only mandatory headers (headers that are changing the GRANDPA authorities set)
|
||||
/// are relayed.
|
||||
#[structopt(long)]
|
||||
only_mandatory_headers: bool,
|
||||
#[structopt(flatten)]
|
||||
prometheus_params: PrometheusParams,
|
||||
}
|
||||
|
||||
// The reason behind this macro is that 'normal' relays are using source and target chains terminology,
|
||||
// which is unusable for both-way relays (if you're relaying headers from Rialto to Millau and from
|
||||
// Millau to Rialto, then which chain is source?).
|
||||
// The reason behind this macro is that 'normal' relays are using source and target chains
|
||||
// terminology, which is unusable for both-way relays (if you're relaying headers from Rialto to
|
||||
// Millau and from Millau to Rialto, then which chain is source?).
|
||||
macro_rules! declare_bridge_options {
|
||||
($chain1:ident, $chain2:ident) => {
|
||||
paste::item! {
|
||||
@@ -116,25 +123,35 @@ macro_rules! select_bridge {
|
||||
type Left = relay_millau_client::Millau;
|
||||
type Right = relay_rialto_client::Rialto;
|
||||
|
||||
type LeftToRightFinality = crate::chains::millau_headers_to_rialto::MillauFinalityToRialto;
|
||||
type RightToLeftFinality = crate::chains::rialto_headers_to_millau::RialtoFinalityToMillau;
|
||||
type LeftToRightFinality =
|
||||
crate::chains::millau_headers_to_rialto::MillauFinalityToRialto;
|
||||
type RightToLeftFinality =
|
||||
crate::chains::rialto_headers_to_millau::RialtoFinalityToMillau;
|
||||
|
||||
type LeftToRightMessages = crate::chains::millau_messages_to_rialto::MillauMessagesToRialto;
|
||||
type RightToLeftMessages = crate::chains::rialto_messages_to_millau::RialtoMessagesToMillau;
|
||||
type LeftToRightMessages =
|
||||
crate::chains::millau_messages_to_rialto::MillauMessagesToRialto;
|
||||
type RightToLeftMessages =
|
||||
crate::chains::rialto_messages_to_millau::RialtoMessagesToMillau;
|
||||
|
||||
type LeftAccountIdConverter = bp_millau::AccountIdConverter;
|
||||
type RightAccountIdConverter = bp_rialto::AccountIdConverter;
|
||||
|
||||
const MAX_MISSING_LEFT_HEADERS_AT_RIGHT: bp_millau::BlockNumber = bp_millau::SESSION_LENGTH;
|
||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_rialto::BlockNumber = bp_rialto::SESSION_LENGTH;
|
||||
const MAX_MISSING_LEFT_HEADERS_AT_RIGHT: bp_millau::BlockNumber =
|
||||
bp_millau::SESSION_LENGTH;
|
||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_rialto::BlockNumber =
|
||||
bp_rialto::SESSION_LENGTH;
|
||||
|
||||
use crate::chains::millau_messages_to_rialto::{
|
||||
add_standalone_metrics as add_left_to_right_standalone_metrics, run as left_to_right_messages,
|
||||
update_rialto_to_millau_conversion_rate as update_right_to_left_conversion_rate,
|
||||
};
|
||||
use crate::chains::rialto_messages_to_millau::{
|
||||
add_standalone_metrics as add_right_to_left_standalone_metrics, run as right_to_left_messages,
|
||||
update_millau_to_rialto_conversion_rate as update_left_to_right_conversion_rate,
|
||||
use crate::chains::{
|
||||
millau_messages_to_rialto::{
|
||||
add_standalone_metrics as add_left_to_right_standalone_metrics,
|
||||
run as left_to_right_messages,
|
||||
update_rialto_to_millau_conversion_rate as update_right_to_left_conversion_rate,
|
||||
},
|
||||
rialto_messages_to_millau::{
|
||||
add_standalone_metrics as add_right_to_left_standalone_metrics,
|
||||
run as right_to_left_messages,
|
||||
update_millau_to_rialto_conversion_rate as update_left_to_right_conversion_rate,
|
||||
},
|
||||
};
|
||||
|
||||
async fn left_create_account(
|
||||
@@ -154,30 +171,40 @@ macro_rules! select_bridge {
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
RelayHeadersAndMessages::RococoWococo(_) => {
|
||||
type Params = RococoWococoHeadersAndMessages;
|
||||
|
||||
type Left = relay_rococo_client::Rococo;
|
||||
type Right = relay_wococo_client::Wococo;
|
||||
|
||||
type LeftToRightFinality = crate::chains::rococo_headers_to_wococo::RococoFinalityToWococo;
|
||||
type RightToLeftFinality = crate::chains::wococo_headers_to_rococo::WococoFinalityToRococo;
|
||||
type LeftToRightFinality =
|
||||
crate::chains::rococo_headers_to_wococo::RococoFinalityToWococo;
|
||||
type RightToLeftFinality =
|
||||
crate::chains::wococo_headers_to_rococo::WococoFinalityToRococo;
|
||||
|
||||
type LeftToRightMessages = crate::chains::rococo_messages_to_wococo::RococoMessagesToWococo;
|
||||
type RightToLeftMessages = crate::chains::wococo_messages_to_rococo::WococoMessagesToRococo;
|
||||
type LeftToRightMessages =
|
||||
crate::chains::rococo_messages_to_wococo::RococoMessagesToWococo;
|
||||
type RightToLeftMessages =
|
||||
crate::chains::wococo_messages_to_rococo::WococoMessagesToRococo;
|
||||
|
||||
type LeftAccountIdConverter = bp_rococo::AccountIdConverter;
|
||||
type RightAccountIdConverter = bp_wococo::AccountIdConverter;
|
||||
|
||||
const MAX_MISSING_LEFT_HEADERS_AT_RIGHT: bp_rococo::BlockNumber = bp_rococo::SESSION_LENGTH;
|
||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_wococo::BlockNumber = bp_wococo::SESSION_LENGTH;
|
||||
const MAX_MISSING_LEFT_HEADERS_AT_RIGHT: bp_rococo::BlockNumber =
|
||||
bp_rococo::SESSION_LENGTH;
|
||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_wococo::BlockNumber =
|
||||
bp_wococo::SESSION_LENGTH;
|
||||
|
||||
use crate::chains::rococo_messages_to_wococo::{
|
||||
add_standalone_metrics as add_left_to_right_standalone_metrics, run as left_to_right_messages,
|
||||
};
|
||||
use crate::chains::wococo_messages_to_rococo::{
|
||||
add_standalone_metrics as add_right_to_left_standalone_metrics, run as right_to_left_messages,
|
||||
use crate::chains::{
|
||||
rococo_messages_to_wococo::{
|
||||
add_standalone_metrics as add_left_to_right_standalone_metrics,
|
||||
run as left_to_right_messages,
|
||||
},
|
||||
wococo_messages_to_rococo::{
|
||||
add_standalone_metrics as add_right_to_left_standalone_metrics,
|
||||
run as right_to_left_messages,
|
||||
},
|
||||
};
|
||||
|
||||
async fn update_right_to_left_conversion_rate(
|
||||
@@ -213,32 +240,42 @@ macro_rules! select_bridge {
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
RelayHeadersAndMessages::KusamaPolkadot(_) => {
|
||||
type Params = KusamaPolkadotHeadersAndMessages;
|
||||
|
||||
type Left = relay_kusama_client::Kusama;
|
||||
type Right = relay_polkadot_client::Polkadot;
|
||||
|
||||
type LeftToRightFinality = crate::chains::kusama_headers_to_polkadot::KusamaFinalityToPolkadot;
|
||||
type RightToLeftFinality = crate::chains::polkadot_headers_to_kusama::PolkadotFinalityToKusama;
|
||||
type LeftToRightFinality =
|
||||
crate::chains::kusama_headers_to_polkadot::KusamaFinalityToPolkadot;
|
||||
type RightToLeftFinality =
|
||||
crate::chains::polkadot_headers_to_kusama::PolkadotFinalityToKusama;
|
||||
|
||||
type LeftToRightMessages = crate::chains::kusama_messages_to_polkadot::KusamaMessagesToPolkadot;
|
||||
type RightToLeftMessages = crate::chains::polkadot_messages_to_kusama::PolkadotMessagesToKusama;
|
||||
type LeftToRightMessages =
|
||||
crate::chains::kusama_messages_to_polkadot::KusamaMessagesToPolkadot;
|
||||
type RightToLeftMessages =
|
||||
crate::chains::polkadot_messages_to_kusama::PolkadotMessagesToKusama;
|
||||
|
||||
type LeftAccountIdConverter = bp_kusama::AccountIdConverter;
|
||||
type RightAccountIdConverter = bp_polkadot::AccountIdConverter;
|
||||
|
||||
const MAX_MISSING_LEFT_HEADERS_AT_RIGHT: bp_kusama::BlockNumber = bp_kusama::SESSION_LENGTH;
|
||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_polkadot::BlockNumber = bp_polkadot::SESSION_LENGTH;
|
||||
const MAX_MISSING_LEFT_HEADERS_AT_RIGHT: bp_kusama::BlockNumber =
|
||||
bp_kusama::SESSION_LENGTH;
|
||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_polkadot::BlockNumber =
|
||||
bp_polkadot::SESSION_LENGTH;
|
||||
|
||||
use crate::chains::kusama_messages_to_polkadot::{
|
||||
add_standalone_metrics as add_left_to_right_standalone_metrics, run as left_to_right_messages,
|
||||
update_polkadot_to_kusama_conversion_rate as update_right_to_left_conversion_rate,
|
||||
};
|
||||
use crate::chains::polkadot_messages_to_kusama::{
|
||||
add_standalone_metrics as add_right_to_left_standalone_metrics, run as right_to_left_messages,
|
||||
update_kusama_to_polkadot_conversion_rate as update_left_to_right_conversion_rate,
|
||||
use crate::chains::{
|
||||
kusama_messages_to_polkadot::{
|
||||
add_standalone_metrics as add_left_to_right_standalone_metrics,
|
||||
run as left_to_right_messages,
|
||||
update_polkadot_to_kusama_conversion_rate as update_right_to_left_conversion_rate,
|
||||
},
|
||||
polkadot_messages_to_kusama::{
|
||||
add_standalone_metrics as add_right_to_left_standalone_metrics,
|
||||
run as right_to_left_messages,
|
||||
update_kusama_to_polkadot_conversion_rate as update_left_to_right_conversion_rate,
|
||||
},
|
||||
};
|
||||
|
||||
async fn left_create_account(
|
||||
@@ -248,25 +285,24 @@ macro_rules! select_bridge {
|
||||
) -> anyhow::Result<()> {
|
||||
let left_genesis_hash = *left_client.genesis_hash();
|
||||
left_client
|
||||
.submit_signed_extrinsic(left_sign.public().into(), move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Left::sign_transaction(
|
||||
left_genesis_hash,
|
||||
&left_sign,
|
||||
relay_substrate_client::TransactionEra::immortal(),
|
||||
UnsignedTransaction::new(
|
||||
relay_kusama_client::runtime::Call::Balances(
|
||||
relay_kusama_client::runtime::BalancesCall::transfer(
|
||||
bp_kusama::AccountAddress::Id(account_id),
|
||||
bp_kusama::EXISTENTIAL_DEPOSIT.into(),
|
||||
.submit_signed_extrinsic(
|
||||
left_sign.public().into(),
|
||||
move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Left::sign_transaction(left_genesis_hash, &left_sign, relay_substrate_client::TransactionEra::immortal(),
|
||||
UnsignedTransaction::new(
|
||||
relay_kusama_client::runtime::Call::Balances(
|
||||
relay_kusama_client::runtime::BalancesCall::transfer(
|
||||
bp_kusama::AccountAddress::Id(account_id),
|
||||
bp_kusama::EXISTENTIAL_DEPOSIT.into(),
|
||||
),
|
||||
),
|
||||
transaction_nonce,
|
||||
),
|
||||
transaction_nonce,
|
||||
),
|
||||
).encode()
|
||||
)
|
||||
.encode(),
|
||||
)
|
||||
})
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map(drop)
|
||||
.map_err(|e| anyhow::format_err!("{}", e))
|
||||
@@ -279,32 +315,31 @@ macro_rules! select_bridge {
|
||||
) -> anyhow::Result<()> {
|
||||
let right_genesis_hash = *right_client.genesis_hash();
|
||||
right_client
|
||||
.submit_signed_extrinsic(right_sign.public().into(), move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Right::sign_transaction(
|
||||
right_genesis_hash,
|
||||
&right_sign,
|
||||
relay_substrate_client::TransactionEra::immortal(),
|
||||
UnsignedTransaction::new(
|
||||
relay_polkadot_client::runtime::Call::Balances(
|
||||
relay_polkadot_client::runtime::BalancesCall::transfer(
|
||||
bp_polkadot::AccountAddress::Id(account_id),
|
||||
bp_polkadot::EXISTENTIAL_DEPOSIT.into(),
|
||||
.submit_signed_extrinsic(
|
||||
right_sign.public().into(),
|
||||
move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Right::sign_transaction(right_genesis_hash, &right_sign, relay_substrate_client::TransactionEra::immortal(),
|
||||
UnsignedTransaction::new(
|
||||
relay_polkadot_client::runtime::Call::Balances(
|
||||
relay_polkadot_client::runtime::BalancesCall::transfer(
|
||||
bp_polkadot::AccountAddress::Id(account_id),
|
||||
bp_polkadot::EXISTENTIAL_DEPOSIT.into(),
|
||||
),
|
||||
),
|
||||
transaction_nonce,
|
||||
),
|
||||
transaction_nonce,
|
||||
),
|
||||
).encode()
|
||||
)
|
||||
.encode(),
|
||||
)
|
||||
})
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map(drop)
|
||||
.map_err(|e| anyhow::format_err!("{}", e))
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -330,16 +365,19 @@ impl RelayHeadersAndMessages {
|
||||
let left_client = params.left.to_client::<Left>().await?;
|
||||
let left_transactions_mortality = params.left_sign.transactions_mortality()?;
|
||||
let left_sign = params.left_sign.to_keypair::<Left>()?;
|
||||
let left_messages_pallet_owner = params.left_messages_pallet_owner.to_keypair::<Left>()?;
|
||||
let left_messages_pallet_owner =
|
||||
params.left_messages_pallet_owner.to_keypair::<Left>()?;
|
||||
let right_client = params.right.to_client::<Right>().await?;
|
||||
let right_transactions_mortality = params.right_sign.transactions_mortality()?;
|
||||
let right_sign = params.right_sign.to_keypair::<Right>()?;
|
||||
let right_messages_pallet_owner = params.right_messages_pallet_owner.to_keypair::<Right>()?;
|
||||
let right_messages_pallet_owner =
|
||||
params.right_messages_pallet_owner.to_keypair::<Right>()?;
|
||||
|
||||
let lanes = params.shared.lane;
|
||||
let relayer_mode = params.shared.relayer_mode.into();
|
||||
|
||||
const METRIC_IS_SOME_PROOF: &str = "it is `None` when metric has been already registered; \
|
||||
const METRIC_IS_SOME_PROOF: &str =
|
||||
"it is `None` when metric has been already registered; \
|
||||
this is the command entrypoint, so nothing has been registered yet; \
|
||||
qed";
|
||||
|
||||
@@ -413,22 +451,40 @@ impl RelayHeadersAndMessages {
|
||||
}
|
||||
|
||||
if params.shared.create_relayers_fund_accounts {
|
||||
let relayer_fund_acount_id =
|
||||
pallet_bridge_messages::relayer_fund_account_id::<AccountIdOf<Left>, LeftAccountIdConverter>();
|
||||
let relayer_fund_acount_id = pallet_bridge_messages::relayer_fund_account_id::<
|
||||
AccountIdOf<Left>,
|
||||
LeftAccountIdConverter,
|
||||
>();
|
||||
let relayers_fund_account_balance =
|
||||
left_client.free_native_balance(relayer_fund_acount_id.clone()).await;
|
||||
if let Err(relay_substrate_client::Error::AccountDoesNotExist) = relayers_fund_account_balance {
|
||||
if let Err(relay_substrate_client::Error::AccountDoesNotExist) =
|
||||
relayers_fund_account_balance
|
||||
{
|
||||
log::info!(target: "bridge", "Going to create relayers fund account at {}.", Left::NAME);
|
||||
left_create_account(left_client.clone(), left_sign.clone(), relayer_fund_acount_id).await?;
|
||||
left_create_account(
|
||||
left_client.clone(),
|
||||
left_sign.clone(),
|
||||
relayer_fund_acount_id,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let relayer_fund_acount_id =
|
||||
pallet_bridge_messages::relayer_fund_account_id::<AccountIdOf<Right>, RightAccountIdConverter>();
|
||||
let relayer_fund_acount_id = pallet_bridge_messages::relayer_fund_account_id::<
|
||||
AccountIdOf<Right>,
|
||||
RightAccountIdConverter,
|
||||
>();
|
||||
let relayers_fund_account_balance =
|
||||
right_client.free_native_balance(relayer_fund_acount_id.clone()).await;
|
||||
if let Err(relay_substrate_client::Error::AccountDoesNotExist) = relayers_fund_account_balance {
|
||||
if let Err(relay_substrate_client::Error::AccountDoesNotExist) =
|
||||
relayers_fund_account_balance
|
||||
{
|
||||
log::info!(target: "bridge", "Going to create relayers fund account at {}.", Right::NAME);
|
||||
right_create_account(right_client.clone(), right_sign.clone(), relayer_fund_acount_id).await?;
|
||||
right_create_account(
|
||||
right_client.clone(),
|
||||
right_sign.clone(),
|
||||
relayer_fund_acount_id,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,13 @@ use strum::{EnumString, EnumVariantNames, VariantNames};
|
||||
|
||||
use substrate_relay_helper::messages_lane::MessagesRelayParams;
|
||||
|
||||
use crate::cli::bridge::FullBridge;
|
||||
use crate::cli::{
|
||||
HexLaneId, PrometheusParams, SourceConnectionParams, SourceSigningParams, TargetConnectionParams,
|
||||
TargetSigningParams,
|
||||
use crate::{
|
||||
cli::{
|
||||
bridge::FullBridge, HexLaneId, PrometheusParams, SourceConnectionParams,
|
||||
SourceSigningParams, TargetConnectionParams, TargetSigningParams,
|
||||
},
|
||||
select_full_bridge,
|
||||
};
|
||||
use crate::select_full_bridge;
|
||||
|
||||
/// Relayer operating mode.
|
||||
#[derive(Debug, EnumString, EnumVariantNames, Clone, Copy, PartialEq)]
|
||||
@@ -32,7 +33,8 @@ use crate::select_full_bridge;
|
||||
pub enum RelayerMode {
|
||||
/// The relayer doesn't care about rewards.
|
||||
Altruistic,
|
||||
/// The relayer will deliver all messages and confirmations as long as he's not losing any funds.
|
||||
/// The relayer will deliver all messages and confirmations as long as he's not losing any
|
||||
/// funds.
|
||||
Rational,
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ use crate::cli::{TargetConnectionParams, TargetSigningParams};
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use num_traits::{One, Zero};
|
||||
use relay_substrate_client::{BlockWithJustification, Chain, Client, Error as SubstrateError, TransactionSignScheme};
|
||||
use relay_substrate_client::{
|
||||
BlockWithJustification, Chain, Client, Error as SubstrateError, TransactionSignScheme,
|
||||
};
|
||||
use relay_utils::FailedClient;
|
||||
use sp_core::Bytes;
|
||||
use sp_runtime::{
|
||||
@@ -54,13 +56,15 @@ macro_rules! select_bridge {
|
||||
type Target = relay_millau_client::Millau;
|
||||
type TargetSign = relay_millau_client::Millau;
|
||||
|
||||
// When large message is being sent from Millau to Rialto AND other transactions are blocking
|
||||
// it from being mined, we'll see something like this in logs:
|
||||
// When large message is being sent from Millau to Rialto AND other transactions are
|
||||
// blocking it from being mined, we'll see something like this in logs:
|
||||
//
|
||||
// Millau transaction priority with tip=0: 17800827994. Target priority: 526186677695
|
||||
// Millau transaction priority with tip=0: 17800827994. Target priority:
|
||||
// 526186677695
|
||||
//
|
||||
// So since fee multiplier in Millau is `1` and `WeightToFee` is `IdentityFee`, then we need
|
||||
// tip around `526186677695 - 17800827994 = 508_385_849_701`. Let's round it up to `1_000_000_000_000`.
|
||||
// So since fee multiplier in Millau is `1` and `WeightToFee` is `IdentityFee`, then
|
||||
// we need tip around `526186677695 - 17800827994 = 508_385_849_701`. Let's round it
|
||||
// up to `1_000_000_000_000`.
|
||||
|
||||
const TIP_STEP: bp_millau::Balance = 1_000_000_000;
|
||||
const TIP_LIMIT: bp_millau::Balance = 1_000_000_000_000;
|
||||
@@ -68,7 +72,7 @@ macro_rules! select_bridge {
|
||||
const STALLED_BLOCKS: bp_millau::BlockNumber = 5;
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -158,8 +162,8 @@ async fn run_until_connection_lost<C: Chain, S: TransactionSignScheme<Chain = C>
|
||||
C::NAME,
|
||||
error,
|
||||
);
|
||||
return Err(FailedClient::Target);
|
||||
}
|
||||
return Err(FailedClient::Target)
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -174,8 +178,8 @@ async fn run_loop_iteration<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
Some(original_transaction) => original_transaction,
|
||||
None => {
|
||||
log::trace!(target: "bridge", "No {} transactions from required signer in the txpool", C::NAME);
|
||||
return Ok(context);
|
||||
}
|
||||
return Ok(context)
|
||||
},
|
||||
};
|
||||
let original_transaction_hash = C::Hasher::hash(&original_transaction.encode());
|
||||
let context = context.notice_transaction(original_transaction_hash);
|
||||
@@ -189,15 +193,15 @@ async fn run_loop_iteration<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
context.stalled_for,
|
||||
context.stalled_for_limit,
|
||||
);
|
||||
return Ok(context);
|
||||
return Ok(context)
|
||||
}
|
||||
|
||||
let (best_block, target_priority) = match read_previous_best_priority::<C, S>(&client).await? {
|
||||
Some((best_block, target_priority)) => (best_block, target_priority),
|
||||
None => {
|
||||
log::trace!(target: "bridge", "Failed to read priority of best {} transaction in its best block", C::NAME);
|
||||
return Ok(context);
|
||||
}
|
||||
return Ok(context)
|
||||
},
|
||||
};
|
||||
|
||||
let (is_updated, updated_transaction) = select_transaction_tip::<C, S>(
|
||||
@@ -213,7 +217,7 @@ async fn run_loop_iteration<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
|
||||
if !is_updated {
|
||||
log::trace!(target: "bridge", "{} transaction tip can not be updated. Reached limit?", C::NAME);
|
||||
return Ok(context);
|
||||
return Ok(context)
|
||||
}
|
||||
|
||||
let updated_transaction = updated_transaction.encode();
|
||||
@@ -241,10 +245,10 @@ async fn lookup_signer_transaction<C: Chain, S: TransactionSignScheme<Chain = C>
|
||||
let pending_transaction = S::SignedTransaction::decode(&mut &pending_transaction.0[..])
|
||||
.map_err(SubstrateError::ResponseParseFailed)?;
|
||||
if !S::is_signed_by(key_pair, &pending_transaction) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
|
||||
return Ok(Some(pending_transaction));
|
||||
return Ok(Some(pending_transaction))
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
@@ -286,14 +290,15 @@ async fn select_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
) -> Result<(bool, S::SignedTransaction), SubstrateError> {
|
||||
let stx = format!("{:?}", tx);
|
||||
let mut current_priority = client.validate_transaction(at_block, tx.clone()).await??.priority;
|
||||
let mut unsigned_tx = S::parse_transaction(tx)
|
||||
.ok_or_else(|| SubstrateError::Custom(format!("Failed to parse {} transaction {}", C::NAME, stx,)))?;
|
||||
let mut unsigned_tx = S::parse_transaction(tx).ok_or_else(|| {
|
||||
SubstrateError::Custom(format!("Failed to parse {} transaction {}", C::NAME, stx,))
|
||||
})?;
|
||||
let old_tip = unsigned_tx.tip;
|
||||
|
||||
while current_priority < target_priority {
|
||||
let next_tip = unsigned_tx.tip + tip_step;
|
||||
if next_tip > tip_limit {
|
||||
break;
|
||||
break
|
||||
}
|
||||
|
||||
log::trace!(
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::cli::bridge::FullBridge;
|
||||
use crate::cli::encode_call::{self, CliEncodeCall};
|
||||
use crate::cli::estimate_fee::estimate_message_delivery_and_dispatch_fee;
|
||||
use crate::cli::{
|
||||
Balance, CliChain, ExplicitOrMaximal, HexBytes, HexLaneId, Origins, SourceConnectionParams, SourceSigningParams,
|
||||
TargetSigningParams,
|
||||
bridge::FullBridge,
|
||||
encode_call::{self, CliEncodeCall},
|
||||
estimate_fee::estimate_message_delivery_and_dispatch_fee,
|
||||
Balance, CliChain, ExplicitOrMaximal, HexBytes, HexLaneId, Origins, SourceConnectionParams,
|
||||
SourceSigningParams, TargetSigningParams,
|
||||
};
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use bp_runtime::BalanceOf;
|
||||
@@ -77,7 +77,8 @@ pub struct SendMessage {
|
||||
/// Dispatch weight of the message. If not passed, determined automatically.
|
||||
#[structopt(long)]
|
||||
dispatch_weight: Option<ExplicitOrMaximal<Weight>>,
|
||||
/// Delivery and dispatch fee in source chain base currency units. If not passed, determined automatically.
|
||||
/// Delivery and dispatch fee in source chain base currency units. If not passed, determined
|
||||
/// automatically.
|
||||
#[structopt(long)]
|
||||
fee: Option<Balance>,
|
||||
/// Message type.
|
||||
@@ -138,7 +139,7 @@ impl SendMessage {
|
||||
target_origin_public.into(),
|
||||
digest_signature.into(),
|
||||
)
|
||||
}
|
||||
},
|
||||
},
|
||||
&target_call,
|
||||
*dispatch_fee_payment,
|
||||
@@ -238,10 +239,7 @@ fn prepare_call_dispatch_weight(
|
||||
weight_from_pre_dispatch_call: ExplicitOrMaximal<Weight>,
|
||||
maximal_allowed_weight: Weight,
|
||||
) -> Weight {
|
||||
match user_specified_dispatch_weight
|
||||
.clone()
|
||||
.unwrap_or(weight_from_pre_dispatch_call)
|
||||
{
|
||||
match user_specified_dispatch_weight.clone().unwrap_or(weight_from_pre_dispatch_call) {
|
||||
ExplicitOrMaximal::Explicit(weight) => weight,
|
||||
ExplicitOrMaximal::Maximal => maximal_allowed_weight,
|
||||
}
|
||||
@@ -272,24 +270,14 @@ where
|
||||
log::info!(target: "bridge", "Encoded Message Payload: {:?}", HexBytes::encode(&payload));
|
||||
|
||||
// re-pack to return `Vec<u8>`
|
||||
let MessagePayload {
|
||||
spec_version,
|
||||
weight,
|
||||
origin,
|
||||
dispatch_fee_payment,
|
||||
call,
|
||||
} = payload;
|
||||
MessagePayload {
|
||||
spec_version,
|
||||
weight,
|
||||
origin,
|
||||
dispatch_fee_payment,
|
||||
call: call.0,
|
||||
}
|
||||
let MessagePayload { spec_version, weight, origin, dispatch_fee_payment, call } = payload;
|
||||
MessagePayload { spec_version, weight, origin, dispatch_fee_payment, call: call.0 }
|
||||
}
|
||||
|
||||
pub(crate) fn compute_maximal_message_dispatch_weight(maximal_extrinsic_weight: Weight) -> Weight {
|
||||
bridge_runtime_common::messages::target::maximal_incoming_message_dispatch_weight(maximal_extrinsic_weight)
|
||||
bridge_runtime_common::messages::target::maximal_incoming_message_dispatch_weight(
|
||||
maximal_extrinsic_weight,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -321,7 +309,9 @@ mod tests {
|
||||
MessagePayload {
|
||||
spec_version: relay_millau_client::Millau::RUNTIME_VERSION.spec_version,
|
||||
weight: 576000,
|
||||
origin: CallOrigin::SourceAccount(sp_keyring::AccountKeyring::Alice.to_account_id()),
|
||||
origin: CallOrigin::SourceAccount(
|
||||
sp_keyring::AccountKeyring::Alice.to_account_id()
|
||||
),
|
||||
dispatch_fee_payment: bp_runtime::messages::DispatchFeePayment::AtSourceChain,
|
||||
call: hex!("0001081234").to_vec(),
|
||||
}
|
||||
|
||||
@@ -28,15 +28,16 @@ use strum::{EnumString, EnumVariantNames, VariantNames};
|
||||
|
||||
use frame_support::dispatch::GetDispatchInfo;
|
||||
use relay_substrate_client::{
|
||||
AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, CallOf, Chain, ChainWithBalances, Client,
|
||||
Error as SubstrateError, HashOf, SignatureOf, Subscription, TransactionSignScheme, TransactionStatusOf,
|
||||
UnsignedTransaction,
|
||||
AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, CallOf, Chain, ChainWithBalances,
|
||||
Client, Error as SubstrateError, HashOf, SignatureOf, Subscription, TransactionSignScheme,
|
||||
TransactionStatusOf, UnsignedTransaction,
|
||||
};
|
||||
use sp_core::{blake2_256, storage::StorageKey, Bytes, Pair, H256, U256};
|
||||
use sp_runtime::traits::{Convert, Header as HeaderT};
|
||||
|
||||
use crate::cli::{
|
||||
Balance, CliChain, SourceConnectionParams, SourceSigningParams, TargetConnectionParams, TargetSigningParams,
|
||||
Balance, CliChain, SourceConnectionParams, SourceSigningParams, TargetConnectionParams,
|
||||
TargetSigningParams,
|
||||
};
|
||||
|
||||
/// Swap tokens.
|
||||
@@ -71,7 +72,8 @@ pub struct SwapTokens {
|
||||
pub enum TokenSwapType {
|
||||
/// The `target_sign` is temporary and only have funds for single swap.
|
||||
NoLock,
|
||||
/// This swap type prevents `source_signer` from restarting the swap after it has been completed.
|
||||
/// This swap type prevents `source_signer` from restarting the swap after it has been
|
||||
/// completed.
|
||||
LockUntilBlock {
|
||||
/// Number of blocks before the swap expires.
|
||||
#[structopt(long)]
|
||||
@@ -119,7 +121,7 @@ macro_rules! select_bridge {
|
||||
const TARGET_TO_SOURCE_LANE_ID: bp_messages::LaneId = [0, 0, 0, 0];
|
||||
|
||||
$generic
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -133,7 +135,8 @@ impl SwapTokens {
|
||||
let target_client = self.target.to_client::<Target>().await?;
|
||||
let target_sign = self.target_sign.to_keypair::<Target>()?;
|
||||
|
||||
// names of variables in this function are matching names used by the `pallet-bridge-token-swap`
|
||||
// names of variables in this function are matching names used by the
|
||||
// `pallet-bridge-token-swap`
|
||||
|
||||
// prepare token swap intention
|
||||
let token_swap = self
|
||||
@@ -143,18 +146,25 @@ impl SwapTokens {
|
||||
// group all accounts that will be used later
|
||||
let accounts = TokenSwapAccounts {
|
||||
source_account_at_bridged_chain: derive_target_account_from_source_account(
|
||||
bp_runtime::SourceAccount::Account(token_swap.source_account_at_this_chain.clone()),
|
||||
bp_runtime::SourceAccount::Account(
|
||||
token_swap.source_account_at_this_chain.clone(),
|
||||
),
|
||||
),
|
||||
target_account_at_this_chain: derive_source_account_from_target_account(
|
||||
bp_runtime::SourceAccount::Account(token_swap.target_account_at_bridged_chain.clone()),
|
||||
bp_runtime::SourceAccount::Account(
|
||||
token_swap.target_account_at_bridged_chain.clone(),
|
||||
),
|
||||
),
|
||||
source_account_at_this_chain: token_swap.source_account_at_this_chain.clone(),
|
||||
target_account_at_bridged_chain: token_swap.target_account_at_bridged_chain.clone(),
|
||||
swap_account: FromSwapToThisAccountIdConverter::convert(token_swap.using_encoded(blake2_256).into()),
|
||||
swap_account: FromSwapToThisAccountIdConverter::convert(
|
||||
token_swap.using_encoded(blake2_256).into(),
|
||||
),
|
||||
};
|
||||
|
||||
// account balances are used to demonstrate what's happening :)
|
||||
let initial_balances = read_account_balances(&accounts, &source_client, &target_client).await?;
|
||||
let initial_balances =
|
||||
read_account_balances(&accounts, &source_client, &target_client).await?;
|
||||
|
||||
// before calling something that may fail, log what we're trying to do
|
||||
log::info!(target: "bridge", "Starting swap: {:?}", token_swap);
|
||||
@@ -171,7 +181,8 @@ impl SwapTokens {
|
||||
token_swap.target_balance_at_bridged_chain,
|
||||
)
|
||||
.into();
|
||||
let bridged_currency_transfer_weight = bridged_currency_transfer.get_dispatch_info().weight;
|
||||
let bridged_currency_transfer_weight =
|
||||
bridged_currency_transfer.get_dispatch_info().weight;
|
||||
|
||||
// sign message
|
||||
let bridged_chain_spec_version = TARGET_SPEC_VERSION;
|
||||
@@ -182,10 +193,12 @@ impl SwapTokens {
|
||||
SOURCE_CHAIN_ID,
|
||||
TARGET_CHAIN_ID,
|
||||
);
|
||||
let bridged_currency_transfer_signature: SignatureOf<Target> = target_sign.sign(&signature_payload).into();
|
||||
let bridged_currency_transfer_signature: SignatureOf<Target> =
|
||||
target_sign.sign(&signature_payload).into();
|
||||
|
||||
// prepare `create_swap` call
|
||||
let target_public_at_bridged_chain: AccountPublicOf<Target> = target_sign.public().into();
|
||||
let target_public_at_bridged_chain: AccountPublicOf<Target> =
|
||||
target_sign.public().into();
|
||||
let swap_delivery_and_dispatch_fee: BalanceOf<Source> =
|
||||
crate::cli::estimate_fee::estimate_message_delivery_and_dispatch_fee(
|
||||
&source_client,
|
||||
@@ -199,7 +212,8 @@ impl SwapTokens {
|
||||
target_public_at_bridged_chain.clone(),
|
||||
bridged_currency_transfer_signature.clone(),
|
||||
),
|
||||
dispatch_fee_payment: bp_runtime::messages::DispatchFeePayment::AtTargetChain,
|
||||
dispatch_fee_payment:
|
||||
bp_runtime::messages::DispatchFeePayment::AtTargetChain,
|
||||
call: bridged_currency_transfer.encode(),
|
||||
},
|
||||
)
|
||||
@@ -245,19 +259,20 @@ impl SwapTokens {
|
||||
pallet_bridge_token_swap::PENDING_SWAPS_MAP_NAME,
|
||||
token_swap_hash.as_ref(),
|
||||
);
|
||||
match read_token_swap_state(&source_client, swap_created_at, &token_swap_storage_key).await? {
|
||||
match read_token_swap_state(&source_client, swap_created_at, &token_swap_storage_key)
|
||||
.await?
|
||||
{
|
||||
Some(bp_token_swap::TokenSwapState::Started) => {
|
||||
log::info!(target: "bridge", "Swap has been successfully started");
|
||||
let intermediate_balances =
|
||||
read_account_balances(&accounts, &source_client, &target_client).await?;
|
||||
log::info!(target: "bridge", "Intermediate balances: {:?}", intermediate_balances);
|
||||
}
|
||||
Some(token_swap_state) => {
|
||||
},
|
||||
Some(token_swap_state) =>
|
||||
return Err(anyhow::format_err!(
|
||||
"Fresh token swap has unexpected state: {:?}",
|
||||
token_swap_state,
|
||||
))
|
||||
}
|
||||
)),
|
||||
None => return Err(anyhow::format_err!("Failed to start token swap")),
|
||||
};
|
||||
|
||||
@@ -265,7 +280,8 @@ impl SwapTokens {
|
||||
// Step 2: message is being relayed to the target chain and dispathed there
|
||||
//
|
||||
|
||||
// wait until message is dispatched at the target chain and dispatch result delivered back to source chain
|
||||
// wait until message is dispatched at the target chain and dispatch result delivered
|
||||
// back to source chain
|
||||
let token_swap_state = wait_until_token_swap_state_is_changed(
|
||||
&source_client,
|
||||
&token_swap_storage_key,
|
||||
@@ -275,32 +291,37 @@ impl SwapTokens {
|
||||
let is_transfer_succeeded = match token_swap_state {
|
||||
Some(bp_token_swap::TokenSwapState::Started) => {
|
||||
unreachable!("wait_until_token_swap_state_is_changed only returns if state is not Started; qed",)
|
||||
}
|
||||
None => return Err(anyhow::format_err!("Fresh token swap has disappeared unexpectedly")),
|
||||
},
|
||||
None =>
|
||||
return Err(anyhow::format_err!("Fresh token swap has disappeared unexpectedly")),
|
||||
Some(bp_token_swap::TokenSwapState::Confirmed) => {
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"Transfer has been successfully dispatched at the target chain. Swap can be claimed",
|
||||
);
|
||||
true
|
||||
}
|
||||
},
|
||||
Some(bp_token_swap::TokenSwapState::Failed) => {
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"Transfer has been dispatched with an error at the target chain. Swap can be canceled",
|
||||
);
|
||||
false
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// by this time: (1) token swap account has been created and (2) if transfer has been successfully
|
||||
// dispatched, both target chain balances have changed
|
||||
let intermediate_balances = read_account_balances(&accounts, &source_client, &target_client).await?;
|
||||
// by this time: (1) token swap account has been created and (2) if transfer has been
|
||||
// successfully dispatched, both target chain balances have changed
|
||||
let intermediate_balances =
|
||||
read_account_balances(&accounts, &source_client, &target_client).await?;
|
||||
log::info!(target: "bridge", "Intermediate balances: {:?}", intermediate_balances);
|
||||
|
||||
// transfer has been dispatched, but we may need to wait until block where swap can be claimed/canceled
|
||||
if let bp_token_swap::TokenSwapType::LockClaimUntilBlock(ref last_available_block_number, _) =
|
||||
token_swap.swap_type
|
||||
// transfer has been dispatched, but we may need to wait until block where swap can be
|
||||
// claimed/canceled
|
||||
if let bp_token_swap::TokenSwapType::LockClaimUntilBlock(
|
||||
ref last_available_block_number,
|
||||
_,
|
||||
) = token_swap.swap_type
|
||||
{
|
||||
wait_until_swap_unlocked(
|
||||
&source_client,
|
||||
@@ -317,7 +338,8 @@ impl SwapTokens {
|
||||
log::info!(target: "bridge", "Claiming the swap swap");
|
||||
|
||||
// prepare `claim_swap` message that will be sent over the bridge
|
||||
let claim_swap_call: CallOf<Source> = pallet_bridge_token_swap::Call::claim_swap(token_swap).into();
|
||||
let claim_swap_call: CallOf<Source> =
|
||||
pallet_bridge_token_swap::Call::claim_swap(token_swap).into();
|
||||
let claim_swap_message = bp_message_dispatch::MessagePayload {
|
||||
spec_version: SOURCE_SPEC_VERSION,
|
||||
weight: claim_swap_call.get_dispatch_info().weight,
|
||||
@@ -354,7 +376,10 @@ impl SwapTokens {
|
||||
target_genesis_hash,
|
||||
&target_sign,
|
||||
relay_substrate_client::TransactionEra::immortal(),
|
||||
UnsignedTransaction::new(send_message_call, transaction_nonce),
|
||||
UnsignedTransaction::new(
|
||||
send_message_call,
|
||||
transaction_nonce,
|
||||
),
|
||||
)
|
||||
.encode(),
|
||||
)
|
||||
@@ -374,7 +399,7 @@ impl SwapTokens {
|
||||
if token_swap_state != None {
|
||||
return Err(anyhow::format_err!(
|
||||
"Confirmed token swap state has been changed to {:?} unexpectedly"
|
||||
));
|
||||
))
|
||||
}
|
||||
} else {
|
||||
log::info!(target: "bridge", "Cancelling the swap");
|
||||
@@ -390,7 +415,10 @@ impl SwapTokens {
|
||||
source_genesis_hash,
|
||||
&source_sign,
|
||||
relay_substrate_client::TransactionEra::immortal(),
|
||||
UnsignedTransaction::new(cancel_swap_call, transaction_nonce),
|
||||
UnsignedTransaction::new(
|
||||
cancel_swap_call,
|
||||
transaction_nonce,
|
||||
),
|
||||
)
|
||||
.encode(),
|
||||
)
|
||||
@@ -402,7 +430,8 @@ impl SwapTokens {
|
||||
}
|
||||
|
||||
// print final balances
|
||||
let final_balances = read_account_balances(&accounts, &source_client, &target_client).await?;
|
||||
let final_balances =
|
||||
read_account_balances(&accounts, &source_client, &target_client).await?;
|
||||
log::info!(target: "bridge", "Final account balances: {:?}", final_balances);
|
||||
|
||||
Ok(())
|
||||
@@ -454,22 +483,18 @@ impl SwapTokens {
|
||||
source_client: &Client<Source>,
|
||||
) -> anyhow::Result<bp_token_swap::TokenSwapType<BlockNumberOf<Source>>> {
|
||||
match self.swap_type {
|
||||
TokenSwapType::NoLock => Ok(bp_token_swap::TokenSwapType::TemporaryTargetAccountAtBridgedChain),
|
||||
TokenSwapType::LockUntilBlock {
|
||||
blocks_before_expire,
|
||||
ref swap_nonce,
|
||||
} => {
|
||||
TokenSwapType::NoLock =>
|
||||
Ok(bp_token_swap::TokenSwapType::TemporaryTargetAccountAtBridgedChain),
|
||||
TokenSwapType::LockUntilBlock { blocks_before_expire, ref swap_nonce } => {
|
||||
let blocks_before_expire: BlockNumberOf<Source> = blocks_before_expire.into();
|
||||
let current_source_block_number = *source_client.best_header().await?.number();
|
||||
Ok(bp_token_swap::TokenSwapType::LockClaimUntilBlock(
|
||||
current_source_block_number + blocks_before_expire,
|
||||
swap_nonce.unwrap_or_else(|| {
|
||||
U256::from(random::<u128>())
|
||||
.overflowing_mul(U256::from(random::<u128>()))
|
||||
.0
|
||||
U256::from(random::<u128>()).overflowing_mul(U256::from(random::<u128>())).0
|
||||
}),
|
||||
))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -551,17 +576,16 @@ async fn wait_until_transaction_is_finalized<C: Chain>(
|
||||
loop {
|
||||
let transaction_status = subscription.next().await?;
|
||||
match transaction_status {
|
||||
Some(TransactionStatusOf::<C>::FinalityTimeout(_))
|
||||
| Some(TransactionStatusOf::<C>::Usurped(_))
|
||||
| Some(TransactionStatusOf::<C>::Dropped)
|
||||
| Some(TransactionStatusOf::<C>::Invalid)
|
||||
| None => {
|
||||
Some(TransactionStatusOf::<C>::FinalityTimeout(_)) |
|
||||
Some(TransactionStatusOf::<C>::Usurped(_)) |
|
||||
Some(TransactionStatusOf::<C>::Dropped) |
|
||||
Some(TransactionStatusOf::<C>::Invalid) |
|
||||
None =>
|
||||
return Err(anyhow::format_err!(
|
||||
"We've been waiting for finalization of {} transaction, but it now has the {:?} status",
|
||||
C::NAME,
|
||||
transaction_status,
|
||||
))
|
||||
}
|
||||
)),
|
||||
Some(TransactionStatusOf::<C>::Finalized(block_hash)) => {
|
||||
log::trace!(
|
||||
target: "bridge",
|
||||
@@ -569,8 +593,8 @@ async fn wait_until_transaction_is_finalized<C: Chain>(
|
||||
C::NAME,
|
||||
block_hash,
|
||||
);
|
||||
return Ok(block_hash);
|
||||
}
|
||||
return Ok(block_hash)
|
||||
},
|
||||
_ => {
|
||||
log::trace!(
|
||||
target: "bridge",
|
||||
@@ -578,7 +602,7 @@ async fn wait_until_transaction_is_finalized<C: Chain>(
|
||||
C::NAME,
|
||||
transaction_status,
|
||||
);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -597,9 +621,10 @@ async fn wait_until_token_swap_state_is_changed<C: Chain>(
|
||||
let best_block_hash = client.block_hash_by_number(best_block).await?;
|
||||
log::trace!(target: "bridge", "Inspecting {} block {}/{}", C::NAME, best_block, best_block_hash);
|
||||
|
||||
let token_swap_state = read_token_swap_state(client, best_block_hash, swap_state_storage_key).await?;
|
||||
let token_swap_state =
|
||||
read_token_swap_state(client, best_block_hash, swap_state_storage_key).await?;
|
||||
match token_swap_state {
|
||||
Some(new_token_swap_state) if new_token_swap_state == previous_token_swap_state => {}
|
||||
Some(new_token_swap_state) if new_token_swap_state == previous_token_swap_state => {},
|
||||
_ => {
|
||||
log::trace!(
|
||||
target: "bridge",
|
||||
@@ -607,8 +632,8 @@ async fn wait_until_token_swap_state_is_changed<C: Chain>(
|
||||
previous_token_swap_state,
|
||||
token_swap_state,
|
||||
);
|
||||
return Ok(token_swap_state);
|
||||
}
|
||||
return Ok(token_swap_state)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -625,7 +650,7 @@ async fn wait_until_swap_unlocked<C: Chain>(
|
||||
let best_block = client.best_finalized_header_number().await?;
|
||||
let best_block_hash = client.block_hash_by_number(best_block).await?;
|
||||
if best_block >= required_block_number {
|
||||
return Ok(());
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
log::trace!(target: "bridge", "Skipping {} block {}/{}", C::NAME, best_block, best_block_hash);
|
||||
@@ -638,7 +663,5 @@ async fn read_token_swap_state<C: Chain>(
|
||||
at_block: C::Hash,
|
||||
swap_state_storage_key: &StorageKey,
|
||||
) -> anyhow::Result<Option<bp_token_swap::TokenSwapState>> {
|
||||
Ok(client
|
||||
.storage_value(swap_state_storage_key.clone(), Some(at_block))
|
||||
.await?)
|
||||
Ok(client.storage_value(swap_state_storage_key.clone(), Some(at_block)).await?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user