Skip to content

Commit

Permalink
Remove message fee + message send calls (paritytech#1642)
Browse files Browse the repository at this point in the history
* remove message fee

* it is compiling!

* fixes + fmt

* more cleanup

* more cleanup

* restore MessageDeliveryAndDispatchPayment since we'll need relayer rewards

* started rational relayer removal

* more removal

* removed estimate fee subcommand

* remove DispatchFeePayment

* more removals

* removed conversion rates && some metrics

* - unneeded associated type

* - OutboundMessageFee

* fix benchmarks compilation

* fmt

* test + fix benchmarks

* fix send message

* clippy
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent ba9dea0 commit 762c182
Show file tree
Hide file tree
Showing 92 changed files with 589 additions and 5,796 deletions.
81 changes: 10 additions & 71 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,8 @@ pub mod rialto_messages;
pub mod rialto_parachain_messages;
pub mod xcm_config;

use crate::{
rialto_messages::{ToRialtoMessagePayload, WithRialtoMessageBridge},
rialto_parachain_messages::{
ToRialtoParachainMessagePayload, WithRialtoParachainMessageBridge,
},
};

use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
use bp_runtime::{HeaderId, HeaderIdProvider};
use bridge_runtime_common::messages::{
source::estimate_message_dispatch_and_delivery_fee, MessageBridge,
};
use codec::Decode;
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
Expand All @@ -57,7 +47,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perquintill,
ApplyExtrinsicResult, FixedPointNumber, Perquintill,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -476,9 +466,6 @@ parameter_types! {
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
pub const MaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
// `IdentityFee` is used by Millau => we may use weight directly
pub const GetDeliveryConfirmationTransactionFee: Balance =
bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT.ref_time() as _;
pub const RootAccountForPayments: Option<AccountId> = None;
pub const RialtoChainId: bp_runtime::ChainId = bp_runtime::RIALTO_CHAIN_ID;
pub const RialtoParachainChainId: bp_runtime::ChainId = bp_runtime::RIALTO_PARACHAIN_CHAIN_ID;
Expand All @@ -490,17 +477,14 @@ pub type WithRialtoMessagesInstance = ();
impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<Runtime>;
type Parameter = rialto_messages::MillauToRialtoMessagesParameter;
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;

type MaximalOutboundPayloadSize = crate::rialto_messages::ToRialtoMaximalOutboundPayloadSize;
type OutboundPayload = crate::rialto_messages::ToRialtoMessagePayload;
type OutboundMessageFee = Balance;

type InboundPayload = crate::rialto_messages::FromRialtoMessagePayload;
type InboundMessageFee = bp_rialto::Balance;
type InboundRelayer = bp_rialto::AccountId;

type TargetHeaderChain = crate::rialto_messages::Rialto;
Expand All @@ -509,7 +493,6 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
pallet_bridge_relayers::MessageDeliveryAndDispatchPaymentAdapter<
Runtime,
WithRialtoMessagesInstance,
GetDeliveryConfirmationTransactionFee,
>;
type OnMessageAccepted = ();
type OnDeliveryConfirmed = ();
Expand All @@ -525,18 +508,15 @@ pub type WithRialtoParachainMessagesInstance = pallet_bridge_messages::Instance1
impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<Runtime>;
type Parameter = rialto_parachain_messages::MillauToRialtoParachainMessagesParameter;
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;

type MaximalOutboundPayloadSize =
crate::rialto_parachain_messages::ToRialtoParachainMaximalOutboundPayloadSize;
type OutboundPayload = crate::rialto_parachain_messages::ToRialtoParachainMessagePayload;
type OutboundMessageFee = Balance;

type InboundPayload = crate::rialto_parachain_messages::FromRialtoParachainMessagePayload;
type InboundMessageFee = bp_rialto_parachain::Balance;
type InboundRelayer = bp_rialto_parachain::AccountId;

type TargetHeaderChain = crate::rialto_parachain_messages::RialtoParachain;
Expand All @@ -545,7 +525,6 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
pallet_bridge_relayers::MessageDeliveryAndDispatchPaymentAdapter<
Runtime,
WithRialtoParachainMessagesInstance,
GetDeliveryConfirmationTransactionFee,
>;
type OnMessageAccepted = ();
type OnDeliveryConfirmed = ();
Expand Down Expand Up @@ -941,35 +920,23 @@ impl_runtime_apis! {
}
}

impl bp_rialto::ToRialtoOutboundLaneApi<Block, Balance, ToRialtoMessagePayload> for Runtime {
fn estimate_message_delivery_and_dispatch_fee(
_lane_id: bp_messages::LaneId,
payload: ToRialtoMessagePayload,
rialto_to_this_conversion_rate: Option<FixedU128>,
) -> Option<Balance> {
estimate_message_dispatch_and_delivery_fee::<WithRialtoMessageBridge>(
&payload,
WithRialtoMessageBridge::RELAYER_FEE_PERCENT,
rialto_to_this_conversion_rate,
).ok()
}

impl bp_rialto::ToRialtoOutboundLaneApi<Block> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
begin: bp_messages::MessageNonce,
end: bp_messages::MessageNonce,
) -> Vec<bp_messages::OutboundMessageDetails<Balance>> {
) -> Vec<bp_messages::OutboundMessageDetails> {
bridge_runtime_common::messages_api::outbound_message_details::<
Runtime,
WithRialtoMessagesInstance,
>(lane, begin, end)
}
}

