Skip to content

Commit

Permalink
Change submit transaction spec_version and transaction_version query …
Browse files Browse the repository at this point in the history
…from chain (paritytech#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
  • Loading branch information
fewensa authored and serban300 committed Apr 9, 2024
1 parent c43b5d3 commit d720e6a
Show file tree
Hide file tree
Showing 29 changed files with 600 additions and 274 deletions.
7 changes: 4 additions & 3 deletions bridges/primitives/polkadot-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ impl<Call> parity_scale_codec::Decode for SignedExtensions<Call> {

impl<Call> SignedExtensions<Call> {
pub fn new(
version: sp_version::RuntimeVersion,
spec_version: u32,
transaction_version: u32,
era: bp_runtime::TransactionEraOf<PolkadotLike>,
genesis_hash: Hash,
nonce: Nonce,
Expand All @@ -282,8 +283,8 @@ impl<Call> SignedExtensions<Call> {
tip.into(), // transaction payment / tip (compact encoding)
),
additional_signed: (
version.spec_version,
version.transaction_version,
spec_version,
transaction_version,
genesis_hash,
era.signed_payload(genesis_hash),
(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sp_core::{Bytes, Pair};
use messages_relay::relay_strategy::MixStrategy;
use relay_kusama_client::Kusama;
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;

/// Description of Kusama -> Polkadot messages bridge.
Expand Down Expand Up @@ -69,14 +69,17 @@ pub(crate) async fn update_polkadot_to_kusama_conversion_rate(
) -> anyhow::Result<()> {
let genesis_hash = *client.genesis_hash();
let signer_id = (*signer.public().as_array_ref()).into();
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
Kusama::sign_transaction(
Kusama::sign_transaction(SignParam {
spec_version,
transaction_version,
genesis_hash,
&signer,
relay_substrate_client::TransactionEra::immortal(),
UnsignedTransaction::new(
signer,
era: relay_substrate_client::TransactionEra::immortal(),
unsigned: UnsignedTransaction::new(
relay_kusama_client::runtime::Call::BridgePolkadotMessages(
relay_kusama_client::runtime::BridgePolkadotMessagesCall::update_pallet_parameter(
relay_kusama_client::runtime::BridgePolkadotMessagesParameter::PolkadotToKusamaConversionRate(
Expand All @@ -86,8 +89,8 @@ pub(crate) async fn update_polkadot_to_kusama_conversion_rate(
),
transaction_nonce,
),
)
.encode(),
})
.encode(),
)
})
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sp_core::{Bytes, Pair};
use messages_relay::relay_strategy::MixStrategy;
use relay_millau_client::Millau;
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::{
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
SubstrateMessageLane,
Expand Down Expand Up @@ -66,23 +66,26 @@ pub(crate) async fn update_rialto_to_millau_conversion_rate(
) -> anyhow::Result<()> {
let genesis_hash = *client.genesis_hash();
let signer_id = (*signer.public().as_array_ref()).into();
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
Millau::sign_transaction(
Millau::sign_transaction(SignParam {
spec_version,
transaction_version,
genesis_hash,
&signer,
relay_substrate_client::TransactionEra::immortal(),
UnsignedTransaction::new(
signer,
era: relay_substrate_client::TransactionEra::immortal(),
unsigned: UnsignedTransaction::new(
millau_runtime::MessagesCall::update_pallet_parameter {
parameter: millau_runtime::rialto_messages::MillauToRialtoMessagesParameter::RialtoToMillauConversionRate(
sp_runtime::FixedU128::from_float(updated_rate),
),
}
.into(),
.into(),
transaction_nonce,
),
)
})
.encode(),
)
})
Expand Down
30 changes: 17 additions & 13 deletions bridges/relays/bin-substrate/src/chains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod tests {
use frame_support::dispatch::GetDispatchInfo;
use relay_millau_client::Millau;
use relay_rialto_client::Rialto;
use relay_substrate_client::{TransactionSignScheme, UnsignedTransaction};
use relay_substrate_client::{SignParam, TransactionSignScheme, UnsignedTransaction};
use sp_core::Pair;
use sp_runtime::traits::{IdentifyAccount, Verify};

Expand Down Expand Up @@ -204,12 +204,14 @@ mod tests {
fn rialto_tx_extra_bytes_constant_is_correct() {
let rialto_call =
rialto_runtime::Call::System(rialto_runtime::SystemCall::remark { remark: vec![] });
let rialto_tx = Rialto::sign_transaction(
Default::default(),
&sp_keyring::AccountKeyring::Alice.pair(),
relay_substrate_client::TransactionEra::immortal(),
UnsignedTransaction::new(rialto_call.clone(), 0),
);
let rialto_tx = Rialto::sign_transaction(SignParam {
spec_version: 1,
transaction_version: 1,
genesis_hash: Default::default(),
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();
assert!(
bp_rialto::TX_EXTRA_BYTES as usize >= extra_bytes_in_transaction,
Expand All @@ -223,12 +225,14 @@ mod tests {
fn millau_tx_extra_bytes_constant_is_correct() {
let millau_call =
millau_runtime::Call::System(millau_runtime::SystemCall::remark { remark: vec![] });
let millau_tx = Millau::sign_transaction(
Default::default(),
&sp_keyring::AccountKeyring::Alice.pair(),
relay_substrate_client::TransactionEra::immortal(),
UnsignedTransaction::new(millau_call.clone(), 0),
);
let millau_tx = Millau::sign_transaction(SignParam {
spec_version: 0,
transaction_version: 0,
genesis_hash: Default::default(),
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();
assert!(
bp_millau::TX_EXTRA_BYTES as usize >= extra_bytes_in_transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use frame_support::weights::Weight;
use messages_relay::relay_strategy::MixStrategy;
use relay_kusama_client::Kusama;
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;

/// Description of Polkadot -> Kusama messages bridge.
Expand Down Expand Up @@ -69,14 +69,17 @@ pub(crate) async fn update_kusama_to_polkadot_conversion_rate(
) -> anyhow::Result<()> {
let genesis_hash = *client.genesis_hash();
let signer_id = (*signer.public().as_array_ref()).into();
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
Polkadot::sign_transaction(
Polkadot::sign_transaction(SignParam {
spec_version,
transaction_version,
genesis_hash,
&signer,
relay_substrate_client::TransactionEra::immortal(),
UnsignedTransaction::new(
signer,
era: relay_substrate_client::TransactionEra::immortal(),
unsigned: UnsignedTransaction::new(
relay_polkadot_client::runtime::Call::BridgeKusamaMessages(
relay_polkadot_client::runtime::BridgeKusamaMessagesCall::update_pallet_parameter(
relay_polkadot_client::runtime::BridgeKusamaMessagesParameter::KusamaToPolkadotConversionRate(
Expand All @@ -85,8 +88,8 @@ pub(crate) async fn update_kusama_to_polkadot_conversion_rate(
)
),
transaction_nonce,
),
)
)
})
.encode(),
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sp_core::{Bytes, Pair};
use messages_relay::relay_strategy::MixStrategy;
use relay_millau_client::Millau;
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::{
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
SubstrateMessageLane,
Expand Down Expand Up @@ -66,23 +66,26 @@ pub(crate) async fn update_millau_to_rialto_conversion_rate(
) -> anyhow::Result<()> {
let genesis_hash = *client.genesis_hash();
let signer_id = (*signer.public().as_array_ref()).into();
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
Rialto::sign_transaction(
Rialto::sign_transaction(SignParam {
spec_version,
transaction_version,
genesis_hash,
&signer,
relay_substrate_client::TransactionEra::immortal(),
UnsignedTransaction::new(
signer,
era: relay_substrate_client::TransactionEra::immortal(),
unsigned: UnsignedTransaction::new(
rialto_runtime::MessagesCall::update_pallet_parameter {
parameter: rialto_runtime::millau_messages::RialtoToMillauMessagesParameter::MillauToRialtoConversionRate(
sp_runtime::FixedU128::from_float(updated_rate),
),
}
.into(),
transaction_nonce,
),
)
)
})
.encode(),
)
})
Expand Down
30 changes: 30 additions & 0 deletions bridges/relays/bin-substrate/src/cli/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ macro_rules! select_full_bridge {
#[allow(unused_imports)]
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
}
FullBridge::RialtoToMillau => {
Expand All @@ -100,6 +105,11 @@ macro_rules! select_full_bridge {
#[allow(unused_imports)]
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
}
FullBridge::RococoToWococo => {
Expand All @@ -122,6 +132,11 @@ macro_rules! select_full_bridge {
#[allow(unused_imports)]
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
}
FullBridge::WococoToRococo => {
Expand All @@ -144,6 +159,11 @@ macro_rules! select_full_bridge {
#[allow(unused_imports)]
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
}
FullBridge::KusamaToPolkadot => {
Expand All @@ -166,6 +186,11 @@ macro_rules! select_full_bridge {
#[allow(unused_imports)]
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
}
FullBridge::PolkadotToKusama => {
Expand All @@ -188,6 +213,11 @@ macro_rules! select_full_bridge {
#[allow(unused_imports)]
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
}
}
Expand Down
9 changes: 7 additions & 2 deletions bridges/relays/bin-substrate/src/cli/estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl EstimateFee {
let Self { source, bridge, lane, payload } = self;

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 payload =
Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?;
Expand Down Expand Up @@ -86,7 +86,7 @@ pub(crate) async fn estimate_message_delivery_and_dispatch_fee<Fee: Decode, C: C
#[cfg(test)]
mod tests {
use super::*;
use crate::cli::encode_call;
use crate::cli::{encode_call, RuntimeVersionType, SourceRuntimeVersionParams};
use sp_core::crypto::Ss58Codec;

#[test]
Expand Down Expand Up @@ -118,6 +118,11 @@ mod tests {
source_host: "127.0.0.1".into(),
source_port: 1234,
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 {
sender: alice.parse().unwrap(),
Expand Down
Loading

0 comments on commit d720e6a

Please sign in to comment.