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

feat(starknet_mempool): remove old transaction from the mempool in get_txs #4115

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

dafnamatsry
Copy link
Collaborator

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

@dafnamatsry dafnamatsry marked this pull request as ready for review February 12, 2025 09:35
@dafnamatsry dafnamatsry changed the base branch from add_tx_ttl_cleanup to main February 16, 2025 09:41
Copy link
Collaborator

@alonh5 alonh5 left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @alonh5 and @ayeletstarkware)


crates/starknet_mempool/src/mempool_test.rs line 977 at r2 (raw file):

    // Only the second transaction should be returned from get_txs, and the first should be removed.
    assert_eq!(mempool.get_txs(2).unwrap(), vec![second_tx.tx.clone()]);

This isn't testing the get_txs removal because you're calling add_tx before.

Code quote:

    // Only the second transaction should be returned from get_txs, and the first should be removed.
    assert_eq!(mempool.get_txs(2).unwrap(), vec![second_tx.tx.clone()]);

crates/starknet_mempool/src/mempool.rs line 199 at r2 (raw file):

                    .remove(tx.tx_hash)
                    .expect("Transaction hash from queue must appear in pool.");
            }

Consider extracting into function.

Code quote:

            // Divide the chunk into transactions that are old and no longer valid and those that
            // remain valid.
            let (old_txs, valid_txs): (Vec<_>, Vec<_>) = chunk.into_iter().partition(|tx| {
                self.tx_pool
                    .get_submission_time(tx.tx_hash)
                    .expect("Transaction hash from queue must appear in pool.")
                    .elapsed()
                    > self.config.transaction_ttl
            });

            // Remove old transactions from the pool.
            for tx in old_txs {
                self.tx_pool
                    .remove(tx.tx_hash)
                    .expect("Transaction hash from queue must appear in pool.");
            }

Copy link
Collaborator Author

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @alonh5 and @ayeletstarkware)


crates/starknet_mempool/src/mempool.rs line 199 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Consider extracting into function.

Done.

Copy link
Collaborator

@alonh5 alonh5 left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware and @dafnamatsry)


crates/starknet_mempool/src/mempool.rs line 419 at r4 (raw file):

    // Given a chunk of transactions, removes from the pool those that are old, and returns the
    // remaining valid ones.
    // Note: This function assumes that the given transactions were already removed from the queue.

Suggestion:

    /// Given a chunk of transactions, removes from the pool those that are old, and returns the
    /// remaining valid ones.
    /// Note: This function assumes that the given transactions were already removed from the queue.

Copy link
Collaborator Author

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @alonh5 and @ayeletstarkware)


crates/starknet_mempool/src/mempool.rs line 419 at r4 (raw file):

    // Given a chunk of transactions, removes from the pool those that are old, and returns the
    // remaining valid ones.
    // Note: This function assumes that the given transactions were already removed from the queue.

Done.

Copy link
Collaborator

@alonh5 alonh5 left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware)

Copy link
Collaborator Author

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @alonh5 and @ayeletstarkware)


crates/starknet_mempool/src/mempool_test.rs line 977 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

This isn't testing the get_txs removal because you're calling add_tx before.

Right! thanks :)
Had to change the mempool a bit, to use the clock.now()

Copy link
Collaborator

@alonh5 alonh5 left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware)


crates/starknet_mempool/src/mempool.rs line 431 at r6 (raw file):

            let tx_submission_time = self
                .tx_pool
                .get_submission_time(tx.tx_hash)

Instead of cloning the clock and having it in both places, how about you implement is_expired for tx pool instead of get_submission_time?

Copy link
Collaborator Author

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @alonh5 and @ayeletstarkware)


crates/starknet_mempool/src/mempool.rs line 431 at r6 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Instead of cloning the clock and having it in both places, how about you implement is_expired for tx pool instead of get_submission_time?

It would require implementing it both in TransactionPool and TimedTransactionMap. I think it's easier to just hold the clock. Might be useful for future things we might have as well.

Copy link
Collaborator

@alonh5 alonh5 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware)

@dafnamatsry dafnamatsry added this pull request to the merge queue Feb 18, 2025
Merged via the queue into main with commit 03edc36 Feb 18, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants