diff --git a/pallets/thea/src/lib.rs b/pallets/thea/src/lib.rs index e8f932432..1e41dc46c 100644 --- a/pallets/thea/src/lib.rs +++ b/pallets/thea/src/lib.rs @@ -289,6 +289,8 @@ pub mod pallet { NoRelayersFound, /// Not expected relayer origin NotAnAllowlistedRelayer, + /// Nonce Error + NonceError } #[pallet::hooks] @@ -298,7 +300,8 @@ pub mod pallet { let active_networks = >::get(); for network in active_networks.clone() { let last_processed_nonce = >::get(network); - match >::take(network, last_processed_nonce.saturating_add(1)) { + let next_nonce = last_processed_nonce.saturating_add(1); + match >::take(network, next_nonce) { None => continue, Some(msg) => { if msg.execute_at <= blk.saturated_into::() { @@ -308,7 +311,7 @@ pub mod pallet { ); >::insert( msg.message.network, - next_nonce.saturating_add(1), + next_nonce, ); Self::deposit_event(Event::::TheaPayloadProcessed( msg.message.network, @@ -381,6 +384,9 @@ pub mod pallet { return Err(Error::::NotEnoughStake.into()) } + let next_nonce = >::get(payload.network); + ensure!(payload.nonce > next_nonce, Error::::NonceError); + match >::get(payload.network, payload.nonce) { None => { // Lock balance