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

Update Rococo/Wococo version + prepare relay for Rococo<>Wococo bridge #1241

Merged
merged 2 commits into from
Dec 3, 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
5 changes: 4 additions & 1 deletion primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: sp_version::create_runtime_str!("rococo"),
impl_name: sp_version::create_runtime_str!("parity-rococo-v1.6"),
authoring_version: 0,
spec_version: 9100,
spec_version: 9130,
impl_version: 0,
apis: sp_version::create_apis_vec![[]],
transaction_version: 0,
Expand Down Expand Up @@ -105,6 +105,9 @@ pub const FROM_ROCOCO_LATEST_CONFIRMED_NONCE_METHOD: &str =
pub const FROM_ROCOCO_UNREWARDED_RELAYERS_STATE: &str =
"FromRococoInboundLaneApi_unrewarded_relayers_state";

/// Existential deposit on Rococo.
pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 100;

/// Weight of pay-dispatch-fee operation for inbound messages at Rococo chain.
///
/// This value corresponds to the result of
Expand Down
4 changes: 3 additions & 1 deletion primitives/chain-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ use sp_std::prelude::*;

pub use bp_polkadot_core::*;
// Rococo runtime = Wococo runtime
pub use bp_rococo::{WeightToFee, PAY_INBOUND_DISPATCH_FEE_WEIGHT, SESSION_LENGTH, VERSION};
pub use bp_rococo::{
WeightToFee, EXISTENTIAL_DEPOSIT, PAY_INBOUND_DISPATCH_FEE_WEIGHT, SESSION_LENGTH, VERSION,
};

/// Wococo Chain
pub type Wococo = PolkadotLike;
Expand Down
157 changes: 93 additions & 64 deletions relays/bin-substrate/src/cli/relay_headers_and_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ use strum::VariantNames;
use codec::Encode;
use messages_relay::relay_strategy::MixStrategy;
use relay_substrate_client::{
AccountIdOf, Chain, Client, TransactionSignScheme, UnsignedTransaction,
AccountIdOf, CallOf, Chain, Client, TransactionSignScheme, UnsignedTransaction,
};
use relay_utils::metrics::MetricsParams;
use sp_core::{Bytes, Pair};
use substrate_relay_helper::{
messages_lane::MessagesRelayParams, on_demand_headers::OnDemandHeadersRelay,
finality_pipeline::SubstrateFinalitySyncPipeline, messages_lane::MessagesRelayParams,
on_demand_headers::OnDemandHeadersRelay,
};

