Skip to content

Commit a6799c0

Browse files
svyatonikbkontur
authored andcommitted
Moving messages code to pallet (#2180)
* moved files around * and fix compilation Move Chain::ID from relay-level Chain to primitives-level Chain (#2181) * move Chain::ID from relay-level Chain to primitives-level Chain * removed chain IDs from bp-runtime * add missing file header Adjust weights (#2185) fix clippy (#2186) Remove source header chain (#2183) * moved messages proof verification to messages pallet * removed SourceHeaderChain * cleanup * benchmarks compilation * fix benchmark tests compilation * clippy * fmt Use compact proofs for messages delivery confirmation (#2187) * Use compact proofs for messages delivery confirmation * Fix benchmarks Move messages delivery proof verification to pallet (#2189) * rename messages_proof.rs to proofs.rs * moved delivery proof verification to the messages pallet * removed TargetHeaderChain * cleaning up * fixed benchmarks compilation * Update modules/messages/README.md Co-authored-by: Adrian Catangiu <[email protected]> * uncommented test and removed printlns * vec![].into_iter().collect() -> vec![].into() --------- Co-authored-by: Adrian Catangiu <[email protected]> removed MaxUnrewardedRelayerEntriesAtInboundLane and MaxUnconfirmedMessagesAtInboundLane from messages pallet config (#2190) * removed MaxUnrewardedRelayerEntriesAtInboundLane and MaxUnconfirmedMessagesAtInboundLane from messages pallet config * fixed doc * fixed benchmarking code * more fixes remove MaximalOutboundPayloadSize and use BridgedChain::maximal_incomging_message_size instead (#2191) remove MessageBridge trait (#2192)
1 parent 57368d5 commit a6799c0

33 files changed

+3636
-2775
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridges/bin/runtime-common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ xcm-builder = { package = "staging-xcm-builder", path = "../../../polkadot/xcm/x
5353
[dev-dependencies]
5454
bp-test-utils = { path = "../../primitives/test-utils" }
5555
pallet-balances = { path = "../../../substrate/frame/balances" }
56+
pallet-bridge-messages = { path = "../../modules/messages", features = ["std", "test-helpers"] }
5657

5758
[features]
5859
default = ["std"]
@@ -93,6 +94,7 @@ runtime-benchmarks = [
9394
"pallet-balances/runtime-benchmarks",
9495
"pallet-bridge-grandpa/runtime-benchmarks",
9596
"pallet-bridge-messages/runtime-benchmarks",
97+
"pallet-bridge-messages/test-helpers",
9698
"pallet-bridge-parachains/runtime-benchmarks",
9799
"pallet-bridge-relayers/runtime-benchmarks",
98100
"pallet-utility/runtime-benchmarks",

bridges/bin/runtime-common/src/extensions/priority_calculator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ mod integrity_tests {
319319
pub mod per_message {
320320
use super::*;
321321

322+
use bp_messages::ChainWithMessages;
322323
use pallet_bridge_messages::WeightInfoExt;
323324

324325
/// Ensures that the value of `PriorityBoostPerMessage` matches the value of
@@ -339,7 +340,7 @@ mod integrity_tests {
339340
BalanceOf<Runtime>: Send + Sync + FixedPointOperand,
340341
{
341342
let maximal_messages_in_delivery_transaction =
342-
Runtime::MaxUnconfirmedMessagesAtInboundLane::get();
343+
Runtime::BridgedChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
343344
super::ensure_priority_boost_is_sane::<PriorityBoostPerMessage, BalanceOf<Runtime>>(
344345
"PriorityBoostPerMessage",
345346
maximal_messages_in_delivery_transaction,

bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
use crate::messages_call_ext::{
2323
CallHelper as MessagesCallHelper, CallInfo as MessagesCallInfo, MessagesCallSubType,
2424
};
25-
use bp_messages::{LaneId, MessageNonce};
25+
use bp_messages::{ChainWithMessages, LaneId, MessageNonce};
2626
use bp_relayers::{ExplicitOrAccountParams, RewardsAccountOwner, RewardsAccountParams};
27-
use bp_runtime::{Parachain, RangeInclusiveExt, StaticStrProvider};
27+
use bp_runtime::{Chain, Parachain, RangeInclusiveExt, StaticStrProvider};
2828
use codec::{Codec, Decode, Encode};
2929
use frame_support::{
3030
dispatch::{CallableCallFor, DispatchInfo, PostDispatchInfo},
@@ -293,7 +293,7 @@ pub trait RefundSignedExtension:
293293
<Self::Msgs as RefundableMessagesLaneId>::Id::get(),
294294
<Self::Runtime as MessagesConfig<
295295
<Self::Msgs as RefundableMessagesLaneId>::Instance,
296-
>>::BridgedChainId::get(),
296+
>>::BridgedChain::ID,
297297
if call_info.is_receive_messages_proof_call() {
298298
RewardsAccountOwner::ThisChain
299299
} else {
@@ -406,8 +406,7 @@ pub trait RefundSignedExtension:
406406
// a quick check to avoid invalid high-priority transactions
407407
let max_unconfirmed_messages_in_confirmation_tx = <Self::Runtime as MessagesConfig<
408408
<Self::Msgs as RefundableMessagesLaneId>::Instance,
409-
>>::MaxUnconfirmedMessagesAtInboundLane::get(
410-
);
409+
>>::BridgedChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
411410
if bundled_messages > max_unconfirmed_messages_in_confirmation_tx {
412411
return None
413412
}
@@ -1163,7 +1162,7 @@ pub(crate) mod tests {
11631162
RuntimeCall::BridgeMessages(MessagesCall::receive_messages_delivery_proof {
11641163
proof: FromBridgedChainMessagesDeliveryProof {
11651164
bridged_header_hash: Default::default(),
1166-
storage_proof: vec![],
1165+
storage_proof: Default::default(),
11671166
lane: TestLaneId::get(),
11681167
},
11691168
relayers_state: UnrewardedRelayersState {
@@ -1326,8 +1325,10 @@ pub(crate) mod tests {
13261325
best_stored_nonce: 100,
13271326
},
13281327
unrewarded_relayers: UnrewardedRelayerOccupation {
1329-
free_relayer_slots: MaxUnrewardedRelayerEntriesAtInboundLane::get(),
1330-
free_message_slots: MaxUnconfirmedMessagesAtInboundLane::get(),
1328+
free_relayer_slots:
1329+
BridgedUnderlyingChain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
1330+
free_message_slots:
1331+
BridgedUnderlyingChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
13311332
},
13321333
}),
13331334
),
@@ -1396,8 +1397,10 @@ pub(crate) mod tests {
13961397
best_stored_nonce: 100,
13971398
},
13981399
unrewarded_relayers: UnrewardedRelayerOccupation {
1399-
free_relayer_slots: MaxUnrewardedRelayerEntriesAtInboundLane::get(),
1400-
free_message_slots: MaxUnconfirmedMessagesAtInboundLane::get(),
1400+
free_relayer_slots:
1401+
BridgedUnderlyingChain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
1402+
free_message_slots:
1403+
BridgedUnderlyingChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
14011404
},
14021405
}),
14031406
),
@@ -1458,8 +1461,10 @@ pub(crate) mod tests {
14581461
best_stored_nonce: 100,
14591462
},
14601463
unrewarded_relayers: UnrewardedRelayerOccupation {
1461-
free_relayer_slots: MaxUnrewardedRelayerEntriesAtInboundLane::get(),
1462-
free_message_slots: MaxUnconfirmedMessagesAtInboundLane::get(),
1464+
free_relayer_slots:
1465+
BridgedUnderlyingChain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
1466+
free_message_slots:
1467+
BridgedUnderlyingChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
14631468
},
14641469
}),
14651470
),
@@ -1498,8 +1503,10 @@ pub(crate) mod tests {
14981503
best_stored_nonce: 100,
14991504
},
15001505
unrewarded_relayers: UnrewardedRelayerOccupation {
1501-
free_relayer_slots: MaxUnrewardedRelayerEntriesAtInboundLane::get(),
1502-
free_message_slots: MaxUnconfirmedMessagesAtInboundLane::get(),
1506+
free_relayer_slots:
1507+
BridgedUnderlyingChain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
1508+
free_message_slots:
1509+
BridgedUnderlyingChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
15031510
},
15041511
},
15051512
)),
@@ -1734,14 +1741,16 @@ pub(crate) mod tests {
17341741

17351742
let fns = [run_validate, run_grandpa_validate, run_messages_validate];
17361743
for f in fns {
1737-
let priority_of_max_messages_delivery =
1738-
f(message_delivery_call(100 + MaxUnconfirmedMessagesAtInboundLane::get()))
1739-
.unwrap()
1740-
.priority;
1741-
let priority_of_more_than_max_messages_delivery =
1742-
f(message_delivery_call(100 + MaxUnconfirmedMessagesAtInboundLane::get() + 1))
1743-
.unwrap()
1744-
.priority;
1744+
let priority_of_max_messages_delivery = f(message_delivery_call(
1745+
100 + BridgedUnderlyingChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
1746+
))
1747+
.unwrap()
1748+
.priority;
1749+
let priority_of_more_than_max_messages_delivery = f(message_delivery_call(
1750+
100 + BridgedUnderlyingChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX + 1,
1751+
))
1752+
.unwrap()
1753+
.priority;
17451754

17461755
assert!(
17471756
priority_of_max_messages_delivery > priority_of_more_than_max_messages_delivery,
@@ -2864,7 +2873,8 @@ pub(crate) mod tests {
28642873
#[test]
28652874
fn does_not_panic_on_boosting_priority_of_empty_message_delivery_transaction() {
28662875
run_test(|| {
2867-
let best_delivered_message = MaxUnconfirmedMessagesAtInboundLane::get();
2876+
let best_delivered_message =
2877+
BridgedUnderlyingChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
28682878
initialize_environment(100, 100, best_delivered_message);
28692879

28702880
// register relayer so it gets priority boost

bridges/bin/runtime-common/src/integrity.rs

Lines changed: 15 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
//! Most of the tests in this module assume that the bridge is using standard (see `crate::messages`
2020
//! module for details) configuration.
2121
22-
use crate::{messages, messages::MessageBridge};
23-
24-
use bp_messages::{InboundLaneData, MessageNonce};
25-
use bp_runtime::{Chain, ChainId};
22+
use bp_messages::{ChainWithMessages, InboundLaneData, MessageNonce};
2623
use codec::Encode;
2724
use frame_support::{storage::generator::StorageValue, traits::Get, weights::Weight};
2825
use frame_system::limits;
@@ -50,56 +47,32 @@ macro_rules! assert_chain_types(
5047
}
5148
);
5249

53-
/// Macro that ensures that the bridge GRANDPA pallet is configured properly to bridge with given
54-
/// chain.
55-
#[macro_export]
56-
macro_rules! assert_bridge_grandpa_pallet_types(
57-
( runtime: $r:path, with_bridged_chain_grandpa_instance: $i:path, bridged_chain: $bridged:path ) => {
58-
{
59-
// if one of asserts fail, then either bridge isn't configured properly (or alternatively - non-standard
60-
// configuration is used), or something has broke existing configuration (meaning that all bridged chains
61-
// and relays will stop functioning)
62-
use pallet_bridge_grandpa::Config as GrandpaConfig;
63-
use static_assertions::assert_type_eq_all;
64-
65-
assert_type_eq_all!(<$r as GrandpaConfig<$i>>::BridgedChain, $bridged);
66-
}
67-
}
68-
);
69-
7050
/// Macro that ensures that the bridge messages pallet is configured properly to bridge using given
7151
/// configuration.
7252
#[macro_export]
7353
macro_rules! assert_bridge_messages_pallet_types(
7454
(
7555
runtime: $r:path,
7656
with_bridged_chain_messages_instance: $i:path,
77-
bridge: $bridge:path
7857
) => {
7958
{
8059
// if one of asserts fail, then either bridge isn't configured properly (or alternatively - non-standard
8160
// configuration is used), or something has broke existing configuration (meaning that all bridged chains
8261
// and relays will stop functioning)
83-
use $crate::messages::{
84-
source::{FromThisChainMessagePayload, TargetHeaderChainAdapter},
85-
target::{FromBridgedChainMessagePayload, SourceHeaderChainAdapter},
86-
AccountIdOf, BalanceOf, BridgedChain, ThisChain,
87-
};
62+
use $crate::messages_xcm_extension::XcmAsPlainPayload;
8863
use pallet_bridge_messages::Config as MessagesConfig;
8964
use static_assertions::assert_type_eq_all;
9065

91-
assert_type_eq_all!(<$r as MessagesConfig<$i>>::OutboundPayload, FromThisChainMessagePayload);
66+
assert_type_eq_all!(<$r as MessagesConfig<$i>>::OutboundPayload, XcmAsPlainPayload);
9267

93-
assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundRelayer, AccountIdOf<BridgedChain<$bridge>>);
94-
95-
assert_type_eq_all!(<$r as MessagesConfig<$i>>::TargetHeaderChain, TargetHeaderChainAdapter<$bridge>);
96-
assert_type_eq_all!(<$r as MessagesConfig<$i>>::SourceHeaderChain, SourceHeaderChainAdapter<$bridge>);
68+
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1666: check ThisChain, BridgedChain
69+
// and BridgedHeaderChain types
9770
}
9871
}
9972
);
10073

10174
/// Macro that combines four other macro calls - `assert_chain_types`, `assert_bridge_types`,
102-
/// `assert_bridge_grandpa_pallet_types` and `assert_bridge_messages_pallet_types`. It may be used
75+
/// and `assert_bridge_messages_pallet_types`. It may be used
10376
/// at the chain that is implementing complete standard messages bridge (i.e. with bridge GRANDPA
10477
/// and messages pallets deployed).
10578
#[macro_export]
@@ -108,20 +81,13 @@ macro_rules! assert_complete_bridge_types(
10881
runtime: $r:path,
10982
with_bridged_chain_grandpa_instance: $gi:path,
11083
with_bridged_chain_messages_instance: $mi:path,
111-
bridge: $bridge:path,
11284
this_chain: $this:path,
11385
bridged_chain: $bridged:path,
11486
) => {
11587
$crate::assert_chain_types!(runtime: $r, this_chain: $this);
116-
$crate::assert_bridge_grandpa_pallet_types!(
117-
runtime: $r,
118-
with_bridged_chain_grandpa_instance: $gi,
119-
bridged_chain: $bridged
120-
);
12188
$crate::assert_bridge_messages_pallet_types!(
12289
runtime: $r,
12390
with_bridged_chain_messages_instance: $mi,
124-
bridge: $bridge
12591
);
12692
}
12793
);
@@ -184,20 +150,8 @@ where
184150
);
185151
}
186152

187-
/// Parameters for asserting messages pallet constants.
188-
#[derive(Debug)]
189-
pub struct AssertBridgeMessagesPalletConstants {
190-
/// Maximal number of unrewarded relayer entries in a confirmation transaction at the bridged
191-
/// chain.
192-
pub max_unrewarded_relayers_in_bridged_confirmation_tx: MessageNonce,
193-
/// Maximal number of unconfirmed messages in a confirmation transaction at the bridged chain.
194-
pub max_unconfirmed_messages_in_bridged_confirmation_tx: MessageNonce,
195-
/// Identifier of the bridged chain.
196-
pub bridged_chain_id: ChainId,
197-
}
198-
199153
/// Test that the constants, used in messages pallet configuration are valid.
200-
pub fn assert_bridge_messages_pallet_constants<R, MI>(params: AssertBridgeMessagesPalletConstants)
154+
pub fn assert_bridge_messages_pallet_constants<R, MI>()
201155
where
202156
R: pallet_bridge_messages::Config<MI>,
203157
MI: 'static,
@@ -207,19 +161,6 @@ where
207161
"ActiveOutboundLanes ({:?}) must not be empty",
208162
R::ActiveOutboundLanes::get(),
209163
);
210-
assert!(
211-
R::MaxUnrewardedRelayerEntriesAtInboundLane::get() <= params.max_unrewarded_relayers_in_bridged_confirmation_tx,
212-
"MaxUnrewardedRelayerEntriesAtInboundLane ({}) must be <= than the hardcoded value for bridged chain: {}",
213-
R::MaxUnrewardedRelayerEntriesAtInboundLane::get(),
214-
params.max_unrewarded_relayers_in_bridged_confirmation_tx,
215-
);
216-
assert!(
217-
R::MaxUnconfirmedMessagesAtInboundLane::get() <= params.max_unconfirmed_messages_in_bridged_confirmation_tx,
218-
"MaxUnrewardedRelayerEntriesAtInboundLane ({}) must be <= than the hardcoded value for bridged chain: {}",
219-
R::MaxUnconfirmedMessagesAtInboundLane::get(),
220-
params.max_unconfirmed_messages_in_bridged_confirmation_tx,
221-
);
222-
assert_eq!(R::BridgedChainId::get(), params.bridged_chain_id);
223164
}
224165

225166
/// Parameters for asserting bridge pallet names.
@@ -238,14 +179,12 @@ pub struct AssertBridgePalletNames<'a> {
238179

239180
/// Tests that bridge pallet names used in `construct_runtime!()` macro call are matching constants
240181
/// from chain primitives crates.
241-
pub fn assert_bridge_pallet_names<B, R, GI, MI>(params: AssertBridgePalletNames)
182+
pub fn assert_bridge_pallet_names<R, GI, MI>(params: AssertBridgePalletNames)
242183
where
243-
B: MessageBridge,
244184
R: pallet_bridge_grandpa::Config<GI> + pallet_bridge_messages::Config<MI>,
245185
GI: 'static,
246186
MI: 'static,
247187
{
248-
assert_eq!(B::BRIDGED_MESSAGES_PALLET_NAME, params.with_this_chain_messages_pallet_name);
249188
assert_eq!(
250189
pallet_bridge_grandpa::PalletOwner::<R, GI>::storage_value_final_key().to_vec(),
251190
bp_runtime::storage_value_key(params.with_bridged_chain_grandpa_pallet_name, "PalletOwner",).0,
@@ -265,32 +204,29 @@ where
265204
pub struct AssertCompleteBridgeConstants<'a> {
266205
/// Parameters to assert this chain constants.
267206
pub this_chain_constants: AssertChainConstants,
268-
/// Parameters to assert messages pallet constants.
269-
pub messages_pallet_constants: AssertBridgeMessagesPalletConstants,
270207
/// Parameters to assert pallet names constants.
271208
pub pallet_names: AssertBridgePalletNames<'a>,
272209
}
273210

274211
/// All bridge-related constants tests for the complete standard messages bridge (i.e. with bridge
275212
/// GRANDPA and messages pallets deployed).
276-
pub fn assert_complete_bridge_constants<R, GI, MI, B>(params: AssertCompleteBridgeConstants)
213+
pub fn assert_complete_bridge_constants<R, GI, MI>(params: AssertCompleteBridgeConstants)
277214
where
278215
R: frame_system::Config
279216
+ pallet_bridge_grandpa::Config<GI>
280217
+ pallet_bridge_messages::Config<MI>,
281218
GI: 'static,
282219
MI: 'static,
283-
B: MessageBridge,
284220
{
285221
assert_chain_constants::<R>(params.this_chain_constants);
286222
assert_bridge_grandpa_pallet_constants::<R, GI>();
287-
assert_bridge_messages_pallet_constants::<R, MI>(params.messages_pallet_constants);
288-
assert_bridge_pallet_names::<B, R, GI, MI>(params.pallet_names);
223+
assert_bridge_messages_pallet_constants::<R, MI>();
224+
assert_bridge_pallet_names::<R, GI, MI>(params.pallet_names);
289225
}
290226

291227
/// Check that the message lane weights are correct.
292228
pub fn check_message_lane_weights<
293-
C: Chain,
229+
C: ChainWithMessages,
294230
T: frame_system::Config + pallet_bridge_messages::Config<MessagesPalletInstance>,
295231
MessagesPalletInstance: 'static,
296232
>(
@@ -309,13 +245,13 @@ pub fn check_message_lane_weights<
309245
pallet_bridge_messages::ensure_weights_are_correct::<Weights<T, MessagesPalletInstance>>();
310246

311247
// check that weights allow us to receive messages
312-
let max_incoming_message_proof_size = bridged_chain_extra_storage_proof_size
313-
.saturating_add(messages::target::maximal_incoming_message_size(C::max_extrinsic_size()));
248+
let max_incoming_message_proof_size =
249+
bridged_chain_extra_storage_proof_size.saturating_add(C::maximal_incoming_message_size());
314250
pallet_bridge_messages::ensure_able_to_receive_message::<Weights<T, MessagesPalletInstance>>(
315251
C::max_extrinsic_size(),
316252
C::max_extrinsic_weight(),
317253
max_incoming_message_proof_size,
318-
messages::target::maximal_incoming_message_dispatch_weight(C::max_extrinsic_weight()),
254+
C::maximal_incoming_message_dispatch_weight(),
319255
);
320256

321257
// check that weights allow us to receive delivery confirmations

0 commit comments

Comments
 (0)