Skip to content

Commit

Permalink
Remove support for encoded-call messaging from relay and runtime inte…
Browse files Browse the repository at this point in the history
…gration code (paritytech#1376)

* remove support for encoded-call messaging

* continue cleanup

* continue cleanup

* continue cleanup

* more cleanpup

* more cleanup

* fmt

* continue cleanup

* spellcheck

* rename

* fix benchmarks

* mention encoded-calls-messaging tag

* fixing deployments

* fix messages generation

* fmt
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent afa3540 commit 3affdc1
Show file tree
Hide file tree
Showing 58 changed files with 406 additions and 7,060 deletions.
5 changes: 5 additions & 0 deletions bridges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Substrate chains.

🚧 The bridges are currently under construction - a hardhat is recommended beyond this point 🚧

**IMPORTANT**: this documentation is outdated and it is mostly related to the previous version of our
bridge. Right there's an ongoing work to make our bridge work with XCM messages. Old bridge is still
available at [encoded-calls-messaging](https://github.com/paritytech/parity-bridges-common/releases/tag/encoded-calls-messaging)
tag.

## Contents

- [Installation](#installation)
Expand Down
7 changes: 0 additions & 7 deletions bridges/bin/millau/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ serde = { version = "1.0", optional = true, features = ["derive"] }
# Bridge dependencies

bp-header-chain = { path = "../../../primitives/header-chain", default-features = false }
bp-message-dispatch = { path = "../../../primitives/message-dispatch", default-features = false }
bp-messages = { path = "../../../primitives/messages", default-features = false }
bp-millau = { path = "../../../primitives/chain-millau", default-features = false }
bp-rialto = { path = "../../../primitives/chain-rialto", default-features = false }
bp-runtime = { path = "../../../primitives/runtime", default-features = false }
bp-westend = { path = "../../../primitives/chain-westend", default-features = false }
bridge-runtime-common = { path = "../../runtime-common", default-features = false }
pallet-bridge-dispatch = { path = "../../../modules/dispatch", default-features = false }
pallet-bridge-grandpa = { path = "../../../modules/grandpa", default-features = false }
pallet-bridge-messages = { path = "../../../modules/messages", default-features = false }
pallet-bridge-token-swap = { path = "../../../modules/token-swap", default-features = false }
pallet-shift-session-manager = { path = "../../../modules/shift-session-manager", default-features = false }

# Substrate Dependencies
Expand Down Expand Up @@ -77,7 +74,6 @@ default = ["std"]
std = [
"beefy-primitives/std",
"bp-header-chain/std",
"bp-message-dispatch/std",
"bp-messages/std",
"bp-millau/std",
"bp-rialto/std",
Expand All @@ -93,10 +89,8 @@ std = [
"pallet-balances/std",
"pallet-beefy/std",
"pallet-beefy-mmr/std",
"pallet-bridge-dispatch/std",
"pallet-bridge-grandpa/std",
"pallet-bridge-messages/std",
"pallet-bridge-token-swap/std",
"pallet-grandpa/std",
"pallet-mmr/std",
"pallet-randomness-collective-flip/std",
Expand Down Expand Up @@ -129,6 +123,5 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"libsecp256k1",
"pallet-bridge-messages/runtime-benchmarks",
"pallet-bridge-token-swap/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
97 changes: 4 additions & 93 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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, MultiSignature, MultiSigner, Perquintill,
ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perquintill,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -225,18 +225,6 @@ impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
}

impl pallet_bridge_dispatch::Config for Runtime {
type Event = Event;
type BridgeMessageId = (bp_messages::LaneId, bp_messages::MessageNonce);
type Call = Call;
type CallFilter = frame_support::traits::Everything;
type EncodedCall = crate::rialto_messages::FromRialtoEncodedCall;
type SourceChainAccountId = bp_rialto::AccountId;
type TargetChainAccountPublic = MultiSigner;
type TargetChainSignature = MultiSignature;
type AccountIdConverter = bp_millau::AccountIdConverter;
}

impl pallet_grandpa::Config for Runtime {
type Event = Event;
type Call = Call;
Expand Down Expand Up @@ -471,38 +459,13 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
GetDeliveryConfirmationTransactionFee,
>;
type OnMessageAccepted = ();
type OnDeliveryConfirmed =
pallet_bridge_token_swap::Pallet<Runtime, WithRialtoTokenSwapInstance>;
type OnDeliveryConfirmed = ();

type SourceHeaderChain = crate::rialto_messages::Rialto;
type MessageDispatch = crate::rialto_messages::FromRialtoMessageDispatch;
type BridgedChainId = RialtoChainId;
}

parameter_types! {
pub const TokenSwapMessagesLane: bp_messages::LaneId = *b"swap";
}

/// Instance of the with-Rialto token swap pallet.
pub type WithRialtoTokenSwapInstance = ();

impl pallet_bridge_token_swap::Config<WithRialtoTokenSwapInstance> for Runtime {
type Event = Event;
type WeightInfo = ();

type BridgedChainId = RialtoChainId;
type OutboundMessageLaneId = TokenSwapMessagesLane;
#[cfg(not(feature = "runtime-benchmarks"))]
type MessagesBridge = pallet_bridge_messages::Pallet<Runtime, WithRialtoMessagesInstance>;
#[cfg(feature = "runtime-benchmarks")]
type MessagesBridge = bp_messages::source_chain::NoopMessagesBridge;
type ThisCurrency = pallet_balances::Pallet<Runtime>;
type FromSwapToThisAccountIdConverter = bp_rialto::AccountIdConverter;

type BridgedChain = bp_rialto::Rialto;
type FromBridgedToThisAccountIdConverter = bp_millau::AccountIdConverter;
}

construct_runtime!(
pub enum Runtime where
Block = Block,
Expand Down Expand Up @@ -532,9 +495,7 @@ construct_runtime!(

// Rialto bridge modules.
BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage},
BridgeDispatch: pallet_bridge_dispatch::{Pallet, Event<T>},
BridgeRialtoMessages: pallet_bridge_messages::{Pallet, Call, Storage, Event<T>, Config<T>},
BridgeRialtoTokenSwap: pallet_bridge_token_swap::{Pallet, Call, Storage, Event<T>, Origin<T>},

// Westend bridge modules.
BridgeWestendGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Config<T>, Storage},
Expand Down Expand Up @@ -806,7 +767,6 @@ impl_runtime_apis! {

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, pallet_bridge_token_swap, BridgeRialtoTokenSwap);
list_benchmark!(list, extra, pallet_bridge_messages, MessagesBench::<Runtime, WithRialtoMessagesInstance>);
list_benchmark!(list, extra, pallet_bridge_grandpa, BridgeRialtoGrandpa);

Expand Down Expand Up @@ -878,8 +838,6 @@ impl_runtime_apis! {
) -> (rialto_messages::FromRialtoMessagesProof, Weight) {
prepare_message_proof::<Runtime, (), (), WithRialtoMessageBridge, bp_rialto::Header, bp_rialto::Hasher>(
params,
&VERSION,
Balance::MAX / 100,
)
}

Expand All @@ -891,33 +849,11 @@ impl_runtime_apis! {
)
}

fn is_message_dispatched(nonce: bp_messages::MessageNonce) -> bool {
frame_system::Pallet::<Runtime>::events()
.into_iter()
.map(|event_record| event_record.event)
.any(|event| matches!(
event,
Event::BridgeDispatch(pallet_bridge_dispatch::Event::<Runtime, _>::MessageDispatched(
_, ([0, 0, 0, 0], nonce_from_event), _,
)) if nonce_from_event == nonce
))
fn is_message_dispatched(_nonce: bp_messages::MessageNonce) -> bool {
true
}
}

use pallet_bridge_token_swap::benchmarking::Config as TokenSwapConfig;

impl TokenSwapConfig<WithRialtoTokenSwapInstance> for Runtime {
fn initialize_environment() {
let relayers_fund_account = pallet_bridge_messages::relayer_fund_account_id::<
bp_millau::AccountId,
bp_millau::AccountIdConverter,
>();
pallet_balances::Pallet::<Runtime>::make_free_balance_be(
&relayers_fund_account,
Balance::MAX / 100,
);
}
}

add_benchmark!(
params,
Expand All @@ -926,37 +862,12 @@ impl_runtime_apis! {
MessagesBench::<Runtime, WithRialtoMessagesInstance>
);
add_benchmark!(params, batches, pallet_bridge_grandpa, BridgeRialtoGrandpa);
add_benchmark!(params, batches, pallet_bridge_token_swap, BridgeRialtoTokenSwap);

Ok(batches)
}
}
}

/// Rialto account ownership digest from Millau.
///
/// The byte vector returned by this function should be signed with a Rialto account private key.
/// This way, the owner of `millau_account_id` on Millau proves that the Rialto account private key
/// is also under his control.
pub fn millau_to_rialto_account_ownership_digest<Call, AccountId, SpecVersion>(
rialto_call: &Call,
millau_account_id: AccountId,
rialto_spec_version: SpecVersion,
) -> sp_std::vec::Vec<u8>
where
Call: codec::Encode,
AccountId: codec::Encode,
SpecVersion: codec::Encode,
{
pallet_bridge_dispatch::account_ownership_digest(
rialto_call,
millau_account_id,
rialto_spec_version,
bp_runtime::MILLAU_CHAIN_ID,
bp_runtime::RIALTO_CHAIN_ID,
)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
46 changes: 6 additions & 40 deletions bridges/bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use frame_support::{
};
use scale_info::TypeInfo;
use sp_runtime::{traits::Saturating, FixedPointNumber, FixedU128};
use sp_std::{convert::TryFrom, ops::RangeInclusive};
use sp_std::convert::TryFrom;

/// Initial value of `RialtoToMillauConversionRate` parameter.
pub const INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE: FixedU128 =
Expand All @@ -49,19 +49,14 @@ parameter_types! {
}

/// Message payload for Millau -> Rialto messages.
pub type ToRialtoMessagePayload =
messages::source::FromThisChainMessagePayload<WithRialtoMessageBridge>;
pub type ToRialtoMessagePayload = messages::source::FromThisChainMessagePayload;

/// Message verifier for Millau -> Rialto messages.
pub type ToRialtoMessageVerifier =
messages::source::FromThisChainMessageVerifier<WithRialtoMessageBridge>;

/// Message payload for Rialto -> Millau messages.
pub type FromRialtoMessagePayload =
messages::target::FromBridgedChainMessagePayload<WithRialtoMessageBridge>;

/// Encoded Millau Call as it comes from Rialto.
pub type FromRialtoEncodedCall = messages::target::FromBridgedChainEncodedMessageCall<crate::Call>;
pub type FromRialtoMessagePayload = messages::target::FromBridgedChainMessagePayload;

/// Messages proof for Rialto -> Millau messages.
pub type FromRialtoMessagesProof = messages::target::FromBridgedChainMessagesProof<bp_rialto::Hash>;
Expand Down Expand Up @@ -120,19 +115,7 @@ impl messages::ThisChainWithMessages for Millau {
type Call = crate::Call;

fn is_message_accepted(send_origin: &Self::Origin, lane: &LaneId) -> bool {
// lanes 0x00000000 && 0x00000001 are accepting any paid messages, while
// `TokenSwapMessageLane` only accepts messages from token swap pallet
let token_swap_dedicated_lane = crate::TokenSwapMessagesLane::get();
match *lane {
[0, 0, 0, 0] | [0, 0, 0, 1] => send_origin.linked_account().is_some(),
_ if *lane == token_swap_dedicated_lane => matches!(
send_origin.caller,
crate::OriginCaller::BridgeRialtoTokenSwap(
pallet_bridge_token_swap::RawOrigin::TokenSwap { .. }
)
),
_ => false,
}
(*lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1]) && send_origin.linked_account().is_some()
}

fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
Expand Down Expand Up @@ -189,19 +172,8 @@ impl messages::BridgedChainWithMessages for Rialto {
bp_rialto::Rialto::max_extrinsic_size()
}

fn message_weight_limits(_message_payload: &[u8]) -> RangeInclusive<Weight> {
// we don't want to relay too large messages + keep reserve for future upgrades
let upper_limit = messages::target::maximal_incoming_message_dispatch_weight(
bp_rialto::Rialto::max_extrinsic_weight(),
);

// we're charging for payload bytes in `WithRialtoMessageBridge::transaction_payment`
// function
//
// this bridge may be used to deliver all kind of messages, so we're not making any
// assumptions about minimal dispatch weight here

0..=upper_limit
fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
true
}

fn estimate_delivery_transaction(
Expand Down Expand Up @@ -296,12 +268,6 @@ impl SenderOrigin<crate::AccountId> for crate::Origin {
crate::OriginCaller::system(frame_system::RawOrigin::Root) |
crate::OriginCaller::system(frame_system::RawOrigin::None) =>
crate::RootAccountForPayments::get(),
crate::OriginCaller::BridgeRialtoTokenSwap(
pallet_bridge_token_swap::RawOrigin::TokenSwap {
ref swap_account_at_this_chain,
..
},
) => Some(swap_account_at_this_chain.clone()),
_ => None,
}
}
Expand Down
4 changes: 0 additions & 4 deletions bridges/bin/rialto/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ serde = { version = "1.0", optional = true, features = ["derive"] }
# Bridge dependencies

bp-header-chain = { path = "../../../primitives/header-chain", default-features = false }
bp-message-dispatch = { path = "../../../primitives/message-dispatch", default-features = false }
bp-messages = { path = "../../../primitives/messages", default-features = false }
bp-millau = { path = "../../../primitives/chain-millau", default-features = false }
bp-rialto = { path = "../../../primitives/chain-rialto", default-features = false }
bp-runtime = { path = "../../../primitives/runtime", default-features = false }
bridge-runtime-common = { path = "../../runtime-common", default-features = false }
pallet-bridge-dispatch = { path = "../../../modules/dispatch", default-features = false }
pallet-bridge-grandpa = { path = "../../../modules/grandpa", default-features = false }
pallet-bridge-messages = { path = "../../../modules/messages", default-features = false }
pallet-shift-session-manager = { path = "../../../modules/shift-session-manager", default-features = false }
Expand Down Expand Up @@ -85,7 +83,6 @@ default = ["std"]
std = [
"beefy-primitives/std",
"bp-header-chain/std",
"bp-message-dispatch/std",
"bp-messages/std",
"bp-millau/std",
"bp-rialto/std",
Expand All @@ -103,7 +100,6 @@ std = [
"pallet-balances/std",
"pallet-beefy/std",
"pallet-beefy-mmr/std",
"pallet-bridge-dispatch/std",
"pallet-bridge-grandpa/std",
"pallet-bridge-messages/std",
"pallet-grandpa/std",
Expand Down
Loading

0 comments on commit 3affdc1

Please sign in to comment.