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

fix(mempool): fix add-tx method by updating the queue according to in… #510

Closed

Conversation

MohammadNassar1
Copy link
Contributor

@MohammadNassar1 MohammadNassar1 commented Jul 18, 2024

…put state


This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.87%. Comparing base (93de0bd) to head (538c0c0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #510      +/-   ##
==========================================
+ Coverage   81.21%   81.87%   +0.65%     
==========================================
  Files          42       42              
  Lines        1826     1826              
  Branches     1826     1826              
==========================================
+ Hits         1483     1495      +12     
+ Misses        269      256      -13     
- Partials       74       75       +1     

☔ 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):
The AddTx method now takes into account the input account state.
It updates the queue accordingly, e.g. a transaction hole can be closed by the accountState.


Copy link
Contributor

@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.

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @elintul, @giladchase, and @MohammadNassar1)


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

        self.tx_pool.insert(tx)?;

        if self.tx_queue.get_nonce(sender_address).is_none() {

out of scope but I think get_address_nonce is better

Code quote:

get_nonce

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

        self.tx_pool.insert(tx)?;

        if self.tx_queue.get_nonce(sender_address).is_none() {

Consider adding a comment about the meaning of this if. I think get_nonce.none is not trivial for checking whether the account is in the queue already

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/fix/add-tx/input-state branch from 134076e to e3c7906 Compare July 18, 2024 15:20
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 109 at r1 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

Consider adding a comment about the meaning of this if. I think get_nonce.none is not trivial for checking whether the account is in the queue already

Done


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

Previously, ayeletstarkware (Ayelet Zilber) wrote…

out of scope but I think get_address_nonce is better

I think get_nonce is a good name for the function. The input argument is the address, so it is clear that it returns the nonce of a specific address.

Copy link
Contributor

@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.

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


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

        // 1. If the input transaction can be added to the queue, this can happen when the input
        //    transaction's nonce equals the next nonce.
        // 2. If the input state fills a gap in the transaction queue, insert it into the queue.

// If no account transaction is in the queue, insert if nonce matches account's.

Code quote:

        // If the queue is empty, check if a transaction can be inserted into the transaction queue:
        // 1. If the input transaction can be added to the queue, this can happen when the input
        //    transaction's nonce equals the next nonce.
        // 2. If the input state fills a gap in the transaction queue, insert it into the queue.

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


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

        if tx.nonce < nonce {
            return Err(MempoolError::DuplicateTransaction { tx_hash: tx.tx_hash });
        }

Okay, but error is inaccurate, and also should be moved to should_insert method from the other PR.

Code quote:

        // Invalid input.
        if tx.nonce < nonce {
            return Err(MempoolError::DuplicateTransaction { tx_hash: tx.tx_hash });
        }

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/fix/add-tx/input-state branch from e3c7906 to d096c6d Compare July 23, 2024 13:35
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, 3 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)


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

Previously, elintul (Elin) wrote…

Okay, but error is inaccurate, and also should be moved to should_insert method from the other PR.

Added a TODO.


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

Previously, ayeletstarkware (Ayelet Zilber) wrote…

// If no account transaction is in the queue, insert if nonce matches account's.

Note that another tx may be added to the queue, not only the specific one.

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

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/fix/add-tx/input-state branch 2 times, most recently from 10015be to a7accbd Compare July 24, 2024 13:11
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 r5, 1 of 1 files at r6, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)


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

                self.tx_queue.insert(*tx_reference);
            }
        }

Suggestion:

        // Maybe close nonce gap.
        if self.tx_queue.get_nonce(sender_address).is_none() {
            if let Some(tx_reference) = self.tx_pool.get_by_address_and_nonce(sender_address, nonce)
            {
                self.tx_queue.insert(*tx_reference);
            }
        }

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/fix/add-tx/input-state branch from 88c9d2e to 538c0c0 Compare July 24, 2024 13:52
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 r7, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware and @giladchase)

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

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.

4 participants