Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use mempool::empty everywhere #271

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -60,10 +65,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
Loading