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

Mortal conversion rate updater transactions #1257

Merged
merged 6 commits into from
Mar 9, 2022
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
50 changes: 10 additions & 40 deletions relays/bin-substrate/src/chains/kusama_messages_to_polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

//! Kusama-to-Polkadot messages sync entrypoint.

use codec::Encode;
use frame_support::weights::Weight;
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, SignParam, TransactionSignScheme, UnsignedTransaction};
use substrate_relay_helper::messages_lane::SubstrateMessageLane;

/// Description of Kusama -> Polkadot messages bridge.
Expand All @@ -41,6 +38,13 @@ substrate_relay_helper::generate_mocked_receive_message_delivery_proof_call_buil
relay_kusama_client::runtime::Call::BridgePolkadotMessages,
relay_kusama_client::runtime::BridgePolkadotMessagesCall::receive_messages_delivery_proof
);
substrate_relay_helper::generate_mocked_update_conversion_rate_call_builder!(
Kusama,
KusamaMessagesToPolkadotUpdateConversionRateCallBuilder,
relay_kusama_client::runtime::Call::BridgePolkadotMessages,
relay_kusama_client::runtime::BridgePolkadotMessagesCall::update_pallet_parameter,
relay_kusama_client::runtime::BridgePolkadotMessagesParameter::PolkadotToKusamaConversionRate
);

impl SubstrateMessageLane for KusamaMessagesToPolkadot {
const SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
Expand Down Expand Up @@ -68,42 +72,8 @@ impl SubstrateMessageLane for KusamaMessagesToPolkadot {
type ReceiveMessagesDeliveryProofCallBuilder =
KusamaMessagesToPolkadotReceiveMessagesDeliveryProofCallBuilder;

type RelayStrategy = MixStrategy;
}
type TargetToSourceChainConversionRateUpdateBuilder =
KusamaMessagesToPolkadotUpdateConversionRateCallBuilder;

/// Update Polkadot -> Kusama conversion rate, stored in Kusama runtime storage.
pub(crate) async fn update_polkadot_to_kusama_conversion_rate(
client: Client<Kusama>,
signer: <Kusama as TransactionSignScheme>::AccountKeyPair,
updated_rate: f64,
) -> 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| {
Ok(Bytes(
Kusama::sign_transaction(SignParam {
spec_version,
transaction_version,
genesis_hash,
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(
sp_runtime::FixedU128::from_float(updated_rate),
)
)
).into(),
transaction_nonce,
),
})?
.encode(),
))
})
.await
.map(drop)
.map_err(|err| anyhow::format_err!("{:?}", err))
type RelayStrategy = MixStrategy;
}
49 changes: 10 additions & 39 deletions relays/bin-substrate/src/chains/millau_messages_to_rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@

//! Millau-to-Rialto messages sync entrypoint.

use codec::Encode;
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, SignParam, TransactionSignScheme, UnsignedTransaction};
use substrate_relay_helper::messages_lane::{
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
SubstrateMessageLane,
Expand All @@ -31,6 +27,13 @@ use substrate_relay_helper::messages_lane::{
/// Description of Millau -> Rialto messages bridge.
#[derive(Clone, Debug)]
pub struct MillauMessagesToRialto;
substrate_relay_helper::generate_direct_update_conversion_rate_call_builder!(
Millau,
MillauMessagesToRialtoUpdateConversionRateCallBuilder,
millau_runtime::Runtime,
millau_runtime::WithRialtoMessagesInstance,
millau_runtime::rialto_messages::MillauToRialtoMessagesParameter::RialtoToMillauConversionRate
);

impl SubstrateMessageLane for MillauMessagesToRialto {
const SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
Expand Down Expand Up @@ -60,40 +63,8 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
millau_runtime::WithRialtoMessagesInstance,
>;

type RelayStrategy = MixStrategy;
}
type TargetToSourceChainConversionRateUpdateBuilder =
MillauMessagesToRialtoUpdateConversionRateCallBuilder;

/// Update Rialto -> Millau conversion rate, stored in Millau runtime storage.
pub(crate) async fn update_rialto_to_millau_conversion_rate(
client: Client<Millau>,
signer: <Millau as TransactionSignScheme>::AccountKeyPair,
updated_rate: f64,
) -> 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| {
Ok(Bytes(
Millau::sign_transaction(SignParam {
spec_version,
transaction_version,
genesis_hash,
signer,
era: relay_substrate_client::TransactionEra::immortal(),
unsigned: UnsignedTransaction::new(
millau_runtime::Call::from(millau_runtime::MessagesCall::update_pallet_parameter {
parameter: millau_runtime::rialto_messages::MillauToRialtoMessagesParameter::RialtoToMillauConversionRate(
sp_runtime::FixedU128::from_float(updated_rate),
),
}).into(),
transaction_nonce,
),
})?
.encode(),
))
})
.await
.map(drop)
.map_err(|err| anyhow::format_err!("{:?}", err))
type RelayStrategy = MixStrategy;
}
51 changes: 10 additions & 41 deletions relays/bin-substrate/src/chains/polkadot_messages_to_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@

//! Polkadot-to-Kusama messages sync entrypoint.

use codec::Encode;
use sp_core::{Bytes, Pair};

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, SignParam, TransactionSignScheme, UnsignedTransaction};
use substrate_relay_helper::messages_lane::SubstrateMessageLane;

