-
Notifications
You must be signed in to change notification settings - Fork 11
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: update priority queue to use ThinPriorityTransaction #195
refactor: update priority queue to use ThinPriorityTransaction #195
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #195 +/- ##
==========================================
+ Coverage 84.55% 84.60% +0.04%
==========================================
Files 28 28
Lines 1360 1364 +4
Branches 1360 1364 +4
==========================================
+ Hits 1150 1154 +4
Misses 151 151
Partials 59 59 ☔ View full report in Codecov by Sentry. |
6c42d40
to
7a0cf05
Compare
0a5e971
to
ac99c1c
Compare
88b2471
to
9a3b04a
Compare
ac99c1c
to
d2084c2
Compare
9a3b04a
to
63c6246
Compare
d2084c2
to
03ce42f
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 3 files reviewed, 4 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 35 at r3 (raw file):
tx_store: TransactionStore::default(), state: HashMap::default(), };
Unrelated to this PR, do we want to impl. Default
for Mempool
?
@giladchase, feel free to answer too.
Code quote:
let mut mempool = Mempool {
txs_queue: TransactionPriorityQueue::default(),
tx_store: TransactionStore::default(),
state: HashMap::default(),
};
crates/mempool/src/mempool.rs
line 41 at r3 (raw file):
// if the key was not present, otherwise returns the old value while updating // the new value. let prev_value = mempool.state.insert(input.account.address, input.account.state);
Please unpack earlier.
Code quote:
input.account.address, input.account.state
crates/mempool/src/mempool.rs
line 41 at r3 (raw file):
// if the key was not present, otherwise returns the old value while updating // the new value. let prev_value = mempool.state.insert(input.account.address, input.account.state);
Suggestion:
existing_account_state
crates/mempool/src/mempool.rs
line 58 at r3 (raw file):
); mempool.txs_queue.push(input.tx.clone().into());
Why this change?
Code quote:
mempool.txs_queue.push(input.tx.clone().into());
03ce42f
to
9043ca6
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 3 files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/mempool.rs
line 58 at r3 (raw file):
Previously, elintul (Elin) wrote…
Why this change?
Now I store ThinPriorityTransaction
in txs_queue
.
And the transaction is stored in tx_store.
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 3 files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/mempool.rs
line 35 at r3 (raw file):
Previously, elintul (Elin) wrote…
Unrelated to this PR, do we want to impl.
Default
forMempool
?
@giladchase, feel free to answer too.
Currently empty returns default Mempool.
Do you want to replace it with default trait impl?
63c6246
to
92bfb61
Compare
9043ca6
to
f5e0c9a
Compare
92bfb61
to
42497f2
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 6 files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware and @giladchase)
crates/mempool/src/mempool.rs
line 41 at r3 (raw file):
Previously, elintul (Elin) wrote…
Please unpack earlier.
Use unpacking syntax instead: let MempoolInput { sender address, state } = mempool_input
.
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 6 of 6 files at r5, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @elintul, @giladchase, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 43 at r5 (raw file):
// the new value. let address = input.account.sender_address; let state = input.account.state;
why is it necessary?
Code quote:
let address = input.account.sender_address;
let state = input.account.state;
crates/mempool/src/mempool.rs
line 81 at r5 (raw file):
let mut txs: Vec<ThinTransaction> = Vec::default(); for pq_tx in &pq_txs { let tx = self.tx_store.remove(&pq_tx.tx_hash)?;
Why do you delete the txs from the tx_store?
crates/mempool/src/mempool_test.rs
line 152 at r5 (raw file):
.iter() .zip(mempool_txs) .all(|(a, b)| <ThinTransaction as Into<ThinPriorityTransaction>>::into(a.clone()) == *b);
I find it hard to read
consider changing to something like this:
Code snippet:
fn check_mempool_txs_eq(mempool: &Mempool, expected_txs: &[ThinTransaction]) -> bool {
let mempool_txs = mempool.txs_queue.iter();
// Convert and compare transactions
let transactions_match = expected_txs.iter().zip(mempool_txs).all(|(expected, actual)| {
let expected_converted: ThinPriorityTransaction = expected.clone().into();
expected_converted == *actual
});
transactions_match
}
crates/mempool/src/priority_queue.rs
line 26 at r5 (raw file):
} impl From<Vec<ThinTransaction>> for TransactionPriorityQueue {
Why did you delete it?
crates/mempool/src/priority_queue.rs
line 28 at r5 (raw file):
#[derive(Clone, Debug, Default)] pub struct ThinPriorityTransaction {
Why not PrioritizedTransaction
? It referred to ThinTransaction
before without mentioning it.
Code quote:
ThinPriorityTransaction
crates/mempool/src/transaction_store.rs
line 2 at r5 (raw file):
use std::collections::HashMap;
Perhaps you could remove the commit - 92bfb61: feat: add transaction store data structure
so it doesn't appear to be part of the PR.
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, 8 unresolved discussions (waiting on @elintul, @giladchase, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 81 at r5 (raw file):
Previously, ayeletstarkware (Ayelet Zilber) wrote…
Why do you delete the txs from the tx_store?
I guess it's part of inserting it into a staging area? If so, add a todo in this PR
42497f2
to
c43438c
Compare
f5e0c9a
to
e798bc7
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, 8 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/mempool.rs
line 43 at r5 (raw file):
Previously, ayeletstarkware (Ayelet Zilber) wrote…
why is it necessary?
Removed
crates/mempool/src/mempool.rs
line 81 at r5 (raw file):
Previously, ayeletstarkware (Ayelet Zilber) wrote…
I guess it's part of inserting it into a staging area? If so, add a todo in this PR
This Pr doesn't implement staging area.
So currently we delete tx in get_txs
.
e798bc7
to
eb6791e
Compare
c43438c
to
0f7462a
Compare
fba5cb8
to
ec0dae6
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 8 files reviewed, 8 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/mempool_test.rs
line 152 at r5 (raw file):
Previously, ayeletstarkware (Ayelet Zilber) wrote…
I find it hard to read
consider changing to something like this:
Done.
crates/mempool/src/priority_queue.rs
line 26 at r5 (raw file):
Previously, ayeletstarkware (Ayelet Zilber) wrote…
Why did you delete it?
Not in use anymore.
crates/mempool/src/priority_queue.rs
line 28 at r5 (raw file):
Previously, ayeletstarkware (Ayelet Zilber) wrote…
Why not
PrioritizedTransaction
? It referred toThinTransaction
before without mentioning it.
Changed back to PrioritizedTransaction
crates/mempool/src/transaction_store.rs
line 2 at r5 (raw file):
Previously, ayeletstarkware (Ayelet Zilber) wrote…
Perhaps you could remove the commit
- 92bfb61: feat: add transaction store data structure
so it doesn't appear to be part of the PR.
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.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @elintul)
crates/mempool/src/mempool.rs
line 49 at r6 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
+1
rust doesn't support format!("{foo.bar}")
, or similarly format!("{foo.bar:?}"
.
It only supports format!("{foo.bar}")
, or similarly format!("{foo.bar:?}"
.
I can't find it in the diff now, but for a while the access to sender address was through tx.sender_address, which made it impossible to use the former form, but now it is possible to use the latter form since sender_address is unpacked into a variable.
crates/mempool/src/priority_queue.rs
line 29 at r12 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Since it's a pub (crate) file, it needs to be used. Alternatively, I can add "allow dead code" instead.
WDYT?
Let's add to mempool iter_queue() -> Impl Iterator
which uses this.
It's a very useful API method to expose, even if we don't use it outside of tests.
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)
crates/mempool/src/priority_queue.rs
line 29 at r12 (raw file):
Previously, giladchase wrote…
Let's add to mempool
iter_queue() -> Impl Iterator
which uses this.It's a very useful API method to expose, even if we don't use it outside of tests.
What mempool iterator should return? only the txs in priority queue?
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 @MohammadNassar1)
crates/mempool/src/transaction_pool.rs
line 32 at r12 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
We return a duplicated error if the transaction already exists.
and panic we added for the case that cannot happen (consistency error) that tx appears in one (account) mapping and doesn't appear in the other (store) mapping.
Then, panic is added in the second if condition.
We should return MempoolError::DuplicateTransaction
when the transaction hash is duplicated; it is not what currently happens.
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)
crates/mempool/src/transaction_pool.rs
line 32 at r12 (raw file):
Previously, elintul (Elin) wrote…
We should return
MempoolError::DuplicateTransaction
when the transaction hash is duplicated; it is not what currently happens.
Shouldn't we return a duplication error if we have a transaction from the same account and the same nonce?
We don't support fee escalation, so we don't allow adding another tx with the same 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.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @elintul)
crates/mempool/src/priority_queue.rs
line 29 at r12 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
What mempool iterator should return? only the txs in priority queue?
Yep.
That's what id expect iter_queue() to return, I think.
Do you think it's OK?
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)
crates/mempool/src/priority_queue.rs
line 29 at r12 (raw file):
Previously, giladchase wrote…
Yep.
That's what id expect iter_queue() to return, I think.
Do you think it's OK?
What about the rest of the txs? (that are in store and not in tx_queue yet)
c1e1cb0
to
6249321
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: 6 of 11 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware and @elintul)
crates/mempool/src/priority_queue.rs
line 29 at r12 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
What about the rest of the txs? (that are in store and not in tx_queue yet)
I think in terms of API, that might be less useful to iterate.
I can see why someone would want to iterate the queue, to inspect what's in store, but iterating over ineligible txs I think would not be as useful.
060d6d8
to
72db2ad
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: 6 of 11 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/priority_queue.rs
line 29 at r12 (raw file):
Previously, giladchase wrote…
I think in terms of API, that might be less useful to iterate.
I can see why someone would want to iterate the queue, to inspect what's in store, but iterating over ineligible txs I think would not be as useful.
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 5 of 5 files at r15, 2 of 2 files at r17, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @MohammadNassar1)
crates/mempool/src/transaction_pool.rs
line 32 at r12 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Shouldn't we return a duplication error if we have a transaction from the same account and the same nonce?
We don't support fee escalation, so we don't allow adding another tx with the same nonce.
This is not exactly the error you're returning; it's not guaranteed that a transaction of same address and nonce will have the same hash. Let's either not implement this part, or add a new error variant. In any case, add a TODO here for fee escalation.
72db2ad
to
3aa3dc6
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: 10 of 11 files reviewed, all discussions resolved (waiting on @elintul)
crates/mempool/src/transaction_pool.rs
line 32 at r12 (raw file):
Previously, elintul (Elin) wrote…
This is not exactly the error you're returning; it's not guaranteed that a transaction of same address and nonce will have the same hash. Let's either not implement this part, or add a new error variant. In any case, add a TODO here for fee escalation.
Done
7d1be82
to
8b53e73
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: 7 of 11 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/transaction_queue.rs
line 51 at r21 (raw file):
} impl From<Vec<TransactionReference>> for TransactionQueue {
Implemented in another PR
Code quote:
impl From<Vec<TransactionReference>> for TransactionQueue
8b53e73
to
32324f7
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: 7 of 11 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/transaction_queue.rs
line 51 at r21 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Implemented in another PR
I mean removed in anther PR :)
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 3 files at r21, 2 of 2 files at r22, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware and @giladchase)
32324f7
to
8e1f437
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 5 files at r15, 2 of 3 files at r21, 2 of 2 files at r22, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @MohammadNassar1)
a discussion (no related file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Thanks!
I opened this PR. it renamePriorityTransaction
->QueuedTransaction
, andPrioritizedTransaction
->QueuedTransaction
. Also changedQueuedTransaction
to be private.
-- commits
line 2 at r23:
Note that the new commit message hints that this PR could have been broken down further, into two independent commits.
But let's get this merged as is for now.
Suggestion:
feat: change TransactionReference structure and change the return value of pop_last_chunk
Instead of reviewing PRs, she is having fun in London and hanging out with friends.
Reopen the branch |
This change is