Skip to content

Commit 464eb29

Browse files
committed
Fixes/comments from PR
1 parent 5abfea8 commit 464eb29

File tree

5 files changed

+44
-37
lines changed

5 files changed

+44
-37
lines changed

modules/messages/src/inbound_lane.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use crate::Config;
2020

2121
use bp_messages::{
2222
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
23-
DeliveredMessages, InboundLaneData, LaneId, MessageKey, MessageNonce, OutboundLaneData,
24-
UnrewardedRelayer,
23+
DeliveredMessages, InboundLaneData, LaneId, MessageKey, MessageNonce, NotDispatchedReason,
24+
OutboundLaneData, ReceivedMessageResult, UnrewardedRelayer,
2525
};
2626
use bp_runtime::messages::MessageDispatchResult;
2727
use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
@@ -124,6 +124,19 @@ pub enum ReceivalResult {
124124
TooManyUnconfirmedMessages,
125125
}
126126

127+
impl From<ReceivalResult> for ReceivedMessageResult {
128+
fn from(value: ReceivalResult) -> Self {
129+
match value {
130+
ReceivalResult::Dispatched(_) => ReceivedMessageResult::Dispatched,
131+
ReceivalResult::InvalidNonce => NotDispatchedReason::InvalidNonce.into(),
132+
ReceivalResult::TooManyUnrewardedRelayers =>
133+
NotDispatchedReason::TooManyUnrewardedRelayers.into(),
134+
ReceivalResult::TooManyUnconfirmedMessages =>
135+
NotDispatchedReason::TooManyUnconfirmedMessages.into(),
136+
}
137+
}
138+
}
139+
127140
/// Inbound messages lane.
128141
pub struct InboundLane<S> {
129142
storage: S,

modules/messages/src/lib.rs

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub const LOG_TARGET: &str = "runtime::bridge-messages";
9191
#[frame_support::pallet]
9292
pub mod pallet {
9393
use super::*;
94-
use bp_messages::{NotDispatchedReason, ReceivedMessageResult, ReceivedMessages};
94+
use bp_messages::{ReceivedMessageResult, ReceivedMessages};
9595
use frame_support::pallet_prelude::*;
9696
use frame_system::pallet_prelude::*;
9797

@@ -317,18 +317,16 @@ pub mod pallet {
317317
}
318318

319319
let mut lane_messages_received_status =
320-
Vec::with_capacity(lane_data.messages.len());
320+
ReceivedMessages::new(lane_id, Vec::with_capacity(lane_data.messages.len()));
321321
let mut is_lane_processing_stopped_no_weight_left = false;
322322

323323
for mut message in lane_data.messages {
324324
debug_assert_eq!(message.key.lane_id, lane_id);
325325
total_messages += 1;
326326

327327
if is_lane_processing_stopped_no_weight_left {
328-
lane_messages_received_status.push((
329-
message.key.nonce,
330-
NotDispatchedReason::NotEnoughWeightForLane.into(),
331-
));
328+
lane_messages_received_status
329+
.push_skipped_for_not_enough_weight(message.key.nonce);
332330
continue
333331
}
334332

@@ -344,10 +342,8 @@ pub mod pallet {
344342
message_dispatch_weight,
345343
dispatch_weight_left,
346344
);
347-
lane_messages_received_status.push((
348-
message.key.nonce,
349-
NotDispatchedReason::NotEnoughWeightForLane.into(),
350-
));
345+
lane_messages_received_status
346+
.push_skipped_for_not_enough_weight(message.key.nonce);
351347
is_lane_processing_stopped_no_weight_left = true;
352348
continue
353349
}
@@ -369,31 +365,16 @@ pub mod pallet {
369365
ReceivalResult::Dispatched(dispatch_result) => {
370366
valid_messages += 1;
371367
lane_messages_received_status
372-
.push((message.key.nonce, ReceivedMessageResult::Dispatched));
368+
.push(message.key.nonce, ReceivedMessageResult::Dispatched);
373369
(
374370
dispatch_result.unspent_weight,
375371
!dispatch_result.dispatch_fee_paid_during_dispatch,
376372
)
377373
},
378-
ReceivalResult::InvalidNonce => {
379-
lane_messages_received_status.push((
380-
message.key.nonce,
381-
NotDispatchedReason::InvalidNonce.into(),
382-
));
383-
(message_dispatch_weight, true)
384-
},
385-
ReceivalResult::TooManyUnrewardedRelayers => {
386-
lane_messages_received_status.push((
387-
message.key.nonce,
388-
NotDispatchedReason::TooManyUnrewardedRelayers.into(),
389-
));
390-
(message_dispatch_weight, true)
391-
},
392-
ReceivalResult::TooManyUnconfirmedMessages => {
393-
lane_messages_received_status.push((
394-
message.key.nonce,
395-
NotDispatchedReason::TooManyUnconfirmedMessages.into(),
396-
));
374+
rr @ ReceivalResult::InvalidNonce |
375+
rr @ ReceivalResult::TooManyUnrewardedRelayers |
376+
rr @ ReceivalResult::TooManyUnconfirmedMessages => {
377+
lane_messages_received_status.push(message.key.nonce, rr.into());
397378
(message_dispatch_weight, true)
398379
},
399380
};
@@ -412,8 +393,7 @@ pub mod pallet {
412393
);
413394
}
414395

415-
messages_received_status
416-
.push(ReceivedMessages::new(lane_id, lane_messages_received_status));
396+
messages_received_status.push(lane_messages_received_status);
417397
}
418398

419399
log::debug!(

primitives/messages/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,25 @@ pub struct UnrewardedRelayer<RelayerId> {
221221
/// Received messages with their dispatch result.
222222
#[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo)]
223223
pub struct ReceivedMessages<Result> {
224+
/// Id of the lane which is receiving messages.
224225
pub lane: LaneId,
226+
/// Result of messages which we tried to dispatch
225227
pub receive_results: Vec<(MessageNonce, Result)>,
228+
/// Messages which were skipped and never dispatched
229+
pub skipped_for_not_enough_weight: Vec<MessageNonce>,
226230
}
227231

228232
impl<Result> ReceivedMessages<Result> {
229233
pub fn new(lane: LaneId, receive_results: Vec<(MessageNonce, Result)>) -> Self {
230-
ReceivedMessages { lane, receive_results }
234+
ReceivedMessages { lane, receive_results, skipped_for_not_enough_weight: Vec::new() }
235+
}
236+
237+
pub fn push(&mut self, message: MessageNonce, result: Result) {
238+
self.receive_results.push((message, result));
239+
}
240+
241+
pub fn push_skipped_for_not_enough_weight(&mut self, message: MessageNonce) {
242+
self.skipped_for_not_enough_weight.push(message);
231243
}
232244
}
233245

@@ -252,8 +264,6 @@ pub enum NotDispatchedReason {
252264
TooManyUnrewardedRelayers,
253265
/// There are too many unconfirmed messages at the lane.
254266
TooManyUnconfirmedMessages,
255-
/// There are too many unconfirmed messages at the lane.
256-
NotEnoughWeightForLane,
257267
}
258268

259269
impl From<NotDispatchedReason> for ReceivedMessageResult {

scripts/send-message-from-millau-rialto.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# we have (to make sure the message relays are running), but remove the message
77
# generator service. From there you may submit messages manually using this script.
88

9+
# TODO: Fix demeo scripts https://github.com/paritytech/parity-bridges-common/issues/1406
10+
911
MILLAU_PORT="${RIALTO_PORT:-9945}"
1012

1113
case "$1" in

scripts/send-message-from-rialto-millau.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# we have (to make sure the message relays are running), but remove the message
77
# generator service. From there you may submit messages manually using this script.
88

9+
# TODO: Fix demeo scripts https://github.com/paritytech/parity-bridges-common/issues/1406
10+
911
RIALTO_PORT="${RIALTO_PORT:-9944}"
1012

1113
case "$1" in

0 commit comments

Comments
 (0)