Skip to content
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
4 changes: 0 additions & 4 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
type InboundMessageFee = bp_rialto::Balance;
type InboundRelayer = bp_rialto::AccountId;

type AccountIdConverter = bp_millau::AccountIdConverter;

type TargetHeaderChain = crate::rialto_messages::Rialto;
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
type MessageDeliveryAndDispatchPayment = ();
Expand Down Expand Up @@ -494,8 +492,6 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
type InboundMessageFee = bp_rialto_parachain::Balance;
type InboundRelayer = bp_rialto_parachain::AccountId;

type AccountIdConverter = bp_millau::AccountIdConverter;

type TargetHeaderChain = crate::rialto_parachain_messages::RialtoParachain;
type LaneMessageVerifier = crate::rialto_parachain_messages::ToRialtoParachainMessageVerifier;
type MessageDeliveryAndDispatchPayment = ();
Expand Down
1 change: 0 additions & 1 deletion bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ mod tests {
bridge: WithRialtoMessageBridge,
this_chain: bp_millau::Millau,
bridged_chain: bp_rialto::Rialto,
this_chain_account_id_converter: bp_millau::AccountIdConverter
);

assert_complete_bridge_constants::<
Expand Down
2 changes: 0 additions & 2 deletions bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,6 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type InboundMessageFee = bp_millau::Balance;
type InboundRelayer = bp_millau::AccountId;

type AccountIdConverter = bp_rialto_parachain::AccountIdConverter;

type TargetHeaderChain = crate::millau_messages::Millau;
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
type MessageDeliveryAndDispatchPayment = ();
Expand Down
2 changes: 0 additions & 2 deletions bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type InboundMessageFee = bp_millau::Balance;
type InboundRelayer = bp_millau::AccountId;

type AccountIdConverter = bp_rialto::AccountIdConverter;

type TargetHeaderChain = crate::millau_messages::Millau;
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
type MessageDeliveryAndDispatchPayment = ();
Expand Down
1 change: 0 additions & 1 deletion bin/rialto/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ mod tests {
bridge: WithMillauMessageBridge,
this_chain: bp_rialto::Rialto,
bridged_chain: bp_millau::Millau,
this_chain_account_id_converter: bp_rialto::AccountIdConverter
);

