diff --git a/concordium-consensus/src/Concordium/GlobalState/Persistent/TreeState.hs b/concordium-consensus/src/Concordium/GlobalState/Persistent/TreeState.hs index 76eeb4700d..c5588532af 100644 --- a/concordium-consensus/src/Concordium/GlobalState/Persistent/TreeState.hs +++ b/concordium-consensus/src/Concordium/GlobalState/Persistent/TreeState.hs @@ -898,12 +898,14 @@ instance oldCredential <- case wmdData of CredentialDeployment{} -> memberTransactionTable wmdHash _ -> return False - -- We need to check here that the nonce is still ok, because it could be - -- that a block was finalized thus the next account nonce being incremented + -- We need to check here that the nonce is still ok with respect to the last finalized block, + -- because it could be that a block was finalized thus the next account nonce being incremented -- after this transaction was received and pre-verified. isNonceOk <- case wmdData of NormalTransaction tr -> do - (nonce, _) <- getNextAccountNonce $ accountAddressEmbed (transactionSender tr) + lfbState <- use (skovPersistentData . lastFinalized . to _bpState) + mAcc <- getAccount lfbState $ transactionSender tr + nonce <- maybe (pure minNonce) getAccountNonce (snd <$> mAcc) return $! nonce <= transactionNonce tr -- the sequence number will be checked by @Impl.addTransaction@. _ -> return False diff --git a/concordium-consensus/src/Concordium/KonsensusV1/Transactions.hs b/concordium-consensus/src/Concordium/KonsensusV1/Transactions.hs index 74aa22fea5..799a45c608 100644 --- a/concordium-consensus/src/Concordium/KonsensusV1/Transactions.hs +++ b/concordium-consensus/src/Concordium/KonsensusV1/Transactions.hs @@ -233,12 +233,14 @@ addPreverifiedTransaction :: TVer.OkResult -> m AddTransactionResult addPreverifiedTransaction bi okRes = do - -- We need to check here that the nonce is still ok, because it could be - -- that a block was finalized thus the next account nonce being incremented + -- We need to check here that the nonce is still ok with respect to the last finalized block, + -- because it could be that a block was finalized thus the next account nonce being incremented -- after this transaction was received and pre-verified. isNonceOk <- case wmdData bi of NormalTransaction tr -> do - (nonce, _) <- runAccountNonceQueryT $ getNextAccountNonce $ accountAddressEmbed (transactionSender tr) + lfbState <- use (Impl.lastFinalized . to bpState) + mAcc <- getAccount lfbState $ transactionSender tr + nonce <- maybe (pure minNonce) getAccountNonce (snd <$> mAcc) return $! nonce <= transactionNonce tr -- the sequence number will be checked by @Impl.addTransaction@. _ -> return True