Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change submit transaction spec_version and transaction_version query from chain #1248

Merged
merged 19 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions deployments/local-scripts/relay-millau-to-rialto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ RUST_LOG=bridge=debug \
--target-host localhost \
--target-port $RIALTO_PORT \
--target-signer //Alice \
--source-version-mode Bundle \
--target-version-mode Bundle

sleep 5
RUST_LOG=bridge=debug \
Expand Down
7 changes: 4 additions & 3 deletions 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
17 changes: 10 additions & 7 deletions relays/bin-substrate/src/chains/kusama_messages_to_polkadot.rs
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
17 changes: 10 additions & 7 deletions relays/bin-substrate/src/chains/millau_messages_to_rialto.rs
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 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
17 changes: 10 additions & 7 deletions relays/bin-substrate/src/chains/polkadot_messages_to_kusama.rs
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
17 changes: 10 additions & 7 deletions relays/bin-substrate/src/chains/rialto_messages_to_millau.rs
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 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 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