Skip to content

apollo_mempool: same block logic#13300

Merged
ayeletstarkware merged 1 commit intomainfrom
ayelet/mempool/fifo/same-block-logic
Mar 26, 2026
Merged

apollo_mempool: same block logic#13300
ayeletstarkware merged 1 commit intomainfrom
ayelet/mempool/fifo/same-block-logic

Conversation

@ayeletstarkware
Copy link
Copy Markdown
Contributor

@ayeletstarkware ayeletstarkware commented Mar 17, 2026

Note

Medium Risk
Changes FIFO mempool batching semantics to depend on both timestamp and block_number, including emitting empty results on block gaps and realigning after rewinds; this affects block-building behavior and could impact liveness/ordering if edge cases are missed.

Overview
FIFO (Echonet) transaction batching is now block-aware. The FIFO queue replaces the single last_returned_timestamp gate with a CurrentProposalState that tracks the proposal timestamp, the expected_block_number, and whether an empty block should be emitted.

get_txs/has_ready_txs/iter_over_ready_txs now only return transactions matching the current proposal’s (timestamp, expected_block_number), advance expected_block_number once a block is drained, return an empty chunk once when a block-number gap is detected, and realign to earlier blocks when rewound transactions reappear at the head.

Adds targeted tests covering: same-block retrieval across multiple get_txs chunks, block-number gaps (single and long), resolving timestamps after the queue is emptied and after new txs arrive, and rewind scenarios that continue within the same block or realign to an earlier block.

Written by Cursor Bugbot for commit 4575a22. This will update automatically on new commits. Configure here.

@ayeletstarkware ayeletstarkware marked this pull request as ready for review March 17, 2026 09:53
@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/fifo/same-block-logic branch 2 times, most recently from 8dc2c20 to fa6269e Compare March 24, 2026 14:45
@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/fifo/same-block-logic branch 2 times, most recently from e92d95a to 3820494 Compare March 25, 2026 14:23
Copy link
Copy Markdown
Contributor

@ron-starkware ron-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ron-starkware reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on ayeletstarkware).

Copy link
Copy Markdown
Collaborator

@matanl-starkware matanl-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matanl-starkware reviewed 2 files and all commit messages, and made 4 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on ayeletstarkware).


crates/apollo_mempool/src/fifo_transaction_queue.rs line 223 at r1 (raw file):

    fn pop_ready_chunk(&mut self, n_txs: usize) -> Vec<TransactionReference> {
        let Some(mut current_state) = self.current_proposal_state else {

Avoid unnecessary move, and then you don't need the last self.current_proposal_state = Some(current_state);

Suggestion:

let Some(current_state) = self.current_proposal_state.as_mut() else {

crates/apollo_mempool/src/fifo_transaction_queue.rs line 232 at r1 (raw file):

            // Queue is empty, nothing to return.
            return Vec::new();
        };

Check this before the non-None current_proposal_state panic

Code quote:

        let Some(front_tx) = self.queue.front() else {
            // Queue is empty, nothing to return.
            return Vec::new();
        };

crates/apollo_mempool/src/fifo_transaction_queue.rs line 307 at r1 (raw file):

            (Some(state), Some(front_tx)) => state.matches_tx(front_tx),
            _ => false,
        }

I like !

Code quote:

        match (self.current_proposal_state, self.queue.front()) {
            (Some(state), Some(front_tx)) => state.matches_tx(front_tx),
            _ => false,
        }

crates/apollo_mempool/src/fifo_transaction_queue.rs line 315 at r1 (raw file):

                .iter()
                .take_while(|tx| {
                    self.current_proposal_state.is_some_and(|state| state.matches_tx(tx))

Extract outside the for loop

Code quote:

self.current_proposal_state.is_some_and(|state| state

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/fifo/same-block-logic branch from 3820494 to 6fc960a Compare March 26, 2026 10:06
Copy link
Copy Markdown
Contributor Author

@ayeletstarkware ayeletstarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayeletstarkware made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on matanl-starkware).


crates/apollo_mempool/src/fifo_transaction_queue.rs line 223 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

Avoid unnecessary move, and then you don't need the last self.current_proposal_state = Some(current_state);

Done.


crates/apollo_mempool/src/fifo_transaction_queue.rs line 315 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

Extract outside the for loop

Done.

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/fifo/same-block-logic branch from 6fc960a to 4575a22 Compare March 26, 2026 10:47
Copy link
Copy Markdown
Collaborator

@matanl-starkware matanl-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matanl-starkware reviewed 2 files and all commit messages, and resolved 2 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on ayeletstarkware).

@ayeletstarkware ayeletstarkware added this pull request to the merge queue Mar 26, 2026
Merged via the queue into main with commit bb13178 Mar 26, 2026
26 of 37 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants