Skip to content

Commit

Permalink
Use actual chunks left (#2354)
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Mar 22, 2023
1 parent fd0f353 commit d354026
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
7 changes: 2 additions & 5 deletions core/bin/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,8 @@ pub async fn run_core(
);

// Start mempool.
let mempool_block_handler_task = run_mempool_block_handler(
connection_pool.clone(),
mempool_block_request_receiver,
config.chain.state_keeper.block_chunk_sizes.clone(),
);
let mempool_block_handler_task =
run_mempool_block_handler(connection_pool.clone(), mempool_block_request_receiver);

// Start token handler.
let token_handler_task = run_token_handler(
Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_core/src/state_keeper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ impl ZkSyncStateKeeper {
block_timestamp,
response_sender,
executed_txs,
chunks_left: self.pending_block.chunks_left,
});

self.tx_for_mempool
Expand Down
6 changes: 4 additions & 2 deletions core/lib/mempool/src/block_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl ProposedBlock {
pub struct GetBlockRequest {
pub last_priority_op_number: u64,
pub block_timestamp: u64,
pub chunks_left: usize,
pub executed_txs: Vec<TxHash>,
pub response_sender: oneshot::Sender<ProposedBlock>,
}
Expand All @@ -46,14 +47,14 @@ pub enum MempoolBlocksRequest {
pub(crate) struct MempoolBlocksHandler {
pub mempool_state: MempoolState,
pub requests: mpsc::Receiver<MempoolBlocksRequest>,
pub max_block_size_chunks: usize,
}

impl MempoolBlocksHandler {
async fn propose_new_block(
&mut self,
current_unprocessed_priority_op: u64,
block_timestamp: u64,
chunks_left: usize,
executed_txs: &[TxHash],
) -> Result<ProposedBlock, TxAddError> {
let start = std::time::Instant::now();
Expand All @@ -66,7 +67,7 @@ impl MempoolBlocksHandler {

let (txs, priority_ops, chunks_left) = tx_queue
.select_transactions(
self.max_block_size_chunks,
chunks_left,
current_unprocessed_priority_op,
block_timestamp,
&self.mempool_state,
Expand Down Expand Up @@ -121,6 +122,7 @@ impl MempoolBlocksHandler {
.propose_new_block(
block.last_priority_op_number,
block.block_timestamp,
block.chunks_left,
&block.executed_txs,
)
.await
Expand Down
6 changes: 0 additions & 6 deletions core/lib/mempool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,12 @@ pub fn run_mempool_tx_handler(
pub fn run_mempool_block_handler(
db_pool: ConnectionPool,
block_requests: mpsc::Receiver<MempoolBlocksRequest>,
block_chunk_sizes: Vec<usize>,
) -> JoinHandle<()> {
let mempool_state = MempoolState::new(db_pool);
let max_block_size_chunks = *block_chunk_sizes
.iter()
.max()
.expect("failed to find max block chunks size");

let blocks_handler = MempoolBlocksHandler {
mempool_state,
requests: block_requests,
max_block_size_chunks,
};

tokio::spawn(blocks_handler.run())
Expand Down

0 comments on commit d354026

Please sign in to comment.