From eab9d28e107b579a35188765cf04a60d37988f7d Mon Sep 17 00:00:00 2001 From: mohammad-starkware <130282237+MohammadNassar1@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:09:53 +0300 Subject: [PATCH] chore(mempool): derive copy for transaction reference struct (#836) --- crates/mempool/src/mempool.rs | 7 +++---- crates/mempool/src/mempool_test.rs | 6 +++--- crates/mempool/src/transaction_queue.rs | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/mempool/src/mempool.rs b/crates/mempool/src/mempool.rs index 69ebb05d92..7153323eee 100644 --- a/crates/mempool/src/mempool.rs +++ b/crates/mempool/src/mempool.rs @@ -164,7 +164,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.clone()); + self.tx_queue.insert(*next_tx_reference); } } @@ -199,7 +199,7 @@ impl Mempool { // Maybe close nonce gap. if self.tx_queue.get_nonce(address).is_none() { if let Some(tx_reference) = self.tx_pool.get_by_address_and_nonce(address, nonce) { - self.tx_queue.insert(tx_reference.clone()); + self.tx_queue.insert(*tx_reference); } } } @@ -214,8 +214,7 @@ impl Mempool { /// execution fields). /// TODO(Mohammad): rename this struct to `ThinTransaction` once that name /// becomes available, to better reflect its purpose and usage. -/// TODO(Mohammad): restore the Copy once ResourceBoundsMapping implements it. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct TransactionReference { pub sender_address: ContractAddress, pub nonce: Nonce, diff --git a/crates/mempool/src/mempool_test.rs b/crates/mempool/src/mempool_test.rs index 2a58675d1c..fbe82f8757 100644 --- a/crates/mempool/src/mempool_test.rs +++ b/crates/mempool/src/mempool_test.rs @@ -365,7 +365,7 @@ fn test_get_txs_with_holes_single_account() { let pool_txs = [input_nonce_1.tx]; let queue_txs = []; let mut mempool: Mempool = - MempoolContent::with_pool_and_queue(pool_txs.clone(), queue_txs.clone()).into(); + MempoolContent::with_pool_and_queue(pool_txs.clone(), queue_txs).into(); // Test. let txs = mempool.get_txs(1).unwrap(); @@ -507,7 +507,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.clone()); + let expected_mempool_content = MempoolContent::with_queue(queue_txs); let pool_txs = [valid_input.tx]; let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queue_txs).into(); @@ -706,7 +706,7 @@ fn test_commit_block_includes_all_txs() { .map(TransactionReference::new); let pool_txs = [tx_address0_nonce4, tx_address0_nonce5, tx_address1_nonce3, tx_address2_nonce1]; let mut mempool: Mempool = - MempoolContent::with_pool_and_queue(pool_txs.clone(), queue_txs.clone()).into(); + MempoolContent::with_pool_and_queue(pool_txs.clone(), queue_txs).into(); // Test. let state_changes = HashMap::from([ diff --git a/crates/mempool/src/transaction_queue.rs b/crates/mempool/src/transaction_queue.rs index a550a83208..1ffe2988b5 100644 --- a/crates/mempool/src/transaction_queue.rs +++ b/crates/mempool/src/transaction_queue.rs @@ -31,7 +31,7 @@ impl TransactionQueue { /// Panics: if given a duplicate tx. pub fn insert(&mut self, tx_reference: TransactionReference) { assert_eq!( - self.address_to_tx.insert(tx_reference.sender_address, tx_reference.clone()), + self.address_to_tx.insert(tx_reference.sender_address, tx_reference), None, "Only a single transaction from the same contract class can be in the mempool at a \ time." @@ -77,7 +77,7 @@ impl TransactionQueue { return false; }; - self.priority_queue.remove(&tx_reference.clone().into()) + self.priority_queue.remove(&tx_reference.into()) || self.pending_queue.remove(&tx_reference.into()) }