diff --git a/modules/messages/src/inbound_lane.rs b/modules/messages/src/inbound_lane.rs index 3f64ab765b5..59ff5667195 100644 --- a/modules/messages/src/inbound_lane.rs +++ b/modules/messages/src/inbound_lane.rs @@ -198,19 +198,17 @@ impl InboundLane { ); // 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) diff --git a/primitives/messages/src/lib.rs b/primitives/messages/src/lib.rs index 3910837a442..2828d5af006 100644 --- a/primitives/messages/src/lib.rs +++ b/primitives/messages/src/lib.rs @@ -164,11 +164,9 @@ impl InboundLaneData { 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::::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 @@ -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 { /// Identifier of the relayer. pub relayer: RelayerId, @@ -270,7 +268,7 @@ pub enum ReceivalResult { } /// 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,