/// Description of Polkadot -> Kusama messages bridge.
Expand All @@ -41,6 +37,13 @@ substrate_relay_helper::generate_mocked_receive_message_delivery_proof_call_buil
relay_polkadot_client::runtime::Call::BridgeKusamaMessages,
relay_polkadot_client::runtime::BridgeKusamaMessagesCall::receive_messages_delivery_proof
);
substrate_relay_helper::generate_mocked_update_conversion_rate_call_builder!(
Polkadot,
PolkadotMessagesToKusamaUpdateConversionRateCallBuilder,
relay_polkadot_client::runtime::Call::BridgeKusamaMessages,
relay_polkadot_client::runtime::BridgeKusamaMessagesCall::update_pallet_parameter,
relay_polkadot_client::runtime::BridgeKusamaMessagesParameter::KusamaToPolkadotConversionRate
);

impl SubstrateMessageLane for PolkadotMessagesToKusama {
const SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
Expand Down Expand Up @@ -68,42 +71,8 @@ impl SubstrateMessageLane for PolkadotMessagesToKusama {
type ReceiveMessagesDeliveryProofCallBuilder =
PolkadotMessagesToKusamaReceiveMessagesDeliveryProofCallBuilder;

type RelayStrategy = MixStrategy;
}
type TargetToSourceChainConversionRateUpdateBuilder =
PolkadotMessagesToKusamaUpdateConversionRateCallBuilder;

/// Update Kusama -> Polkadot conversion rate, stored in Polkadot runtime storage.
pub(crate) async fn update_kusama_to_polkadot_conversion_rate(
client: Client<Polkadot>,
signer: <Polkadot as TransactionSignScheme>::AccountKeyPair,
updated_rate: f64,
) -> 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| {
Ok(Bytes(
Polkadot::sign_transaction(SignParam {
spec_version,
transaction_version,
genesis_hash,
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(
sp_runtime::FixedU128::from_float(updated_rate),
)
)
).into(),
transaction_nonce,
)
})?
.encode(),
))
})
.await
.map(drop)
.map_err(|err| anyhow::format_err!("{:?}", err))
type RelayStrategy = MixStrategy;
}
49 changes: 10 additions & 39 deletions relays/bin-substrate/src/chains/rialto_messages_to_millau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@

//! Rialto-to-Millau messages sync entrypoint.

use codec::Encode;
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, SignParam, TransactionSignScheme, UnsignedTransaction};
use substrate_relay_helper::messages_lane::{
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
SubstrateMessageLane,
Expand All @@ -31,6 +27,13 @@ use substrate_relay_helper::messages_lane::{
/// Description of Rialto -> Millau messages bridge.
#[derive(Clone, Debug)]
pub struct RialtoMessagesToMillau;
substrate_relay_helper::generate_direct_update_conversion_rate_call_builder!(
Rialto,
RialtoMessagesToMillauUpdateConversionRateCallBuilder,
rialto_runtime::Runtime,
rialto_runtime::WithMillauMessagesInstance,
rialto_runtime::millau_messages::RialtoToMillauMessagesParameter::MillauToRialtoConversionRate
);

impl SubstrateMessageLane for RialtoMessagesToMillau {
const SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
Expand Down Expand Up @@ -60,40 +63,8 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
rialto_runtime::WithMillauMessagesInstance,
>;

type RelayStrategy = MixStrategy;
}
type TargetToSourceChainConversionRateUpdateBuilder =
RialtoMessagesToMillauUpdateConversionRateCallBuilder;

/// Update Millau -> Rialto conversion rate, stored in Rialto runtime storage.
pub(crate) async fn update_millau_to_rialto_conversion_rate(
client: Client<Rialto>,
signer: <Rialto as TransactionSignScheme>::AccountKeyPair,
updated_rate: f64,
) -> 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| {
Ok(Bytes(
Rialto::sign_transaction(SignParam {
spec_version,
transaction_version,
genesis_hash,
signer,
era: relay_substrate_client::TransactionEra::immortal(),
unsigned: UnsignedTransaction::new(
rialto_runtime::Call::from(rialto_runtime::MessagesCall::update_pallet_parameter {
parameter: rialto_runtime::millau_messages::RialtoToMillauMessagesParameter::MillauToRialtoConversionRate(
sp_runtime::FixedU128::from_float(updated_rate),
),
}).into(),
transaction_nonce,
)
})?
.encode(),
))
})
.await
.map(drop)
.map_err(|err| anyhow::format_err!("{:?}", err))
type RelayStrategy = MixStrategy;
}
2 changes: 2 additions & 0 deletions relays/bin-substrate/src/chains/rococo_messages_to_wococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ impl SubstrateMessageLane for RococoMessagesToWococo {
type ReceiveMessagesDeliveryProofCallBuilder =
RococoMessagesToWococoReceiveMessagesDeliveryProofCallBuilder;

type TargetToSourceChainConversionRateUpdateBuilder = ();

type RelayStrategy = MixStrategy;
}
2 changes: 2 additions & 0 deletions relays/bin-substrate/src/chains/wococo_messages_to_rococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ impl SubstrateMessageLane for WococoMessagesToRococo {
type ReceiveMessagesDeliveryProofCallBuilder =
WococoMessagesToRococoReceiveMessagesDeliveryProofCallBuilder;

type TargetToSourceChainConversionRateUpdateBuilder = ();

type RelayStrategy = MixStrategy;
}
Loading