diff --git a/parachain/pallets/outbound-queue/Cargo.toml b/parachain/pallets/outbound-queue/Cargo.toml index aaf83e597c..2d91611d2d 100644 --- a/parachain/pallets/outbound-queue/Cargo.toml +++ b/parachain/pallets/outbound-queue/Cargo.toml @@ -29,7 +29,7 @@ bridge-hub-common = { path = "../../../polkadot-sdk/cumulus/parachains/runtimes/ snowbridge-core = { path = "../../primitives/core", features = ["serde"], default-features = false } snowbridge-outbound-queue-merkle-tree = { path = "merkle-tree", default-features = false } -ethabi = { git = "https://github.com/Snowfork/ethabi-decode.git", package = "ethabi-decode", branch = "master", default-features = false } +ethabi = { git = "https://github.com/snowfork/ethabi-decode.git", package = "ethabi-decode", branch = "master", default-features = false } xcm = { package = "staging-xcm", path = "../../../polkadot-sdk/polkadot/xcm", default-features = false } diff --git a/parachain/pallets/outbound-queue/src/lib.rs b/parachain/pallets/outbound-queue/src/lib.rs index c8f2e2d6d0..6c461510b3 100644 --- a/parachain/pallets/outbound-queue/src/lib.rs +++ b/parachain/pallets/outbound-queue/src/lib.rs @@ -308,10 +308,16 @@ pub mod pallet { let queued_message: QueuedMessage = versioned_queued_message.try_into().map_err(|_| Unsupported)?; - let pricing_params = T::PricingParameters::get(); - - let next_nonce = Nonce::::get(queued_message.channel_id).saturating_add(1); + // Obtain next nonce + let nonce = >::try_mutate( + queued_message.channel_id, + |nonce| -> Result { + *nonce = nonce.checked_add(1).ok_or(Unsupported)?; + Ok(*nonce) + }, + )?; + let pricing_params = T::PricingParameters::get(); let command = queued_message.command.index(); let params = queued_message.command.abi_encode(); let max_dispatch_gas = @@ -321,7 +327,7 @@ pub mod pallet { // Construct the final committed message let message = CommittedMessage { channel_id: queued_message.channel_id, - nonce: next_nonce, + nonce, command, params, max_dispatch_gas, @@ -339,12 +345,8 @@ pub mod pallet { Messages::::append(Box::new(message)); MessageLeaves::::append(message_abi_encoded_hash); - Nonce::::set(queued_message.channel_id, next_nonce); - Self::deposit_event(Event::MessageAccepted { - id: queued_message.id, - nonce: next_nonce, - }); + Self::deposit_event(Event::MessageAccepted { id: queued_message.id, nonce }); Ok(true) } diff --git a/parachain/pallets/outbound-queue/src/test.rs b/parachain/pallets/outbound-queue/src/test.rs index 77fa7e92f0..7db5fbec2c 100644 --- a/parachain/pallets/outbound-queue/src/test.rs +++ b/parachain/pallets/outbound-queue/src/test.rs @@ -99,16 +99,46 @@ fn process_message_yields_on_max_messages_per_block() { }) } +#[test] +fn process_message_fails_on_max_nonce_reached() { + new_tester().execute_with(|| { + let sibling_id = 1000; + let channel_id: ChannelId = ParaId::from(sibling_id).into(); + let origin = AggregateMessageOrigin::Snowbridge(channel_id.into()); + let message: QueuedMessage = QueuedMessage { + id: H256::zero(), + channel_id, + command: mock_message(sibling_id).command, + }; + let versioned_queued_message: VersionedQueuedMessage = message.try_into().unwrap(); + let encoded = versioned_queued_message.encode(); + let mut meter = WeightMeter::with_limit(Weight::MAX); + + Nonce::::set(channel_id, u64::MAX); + + assert_noop!( + OutboundQueue::process_message(&encoded.as_slice(), origin, &mut meter, &mut [0u8; 32]), + ProcessMessageError::Unsupported + ); + }) +} + #[test] fn process_message_fails_on_overweight_message() { new_tester().execute_with(|| { let sibling_id = 1000; let channel_id: ChannelId = ParaId::from(sibling_id).into(); let origin = AggregateMessageOrigin::Snowbridge(channel_id); - let message = mock_message(sibling_id).encode(); + let message: QueuedMessage = QueuedMessage { + id: H256::zero(), + channel_id, + command: mock_message(sibling_id).command, + }; + let versioned_queued_message: VersionedQueuedMessage = message.try_into().unwrap(); + let encoded = versioned_queued_message.encode(); let mut meter = WeightMeter::with_limit(Weight::from_parts(1, 1)); assert_noop!( - OutboundQueue::process_message(message.as_slice(), origin, &mut meter, &mut [0u8; 32]), + OutboundQueue::process_message(&encoded.as_slice(), origin, &mut meter, &mut [0u8; 32]), ProcessMessageError::Overweight(::WeightInfo::do_process_message()) ); }) diff --git a/smoketest/Cargo.lock b/smoketest/Cargo.lock index 322f090eb6..06124bb292 100644 --- a/smoketest/Cargo.lock +++ b/smoketest/Cargo.lock @@ -4209,9 +4209,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" dependencies = [ "serde", ] @@ -4260,9 +4260,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.30" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable",