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(mempool): rearrange insert_tx before refactoring code #470

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

ayeletstarkware
Copy link
Contributor

@ayeletstarkware ayeletstarkware commented Aug 15, 2024

rearrange insert_tx func before refactoring code to share code functionality


This change is Reviewable

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/add_tx/delete-tx-with-lower-nonce-from-queue branch from 299153f to b6af979 Compare August 15, 2024 09:24
@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/rearrange-insert-tx branch from 2649967 to 724c44d Compare August 15, 2024 10:34
Copy link
Contributor

@MohammadNassar1 MohammadNassar1 left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)


crates/mempool/src/mempool.rs line 136 at r1 (raw file):

        let MempoolInput { tx, account: Account { sender_address, state: AccountState { nonce } } } =
            input;

Please add in the test a check on the queue.


crates/mempool/src/mempool.rs line 153 at r1 (raw file):

        }

        self.tx_pool.remove_up_to_nonce(sender_address, nonce);

why did you move it here? after updating the queue?

Code quote:

self.tx_pool.remove_up_to_nonce(sender_address, nonce);

Copy link
Collaborator

@elintul elintul 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 r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)


crates/mempool/src/mempool.rs line 153 at r1 (raw file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

why did you move it here? after updating the queue?

Please explain why this is equivalent (the order doesn't matter); not sure I'm convinced.

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/add_tx/delete-tx-with-lower-nonce-from-queue branch 4 times, most recently from 8ef6446 to 1f32454 Compare August 18, 2024 11:07
@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/rearrange-insert-tx branch from 724c44d to 2929df4 Compare August 18, 2024 11:31
Copy link
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.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @elintul, @giladchase, and @MohammadNassar1)


crates/mempool/src/mempool.rs line 136 at r1 (raw file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Please add in the test a check on the queue.

added in #452


crates/mempool/src/mempool.rs line 153 at r1 (raw file):

Previously, elintul (Elin) wrote…

Please explain why this is equivalent (the order doesn't matter); not sure I'm convinced.

I moved it to align with the commit_block code.
Why is this equivalent? Let’s break down the steps:

  1. We add the new transaction to the pool.
  2. We check if the new transaction has a higher account nonce than the one in the queue. If it does, we remove the queued transaction.
  3. We check if there’s a transaction in the pool with the current account nonce. If there is, we insert it into the queue.
  4. We remove transactions from the pool with lower nonces than the current account nonce.

In this PR, I made two changes by reordering the steps:

  • Previously, step 4 (removing older nonce transactions from the pool) was the first step. I believe the order doesn’t matter because none of the other steps will interact with pool transactions that have lower nonces than the current account nonce.
  • The insertion of the pool transaction was originally between steps 2 and 3. I moved it to the first line. This change is safe because step 2 doesn’t modify the pool.

Copy link
Collaborator

@elintul elintul 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 r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)


crates/mempool/src/mempool.rs line 153 at r1 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

I moved it to align with the commit_block code.
Why is this equivalent? Let’s break down the steps:

  1. We add the new transaction to the pool.
  2. We check if the new transaction has a higher account nonce than the one in the queue. If it does, we remove the queued transaction.
  3. We check if there’s a transaction in the pool with the current account nonce. If there is, we insert it into the queue.
  4. We remove transactions from the pool with lower nonces than the current account nonce.

In this PR, I made two changes by reordering the steps:

  • Previously, step 4 (removing older nonce transactions from the pool) was the first step. I believe the order doesn’t matter because none of the other steps will interact with pool transactions that have lower nonces than the current account nonce.
  • The insertion of the pool transaction was originally between steps 2 and 3. I moved it to the first line. This change is safe because step 2 doesn’t modify the pool.

Why not: maybe remove from queue, then from pool; then add to pool, maybe remove from queue.
This is a more logical story to tell.

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/add_tx/delete-tx-with-lower-nonce-from-queue branch from 1f32454 to 369e892 Compare August 19, 2024 07:04
Copy link
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.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @elintul, @giladchase, and @MohammadNassar1)


crates/mempool/src/mempool.rs line 153 at r1 (raw file):

Previously, elintul (Elin) wrote…

Why not: maybe remove from queue, then from pool; then add to pool, maybe remove from queue.
This is a more logical story to tell.

I need the insertion to the pool to be the first or the last step since I'm extracting steps 2-4 to a function in #472. Anyway, can I change the order after extracting this logic to a function and use it in both add_tx and commit_block, so I won't have to change it in both?

Copy link
Collaborator

@elintul elintul 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, 2 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)


