mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 02:51:01 +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:
@@ -41,41 +41,41 @@ impl CliEncodeCall for Kusama {
|
||||
|
||||
fn encode_call(call: &Call) -> anyhow::Result<Self::Call> {
|
||||
Ok(match call {
|
||||
Call::Remark { remark_payload, .. } => {
|
||||
relay_kusama_client::runtime::Call::System(relay_kusama_client::runtime::SystemCall::remark(
|
||||
Call::Remark { remark_payload, .. } => relay_kusama_client::runtime::Call::System(
|
||||
relay_kusama_client::runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
))
|
||||
}
|
||||
Call::BridgeSendMessage {
|
||||
lane,
|
||||
payload,
|
||||
fee,
|
||||
bridge_instance_index,
|
||||
} => match *bridge_instance_index {
|
||||
bridge::KUSAMA_TO_POLKADOT_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
relay_kusama_client::runtime::Call::BridgePolkadotMessages(
|
||||
relay_kusama_client::runtime::BridgePolkadotMessagesCall::send_message(lane.0, payload, fee.0),
|
||||
)
|
||||
}
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::KUSAMA_TO_POLKADOT_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
relay_kusama_client::runtime::Call::BridgePolkadotMessages(
|
||||
relay_kusama_client::runtime::BridgePolkadotMessagesCall::send_message(
|
||||
lane.0, payload, fee.0,
|
||||
),
|
||||
)
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
_ => anyhow::bail!("Unsupported Kusama call: {:?}", call),
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(call: &relay_kusama_client::runtime::Call) -> anyhow::Result<DispatchInfo> {
|
||||
fn get_dispatch_info(
|
||||
call: &relay_kusama_client::runtime::Call,
|
||||
) -> anyhow::Result<DispatchInfo> {
|
||||
match *call {
|
||||
relay_kusama_client::runtime::Call::System(relay_kusama_client::runtime::SystemCall::remark(_)) => {
|
||||
Ok(DispatchInfo {
|
||||
weight: crate::chains::kusama::SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
})
|
||||
}
|
||||
relay_kusama_client::runtime::Call::System(
|
||||
relay_kusama_client::runtime::SystemCall::remark(_),
|
||||
) => Ok(DispatchInfo {
|
||||
weight: crate::chains::kusama::SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
}),
|
||||
_ => anyhow::bail!("Unsupported Kusama call: {:?}", call),
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,9 @@ impl CliChain for Kusama {
|
||||
bp_kusama::max_extrinsic_weight()
|
||||
}
|
||||
|
||||
fn encode_message(_message: encode_message::MessagePayload) -> Result<Self::MessagePayload, String> {
|
||||
fn encode_message(
|
||||
_message: encode_message::MessagePayload,
|
||||
) -> Result<Self::MessagePayload, String> {
|
||||
Err("Sending messages from Kusama is not yet supported.".into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,15 @@ use relay_kusama_client::{Kusama, SyncHeader as KusamaSyncHeader};
|
||||
use relay_polkadot_client::{Polkadot, SigningParams as PolkadotSigningParams};
|
||||
use relay_substrate_client::{Client, TransactionSignScheme, UnsignedTransaction};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use substrate_relay_helper::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate};
|
||||
use substrate_relay_helper::finality_pipeline::{
|
||||
SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate,
|
||||
};
|
||||
|
||||
/// Maximal saturating difference between `balance(now)` and `balance(now-24h)` to treat
|
||||
/// relay as gone wild.
|
||||
///
|
||||
/// Actual value, returned by `maximal_balance_decrease_per_day_is_sane` test is approximately 21 DOT,
|
||||
/// but let's round up to 30 DOT here.
|
||||
/// Actual value, returned by `maximal_balance_decrease_per_day_is_sane` test is approximately 21
|
||||
/// DOT, but let's round up to 30 DOT here.
|
||||
pub(crate) const MAXIMAL_BALANCE_DECREASE_PER_DAY: bp_polkadot::Balance = 30_000_000_000;
|
||||
|
||||
/// Kusama-to-Polkadot finality sync pipeline.
|
||||
@@ -45,7 +47,10 @@ pub(crate) struct KusamaFinalityToPolkadot {
|
||||
impl KusamaFinalityToPolkadot {
|
||||
pub fn new(target_client: Client<Polkadot>, target_sign: PolkadotSigningParams) -> Self {
|
||||
Self {
|
||||
finality_pipeline: FinalityPipelineKusamaFinalityToPolkadot::new(target_client, target_sign),
|
||||
finality_pipeline: FinalityPipelineKusamaFinalityToPolkadot::new(
|
||||
target_client,
|
||||
target_sign,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +58,8 @@ impl KusamaFinalityToPolkadot {
|
||||
impl SubstrateFinalitySyncPipeline for KusamaFinalityToPolkadot {
|
||||
type FinalitySyncPipeline = FinalityPipelineKusamaFinalityToPolkadot;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_kusama::BEST_FINALIZED_KUSAMA_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_kusama::BEST_FINALIZED_KUSAMA_HEADER_METHOD;
|
||||
|
||||
type TargetChain = Polkadot;
|
||||
|
||||
@@ -116,29 +122,36 @@ pub(crate) mod tests {
|
||||
B: From<u32> + std::ops::Mul<Output = B>,
|
||||
W: WeightToFeePolynomial<Balance = B>,
|
||||
{
|
||||
// we assume that the GRANDPA is not lagging here => ancestry length will be near to 0 (let's round up to 2)
|
||||
// we assume that the GRANDPA is not lagging here => ancestry length will be near to 0
|
||||
// (let's round up to 2)
|
||||
const AVG_VOTES_ANCESTRIES_LEN: u32 = 2;
|
||||
// let's assume number of validators is 1024 (more than on any existing well-known chain atm)
|
||||
// => number of precommits is *2/3 + 1
|
||||
// let's assume number of validators is 1024 (more than on any existing well-known chain
|
||||
// atm) => number of precommits is *2/3 + 1
|
||||
const AVG_PRECOMMITS_LEN: u32 = 1024 * 2 / 3 + 1;
|
||||
|
||||
// GRANDPA pallet weights. We're now using Rialto weights everywhere.
|
||||
//
|
||||
// Using Rialto runtime is slightly incorrect, because `DbWeight` of other runtimes may differ
|
||||
// from the `DbWeight` of Rialto runtime. But now (and most probably forever) it is the same.
|
||||
type GrandpaPalletWeights = pallet_bridge_grandpa::weights::RialtoWeight<rialto_runtime::Runtime>;
|
||||
// Using Rialto runtime is slightly incorrect, because `DbWeight` of other runtimes may
|
||||
// differ from the `DbWeight` of Rialto runtime. But now (and most probably forever) it is
|
||||
// the same.
|
||||
type GrandpaPalletWeights =
|
||||
pallet_bridge_grandpa::weights::RialtoWeight<rialto_runtime::Runtime>;
|
||||
|
||||
// The following formula shall not be treated as super-accurate - guard is to protect from mad relays,
|
||||
// not to protect from over-average loses.
|
||||
// The following formula shall not be treated as super-accurate - guard is to protect from
|
||||
// mad relays, not to protect from over-average loses.
|
||||
|
||||
// increase number of headers a bit
|
||||
let expected_source_headers_per_day = expected_source_headers_per_day * 110 / 100;
|
||||
let single_source_header_submit_call_weight =
|
||||
GrandpaPalletWeights::submit_finality_proof(AVG_VOTES_ANCESTRIES_LEN, AVG_PRECOMMITS_LEN);
|
||||
// for simplicity - add extra weight for base tx fee + fee that is paid for the tx size + adjusted fee
|
||||
let single_source_header_submit_call_weight = GrandpaPalletWeights::submit_finality_proof(
|
||||
AVG_VOTES_ANCESTRIES_LEN,
|
||||
AVG_PRECOMMITS_LEN,
|
||||
);
|
||||
// for simplicity - add extra weight for base tx fee + fee that is paid for the tx size +
|
||||
// adjusted fee
|
||||
let single_source_header_submit_tx_weight = single_source_header_submit_call_weight * 3 / 2;
|
||||
let single_source_header_tx_cost = W::calc(&single_source_header_submit_tx_weight);
|
||||
let maximal_expected_decrease = single_source_header_tx_cost * B::from(expected_source_headers_per_day);
|
||||
let maximal_expected_decrease =
|
||||
single_source_header_tx_cost * B::from(expected_source_headers_per_day);
|
||||
|
||||
maximal_expected_decrease
|
||||
}
|
||||
|
||||
@@ -25,17 +25,23 @@ use bp_messages::MessageNonce;
|
||||
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
|
||||
use frame_support::weights::Weight;
|
||||
use messages_relay::message_lane::MessageLane;
|
||||
use relay_kusama_client::{HeaderId as KusamaHeaderId, Kusama, SigningParams as KusamaSigningParams};
|
||||
use relay_polkadot_client::{HeaderId as PolkadotHeaderId, Polkadot, SigningParams as PolkadotSigningParams};
|
||||
use relay_kusama_client::{
|
||||
HeaderId as KusamaHeaderId, Kusama, SigningParams as KusamaSigningParams,
|
||||
};
|
||||
use relay_polkadot_client::{
|
||||
HeaderId as PolkadotHeaderId, Polkadot, SigningParams as PolkadotSigningParams,
|
||||
};
|
||||
use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use sp_runtime::{FixedPointNumber, FixedU128};
|
||||
use substrate_relay_helper::messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
use substrate_relay_helper::{
|
||||
messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics,
|
||||
SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
},
|
||||
messages_source::SubstrateMessagesSource,
|
||||
messages_target::SubstrateMessagesTarget,
|
||||
};
|
||||
use substrate_relay_helper::messages_source::SubstrateMessagesSource;
|
||||
use substrate_relay_helper::messages_target::SubstrateMessagesTarget;
|
||||
|
||||
/// Kusama-to-Polkadot message lane.
|
||||
pub type MessageLaneKusamaMessagesToPolkadot =
|
||||
@@ -49,24 +55,32 @@ pub struct KusamaMessagesToPolkadot {
|
||||
impl SubstrateMessageLane for KusamaMessagesToPolkadot {
|
||||
type MessageLane = MessageLaneKusamaMessagesToPolkadot;
|
||||
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str = bp_polkadot::TO_POLKADOT_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_polkadot::TO_POLKADOT_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_GENERATED_NONCE_METHOD: &'static str =
|
||||
bp_polkadot::TO_POLKADOT_LATEST_GENERATED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_polkadot::TO_POLKADOT_LATEST_RECEIVED_NONCE_METHOD;
|
||||
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_kusama::FROM_KUSAMA_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_kusama::FROM_KUSAMA_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
|
||||
bp_kusama::FROM_KUSAMA_LATEST_CONFIRMED_NONCE_METHOD;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str = bp_kusama::FROM_KUSAMA_UNREWARDED_RELAYERS_STATE;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str =
|
||||
bp_kusama::FROM_KUSAMA_UNREWARDED_RELAYERS_STATE;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_kusama::BEST_FINALIZED_KUSAMA_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str = bp_polkadot::BEST_FINALIZED_POLKADOT_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_kusama::BEST_FINALIZED_KUSAMA_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str =
|
||||
bp_polkadot::BEST_FINALIZED_POLKADOT_HEADER_METHOD;
|
||||
|
||||
const MESSAGE_PALLET_NAME_AT_SOURCE: &'static str = bp_kusama::WITH_POLKADOT_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_TARGET: &'static str = bp_polkadot::WITH_KUSAMA_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_SOURCE: &'static str =
|
||||
bp_kusama::WITH_POLKADOT_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_TARGET: &'static str =
|
||||
bp_polkadot::WITH_KUSAMA_MESSAGES_PALLET_NAME;
|
||||
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight = bp_polkadot::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight =
|
||||
bp_polkadot::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
|
||||
type SourceChain = Kusama;
|
||||
type TargetChain = Polkadot;
|
||||
@@ -117,11 +131,7 @@ impl SubstrateMessageLane for KusamaMessagesToPolkadot {
|
||||
proof: <Self::MessageLane as MessageLane>::MessagesProof,
|
||||
) -> Bytes {
|
||||
let (dispatch_weight, proof) = proof;
|
||||
let FromBridgedChainMessagesProof {
|
||||
ref nonces_start,
|
||||
ref nonces_end,
|
||||
..
|
||||
} = proof;
|
||||
let FromBridgedChainMessagesProof { ref nonces_start, ref nonces_end, .. } = proof;
|
||||
let messages_count = nonces_end - nonces_start + 1;
|
||||
|
||||
let call = relay_polkadot_client::runtime::Call::BridgeKusamaMessages(
|
||||
@@ -180,14 +190,14 @@ pub async fn run(
|
||||
// we don't know exact weights of the Polkadot runtime. So to guess weights we'll be using
|
||||
// weights from Rialto and then simply dividing it by x2.
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
select_delivery_transaction_limits::<pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>>(
|
||||
select_delivery_transaction_limits::<
|
||||
pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>,
|
||||
>(
|
||||
bp_polkadot::max_extrinsic_weight(),
|
||||
bp_polkadot::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
);
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) = (
|
||||
max_messages_in_single_batch / 2,
|
||||
max_messages_weight_in_single_batch / 2,
|
||||
);
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
(max_messages_in_single_batch / 2, max_messages_weight_in_single_batch / 2);
|
||||
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
@@ -219,8 +229,10 @@ pub async fn run(
|
||||
reconnect_delay: relay_utils::relay_loop::RECONNECT_DELAY,
|
||||
stall_timeout,
|
||||
delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams {
|
||||
max_unrewarded_relayer_entries_at_target: bp_polkadot::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target: bp_polkadot::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_unrewarded_relayer_entries_at_target:
|
||||
bp_polkadot::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target:
|
||||
bp_polkadot::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_messages_in_single_batch,
|
||||
max_messages_weight_in_single_batch,
|
||||
max_messages_size_in_single_batch,
|
||||
@@ -252,8 +264,10 @@ pub(crate) fn add_standalone_metrics(
|
||||
metrics_params: MetricsParams,
|
||||
source_client: Client<Kusama>,
|
||||
) -> anyhow::Result<(MetricsParams, StandaloneMessagesMetrics)> {
|
||||
let polkadot_to_kusama_conversion_rate_key =
|
||||
bp_runtime::storage_parameter_key(bp_kusama::POLKADOT_TO_KUSAMA_CONVERSION_RATE_PARAMETER_NAME).0;
|
||||
let polkadot_to_kusama_conversion_rate_key = bp_runtime::storage_parameter_key(
|
||||
bp_kusama::POLKADOT_TO_KUSAMA_CONVERSION_RATE_PARAMETER_NAME,
|
||||
)
|
||||
.0;
|
||||
|
||||
substrate_relay_helper::messages_lane::add_standalone_metrics::<KusamaMessagesToPolkadot>(
|
||||
metrics_prefix,
|
||||
|
||||
@@ -37,31 +37,26 @@ impl CliEncodeCall for Millau {
|
||||
fn encode_call(call: &Call) -> anyhow::Result<Self::Call> {
|
||||
Ok(match call {
|
||||
Call::Raw { data } => Decode::decode(&mut &*data.0)?,
|
||||
Call::Remark { remark_payload, .. } => millau_runtime::Call::System(millau_runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
)),
|
||||
Call::Remark { remark_payload, .. } =>
|
||||
millau_runtime::Call::System(millau_runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
)),
|
||||
Call::Transfer { recipient, amount } => millau_runtime::Call::Balances(
|
||||
millau_runtime::BalancesCall::transfer(recipient.raw_id(), amount.cast()),
|
||||
),
|
||||
Call::BridgeSendMessage {
|
||||
lane,
|
||||
payload,
|
||||
fee,
|
||||
bridge_instance_index,
|
||||
} => match *bridge_instance_index {
|
||||
bridge::MILLAU_TO_RIALTO_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
millau_runtime::Call::BridgeRialtoMessages(millau_runtime::MessagesCall::send_message(
|
||||
lane.0,
|
||||
payload,
|
||||
fee.cast(),
|
||||
))
|
||||
}
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::MILLAU_TO_RIALTO_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
millau_runtime::Call::BridgeRialtoMessages(
|
||||
millau_runtime::MessagesCall::send_message(lane.0, payload, fee.cast()),
|
||||
)
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,7 +69,12 @@ impl CliChain for Millau {
|
||||
const RUNTIME_VERSION: RuntimeVersion = millau_runtime::VERSION;
|
||||
|
||||
type KeyPair = sp_core::sr25519::Pair;
|
||||
type MessagePayload = MessagePayload<bp_millau::AccountId, bp_rialto::AccountSigner, bp_rialto::Signature, Vec<u8>>;
|
||||
type MessagePayload = MessagePayload<
|
||||
bp_millau::AccountId,
|
||||
bp_rialto::AccountSigner,
|
||||
bp_rialto::Signature,
|
||||
Vec<u8>,
|
||||
>;
|
||||
|
||||
fn ss58_format() -> u16 {
|
||||
millau_runtime::SS58Prefix::get() as u16
|
||||
@@ -85,7 +85,9 @@ impl CliChain for Millau {
|
||||
}
|
||||
|
||||
// TODO [#854|#843] support multiple bridges?
|
||||
fn encode_message(message: encode_message::MessagePayload) -> Result<Self::MessagePayload, String> {
|
||||
fn encode_message(
|
||||
message: encode_message::MessagePayload,
|
||||
) -> Result<Self::MessagePayload, String> {
|
||||
match message {
|
||||
encode_message::MessagePayload::Raw { data } => MessagePayload::decode(&mut &*data.0)
|
||||
.map_err(|e| format!("Failed to decode Millau's MessagePayload: {:?}", e)),
|
||||
@@ -96,7 +98,10 @@ impl CliChain for Millau {
|
||||
sender.enforce_chain::<Source>();
|
||||
let spec_version = Target::RUNTIME_VERSION.spec_version;
|
||||
let origin = CallOrigin::SourceAccount(sender.raw_id());
|
||||
encode_call::preprocess_call::<Source, Target>(&mut call, bridge::MILLAU_TO_RIALTO_INDEX);
|
||||
encode_call::preprocess_call::<Source, Target>(
|
||||
&mut call,
|
||||
bridge::MILLAU_TO_RIALTO_INDEX,
|
||||
);
|
||||
let call = Target::encode_call(&call).map_err(|e| e.to_string())?;
|
||||
let weight = call.get_dispatch_info().weight;
|
||||
|
||||
@@ -107,7 +112,7 @@ impl CliChain for Millau {
|
||||
&call,
|
||||
DispatchFeePayment::AtSourceChain,
|
||||
))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,13 @@ 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::{Client, IndexOf, TransactionSignScheme, UnsignedTransaction};
|
||||
use substrate_relay_helper::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate};
|
||||
use substrate_relay_helper::finality_pipeline::{
|
||||
SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate,
|
||||
};
|
||||
|
||||
/// Millau-to-Rialto finality sync pipeline.
|
||||
pub(crate) type FinalityPipelineMillauToRialto = SubstrateFinalityToSubstrate<Millau, Rialto, RialtoSigningParams>;
|
||||
pub(crate) type FinalityPipelineMillauToRialto =
|
||||
SubstrateFinalityToSubstrate<Millau, Rialto, RialtoSigningParams>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct MillauFinalityToRialto {
|
||||
@@ -35,16 +38,15 @@ pub(crate) struct MillauFinalityToRialto {
|
||||
|
||||
impl MillauFinalityToRialto {
|
||||
pub fn new(target_client: Client<Rialto>, target_sign: RialtoSigningParams) -> Self {
|
||||
Self {
|
||||
finality_pipeline: FinalityPipelineMillauToRialto::new(target_client, target_sign),
|
||||
}
|
||||
Self { finality_pipeline: FinalityPipelineMillauToRialto::new(target_client, target_sign) }
|
||||
}
|
||||
}
|
||||
|
||||
impl SubstrateFinalitySyncPipeline for MillauFinalityToRialto {
|
||||
type FinalitySyncPipeline = FinalityPipelineMillauToRialto;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_millau::BEST_FINALIZED_MILLAU_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_millau::BEST_FINALIZED_MILLAU_HEADER_METHOD;
|
||||
|
||||
type TargetChain = Rialto;
|
||||
|
||||
@@ -59,8 +61,11 @@ impl SubstrateFinalitySyncPipeline for MillauFinalityToRialto {
|
||||
header: MillauSyncHeader,
|
||||
proof: GrandpaJustification<bp_millau::Header>,
|
||||
) -> Bytes {
|
||||
let call =
|
||||
rialto_runtime::BridgeGrandpaMillauCall::submit_finality_proof(Box::new(header.into_inner()), proof).into();
|
||||
let call = rialto_runtime::BridgeGrandpaMillauCall::submit_finality_proof(
|
||||
Box::new(header.into_inner()),
|
||||
proof,
|
||||
)
|
||||
.into();
|
||||
|
||||
let genesis_hash = *self.finality_pipeline.target_client.genesis_hash();
|
||||
let transaction = Rialto::sign_transaction(
|
||||
|
||||
@@ -26,16 +26,22 @@ use bp_messages::MessageNonce;
|
||||
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
|
||||
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_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, IndexOf, TransactionSignScheme, UnsignedTransaction};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use substrate_relay_helper::messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
use substrate_relay_helper::{
|
||||
messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics,
|
||||
SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
},
|
||||
messages_source::SubstrateMessagesSource,
|
||||
messages_target::SubstrateMessagesTarget,
|
||||
};
|
||||
use substrate_relay_helper::messages_source::SubstrateMessagesSource;
|
||||
use substrate_relay_helper::messages_target::SubstrateMessagesTarget;
|
||||
|
||||
/// Millau-to-Rialto message lane.
|
||||
pub type MessageLaneMillauMessagesToRialto =
|
||||
@@ -49,23 +55,30 @@ pub struct MillauMessagesToRialto {
|
||||
impl SubstrateMessageLane for MillauMessagesToRialto {
|
||||
type MessageLane = MessageLaneMillauMessagesToRialto;
|
||||
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str = bp_rialto::TO_RIALTO_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_rialto::TO_RIALTO_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_GENERATED_NONCE_METHOD: &'static str =
|
||||
bp_rialto::TO_RIALTO_LATEST_GENERATED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_rialto::TO_RIALTO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_rialto::TO_RIALTO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_millau::FROM_MILLAU_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_millau::FROM_MILLAU_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
|
||||
bp_millau::FROM_MILLAU_LATEST_CONFIRMED_NONCE_METHOD;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str = bp_millau::FROM_MILLAU_UNREWARDED_RELAYERS_STATE;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str =
|
||||
bp_millau::FROM_MILLAU_UNREWARDED_RELAYERS_STATE;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_millau::BEST_FINALIZED_MILLAU_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str = bp_rialto::BEST_FINALIZED_RIALTO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_millau::BEST_FINALIZED_MILLAU_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str =
|
||||
bp_rialto::BEST_FINALIZED_RIALTO_HEADER_METHOD;
|
||||
|
||||
const MESSAGE_PALLET_NAME_AT_SOURCE: &'static str = bp_millau::WITH_RIALTO_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_TARGET: &'static str = bp_rialto::WITH_MILLAU_MESSAGES_PALLET_NAME;
|
||||
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight = bp_rialto::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight =
|
||||
bp_rialto::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
|
||||
type SourceChain = Millau;
|
||||
type TargetChain = Rialto;
|
||||
@@ -82,7 +95,8 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
|
||||
) -> Bytes {
|
||||
let (relayers_state, proof) = proof;
|
||||
let call: millau_runtime::Call =
|
||||
millau_runtime::MessagesCall::receive_messages_delivery_proof(proof, relayers_state).into();
|
||||
millau_runtime::MessagesCall::receive_messages_delivery_proof(proof, relayers_state)
|
||||
.into();
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let genesis_hash = *self.message_lane.source_client.genesis_hash();
|
||||
let transaction = Millau::sign_transaction(
|
||||
@@ -114,11 +128,7 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
|
||||
proof: <Self::MessageLane as MessageLane>::MessagesProof,
|
||||
) -> Bytes {
|
||||
let (dispatch_weight, proof) = proof;
|
||||
let FromBridgedChainMessagesProof {
|
||||
ref nonces_start,
|
||||
ref nonces_end,
|
||||
..
|
||||
} = proof;
|
||||
let FromBridgedChainMessagesProof { ref nonces_start, ref nonces_end, .. } = proof;
|
||||
let messages_count = nonces_end - nonces_start + 1;
|
||||
let call: rialto_runtime::Call = rialto_runtime::MessagesCall::receive_messages_proof(
|
||||
self.message_lane.relayer_id_at_source.clone(),
|
||||
@@ -176,7 +186,9 @@ pub async fn run(
|
||||
let max_messages_size_in_single_batch = bp_rialto::max_extrinsic_size() / 3;
|
||||
// TODO: use Millau weights after https://github.com/paritytech/parity-bridges-common/issues/390
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
select_delivery_transaction_limits::<pallet_bridge_messages::weights::RialtoWeight<millau_runtime::Runtime>>(
|
||||
select_delivery_transaction_limits::<
|
||||
pallet_bridge_messages::weights::RialtoWeight<millau_runtime::Runtime>,
|
||||
>(
|
||||
bp_rialto::max_extrinsic_weight(),
|
||||
bp_rialto::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
);
|
||||
@@ -211,8 +223,10 @@ pub async fn run(
|
||||
reconnect_delay: relay_utils::relay_loop::RECONNECT_DELAY,
|
||||
stall_timeout,
|
||||
delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams {
|
||||
max_unrewarded_relayer_entries_at_target: bp_rialto::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target: bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_unrewarded_relayer_entries_at_target:
|
||||
bp_rialto::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target:
|
||||
bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_messages_in_single_batch,
|
||||
max_messages_weight_in_single_batch,
|
||||
max_messages_size_in_single_batch,
|
||||
@@ -251,7 +265,9 @@ pub(crate) fn add_standalone_metrics(
|
||||
Some(crate::chains::MILLAU_ASSOCIATED_TOKEN_ID),
|
||||
Some(crate::chains::RIALTO_ASSOCIATED_TOKEN_ID),
|
||||
Some((
|
||||
sp_core::storage::StorageKey(millau_runtime::rialto_messages::RialtoToMillauConversionRate::key().to_vec()),
|
||||
sp_core::storage::StorageKey(
|
||||
millau_runtime::rialto_messages::RialtoToMillauConversionRate::key().to_vec(),
|
||||
),
|
||||
millau_runtime::rialto_messages::INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE,
|
||||
)),
|
||||
)
|
||||
|
||||
@@ -38,9 +38,9 @@ mod rococo;
|
||||
mod westend;
|
||||
mod wococo;
|
||||
|
||||
// Millau/Rialto tokens have no any real value, so the conversion rate we use is always 1:1. But we want to
|
||||
// test our code that is intended to work with real-value chains. So to keep it close to 1:1, we'll be treating
|
||||
// Rialto as BTC and Millau as wBTC (only in relayer).
|
||||
// Millau/Rialto tokens have no any real value, so the conversion rate we use is always 1:1. But we
|
||||
// want to test our code that is intended to work with real-value chains. So to keep it close to
|
||||
// 1:1, we'll be treating Rialto as BTC and Millau as wBTC (only in relayer).
|
||||
|
||||
/// The identifier of token, which value is associated with Rialto token value by relayer.
|
||||
pub(crate) const RIALTO_ASSOCIATED_TOKEN_ID: &str = polkadot::TOKEN_ID;
|
||||
@@ -53,8 +53,8 @@ pub(crate) fn add_polkadot_kusama_price_metrics<T: finality_relay::FinalitySyncP
|
||||
prefix: Option<String>,
|
||||
params: MetricsParams,
|
||||
) -> anyhow::Result<MetricsParams> {
|
||||
// Polkadot/Kusama prices are added as metrics here, because atm we don't have Polkadot <-> Kusama
|
||||
// relays, but we want to test metrics/dashboards in advance
|
||||
// Polkadot/Kusama prices are added as metrics here, because atm we don't have Polkadot <->
|
||||
// Kusama relays, but we want to test metrics/dashboards in advance
|
||||
Ok(relay_utils::relay_metrics(prefix, params)
|
||||
.standalone_metric(|registry, prefix| {
|
||||
substrate_relay_helper::helpers::token_price_metric(registry, prefix, "polkadot")
|
||||
@@ -92,7 +92,8 @@ mod tests {
|
||||
rialto_runtime::VERSION.spec_version,
|
||||
);
|
||||
|
||||
let rialto_signer = relay_rialto_client::SigningParams::from_string("//Dave", None).unwrap();
|
||||
let rialto_signer =
|
||||
relay_rialto_client::SigningParams::from_string("//Dave", None).unwrap();
|
||||
let signature = rialto_signer.sign(&digest);
|
||||
|
||||
assert!(signature.verify(&digest[..], &rialto_signer.public()));
|
||||
@@ -113,7 +114,8 @@ mod tests {
|
||||
millau_runtime::VERSION.spec_version,
|
||||
);
|
||||
|
||||
let millau_signer = relay_millau_client::SigningParams::from_string("//Dave", None).unwrap();
|
||||
let millau_signer =
|
||||
relay_millau_client::SigningParams::from_string("//Dave", None).unwrap();
|
||||
let signature = millau_signer.sign(&digest);
|
||||
|
||||
assert!(signature.verify(&digest[..], &millau_signer.public()));
|
||||
@@ -128,7 +130,8 @@ mod tests {
|
||||
bp_millau::max_extrinsic_size(),
|
||||
);
|
||||
|
||||
let call: millau_runtime::Call = millau_runtime::SystemCall::remark(vec![42; maximal_remark_size as _]).into();
|
||||
let call: millau_runtime::Call =
|
||||
millau_runtime::SystemCall::remark(vec![42; maximal_remark_size as _]).into();
|
||||
let payload = send_message::message_payload(
|
||||
Default::default(),
|
||||
call.get_dispatch_info().weight,
|
||||
@@ -164,8 +167,9 @@ mod tests {
|
||||
fn maximal_rialto_to_millau_message_dispatch_weight_is_computed_correctly() {
|
||||
use rialto_runtime::millau_messages::Millau;
|
||||
|
||||
let maximal_dispatch_weight =
|
||||
send_message::compute_maximal_message_dispatch_weight(bp_millau::max_extrinsic_weight());
|
||||
let maximal_dispatch_weight = send_message::compute_maximal_message_dispatch_weight(
|
||||
bp_millau::max_extrinsic_weight(),
|
||||
);
|
||||
let call: millau_runtime::Call = rialto_runtime::SystemCall::remark(vec![]).into();
|
||||
|
||||
let payload = send_message::message_payload(
|
||||
@@ -191,8 +195,9 @@ mod tests {
|
||||
fn maximal_weight_fill_block_to_rialto_is_generated_correctly() {
|
||||
use millau_runtime::rialto_messages::Rialto;
|
||||
|
||||
let maximal_dispatch_weight =
|
||||
send_message::compute_maximal_message_dispatch_weight(bp_rialto::max_extrinsic_weight());
|
||||
let maximal_dispatch_weight = send_message::compute_maximal_message_dispatch_weight(
|
||||
bp_rialto::max_extrinsic_weight(),
|
||||
);
|
||||
let call: rialto_runtime::Call = millau_runtime::SystemCall::remark(vec![]).into();
|
||||
|
||||
let payload = send_message::message_payload(
|
||||
@@ -325,7 +330,10 @@ mod westend_tests {
|
||||
votes_ancestries: vec![],
|
||||
};
|
||||
|
||||
let actual = bp_westend::BridgeGrandpaRococoCall::submit_finality_proof(header.clone(), justification.clone());
|
||||
let actual = bp_westend::BridgeGrandpaRococoCall::submit_finality_proof(
|
||||
header.clone(),
|
||||
justification.clone(),
|
||||
);
|
||||
let expected = millau_runtime::BridgeGrandpaRialtoCall::<millau_runtime::Runtime>::submit_finality_proof(
|
||||
Box::new(header),
|
||||
justification,
|
||||
|
||||
@@ -41,41 +41,41 @@ impl CliEncodeCall for Polkadot {
|
||||
|
||||
fn encode_call(call: &Call) -> anyhow::Result<Self::Call> {
|
||||
Ok(match call {
|
||||
Call::Remark { remark_payload, .. } => {
|
||||
relay_polkadot_client::runtime::Call::System(relay_polkadot_client::runtime::SystemCall::remark(
|
||||
Call::Remark { remark_payload, .. } => relay_polkadot_client::runtime::Call::System(
|
||||
relay_polkadot_client::runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
))
|
||||
}
|
||||
Call::BridgeSendMessage {
|
||||
lane,
|
||||
payload,
|
||||
fee,
|
||||
bridge_instance_index,
|
||||
} => match *bridge_instance_index {
|
||||
bridge::POLKADOT_TO_KUSAMA_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
relay_polkadot_client::runtime::Call::BridgeKusamaMessages(
|
||||
relay_polkadot_client::runtime::BridgeKusamaMessagesCall::send_message(lane.0, payload, fee.0),
|
||||
)
|
||||
}
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::POLKADOT_TO_KUSAMA_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
relay_polkadot_client::runtime::Call::BridgeKusamaMessages(
|
||||
relay_polkadot_client::runtime::BridgeKusamaMessagesCall::send_message(
|
||||
lane.0, payload, fee.0,
|
||||
),
|
||||
)
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
_ => anyhow::bail!("Unsupported Polkadot call: {:?}", call),
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(call: &relay_polkadot_client::runtime::Call) -> anyhow::Result<DispatchInfo> {
|
||||
fn get_dispatch_info(
|
||||
call: &relay_polkadot_client::runtime::Call,
|
||||
) -> anyhow::Result<DispatchInfo> {
|
||||
match *call {
|
||||
relay_polkadot_client::runtime::Call::System(relay_polkadot_client::runtime::SystemCall::remark(_)) => {
|
||||
Ok(DispatchInfo {
|
||||
weight: crate::chains::polkadot::SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
})
|
||||
}
|
||||
relay_polkadot_client::runtime::Call::System(
|
||||
relay_polkadot_client::runtime::SystemCall::remark(_),
|
||||
) => Ok(DispatchInfo {
|
||||
weight: crate::chains::polkadot::SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
}),
|
||||
_ => anyhow::bail!("Unsupported Polkadot call: {:?}", call),
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,9 @@ impl CliChain for Polkadot {
|
||||
bp_polkadot::max_extrinsic_weight()
|
||||
}
|
||||
|
||||
fn encode_message(_message: encode_message::MessagePayload) -> Result<Self::MessagePayload, String> {
|
||||
fn encode_message(
|
||||
_message: encode_message::MessagePayload,
|
||||
) -> Result<Self::MessagePayload, String> {
|
||||
Err("Sending messages from Polkadot is not yet supported.".into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,15 @@ use relay_kusama_client::{Kusama, SigningParams as KusamaSigningParams};
|
||||
use relay_polkadot_client::{Polkadot, SyncHeader as PolkadotSyncHeader};
|
||||
use relay_substrate_client::{Client, TransactionSignScheme, UnsignedTransaction};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use substrate_relay_helper::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate};
|
||||
use substrate_relay_helper::finality_pipeline::{
|
||||
SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate,
|
||||
};
|
||||
|
||||
/// Maximal saturating difference between `balance(now)` and `balance(now-24h)` to treat
|
||||
/// relay as gone wild.
|
||||
///
|
||||
/// Actual value, returned by `maximal_balance_decrease_per_day_is_sane` test is approximately 0.001 KSM,
|
||||
/// but let's round up to 0.1 KSM here.
|
||||
/// Actual value, returned by `maximal_balance_decrease_per_day_is_sane` test is approximately 0.001
|
||||
/// KSM, but let's round up to 0.1 KSM here.
|
||||
pub(crate) const MAXIMAL_BALANCE_DECREASE_PER_DAY: bp_polkadot::Balance = 100_000_000_000;
|
||||
|
||||
/// Polkadot-to-Kusama finality sync pipeline.
|
||||
@@ -45,7 +47,10 @@ pub(crate) struct PolkadotFinalityToKusama {
|
||||
impl PolkadotFinalityToKusama {
|
||||
pub fn new(target_client: Client<Kusama>, target_sign: KusamaSigningParams) -> Self {
|
||||
Self {
|
||||
finality_pipeline: FinalityPipelinePolkadotFinalityToKusama::new(target_client, target_sign),
|
||||
finality_pipeline: FinalityPipelinePolkadotFinalityToKusama::new(
|
||||
target_client,
|
||||
target_sign,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +58,8 @@ impl PolkadotFinalityToKusama {
|
||||
impl SubstrateFinalitySyncPipeline for PolkadotFinalityToKusama {
|
||||
type FinalitySyncPipeline = FinalityPipelinePolkadotFinalityToKusama;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_polkadot::BEST_FINALIZED_POLKADOT_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_polkadot::BEST_FINALIZED_POLKADOT_HEADER_METHOD;
|
||||
|
||||
type TargetChain = Kusama;
|
||||
|
||||
|
||||
@@ -25,17 +25,23 @@ use bp_messages::MessageNonce;
|
||||
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
|
||||
use frame_support::weights::Weight;
|
||||
use messages_relay::message_lane::MessageLane;
|
||||
use relay_kusama_client::{HeaderId as KusamaHeaderId, Kusama, SigningParams as KusamaSigningParams};
|
||||
use relay_polkadot_client::{HeaderId as PolkadotHeaderId, Polkadot, SigningParams as PolkadotSigningParams};
|
||||
use relay_kusama_client::{
|
||||
HeaderId as KusamaHeaderId, Kusama, SigningParams as KusamaSigningParams,
|
||||
};
|
||||
use relay_polkadot_client::{
|
||||
HeaderId as PolkadotHeaderId, Polkadot, SigningParams as PolkadotSigningParams,
|
||||
};
|
||||
use relay_substrate_client::{Chain, Client, TransactionSignScheme, UnsignedTransaction};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use sp_runtime::{FixedPointNumber, FixedU128};
|
||||
use substrate_relay_helper::messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
use substrate_relay_helper::{
|
||||
messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics,
|
||||
SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
},
|
||||
messages_source::SubstrateMessagesSource,
|
||||
messages_target::SubstrateMessagesTarget,
|
||||
};
|
||||
use substrate_relay_helper::messages_source::SubstrateMessagesSource;
|
||||
use substrate_relay_helper::messages_target::SubstrateMessagesTarget;
|
||||
|
||||
/// Polkadot-to-Kusama message lane.
|
||||
pub type MessageLanePolkadotMessagesToKusama =
|
||||
@@ -48,24 +54,32 @@ pub struct PolkadotMessagesToKusama {
|
||||
|
||||
impl SubstrateMessageLane for PolkadotMessagesToKusama {
|
||||
type MessageLane = MessageLanePolkadotMessagesToKusama;
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str = bp_kusama::TO_KUSAMA_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_kusama::TO_KUSAMA_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_GENERATED_NONCE_METHOD: &'static str =
|
||||
bp_kusama::TO_KUSAMA_LATEST_GENERATED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_kusama::TO_KUSAMA_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_kusama::TO_KUSAMA_LATEST_RECEIVED_NONCE_METHOD;
|
||||
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_polkadot::FROM_POLKADOT_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
|
||||
bp_polkadot::FROM_POLKADOT_LATEST_CONFIRMED_NONCE_METHOD;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str = bp_polkadot::FROM_POLKADOT_UNREWARDED_RELAYERS_STATE;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str =
|
||||
bp_polkadot::FROM_POLKADOT_UNREWARDED_RELAYERS_STATE;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_polkadot::BEST_FINALIZED_POLKADOT_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str = bp_kusama::BEST_FINALIZED_KUSAMA_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_polkadot::BEST_FINALIZED_POLKADOT_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str =
|
||||
bp_kusama::BEST_FINALIZED_KUSAMA_HEADER_METHOD;
|
||||
|
||||
const MESSAGE_PALLET_NAME_AT_SOURCE: &'static str = bp_polkadot::WITH_KUSAMA_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_TARGET: &'static str = bp_kusama::WITH_POLKADOT_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_SOURCE: &'static str =
|
||||
bp_polkadot::WITH_KUSAMA_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_TARGET: &'static str =
|
||||
bp_kusama::WITH_POLKADOT_MESSAGES_PALLET_NAME;
|
||||
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight = bp_kusama::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight =
|
||||
bp_kusama::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
|
||||
type SourceChain = Polkadot;
|
||||
type TargetChain = Kusama;
|
||||
@@ -116,11 +130,7 @@ impl SubstrateMessageLane for PolkadotMessagesToKusama {
|
||||
proof: <Self::MessageLane as MessageLane>::MessagesProof,
|
||||
) -> Bytes {
|
||||
let (dispatch_weight, proof) = proof;
|
||||
let FromBridgedChainMessagesProof {
|
||||
ref nonces_start,
|
||||
ref nonces_end,
|
||||
..
|
||||
} = proof;
|
||||
let FromBridgedChainMessagesProof { ref nonces_start, ref nonces_end, .. } = proof;
|
||||
let messages_count = nonces_end - nonces_start + 1;
|
||||
|
||||
let call = relay_kusama_client::runtime::Call::BridgePolkadotMessages(
|
||||
@@ -179,14 +189,14 @@ pub async fn run(
|
||||
// we don't know exact weights of the Kusama runtime. So to guess weights we'll be using
|
||||
// weights from Rialto and then simply dividing it by x2.
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
select_delivery_transaction_limits::<pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>>(
|
||||
select_delivery_transaction_limits::<
|
||||
pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>,
|
||||
>(
|
||||
bp_kusama::max_extrinsic_weight(),
|
||||
bp_kusama::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
);
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) = (
|
||||
max_messages_in_single_batch / 2,
|
||||
max_messages_weight_in_single_batch / 2,
|
||||
);
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
(max_messages_in_single_batch / 2, max_messages_weight_in_single_batch / 2);
|
||||
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
@@ -218,8 +228,10 @@ pub async fn run(
|
||||
reconnect_delay: relay_utils::relay_loop::RECONNECT_DELAY,
|
||||
stall_timeout,
|
||||
delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams {
|
||||
max_unrewarded_relayer_entries_at_target: bp_kusama::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target: bp_kusama::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_unrewarded_relayer_entries_at_target:
|
||||
bp_kusama::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target:
|
||||
bp_kusama::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_messages_in_single_batch,
|
||||
max_messages_weight_in_single_batch,
|
||||
max_messages_size_in_single_batch,
|
||||
@@ -251,8 +263,10 @@ pub(crate) fn add_standalone_metrics(
|
||||
metrics_params: MetricsParams,
|
||||
source_client: Client<Polkadot>,
|
||||
) -> anyhow::Result<(MetricsParams, StandaloneMessagesMetrics)> {
|
||||
let kusama_to_polkadot_conversion_rate_key =
|
||||
bp_runtime::storage_parameter_key(bp_polkadot::KUSAMA_TO_POLKADOT_CONVERSION_RATE_PARAMETER_NAME).0;
|
||||
let kusama_to_polkadot_conversion_rate_key = bp_runtime::storage_parameter_key(
|
||||
bp_polkadot::KUSAMA_TO_POLKADOT_CONVERSION_RATE_PARAMETER_NAME,
|
||||
)
|
||||
.0;
|
||||
|
||||
substrate_relay_helper::messages_lane::add_standalone_metrics::<PolkadotMessagesToKusama>(
|
||||
metrics_prefix,
|
||||
|
||||
@@ -37,29 +37,26 @@ impl CliEncodeCall for Rialto {
|
||||
fn encode_call(call: &Call) -> anyhow::Result<Self::Call> {
|
||||
Ok(match call {
|
||||
Call::Raw { data } => Decode::decode(&mut &*data.0)?,
|
||||
Call::Remark { remark_payload, .. } => rialto_runtime::Call::System(rialto_runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
)),
|
||||
Call::Remark { remark_payload, .. } =>
|
||||
rialto_runtime::Call::System(rialto_runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
)),
|
||||
Call::Transfer { recipient, amount } => rialto_runtime::Call::Balances(
|
||||
rialto_runtime::BalancesCall::transfer(recipient.raw_id().into(), amount.0),
|
||||
),
|
||||
Call::BridgeSendMessage {
|
||||
lane,
|
||||
payload,
|
||||
fee,
|
||||
bridge_instance_index,
|
||||
} => match *bridge_instance_index {
|
||||
bridge::RIALTO_TO_MILLAU_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
rialto_runtime::Call::BridgeMillauMessages(rialto_runtime::MessagesCall::send_message(
|
||||
lane.0, payload, fee.0,
|
||||
))
|
||||
}
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::RIALTO_TO_MILLAU_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
rialto_runtime::Call::BridgeMillauMessages(
|
||||
rialto_runtime::MessagesCall::send_message(lane.0, payload, fee.0),
|
||||
)
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -72,7 +69,12 @@ impl CliChain for Rialto {
|
||||
const RUNTIME_VERSION: RuntimeVersion = rialto_runtime::VERSION;
|
||||
|
||||
type KeyPair = sp_core::sr25519::Pair;
|
||||
type MessagePayload = MessagePayload<bp_rialto::AccountId, bp_millau::AccountSigner, bp_millau::Signature, Vec<u8>>;
|
||||
type MessagePayload = MessagePayload<
|
||||
bp_rialto::AccountId,
|
||||
bp_millau::AccountSigner,
|
||||
bp_millau::Signature,
|
||||
Vec<u8>,
|
||||
>;
|
||||
|
||||
fn ss58_format() -> u16 {
|
||||
rialto_runtime::SS58Prefix::get() as u16
|
||||
@@ -82,7 +84,9 @@ impl CliChain for Rialto {
|
||||
bp_rialto::max_extrinsic_weight()
|
||||
}
|
||||
|
||||
fn encode_message(message: encode_message::MessagePayload) -> Result<Self::MessagePayload, String> {
|
||||
fn encode_message(
|
||||
message: encode_message::MessagePayload,
|
||||
) -> Result<Self::MessagePayload, String> {
|
||||
match message {
|
||||
encode_message::MessagePayload::Raw { data } => MessagePayload::decode(&mut &*data.0)
|
||||
.map_err(|e| format!("Failed to decode Rialto's MessagePayload: {:?}", e)),
|
||||
@@ -93,7 +97,10 @@ impl CliChain for Rialto {
|
||||
sender.enforce_chain::<Source>();
|
||||
let spec_version = Target::RUNTIME_VERSION.spec_version;
|
||||
let origin = CallOrigin::SourceAccount(sender.raw_id());
|
||||
encode_call::preprocess_call::<Source, Target>(&mut call, bridge::RIALTO_TO_MILLAU_INDEX);
|
||||
encode_call::preprocess_call::<Source, Target>(
|
||||
&mut call,
|
||||
bridge::RIALTO_TO_MILLAU_INDEX,
|
||||
);
|
||||
let call = Target::encode_call(&call).map_err(|e| e.to_string())?;
|
||||
let weight = call.get_dispatch_info().weight;
|
||||
|
||||
@@ -104,7 +111,7 @@ impl CliChain for Rialto {
|
||||
&call,
|
||||
DispatchFeePayment::AtSourceChain,
|
||||
))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@ 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::{Client, IndexOf, TransactionSignScheme, UnsignedTransaction};
|
||||
use substrate_relay_helper::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate};
|
||||
use substrate_relay_helper::finality_pipeline::{
|
||||
SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate,
|
||||
};
|
||||
|
||||
/// Rialto-to-Millau finality sync pipeline.
|
||||
pub(crate) type FinalityPipelineRialtoFinalityToMillau =
|
||||
@@ -37,7 +39,10 @@ pub struct RialtoFinalityToMillau {
|
||||
impl RialtoFinalityToMillau {
|
||||
pub fn new(target_client: Client<Millau>, target_sign: MillauSigningParams) -> Self {
|
||||
Self {
|
||||
finality_pipeline: FinalityPipelineRialtoFinalityToMillau::new(target_client, target_sign),
|
||||
finality_pipeline: FinalityPipelineRialtoFinalityToMillau::new(
|
||||
target_client,
|
||||
target_sign,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +50,8 @@ impl RialtoFinalityToMillau {
|
||||
impl SubstrateFinalitySyncPipeline for RialtoFinalityToMillau {
|
||||
type FinalitySyncPipeline = FinalityPipelineRialtoFinalityToMillau;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_rialto::BEST_FINALIZED_RIALTO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_rialto::BEST_FINALIZED_RIALTO_HEADER_METHOD;
|
||||
|
||||
type TargetChain = Millau;
|
||||
|
||||
|
||||
@@ -26,16 +26,22 @@ use bp_messages::MessageNonce;
|
||||
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
|
||||
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_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, IndexOf, TransactionSignScheme, UnsignedTransaction};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use substrate_relay_helper::messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
use substrate_relay_helper::{
|
||||
messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics,
|
||||
SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
},
|
||||
messages_source::SubstrateMessagesSource,
|
||||
messages_target::SubstrateMessagesTarget,
|
||||
};
|
||||
use substrate_relay_helper::messages_source::SubstrateMessagesSource;
|
||||
use substrate_relay_helper::messages_target::SubstrateMessagesTarget;
|
||||
|
||||
/// Rialto-to-Millau message lane.
|
||||
pub type MessageLaneRialtoMessagesToMillau =
|
||||
@@ -49,23 +55,30 @@ pub struct RialtoMessagesToMillau {
|
||||
impl SubstrateMessageLane for RialtoMessagesToMillau {
|
||||
type MessageLane = MessageLaneRialtoMessagesToMillau;
|
||||
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str = bp_millau::TO_MILLAU_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_millau::TO_MILLAU_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_GENERATED_NONCE_METHOD: &'static str =
|
||||
bp_millau::TO_MILLAU_LATEST_GENERATED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_millau::TO_MILLAU_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_millau::TO_MILLAU_LATEST_RECEIVED_NONCE_METHOD;
|
||||
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_rialto::FROM_RIALTO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_rialto::FROM_RIALTO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
|
||||
bp_rialto::FROM_RIALTO_LATEST_CONFIRMED_NONCE_METHOD;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str = bp_rialto::FROM_RIALTO_UNREWARDED_RELAYERS_STATE;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str =
|
||||
bp_rialto::FROM_RIALTO_UNREWARDED_RELAYERS_STATE;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_rialto::BEST_FINALIZED_RIALTO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str = bp_millau::BEST_FINALIZED_MILLAU_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_rialto::BEST_FINALIZED_RIALTO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str =
|
||||
bp_millau::BEST_FINALIZED_MILLAU_HEADER_METHOD;
|
||||
|
||||
const MESSAGE_PALLET_NAME_AT_SOURCE: &'static str = bp_rialto::WITH_MILLAU_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_TARGET: &'static str = bp_millau::WITH_RIALTO_MESSAGES_PALLET_NAME;
|
||||
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight = bp_millau::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight =
|
||||
bp_millau::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
|
||||
type SourceChain = Rialto;
|
||||
type TargetChain = Millau;
|
||||
@@ -82,7 +95,8 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
|
||||
) -> Bytes {
|
||||
let (relayers_state, proof) = proof;
|
||||
let call: rialto_runtime::Call =
|
||||
rialto_runtime::MessagesCall::receive_messages_delivery_proof(proof, relayers_state).into();
|
||||
rialto_runtime::MessagesCall::receive_messages_delivery_proof(proof, relayers_state)
|
||||
.into();
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let genesis_hash = *self.message_lane.source_client.genesis_hash();
|
||||
let transaction = Rialto::sign_transaction(
|
||||
@@ -114,11 +128,7 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
|
||||
proof: <Self::MessageLane as MessageLane>::MessagesProof,
|
||||
) -> Bytes {
|
||||
let (dispatch_weight, proof) = proof;
|
||||
let FromBridgedChainMessagesProof {
|
||||
ref nonces_start,
|
||||
ref nonces_end,
|
||||
..
|
||||
} = proof;
|
||||
let FromBridgedChainMessagesProof { ref nonces_start, ref nonces_end, .. } = proof;
|
||||
let messages_count = nonces_end - nonces_start + 1;
|
||||
let call: millau_runtime::Call = millau_runtime::MessagesCall::receive_messages_proof(
|
||||
self.message_lane.relayer_id_at_source.clone(),
|
||||
@@ -175,7 +185,9 @@ pub async fn run(
|
||||
// 2/3 is reserved for proofs and tx overhead
|
||||
let max_messages_size_in_single_batch = bp_millau::max_extrinsic_size() / 3;
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
select_delivery_transaction_limits::<pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>>(
|
||||
select_delivery_transaction_limits::<
|
||||
pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>,
|
||||
>(
|
||||
bp_millau::max_extrinsic_weight(),
|
||||
bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
);
|
||||
@@ -210,8 +222,10 @@ pub async fn run(
|
||||
reconnect_delay: relay_utils::relay_loop::RECONNECT_DELAY,
|
||||
stall_timeout,
|
||||
delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams {
|
||||
max_unrewarded_relayer_entries_at_target: bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target: bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_unrewarded_relayer_entries_at_target:
|
||||
bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target:
|
||||
bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_messages_in_single_batch,
|
||||
max_messages_weight_in_single_batch,
|
||||
max_messages_size_in_single_batch,
|
||||
@@ -250,7 +264,9 @@ pub(crate) fn add_standalone_metrics(
|
||||
Some(crate::chains::RIALTO_ASSOCIATED_TOKEN_ID),
|
||||
Some(crate::chains::MILLAU_ASSOCIATED_TOKEN_ID),
|
||||
Some((
|
||||
sp_core::storage::StorageKey(rialto_runtime::millau_messages::MillauToRialtoConversionRate::key().to_vec()),
|
||||
sp_core::storage::StorageKey(
|
||||
rialto_runtime::millau_messages::MillauToRialtoConversionRate::key().to_vec(),
|
||||
),
|
||||
rialto_runtime::millau_messages::INITIAL_MILLAU_TO_RIALTO_CONVERSION_RATE,
|
||||
)),
|
||||
)
|
||||
|
||||
@@ -38,41 +38,41 @@ impl CliEncodeCall for Rococo {
|
||||
|
||||
fn encode_call(call: &Call) -> anyhow::Result<Self::Call> {
|
||||
Ok(match call {
|
||||
Call::Remark { remark_payload, .. } => {
|
||||
relay_rococo_client::runtime::Call::System(relay_rococo_client::runtime::SystemCall::remark(
|
||||
Call::Remark { remark_payload, .. } => relay_rococo_client::runtime::Call::System(
|
||||
relay_rococo_client::runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
))
|
||||
}
|
||||
Call::BridgeSendMessage {
|
||||
lane,
|
||||
payload,
|
||||
fee,
|
||||
bridge_instance_index,
|
||||
} => match *bridge_instance_index {
|
||||
bridge::ROCOCO_TO_WOCOCO_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
relay_rococo_client::runtime::Call::BridgeMessagesWococo(
|
||||
relay_rococo_client::runtime::BridgeMessagesWococoCall::send_message(lane.0, payload, fee.0),
|
||||
)
|
||||
}
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::ROCOCO_TO_WOCOCO_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
relay_rococo_client::runtime::Call::BridgeMessagesWococo(
|
||||
relay_rococo_client::runtime::BridgeMessagesWococoCall::send_message(
|
||||
lane.0, payload, fee.0,
|
||||
),
|
||||
)
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
_ => anyhow::bail!("The call is not supported"),
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(call: &relay_rococo_client::runtime::Call) -> anyhow::Result<DispatchInfo> {
|
||||
fn get_dispatch_info(
|
||||
call: &relay_rococo_client::runtime::Call,
|
||||
) -> anyhow::Result<DispatchInfo> {
|
||||
match *call {
|
||||
relay_rococo_client::runtime::Call::System(relay_rococo_client::runtime::SystemCall::remark(_)) => {
|
||||
Ok(DispatchInfo {
|
||||
weight: SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
})
|
||||
}
|
||||
relay_rococo_client::runtime::Call::System(
|
||||
relay_rococo_client::runtime::SystemCall::remark(_),
|
||||
) => Ok(DispatchInfo {
|
||||
weight: SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
}),
|
||||
_ => anyhow::bail!("Unsupported Rococo call: {:?}", call),
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,9 @@ impl CliChain for Rococo {
|
||||
bp_wococo::max_extrinsic_weight()
|
||||
}
|
||||
|
||||
fn encode_message(_message: encode_message::MessagePayload) -> Result<Self::MessagePayload, String> {
|
||||
fn encode_message(
|
||||
_message: encode_message::MessagePayload,
|
||||
) -> Result<Self::MessagePayload, String> {
|
||||
Err("Sending messages from Rococo is not yet supported.".into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ use relay_rococo_client::{Rococo, SyncHeader as RococoSyncHeader};
|
||||
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};
|
||||
use substrate_relay_helper::finality_pipeline::{
|
||||
SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate,
|
||||
};
|
||||
|
||||
use crate::chains::wococo_headers_to_rococo::MAXIMAL_BALANCE_DECREASE_PER_DAY;
|
||||
|
||||
@@ -40,7 +42,10 @@ pub(crate) struct RococoFinalityToWococo {
|
||||
impl RococoFinalityToWococo {
|
||||
pub fn new(target_client: Client<Wococo>, target_sign: WococoSigningParams) -> Self {
|
||||
Self {
|
||||
finality_pipeline: FinalityPipelineRococoFinalityToWococo::new(target_client, target_sign),
|
||||
finality_pipeline: FinalityPipelineRococoFinalityToWococo::new(
|
||||
target_client,
|
||||
target_sign,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +53,8 @@ impl RococoFinalityToWococo {
|
||||
impl SubstrateFinalitySyncPipeline for RococoFinalityToWococo {
|
||||
type FinalitySyncPipeline = FinalityPipelineRococoFinalityToWococo;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_rococo::BEST_FINALIZED_ROCOCO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_rococo::BEST_FINALIZED_ROCOCO_HEADER_METHOD;
|
||||
|
||||
type TargetChain = Wococo;
|
||||
|
||||
|
||||
@@ -25,16 +25,22 @@ use bp_messages::MessageNonce;
|
||||
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_rococo_client::{
|
||||
HeaderId as RococoHeaderId, Rococo, SigningParams as RococoSigningParams,
|
||||
};
|
||||
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::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
use relay_wococo_client::{
|
||||
HeaderId as WococoHeaderId, SigningParams as WococoSigningParams, Wococo,
|
||||
};
|
||||
use substrate_relay_helper::{
|
||||
messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics,
|
||||
SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
},
|
||||
messages_source::SubstrateMessagesSource,
|
||||
messages_target::SubstrateMessagesTarget,
|
||||
};
|
||||
use substrate_relay_helper::messages_source::SubstrateMessagesSource;
|
||||
use substrate_relay_helper::messages_target::SubstrateMessagesTarget;
|
||||
|
||||
/// Rococo-to-Wococo message lane.
|
||||
pub type MessageLaneRococoMessagesToWococo =
|
||||
@@ -48,23 +54,30 @@ pub struct RococoMessagesToWococo {
|
||||
impl SubstrateMessageLane for RococoMessagesToWococo {
|
||||
type MessageLane = MessageLaneRococoMessagesToWococo;
|
||||
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str = bp_wococo::TO_WOCOCO_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_wococo::TO_WOCOCO_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_GENERATED_NONCE_METHOD: &'static str =
|
||||
bp_wococo::TO_WOCOCO_LATEST_GENERATED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_wococo::TO_WOCOCO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_wococo::TO_WOCOCO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_rococo::FROM_ROCOCO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_rococo::FROM_ROCOCO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
|
||||
bp_rococo::FROM_ROCOCO_LATEST_CONFIRMED_NONCE_METHOD;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str = bp_rococo::FROM_ROCOCO_UNREWARDED_RELAYERS_STATE;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str =
|
||||
bp_rococo::FROM_ROCOCO_UNREWARDED_RELAYERS_STATE;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_rococo::BEST_FINALIZED_ROCOCO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str = bp_wococo::BEST_FINALIZED_WOCOCO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_rococo::BEST_FINALIZED_ROCOCO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str =
|
||||
bp_wococo::BEST_FINALIZED_WOCOCO_HEADER_METHOD;
|
||||
|
||||
const MESSAGE_PALLET_NAME_AT_SOURCE: &'static str = bp_rococo::WITH_WOCOCO_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_TARGET: &'static str = bp_wococo::WITH_ROCOCO_MESSAGES_PALLET_NAME;
|
||||
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight = bp_wococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight =
|
||||
bp_wococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
|
||||
type SourceChain = Rococo;
|
||||
type TargetChain = Wococo;
|
||||
@@ -115,11 +128,7 @@ impl SubstrateMessageLane for RococoMessagesToWococo {
|
||||
proof: <Self::MessageLane as MessageLane>::MessagesProof,
|
||||
) -> Bytes {
|
||||
let (dispatch_weight, proof) = proof;
|
||||
let FromBridgedChainMessagesProof {
|
||||
ref nonces_start,
|
||||
ref nonces_end,
|
||||
..
|
||||
} = proof;
|
||||
let FromBridgedChainMessagesProof { ref nonces_start, ref nonces_end, .. } = proof;
|
||||
let messages_count = nonces_end - nonces_start + 1;
|
||||
|
||||
let call = relay_wococo_client::runtime::Call::BridgeMessagesRococo(
|
||||
@@ -178,14 +187,14 @@ pub async fn run(
|
||||
// we don't know exact weights of the Wococo runtime. So to guess weights we'll be using
|
||||
// weights from Rialto and then simply dividing it by x2.
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
select_delivery_transaction_limits::<pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>>(
|
||||
select_delivery_transaction_limits::<
|
||||
pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>,
|
||||
>(
|
||||
bp_wococo::max_extrinsic_weight(),
|
||||
bp_wococo::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
);
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) = (
|
||||
max_messages_in_single_batch / 2,
|
||||
max_messages_weight_in_single_batch / 2,
|
||||
);
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
(max_messages_in_single_batch / 2, max_messages_weight_in_single_batch / 2);
|
||||
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
@@ -217,8 +226,10 @@ pub async fn run(
|
||||
reconnect_delay: relay_utils::relay_loop::RECONNECT_DELAY,
|
||||
stall_timeout,
|
||||
delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams {
|
||||
max_unrewarded_relayer_entries_at_target: bp_wococo::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target: bp_wococo::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_unrewarded_relayer_entries_at_target:
|
||||
bp_wococo::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target:
|
||||
bp_wococo::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_messages_in_single_batch,
|
||||
max_messages_weight_in_single_batch,
|
||||
max_messages_size_in_single_batch,
|
||||
|
||||
@@ -35,7 +35,9 @@ impl CliChain for Westend {
|
||||
0
|
||||
}
|
||||
|
||||
fn encode_message(_message: encode_message::MessagePayload) -> Result<Self::MessagePayload, String> {
|
||||
fn encode_message(
|
||||
_message: encode_message::MessagePayload,
|
||||
) -> Result<Self::MessagePayload, String> {
|
||||
Err("Sending messages from Westend is not yet supported.".into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ use relay_millau_client::{Millau, SigningParams as MillauSigningParams};
|
||||
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};
|
||||
use substrate_relay_helper::finality_pipeline::{
|
||||
SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate,
|
||||
};
|
||||
|
||||
/// Westend-to-Millau finality sync pipeline.
|
||||
pub(crate) type FinalityPipelineWestendFinalityToMillau =
|
||||
@@ -38,7 +40,10 @@ pub(crate) struct WestendFinalityToMillau {
|
||||
impl WestendFinalityToMillau {
|
||||
pub fn new(target_client: Client<Millau>, target_sign: MillauSigningParams) -> Self {
|
||||
Self {
|
||||
finality_pipeline: FinalityPipelineWestendFinalityToMillau::new(target_client, target_sign),
|
||||
finality_pipeline: FinalityPipelineWestendFinalityToMillau::new(
|
||||
target_client,
|
||||
target_sign,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +51,8 @@ impl WestendFinalityToMillau {
|
||||
impl SubstrateFinalitySyncPipeline for WestendFinalityToMillau {
|
||||
type FinalitySyncPipeline = FinalityPipelineWestendFinalityToMillau;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_westend::BEST_FINALIZED_WESTEND_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_westend::BEST_FINALIZED_WESTEND_HEADER_METHOD;
|
||||
|
||||
type TargetChain = Millau;
|
||||
|
||||
|
||||
@@ -32,41 +32,41 @@ impl CliEncodeCall for Wococo {
|
||||
|
||||
fn encode_call(call: &Call) -> anyhow::Result<Self::Call> {
|
||||
Ok(match call {
|
||||
Call::Remark { remark_payload, .. } => {
|
||||
relay_wococo_client::runtime::Call::System(relay_wococo_client::runtime::SystemCall::remark(
|
||||
Call::Remark { remark_payload, .. } => relay_wococo_client::runtime::Call::System(
|
||||
relay_wococo_client::runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
))
|
||||
}
|
||||
Call::BridgeSendMessage {
|
||||
lane,
|
||||
payload,
|
||||
fee,
|
||||
bridge_instance_index,
|
||||
} => match *bridge_instance_index {
|
||||
bridge::WOCOCO_TO_ROCOCO_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
relay_wococo_client::runtime::Call::BridgeMessagesRococo(
|
||||
relay_wococo_client::runtime::BridgeMessagesRococoCall::send_message(lane.0, payload, fee.0),
|
||||
)
|
||||
}
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::WOCOCO_TO_ROCOCO_INDEX => {
|
||||
let payload = Decode::decode(&mut &*payload.0)?;
|
||||
relay_wococo_client::runtime::Call::BridgeMessagesRococo(
|
||||
relay_wococo_client::runtime::BridgeMessagesRococoCall::send_message(
|
||||
lane.0, payload, fee.0,
|
||||
),
|
||||
)
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
},
|
||||
_ => anyhow::bail!("The call is not supported"),
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(call: &relay_wococo_client::runtime::Call) -> anyhow::Result<DispatchInfo> {
|
||||
fn get_dispatch_info(
|
||||
call: &relay_wococo_client::runtime::Call,
|
||||
) -> anyhow::Result<DispatchInfo> {
|
||||
match *call {
|
||||
relay_wococo_client::runtime::Call::System(relay_wococo_client::runtime::SystemCall::remark(_)) => {
|
||||
Ok(DispatchInfo {
|
||||
weight: crate::chains::rococo::SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
})
|
||||
}
|
||||
relay_wococo_client::runtime::Call::System(
|
||||
relay_wococo_client::runtime::SystemCall::remark(_),
|
||||
) => Ok(DispatchInfo {
|
||||
weight: crate::chains::rococo::SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
}),
|
||||
_ => anyhow::bail!("Unsupported Rococo call: {:?}", call),
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,9 @@ impl CliChain for Wococo {
|
||||
bp_wococo::max_extrinsic_weight()
|
||||
}
|
||||
|
||||
fn encode_message(_message: encode_message::MessagePayload) -> Result<Self::MessagePayload, String> {
|
||||
fn encode_message(
|
||||
_message: encode_message::MessagePayload,
|
||||
) -> Result<Self::MessagePayload, String> {
|
||||
Err("Sending messages from Wococo is not yet supported.".into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ use relay_rococo_client::{Rococo, SigningParams as RococoSigningParams};
|
||||
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};
|
||||
use substrate_relay_helper::finality_pipeline::{
|
||||
SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate,
|
||||
};
|
||||
|
||||
/// Maximal saturating difference between `balance(now)` and `balance(now-24h)` to treat
|
||||
/// relay as gone wild.
|
||||
@@ -45,7 +47,10 @@ pub(crate) struct WococoFinalityToRococo {
|
||||
impl WococoFinalityToRococo {
|
||||
pub fn new(target_client: Client<Rococo>, target_sign: RococoSigningParams) -> Self {
|
||||
Self {
|
||||
finality_pipeline: FinalityPipelineWococoFinalityToRococo::new(target_client, target_sign),
|
||||
finality_pipeline: FinalityPipelineWococoFinalityToRococo::new(
|
||||
target_client,
|
||||
target_sign,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +58,8 @@ impl WococoFinalityToRococo {
|
||||
impl SubstrateFinalitySyncPipeline for WococoFinalityToRococo {
|
||||
type FinalitySyncPipeline = FinalityPipelineWococoFinalityToRococo;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_wococo::BEST_FINALIZED_WOCOCO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_wococo::BEST_FINALIZED_WOCOCO_HEADER_METHOD;
|
||||
|
||||
type TargetChain = Rococo;
|
||||
|
||||
@@ -113,8 +119,10 @@ mod tests {
|
||||
#[test]
|
||||
fn maximal_balance_decrease_per_day_is_sane() {
|
||||
// we expect Wococo -> Rococo relay to be running in all-headers mode
|
||||
let maximal_balance_decrease =
|
||||
compute_maximal_balance_decrease_per_day::<bp_kusama::Balance, bp_kusama::WeightToFee>(bp_wococo::DAYS);
|
||||
let maximal_balance_decrease = compute_maximal_balance_decrease_per_day::<
|
||||
bp_kusama::Balance,
|
||||
bp_kusama::WeightToFee,
|
||||
>(bp_wococo::DAYS);
|
||||
assert!(
|
||||
MAXIMAL_BALANCE_DECREASE_PER_DAY >= maximal_balance_decrease,
|
||||
"Maximal expected loss per day {} is larger than hardcoded {}",
|
||||
|
||||
@@ -25,16 +25,22 @@ use bp_messages::MessageNonce;
|
||||
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_rococo_client::{
|
||||
HeaderId as RococoHeaderId, Rococo, SigningParams as RococoSigningParams,
|
||||
};
|
||||
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::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
use relay_wococo_client::{
|
||||
HeaderId as WococoHeaderId, SigningParams as WococoSigningParams, Wococo,
|
||||
};
|
||||
use substrate_relay_helper::{
|
||||
messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics,
|
||||
SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
},
|
||||
messages_source::SubstrateMessagesSource,
|
||||
messages_target::SubstrateMessagesTarget,
|
||||
};
|
||||
use substrate_relay_helper::messages_source::SubstrateMessagesSource;
|
||||
use substrate_relay_helper::messages_target::SubstrateMessagesTarget;
|
||||
|
||||
/// Wococo-to-Rococo message lane.
|
||||
pub type MessageLaneWococoMessagesToRococo =
|
||||
@@ -47,23 +53,30 @@ pub struct WococoMessagesToRococo {
|
||||
|
||||
impl SubstrateMessageLane for WococoMessagesToRococo {
|
||||
type MessageLane = MessageLaneWococoMessagesToRococo;
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str = bp_rococo::TO_ROCOCO_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_rococo::TO_ROCOCO_MESSAGE_DETAILS_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_GENERATED_NONCE_METHOD: &'static str =
|
||||
bp_rococo::TO_ROCOCO_LATEST_GENERATED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_rococo::TO_ROCOCO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_rococo::TO_ROCOCO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_wococo::FROM_WOCOCO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str =
|
||||
bp_wococo::FROM_WOCOCO_LATEST_RECEIVED_NONCE_METHOD;
|
||||
const INBOUND_LANE_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
|
||||
bp_wococo::FROM_WOCOCO_LATEST_CONFIRMED_NONCE_METHOD;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str = bp_wococo::FROM_WOCOCO_UNREWARDED_RELAYERS_STATE;
|
||||
const INBOUND_LANE_UNREWARDED_RELAYERS_STATE: &'static str =
|
||||
bp_wococo::FROM_WOCOCO_UNREWARDED_RELAYERS_STATE;
|
||||
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_wococo::BEST_FINALIZED_WOCOCO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str = bp_rococo::BEST_FINALIZED_ROCOCO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str =
|
||||
bp_wococo::BEST_FINALIZED_WOCOCO_HEADER_METHOD;
|
||||
const BEST_FINALIZED_TARGET_HEADER_ID_AT_SOURCE: &'static str =
|
||||
bp_rococo::BEST_FINALIZED_ROCOCO_HEADER_METHOD;
|
||||
|
||||
const MESSAGE_PALLET_NAME_AT_SOURCE: &'static str = bp_wococo::WITH_ROCOCO_MESSAGES_PALLET_NAME;
|
||||
const MESSAGE_PALLET_NAME_AT_TARGET: &'static str = bp_rococo::WITH_WOCOCO_MESSAGES_PALLET_NAME;
|
||||
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight = bp_rococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_TARGET_CHAIN: Weight =
|
||||
bp_rococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
|
||||
type SourceChain = Wococo;
|
||||
type TargetChain = Rococo;
|
||||
@@ -114,11 +127,7 @@ impl SubstrateMessageLane for WococoMessagesToRococo {
|
||||
proof: <Self::MessageLane as MessageLane>::MessagesProof,
|
||||
) -> Bytes {
|
||||
let (dispatch_weight, proof) = proof;
|
||||
let FromBridgedChainMessagesProof {
|
||||
ref nonces_start,
|
||||
ref nonces_end,
|
||||
..
|
||||
} = proof;
|
||||
let FromBridgedChainMessagesProof { ref nonces_start, ref nonces_end, .. } = proof;
|
||||
let messages_count = nonces_end - nonces_start + 1;
|
||||
|
||||
let call = relay_rococo_client::runtime::Call::BridgeMessagesWococo(
|
||||
@@ -177,14 +186,14 @@ pub async fn run(
|
||||
// we don't know exact weights of the Rococo runtime. So to guess weights we'll be using
|
||||
// weights from Rialto and then simply dividing it by x2.
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
select_delivery_transaction_limits::<pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>>(
|
||||
select_delivery_transaction_limits::<
|
||||
pallet_bridge_messages::weights::RialtoWeight<rialto_runtime::Runtime>,
|
||||
>(
|
||||
bp_rococo::max_extrinsic_weight(),
|
||||
bp_rococo::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
);
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) = (
|
||||
max_messages_in_single_batch / 2,
|
||||
max_messages_weight_in_single_batch / 2,
|
||||
);
|
||||
let (max_messages_in_single_batch, max_messages_weight_in_single_batch) =
|
||||
(max_messages_in_single_batch / 2, max_messages_weight_in_single_batch / 2);
|
||||
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
@@ -216,8 +225,10 @@ pub async fn run(
|
||||
reconnect_delay: relay_utils::relay_loop::RECONNECT_DELAY,
|
||||
stall_timeout,
|
||||
delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams {
|
||||
max_unrewarded_relayer_entries_at_target: bp_rococo::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target: bp_rococo::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_unrewarded_relayer_entries_at_target:
|
||||
bp_rococo::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
|
||||
max_unconfirmed_nonces_at_target:
|
||||
bp_rococo::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
|
||||
max_messages_in_single_batch,
|
||||
max_messages_weight_in_single_batch,
|
||||
max_messages_size_in_single_batch,
|
||||
|
||||
@@ -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