-
Notifications
You must be signed in to change notification settings - Fork 27
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
Conversation
299153f
to
b6af979
Compare
2649967
to
724c44d
Compare
There was a problem hiding this 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);
There was a problem hiding this 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.
8ef6446
to
1f32454
Compare
724c44d
to
2929df4
Compare
There was a problem hiding this 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:
- We add the new transaction to the pool.
- 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.
- We check if there’s a transaction in the pool with the current account nonce. If there is, we insert it into the queue.
- 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.
There was a problem hiding this 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:
- We add the new transaction to the pool.
- 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.
- We check if there’s a transaction in the pool with the current account nonce. If there is, we insert it into the queue.
- 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.
1f32454
to
369e892
Compare
There was a problem hiding this 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?
There was a problem hiding this 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
andcommit_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.
There was a problem hiding this 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.
2929df4
to
6884a0d
Compare
There was a problem hiding this 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 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.
6884a0d
to
80f1bd5
Compare
There was a problem hiding this 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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @giladchase)
80f1bd5
to
0a347a6
Compare
There was a problem hiding this 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.
0a347a6
to
5e86960
Compare
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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
There was a problem hiding this 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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @giladchase)
rearrange insert_tx func before refactoring code to share code functionality
This change is