use crate::{
Expand Down Expand Up @@ -138,8 +139,8 @@ macro_rules! select_bridge {

use crate::chains::{
millau_messages_to_rialto::{
standalone_metrics as left_to_right_standalone_metrics,
run as left_to_right_messages,
standalone_metrics as left_to_right_standalone_metrics,
update_rialto_to_millau_conversion_rate as update_right_to_left_conversion_rate,
},
rialto_messages_to_millau::{
Expand Down Expand Up @@ -187,12 +188,10 @@ macro_rules! select_bridge {

use crate::chains::{
rococo_messages_to_wococo::{
standalone_metrics as left_to_right_standalone_metrics,
run as left_to_right_messages,
standalone_metrics as left_to_right_standalone_metrics,
},
wococo_messages_to_rococo::{
run as right_to_left_messages,
},
wococo_messages_to_rococo::run as right_to_left_messages,
};

async fn update_right_to_left_conversion_rate(
Expand All @@ -212,19 +211,39 @@ macro_rules! select_bridge {
}

async fn left_create_account(
_left_client: Client<Left>,
_left_sign: <Left as TransactionSignScheme>::AccountKeyPair,
_account_id: AccountIdOf<Left>,
left_client: Client<Left>,
left_sign: <Left as TransactionSignScheme>::AccountKeyPair,
account_id: AccountIdOf<Left>,
) -> anyhow::Result<()> {
Err(anyhow::format_err!("Account creation is not supported by this bridge"))
submit_signed_extrinsic(
left_client,
left_sign,
relay_rococo_client::runtime::Call::Balances(
relay_rococo_client::runtime::BalancesCall::transfer(
bp_rococo::AccountAddress::Id(account_id),
bp_rococo::EXISTENTIAL_DEPOSIT.into(),
),
),
)
.await
}

async fn right_create_account(
_right_client: Client<Right>,
_right_sign: <Right as TransactionSignScheme>::AccountKeyPair,
_account_id: AccountIdOf<Right>,
right_client: Client<Right>,
right_sign: <Right as TransactionSignScheme>::AccountKeyPair,
account_id: AccountIdOf<Right>,
) -> anyhow::Result<()> {
Err(anyhow::format_err!("Account creation is not supported by this bridge"))
submit_signed_extrinsic(
right_client,
right_sign,
relay_wococo_client::runtime::Call::Balances(
relay_wococo_client::runtime::BalancesCall::transfer(
bp_wococo::AccountAddress::Id(account_id),
bp_wococo::EXISTENTIAL_DEPOSIT.into(),
),
),
)
.await
}

$generic
Expand All @@ -250,8 +269,8 @@ macro_rules! select_bridge {

use crate::chains::{
kusama_messages_to_polkadot::{
standalone_metrics as left_to_right_standalone_metrics,
run as left_to_right_messages,
standalone_metrics as left_to_right_standalone_metrics,
update_polkadot_to_kusama_conversion_rate as update_right_to_left_conversion_rate,
},
polkadot_messages_to_kusama::{
Expand All @@ -265,59 +284,35 @@ macro_rules! select_bridge {
left_sign: <Left as TransactionSignScheme>::AccountKeyPair,
account_id: AccountIdOf<Left>,
) -> anyhow::Result<()> {
let left_genesis_hash = *left_client.genesis_hash();
left_client
.submit_signed_extrinsic(
left_sign.public().into(),
move |_, transaction_nonce| {
Bytes(
Left::sign_transaction(left_genesis_hash, &left_sign, relay_substrate_client::TransactionEra::immortal(),
UnsignedTransaction::new(
relay_kusama_client::runtime::Call::Balances(
relay_kusama_client::runtime::BalancesCall::transfer(
bp_kusama::AccountAddress::Id(account_id),
bp_kusama::EXISTENTIAL_DEPOSIT.into(),
),
),
transaction_nonce,
),
).encode()
)
},
)
.await
.map(drop)
.map_err(|e| anyhow::format_err!("{}", e))
submit_signed_extrinsic(
left_client,
left_sign,
relay_kusama_client::runtime::Call::Balances(
relay_kusama_client::runtime::BalancesCall::transfer(
bp_kusama::AccountAddress::Id(account_id),
bp_kusama::EXISTENTIAL_DEPOSIT.into(),
),
),
)
.await
}

async fn right_create_account(
right_client: Client<Right>,
right_sign: <Right as TransactionSignScheme>::AccountKeyPair,
account_id: AccountIdOf<Right>,
) -> anyhow::Result<()> {
let right_genesis_hash = *right_client.genesis_hash();
right_client
.submit_signed_extrinsic(
right_sign.public().into(),
move |_, transaction_nonce| {
Bytes(
Right::sign_transaction(right_genesis_hash, &right_sign, relay_substrate_client::TransactionEra::immortal(),
UnsignedTransaction::new(
relay_polkadot_client::runtime::Call::Balances(
relay_polkadot_client::runtime::BalancesCall::transfer(
bp_polkadot::AccountAddress::Id(account_id),
bp_polkadot::EXISTENTIAL_DEPOSIT.into(),
),
),
transaction_nonce,
),
).encode()
)
},
)
.await
.map(drop)
.map_err(|e| anyhow::format_err!("{}", e))
submit_signed_extrinsic(
right_client,
right_sign,
relay_polkadot_client::runtime::Call::Balances(
relay_polkadot_client::runtime::BalancesCall::transfer(
bp_polkadot::AccountAddress::Id(account_id),
bp_polkadot::EXISTENTIAL_DEPOSIT.into(),
),
),
)
.await
}

$generic
Expand Down Expand Up @@ -494,19 +489,25 @@ impl RelayHeadersAndMessages {
}

// start on-demand header relays
let left_to_right_finality =
LeftToRightFinality::new(right_client.clone(), right_sign.clone());
let right_to_left_finality =
RightToLeftFinality::new(left_client.clone(), left_sign.clone());
left_to_right_finality.start_relay_guards();
right_to_left_finality.start_relay_guards();
let left_to_right_on_demand_headers = OnDemandHeadersRelay::new(
left_client.clone(),
right_client.clone(),
right_transactions_mortality,
LeftToRightFinality::new(right_client.clone(), right_sign.clone()),
left_to_right_finality,
MAX_MISSING_LEFT_HEADERS_AT_RIGHT,
params.shared.only_mandatory_headers,
);
let right_to_left_on_demand_headers = OnDemandHeadersRelay::new(
right_client.clone(),
left_client.clone(),
left_transactions_mortality,
RightToLeftFinality::new(left_client.clone(), left_sign.clone()),
right_to_left_finality,
MAX_MISSING_RIGHT_HEADERS_AT_LEFT,
params.shared.only_mandatory_headers,
);
Expand Down Expand Up @@ -561,3 +562,31 @@ impl RelayHeadersAndMessages {
})
}
}

/// Sign and submit transaction with given call to the chain.
async fn submit_signed_extrinsic<C: Chain + TransactionSignScheme<Chain = C>>(
client: Client<C>,
sign: C::AccountKeyPair,
call: CallOf<C>,
) -> anyhow::Result<()>
where
AccountIdOf<C>: From<<<C as TransactionSignScheme>::AccountKeyPair as Pair>::Public>,
CallOf<C>: Send,
{
let genesis_hash = *client.genesis_hash();
client
.submit_signed_extrinsic(sign.public().into(), move |_, transaction_nonce| {
Bytes(
C::sign_transaction(
genesis_hash,
&sign,
relay_substrate_client::TransactionEra::immortal(),
UnsignedTransaction::new(call, transaction_nonce),
)
.encode(),
)
})
.await
.map(drop)
.map_err(|e| anyhow::format_err!("{}", e))
}
14 changes: 12 additions & 2 deletions relays/client-rococo/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
//! Types that are specific to the Rococo runtime.

use bp_messages::{LaneId, UnrewardedRelayersState};
use bp_polkadot_core::PolkadotLike;
use bp_polkadot_core::{AccountAddress, Balance, PolkadotLike};
use bp_runtime::Chain;
use codec::{Decode, Encode};
use codec::{Compact, Decode, Encode};
use frame_support::weights::Weight;
use scale_info::TypeInfo;

Expand Down Expand Up @@ -66,6 +66,9 @@ pub enum Call {
/// System pallet.
#[codec(index = 0)]
System(SystemCall),
/// Balances pallet.
#[codec(index = 4)]
Balances(BalancesCall),
/// Wococo bridge pallet.
#[codec(index = 41)]
BridgeGrandpaWococo(BridgeGrandpaWococoCall),
Expand All @@ -81,6 +84,13 @@ pub enum SystemCall {
remark(Vec<u8>),
}

#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BalancesCall {
#[codec(index = 0)]
transfer(AccountAddress, Compact<Balance>),
}

#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeGrandpaWococoCall {
Expand Down
14 changes: 12 additions & 2 deletions relays/client-wococo/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
//! Types that are specific to the Wococo runtime.

use bp_messages::{LaneId, UnrewardedRelayersState};
use bp_polkadot_core::PolkadotLike;
use bp_polkadot_core::{AccountAddress, Balance, PolkadotLike};
use bp_runtime::Chain;
use codec::{Decode, Encode};
use codec::{Compact, Decode, Encode};
use frame_support::weights::Weight;
use scale_info::TypeInfo;

Expand Down Expand Up @@ -66,6 +66,9 @@ pub enum Call {
/// System pallet.
#[codec(index = 0)]
System(SystemCall),
/// Balances pallet.
#[codec(index = 4)]
Balances(BalancesCall),
/// Rococo bridge pallet.
#[codec(index = 40)]
BridgeGrandpaRococo(BridgeGrandpaRococoCall),
Expand All @@ -81,6 +84,13 @@ pub enum SystemCall {
remark(Vec<u8>),
}

#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BalancesCall {
#[codec(index = 0)]
transfer(AccountAddress, Compact<Balance>),
}

#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeGrandpaRococoCall {
Expand Down