mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 11:01:01 +00:00
Remove support for encoded-call messaging from relay and runtime integration code (#1376)
* remove support for encoded-call messaging * continue cleanup * continue cleanup * continue cleanup * more cleanpup * more cleanup * fmt * continue cleanup * spellcheck * rename * fix benchmarks * mention encoded-calls-messaging tag * fixing deployments * fix messages generation * fmt
This commit is contained in:
committed by
Bastian Köcher
parent
dc96aeea35
commit
d582061dff
@@ -16,18 +16,14 @@
|
||||
|
||||
use crate::cli::{
|
||||
bridge::FullBridge,
|
||||
encode_call::{self, CliEncodeCall},
|
||||
encode_message::{self, CliEncodeMessage},
|
||||
estimate_fee::{estimate_message_delivery_and_dispatch_fee, ConversionRateOverride},
|
||||
Balance, ExplicitOrMaximal, HexBytes, HexLaneId, Origins, SourceConnectionParams,
|
||||
SourceSigningParams, TargetConnectionParams, TargetSigningParams,
|
||||
Balance, HexBytes, HexLaneId, SourceConnectionParams, SourceSigningParams,
|
||||
};
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use bp_runtime::Chain as _;
|
||||
use codec::Encode;
|
||||
use frame_support::weights::Weight;
|
||||
use relay_substrate_client::{Chain, SignParam, TransactionSignScheme, UnsignedTransaction};
|
||||
use sp_core::{Bytes, Pair};
|
||||
use sp_runtime::{traits::IdentifyAccount, AccountId32, MultiSignature, MultiSigner};
|
||||
use sp_runtime::AccountId32;
|
||||
use std::fmt::Debug;
|
||||
use structopt::StructOpt;
|
||||
use strum::{EnumString, EnumVariantNames, VariantNames};
|
||||
@@ -61,8 +57,6 @@ pub struct SendMessage {
|
||||
source: SourceConnectionParams,
|
||||
#[structopt(flatten)]
|
||||
source_sign: SourceSigningParams,
|
||||
#[structopt(flatten)]
|
||||
target_sign: TargetSigningParams,
|
||||
/// Hex-encoded lane id. Defaults to `00000000`.
|
||||
#[structopt(long, default_value = "00000000")]
|
||||
lane: HexLaneId,
|
||||
@@ -72,104 +66,20 @@ pub struct SendMessage {
|
||||
/// your message won't be relayed.
|
||||
#[structopt(long)]
|
||||
conversion_rate_override: Option<ConversionRateOverride>,
|
||||
/// Where dispatch fee is paid?
|
||||
#[structopt(
|
||||
long,
|
||||
possible_values = DispatchFeePayment::VARIANTS,
|
||||
case_insensitive = true,
|
||||
default_value = "at-source-chain",
|
||||
)]
|
||||
dispatch_fee_payment: DispatchFeePayment,
|
||||
/// 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.
|
||||
#[structopt(long)]
|
||||
fee: Option<Balance>,
|
||||
/// Message type.
|
||||
#[structopt(subcommand)]
|
||||
message: crate::cli::encode_call::Call,
|
||||
/// The origin to use when dispatching the message on the target chain. Defaults to
|
||||
/// `SourceAccount`.
|
||||
#[structopt(long, possible_values = &Origins::variants(), default_value = "Source")]
|
||||
origin: Origins,
|
||||
|
||||
// Normally we don't need to connect to the target chain to send message. But for testing
|
||||
// we may want to use **actual** `spec_version` of the target chain when composing a message.
|
||||
// Then we'll need to read version from the target chain node.
|
||||
#[structopt(flatten)]
|
||||
target: TargetConnectionParams,
|
||||
message: crate::cli::encode_message::Message,
|
||||
}
|
||||
|
||||
impl SendMessage {
|
||||
pub async fn encode_payload(
|
||||
&mut self,
|
||||
) -> anyhow::Result<MessagePayload<AccountId32, MultiSigner, MultiSignature, Vec<u8>>> {
|
||||
crate::select_full_bridge!(self.bridge, {
|
||||
let SendMessage {
|
||||
source_sign,
|
||||
target_sign,
|
||||
ref mut message,
|
||||
dispatch_fee_payment,
|
||||
dispatch_weight,
|
||||
origin,
|
||||
bridge,
|
||||
..
|
||||
} = self;
|
||||
|
||||
let source_sign = source_sign.to_keypair::<Source>()?;
|
||||
|
||||
encode_call::preprocess_call::<Source, Target>(message, bridge.bridge_instance_index());
|
||||
let target_call = Target::encode_call(message)?;
|
||||
let target_spec_version = self.target.selected_chain_spec_version::<Target>().await?;
|
||||
|
||||
let payload = {
|
||||
let target_call_weight = prepare_call_dispatch_weight(
|
||||
dispatch_weight,
|
||||
|| {
|
||||
Ok(ExplicitOrMaximal::Explicit(
|
||||
Target::get_dispatch_info(&target_call)?.weight,
|
||||
))
|
||||
},
|
||||
compute_maximal_message_dispatch_weight(Target::max_extrinsic_weight()),
|
||||
)?;
|
||||
let source_sender_public: MultiSigner = source_sign.public().into();
|
||||
let source_account_id = source_sender_public.into_account();
|
||||
|
||||
message_payload(
|
||||
target_spec_version,
|
||||
target_call_weight,
|
||||
match origin {
|
||||
Origins::Source => CallOrigin::SourceAccount(source_account_id),
|
||||
Origins::Target => {
|
||||
let target_sign = target_sign.to_keypair::<Target>()?;
|
||||
let digest = account_ownership_digest(
|
||||
&target_call,
|
||||
source_account_id.clone(),
|
||||
target_spec_version,
|
||||
);
|
||||
let target_origin_public = target_sign.public();
|
||||
let digest_signature = target_sign.sign(&digest);
|
||||
CallOrigin::TargetAccount(
|
||||
source_account_id,
|
||||
target_origin_public.into(),
|
||||
digest_signature.into(),
|
||||
)
|
||||
},
|
||||
},
|
||||
&target_call,
|
||||
*dispatch_fee_payment,
|
||||
)
|
||||
};
|
||||
Ok(payload)
|
||||
})
|
||||
}
|
||||
|
||||
/// Run the command.
|
||||
pub async fn run(mut self) -> anyhow::Result<()> {
|
||||
pub async fn run(self) -> anyhow::Result<()> {
|
||||
crate::select_full_bridge!(self.bridge, {
|
||||
let payload = self.encode_payload().await?;
|
||||
let payload = encode_message::encode_message::<Source, Target>(&self.message)?;
|
||||
|
||||
let source_client = self.source.to_client::<Source>().await?;
|
||||
let source_sign = self.source_sign.to_keypair::<Source>()?;
|
||||
@@ -189,14 +99,13 @@ impl SendMessage {
|
||||
.await? as _,
|
||||
),
|
||||
};
|
||||
let dispatch_weight = payload.weight;
|
||||
let payload_len = payload.encode().len();
|
||||
let send_message_call = Source::encode_call(&encode_call::Call::BridgeSendMessage {
|
||||
bridge_instance_index: self.bridge.bridge_instance_index(),
|
||||
lane: self.lane,
|
||||
payload: HexBytes::encode(&payload),
|
||||
fee,
|
||||
})?;
|
||||
let send_message_call = Source::encode_send_message_call(
|
||||
self.lane.0,
|
||||
payload,
|
||||
fee.cast().into(),
|
||||
self.bridge.bridge_instance_index(),
|
||||
)?;
|
||||
|
||||
let source_genesis_hash = *source_client.genesis_hash();
|
||||
let (spec_version, transaction_version) =
|
||||
@@ -228,11 +137,10 @@ impl SendMessage {
|
||||
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"Sending message to {}. Lane: {:?}. Size: {}. Dispatch weight: {}. Fee: {}",
|
||||
"Sending message to {}. Lane: {:?}. Size: {}. Fee: {}",
|
||||
Target::NAME,
|
||||
lane,
|
||||
payload_len,
|
||||
dispatch_weight,
|
||||
fee,
|
||||
);
|
||||
log::info!(
|
||||
@@ -260,66 +168,15 @@ impl SendMessage {
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_call_dispatch_weight(
|
||||
user_specified_dispatch_weight: &Option<ExplicitOrMaximal<Weight>>,
|
||||
weight_from_pre_dispatch_call: impl Fn() -> anyhow::Result<ExplicitOrMaximal<Weight>>,
|
||||
maximal_allowed_weight: Weight,
|
||||
) -> anyhow::Result<Weight> {
|
||||
match user_specified_dispatch_weight
|
||||
.clone()
|
||||
.map(Ok)
|
||||
.unwrap_or_else(weight_from_pre_dispatch_call)?
|
||||
{
|
||||
ExplicitOrMaximal::Explicit(weight) => Ok(weight),
|
||||
ExplicitOrMaximal::Maximal => Ok(maximal_allowed_weight),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn message_payload<SAccountId, TPublic, TSignature>(
|
||||
spec_version: u32,
|
||||
weight: Weight,
|
||||
origin: CallOrigin<SAccountId, TPublic, TSignature>,
|
||||
call: &impl Encode,
|
||||
dispatch_fee_payment: DispatchFeePayment,
|
||||
) -> MessagePayload<SAccountId, TPublic, TSignature, Vec<u8>>
|
||||
where
|
||||
SAccountId: Encode + Debug,
|
||||
TPublic: Encode + Debug,
|
||||
TSignature: Encode + Debug,
|
||||
{
|
||||
// Display nicely formatted call.
|
||||
let payload = MessagePayload {
|
||||
spec_version,
|
||||
weight,
|
||||
origin,
|
||||
dispatch_fee_payment: dispatch_fee_payment.into(),
|
||||
call: HexBytes::encode(call),
|
||||
};
|
||||
|
||||
log::info!(target: "bridge", "Created Message Payload: {:#?}", payload);
|
||||
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 }
|
||||
}
|
||||
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::cli::CliChain;
|
||||
use hex_literal::hex;
|
||||
use crate::cli::ExplicitOrMaximal;
|
||||
|
||||
#[async_std::test]
|
||||
async fn send_remark_rialto_to_millau() {
|
||||
#[test]
|
||||
fn send_raw_rialto_to_millau() {
|
||||
// given
|
||||
let mut send_message = SendMessage::from_iter(vec![
|
||||
let send_message = SendMessage::from_iter(vec![
|
||||
"send-message",
|
||||
"rialto-to-millau",
|
||||
"--source-port",
|
||||
@@ -328,117 +185,48 @@ mod tests {
|
||||
"//Alice",
|
||||
"--conversion-rate-override",
|
||||
"0.75",
|
||||
"remark",
|
||||
"--remark-payload",
|
||||
"1234",
|
||||
"raw",
|
||||
"dead",
|
||||
]);
|
||||
|
||||
// when
|
||||
let payload = send_message.encode_payload().await.unwrap();
|
||||
|
||||
// then
|
||||
assert_eq!(send_message.bridge, FullBridge::RialtoToMillau);
|
||||
assert_eq!(send_message.source.source_port, 1234);
|
||||
assert_eq!(send_message.source_sign.source_signer, Some("//Alice".into()));
|
||||
assert_eq!(
|
||||
payload,
|
||||
MessagePayload {
|
||||
spec_version: relay_millau_client::Millau::RUNTIME_VERSION.spec_version,
|
||||
weight: 0,
|
||||
origin: CallOrigin::SourceAccount(
|
||||
sp_keyring::AccountKeyring::Alice.to_account_id()
|
||||
),
|
||||
dispatch_fee_payment: bp_runtime::messages::DispatchFeePayment::AtSourceChain,
|
||||
call: hex!("0001081234").to_vec(),
|
||||
}
|
||||
send_message.conversion_rate_override,
|
||||
Some(ConversionRateOverride::Explicit(0.75))
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn send_remark_millau_to_rialto() {
|
||||
// given
|
||||
let mut send_message = SendMessage::from_iter(vec![
|
||||
"send-message",
|
||||
"millau-to-rialto",
|
||||
"--source-port",
|
||||
"1234",
|
||||
"--source-signer",
|
||||
"//Alice",
|
||||
"--origin",
|
||||
"Target",
|
||||
"--target-signer",
|
||||
"//Bob",
|
||||
"--conversion-rate-override",
|
||||
"metric",
|
||||
"remark",
|
||||
"--remark-payload",
|
||||
"1234",
|
||||
]);
|
||||
|
||||
// when
|
||||
let payload = send_message.encode_payload().await.unwrap();
|
||||
|
||||
// then
|
||||
// Since signatures are randomized we extract it from here and only check the rest.
|
||||
let signature = match payload.origin {
|
||||
CallOrigin::TargetAccount(_, _, ref sig) => sig.clone(),
|
||||
_ => panic!("Unexpected `CallOrigin`: {:?}", payload),
|
||||
};
|
||||
assert_eq!(
|
||||
payload,
|
||||
MessagePayload {
|
||||
spec_version: relay_millau_client::Millau::RUNTIME_VERSION.spec_version,
|
||||
weight: 0,
|
||||
origin: CallOrigin::TargetAccount(
|
||||
sp_keyring::AccountKeyring::Alice.to_account_id(),
|
||||
sp_keyring::AccountKeyring::Bob.into(),
|
||||
signature,
|
||||
),
|
||||
dispatch_fee_payment: bp_runtime::messages::DispatchFeePayment::AtSourceChain,
|
||||
call: hex!("0001081234").to_vec(),
|
||||
}
|
||||
send_message.message,
|
||||
crate::cli::encode_message::Message::Raw { data: HexBytes(vec![0xDE, 0xAD]) }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_send_message_command_without_target_sign_options() {
|
||||
fn send_sized_rialto_to_millau() {
|
||||
// given
|
||||
let send_message = SendMessage::from_iter_safe(vec![
|
||||
let send_message = SendMessage::from_iter(vec![
|
||||
"send-message",
|
||||
"rialto-to-millau",
|
||||
"--source-port",
|
||||
"1234",
|
||||
"--source-signer",
|
||||
"//Alice",
|
||||
"--origin",
|
||||
"Target",
|
||||
"remark",
|
||||
"--remark-payload",
|
||||
"1234",
|
||||
"--conversion-rate-override",
|
||||
"metric",
|
||||
"sized",
|
||||
"max",
|
||||
]);
|
||||
|
||||
assert!(send_message.is_ok());
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn accepts_non_default_dispatch_fee_payment() {
|
||||
// given
|
||||
let mut send_message = SendMessage::from_iter(vec![
|
||||
"send-message",
|
||||
"rialto-to-millau",
|
||||
"--source-port",
|
||||
"1234",
|
||||
"--source-signer",
|
||||
"//Alice",
|
||||
"--dispatch-fee-payment",
|
||||
"at-target-chain",
|
||||
"remark",
|
||||
]);
|
||||
|
||||
// when
|
||||
let payload = send_message.encode_payload().await.unwrap();
|
||||
|
||||
// then
|
||||
assert_eq!(send_message.bridge, FullBridge::RialtoToMillau);
|
||||
assert_eq!(send_message.source.source_port, 1234);
|
||||
assert_eq!(send_message.source_sign.source_signer, Some("//Alice".into()));
|
||||
assert_eq!(send_message.conversion_rate_override, Some(ConversionRateOverride::Metric));
|
||||
assert_eq!(
|
||||
payload.dispatch_fee_payment,
|
||||
bp_runtime::messages::DispatchFeePayment::AtTargetChain
|
||||
send_message.message,
|
||||
crate::cli::encode_message::Message::Sized { size: ExplicitOrMaximal::Maximal }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user