Boost message delivery transaction priority (#2023)

* reject delivery transactions with at least one obsolete message

* clippy

* boost priority of message delivery transactions: transaction with more messages has larger priority than the transaction with less messages

* apply review suggestion

* CallInfo::bundled_messages

* validate_does_not_boost_priority_of_message_delivery_transactons_with_too_many_messages

* clippy
This commit is contained in:
Svyatoslav Nikolsky
2023-04-10 13:43:37 +03:00
committed by Bastian Köcher
parent ceea1a10f7
commit f7380490c0
9 changed files with 481 additions and 65 deletions
@@ -104,6 +104,22 @@ pub enum CallInfo {
ReceiveMessagesDeliveryProof(ReceiveMessagesDeliveryProofInfo),
}
impl CallInfo {
/// Returns number of messages, bundled with this transaction.
pub fn bundled_messages(&self) -> MessageNonce {
let bundled_range = match *self {
Self::ReceiveMessagesProof(ref info) => &info.0.bundled_range,
Self::ReceiveMessagesDeliveryProof(ref info) => &info.0.bundled_range,
};
bundled_range
.end()
.checked_sub(*bundled_range.start())
.map(|d| d.saturating_add(1))
.unwrap_or(0)
}
}
/// Helper struct that provides methods for working with a call supported by `CallInfo`.
pub struct CallHelper<T: Config<I>, I: 'static> {
pub _phantom_data: sp_std::marker::PhantomData<(T, I)>,
@@ -321,6 +337,7 @@ mod tests {
TestRuntime, ThisChainRuntimeCall,
},
};
use bitvec::prelude::*;
use bp_messages::{DeliveredMessages, UnrewardedRelayer, UnrewardedRelayersState};
use sp_std::ops::RangeInclusive;
@@ -330,7 +347,11 @@ mod tests {
for n in 0..MaxUnrewardedRelayerEntriesAtInboundLane::get() {
inbound_lane_state.relayers.push_back(UnrewardedRelayer {
relayer: Default::default(),
messages: DeliveredMessages { begin: n + 1, end: n + 1 },
messages: DeliveredMessages {
begin: n + 1,
end: n + 1,
dispatch_results: bitvec![u8, Msb0; 1; 1],
},
});
}
pallet_bridge_messages::InboundLanes::<TestRuntime>::insert(
@@ -347,6 +368,7 @@ mod tests {
messages: DeliveredMessages {
begin: 1,
end: MaxUnconfirmedMessagesAtInboundLane::get(),
dispatch_results: bitvec![u8, Msb0; 1; MaxUnconfirmedMessagesAtInboundLane::get() as _],
},
});
pallet_bridge_messages::InboundLanes::<TestRuntime>::insert(