impl bp_rialto::FromRialtoInboundLaneApi<Block, bp_rialto::Balance> for Runtime {
impl bp_rialto::FromRialtoInboundLaneApi<Block> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails<bp_rialto::Balance>)>,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails)>,
) -> Vec<bp_messages::InboundMessageDetails> {
bridge_runtime_common::messages_api::inbound_message_details::<
Runtime,
Expand All @@ -978,35 +945,23 @@ impl_runtime_apis! {
}
}

impl bp_rialto_parachain::ToRialtoParachainOutboundLaneApi<Block, Balance, ToRialtoParachainMessagePayload> for Runtime {
fn estimate_message_delivery_and_dispatch_fee(
_lane_id: bp_messages::LaneId,
payload: ToRialtoParachainMessagePayload,
rialto_parachain_to_this_conversion_rate: Option<FixedU128>,
) -> Option<Balance> {
estimate_message_dispatch_and_delivery_fee::<WithRialtoParachainMessageBridge>(
&payload,
WithRialtoParachainMessageBridge::RELAYER_FEE_PERCENT,
rialto_parachain_to_this_conversion_rate,
).ok()
}

impl bp_rialto_parachain::ToRialtoParachainOutboundLaneApi<Block> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
begin: bp_messages::MessageNonce,
end: bp_messages::MessageNonce,
) -> Vec<bp_messages::OutboundMessageDetails<Balance>> {
) -> Vec<bp_messages::OutboundMessageDetails> {
bridge_runtime_common::messages_api::outbound_message_details::<
Runtime,
WithRialtoParachainMessagesInstance,
>(lane, begin, end)
}
}

impl bp_rialto_parachain::FromRialtoParachainInboundLaneApi<Block, bp_rialto_parachain::Balance> for Runtime {
impl bp_rialto_parachain::FromRialtoParachainInboundLaneApi<Block> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails<bp_rialto_parachain::Balance>)>,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails)>,
) -> Vec<bp_messages::InboundMessageDetails> {
bridge_runtime_common::messages_api::inbound_message_details::<
Runtime,
Expand Down Expand Up @@ -1060,13 +1015,11 @@ impl_runtime_apis! {
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);

use bridge_runtime_common::messages_benchmarking::{prepare_message_delivery_proof, prepare_message_proof, prepare_outbound_message};
use bridge_runtime_common::messages;
use bridge_runtime_common::messages_benchmarking::{prepare_message_delivery_proof, prepare_message_proof};
use pallet_bridge_messages::benchmarking::{
Pallet as MessagesBench,
Config as MessagesConfig,
MessageDeliveryProofParams,
MessageParams,
MessageProofParams,
};
use pallet_bridge_parachains::benchmarking::{
Expand All @@ -1076,31 +1029,17 @@ impl_runtime_apis! {
use rialto_messages::WithRialtoMessageBridge;

impl MessagesConfig<WithRialtoMessagesInstance> for Runtime {
fn maximal_message_size() -> u32 {
messages::source::maximal_message_size::<WithRialtoMessageBridge>()
}

fn bridged_relayer_id() -> Self::InboundRelayer {
[0u8; 32].into()
}

fn account_balance(account: &Self::AccountId) -> Self::OutboundMessageFee {
pallet_balances::Pallet::<Runtime>::free_balance(account)
}

fn endow_account(account: &Self::AccountId) {
pallet_balances::Pallet::<Runtime>::make_free_balance_be(
account,
Balance::MAX / 100,
);
}

fn prepare_outbound_message(
params: MessageParams<Self::AccountId>,
) -> (rialto_messages::ToRialtoMessagePayload, Balance) {
(prepare_outbound_message::<WithRialtoMessageBridge>(params), Self::message_fee())
}

fn prepare_message_proof(
params: MessageProofParams,
) -> (rialto_messages::FromRialtoMessagesProof, Weight) {
Expand Down
Loading

0 comments on commit 762c182

Please sign in to comment.