Skip to content

Commit

Permalink
fix(mempool): fix nonce incremental
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 committed Jul 22, 2024
1 parent c9f77e7 commit 013569d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 0 additions & 1 deletion crates/mempool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ derive_more.workspace = true
starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" }
starknet_api.workspace = true
starknet_mempool_types = { path = "../mempool_types", version = "0.0" }
starknet-types-core.workspace = true
tokio.workspace = true

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/mempool/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::collections::HashMap;

use starknet_api::core::{ContractAddress, Nonce};
use starknet_api::transaction::{Tip, TransactionHash};
use starknet_mempool_types::errors::MempoolError;
use starknet_mempool_types::mempool_types::{
Account, AccountState, MempoolInput, MempoolResult, ThinTransaction,
};
use starknet_types_core::felt::Felt;

use crate::transaction_pool::TransactionPool;
use crate::transaction_queue::TransactionQueue;
Expand Down Expand Up @@ -76,7 +76,7 @@ impl Mempool {
state_changes: HashMap<ContractAddress, AccountState>,
) -> MempoolResult<()> {
for (address, AccountState { nonce }) in state_changes {
let next_nonce = Nonce(nonce.0 + Felt::ONE);
let next_nonce = nonce.try_increment().map_err(|_| MempoolError::FeltOutOfRange)?;
// Dequeue transactions from the queue in the following cases:
// 1. Remove a transaction from queue with nonce lower and eq than those committed to
// the block, applicable when the block is from the same leader.
Expand Down
3 changes: 3 additions & 0 deletions crates/mempool_types/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ pub enum MempoolError {
DuplicateTransaction { tx_hash: TransactionHash },
#[error("Transaction with hash: {tx_hash} not found")]
TransactionNotFound { tx_hash: TransactionHash },
// TODO(Mohammad): Consider using `StarknetApiError` once it implements `PartialEq`.
#[error("Out of range.")]
FeltOutOfRange,
}

0 comments on commit 013569d

Please sign in to comment.