diff --git a/crates/mempool/src/mempool.rs b/crates/mempool/src/mempool.rs index b2fc747b8d..8732b25274 100644 --- a/crates/mempool/src/mempool.rs +++ b/crates/mempool/src/mempool.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use starknet_api::core::{ContractAddress, Nonce}; -use starknet_api::transaction::{Tip, TransactionHash}; +use starknet_api::transaction::{ResourceBoundsMapping, Tip, TransactionHash}; use starknet_mempool_types::errors::MempoolError; use starknet_mempool_types::mempool_types::{ Account, @@ -111,7 +111,7 @@ impl Mempool { if self.tx_queue.get_nonce(address).is_none() { if let Some(tx) = self.tx_pool.get_by_address_and_nonce(address, next_nonce) { - self.tx_queue.insert(*tx); + self.tx_queue.insert(tx.clone()); } } @@ -143,7 +143,7 @@ impl Mempool { if self.tx_queue.get_nonce(sender_address).is_none() { if let Some(tx_reference) = self.tx_pool.get_by_address_and_nonce(sender_address, nonce) { - self.tx_queue.insert(*tx_reference); + self.tx_queue.insert(tx_reference.clone()); } } @@ -198,7 +198,7 @@ impl Mempool { if let Some(next_tx_reference) = self.tx_pool.get_next_eligible_tx(current_account_state)? { - self.tx_queue.insert(*next_tx_reference); + self.tx_queue.insert(next_tx_reference.clone()); } } @@ -215,12 +215,13 @@ impl Mempool { /// execution fields). /// TODO(Mohammad): rename this struct to `ThinTransaction` once that name /// becomes available, to better reflect its purpose and usage. -#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] +#[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct TransactionReference { pub sender_address: ContractAddress, pub nonce: Nonce, pub tx_hash: TransactionHash, pub tip: Tip, + pub resource_bounds: ResourceBoundsMapping, } impl TransactionReference { @@ -230,6 +231,8 @@ impl TransactionReference { nonce: tx.nonce, tx_hash: tx.tx_hash, tip: tx.tip, + // TODO(Mohammad): add resource bounds to the transaction. + resource_bounds: ResourceBoundsMapping::default(), } } } diff --git a/crates/mempool/src/mempool_test.rs b/crates/mempool/src/mempool_test.rs index 6343b02e12..045e72076d 100644 --- a/crates/mempool/src/mempool_test.rs +++ b/crates/mempool/src/mempool_test.rs @@ -350,7 +350,7 @@ fn test_get_txs_with_holes_single_account() { let pool_txs = [input_nonce_1.tx]; let queue_txs = []; - let mut mempool: Mempool = MempoolContent::new(pool_txs.clone(), queue_txs).into(); + let mut mempool: Mempool = MempoolContent::new(pool_txs.clone(), queue_txs.clone()).into(); // Test. let txs = mempool.get_txs(1).unwrap(); @@ -441,7 +441,7 @@ fn test_add_tx_lower_than_queued_nonce() { add_tx_input!(tx_hash: 2, sender_address: "0x0", tx_nonce: 0_u8, account_nonce: 0_u8); let queue_txs = [TransactionReference::new(&valid_input.tx)]; - let expected_mempool_content = MempoolContent::with_queue(queue_txs); + let expected_mempool_content = MempoolContent::with_queue(queue_txs.clone()); let pool_txs = [valid_input.tx]; let mut mempool: Mempool = MempoolContent::new(pool_txs, queue_txs).into(); @@ -594,7 +594,7 @@ fn test_commit_block_includes_all_txs() { let queue_txs = [&tx_address0_nonce4, &tx_address1_nonce3, &tx_address2_nonce1] .map(TransactionReference::new); let pool_txs = [tx_address0_nonce4, tx_address0_nonce5, tx_address1_nonce3, tx_address2_nonce1]; - let mut mempool: Mempool = MempoolContent::new(pool_txs.clone(), queue_txs).into(); + let mut mempool: Mempool = MempoolContent::new(pool_txs.clone(), queue_txs.clone()).into(); // Test. let state_changes = HashMap::from([ diff --git a/crates/mempool/src/transaction_queue.rs b/crates/mempool/src/transaction_queue.rs index 72ec458929..4863ea9ac8 100644 --- a/crates/mempool/src/transaction_queue.rs +++ b/crates/mempool/src/transaction_queue.rs @@ -22,7 +22,7 @@ impl TransactionQueue { // assert. pub fn insert(&mut self, tx: TransactionReference) { assert_eq!( - self.address_to_tx.insert(tx.sender_address, tx), + self.address_to_tx.insert(tx.sender_address, tx.clone()), None, "Only a single transaction from the same contract class can be in the mempool at a \ time."