Skip to content

Commit

Permalink
Add check for next nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauthamastro committed Feb 2, 2024
1 parent 1e8801f commit 292d413
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pallets/thea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ pub mod pallet {
NoRelayersFound,
/// Not expected relayer origin
NotAnAllowlistedRelayer,
/// Nonce Error
NonceError
}

#[pallet::hooks]
Expand All @@ -298,7 +300,8 @@ pub mod pallet {
let active_networks = <ActiveNetworks<T>>::get();
for network in active_networks.clone() {
let last_processed_nonce = <IncomingNonce<T>>::get(network);
match <IncomingMessagesQueue<T>>::take(network, last_processed_nonce.saturating_add(1)) {
let next_nonce = last_processed_nonce.saturating_add(1);
match <IncomingMessagesQueue<T>>::take(network, next_nonce) {
None => continue,
Some(msg) => {
if msg.execute_at <= blk.saturated_into::<u32>() {
Expand All @@ -308,7 +311,7 @@ pub mod pallet {
);
<IncomingNonce<T>>::insert(
msg.message.network,
next_nonce.saturating_add(1),
next_nonce,
);
Self::deposit_event(Event::<T>::TheaPayloadProcessed(
msg.message.network,
Expand Down Expand Up @@ -381,6 +384,9 @@ pub mod pallet {
return Err(Error::<T>::NotEnoughStake.into())
}

let next_nonce = <IncomingNonce<T>>::get(payload.network);
ensure!(payload.nonce > next_nonce, Error::<T>::NonceError);

match <IncomingMessagesQueue<T>>::get(payload.network, payload.nonce) {
None => {
// Lock balance
Expand Down

0 comments on commit 292d413

Please sign in to comment.