|
17 | 17 | use crate::messages::{ |
18 | 18 | source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, |
19 | 19 | }; |
20 | | -use bp_messages::{InboundLaneData, LaneId, MessageNonce}; |
| 20 | +use bp_messages::{target_chain::MessageDispatch, InboundLaneData, LaneId, MessageNonce}; |
21 | 21 | use frame_support::{ |
22 | 22 | dispatch::CallableCallFor, |
23 | 23 | traits::{Get, IsSubType}, |
@@ -77,7 +77,12 @@ impl ReceiveMessagesProofInfo { |
77 | 77 | /// |
78 | 78 | /// - or there are no bundled messages, but the inbound lane is blocked by too many unconfirmed |
79 | 79 | /// messages and/or unrewarded relayers. |
80 | | - fn is_obsolete(&self) -> bool { |
| 80 | + fn is_obsolete(&self, is_dispatcher_active: bool) -> bool { |
| 81 | + // if dispatcher is inactive, we don't accept any delivery transactions |
| 82 | + if !is_dispatcher_active { |
| 83 | + return true |
| 84 | + } |
| 85 | + |
81 | 86 | // transactions with zero bundled nonces are not allowed, unless they're message |
82 | 87 | // delivery transactions, which brings reward confirmations required to unblock |
83 | 88 | // the lane |
@@ -275,7 +280,9 @@ impl< |
275 | 280 |
|
276 | 281 | fn check_obsolete_call(&self) -> TransactionValidity { |
277 | 282 | match self.call_info() { |
278 | | - Some(CallInfo::ReceiveMessagesProof(proof_info)) if proof_info.is_obsolete() => { |
| 283 | + Some(CallInfo::ReceiveMessagesProof(proof_info)) |
| 284 | + if proof_info.is_obsolete(T::MessageDispatch::is_active()) => |
| 285 | + { |
279 | 286 | log::trace!( |
280 | 287 | target: pallet_bridge_messages::LOG_TARGET, |
281 | 288 | "Rejecting obsolete messages delivery transaction: {:?}", |
@@ -327,8 +334,8 @@ mod tests { |
327 | 334 | }, |
328 | 335 | messages_call_ext::MessagesCallSubType, |
329 | 336 | mock::{ |
330 | | - MaxUnconfirmedMessagesAtInboundLane, MaxUnrewardedRelayerEntriesAtInboundLane, |
331 | | - TestRuntime, ThisChainRuntimeCall, |
| 337 | + DummyMessageDispatch, MaxUnconfirmedMessagesAtInboundLane, |
| 338 | + MaxUnrewardedRelayerEntriesAtInboundLane, TestRuntime, ThisChainRuntimeCall, |
332 | 339 | }, |
333 | 340 | }; |
334 | 341 | use bp_messages::{DeliveredMessages, UnrewardedRelayer, UnrewardedRelayersState}; |
@@ -435,6 +442,18 @@ mod tests { |
435 | 442 | }); |
436 | 443 | } |
437 | 444 |
|
| 445 | + #[test] |
| 446 | + fn extension_reject_call_when_dispatcher_is_inactive() { |
| 447 | + sp_io::TestExternalities::new(Default::default()).execute_with(|| { |
| 448 | + // when current best delivered is message#10 and we're trying to deliver message 11..=15 |
| 449 | + // => tx is accepted, but we have inactive dispatcher, so... |
| 450 | + deliver_message_10(); |
| 451 | + |
| 452 | + DummyMessageDispatch::deactivate(); |
| 453 | + assert!(!validate_message_delivery(11, 15)); |
| 454 | + }); |
| 455 | + } |
| 456 | + |
438 | 457 | #[test] |
439 | 458 | fn extension_rejects_empty_delivery_with_rewards_confirmations_if_there_are_free_relayer_and_message_slots( |
440 | 459 | ) { |
|
0 commit comments