mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
Change submit transaction spec_version and transaction_version query from chain (#1248)
* The `spec_version` and `transaction_version` query from chain * fix compile * Lint * Custom spec_version and transaction_version * runtime version params struct opt * runtime version cli * cli params * Add missing types defined * fix compile * debug cli * clippy * clippy * Query spec_version and transaction_version same times * Fix vars * Wrap option * Wrap option * Try fix ci * Change follow suggestions
This commit is contained in:
@@ -265,7 +265,8 @@ impl<Call> parity_scale_codec::Decode for SignedExtensions<Call> {
|
|||||||
|
|
||||||
impl<Call> SignedExtensions<Call> {
|
impl<Call> SignedExtensions<Call> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
version: sp_version::RuntimeVersion,
|
spec_version: u32,
|
||||||
|
transaction_version: u32,
|
||||||
era: bp_runtime::TransactionEraOf<PolkadotLike>,
|
era: bp_runtime::TransactionEraOf<PolkadotLike>,
|
||||||
genesis_hash: Hash,
|
genesis_hash: Hash,
|
||||||
nonce: Nonce,
|
nonce: Nonce,
|
||||||
@@ -282,8 +283,8 @@ impl<Call> SignedExtensions<Call> {
|
|||||||
tip.into(), // transaction payment / tip (compact encoding)
|
tip.into(), // transaction payment / tip (compact encoding)
|
||||||
),
|
),
|
||||||
additional_signed: (
|
additional_signed: (
|
||||||
version.spec_version,
|
spec_version,
|
||||||
version.transaction_version,
|
transaction_version,
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
era.signed_payload(genesis_hash),
|
era.signed_payload(genesis_hash),
|
||||||
(),
|
(),
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use sp_core::{Bytes, Pair};
|
|||||||
use messages_relay::relay_strategy::MixStrategy;
|
use messages_relay::relay_strategy::MixStrategy;
|
||||||
use relay_kusama_client::Kusama;
|
use relay_kusama_client::Kusama;
|
||||||
use relay_polkadot_client::Polkadot;
|
use relay_polkadot_client::Polkadot;
|
||||||
use relay_substrate_client::{Client, TransactionSignScheme, UnsignedTransaction};
|
use relay_substrate_client::{Client, SignParam, TransactionSignScheme, UnsignedTransaction};
|
||||||
use substrate_relay_helper::messages_lane::SubstrateMessageLane;
|
use substrate_relay_helper::messages_lane::SubstrateMessageLane;
|
||||||
|
|
||||||
/// Description of Kusama -> Polkadot messages bridge.
|
/// Description of Kusama -> Polkadot messages bridge.
|
||||||
@@ -69,14 +69,17 @@ pub(crate) async fn update_polkadot_to_kusama_conversion_rate(
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let genesis_hash = *client.genesis_hash();
|
let genesis_hash = *client.genesis_hash();
|
||||||
let signer_id = (*signer.public().as_array_ref()).into();
|
let signer_id = (*signer.public().as_array_ref()).into();
|
||||||
|
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||||
client
|
client
|
||||||
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Kusama::sign_transaction(
|
Kusama::sign_transaction(SignParam {
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
&signer,
|
signer,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
UnsignedTransaction::new(
|
unsigned: UnsignedTransaction::new(
|
||||||
relay_kusama_client::runtime::Call::BridgePolkadotMessages(
|
relay_kusama_client::runtime::Call::BridgePolkadotMessages(
|
||||||
relay_kusama_client::runtime::BridgePolkadotMessagesCall::update_pallet_parameter(
|
relay_kusama_client::runtime::BridgePolkadotMessagesCall::update_pallet_parameter(
|
||||||
relay_kusama_client::runtime::BridgePolkadotMessagesParameter::PolkadotToKusamaConversionRate(
|
relay_kusama_client::runtime::BridgePolkadotMessagesParameter::PolkadotToKusamaConversionRate(
|
||||||
@@ -86,8 +89,8 @@ pub(crate) async fn update_polkadot_to_kusama_conversion_rate(
|
|||||||
),
|
),
|
||||||
transaction_nonce,
|
transaction_nonce,
|
||||||
),
|
),
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use sp_core::{Bytes, Pair};
|
|||||||
use messages_relay::relay_strategy::MixStrategy;
|
use messages_relay::relay_strategy::MixStrategy;
|
||||||
use relay_millau_client::Millau;
|
use relay_millau_client::Millau;
|
||||||
use relay_rialto_client::Rialto;
|
use relay_rialto_client::Rialto;
|
||||||
use relay_substrate_client::{Client, TransactionSignScheme, UnsignedTransaction};
|
use relay_substrate_client::{Client, SignParam, TransactionSignScheme, UnsignedTransaction};
|
||||||
use substrate_relay_helper::messages_lane::{
|
use substrate_relay_helper::messages_lane::{
|
||||||
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
|
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
|
||||||
SubstrateMessageLane,
|
SubstrateMessageLane,
|
||||||
@@ -66,23 +66,26 @@ pub(crate) async fn update_rialto_to_millau_conversion_rate(
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let genesis_hash = *client.genesis_hash();
|
let genesis_hash = *client.genesis_hash();
|
||||||
let signer_id = (*signer.public().as_array_ref()).into();
|
let signer_id = (*signer.public().as_array_ref()).into();
|
||||||
|
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||||
client
|
client
|
||||||
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Millau::sign_transaction(
|
Millau::sign_transaction(SignParam {
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
&signer,
|
signer,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
UnsignedTransaction::new(
|
unsigned: UnsignedTransaction::new(
|
||||||
millau_runtime::MessagesCall::update_pallet_parameter {
|
millau_runtime::MessagesCall::update_pallet_parameter {
|
||||||
parameter: millau_runtime::rialto_messages::MillauToRialtoMessagesParameter::RialtoToMillauConversionRate(
|
parameter: millau_runtime::rialto_messages::MillauToRialtoMessagesParameter::RialtoToMillauConversionRate(
|
||||||
sp_runtime::FixedU128::from_float(updated_rate),
|
sp_runtime::FixedU128::from_float(updated_rate),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
transaction_nonce,
|
transaction_nonce,
|
||||||
),
|
),
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ mod tests {
|
|||||||
use frame_support::dispatch::GetDispatchInfo;
|
use frame_support::dispatch::GetDispatchInfo;
|
||||||
use relay_millau_client::Millau;
|
use relay_millau_client::Millau;
|
||||||
use relay_rialto_client::Rialto;
|
use relay_rialto_client::Rialto;
|
||||||
use relay_substrate_client::{TransactionSignScheme, UnsignedTransaction};
|
use relay_substrate_client::{SignParam, TransactionSignScheme, UnsignedTransaction};
|
||||||
use sp_core::Pair;
|
use sp_core::Pair;
|
||||||
use sp_runtime::traits::{IdentifyAccount, Verify};
|
use sp_runtime::traits::{IdentifyAccount, Verify};
|
||||||
|
|
||||||
@@ -204,12 +204,14 @@ mod tests {
|
|||||||
fn rialto_tx_extra_bytes_constant_is_correct() {
|
fn rialto_tx_extra_bytes_constant_is_correct() {
|
||||||
let rialto_call =
|
let rialto_call =
|
||||||
rialto_runtime::Call::System(rialto_runtime::SystemCall::remark { remark: vec![] });
|
rialto_runtime::Call::System(rialto_runtime::SystemCall::remark { remark: vec![] });
|
||||||
let rialto_tx = Rialto::sign_transaction(
|
let rialto_tx = Rialto::sign_transaction(SignParam {
|
||||||
Default::default(),
|
spec_version: 1,
|
||||||
&sp_keyring::AccountKeyring::Alice.pair(),
|
transaction_version: 1,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: Default::default(),
|
||||||
UnsignedTransaction::new(rialto_call.clone(), 0),
|
signer: sp_keyring::AccountKeyring::Alice.pair(),
|
||||||
);
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(rialto_call.clone(), 0),
|
||||||
|
});
|
||||||
let extra_bytes_in_transaction = rialto_tx.encode().len() - rialto_call.encode().len();
|
let extra_bytes_in_transaction = rialto_tx.encode().len() - rialto_call.encode().len();
|
||||||
assert!(
|
assert!(
|
||||||
bp_rialto::TX_EXTRA_BYTES as usize >= extra_bytes_in_transaction,
|
bp_rialto::TX_EXTRA_BYTES as usize >= extra_bytes_in_transaction,
|
||||||
@@ -223,12 +225,14 @@ mod tests {
|
|||||||
fn millau_tx_extra_bytes_constant_is_correct() {
|
fn millau_tx_extra_bytes_constant_is_correct() {
|
||||||
let millau_call =
|
let millau_call =
|
||||||
millau_runtime::Call::System(millau_runtime::SystemCall::remark { remark: vec![] });
|
millau_runtime::Call::System(millau_runtime::SystemCall::remark { remark: vec![] });
|
||||||
let millau_tx = Millau::sign_transaction(
|
let millau_tx = Millau::sign_transaction(SignParam {
|
||||||
Default::default(),
|
spec_version: 0,
|
||||||
&sp_keyring::AccountKeyring::Alice.pair(),
|
transaction_version: 0,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: Default::default(),
|
||||||
UnsignedTransaction::new(millau_call.clone(), 0),
|
signer: sp_keyring::AccountKeyring::Alice.pair(),
|
||||||
);
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(millau_call.clone(), 0),
|
||||||
|
});
|
||||||
let extra_bytes_in_transaction = millau_tx.encode().len() - millau_call.encode().len();
|
let extra_bytes_in_transaction = millau_tx.encode().len() - millau_call.encode().len();
|
||||||
assert!(
|
assert!(
|
||||||
bp_millau::TX_EXTRA_BYTES as usize >= extra_bytes_in_transaction,
|
bp_millau::TX_EXTRA_BYTES as usize >= extra_bytes_in_transaction,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use frame_support::weights::Weight;
|
|||||||
use messages_relay::relay_strategy::MixStrategy;
|
use messages_relay::relay_strategy::MixStrategy;
|
||||||
use relay_kusama_client::Kusama;
|
use relay_kusama_client::Kusama;
|
||||||
use relay_polkadot_client::Polkadot;
|
use relay_polkadot_client::Polkadot;
|
||||||
use relay_substrate_client::{Client, TransactionSignScheme, UnsignedTransaction};
|
use relay_substrate_client::{Client, SignParam, TransactionSignScheme, UnsignedTransaction};
|
||||||
use substrate_relay_helper::messages_lane::SubstrateMessageLane;
|
use substrate_relay_helper::messages_lane::SubstrateMessageLane;
|
||||||
|
|
||||||
/// Description of Polkadot -> Kusama messages bridge.
|
/// Description of Polkadot -> Kusama messages bridge.
|
||||||
@@ -69,14 +69,17 @@ pub(crate) async fn update_kusama_to_polkadot_conversion_rate(
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let genesis_hash = *client.genesis_hash();
|
let genesis_hash = *client.genesis_hash();
|
||||||
let signer_id = (*signer.public().as_array_ref()).into();
|
let signer_id = (*signer.public().as_array_ref()).into();
|
||||||
|
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||||
client
|
client
|
||||||
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Polkadot::sign_transaction(
|
Polkadot::sign_transaction(SignParam {
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
&signer,
|
signer,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
UnsignedTransaction::new(
|
unsigned: UnsignedTransaction::new(
|
||||||
relay_polkadot_client::runtime::Call::BridgeKusamaMessages(
|
relay_polkadot_client::runtime::Call::BridgeKusamaMessages(
|
||||||
relay_polkadot_client::runtime::BridgeKusamaMessagesCall::update_pallet_parameter(
|
relay_polkadot_client::runtime::BridgeKusamaMessagesCall::update_pallet_parameter(
|
||||||
relay_polkadot_client::runtime::BridgeKusamaMessagesParameter::KusamaToPolkadotConversionRate(
|
relay_polkadot_client::runtime::BridgeKusamaMessagesParameter::KusamaToPolkadotConversionRate(
|
||||||
@@ -85,8 +88,8 @@ pub(crate) async fn update_kusama_to_polkadot_conversion_rate(
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
transaction_nonce,
|
transaction_nonce,
|
||||||
),
|
)
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use sp_core::{Bytes, Pair};
|
|||||||
use messages_relay::relay_strategy::MixStrategy;
|
use messages_relay::relay_strategy::MixStrategy;
|
||||||
use relay_millau_client::Millau;
|
use relay_millau_client::Millau;
|
||||||
use relay_rialto_client::Rialto;
|
use relay_rialto_client::Rialto;
|
||||||
use relay_substrate_client::{Client, TransactionSignScheme, UnsignedTransaction};
|
use relay_substrate_client::{Client, SignParam, TransactionSignScheme, UnsignedTransaction};
|
||||||
use substrate_relay_helper::messages_lane::{
|
use substrate_relay_helper::messages_lane::{
|
||||||
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
|
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
|
||||||
SubstrateMessageLane,
|
SubstrateMessageLane,
|
||||||
@@ -66,14 +66,17 @@ pub(crate) async fn update_millau_to_rialto_conversion_rate(
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let genesis_hash = *client.genesis_hash();
|
let genesis_hash = *client.genesis_hash();
|
||||||
let signer_id = (*signer.public().as_array_ref()).into();
|
let signer_id = (*signer.public().as_array_ref()).into();
|
||||||
|
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||||
client
|
client
|
||||||
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Rialto::sign_transaction(
|
Rialto::sign_transaction(SignParam {
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
&signer,
|
signer,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
UnsignedTransaction::new(
|
unsigned: UnsignedTransaction::new(
|
||||||
rialto_runtime::MessagesCall::update_pallet_parameter {
|
rialto_runtime::MessagesCall::update_pallet_parameter {
|
||||||
parameter: rialto_runtime::millau_messages::RialtoToMillauMessagesParameter::MillauToRialtoConversionRate(
|
parameter: rialto_runtime::millau_messages::RialtoToMillauMessagesParameter::MillauToRialtoConversionRate(
|
||||||
sp_runtime::FixedU128::from_float(updated_rate),
|
sp_runtime::FixedU128::from_float(updated_rate),
|
||||||
@@ -81,8 +84,8 @@ pub(crate) async fn update_millau_to_rialto_conversion_rate(
|
|||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
transaction_nonce,
|
transaction_nonce,
|
||||||
),
|
)
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ macro_rules! select_full_bridge {
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use millau_runtime::millau_to_rialto_account_ownership_digest as account_ownership_digest;
|
use millau_runtime::millau_to_rialto_account_ownership_digest as account_ownership_digest;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(millau_runtime::VERSION);
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(rialto_runtime::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
}
|
}
|
||||||
FullBridge::RialtoToMillau => {
|
FullBridge::RialtoToMillau => {
|
||||||
@@ -100,6 +105,11 @@ macro_rules! select_full_bridge {
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use rialto_runtime::rialto_to_millau_account_ownership_digest as account_ownership_digest;
|
use rialto_runtime::rialto_to_millau_account_ownership_digest as account_ownership_digest;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(rialto_runtime::VERSION);
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(millau_runtime::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
}
|
}
|
||||||
FullBridge::RococoToWococo => {
|
FullBridge::RococoToWococo => {
|
||||||
@@ -122,6 +132,11 @@ macro_rules! select_full_bridge {
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use relay_rococo_client::runtime::rococo_to_wococo_account_ownership_digest as account_ownership_digest;
|
use relay_rococo_client::runtime::rococo_to_wococo_account_ownership_digest as account_ownership_digest;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_rococo::VERSION);
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_wococo::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
}
|
}
|
||||||
FullBridge::WococoToRococo => {
|
FullBridge::WococoToRococo => {
|
||||||
@@ -144,6 +159,11 @@ macro_rules! select_full_bridge {
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use relay_wococo_client::runtime::wococo_to_rococo_account_ownership_digest as account_ownership_digest;
|
use relay_wococo_client::runtime::wococo_to_rococo_account_ownership_digest as account_ownership_digest;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_wococo::VERSION);
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_rococo::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
}
|
}
|
||||||
FullBridge::KusamaToPolkadot => {
|
FullBridge::KusamaToPolkadot => {
|
||||||
@@ -166,6 +186,11 @@ macro_rules! select_full_bridge {
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use relay_kusama_client::runtime::kusama_to_polkadot_account_ownership_digest as account_ownership_digest;
|
use relay_kusama_client::runtime::kusama_to_polkadot_account_ownership_digest as account_ownership_digest;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_kusama::VERSION);
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_polkadot::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
}
|
}
|
||||||
FullBridge::PolkadotToKusama => {
|
FullBridge::PolkadotToKusama => {
|
||||||
@@ -188,6 +213,11 @@ macro_rules! select_full_bridge {
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use relay_polkadot_client::runtime::polkadot_to_kusama_account_ownership_digest as account_ownership_digest;
|
use relay_polkadot_client::runtime::polkadot_to_kusama_account_ownership_digest as account_ownership_digest;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_polkadot::VERSION);
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_kusama::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ impl EstimateFee {
|
|||||||
let Self { source, bridge, lane, payload } = self;
|
let Self { source, bridge, lane, payload } = self;
|
||||||
|
|
||||||
select_full_bridge!(bridge, {
|
select_full_bridge!(bridge, {
|
||||||
let source_client = source.to_client::<Source>().await?;
|
let source_client = source.to_client::<Source>(SOURCE_RUNTIME_VERSION).await?;
|
||||||
let lane = lane.into();
|
let lane = lane.into();
|
||||||
let payload =
|
let payload =
|
||||||
Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?;
|
Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?;
|
||||||
@@ -86,7 +86,7 @@ pub(crate) async fn estimate_message_delivery_and_dispatch_fee<Fee: Decode, C: C
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::cli::encode_call;
|
use crate::cli::{encode_call, RuntimeVersionType, SourceRuntimeVersionParams};
|
||||||
use sp_core::crypto::Ss58Codec;
|
use sp_core::crypto::Ss58Codec;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -118,6 +118,11 @@ mod tests {
|
|||||||
source_host: "127.0.0.1".into(),
|
source_host: "127.0.0.1".into(),
|
||||||
source_port: 1234,
|
source_port: 1234,
|
||||||
source_secure: false,
|
source_secure: false,
|
||||||
|
source_runtime_version: SourceRuntimeVersionParams {
|
||||||
|
source_version_mode: RuntimeVersionType::Bundle,
|
||||||
|
source_spec_version: None,
|
||||||
|
source_transaction_version: None,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
payload: crate::cli::encode_message::MessagePayload::Call {
|
payload: crate::cli::encode_message::MessagePayload::Call {
|
||||||
sender: alice.parse().unwrap(),
|
sender: alice.parse().unwrap(),
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use crate::cli::{SourceConnectionParams, TargetConnectionParams, TargetSigningPa
|
|||||||
use bp_header_chain::InitializationData;
|
use bp_header_chain::InitializationData;
|
||||||
use bp_runtime::Chain as ChainBase;
|
use bp_runtime::Chain as ChainBase;
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use relay_substrate_client::{Chain, TransactionSignScheme, UnsignedTransaction};
|
use relay_substrate_client::{Chain, SignParam, TransactionSignScheme, UnsignedTransaction};
|
||||||
use sp_core::{Bytes, Pair};
|
use sp_core::{Bytes, Pair};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use strum::{EnumString, EnumVariantNames, VariantNames};
|
use strum::{EnumString, EnumVariantNames, VariantNames};
|
||||||
@@ -56,6 +56,10 @@ macro_rules! select_bridge {
|
|||||||
InitBridgeName::MillauToRialto => {
|
InitBridgeName::MillauToRialto => {
|
||||||
type Source = relay_millau_client::Millau;
|
type Source = relay_millau_client::Millau;
|
||||||
type Target = relay_rialto_client::Rialto;
|
type Target = relay_rialto_client::Rialto;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(millau_runtime::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(rialto_runtime::VERSION);
|
||||||
|
|
||||||
fn encode_init_bridge(
|
fn encode_init_bridge(
|
||||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||||
@@ -74,6 +78,10 @@ macro_rules! select_bridge {
|
|||||||
InitBridgeName::RialtoToMillau => {
|
InitBridgeName::RialtoToMillau => {
|
||||||
type Source = relay_rialto_client::Rialto;
|
type Source = relay_rialto_client::Rialto;
|
||||||
type Target = relay_millau_client::Millau;
|
type Target = relay_millau_client::Millau;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(rialto_runtime::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(millau_runtime::VERSION);
|
||||||
|
|
||||||
fn encode_init_bridge(
|
fn encode_init_bridge(
|
||||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||||
@@ -92,6 +100,10 @@ macro_rules! select_bridge {
|
|||||||
InitBridgeName::WestendToMillau => {
|
InitBridgeName::WestendToMillau => {
|
||||||
type Source = relay_westend_client::Westend;
|
type Source = relay_westend_client::Westend;
|
||||||
type Target = relay_millau_client::Millau;
|
type Target = relay_millau_client::Millau;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_westend::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(millau_runtime::VERSION);
|
||||||
|
|
||||||
fn encode_init_bridge(
|
fn encode_init_bridge(
|
||||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||||
@@ -114,6 +126,10 @@ macro_rules! select_bridge {
|
|||||||
InitBridgeName::RococoToWococo => {
|
InitBridgeName::RococoToWococo => {
|
||||||
type Source = relay_rococo_client::Rococo;
|
type Source = relay_rococo_client::Rococo;
|
||||||
type Target = relay_wococo_client::Wococo;
|
type Target = relay_wococo_client::Wococo;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_rococo::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_wococo::VERSION);
|
||||||
|
|
||||||
fn encode_init_bridge(
|
fn encode_init_bridge(
|
||||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||||
@@ -130,6 +146,10 @@ macro_rules! select_bridge {
|
|||||||
InitBridgeName::WococoToRococo => {
|
InitBridgeName::WococoToRococo => {
|
||||||
type Source = relay_wococo_client::Wococo;
|
type Source = relay_wococo_client::Wococo;
|
||||||
type Target = relay_rococo_client::Rococo;
|
type Target = relay_rococo_client::Rococo;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_wococo::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_rococo::VERSION);
|
||||||
|
|
||||||
fn encode_init_bridge(
|
fn encode_init_bridge(
|
||||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||||
@@ -146,6 +166,10 @@ macro_rules! select_bridge {
|
|||||||
InitBridgeName::KusamaToPolkadot => {
|
InitBridgeName::KusamaToPolkadot => {
|
||||||
type Source = relay_kusama_client::Kusama;
|
type Source = relay_kusama_client::Kusama;
|
||||||
type Target = relay_polkadot_client::Polkadot;
|
type Target = relay_polkadot_client::Polkadot;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_kusama::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_polkadot::VERSION);
|
||||||
|
|
||||||
fn encode_init_bridge(
|
fn encode_init_bridge(
|
||||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||||
@@ -162,6 +186,10 @@ macro_rules! select_bridge {
|
|||||||
InitBridgeName::PolkadotToKusama => {
|
InitBridgeName::PolkadotToKusama => {
|
||||||
type Source = relay_polkadot_client::Polkadot;
|
type Source = relay_polkadot_client::Polkadot;
|
||||||
type Target = relay_kusama_client::Kusama;
|
type Target = relay_kusama_client::Kusama;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_polkadot::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_kusama::VERSION);
|
||||||
|
|
||||||
fn encode_init_bridge(
|
fn encode_init_bridge(
|
||||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||||
@@ -183,25 +211,29 @@ impl InitBridge {
|
|||||||
/// Run the command.
|
/// Run the command.
|
||||||
pub async fn run(self) -> anyhow::Result<()> {
|
pub async fn run(self) -> anyhow::Result<()> {
|
||||||
select_bridge!(self.bridge, {
|
select_bridge!(self.bridge, {
|
||||||
let source_client = self.source.to_client::<Source>().await?;
|
let source_client = self.source.to_client::<Source>(SOURCE_RUNTIME_VERSION).await?;
|
||||||
let target_client = self.target.to_client::<Target>().await?;
|
let target_client = self.target.to_client::<Target>(TARGET_RUNTIME_VERSION).await?;
|
||||||
let target_sign = self.target_sign.to_keypair::<Target>()?;
|
let target_sign = self.target_sign.to_keypair::<Target>()?;
|
||||||
|
|
||||||
|
let (spec_version, transaction_version) =
|
||||||
|
target_client.simple_runtime_version().await?;
|
||||||
substrate_relay_helper::headers_initialize::initialize(
|
substrate_relay_helper::headers_initialize::initialize(
|
||||||
source_client,
|
source_client,
|
||||||
target_client.clone(),
|
target_client.clone(),
|
||||||
target_sign.public().into(),
|
target_sign.public().into(),
|
||||||
move |transaction_nonce, initialization_data| {
|
move |transaction_nonce, initialization_data| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Target::sign_transaction(
|
Target::sign_transaction(SignParam {
|
||||||
*target_client.genesis_hash(),
|
spec_version,
|
||||||
&target_sign,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: *target_client.genesis_hash(),
|
||||||
UnsignedTransaction::new(
|
signer: target_sign,
|
||||||
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(
|
||||||
encode_init_bridge(initialization_data),
|
encode_init_bridge(initialization_data),
|
||||||
transaction_nonce,
|
transaction_nonce,
|
||||||
),
|
),
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,10 +18,13 @@
|
|||||||
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use bp_messages::LaneId;
|
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
|
use relay_substrate_client::ChainRuntimeVersion;
|
||||||
use sp_runtime::app_crypto::Ss58Codec;
|
use sp_runtime::app_crypto::Ss58Codec;
|
||||||
use structopt::{clap::arg_enum, StructOpt};
|
use structopt::{clap::arg_enum, StructOpt};
|
||||||
|
use strum::{EnumString, EnumVariantNames};
|
||||||
|
|
||||||
|
use bp_messages::LaneId;
|
||||||
|
|
||||||
pub(crate) mod bridge;
|
pub(crate) mod bridge;
|
||||||
pub(crate) mod encode_call;
|
pub(crate) mod encode_call;
|
||||||
@@ -364,6 +367,17 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Runtime version params."]
|
||||||
|
#[derive(StructOpt, Debug, PartialEq, Eq, Clone, EnumString, EnumVariantNames)]
|
||||||
|
pub enum RuntimeVersionType {
|
||||||
|
/// Auto query version from chain
|
||||||
|
Auto,
|
||||||
|
/// Custom `spec_version` and `transaction_version`
|
||||||
|
Custom,
|
||||||
|
/// Read version from bundle dependencies directly.
|
||||||
|
Bundle,
|
||||||
|
}
|
||||||
|
|
||||||
/// Create chain-specific set of configuration objects: connection parameters,
|
/// Create chain-specific set of configuration objects: connection parameters,
|
||||||
/// signing parameters and bridge initialization parameters.
|
/// signing parameters and bridge initialization parameters.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
@@ -382,6 +396,23 @@ macro_rules! declare_chain_options {
|
|||||||
#[doc = "Use secure websocket connection."]
|
#[doc = "Use secure websocket connection."]
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
pub [<$chain_prefix _secure>]: bool,
|
pub [<$chain_prefix _secure>]: bool,
|
||||||
|
#[doc = "Custom runtime version"]
|
||||||
|
#[structopt(flatten)]
|
||||||
|
pub [<$chain_prefix _runtime_version>]: [<$chain RuntimeVersionParams>],
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc = $chain " runtime version params."]
|
||||||
|
#[derive(StructOpt, Debug, PartialEq, Eq, Clone)]
|
||||||
|
pub struct [<$chain RuntimeVersionParams>] {
|
||||||
|
#[doc = "The type of runtime version for chain " $chain]
|
||||||
|
#[structopt(long, default_value = "Bundle")]
|
||||||
|
pub [<$chain_prefix _version_mode>]: RuntimeVersionType,
|
||||||
|
#[doc = "The custom sepc_version for chain " $chain]
|
||||||
|
#[structopt(long)]
|
||||||
|
pub [<$chain_prefix _spec_version>]: Option<u32>,
|
||||||
|
#[doc = "The custom transaction_version for chain " $chain]
|
||||||
|
#[structopt(long)]
|
||||||
|
pub [<$chain_prefix _transaction_version>]: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = $chain " signing params."]
|
#[doc = $chain " signing params."]
|
||||||
@@ -500,11 +531,36 @@ macro_rules! declare_chain_options {
|
|||||||
/// Convert connection params into Substrate client.
|
/// Convert connection params into Substrate client.
|
||||||
pub async fn to_client<Chain: CliChain>(
|
pub async fn to_client<Chain: CliChain>(
|
||||||
&self,
|
&self,
|
||||||
|
bundle_runtime_version: Option<sp_version::RuntimeVersion>
|
||||||
) -> anyhow::Result<relay_substrate_client::Client<Chain>> {
|
) -> anyhow::Result<relay_substrate_client::Client<Chain>> {
|
||||||
|
let runtime_version_params = &self.[<$chain_prefix _runtime_version>];
|
||||||
|
let chain_runtime_version = match runtime_version_params.[<$chain_prefix _version_mode>] {
|
||||||
|
RuntimeVersionType::Auto => ChainRuntimeVersion::Auto,
|
||||||
|
RuntimeVersionType::Custom => {
|
||||||
|
let except_spec_version = runtime_version_params.[<$chain_prefix _spec_version>]
|
||||||
|
.ok_or(anyhow::Error::msg(format!("The {}-spec-version is required when choose custom mode", stringify!($chain_prefix))))?;
|
||||||
|
let except_transaction_version = runtime_version_params.[<$chain_prefix _transaction_version>]
|
||||||
|
.ok_or(anyhow::Error::msg(format!("The {}-transaction-version is required when choose custom mode", stringify!($chain_prefix))))?;
|
||||||
|
ChainRuntimeVersion::Custom(
|
||||||
|
except_spec_version,
|
||||||
|
except_transaction_version
|
||||||
|
)
|
||||||
|
}
|
||||||
|
RuntimeVersionType::Bundle => {
|
||||||
|
match bundle_runtime_version {
|
||||||
|
Some(runtime_version) => ChainRuntimeVersion::Custom(
|
||||||
|
runtime_version.spec_version,
|
||||||
|
runtime_version.transaction_version
|
||||||
|
),
|
||||||
|
None => ChainRuntimeVersion::Auto
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
Ok(relay_substrate_client::Client::new(relay_substrate_client::ConnectionParams {
|
Ok(relay_substrate_client::Client::new(relay_substrate_client::ConnectionParams {
|
||||||
host: self.[<$chain_prefix _host>].clone(),
|
host: self.[<$chain_prefix _host>].clone(),
|
||||||
port: self.[<$chain_prefix _port>],
|
port: self.[<$chain_prefix _port>],
|
||||||
secure: self.[<$chain_prefix _secure>],
|
secure: self.[<$chain_prefix _secure>],
|
||||||
|
chain_runtime_version,
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
)
|
)
|
||||||
@@ -521,9 +577,10 @@ declare_chain_options!(Parachain, parachain);
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use sp_core::Pair;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use sp_core::Pair;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ use polkadot_runtime_common::{
|
|||||||
};
|
};
|
||||||
use polkadot_runtime_parachains::paras::ParaLifecycle;
|
use polkadot_runtime_parachains::paras::ParaLifecycle;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
AccountIdOf, CallOf, Chain, Client, TransactionSignScheme, UnsignedTransaction,
|
AccountIdOf, CallOf, Chain, Client, SignParam, TransactionSignScheme, UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use rialto_runtime::SudoCall;
|
use rialto_runtime::SudoCall;
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
@@ -83,6 +83,11 @@ macro_rules! select_bridge {
|
|||||||
|
|
||||||
use bp_rialto::{PARAS_PALLET_NAME, PARAS_REGISTRAR_PALLET_NAME};
|
use bp_rialto::{PARAS_PALLET_NAME, PARAS_REGISTRAR_PALLET_NAME};
|
||||||
|
|
||||||
|
const RELAY_CHAIN_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(rialto_runtime::VERSION);
|
||||||
|
const PARA_CHAIN_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(rialto_parachain_runtime::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -93,9 +98,13 @@ impl RegisterParachain {
|
|||||||
/// Run the command.
|
/// Run the command.
|
||||||
pub async fn run(self) -> anyhow::Result<()> {
|
pub async fn run(self) -> anyhow::Result<()> {
|
||||||
select_bridge!(self.parachain, {
|
select_bridge!(self.parachain, {
|
||||||
let relay_client = self.relay_connection.to_client::<Relaychain>().await?;
|
let relay_client = self
|
||||||
|
.relay_connection
|
||||||
|
.to_client::<Relaychain>(RELAY_CHAIN_RUNTIME_VERSION)
|
||||||
|
.await?;
|
||||||
let relay_sign = self.relay_sign.to_keypair::<Relaychain>()?;
|
let relay_sign = self.relay_sign.to_keypair::<Relaychain>()?;
|
||||||
let para_client = self.para_connection.to_client::<Parachain>().await?;
|
let para_client =
|
||||||
|
self.para_connection.to_client::<Parachain>(PARA_CHAIN_RUNTIME_VERSION).await?;
|
||||||
|
|
||||||
// hopefully we're the only actor that is registering parachain right now
|
// hopefully we're the only actor that is registering parachain right now
|
||||||
// => read next parachain id
|
// => read next parachain id
|
||||||
@@ -116,21 +125,24 @@ impl RegisterParachain {
|
|||||||
let reserve_parachain_id_call: CallOf<Relaychain> =
|
let reserve_parachain_id_call: CallOf<Relaychain> =
|
||||||
ParaRegistrarCall::reserve {}.into();
|
ParaRegistrarCall::reserve {}.into();
|
||||||
let reserve_parachain_signer = relay_sign.clone();
|
let reserve_parachain_signer = relay_sign.clone();
|
||||||
|
let (spec_version, transaction_version) = relay_client.simple_runtime_version().await?;
|
||||||
wait_until_transaction_is_finalized::<Relaychain>(
|
wait_until_transaction_is_finalized::<Relaychain>(
|
||||||
relay_client
|
relay_client
|
||||||
.submit_and_watch_signed_extrinsic(
|
.submit_and_watch_signed_extrinsic(
|
||||||
relay_sudo_account.clone(),
|
relay_sudo_account.clone(),
|
||||||
move |_, transaction_nonce| {
|
move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Relaychain::sign_transaction(
|
Relaychain::sign_transaction(SignParam {
|
||||||
relay_genesis_hash,
|
spec_version,
|
||||||
&reserve_parachain_signer,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: relay_genesis_hash,
|
||||||
UnsignedTransaction::new(
|
signer: reserve_parachain_signer,
|
||||||
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(
|
||||||
reserve_parachain_id_call,
|
reserve_parachain_id_call,
|
||||||
transaction_nonce,
|
transaction_nonce,
|
||||||
),
|
),
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -169,15 +181,17 @@ impl RegisterParachain {
|
|||||||
relay_sudo_account.clone(),
|
relay_sudo_account.clone(),
|
||||||
move |_, transaction_nonce| {
|
move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Relaychain::sign_transaction(
|
Relaychain::sign_transaction(SignParam {
|
||||||
relay_genesis_hash,
|
spec_version,
|
||||||
®ister_parathread_signer,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: relay_genesis_hash,
|
||||||
UnsignedTransaction::new(
|
signer: register_parathread_signer,
|
||||||
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(
|
||||||
register_parathread_call,
|
register_parathread_call,
|
||||||
transaction_nonce,
|
transaction_nonce,
|
||||||
),
|
),
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -229,12 +243,14 @@ impl RegisterParachain {
|
|||||||
relay_client
|
relay_client
|
||||||
.submit_signed_extrinsic(relay_sudo_account.clone(), move |_, transaction_nonce| {
|
.submit_signed_extrinsic(relay_sudo_account.clone(), move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Relaychain::sign_transaction(
|
Relaychain::sign_transaction(SignParam {
|
||||||
relay_genesis_hash,
|
spec_version,
|
||||||
&force_lease_signer,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: relay_genesis_hash,
|
||||||
UnsignedTransaction::new(force_lease_call, transaction_nonce),
|
signer: force_lease_signer,
|
||||||
)
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(force_lease_call, transaction_nonce),
|
||||||
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -292,6 +308,9 @@ async fn wait_para_state<Relaychain: Chain>(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::cli::{
|
||||||
|
ParachainRuntimeVersionParams, RelaychainRuntimeVersionParams, RuntimeVersionType,
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn register_rialto_parachain() {
|
fn register_rialto_parachain() {
|
||||||
@@ -327,6 +346,11 @@ mod tests {
|
|||||||
relaychain_host: "127.0.0.1".into(),
|
relaychain_host: "127.0.0.1".into(),
|
||||||
relaychain_port: 9944,
|
relaychain_port: 9944,
|
||||||
relaychain_secure: false,
|
relaychain_secure: false,
|
||||||
|
relaychain_runtime_version: RelaychainRuntimeVersionParams {
|
||||||
|
relaychain_version_mode: RuntimeVersionType::Bundle,
|
||||||
|
relaychain_spec_version: None,
|
||||||
|
relaychain_transaction_version: None,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
relay_sign: RelaychainSigningParams {
|
relay_sign: RelaychainSigningParams {
|
||||||
relaychain_signer: Some("//Alice".into()),
|
relaychain_signer: Some("//Alice".into()),
|
||||||
@@ -339,6 +363,11 @@ mod tests {
|
|||||||
parachain_host: "127.0.0.1".into(),
|
parachain_host: "127.0.0.1".into(),
|
||||||
parachain_port: 11949,
|
parachain_port: 11949,
|
||||||
parachain_secure: false,
|
parachain_secure: false,
|
||||||
|
parachain_runtime_version: ParachainRuntimeVersionParams {
|
||||||
|
parachain_version_mode: RuntimeVersionType::Bundle,
|
||||||
|
parachain_spec_version: None,
|
||||||
|
parachain_transaction_version: None,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ macro_rules! select_bridge {
|
|||||||
type Source = relay_millau_client::Millau;
|
type Source = relay_millau_client::Millau;
|
||||||
type Target = relay_rialto_client::Rialto;
|
type Target = relay_rialto_client::Rialto;
|
||||||
type Finality = crate::chains::millau_headers_to_rialto::MillauFinalityToRialto;
|
type Finality = crate::chains::millau_headers_to_rialto::MillauFinalityToRialto;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(millau_runtime::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(rialto_runtime::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
@@ -71,6 +75,10 @@ macro_rules! select_bridge {
|
|||||||
type Source = relay_rialto_client::Rialto;
|
type Source = relay_rialto_client::Rialto;
|
||||||
type Target = relay_millau_client::Millau;
|
type Target = relay_millau_client::Millau;
|
||||||
type Finality = crate::chains::rialto_headers_to_millau::RialtoFinalityToMillau;
|
type Finality = crate::chains::rialto_headers_to_millau::RialtoFinalityToMillau;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(rialto_runtime::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(millau_runtime::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
@@ -78,6 +86,10 @@ macro_rules! select_bridge {
|
|||||||
type Source = relay_westend_client::Westend;
|
type Source = relay_westend_client::Westend;
|
||||||
type Target = relay_millau_client::Millau;
|
type Target = relay_millau_client::Millau;
|
||||||
type Finality = crate::chains::westend_headers_to_millau::WestendFinalityToMillau;
|
type Finality = crate::chains::westend_headers_to_millau::WestendFinalityToMillau;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_westend::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(millau_runtime::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
@@ -85,6 +97,10 @@ macro_rules! select_bridge {
|
|||||||
type Source = relay_rococo_client::Rococo;
|
type Source = relay_rococo_client::Rococo;
|
||||||
type Target = relay_wococo_client::Wococo;
|
type Target = relay_wococo_client::Wococo;
|
||||||
type Finality = crate::chains::rococo_headers_to_wococo::RococoFinalityToWococo;
|
type Finality = crate::chains::rococo_headers_to_wococo::RococoFinalityToWococo;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_rococo::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_wococo::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
@@ -92,6 +108,10 @@ macro_rules! select_bridge {
|
|||||||
type Source = relay_wococo_client::Wococo;
|
type Source = relay_wococo_client::Wococo;
|
||||||
type Target = relay_rococo_client::Rococo;
|
type Target = relay_rococo_client::Rococo;
|
||||||
type Finality = crate::chains::wococo_headers_to_rococo::WococoFinalityToRococo;
|
type Finality = crate::chains::wococo_headers_to_rococo::WococoFinalityToRococo;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_wococo::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_rococo::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
@@ -99,6 +119,10 @@ macro_rules! select_bridge {
|
|||||||
type Source = relay_kusama_client::Kusama;
|
type Source = relay_kusama_client::Kusama;
|
||||||
type Target = relay_polkadot_client::Polkadot;
|
type Target = relay_polkadot_client::Polkadot;
|
||||||
type Finality = crate::chains::kusama_headers_to_polkadot::KusamaFinalityToPolkadot;
|
type Finality = crate::chains::kusama_headers_to_polkadot::KusamaFinalityToPolkadot;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_kusama::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_polkadot::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
@@ -106,6 +130,10 @@ macro_rules! select_bridge {
|
|||||||
type Source = relay_polkadot_client::Polkadot;
|
type Source = relay_polkadot_client::Polkadot;
|
||||||
type Target = relay_kusama_client::Kusama;
|
type Target = relay_kusama_client::Kusama;
|
||||||
type Finality = crate::chains::polkadot_headers_to_kusama::PolkadotFinalityToKusama;
|
type Finality = crate::chains::polkadot_headers_to_kusama::PolkadotFinalityToKusama;
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_polkadot::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_kusama::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
@@ -117,8 +145,8 @@ impl RelayHeaders {
|
|||||||
/// Run the command.
|
/// Run the command.
|
||||||
pub async fn run(self) -> anyhow::Result<()> {
|
pub async fn run(self) -> anyhow::Result<()> {
|
||||||
select_bridge!(self.bridge, {
|
select_bridge!(self.bridge, {
|
||||||
let source_client = self.source.to_client::<Source>().await?;
|
let source_client = self.source.to_client::<Source>(SOURCE_RUNTIME_VERSION).await?;
|
||||||
let target_client = self.target.to_client::<Target>().await?;
|
let target_client = self.target.to_client::<Target>(TARGET_RUNTIME_VERSION).await?;
|
||||||
let target_transactions_mortality = self.target_sign.target_transactions_mortality;
|
let target_transactions_mortality = self.target_sign.target_transactions_mortality;
|
||||||
let target_sign = self.target_sign.to_keypair::<Target>()?;
|
let target_sign = self.target_sign.to_keypair::<Target>()?;
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ use strum::VariantNames;
|
|||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use messages_relay::relay_strategy::MixStrategy;
|
use messages_relay::relay_strategy::MixStrategy;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
AccountIdOf, CallOf, Chain, Client, TransactionSignScheme, UnsignedTransaction,
|
AccountIdOf, CallOf, Chain, ChainRuntimeVersion, Client, SignParam, TransactionSignScheme,
|
||||||
|
UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use relay_utils::metrics::MetricsParams;
|
use relay_utils::metrics::MetricsParams;
|
||||||
use sp_core::{Bytes, Pair};
|
use sp_core::{Bytes, Pair};
|
||||||
@@ -39,7 +40,7 @@ use substrate_relay_helper::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::{relay_messages::RelayerMode, CliChain, HexLaneId, PrometheusParams},
|
cli::{relay_messages::RelayerMode, CliChain, HexLaneId, PrometheusParams, RuntimeVersionType},
|
||||||
declare_chain_options,
|
declare_chain_options,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -136,6 +137,10 @@ macro_rules! select_bridge {
|
|||||||
bp_millau::SESSION_LENGTH;
|
bp_millau::SESSION_LENGTH;
|
||||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_rialto::BlockNumber =
|
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_rialto::BlockNumber =
|
||||||
bp_rialto::SESSION_LENGTH;
|
bp_rialto::SESSION_LENGTH;
|
||||||
|
const LEFT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(millau_runtime::VERSION);
|
||||||
|
const RIGHT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(rialto_runtime::VERSION);
|
||||||
|
|
||||||
use crate::chains::{
|
use crate::chains::{
|
||||||
millau_messages_to_rialto::{
|
millau_messages_to_rialto::{
|
||||||
@@ -185,6 +190,11 @@ macro_rules! select_bridge {
|
|||||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_wococo::BlockNumber =
|
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_wococo::BlockNumber =
|
||||||
bp_wococo::SESSION_LENGTH;
|
bp_wococo::SESSION_LENGTH;
|
||||||
|
|
||||||
|
const LEFT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_rococo::VERSION);
|
||||||
|
const RIGHT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_wococo::VERSION);
|
||||||
|
|
||||||
use crate::chains::{
|
use crate::chains::{
|
||||||
rococo_messages_to_wococo::RococoMessagesToWococo as LeftToRightMessageLane,
|
rococo_messages_to_wococo::RococoMessagesToWococo as LeftToRightMessageLane,
|
||||||
wococo_messages_to_rococo::WococoMessagesToRococo as RightToLeftMessageLane,
|
wococo_messages_to_rococo::WococoMessagesToRococo as RightToLeftMessageLane,
|
||||||
@@ -263,6 +273,11 @@ macro_rules! select_bridge {
|
|||||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_polkadot::BlockNumber =
|
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_polkadot::BlockNumber =
|
||||||
bp_polkadot::SESSION_LENGTH;
|
bp_polkadot::SESSION_LENGTH;
|
||||||
|
|
||||||
|
const LEFT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_kusama::VERSION);
|
||||||
|
const RIGHT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_polkadot::VERSION);
|
||||||
|
|
||||||
use crate::chains::{
|
use crate::chains::{
|
||||||
kusama_messages_to_polkadot::{
|
kusama_messages_to_polkadot::{
|
||||||
update_polkadot_to_kusama_conversion_rate as update_right_to_left_conversion_rate,
|
update_polkadot_to_kusama_conversion_rate as update_right_to_left_conversion_rate,
|
||||||
@@ -334,12 +349,12 @@ impl RelayHeadersAndMessages {
|
|||||||
select_bridge!(self, {
|
select_bridge!(self, {
|
||||||
let params: Params = self.into();
|
let params: Params = self.into();
|
||||||
|
|
||||||
let left_client = params.left.to_client::<Left>().await?;
|
let left_client = params.left.to_client::<Left>(LEFT_RUNTIME_VERSION).await?;
|
||||||
let left_transactions_mortality = params.left_sign.transactions_mortality()?;
|
let left_transactions_mortality = params.left_sign.transactions_mortality()?;
|
||||||
let left_sign = params.left_sign.to_keypair::<Left>()?;
|
let left_sign = params.left_sign.to_keypair::<Left>()?;
|
||||||
let left_messages_pallet_owner =
|
let left_messages_pallet_owner =
|
||||||
params.left_messages_pallet_owner.to_keypair::<Left>()?;
|
params.left_messages_pallet_owner.to_keypair::<Left>()?;
|
||||||
let right_client = params.right.to_client::<Right>().await?;
|
let right_client = params.right.to_client::<Right>(RIGHT_RUNTIME_VERSION).await?;
|
||||||
let right_transactions_mortality = params.right_sign.transactions_mortality()?;
|
let right_transactions_mortality = params.right_sign.transactions_mortality()?;
|
||||||
let right_sign = params.right_sign.to_keypair::<Right>()?;
|
let right_sign = params.right_sign.to_keypair::<Right>()?;
|
||||||
let right_messages_pallet_owner =
|
let right_messages_pallet_owner =
|
||||||
@@ -591,15 +606,18 @@ where
|
|||||||
CallOf<C>: Send,
|
CallOf<C>: Send,
|
||||||
{
|
{
|
||||||
let genesis_hash = *client.genesis_hash();
|
let genesis_hash = *client.genesis_hash();
|
||||||
|
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||||
client
|
client
|
||||||
.submit_signed_extrinsic(sign.public().into(), move |_, transaction_nonce| {
|
.submit_signed_extrinsic(sign.public().into(), move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
C::sign_transaction(
|
C::sign_transaction(SignParam {
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
&sign,
|
signer: sign,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
UnsignedTransaction::new(call, transaction_nonce),
|
unsigned: UnsignedTransaction::new(call, transaction_nonce),
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ impl RelayMessages {
|
|||||||
/// Run the command.
|
/// Run the command.
|
||||||
pub async fn run(self) -> anyhow::Result<()> {
|
pub async fn run(self) -> anyhow::Result<()> {
|
||||||
select_full_bridge!(self.bridge, {
|
select_full_bridge!(self.bridge, {
|
||||||
let source_client = self.source.to_client::<Source>().await?;
|
let source_client = self.source.to_client::<Source>(SOURCE_RUNTIME_VERSION).await?;
|
||||||
let source_sign = self.source_sign.to_keypair::<Source>()?;
|
let source_sign = self.source_sign.to_keypair::<Source>()?;
|
||||||
let source_transactions_mortality = self.source_sign.transactions_mortality()?;
|
let source_transactions_mortality = self.source_sign.transactions_mortality()?;
|
||||||
let target_client = self.target.to_client::<Target>().await?;
|
let target_client = self.target.to_client::<Target>(TARGET_RUNTIME_VERSION).await?;
|
||||||
let target_sign = self.target_sign.to_keypair::<Target>()?;
|
let target_sign = self.target_sign.to_keypair::<Target>()?;
|
||||||
let target_transactions_mortality = self.target_sign.transactions_mortality()?;
|
let target_transactions_mortality = self.target_sign.transactions_mortality()?;
|
||||||
let relayer_mode = self.relayer_mode.into();
|
let relayer_mode = self.relayer_mode.into();
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ use crate::cli::{Balance, TargetConnectionParams, TargetSigningParams};
|
|||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use num_traits::{One, Zero};
|
use num_traits::{One, Zero};
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
BlockWithJustification, Chain, Client, Error as SubstrateError, HeaderOf, TransactionSignScheme,
|
BlockWithJustification, Chain, Client, Error as SubstrateError, HeaderOf, SignParam,
|
||||||
|
TransactionSignScheme,
|
||||||
};
|
};
|
||||||
use relay_utils::FailedClient;
|
use relay_utils::FailedClient;
|
||||||
use sp_core::Bytes;
|
use sp_core::Bytes;
|
||||||
@@ -90,18 +91,24 @@ macro_rules! select_bridge {
|
|||||||
RelayChain::Millau => {
|
RelayChain::Millau => {
|
||||||
type Target = relay_millau_client::Millau;
|
type Target = relay_millau_client::Millau;
|
||||||
type TargetSign = relay_millau_client::Millau;
|
type TargetSign = relay_millau_client::Millau;
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(millau_runtime::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
RelayChain::Kusama => {
|
RelayChain::Kusama => {
|
||||||
type Target = relay_kusama_client::Kusama;
|
type Target = relay_kusama_client::Kusama;
|
||||||
type TargetSign = relay_kusama_client::Kusama;
|
type TargetSign = relay_kusama_client::Kusama;
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_kusama::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
RelayChain::Polkadot => {
|
RelayChain::Polkadot => {
|
||||||
type Target = relay_polkadot_client::Polkadot;
|
type Target = relay_polkadot_client::Polkadot;
|
||||||
type TargetSign = relay_polkadot_client::Polkadot;
|
type TargetSign = relay_polkadot_client::Polkadot;
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(bp_polkadot::VERSION);
|
||||||
|
|
||||||
$generic
|
$generic
|
||||||
},
|
},
|
||||||
@@ -114,7 +121,7 @@ impl ResubmitTransactions {
|
|||||||
pub async fn run(self) -> anyhow::Result<()> {
|
pub async fn run(self) -> anyhow::Result<()> {
|
||||||
select_bridge!(self.chain, {
|
select_bridge!(self.chain, {
|
||||||
let relay_loop_name = format!("ResubmitTransactions{}", Target::NAME);
|
let relay_loop_name = format!("ResubmitTransactions{}", Target::NAME);
|
||||||
let client = self.target.to_client::<Target>().await?;
|
let client = self.target.to_client::<Target>(TARGET_RUNTIME_VERSION).await?;
|
||||||
let key_pair = self.target_sign.to_keypair::<Target>()?;
|
let key_pair = self.target_sign.to_keypair::<Target>()?;
|
||||||
|
|
||||||
relay_utils::relay_loop((), client)
|
relay_utils::relay_loop((), client)
|
||||||
@@ -411,6 +418,7 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
|||||||
})?;
|
})?;
|
||||||
let old_tip = unsigned_tx.tip;
|
let old_tip = unsigned_tx.tip;
|
||||||
|
|
||||||
|
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||||
while current_priority < target_priority {
|
while current_priority < target_priority {
|
||||||
let next_tip = unsigned_tx.tip + tip_step;
|
let next_tip = unsigned_tx.tip + tip_step;
|
||||||
if next_tip > tip_limit {
|
if next_tip > tip_limit {
|
||||||
@@ -430,12 +438,14 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
|||||||
current_priority = client
|
current_priority = client
|
||||||
.validate_transaction(
|
.validate_transaction(
|
||||||
at_block,
|
at_block,
|
||||||
S::sign_transaction(
|
S::sign_transaction(SignParam {
|
||||||
*client.genesis_hash(),
|
spec_version,
|
||||||
key_pair,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: *client.genesis_hash(),
|
||||||
unsigned_tx.clone(),
|
signer: key_pair.clone(),
|
||||||
),
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: unsigned_tx.clone(),
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.await??
|
.await??
|
||||||
.priority;
|
.priority;
|
||||||
@@ -451,12 +461,14 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
|||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
old_tip != unsigned_tx.tip,
|
old_tip != unsigned_tx.tip,
|
||||||
S::sign_transaction(
|
S::sign_transaction(SignParam {
|
||||||
*client.genesis_hash(),
|
spec_version,
|
||||||
key_pair,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: *client.genesis_hash(),
|
||||||
unsigned_tx,
|
signer: key_pair.clone(),
|
||||||
),
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: unsigned_tx,
|
||||||
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ use bp_message_dispatch::{CallOrigin, MessagePayload};
|
|||||||
use bp_runtime::{BalanceOf, Chain as _};
|
use bp_runtime::{BalanceOf, Chain as _};
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use frame_support::weights::Weight;
|
use frame_support::weights::Weight;
|
||||||
use relay_substrate_client::{Chain, TransactionSignScheme, UnsignedTransaction};
|
use relay_substrate_client::{Chain, SignParam, TransactionSignScheme, UnsignedTransaction};
|
||||||
use sp_core::{Bytes, Pair};
|
use sp_core::{Bytes, Pair};
|
||||||
use sp_runtime::{traits::IdentifyAccount, AccountId32, MultiSignature, MultiSigner};
|
use sp_runtime::{traits::IdentifyAccount, AccountId32, MultiSignature, MultiSigner};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
@@ -154,7 +154,7 @@ impl SendMessage {
|
|||||||
crate::select_full_bridge!(self.bridge, {
|
crate::select_full_bridge!(self.bridge, {
|
||||||
let payload = self.encode_payload()?;
|
let payload = self.encode_payload()?;
|
||||||
|
|
||||||
let source_client = self.source.to_client::<Source>().await?;
|
let source_client = self.source.to_client::<Source>(SOURCE_RUNTIME_VERSION).await?;
|
||||||
let source_sign = self.source_sign.to_keypair::<Source>()?;
|
let source_sign = self.source_sign.to_keypair::<Source>()?;
|
||||||
|
|
||||||
let lane = self.lane.clone().into();
|
let lane = self.lane.clone().into();
|
||||||
@@ -179,25 +179,31 @@ impl SendMessage {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
let source_genesis_hash = *source_client.genesis_hash();
|
let source_genesis_hash = *source_client.genesis_hash();
|
||||||
|
let (spec_version, transaction_version) =
|
||||||
|
source_client.simple_runtime_version().await?;
|
||||||
let estimated_transaction_fee = source_client
|
let estimated_transaction_fee = source_client
|
||||||
.estimate_extrinsic_fee(Bytes(
|
.estimate_extrinsic_fee(Bytes(
|
||||||
Source::sign_transaction(
|
Source::sign_transaction(SignParam {
|
||||||
source_genesis_hash,
|
spec_version,
|
||||||
&source_sign,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: source_genesis_hash,
|
||||||
UnsignedTransaction::new(send_message_call.clone(), 0),
|
signer: source_sign.clone(),
|
||||||
)
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(send_message_call.clone(), 0),
|
||||||
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
source_client
|
source_client
|
||||||
.submit_signed_extrinsic(source_sign.public().into(), move |_, transaction_nonce| {
|
.submit_signed_extrinsic(source_sign.public().into(), move |_, transaction_nonce| {
|
||||||
let signed_source_call = Source::sign_transaction(
|
let signed_source_call = Source::sign_transaction(SignParam {
|
||||||
source_genesis_hash,
|
spec_version,
|
||||||
&source_sign,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: source_genesis_hash,
|
||||||
UnsignedTransaction::new(send_message_call, transaction_nonce),
|
signer: source_sign.clone(),
|
||||||
)
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(send_message_call, transaction_nonce),
|
||||||
|
})
|
||||||
.encode();
|
.encode();
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ use strum::{EnumString, EnumVariantNames, VariantNames};
|
|||||||
use frame_support::dispatch::GetDispatchInfo;
|
use frame_support::dispatch::GetDispatchInfo;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, CallOf, Chain, ChainWithBalances,
|
AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, CallOf, Chain, ChainWithBalances,
|
||||||
Client, Error as SubstrateError, HashOf, SignatureOf, Subscription, TransactionSignScheme,
|
Client, Error as SubstrateError, HashOf, SignParam, SignatureOf, Subscription,
|
||||||
TransactionStatusOf, UnsignedTransaction,
|
TransactionSignScheme, TransactionStatusOf, UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use sp_core::{blake2_256, storage::StorageKey, Bytes, Pair, H256, U256};
|
use sp_core::{blake2_256, storage::StorageKey, Bytes, Pair, H256, U256};
|
||||||
use sp_runtime::traits::{Convert, Header as HeaderT};
|
use sp_runtime::traits::{Convert, Header as HeaderT};
|
||||||
@@ -98,6 +98,13 @@ macro_rules! select_bridge {
|
|||||||
SwapTokensBridge::MillauToRialto => {
|
SwapTokensBridge::MillauToRialto => {
|
||||||
type Source = relay_millau_client::Millau;
|
type Source = relay_millau_client::Millau;
|
||||||
type Target = relay_rialto_client::Rialto;
|
type Target = relay_rialto_client::Rialto;
|
||||||
|
const SOURCE_SPEC_VERSION: u32 = millau_runtime::VERSION.spec_version;
|
||||||
|
const TARGET_SPEC_VERSION: u32 = rialto_runtime::VERSION.spec_version;
|
||||||
|
|
||||||
|
const SOURCE_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(millau_runtime::VERSION);
|
||||||
|
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
|
||||||
|
Some(rialto_runtime::VERSION);
|
||||||
|
|
||||||
type FromSwapToThisAccountIdConverter = bp_rialto::AccountIdConverter;
|
type FromSwapToThisAccountIdConverter = bp_rialto::AccountIdConverter;
|
||||||
|
|
||||||
@@ -114,9 +121,6 @@ macro_rules! select_bridge {
|
|||||||
const SOURCE_CHAIN_ID: bp_runtime::ChainId = bp_runtime::MILLAU_CHAIN_ID;
|
const SOURCE_CHAIN_ID: bp_runtime::ChainId = bp_runtime::MILLAU_CHAIN_ID;
|
||||||
const TARGET_CHAIN_ID: bp_runtime::ChainId = bp_runtime::RIALTO_CHAIN_ID;
|
const TARGET_CHAIN_ID: bp_runtime::ChainId = bp_runtime::RIALTO_CHAIN_ID;
|
||||||
|
|
||||||
const SOURCE_SPEC_VERSION: u32 = millau_runtime::VERSION.spec_version;
|
|
||||||
const TARGET_SPEC_VERSION: u32 = rialto_runtime::VERSION.spec_version;
|
|
||||||
|
|
||||||
const SOURCE_TO_TARGET_LANE_ID: bp_messages::LaneId = *b"swap";
|
const SOURCE_TO_TARGET_LANE_ID: bp_messages::LaneId = *b"swap";
|
||||||
const TARGET_TO_SOURCE_LANE_ID: bp_messages::LaneId = [0, 0, 0, 0];
|
const TARGET_TO_SOURCE_LANE_ID: bp_messages::LaneId = [0, 0, 0, 0];
|
||||||
|
|
||||||
@@ -130,9 +134,9 @@ impl SwapTokens {
|
|||||||
/// Run the command.
|
/// Run the command.
|
||||||
pub async fn run(self) -> anyhow::Result<()> {
|
pub async fn run(self) -> anyhow::Result<()> {
|
||||||
select_bridge!(self.bridge, {
|
select_bridge!(self.bridge, {
|
||||||
let source_client = self.source.to_client::<Source>().await?;
|
let source_client = self.source.to_client::<Source>(SOURCE_RUNTIME_VERSION).await?;
|
||||||
let source_sign = self.source_sign.to_keypair::<Target>()?;
|
let source_sign = self.source_sign.to_keypair::<Target>()?;
|
||||||
let target_client = self.target.to_client::<Target>().await?;
|
let target_client = self.target.to_client::<Target>(TARGET_RUNTIME_VERSION).await?;
|
||||||
let target_sign = self.target_sign.to_keypair::<Target>()?;
|
let target_sign = self.target_sign.to_keypair::<Target>()?;
|
||||||
|
|
||||||
// names of variables in this function are matching names used by the
|
// names of variables in this function are matching names used by the
|
||||||
@@ -234,18 +238,25 @@ impl SwapTokens {
|
|||||||
// start tokens swap
|
// start tokens swap
|
||||||
let source_genesis_hash = *source_client.genesis_hash();
|
let source_genesis_hash = *source_client.genesis_hash();
|
||||||
let create_swap_signer = source_sign.clone();
|
let create_swap_signer = source_sign.clone();
|
||||||
|
let (spec_version, transaction_version) =
|
||||||
|
source_client.simple_runtime_version().await?;
|
||||||
let swap_created_at = wait_until_transaction_is_finalized::<Source>(
|
let swap_created_at = wait_until_transaction_is_finalized::<Source>(
|
||||||
source_client
|
source_client
|
||||||
.submit_and_watch_signed_extrinsic(
|
.submit_and_watch_signed_extrinsic(
|
||||||
accounts.source_account_at_this_chain.clone(),
|
accounts.source_account_at_this_chain.clone(),
|
||||||
move |_, transaction_nonce| {
|
move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Source::sign_transaction(
|
Source::sign_transaction(SignParam {
|
||||||
source_genesis_hash,
|
spec_version,
|
||||||
&create_swap_signer,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: source_genesis_hash,
|
||||||
UnsignedTransaction::new(create_swap_call, transaction_nonce),
|
signer: create_swap_signer,
|
||||||
)
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(
|
||||||
|
create_swap_call,
|
||||||
|
transaction_nonce,
|
||||||
|
),
|
||||||
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -369,21 +380,25 @@ impl SwapTokens {
|
|||||||
|
|
||||||
// send `claim_swap` message
|
// send `claim_swap` message
|
||||||
let target_genesis_hash = *target_client.genesis_hash();
|
let target_genesis_hash = *target_client.genesis_hash();
|
||||||
|
let (spec_version, transaction_version) =
|
||||||
|
target_client.simple_runtime_version().await?;
|
||||||
let _ = wait_until_transaction_is_finalized::<Target>(
|
let _ = wait_until_transaction_is_finalized::<Target>(
|
||||||
target_client
|
target_client
|
||||||
.submit_and_watch_signed_extrinsic(
|
.submit_and_watch_signed_extrinsic(
|
||||||
accounts.target_account_at_bridged_chain.clone(),
|
accounts.target_account_at_bridged_chain.clone(),
|
||||||
move |_, transaction_nonce| {
|
move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Target::sign_transaction(
|
Target::sign_transaction(SignParam {
|
||||||
target_genesis_hash,
|
spec_version,
|
||||||
&target_sign,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: target_genesis_hash,
|
||||||
UnsignedTransaction::new(
|
signer: target_sign,
|
||||||
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(
|
||||||
send_message_call,
|
send_message_call,
|
||||||
transaction_nonce,
|
transaction_nonce,
|
||||||
),
|
),
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -409,21 +424,25 @@ impl SwapTokens {
|
|||||||
log::info!(target: "bridge", "Cancelling the swap");
|
log::info!(target: "bridge", "Cancelling the swap");
|
||||||
let cancel_swap_call: CallOf<Source> =
|
let cancel_swap_call: CallOf<Source> =
|
||||||
pallet_bridge_token_swap::Call::cancel_swap { swap: token_swap.clone() }.into();
|
pallet_bridge_token_swap::Call::cancel_swap { swap: token_swap.clone() }.into();
|
||||||
|
let (spec_version, transaction_version) =
|
||||||
|
source_client.simple_runtime_version().await?;
|
||||||
let _ = wait_until_transaction_is_finalized::<Source>(
|
let _ = wait_until_transaction_is_finalized::<Source>(
|
||||||
source_client
|
source_client
|
||||||
.submit_and_watch_signed_extrinsic(
|
.submit_and_watch_signed_extrinsic(
|
||||||
accounts.source_account_at_this_chain.clone(),
|
accounts.source_account_at_this_chain.clone(),
|
||||||
move |_, transaction_nonce| {
|
move |_, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
Source::sign_transaction(
|
Source::sign_transaction(SignParam {
|
||||||
source_genesis_hash,
|
spec_version,
|
||||||
&source_sign,
|
transaction_version,
|
||||||
relay_substrate_client::TransactionEra::immortal(),
|
genesis_hash: source_genesis_hash,
|
||||||
UnsignedTransaction::new(
|
signer: source_sign,
|
||||||
|
era: relay_substrate_client::TransactionEra::immortal(),
|
||||||
|
unsigned: UnsignedTransaction::new(
|
||||||
cancel_swap_call,
|
cancel_swap_call,
|
||||||
transaction_nonce,
|
transaction_nonce,
|
||||||
),
|
),
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -673,6 +692,7 @@ async fn read_token_swap_state<C: Chain>(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::cli::{RuntimeVersionType, SourceRuntimeVersionParams, TargetRuntimeVersionParams};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn swap_tokens_millau_to_rialto_no_lock() {
|
fn swap_tokens_millau_to_rialto_no_lock() {
|
||||||
@@ -706,6 +726,11 @@ mod tests {
|
|||||||
source_host: "127.0.0.1".into(),
|
source_host: "127.0.0.1".into(),
|
||||||
source_port: 9000,
|
source_port: 9000,
|
||||||
source_secure: false,
|
source_secure: false,
|
||||||
|
source_runtime_version: SourceRuntimeVersionParams {
|
||||||
|
source_version_mode: RuntimeVersionType::Bundle,
|
||||||
|
source_spec_version: None,
|
||||||
|
source_transaction_version: None,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
source_sign: SourceSigningParams {
|
source_sign: SourceSigningParams {
|
||||||
source_signer: Some("//Alice".into()),
|
source_signer: Some("//Alice".into()),
|
||||||
@@ -718,6 +743,11 @@ mod tests {
|
|||||||
target_host: "127.0.0.1".into(),
|
target_host: "127.0.0.1".into(),
|
||||||
target_port: 9001,
|
target_port: 9001,
|
||||||
target_secure: false,
|
target_secure: false,
|
||||||
|
target_runtime_version: TargetRuntimeVersionParams {
|
||||||
|
target_version_mode: RuntimeVersionType::Bundle,
|
||||||
|
target_spec_version: None,
|
||||||
|
target_transaction_version: None,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
target_sign: TargetSigningParams {
|
target_sign: TargetSigningParams {
|
||||||
target_signer: Some("//Bob".into()),
|
target_signer: Some("//Bob".into()),
|
||||||
@@ -767,6 +797,11 @@ mod tests {
|
|||||||
source_host: "127.0.0.1".into(),
|
source_host: "127.0.0.1".into(),
|
||||||
source_port: 9000,
|
source_port: 9000,
|
||||||
source_secure: false,
|
source_secure: false,
|
||||||
|
source_runtime_version: SourceRuntimeVersionParams {
|
||||||
|
source_version_mode: RuntimeVersionType::Bundle,
|
||||||
|
source_spec_version: None,
|
||||||
|
source_transaction_version: None,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
source_sign: SourceSigningParams {
|
source_sign: SourceSigningParams {
|
||||||
source_signer: Some("//Alice".into()),
|
source_signer: Some("//Alice".into()),
|
||||||
@@ -779,6 +814,11 @@ mod tests {
|
|||||||
target_host: "127.0.0.1".into(),
|
target_host: "127.0.0.1".into(),
|
||||||
target_port: 9001,
|
target_port: 9001,
|
||||||
target_secure: false,
|
target_secure: false,
|
||||||
|
target_runtime_version: TargetRuntimeVersionParams {
|
||||||
|
target_version_mode: RuntimeVersionType::Bundle,
|
||||||
|
target_spec_version: None,
|
||||||
|
target_transaction_version: None,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
target_sign: TargetSigningParams {
|
target_sign: TargetSigningParams {
|
||||||
target_signer: Some("//Bob".into()),
|
target_signer: Some("//Bob".into()),
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ use bp_messages::MessageNonce;
|
|||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use frame_support::weights::Weight;
|
use frame_support::weights::Weight;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
Chain, ChainBase, ChainWithBalances, ChainWithMessages, TransactionEraOf,
|
Chain, ChainBase, ChainWithBalances, ChainWithMessages, SignParam, TransactionSignScheme,
|
||||||
TransactionSignScheme, UnsignedTransaction,
|
UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use sp_core::{storage::StorageKey, Pair};
|
use sp_core::{storage::StorageKey, Pair};
|
||||||
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
||||||
@@ -105,26 +105,22 @@ impl TransactionSignScheme for Kusama {
|
|||||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||||
type SignedTransaction = crate::runtime::UncheckedExtrinsic;
|
type SignedTransaction = crate::runtime::UncheckedExtrinsic;
|
||||||
|
|
||||||
fn sign_transaction(
|
fn sign_transaction(param: SignParam<Self>) -> Self::SignedTransaction {
|
||||||
genesis_hash: <Self::Chain as ChainBase>::Hash,
|
|
||||||
signer: &Self::AccountKeyPair,
|
|
||||||
era: TransactionEraOf<Self::Chain>,
|
|
||||||
unsigned: UnsignedTransaction<Self::Chain>,
|
|
||||||
) -> Self::SignedTransaction {
|
|
||||||
let raw_payload = SignedPayload::new(
|
let raw_payload = SignedPayload::new(
|
||||||
unsigned.call,
|
param.unsigned.call.clone(),
|
||||||
bp_kusama::SignedExtensions::new(
|
bp_kusama::SignedExtensions::new(
|
||||||
bp_kusama::VERSION,
|
param.spec_version,
|
||||||
era,
|
param.transaction_version,
|
||||||
genesis_hash,
|
param.era,
|
||||||
unsigned.nonce,
|
param.genesis_hash,
|
||||||
unsigned.tip,
|
param.unsigned.nonce,
|
||||||
|
param.unsigned.tip,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.expect("SignedExtension never fails.");
|
.expect("SignedExtension never fails.");
|
||||||
|
|
||||||
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
|
let signature = raw_payload.using_encoded(|payload| param.signer.sign(payload));
|
||||||
let signer: sp_runtime::MultiSigner = signer.public().into();
|
let signer: sp_runtime::MultiSigner = param.signer.public().into();
|
||||||
let (call, extra, _) = raw_payload.deconstruct();
|
let (call, extra, _) = raw_payload.deconstruct();
|
||||||
|
|
||||||
bp_kusama::UncheckedExtrinsic::new_signed(
|
bp_kusama::UncheckedExtrinsic::new_signed(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use bp_messages::MessageNonce;
|
|||||||
use codec::{Compact, Decode, Encode};
|
use codec::{Compact, Decode, Encode};
|
||||||
use frame_support::weights::Weight;
|
use frame_support::weights::Weight;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
BalanceOf, Chain, ChainBase, ChainWithBalances, ChainWithMessages, IndexOf, TransactionEraOf,
|
BalanceOf, Chain, ChainBase, ChainWithBalances, ChainWithMessages, IndexOf, SignParam,
|
||||||
TransactionSignScheme, UnsignedTransaction,
|
TransactionSignScheme, UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use sp_core::{storage::StorageKey, Pair};
|
use sp_core::{storage::StorageKey, Pair};
|
||||||
@@ -107,35 +107,30 @@ impl TransactionSignScheme for Millau {
|
|||||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||||
type SignedTransaction = millau_runtime::UncheckedExtrinsic;
|
type SignedTransaction = millau_runtime::UncheckedExtrinsic;
|
||||||
|
|
||||||
fn sign_transaction(
|
fn sign_transaction(param: SignParam<Self>) -> Self::SignedTransaction {
|
||||||
genesis_hash: <Self::Chain as ChainBase>::Hash,
|
|
||||||
signer: &Self::AccountKeyPair,
|
|
||||||
era: TransactionEraOf<Self::Chain>,
|
|
||||||
unsigned: UnsignedTransaction<Self::Chain>,
|
|
||||||
) -> Self::SignedTransaction {
|
|
||||||
let raw_payload = SignedPayload::from_raw(
|
let raw_payload = SignedPayload::from_raw(
|
||||||
unsigned.call,
|
param.unsigned.call.clone(),
|
||||||
(
|
(
|
||||||
frame_system::CheckSpecVersion::<millau_runtime::Runtime>::new(),
|
frame_system::CheckSpecVersion::<millau_runtime::Runtime>::new(),
|
||||||
frame_system::CheckTxVersion::<millau_runtime::Runtime>::new(),
|
frame_system::CheckTxVersion::<millau_runtime::Runtime>::new(),
|
||||||
frame_system::CheckGenesis::<millau_runtime::Runtime>::new(),
|
frame_system::CheckGenesis::<millau_runtime::Runtime>::new(),
|
||||||
frame_system::CheckEra::<millau_runtime::Runtime>::from(era.frame_era()),
|
frame_system::CheckEra::<millau_runtime::Runtime>::from(param.era.frame_era()),
|
||||||
frame_system::CheckNonce::<millau_runtime::Runtime>::from(unsigned.nonce),
|
frame_system::CheckNonce::<millau_runtime::Runtime>::from(param.unsigned.nonce),
|
||||||
frame_system::CheckWeight::<millau_runtime::Runtime>::new(),
|
frame_system::CheckWeight::<millau_runtime::Runtime>::new(),
|
||||||
pallet_transaction_payment::ChargeTransactionPayment::<millau_runtime::Runtime>::from(unsigned.tip),
|
pallet_transaction_payment::ChargeTransactionPayment::<millau_runtime::Runtime>::from(param.unsigned.tip),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
millau_runtime::VERSION.spec_version,
|
param.spec_version,
|
||||||
millau_runtime::VERSION.transaction_version,
|
param.transaction_version,
|
||||||
genesis_hash,
|
param.genesis_hash,
|
||||||
era.signed_payload(genesis_hash),
|
param.era.signed_payload(param.genesis_hash),
|
||||||
(),
|
(),
|
||||||
(),
|
(),
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
|
let signature = raw_payload.using_encoded(|payload| param.signer.sign(payload));
|
||||||
let signer: sp_runtime::MultiSigner = signer.public().into();
|
let signer: sp_runtime::MultiSigner = param.signer.public().into();
|
||||||
let (call, extra, _) = raw_payload.deconstruct();
|
let (call, extra, _) = raw_payload.deconstruct();
|
||||||
|
|
||||||
millau_runtime::UncheckedExtrinsic::new_signed(
|
millau_runtime::UncheckedExtrinsic::new_signed(
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ use bp_messages::MessageNonce;
|
|||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use frame_support::weights::Weight;
|
use frame_support::weights::Weight;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
Chain, ChainBase, ChainWithBalances, ChainWithMessages, TransactionEraOf,
|
Chain, ChainBase, ChainWithBalances, ChainWithMessages, SignParam, TransactionSignScheme,
|
||||||
TransactionSignScheme, UnsignedTransaction,
|
UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use sp_core::{storage::StorageKey, Pair};
|
use sp_core::{storage::StorageKey, Pair};
|
||||||
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
||||||
@@ -105,26 +105,22 @@ impl TransactionSignScheme for Polkadot {
|
|||||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||||
type SignedTransaction = crate::runtime::UncheckedExtrinsic;
|
type SignedTransaction = crate::runtime::UncheckedExtrinsic;
|
||||||
|
|
||||||
fn sign_transaction(
|
fn sign_transaction(param: SignParam<Self>) -> Self::SignedTransaction {
|
||||||
genesis_hash: <Self::Chain as ChainBase>::Hash,
|
|
||||||
signer: &Self::AccountKeyPair,
|
|
||||||
era: TransactionEraOf<Self::Chain>,
|
|
||||||
unsigned: UnsignedTransaction<Self::Chain>,
|
|
||||||
) -> Self::SignedTransaction {
|
|
||||||
let raw_payload = SignedPayload::new(
|
let raw_payload = SignedPayload::new(
|
||||||
unsigned.call,
|
param.unsigned.call.clone(),
|
||||||
bp_polkadot::SignedExtensions::new(
|
bp_polkadot::SignedExtensions::new(
|
||||||
bp_polkadot::VERSION,
|
param.spec_version,
|
||||||
era,
|
param.transaction_version,
|
||||||
genesis_hash,
|
param.era,
|
||||||
unsigned.nonce,
|
param.genesis_hash,
|
||||||
unsigned.tip,
|
param.unsigned.nonce,
|
||||||
|
param.unsigned.tip,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.expect("SignedExtension never fails.");
|
.expect("SignedExtension never fails.");
|
||||||
|
|
||||||
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
|
let signature = raw_payload.using_encoded(|payload| param.signer.sign(payload));
|
||||||
let signer: sp_runtime::MultiSigner = signer.public().into();
|
let signer: sp_runtime::MultiSigner = param.signer.public().into();
|
||||||
let (call, extra, _) = raw_payload.deconstruct();
|
let (call, extra, _) = raw_payload.deconstruct();
|
||||||
|
|
||||||
bp_polkadot::UncheckedExtrinsic::new_signed(
|
bp_polkadot::UncheckedExtrinsic::new_signed(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use bp_messages::MessageNonce;
|
|||||||
use codec::{Compact, Decode, Encode};
|
use codec::{Compact, Decode, Encode};
|
||||||
use frame_support::weights::Weight;
|
use frame_support::weights::Weight;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
BalanceOf, Chain, ChainBase, ChainWithBalances, ChainWithMessages, IndexOf, TransactionEraOf,
|
BalanceOf, Chain, ChainBase, ChainWithBalances, ChainWithMessages, IndexOf, SignParam,
|
||||||
TransactionSignScheme, UnsignedTransaction,
|
TransactionSignScheme, UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use sp_core::{storage::StorageKey, Pair};
|
use sp_core::{storage::StorageKey, Pair};
|
||||||
@@ -107,35 +107,30 @@ impl TransactionSignScheme for Rialto {
|
|||||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||||
type SignedTransaction = rialto_runtime::UncheckedExtrinsic;
|
type SignedTransaction = rialto_runtime::UncheckedExtrinsic;
|
||||||
|
|
||||||
fn sign_transaction(
|
fn sign_transaction(param: SignParam<Self>) -> Self::SignedTransaction {
|
||||||
genesis_hash: <Self::Chain as ChainBase>::Hash,
|
|
||||||
signer: &Self::AccountKeyPair,
|
|
||||||
era: TransactionEraOf<Self::Chain>,
|
|
||||||
unsigned: UnsignedTransaction<Self::Chain>,
|
|
||||||
) -> Self::SignedTransaction {
|
|
||||||
let raw_payload = SignedPayload::from_raw(
|
let raw_payload = SignedPayload::from_raw(
|
||||||
unsigned.call,
|
param.unsigned.call.clone(),
|
||||||
(
|
(
|
||||||
frame_system::CheckSpecVersion::<rialto_runtime::Runtime>::new(),
|
frame_system::CheckSpecVersion::<rialto_runtime::Runtime>::new(),
|
||||||
frame_system::CheckTxVersion::<rialto_runtime::Runtime>::new(),
|
frame_system::CheckTxVersion::<rialto_runtime::Runtime>::new(),
|
||||||
frame_system::CheckGenesis::<rialto_runtime::Runtime>::new(),
|
frame_system::CheckGenesis::<rialto_runtime::Runtime>::new(),
|
||||||
frame_system::CheckEra::<rialto_runtime::Runtime>::from(era.frame_era()),
|
frame_system::CheckEra::<rialto_runtime::Runtime>::from(param.era.frame_era()),
|
||||||
frame_system::CheckNonce::<rialto_runtime::Runtime>::from(unsigned.nonce),
|
frame_system::CheckNonce::<rialto_runtime::Runtime>::from(param.unsigned.nonce),
|
||||||
frame_system::CheckWeight::<rialto_runtime::Runtime>::new(),
|
frame_system::CheckWeight::<rialto_runtime::Runtime>::new(),
|
||||||
pallet_transaction_payment::ChargeTransactionPayment::<rialto_runtime::Runtime>::from(unsigned.tip),
|
pallet_transaction_payment::ChargeTransactionPayment::<rialto_runtime::Runtime>::from(param.unsigned.tip),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
rialto_runtime::VERSION.spec_version,
|
param.spec_version,
|
||||||
rialto_runtime::VERSION.transaction_version,
|
param.transaction_version,
|
||||||
genesis_hash,
|
param.genesis_hash,
|
||||||
era.signed_payload(genesis_hash),
|
param.era.signed_payload(param.genesis_hash),
|
||||||
(),
|
(),
|
||||||
(),
|
(),
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
|
let signature = raw_payload.using_encoded(|payload| param.signer.sign(payload));
|
||||||
let signer: sp_runtime::MultiSigner = signer.public().into();
|
let signer: sp_runtime::MultiSigner = param.signer.public().into();
|
||||||
let (call, extra, _) = raw_payload.deconstruct();
|
let (call, extra, _) = raw_payload.deconstruct();
|
||||||
|
|
||||||
rialto_runtime::UncheckedExtrinsic::new_signed(
|
rialto_runtime::UncheckedExtrinsic::new_signed(
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ use bp_messages::MessageNonce;
|
|||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use frame_support::weights::Weight;
|
use frame_support::weights::Weight;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
Chain, ChainBase, ChainWithBalances, ChainWithMessages, TransactionEraOf,
|
Chain, ChainBase, ChainWithBalances, ChainWithMessages, SignParam, TransactionSignScheme,
|
||||||
TransactionSignScheme, UnsignedTransaction,
|
UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use sp_core::{storage::StorageKey, Pair};
|
use sp_core::{storage::StorageKey, Pair};
|
||||||
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
||||||
@@ -108,26 +108,22 @@ impl TransactionSignScheme for Rococo {
|
|||||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||||
type SignedTransaction = crate::runtime::UncheckedExtrinsic;
|
type SignedTransaction = crate::runtime::UncheckedExtrinsic;
|
||||||
|
|
||||||
fn sign_transaction(
|
fn sign_transaction(param: SignParam<Self>) -> Self::SignedTransaction {
|
||||||
genesis_hash: <Self::Chain as ChainBase>::Hash,
|
|
||||||
signer: &Self::AccountKeyPair,
|
|
||||||
era: TransactionEraOf<Self::Chain>,
|
|
||||||
unsigned: UnsignedTransaction<Self::Chain>,
|
|
||||||
) -> Self::SignedTransaction {
|
|
||||||
let raw_payload = SignedPayload::new(
|
let raw_payload = SignedPayload::new(
|
||||||
unsigned.call,
|
param.unsigned.call.clone(),
|
||||||
bp_rococo::SignedExtensions::new(
|
bp_rococo::SignedExtensions::new(
|
||||||
bp_rococo::VERSION,
|
param.spec_version,
|
||||||
era,
|
param.transaction_version,
|
||||||
genesis_hash,
|
param.era,
|
||||||
unsigned.nonce,
|
param.genesis_hash,
|
||||||
unsigned.tip,
|
param.unsigned.nonce,
|
||||||
|
param.unsigned.tip,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.expect("SignedExtension never fails.");
|
.expect("SignedExtension never fails.");
|
||||||
|
|
||||||
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
|
let signature = raw_payload.using_encoded(|payload| param.signer.sign(payload));
|
||||||
let signer: sp_runtime::MultiSigner = signer.public().into();
|
let signer: sp_runtime::MultiSigner = param.signer.public().into();
|
||||||
let (call, extra, _) = raw_payload.deconstruct();
|
let (call, extra, _) = raw_payload.deconstruct();
|
||||||
|
|
||||||
bp_rococo::UncheckedExtrinsic::new_signed(
|
bp_rococo::UncheckedExtrinsic::new_signed(
|
||||||
|
|||||||
@@ -172,12 +172,9 @@ pub trait TransactionSignScheme {
|
|||||||
type SignedTransaction: Clone + Debug + Codec + Send + 'static;
|
type SignedTransaction: Clone + Debug + Codec + Send + 'static;
|
||||||
|
|
||||||
/// Create transaction for given runtime call, signed by given account.
|
/// Create transaction for given runtime call, signed by given account.
|
||||||
fn sign_transaction(
|
fn sign_transaction(param: SignParam<Self>) -> Self::SignedTransaction
|
||||||
genesis_hash: <Self::Chain as ChainBase>::Hash,
|
where
|
||||||
signer: &Self::AccountKeyPair,
|
Self: Sized;
|
||||||
era: TransactionEraOf<Self::Chain>,
|
|
||||||
unsigned: UnsignedTransaction<Self::Chain>,
|
|
||||||
) -> Self::SignedTransaction;
|
|
||||||
|
|
||||||
/// Returns true if transaction is signed.
|
/// Returns true if transaction is signed.
|
||||||
fn is_signed(tx: &Self::SignedTransaction) -> bool;
|
fn is_signed(tx: &Self::SignedTransaction) -> bool;
|
||||||
@@ -191,6 +188,22 @@ pub trait TransactionSignScheme {
|
|||||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self::Chain>>;
|
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self::Chain>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sign transaction parameters
|
||||||
|
pub struct SignParam<T: TransactionSignScheme> {
|
||||||
|
/// Version of the runtime specification.
|
||||||
|
pub spec_version: u32,
|
||||||
|
/// Transaction version
|
||||||
|
pub transaction_version: u32,
|
||||||
|
/// Hash of the genesis block.
|
||||||
|
pub genesis_hash: <T::Chain as ChainBase>::Hash,
|
||||||
|
/// Signer account
|
||||||
|
pub signer: T::AccountKeyPair,
|
||||||
|
/// Transaction era used by the chain.
|
||||||
|
pub era: TransactionEraOf<T::Chain>,
|
||||||
|
/// Transaction before it is signed.
|
||||||
|
pub unsigned: UnsignedTransaction<T::Chain>,
|
||||||
|
}
|
||||||
|
|
||||||
impl<Block: BlockT> BlockWithJustification<Block::Header> for SignedBlock<Block> {
|
impl<Block: BlockT> BlockWithJustification<Block::Header> for SignedBlock<Block> {
|
||||||
fn header(&self) -> Block::Header {
|
fn header(&self) -> Block::Header {
|
||||||
self.block.header().clone()
|
self.block.header().clone()
|
||||||
|
|||||||
@@ -60,6 +60,17 @@ pub struct Subscription<T>(Mutex<futures::channel::mpsc::Receiver<Option<T>>>);
|
|||||||
/// Opaque GRANDPA authorities set.
|
/// Opaque GRANDPA authorities set.
|
||||||
pub type OpaqueGrandpaAuthoritiesSet = Vec<u8>;
|
pub type OpaqueGrandpaAuthoritiesSet = Vec<u8>;
|
||||||
|
|
||||||
|
/// Chain runtime version in client
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum ChainRuntimeVersion {
|
||||||
|
/// Auto query from chain.
|
||||||
|
Auto,
|
||||||
|
/// Custom runtime version, defined by user.
|
||||||
|
/// the first is `spec_version`
|
||||||
|
/// the second is `transaction_version`
|
||||||
|
Custom(u32, u32),
|
||||||
|
}
|
||||||
|
|
||||||
/// Substrate client type.
|
/// Substrate client type.
|
||||||
///
|
///
|
||||||
/// Cloning `Client` is a cheap operation.
|
/// Cloning `Client` is a cheap operation.
|
||||||
@@ -77,6 +88,8 @@ pub struct Client<C: Chain> {
|
|||||||
/// transactions will be rejected from the pool. This lock is here to prevent situations like
|
/// transactions will be rejected from the pool. This lock is here to prevent situations like
|
||||||
/// that.
|
/// that.
|
||||||
submit_signed_extrinsic_lock: Arc<Mutex<()>>,
|
submit_signed_extrinsic_lock: Arc<Mutex<()>>,
|
||||||
|
/// Saved chain runtime version
|
||||||
|
chain_runtime_version: ChainRuntimeVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -99,6 +112,7 @@ impl<C: Chain> Clone for Client<C> {
|
|||||||
client: self.client.clone(),
|
client: self.client.clone(),
|
||||||
genesis_hash: self.genesis_hash,
|
genesis_hash: self.genesis_hash,
|
||||||
submit_signed_extrinsic_lock: self.submit_signed_extrinsic_lock.clone(),
|
submit_signed_extrinsic_lock: self.submit_signed_extrinsic_lock.clone(),
|
||||||
|
chain_runtime_version: self.chain_runtime_version.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,12 +158,14 @@ impl<C: Chain> Client<C> {
|
|||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
let chain_runtime_version = params.chain_runtime_version.clone();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
tokio,
|
tokio,
|
||||||
params,
|
params,
|
||||||
client,
|
client,
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
submit_signed_extrinsic_lock: Arc::new(Mutex::new(())),
|
submit_signed_extrinsic_lock: Arc::new(Mutex::new(())),
|
||||||
|
chain_runtime_version,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +194,19 @@ impl<C: Chain> Client<C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<C: Chain> Client<C> {
|
impl<C: Chain> Client<C> {
|
||||||
|
/// Return simple runtime version, only include `spec_version` and `transaction_version`.
|
||||||
|
pub async fn simple_runtime_version(&self) -> Result<(u32, u32)> {
|
||||||
|
let (spec_version, transaction_version) = match self.chain_runtime_version {
|
||||||
|
ChainRuntimeVersion::Auto => {
|
||||||
|
let runtime_version = self.runtime_version().await?;
|
||||||
|
(runtime_version.spec_version, runtime_version.transaction_version)
|
||||||
|
},
|
||||||
|
ChainRuntimeVersion::Custom(spec_version, transaction_version) =>
|
||||||
|
(spec_version, transaction_version),
|
||||||
|
};
|
||||||
|
Ok((spec_version, transaction_version))
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if client is connected to at least one peer and is in synced state.
|
/// Returns true if client is connected to at least one peer and is in synced state.
|
||||||
pub async fn ensure_synced(&self) -> Result<()> {
|
pub async fn ensure_synced(&self) -> Result<()> {
|
||||||
self.jsonrpsee_execute(|client| async move {
|
self.jsonrpsee_execute(|client| async move {
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ use std::time::Duration;
|
|||||||
pub use crate::{
|
pub use crate::{
|
||||||
chain::{
|
chain::{
|
||||||
AccountKeyPairOf, BlockWithJustification, CallOf, Chain, ChainWithBalances,
|
AccountKeyPairOf, BlockWithJustification, CallOf, Chain, ChainWithBalances,
|
||||||
ChainWithMessages, TransactionSignScheme, TransactionStatusOf, UnsignedTransaction,
|
ChainWithMessages, SignParam, TransactionSignScheme, TransactionStatusOf,
|
||||||
WeightToFeeOf,
|
UnsignedTransaction, WeightToFeeOf,
|
||||||
},
|
},
|
||||||
client::{Client, OpaqueGrandpaAuthoritiesSet, Subscription},
|
client::{ChainRuntimeVersion, Client, OpaqueGrandpaAuthoritiesSet, Subscription},
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
sync_header::SyncHeader,
|
sync_header::SyncHeader,
|
||||||
};
|
};
|
||||||
@@ -56,11 +56,18 @@ pub struct ConnectionParams {
|
|||||||
pub port: u16,
|
pub port: u16,
|
||||||
/// Use secure websocket connection.
|
/// Use secure websocket connection.
|
||||||
pub secure: bool,
|
pub secure: bool,
|
||||||
|
/// Defined chain runtime version
|
||||||
|
pub chain_runtime_version: ChainRuntimeVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ConnectionParams {
|
impl Default for ConnectionParams {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
ConnectionParams { host: "localhost".into(), port: 9944, secure: false }
|
ConnectionParams {
|
||||||
|
host: "localhost".into(),
|
||||||
|
port: 9944,
|
||||||
|
secure: false,
|
||||||
|
chain_runtime_version: ChainRuntimeVersion::Auto,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ use bp_messages::MessageNonce;
|
|||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use frame_support::weights::Weight;
|
use frame_support::weights::Weight;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
Chain, ChainBase, ChainWithBalances, ChainWithMessages, TransactionEraOf,
|
Chain, ChainBase, ChainWithBalances, ChainWithMessages, SignParam, TransactionSignScheme,
|
||||||
TransactionSignScheme, UnsignedTransaction,
|
UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use sp_core::{storage::StorageKey, Pair};
|
use sp_core::{storage::StorageKey, Pair};
|
||||||
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
||||||
@@ -108,26 +108,22 @@ impl TransactionSignScheme for Wococo {
|
|||||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||||
type SignedTransaction = crate::runtime::UncheckedExtrinsic;
|
type SignedTransaction = crate::runtime::UncheckedExtrinsic;
|
||||||
|
|
||||||
fn sign_transaction(
|
fn sign_transaction(param: SignParam<Self>) -> Self::SignedTransaction {
|
||||||
genesis_hash: <Self::Chain as ChainBase>::Hash,
|
|
||||||
signer: &Self::AccountKeyPair,
|
|
||||||
era: TransactionEraOf<Self::Chain>,
|
|
||||||
unsigned: UnsignedTransaction<Self::Chain>,
|
|
||||||
) -> Self::SignedTransaction {
|
|
||||||
let raw_payload = SignedPayload::new(
|
let raw_payload = SignedPayload::new(
|
||||||
unsigned.call,
|
param.unsigned.call.clone(),
|
||||||
bp_wococo::SignedExtensions::new(
|
bp_wococo::SignedExtensions::new(
|
||||||
bp_wococo::VERSION,
|
param.spec_version,
|
||||||
era,
|
param.transaction_version,
|
||||||
genesis_hash,
|
param.era,
|
||||||
unsigned.nonce,
|
param.genesis_hash,
|
||||||
unsigned.tip,
|
param.unsigned.nonce,
|
||||||
|
param.unsigned.tip,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.expect("SignedExtension never fails.");
|
.expect("SignedExtension never fails.");
|
||||||
|
|
||||||
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
|
let signature = raw_payload.using_encoded(|payload| param.signer.sign(payload));
|
||||||
let signer: sp_runtime::MultiSigner = signer.public().into();
|
let signer: sp_runtime::MultiSigner = param.signer.public().into();
|
||||||
let (call, extra, _) = raw_payload.deconstruct();
|
let (call, extra, _) = raw_payload.deconstruct();
|
||||||
|
|
||||||
bp_wococo::UncheckedExtrinsic::new_signed(
|
bp_wococo::UncheckedExtrinsic::new_signed(
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ use codec::Encode;
|
|||||||
use finality_relay::TargetClient;
|
use finality_relay::TargetClient;
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
AccountIdOf, AccountKeyPairOf, BlockNumberOf, Chain, Client, Error, HashOf, HeaderOf,
|
AccountIdOf, AccountKeyPairOf, BlockNumberOf, Chain, Client, Error, HashOf, HeaderOf,
|
||||||
SyncHeader, TransactionEra, TransactionSignScheme, UnsignedTransaction,
|
SignParam, SyncHeader, TransactionEra, TransactionSignScheme, UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use relay_utils::relay_loop::Client as RelayClient;
|
use relay_utils::relay_loop::Client as RelayClient;
|
||||||
use sp_core::{Bytes, Pair};
|
use sp_core::{Bytes, Pair};
|
||||||
@@ -103,17 +103,20 @@ where
|
|||||||
let transaction_params = self.transaction_params.clone();
|
let transaction_params = self.transaction_params.clone();
|
||||||
let call =
|
let call =
|
||||||
P::SubmitFinalityProofCallBuilder::build_submit_finality_proof_call(header, proof);
|
P::SubmitFinalityProofCallBuilder::build_submit_finality_proof_call(header, proof);
|
||||||
|
let (spec_version, transaction_version) = self.client.simple_runtime_version().await?;
|
||||||
self.client
|
self.client
|
||||||
.submit_signed_extrinsic(
|
.submit_signed_extrinsic(
|
||||||
self.transaction_params.signer.public().into(),
|
self.transaction_params.signer.public().into(),
|
||||||
move |best_block_id, transaction_nonce| {
|
move |best_block_id, transaction_nonce| {
|
||||||
Bytes(
|
Bytes(
|
||||||
P::TransactionSignScheme::sign_transaction(
|
P::TransactionSignScheme::sign_transaction(SignParam {
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
&transaction_params.signer,
|
signer: transaction_params.signer.clone(),
|
||||||
TransactionEra::new(best_block_id, transaction_params.mortality),
|
era: TransactionEra::new(best_block_id, transaction_params.mortality),
|
||||||
UnsignedTransaction::new(call, transaction_nonce),
|
unsigned: UnsignedTransaction::new(call, transaction_nonce),
|
||||||
)
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ use messages_relay::{
|
|||||||
use num_traits::{Bounded, Zero};
|
use num_traits::{Bounded, Zero};
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
AccountIdOf, AccountKeyPairOf, BalanceOf, Chain, ChainWithMessages, Client,
|
AccountIdOf, AccountKeyPairOf, BalanceOf, Chain, ChainWithMessages, Client,
|
||||||
Error as SubstrateError, HashOf, HeaderIdOf, IndexOf, TransactionEra, TransactionSignScheme,
|
Error as SubstrateError, HashOf, HeaderIdOf, IndexOf, SignParam, TransactionEra,
|
||||||
UnsignedTransaction,
|
TransactionSignScheme, UnsignedTransaction,
|
||||||
};
|
};
|
||||||
use relay_utils::{relay_loop::Client as RelayClient, HeaderId};
|
use relay_utils::{relay_loop::Client as RelayClient, HeaderId};
|
||||||
use sp_core::{Bytes, Pair};
|
use sp_core::{Bytes, Pair};
|
||||||
@@ -230,11 +230,14 @@ where
|
|||||||
) -> Result<(), SubstrateError> {
|
) -> Result<(), SubstrateError> {
|
||||||
let genesis_hash = *self.client.genesis_hash();
|
let genesis_hash = *self.client.genesis_hash();
|
||||||
let transaction_params = self.transaction_params.clone();
|
let transaction_params = self.transaction_params.clone();
|
||||||
|
let (spec_version, transaction_version) = self.client.simple_runtime_version().await?;
|
||||||
self.client
|
self.client
|
||||||
.submit_signed_extrinsic(
|
.submit_signed_extrinsic(
|
||||||
self.transaction_params.signer.public().into(),
|
self.transaction_params.signer.public().into(),
|
||||||
move |best_block_id, transaction_nonce| {
|
move |best_block_id, transaction_nonce| {
|
||||||
make_messages_delivery_proof_transaction::<P>(
|
make_messages_delivery_proof_transaction::<P>(
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
&genesis_hash,
|
&genesis_hash,
|
||||||
&transaction_params,
|
&transaction_params,
|
||||||
best_block_id,
|
best_block_id,
|
||||||
@@ -257,8 +260,14 @@ where
|
|||||||
async fn estimate_confirmation_transaction(
|
async fn estimate_confirmation_transaction(
|
||||||
&self,
|
&self,
|
||||||
) -> <MessageLaneAdapter<P> as MessageLane>::SourceChainBalance {
|
) -> <MessageLaneAdapter<P> as MessageLane>::SourceChainBalance {
|
||||||
|
let runtime_version = match self.client.runtime_version().await {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(_) => return BalanceOf::<P::SourceChain>::max_value(),
|
||||||
|
};
|
||||||
self.client
|
self.client
|
||||||
.estimate_extrinsic_fee(make_messages_delivery_proof_transaction::<P>(
|
.estimate_extrinsic_fee(make_messages_delivery_proof_transaction::<P>(
|
||||||
|
runtime_version.spec_version,
|
||||||
|
runtime_version.transaction_version,
|
||||||
self.client.genesis_hash(),
|
self.client.genesis_hash(),
|
||||||
&self.transaction_params,
|
&self.transaction_params,
|
||||||
HeaderId(Default::default(), Default::default()),
|
HeaderId(Default::default(), Default::default()),
|
||||||
@@ -274,6 +283,8 @@ where
|
|||||||
|
|
||||||
/// Make messages delivery proof transaction from given proof.
|
/// Make messages delivery proof transaction from given proof.
|
||||||
fn make_messages_delivery_proof_transaction<P: SubstrateMessageLane>(
|
fn make_messages_delivery_proof_transaction<P: SubstrateMessageLane>(
|
||||||
|
spec_version: u32,
|
||||||
|
transaction_version: u32,
|
||||||
source_genesis_hash: &HashOf<P::SourceChain>,
|
source_genesis_hash: &HashOf<P::SourceChain>,
|
||||||
source_transaction_params: &TransactionParams<AccountKeyPairOf<P::SourceTransactionSignScheme>>,
|
source_transaction_params: &TransactionParams<AccountKeyPairOf<P::SourceTransactionSignScheme>>,
|
||||||
source_best_block_id: HeaderIdOf<P::SourceChain>,
|
source_best_block_id: HeaderIdOf<P::SourceChain>,
|
||||||
@@ -289,12 +300,14 @@ where
|
|||||||
proof, trace_call,
|
proof, trace_call,
|
||||||
);
|
);
|
||||||
Bytes(
|
Bytes(
|
||||||
P::SourceTransactionSignScheme::sign_transaction(
|
P::SourceTransactionSignScheme::sign_transaction(SignParam {
|
||||||
*source_genesis_hash,
|
spec_version,
|
||||||
&source_transaction_params.signer,
|
transaction_version,
|
||||||
TransactionEra::new(source_best_block_id, source_transaction_params.mortality),
|
genesis_hash: *source_genesis_hash,
|
||||||
UnsignedTransaction::new(call, transaction_nonce),
|
signer: source_transaction_params.signer.clone(),
|
||||||
)
|
era: TransactionEra::new(source_best_block_id, source_transaction_params.mortality),
|
||||||
|
unsigned: UnsignedTransaction::new(call, transaction_nonce),
|
||||||
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ use messages_relay::{
|
|||||||
use num_traits::{Bounded, Zero};
|
use num_traits::{Bounded, Zero};
|
||||||
use relay_substrate_client::{
|
use relay_substrate_client::{
|
||||||
AccountIdOf, AccountKeyPairOf, BalanceOf, Chain, ChainWithMessages, Client,
|
AccountIdOf, AccountKeyPairOf, BalanceOf, Chain, ChainWithMessages, Client,
|
||||||
Error as SubstrateError, HashOf, HeaderIdOf, IndexOf, TransactionEra, TransactionSignScheme,
|
Error as SubstrateError, HashOf, HeaderIdOf, IndexOf, SignParam, TransactionEra,
|
||||||
UnsignedTransaction, WeightToFeeOf,
|
TransactionSignScheme, UnsignedTransaction, WeightToFeeOf,
|
||||||
};
|
};
|
||||||
use relay_utils::{relay_loop::Client as RelayClient, HeaderId};
|
use relay_utils::{relay_loop::Client as RelayClient, HeaderId};
|
||||||
use sp_core::{Bytes, Pair};
|
use sp_core::{Bytes, Pair};
|
||||||
@@ -218,11 +218,14 @@ where
|
|||||||
let transaction_params = self.transaction_params.clone();
|
let transaction_params = self.transaction_params.clone();
|
||||||
let relayer_id_at_source = self.relayer_id_at_source.clone();
|
let relayer_id_at_source = self.relayer_id_at_source.clone();
|
||||||
let nonces_clone = nonces.clone();
|
let nonces_clone = nonces.clone();
|
||||||
|
let (spec_version, transaction_version) = self.client.simple_runtime_version().await?;
|
||||||
self.client
|
self.client
|
||||||
.submit_signed_extrinsic(
|
.submit_signed_extrinsic(
|
||||||
self.transaction_params.signer.public().into(),
|
self.transaction_params.signer.public().into(),
|
||||||
move |best_block_id, transaction_nonce| {
|
move |best_block_id, transaction_nonce| {
|
||||||
make_messages_delivery_transaction::<P>(
|
make_messages_delivery_transaction::<P>(
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
&genesis_hash,
|
&genesis_hash,
|
||||||
&transaction_params,
|
&transaction_params,
|
||||||
best_block_id,
|
best_block_id,
|
||||||
@@ -260,8 +263,11 @@ where
|
|||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
let (spec_version, transaction_version) = self.client.simple_runtime_version().await?;
|
||||||
// Prepare 'dummy' delivery transaction - we only care about its length and dispatch weight.
|
// Prepare 'dummy' delivery transaction - we only care about its length and dispatch weight.
|
||||||
let delivery_tx = make_messages_delivery_transaction::<P>(
|
let delivery_tx = make_messages_delivery_transaction::<P>(
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
self.client.genesis_hash(),
|
self.client.genesis_hash(),
|
||||||
&self.transaction_params,
|
&self.transaction_params,
|
||||||
HeaderId(Default::default(), Default::default()),
|
HeaderId(Default::default(), Default::default()),
|
||||||
@@ -297,10 +303,13 @@ where
|
|||||||
let expected_refund_in_target_tokens = if total_prepaid_nonces != 0 {
|
let expected_refund_in_target_tokens = if total_prepaid_nonces != 0 {
|
||||||
const WEIGHT_DIFFERENCE: Weight = 100;
|
const WEIGHT_DIFFERENCE: Weight = 100;
|
||||||
|
|
||||||
|
let (spec_version, transaction_version) = self.client.simple_runtime_version().await?;
|
||||||
let larger_dispatch_weight = total_dispatch_weight.saturating_add(WEIGHT_DIFFERENCE);
|
let larger_dispatch_weight = total_dispatch_weight.saturating_add(WEIGHT_DIFFERENCE);
|
||||||
let larger_delivery_tx_fee = self
|
let larger_delivery_tx_fee = self
|
||||||
.client
|
.client
|
||||||
.estimate_extrinsic_fee(make_messages_delivery_transaction::<P>(
|
.estimate_extrinsic_fee(make_messages_delivery_transaction::<P>(
|
||||||
|
spec_version,
|
||||||
|
transaction_version,
|
||||||
self.client.genesis_hash(),
|
self.client.genesis_hash(),
|
||||||
&self.transaction_params,
|
&self.transaction_params,
|
||||||
HeaderId(Default::default(), Default::default()),
|
HeaderId(Default::default(), Default::default()),
|
||||||
@@ -365,6 +374,8 @@ where
|
|||||||
/// Make messages delivery transaction from given proof.
|
/// Make messages delivery transaction from given proof.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn make_messages_delivery_transaction<P: SubstrateMessageLane>(
|
fn make_messages_delivery_transaction<P: SubstrateMessageLane>(
|
||||||
|
spec_version: u32,
|
||||||
|
transaction_version: u32,
|
||||||
target_genesis_hash: &HashOf<P::TargetChain>,
|
target_genesis_hash: &HashOf<P::TargetChain>,
|
||||||
target_transaction_params: &TransactionParams<AccountKeyPairOf<P::TargetTransactionSignScheme>>,
|
target_transaction_params: &TransactionParams<AccountKeyPairOf<P::TargetTransactionSignScheme>>,
|
||||||
target_best_block_id: HeaderIdOf<P::TargetChain>,
|
target_best_block_id: HeaderIdOf<P::TargetChain>,
|
||||||
@@ -387,12 +398,14 @@ where
|
|||||||
trace_call,
|
trace_call,
|
||||||
);
|
);
|
||||||
Bytes(
|
Bytes(
|
||||||
P::TargetTransactionSignScheme::sign_transaction(
|
P::TargetTransactionSignScheme::sign_transaction(SignParam {
|
||||||
*target_genesis_hash,
|
spec_version,
|
||||||
&target_transaction_params.signer,
|
transaction_version,
|
||||||
TransactionEra::new(target_best_block_id, target_transaction_params.mortality),
|
genesis_hash: *target_genesis_hash,
|
||||||
UnsignedTransaction::new(call, transaction_nonce),
|
signer: target_transaction_params.signer.clone(),
|
||||||
)
|
era: TransactionEra::new(target_best_block_id, target_transaction_params.mortality),
|
||||||
|
unsigned: UnsignedTransaction::new(call, transaction_nonce),
|
||||||
|
})
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user