crates/mempool/src/mempool.rs line 153 at r1 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

I need the insertion to the pool to be the first or the last step since I'm extracting steps 2-4 to a function in #472. Anyway, can I change the order after extracting this logic to a function and use it in both add_tx and commit_block, so I won't have to change it in both?

It can't be last, since it affects what you maybe insert to the queue.
I'll reorder: maybe remove from queue, maybe remove from pool, add to pool, maybe add to queue.
When removing: you should first remove from the queue and then from pool; when inserting: you should first insert to pool, and then to queue. Perhaps we should separate removal and insertion.

Copy link
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.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @elintul, @giladchase, and @MohammadNassar1)


crates/mempool/src/mempool.rs line 153 at r1 (raw file):

Previously, elintul (Elin) wrote…

It can't be last, since it affects what you maybe insert to the queue.
I'll reorder: maybe remove from queue, maybe remove from pool, add to pool, maybe add to queue.
When removing: you should first remove from the queue and then from pool; when inserting: you should first insert to pool, and then to queue. Perhaps we should separate removal and insertion.

Done. commit_block doesn’t insert into the pool, so this order doesn’t work if we want to share code. However, this is out of scope for this PR—let’s discuss it F2F.

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/rearrange-insert-tx branch from 2929df4 to 6884a0d Compare August 19, 2024 11:33
Copy link
Collaborator

@elintul elintul left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @giladchase and @MohammadNassar1)


crates/mempool/src/mempool.rs line 153 at r1 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

Done. commit_block doesn’t insert into the pool, so this order doesn’t work if we want to share code. However, this is out of scope for this PR—let’s discuss it F2F.

Note you haven't changed anything in the end.

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/rearrange-insert-tx branch from 6884a0d to 80f1bd5 Compare August 19, 2024 14:59
Copy link
Contributor

@MohammadNassar1 MohammadNassar1 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, 1 unresolved discussion (waiting on @giladchase)

Copy link
Contributor

@MohammadNassar1 MohammadNassar1 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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase)

@ayeletstarkware ayeletstarkware changed the base branch from ayelet/mempool/add_tx/delete-tx-with-lower-nonce-from-queue to main August 20, 2024 08:24
@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/rearrange-insert-tx branch from 80f1bd5 to 0a347a6 Compare August 20, 2024 08:28
@ayeletstarkware ayeletstarkware changed the title refactor(mempool): rearrange insert_tx before refactoring code to sha… refactor(mempool): rearrange insert_tx before refactoring code Aug 20, 2024
Copy link
Collaborator

@elintul elintul 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 r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware and @giladchase)


crates/mempool/src/mempool.rs line 91 at r5 (raw file):

            // Align the queue with the committed nonces.

            // Remove transactions with lower nonces from the queue and the pool.

Please update documentation of both segments of code with the one we agreed on in #472.

Code quote:

// Remove transactions with lower nonces from the queue and the pool.

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/rearrange-insert-tx branch from 0a347a6 to 5e86960 Compare August 20, 2024 13:36
Copy link
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.

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @elintul and @giladchase)


crates/mempool/src/mempool.rs line 91 at r5 (raw file):

Previously, elintul (Elin) wrote…

Please update documentation of both segments of code with the one we agreed on in #472.

Done.

Copy link
Collaborator

@elintul elintul 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 and @giladchase)


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

        // Maybe remove out-of-date transactions.
        // Note: != is actually equivalent to > here, as lower nonces are rejected in validation.

This should also appear in the new method; please be minded that you're not deleting documentation when moving code.

Code quote:

Note: != is actually equivalent to > here, as lower nonces are rejected in validation.

Copy link
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.

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


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

Previously, elintul (Elin) wrote…

This should also appear in the new method; please be minded that you're not deleting documentation when moving code.

yes it's in the align function in #472

Copy link
Collaborator

@elintul elintul 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 @ayeletstarkware and @giladchase)


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

Previously, ayeletstarkware (Ayelet Zilber) wrote…

yes it's in the align function in #472

Great!

Copy link
Collaborator

@elintul elintul 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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase)

@ayeletstarkware ayeletstarkware merged commit 0a81470 into main Aug 20, 2024
10 checks passed
@ayeletstarkware ayeletstarkware deleted the ayelet/mempool/rearrange-insert-tx branch August 20, 2024 13:47
@ayeletstarkware ayeletstarkware restored the ayelet/mempool/rearrange-insert-tx branch August 20, 2024 14:01
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2024
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.

3 participants