Skip to content

Commit 8c6dfc4

Browse files
svyatonikbkchr
authored andcommitted
get rid of LaneMessageVerifier (#2168) (#2764)
1 parent 1dbfab8 commit 8c6dfc4

File tree

6 files changed

+15
-149
lines changed

6 files changed

+15
-149
lines changed

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

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub use bp_runtime::{RangeInclusiveExt, UnderlyingChainOf, UnderlyingChainProvid
2424

2525
use bp_header_chain::HeaderChain;
2626
use bp_messages::{
27-
source_chain::{LaneMessageVerifier, TargetHeaderChain},
27+
source_chain::TargetHeaderChain,
2828
target_chain::{ProvedLaneMessages, ProvedMessages, SourceHeaderChain},
2929
InboundLaneData, LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData,
3030
VerificationError,
@@ -120,42 +120,6 @@ pub mod source {
120120
pub type ParsedMessagesDeliveryProofFromBridgedChain<B> =
121121
(LaneId, InboundLaneData<AccountIdOf<ThisChain<B>>>);
122122

123-
/// Message verifier that is doing all basic checks.
124-
///
125-
/// This verifier assumes following:
126-
///
127-
/// - all message lanes are equivalent, so all checks are the same;
128-
///
129-
/// Following checks are made:
130-
///
131-
/// - message is rejected if its lane is currently blocked;
132-
/// - message is rejected if there are too many pending (undelivered) messages at the outbound
133-
/// lane;
134-
/// - check that the sender has rights to dispatch the call on target chain using provided
135-
/// dispatch origin;
136-
/// - check that the sender has paid enough funds for both message delivery and dispatch.
137-
#[derive(RuntimeDebug)]
138-
pub struct FromThisChainMessageVerifier<B>(PhantomData<B>);
139-
140-
impl<B> LaneMessageVerifier<FromThisChainMessagePayload> for FromThisChainMessageVerifier<B>
141-
where
142-
B: MessageBridge,
143-
{
144-
fn verify_message(
145-
_lane: &LaneId,
146-
_lane_outbound_data: &OutboundLaneData,
147-
_payload: &FromThisChainMessagePayload,
148-
) -> Result<(), VerificationError> {
149-
// IMPORTANT: any error that is returned here is fatal for the bridge, because
150-
// this code is executed at the bridge hub and message sender actually lives
151-
// at some sibling parachain. So we are failing **after** the message has been
152-
// sent and we can't report it back to sender (unless error report mechanism is
153-
// embedded into message and its dispatcher).
154-
155-
Ok(())
156-
}
157-
}
158-
159123
/// Return maximal message size of This -> Bridged chain message.
160124
pub fn maximal_message_size<B: MessageBridge>() -> u32 {
161125
super::target::maximal_incoming_message_size(
@@ -185,8 +149,7 @@ pub mod source {
185149
/// Do basic Bridged-chain specific verification of This -> Bridged chain message.
186150
///
187151
/// Ok result from this function means that the delivery transaction with this message
188-
/// may be 'mined' by the target chain. But the lane may have its own checks (e.g. fee
189-
/// check) that would reject message (see `FromThisChainMessageVerifier`).
152+
/// may be 'mined' by the target chain.
190153
pub fn verify_chain_message<B: MessageBridge>(
191154
payload: &FromThisChainMessagePayload,
192155
) -> Result<(), VerificationError> {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use crate::messages::{
2222
source::{
2323
FromThisChainMaximalOutboundPayloadSize, FromThisChainMessagePayload,
24-
FromThisChainMessageVerifier, TargetHeaderChainAdapter,
24+
TargetHeaderChainAdapter,
2525
},
2626
target::{FromBridgedChainMessagePayload, SourceHeaderChainAdapter},
2727
BridgedChainWithMessages, HashOf, MessageBridge, ThisChainWithMessages,
@@ -213,7 +213,6 @@ impl pallet_bridge_messages::Config for TestRuntime {
213213
type DeliveryPayments = ();
214214

215215
type TargetHeaderChain = TargetHeaderChainAdapter<OnThisChainBridge>;
216-
type LaneMessageVerifier = FromThisChainMessageVerifier<OnThisChainBridge>;
217216
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
218217
TestRuntime,
219218
(),

bridges/modules/messages/README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,12 @@ maximal possible transaction size of the chain and so on. And when the relayer s
116116
implementation must be able to parse and verify the proof of messages delivery. Normally, you would reuse the same
117117
(configurable) type on all chains that are sending messages to the same bridged chain.
118118

119-
The `pallet_bridge_messages::Config::LaneMessageVerifier` defines a single callback to verify outbound messages. The
120-
simplest callback may just accept all messages. But in this case you'll need to answer many questions first. Who will
121-
pay for the delivery and confirmation transaction? Are we sure that someone will ever deliver this message to the
122-
bridged chain? Are we sure that we don't bloat our runtime storage by accepting this message? What if the message is
123-
improperly encoded or has some fields set to invalid values? Answering all those (and similar) questions would lead to
124-
correct implementation.
125-
126-
There's another thing to consider when implementing type for use in
127-
`pallet_bridge_messages::Config::LaneMessageVerifier`. It is whether we treat all message lanes identically, or they'll
128-
have different sets of verification rules? For example, you may reserve lane#1 for messages coming from some
129-
'wrapped-token' pallet - then you may verify in your implementation that the origin is associated with this pallet.
130-
Lane#2 may be reserved for 'system' messages and you may charge zero fee for such messages. You may have some rate
131-
limiting for messages sent over the lane#3. Or you may just verify the same rules set for all outbound messages - it is
132-
all up to the `pallet_bridge_messages::Config::LaneMessageVerifier` implementation.
133-
134-
The last type is the `pallet_bridge_messages::Config::DeliveryConfirmationPayments`. When confirmation transaction is
135-
received, we call the `pay_reward()` method, passing the range of delivered messages. You may use the
136-
[`pallet-bridge-relayers`](../relayers/) pallet and its
137-
[`DeliveryConfirmationPaymentsAdapter`](../relayers/src/payment_adapter.rs) adapter as a possible implementation. It
138-
allows you to pay fixed reward for relaying the message and some of its portion for confirming delivery.
119+
The last type is the `pallet_bridge_messages::Config::DeliveryConfirmationPayments`. When confirmation
120+
transaction is received, we call the `pay_reward()` method, passing the range of delivered messages.
121+
You may use the [`pallet-bridge-relayers`](../relayers/) pallet and its
122+
[`DeliveryConfirmationPaymentsAdapter`](../relayers/src/payment_adapter.rs) adapter as a possible
123+
implementation. It allows you to pay fixed reward for relaying the message and some of its portion
124+
for confirming delivery.
139125

140126
### I have a Messages Module in my Runtime, but I Want to Reject all Outbound Messages. What shall I do?
141127

bridges/modules/messages/src/lib.rs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ use crate::{
5353

5454
use bp_messages::{
5555
source_chain::{
56-
DeliveryConfirmationPayments, LaneMessageVerifier, OnMessagesDelivered,
57-
SendMessageArtifacts, TargetHeaderChain,
56+
DeliveryConfirmationPayments, OnMessagesDelivered, SendMessageArtifacts, TargetHeaderChain,
5857
},
5958
target_chain::{
6059
DeliveryPayments, DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages,
@@ -155,8 +154,6 @@ pub mod pallet {
155154

156155
/// Target header chain.
157156
type TargetHeaderChain: TargetHeaderChain<Self::OutboundPayload, Self::AccountId>;
158-
/// Message payload verifier.
159-
type LaneMessageVerifier: LaneMessageVerifier<Self::OutboundPayload>;
160157
/// Delivery confirmation payments.
161158
type DeliveryConfirmationPayments: DeliveryConfirmationPayments<Self::AccountId>;
162159
/// Delivery confirmation callback.
@@ -723,20 +720,8 @@ fn send_message<T: Config<I>, I: 'static>(
723720
Error::<T, I>::MessageRejectedByChainVerifier(err)
724721
})?;
725722

726-
// now let's enforce any additional lane rules
727-
let mut lane = outbound_lane::<T, I>(lane_id);
728-
T::LaneMessageVerifier::verify_message(&lane_id, &lane.data(), &payload).map_err(|err| {
729-
log::trace!(
730-
target: LOG_TARGET,
731-
"Message to lane {:?} is rejected by lane verifier: {:?}",
732-
lane_id,
733-
err,
734-
);
735-
736-
Error::<T, I>::MessageRejectedByLaneVerifier(err)
737-
})?;
738-
739723
// finally, save message in outbound storage and emit event
724+
let mut lane = outbound_lane::<T, I>(lane_id);
740725
let encoded_payload = payload.encode();
741726
let encoded_payload_len = encoded_payload.len();
742727
let nonce = lane
@@ -1151,21 +1136,6 @@ mod tests {
11511136
});
11521137
}
11531138

1154-
#[test]
1155-
fn lane_verifier_rejects_invalid_message_in_send_message() {
1156-
run_test(|| {
1157-
// messages with zero fee are rejected by lane verifier
1158-
let mut message = REGULAR_PAYLOAD;
1159-
message.reject_by_lane_verifier = true;
1160-
assert_noop!(
1161-
send_message::<TestRuntime, ()>(TEST_LANE_ID, message,),
1162-
Error::<TestRuntime, ()>::MessageRejectedByLaneVerifier(VerificationError::Other(
1163-
mock::TEST_ERROR
1164-
)),
1165-
);
1166-
});
1167-
}
1168-
11691139
#[test]
11701140
fn receive_messages_proof_works() {
11711141
run_test(|| {

bridges/modules/messages/src/mock.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ use crate::Config;
2121

2222
use bp_messages::{
2323
calc_relayers_rewards,
24-
source_chain::{
25-
DeliveryConfirmationPayments, LaneMessageVerifier, OnMessagesDelivered, TargetHeaderChain,
26-
},
24+
source_chain::{DeliveryConfirmationPayments, OnMessagesDelivered, TargetHeaderChain},
2725
target_chain::{
2826
DeliveryPayments, DispatchMessage, DispatchMessageData, MessageDispatch,
2927
ProvedLaneMessages, ProvedMessages, SourceHeaderChain,
3028
},
3129
DeliveredMessages, InboundLaneData, LaneId, Message, MessageKey, MessageNonce, MessagePayload,
32-
OutboundLaneData, UnrewardedRelayer, UnrewardedRelayersState, VerificationError,
30+
UnrewardedRelayer, UnrewardedRelayersState, VerificationError,
3331
};
3432
use bp_runtime::{messages::MessageDispatchResult, Size};
3533
use codec::{Decode, Encode};
@@ -50,8 +48,6 @@ pub type Balance = u64;
5048
pub struct TestPayload {
5149
/// Field that may be used to identify messages.
5250
pub id: u64,
53-
/// Reject this message by lane verifier?
54-
pub reject_by_lane_verifier: bool,
5551
/// Dispatch weight that is declared by the message sender.
5652
pub declared_weight: Weight,
5753
/// Message dispatch result.
@@ -120,7 +116,6 @@ impl Config for TestRuntime {
120116
type DeliveryPayments = TestDeliveryPayments;
121117

122118
type TargetHeaderChain = TestTargetHeaderChain;
123-
type LaneMessageVerifier = TestLaneMessageVerifier;
124119
type DeliveryConfirmationPayments = TestDeliveryConfirmationPayments;
125120
type OnMessagesDelivered = TestOnMessagesDelivered;
126121

@@ -268,24 +263,6 @@ impl TargetHeaderChain<TestPayload, TestRelayer> for TestTargetHeaderChain {
268263
}
269264
}
270265

271-
/// Lane message verifier that is used in tests.
272-
#[derive(Debug, Default)]
273-
pub struct TestLaneMessageVerifier;
274-
275-
impl LaneMessageVerifier<TestPayload> for TestLaneMessageVerifier {
276-
fn verify_message(
277-
_lane: &LaneId,
278-
_lane_outbound_data: &OutboundLaneData,
279-
payload: &TestPayload,
280-
) -> Result<(), VerificationError> {
281-
if !payload.reject_by_lane_verifier {
282-
Ok(())
283-
} else {
284-
Err(VerificationError::Other(TEST_ERROR))
285-
}
286-
}
287-
}
288-
289266
/// Reward payments at the target chain during delivery transaction.
290267
#[derive(Debug, Default)]
291268
pub struct TestDeliveryPayments;
@@ -438,7 +415,6 @@ pub fn inbound_message_data(payload: TestPayload) -> DispatchMessageData<TestPay
438415
pub const fn message_payload(id: u64, declared_weight: u64) -> TestPayload {
439416
TestPayload {
440417
id,
441-
reject_by_lane_verifier: false,
442418
declared_weight: Weight::from_parts(declared_weight, 0),
443419
dispatch_result: dispatch_result(0),
444420
extra: Vec::new(),

bridges/primitives/messages/src/source_chain.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
//! Primitives of messages module, that are used on the source chain.
1818
19-
use crate::{InboundLaneData, LaneId, MessageNonce, OutboundLaneData, VerificationError};
19+
use crate::{InboundLaneData, LaneId, MessageNonce, VerificationError};
2020

2121
use crate::UnrewardedRelayer;
2222
use bp_runtime::Size;
@@ -64,24 +64,6 @@ pub trait TargetHeaderChain<Payload, AccountId> {
6464
) -> Result<(LaneId, InboundLaneData<AccountId>), VerificationError>;
6565
}
6666

67-
/// Lane message verifier.
68-
///
69-
/// Runtime developer may implement any additional validation logic over message-lane mechanism.
70-
/// E.g. if lanes should have some security (e.g. you can only accept Lane1 messages from
71-
/// Submitter1, Lane2 messages for those who has submitted first message to this lane, disable
72-
/// Lane3 until some block, ...), then it may be built using this verifier.
73-
///
74-
/// Any fee requirements should also be enforced here.
75-
pub trait LaneMessageVerifier<Payload> {
76-
/// Verify message payload and return Ok(()) if message is valid and allowed to be sent over the
77-
/// lane.
78-
fn verify_message(
79-
lane: &LaneId,
80-
outbound_data: &OutboundLaneData,
81-
payload: &Payload,
82-
) -> Result<(), VerificationError>;
83-
}
84-
8567
/// Manages payments that are happening at the source chain during delivery confirmation
8668
/// transaction.
8769
pub trait DeliveryConfirmationPayments<AccountId> {
@@ -161,7 +143,7 @@ impl<Payload> MessagesBridge<Payload> for NoopMessagesBridge {
161143
}
162144
}
163145

164-
/// Structure that may be used in place of `TargetHeaderChain`, `LaneMessageVerifier` and
146+
/// Structure that may be used in place of `TargetHeaderChain` and
165147
/// `MessageDeliveryAndDispatchPayment` on chains, where outbound messages are forbidden.
166148
pub struct ForbidOutboundMessages;
167149

@@ -183,16 +165,6 @@ impl<Payload, AccountId> TargetHeaderChain<Payload, AccountId> for ForbidOutboun
183165
}
184166
}
185167

186-
impl<Payload> LaneMessageVerifier<Payload> for ForbidOutboundMessages {
187-
fn verify_message(
188-
_lane: &LaneId,
189-
_outbound_data: &OutboundLaneData,
190-
_payload: &Payload,
191-
) -> Result<(), VerificationError> {
192-
Err(VerificationError::Other(ALL_OUTBOUND_MESSAGES_REJECTED))
193-
}
194-
}
195-
196168
impl<AccountId> DeliveryConfirmationPayments<AccountId> for ForbidOutboundMessages {
197169
type Error = &'static str;
198170

0 commit comments

Comments
 (0)