assert_complete_bridge_constants::<
Expand Down
9 changes: 2 additions & 7 deletions bin/runtime-common/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ macro_rules! assert_bridge_messages_pallet_types(
(
runtime: $r:path,
with_bridged_chain_messages_instance: $i:path,
bridge: $bridge:path,
this_chain_account_id_converter: $this_converter:path
bridge: $bridge:path
) => {
{
// if one of asserts fail, then either bridge isn't configured properly (or alternatively - non-standard
Expand All @@ -127,8 +126,6 @@ macro_rules! assert_bridge_messages_pallet_types(
assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundMessageFee, BalanceOf<BridgedChain<$bridge>>);
assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundRelayer, AccountIdOf<BridgedChain<$bridge>>);

assert_type_eq_all!(<$r as MessagesConfig<$i>>::AccountIdConverter, $this_converter);

assert_type_eq_all!(<$r as MessagesConfig<$i>>::TargetHeaderChain, BridgedChain<$bridge>);
assert_type_eq_all!(<$r as MessagesConfig<$i>>::SourceHeaderChain, BridgedChain<$bridge>);
}
Expand All @@ -148,7 +145,6 @@ macro_rules! assert_complete_bridge_types(
bridge: $bridge:path,
this_chain: $this:path,
bridged_chain: $bridged:path,
this_chain_account_id_converter: $this_converter:path
) => {
$crate::assert_chain_types!(runtime: $r, this_chain: $this);
$crate::assert_bridge_types!(bridge: $bridge, this_chain: $this, bridged_chain: $bridged);
Expand All @@ -160,8 +156,7 @@ macro_rules! assert_complete_bridge_types(
$crate::assert_bridge_messages_pallet_types!(
runtime: $r,
with_bridged_chain_messages_instance: $mi,
bridge: $bridge,
this_chain_account_id_converter: $this_converter
bridge: $bridge
);
}
);
Expand Down
16 changes: 0 additions & 16 deletions modules/messages/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ benchmarks_instance_pallet! {
// added.
send_minimal_message_worst_case {
let lane_id = T::bench_lane_id();
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 0, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

// 'send' messages that are to be pruned when our message is sent
for _nonce in 1..=T::MaxMessagesToPruneAtOnce::get() {
Expand Down Expand Up @@ -159,10 +157,8 @@ benchmarks_instance_pallet! {
// `(send_16_kb_message_worst_case - send_1_kb_message_worst_case) / 15`.
send_1_kb_message_worst_case {
let lane_id = T::bench_lane_id();
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 0, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

// 'send' messages that are to be pruned when our message is sent
for _nonce in 1..=T::MaxMessagesToPruneAtOnce::get() {
Expand Down Expand Up @@ -198,10 +194,8 @@ benchmarks_instance_pallet! {
// `(send_16_kb_message_worst_case - send_1_kb_message_worst_case) / 15`.
send_16_kb_message_worst_case {
let lane_id = T::bench_lane_id();
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 0, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

// 'send' messages that are to be pruned when our message is sent
for _nonce in 1..=T::MaxMessagesToPruneAtOnce::get() {
Expand Down Expand Up @@ -233,10 +227,8 @@ benchmarks_instance_pallet! {
//
// Result of this benchmark is directly used by weight formula of the call.
maximal_increase_message_fee {
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 42, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

let additional_fee = T::account_balance(&sender);
let lane_id = T::bench_lane_id();
Expand All @@ -257,10 +249,8 @@ benchmarks_instance_pallet! {
increase_message_fee {
let i in 0..T::maximal_message_size().try_into().unwrap_or_default();

let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 42, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

let additional_fee = T::account_balance(&sender);
let lane_id = T::bench_lane_id();
Expand Down Expand Up @@ -488,10 +478,8 @@ benchmarks_instance_pallet! {
//
// This is base benchmark for all other confirmations delivery benchmarks.
receive_delivery_proof_for_single_message {
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let relayer_id: T::AccountId = account("relayer", 0, SEED);
let relayer_balance = T::account_balance(&relayer_id);
T::endow_account(&relayers_fund_id);

// send message that we're going to confirm
send_regular_message::<T, I>();
Expand Down Expand Up @@ -526,10 +514,8 @@ benchmarks_instance_pallet! {
// as `weight(receive_delivery_proof_for_two_messages_by_single_relayer)
// - weight(receive_delivery_proof_for_single_message)`.
receive_delivery_proof_for_two_messages_by_single_relayer {
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let relayer_id: T::AccountId = account("relayer", 0, SEED);
let relayer_balance = T::account_balance(&relayer_id);
T::endow_account(&relayers_fund_id);

// send message that we're going to confirm
send_regular_message::<T, I>();
Expand Down Expand Up @@ -567,12 +553,10 @@ benchmarks_instance_pallet! {
// as `weight(receive_delivery_proof_for_two_messages_by_two_relayers)
// - weight(receive_delivery_proof_for_two_messages_by_single_relayer)`.
receive_delivery_proof_for_two_messages_by_two_relayers {
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let relayer1_id: T::AccountId = account("relayer1", 1, SEED);
let relayer1_balance = T::account_balance(&relayer1_id);
let relayer2_id: T::AccountId = account("relayer2", 2, SEED);
let relayer2_balance = T::account_balance(&relayer2_id);
T::endow_account(&relayers_fund_id);

// send message that we're going to confirm
send_regular_message::<T, I>();
Expand Down
25 changes: 1 addition & 24 deletions modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ use frame_support::{
weights::{Pays, PostDispatchInfo},
};
use num_traits::{SaturatingAdd, Zero};
use sp_core::H256;
use sp_runtime::traits::Convert;
use sp_std::{
cell::RefCell, cmp::PartialOrd, collections::vec_deque::VecDeque, marker::PhantomData,
ops::RangeInclusive, prelude::*,
Expand Down Expand Up @@ -170,11 +168,6 @@ pub mod pallet {
/// bridged chain.
type InboundRelayer: Parameter + MaxEncodedLen;

/// A type which can be turned into an AccountId from a 256-bit hash.
///
/// Used when deriving the shared relayer fund account.
type AccountIdConverter: sp_runtime::traits::Convert<sp_core::hash::H256, Self::AccountId>;

// Types that are used by outbound_lane (on source chain).

/// Target header chain.
Expand Down Expand Up @@ -313,16 +306,14 @@ pub mod pallet {
T::MessageDeliveryAndDispatchPayment::pay_delivery_and_dispatch_fee(
&origin,
&additional_fee,
&relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>(),
)
.map_err(|err| {
log::trace!(
target: LOG_TARGET,
"Submitter can't pay additional fee {:?} for the message {:?}/{:?} to {:?}: {:?}",
"Submitter can't pay additional fee {:?} for the message {:?}/{:?}: {:?}",
additional_fee,
lane_id,
nonce,
relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>(),
err,
);

Expand Down Expand Up @@ -629,14 +620,11 @@ pub mod pallet {
});

// if some new messages have been confirmed, reward relayers
let relayer_fund_account =
relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
<T as Config<I>>::MessageDeliveryAndDispatchPayment::pay_relayers_rewards(
lane_id,
lane_data.relayers,
&confirmation_relayer,
&received_range,
&relayer_fund_account,
);
}

Expand Down Expand Up @@ -787,16 +775,6 @@ pub mod pallet {
}
}

/// AccountId of the shared relayer fund account.
///
/// This account is passed to `MessageDeliveryAndDispatchPayment` trait, and depending
/// on the implementation it can be used to store relayers rewards.
pub fn relayer_fund_account_id<AccountId, AccountIdConverter: Convert<H256, AccountId>>(
) -> AccountId {
let encoded_id = bp_runtime::derive_relayer_fund_account_id(bp_runtime::NO_INSTANCE_ID);
AccountIdConverter::convert(encoded_id)
}

impl<T, I>
bp_messages::source_chain::MessagesBridge<
T::Origin,
Expand Down Expand Up @@ -877,7 +855,6 @@ fn send_message<T: Config<I>, I: 'static>(
T::MessageDeliveryAndDispatchPayment::pay_delivery_and_dispatch_fee(
&submitter,
&delivery_and_dispatch_fee,
&relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>(),
)
.map_err(|err| {
log::trace!(
Expand Down
12 changes: 0 additions & 12 deletions modules/messages/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ pub struct TestPayload {
pub type TestMessageFee = u64;
pub type TestRelayer = u64;

pub struct AccountIdConverter;

impl sp_runtime::traits::Convert<H256, AccountId> for AccountIdConverter {
fn convert(hash: H256) -> AccountId {
hash.to_low_u64_ne()
}
}

type Block = frame_system::mocking::MockBlock<TestRuntime>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;

Expand Down Expand Up @@ -182,8 +174,6 @@ impl Config for TestRuntime {
type InboundMessageFee = TestMessageFee;
type InboundRelayer = TestRelayer;

type AccountIdConverter = AccountIdConverter;

type TargetHeaderChain = TestTargetHeaderChain;
type LaneMessageVerifier = TestLaneMessageVerifier;
type MessageDeliveryAndDispatchPayment = TestMessageDeliveryAndDispatchPayment;
Expand Down Expand Up @@ -360,7 +350,6 @@ impl MessageDeliveryAndDispatchPayment<Origin, AccountId, TestMessageFee>
fn pay_delivery_and_dispatch_fee(
submitter: &Origin,
fee: &TestMessageFee,
_relayer_fund_account: &AccountId,
) -> Result<(), Self::Error> {
if frame_support::storage::unhashed::get(b":reject-message-fee:") == Some(true) {
return Err(TEST_ERROR)
Expand All @@ -376,7 +365,6 @@ impl MessageDeliveryAndDispatchPayment<Origin, AccountId, TestMessageFee>
message_relayers: VecDeque<UnrewardedRelayer<AccountId>>,
_confirmation_relayer: &AccountId,
received_range: &RangeInclusive<MessageNonce>,
_relayer_fund_account: &AccountId,
) {
let relayers_rewards =
calc_relayers_rewards::<TestRuntime, ()>(lane_id, message_relayers, received_range);
Expand Down
7 changes: 0 additions & 7 deletions primitives/chain-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ impl WeightToFeePolynomial for WeightToFee {
}
}

// We use this to get the account on Kusama (target) which is derived from Polkadot's (source)
// account.
pub fn derive_account_from_polkadot_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId {
let encoded_id = bp_runtime::derive_account_id(bp_runtime::POLKADOT_CHAIN_ID, id);
AccountIdConverter::convert(encoded_id)
}

/// Per-byte fee for Kusama transactions.
pub const TRANSACTION_BYTE_FEE: Balance = 10 * 1_000_000_000_000 / 30_000 / 1_000;

Expand Down
39 changes: 1 addition & 38 deletions primitives/chain-millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use frame_system::limits;
use scale_info::TypeInfo;
use sp_core::{storage::StateVersion, Hasher as HasherT};
use sp_runtime::{
traits::{Convert, IdentifyAccount, Verify},
traits::{IdentifyAccount, Verify},
FixedU128, MultiSignature, MultiSigner, Perbill,
};
use sp_std::prelude::*;
Expand Down Expand Up @@ -218,43 +218,6 @@ impl sp_runtime::traits::Hash for BlakeTwoAndKeccak256 {
}
}

/// Convert a 256-bit hash into an AccountId.
pub struct AccountIdConverter;

impl sp_runtime::traits::Convert<sp_core::H256, AccountId> for AccountIdConverter {
fn convert(hash: sp_core::H256) -> AccountId {
hash.to_fixed_bytes().into()
}
}

/// We use this to get the account on Millau (target) which is derived from Rialto's (source)
/// account. We do this so we can fund the derived account on Millau at Genesis to it can pay
/// transaction fees.
///
/// The reason we can use the same `AccountId` type for both chains is because they share the same
/// development seed phrase.
///
/// Note that this should only be used for testing.
pub fn derive_account_from_rialto_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId {
let encoded_id = bp_runtime::derive_account_id(bp_runtime::RIALTO_CHAIN_ID, id);
AccountIdConverter::convert(encoded_id)
}

/// We use this to get the account on Millau (target) which is derived from RialtoParachain's
/// (source) account. We do this so we can fund the derived account on Millau at Genesis to it can
/// pay transaction fees.
///
/// The reason we can use the same `AccountId` type for both chains is because they share the same
/// development seed phrase.
///
/// Note that this should only be used for testing.
pub fn derive_account_from_rialto_parachain_id(
id: bp_runtime::SourceAccount<AccountId>,
) -> AccountId {
let encoded_id = bp_runtime::derive_account_id(bp_runtime::RIALTO_PARACHAIN_CHAIN_ID, id);
AccountIdConverter::convert(encoded_id)
}

frame_support::parameter_types! {
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(2 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
Expand Down
7 changes: 0 additions & 7 deletions primitives/chain-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ impl WeightToFeePolynomial for WeightToFee {
}
}

// We use this to get the account on Polkadot (target) which is derived from Kusama's (source)
// account.
pub fn derive_account_from_kusama_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId {
let encoded_id = bp_runtime::derive_account_id(bp_runtime::KUSAMA_CHAIN_ID, id);
AccountIdConverter::convert(encoded_id)
}

/// Per-byte fee for Polkadot transactions.
pub const TRANSACTION_BYTE_FEE: Balance = 10 * 10_000_000_000 / 100 / 1_000;

Expand Down
Loading