Skip to content

Commit

Permalink
fiox overflow when computing priority boost (#2587)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik committed Sep 28, 2023
1 parent 95a7f53 commit 8a2b6af
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
43 changes: 40 additions & 3 deletions modules/relayers/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,10 @@ mod tests {
use bp_header_chain::SubmitFinalityProofInfo;
use bp_messages::{
source_chain::FromBridgedChainMessagesDeliveryProof,
target_chain::FromBridgedChainMessagesProof, BaseMessagesProofInfo, InboundLaneData,
LaneId, MessageNonce, MessagesCallInfo, OutboundLaneData, ReceiveMessagesDeliveryProofInfo,
ReceiveMessagesProofInfo, UnrewardedRelayerOccupation, UnrewardedRelayersState,
target_chain::FromBridgedChainMessagesProof, BaseMessagesProofInfo, DeliveredMessages,
InboundLaneData, LaneId, MessageNonce, MessagesCallInfo, OutboundLaneData,
ReceiveMessagesDeliveryProofInfo, ReceiveMessagesProofInfo, UnrewardedRelayer,
UnrewardedRelayerOccupation, UnrewardedRelayersState,
};
use bp_parachains::{BestParaHeadHash, ParaInfo, SubmitParachainHeadsInfo};
use bp_polkadot_core::parachains::{ParaHeadsProof, ParaId};
Expand Down Expand Up @@ -1782,4 +1783,40 @@ mod tests {
);
});
}

#[test]
fn does_not_panic_on_boosting_priority_of_empty_message_delivery_transaction() {
run_test(|| {
let best_delivered_message =
BridgedUnderlyingChain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
initialize_environment(100, 100, best_delivered_message);

// register relayer so it gets priority boost
BridgeRelayers::register(RuntimeOrigin::signed(relayer_account_at_this_chain()), 1000)
.unwrap();

// allow empty message delivery transactions
let lane_id = TestLaneId::get();
let in_lane_data = InboundLaneData {
last_confirmed_nonce: 0,
relayers: vec![UnrewardedRelayer {
relayer: relayer_account_at_bridged_chain(),
messages: DeliveredMessages { begin: 1, end: best_delivered_message },
}]
.into(),
..Default::default()
};
pallet_bridge_messages::InboundLanes::<TestRuntime>::insert(lane_id, in_lane_data);

// now check that the priority of empty tx is the same as priority of 1-message tx
let priority_of_zero_messages_delivery =
run_validate(message_delivery_call(best_delivered_message)).unwrap().priority;
let priority_of_one_messages_delivery =
run_validate(message_delivery_call(best_delivered_message + 1))
.unwrap()
.priority;

assert_eq!(priority_of_zero_messages_delivery, priority_of_one_messages_delivery);
});
}
}
2 changes: 1 addition & 1 deletion modules/relayers/src/extension/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where
PriorityBoostPerMessage: Get<TransactionPriority>,
{
// we don't want any boost for transaction with single message => minus one
PriorityBoostPerMessage::get().saturating_mul(messages - 1)
PriorityBoostPerMessage::get().saturating_mul(messages.saturating_sub(1))
}

#[cfg(not(feature = "integrity-test"))]
Expand Down

0 comments on commit 8a2b6af

Please sign in to comment.