Skip to content

Commit

Permalink
Small simplifications (#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 authored Apr 17, 2023
1 parent d30927c commit d397094
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
16 changes: 7 additions & 9 deletions modules/messages/src/inbound_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,17 @@ impl<S: InboundLaneStorage> InboundLane<S> {
);

// now let's update inbound lane storage
let push_new = match data.relayers.back_mut() {
match data.relayers.back_mut() {
Some(entry) if entry.relayer == *relayer_at_bridged_chain => {
entry.messages.note_dispatched_message();
false
},
_ => true,
_ => {
data.relayers.push_back(UnrewardedRelayer {
relayer: relayer_at_bridged_chain.clone(),
messages: DeliveredMessages::new(nonce),
});
},
};
if push_new {
data.relayers.push_back(UnrewardedRelayer {
relayer: (*relayer_at_bridged_chain).clone(),
messages: DeliveredMessages::new(nonce),
});
}
self.storage.set_data(data);

ReceivalResult::Dispatched(dispatch_result)
Expand Down
12 changes: 5 additions & 7 deletions primitives/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,9 @@ impl<RelayerId> InboundLaneData<RelayerId> {
where
RelayerId: MaxEncodedLen,
{
let message_nonce_size = MessageNonce::max_encoded_len();
let relayer_id_encoded_size = RelayerId::max_encoded_len();
let relayers_entry_size = relayer_id_encoded_size.checked_add(2 * message_nonce_size)?;
let relayers_size = relayers_entries.checked_mul(relayers_entry_size)?;
relayers_size.checked_add(message_nonce_size)
relayers_entries
.checked_mul(UnrewardedRelayer::<RelayerId>::max_encoded_len())?
.checked_add(MessageNonce::max_encoded_len())
}

/// Returns the approximate size of the struct as u32, given a number of entries in the
Expand Down Expand Up @@ -223,7 +221,7 @@ pub struct InboundMessageDetails {
///
/// This struct represents a continuous range of messages that have been delivered by the same
/// relayer and whose confirmations are still pending.
#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo)]
#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub struct UnrewardedRelayer<RelayerId> {
/// Identifier of the relayer.
pub relayer: RelayerId,
Expand Down Expand Up @@ -270,7 +268,7 @@ pub enum ReceivalResult<DispatchLevelResult> {
}

/// Delivered messages with their dispatch result.
#[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo)]
#[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub struct DeliveredMessages {
/// Nonce of the first message that has been delivered (inclusive).
pub begin: MessageNonce,
Expand Down

0 comments on commit d397094

Please sign in to comment.