Skip to content

Commit

Permalink
refactor: use mempool::empty everywhere (#271)
Browse files Browse the repository at this point in the history
Also impl with `Default`.

Co-Authored-By: Gilad Chase <gilad@starkware.com>
  • Loading branch information
giladchase and Gilad Chase authored Jun 24, 2024
1 parent e26cb96 commit 3a24fb1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
11 changes: 7 additions & 4 deletions crates/gateway/src/gateway_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use blockifier::context::ChainInfo;
use blockifier::test_utils::CairoVersion;
use rstest::rstest;
use rstest::{fixture, rstest};
use starknet_api::rpc_transaction::RPCTransaction;
use starknet_api::transaction::TransactionHash;
use starknet_mempool::communication::create_mempool_server;
Expand All @@ -28,6 +28,11 @@ use crate::utils::{external_tx_to_account_tx, get_tx_hash};

const MEMPOOL_INVOCATIONS_QUEUE_SIZE: usize = 32;

#[fixture]
fn mempool() -> Mempool {
Mempool::empty()
}

pub fn app_state(
mempool_client: SharedMempoolClient,
state_reader_factory: TestStateReaderFactory,
Expand Down Expand Up @@ -67,10 +72,8 @@ pub fn app_state(
async fn test_add_tx(
#[case] tx: RPCTransaction,
#[case] state_reader_factory: TestStateReaderFactory,
mempool: Mempool,
) {
// TODO: Add fixture.

let mempool = Mempool::new([]);
// TODO(Tsabary): wrap creation of channels in dedicated functions, take channel capacity from
// config.
let (tx_mempool, rx_mempool) =
Expand Down
10 changes: 3 additions & 7 deletions crates/mempool/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::transaction_pool::TransactionPool;
#[path = "mempool_test.rs"]
pub mod mempool_test;

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Mempool {
// TODO: add docstring explaining visibility and coupling of the fields.
txs_queue: TransactionPriorityQueue,
Expand All @@ -25,11 +25,7 @@ pub struct Mempool {

impl Mempool {
pub fn new(inputs: impl IntoIterator<Item = MempoolInput>) -> Self {
let mut mempool = Mempool {
txs_queue: TransactionPriorityQueue::default(),
tx_pool: TransactionPool::default(),
state: HashMap::default(),
};
let mut mempool = Mempool::empty();

for MempoolInput { tx, account: Account { sender_address, state } } in inputs.into_iter() {
// Attempts to insert a key-value pair into the mempool's state. Returns `None`
Expand Down Expand Up @@ -57,7 +53,7 @@ impl Mempool {
}

pub fn empty() -> Self {
Mempool::new([])
Mempool::default()
}

/// Retrieves up to `n_txs` transactions with the highest priority from the mempool.
Expand Down
2 changes: 1 addition & 1 deletion crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ macro_rules! add_tx_input {

#[fixture]
fn mempool() -> Mempool {
Mempool::new([])
Mempool::empty()
}

#[rstest]
Expand Down

0 comments on commit 3a24fb1

Please sign in to comment.