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(mempool): insert eligible tx to tx queue in commit-block accordi… #464

Merged

Conversation

MohammadNassar1
Copy link
Contributor

@MohammadNassar1 MohammadNassar1 commented Jul 14, 2024

…ng to state changes


This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 81.16%. Comparing base (231b340) to head (a403fef).

Files Patch % Lines
crates/mempool/src/mempool.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #464      +/-   ##
==========================================
- Coverage   81.38%   81.16%   -0.23%     
==========================================
  Files          42       42              
  Lines        1816     1821       +5     
  Branches     1816     1821       +5     
==========================================
  Hits         1478     1478              
- Misses        264      269       +5     
  Partials       74       74              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor Author

@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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @elintul, and @giladchase)

a discussion (no related file):
This PR adds an eligible transaction to the tx_queue based on the state changes.
It inserts new transactions in commit_block from another leader, provided the transaction is already present in the tx_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 r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)


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

                if let Some(tx) = self.tx_pool.get_by_address_and_nonce(address, nonce) {
                    self.tx_queue.insert(*tx);
                }

Can this be moved into the scope of removing from the Q?

Code quote:

                if let Some(tx) = self.tx_pool.get_by_address_and_nonce(address, nonce) {
                    self.tx_queue.insert(*tx);
                }

Copy link
Contributor Author

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


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

Previously, elintul (Elin) wrote…

Can this be moved into the scope of removing from the Q?

Not sure I get it :)

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 92 at r1 (raw file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Not sure I get it :)

        for (address, AccountState { nonce }) in state_changes {
            if self.tx_queue.get_nonce(address).is_some_and(|queued_nonce| queued_nonce != nonce) {
                self.tx_queue.remove(address);

                if let Some(tx) = self.tx_pool.get_by_address_and_nonce(address, nonce) {
                    self.tx_queue.insert(*tx);
                }
            }
        }

What am I missing?
Maybe we should add a get_next_eligible_tx(account) API?

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 80 at r1 (raw file):

            //    block, applicable when the block is from the same leader.
            // 2. Remove a transaction from queue with nonce greater than those committed to the
            //    block, applicable when the block is from a different leader.

I think this doc. is too extensive, not sure I want to reference consensus (it's our of scope). Perhaps saying // Align the queue with the committed nonces..
I also think it can appear in one paragraph:

// Align the queue with the committed nonces.
if self.tx_queue.get_nonce(address).is_some_and(|queued_nonce| queued_nonce != next_nonce) {
    self.tx_queue.remove(address);
}

if self.tx_queue.get_nonce(address).is_none() {
    if let Some(next_eligible_tx) = self.tx_pool.get_by_address_and_nonce(address, next_nonce) {
        self.tx_queue.insert(*next_eligible_tx);
    }
}

Where do we have get_next_eligible_tx API? It can be used here, right?

Code quote:

            // Dequeue transactions from the queue in the following cases:
            // 1. Remove a transaction from queue with nonce lower than those committed to the
            //    block, applicable when the block is from the same leader.
            // 2. Remove a transaction from queue with nonce greater than those committed to the
            //    block, applicable when the block is from a different leader.

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/commit-block/add-eligible-txs-to-queue branch from 554b01f to a26b234 Compare July 23, 2024 09:02
Copy link
Contributor Author

@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: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)


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

Previously, elintul (Elin) wrote…

I think this doc. is too extensive, not sure I want to reference consensus (it's our of scope). Perhaps saying // Align the queue with the committed nonces..
I also think it can appear in one paragraph:

// Align the queue with the committed nonces.
if self.tx_queue.get_nonce(address).is_some_and(|queued_nonce| queued_nonce != next_nonce) {
    self.tx_queue.remove(address);
}

if self.tx_queue.get_nonce(address).is_none() {
    if let Some(next_eligible_tx) = self.tx_pool.get_by_address_and_nonce(address, next_nonce) {
        self.tx_queue.insert(*next_eligible_tx);
    }
}

Where do we have get_next_eligible_tx API? It can be used here, right?

Thanks, updated.

This my my next_elegible method:
self.tx_pool.get_by_address_and_nonce(address, nonce).


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

Previously, elintul (Elin) wrote…
        for (address, AccountState { nonce }) in state_changes {
            if self.tx_queue.get_nonce(address).is_some_and(|queued_nonce| queued_nonce != nonce) {
                self.tx_queue.remove(address);

                if let Some(tx) = self.tx_pool.get_by_address_and_nonce(address, nonce) {
                    self.tx_queue.insert(*tx);
                }
            }
        }

What am I missing?
Maybe we should add a get_next_eligible_tx(account) API?

The code has been updated. See the above comment.

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 80 at r1 (raw file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Thanks, updated.

This my my next_elegible method:
self.tx_pool.get_by_address_and_nonce(address, nonce).

I think it can be a method (can be done in a separated PR), and also shared with replenishing logic.

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:

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

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


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

            }

            // TODO: remove the transactions from the tx_pool.

Can be in another PR.

Suggestion:

            }
            
            if self.tx_queue.get_nonce(address).is_none() {
                if let Some(tx) = self.tx_pool.get_by_address_and_nonce(address, nonce) {
                    self.tx_queue.insert(*tx);
                }
            }

            // TODO: remove the transactions from the tx_pool.

Copy link
Contributor Author

@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: all files reviewed, 3 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)


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

Previously, elintul (Elin) wrote…

I think it can be a method (can be done in a separated PR), and also shared with replenishing logic.

Okay, we'll do in another PR.

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)

@MohammadNassar1 MohammadNassar1 changed the base branch from mohammad/mempool/commit-block/temove-transactions-from-queue to main July 23, 2024 13:35
@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/commit-block/add-eligible-txs-to-queue branch from a26b234 to 6de72da Compare July 23, 2024 13:38
@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/commit-block/add-eligible-txs-to-queue branch from 6de72da to a403fef Compare July 23, 2024 13:38
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 r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware and @giladchase)

@MohammadNassar1 MohammadNassar1 merged commit 5b08d60 into main Jul 23, 2024
8 checks passed
@MohammadNassar1 MohammadNassar1 deleted the mohammad/mempool/commit-block/add-eligible-txs-to-queue branch July 23, 2024 13:46
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