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): implement remove method for transaction queue #412

Merged

Conversation

MohammadNassar1
Copy link
Contributor

@MohammadNassar1 MohammadNassar1 commented Jul 9, 2024

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jul 9, 2024

Codecov Report

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

Project coverage is 83.40%. Comparing base (2c64fcd) to head (e56b0d1).
Report is 1 commits behind head on main.

Files Patch % Lines
crates/mempool/src/transaction_queue.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #412      +/-   ##
==========================================
- Coverage   83.69%   83.40%   -0.30%     
==========================================
  Files          37       37              
  Lines        1717     1723       +6     
  Branches     1717     1723       +6     
==========================================
  Hits         1437     1437              
- Misses        203      209       +6     
  Partials       77       77              

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

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transacion-queue/address-to-tx/change-value-type branch from 331b790 to 3d2f02c Compare July 9, 2024 12:33
@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction-queue/implement-remove-method branch 3 times, most recently from 8723580 to 3b579de Compare July 9, 2024 13:08
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/transaction_queue.rs line 52 at r2 (raw file):

    }

    /// At most one transaction is associated with a single address in the queue.

Suggestion:

/// Removes the transaction of the given account address from the queue. 
/// This is well-defined, since there is at most one transaction per address in the queue.

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

    /// At most one transaction is associated with a single address in the queue.
    pub fn _remove(mut self, address: &ContractAddress) -> Option<TransactionReference> {

Temporary name until used?

Code quote:

_remove

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/transaction_queue.rs line 53 at r2 (raw file):

    /// At most one transaction is associated with a single address in the queue.
    pub fn _remove(mut self, address: &ContractAddress) -> Option<TransactionReference> {

Pass self by reference, while address is Copy so no need.

Suggestion:

&mut self, address: ContractAddress

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transacion-queue/address-to-tx/change-value-type branch from 3d2f02c to 4fd12e9 Compare July 9, 2024 14:07
@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction-queue/implement-remove-method branch from 3b579de to c4e5e4b Compare July 9, 2024 14:11
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/transaction_queue.rs line 53 at r2 (raw file):

Previously, elintul (Elin) wrote…

Temporary name until used?

Exactly


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

Previously, elintul (Elin) wrote…

Pass self by reference, while address is Copy so no need.

Done.

Copy link
Collaborator

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


crates/mempool/src/transaction_queue.rs line 58 at r3 (raw file):

            self.queue.remove(&tx.into());
            tx
        })

I like the chaining attempt, but it's best to keep side-effects away from map; it's intended goal is for transformation, rather than side-effects.

Suggestion:

        let tx = self.address_to_tx.remove(&address)?
        
        self.queue.remove(&tx.into());
        tx
        
        /// Technically this will also work, but this feels more complicated.
        // let tx = self.address_to_tx.remove(&address)?;
        // self.queue.take(&tx.into()).map(|tx| tx.0)
        

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction-queue/implement-remove-method branch from c4e5e4b to 1cc6e11 Compare July 10, 2024 07:12
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/transaction_queue.rs line 58 at r3 (raw file):

Previously, giladchase wrote…

I like the chaining attempt, but it's best to keep side-effects away from map; it's intended goal is for transformation, rather than side-effects.

Done.

Copy link
Collaborator

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

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 r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware)

@MohammadNassar1 MohammadNassar1 deleted the branch main July 10, 2024 08:35
@MohammadNassar1 MohammadNassar1 changed the base branch from mohammad/transacion-queue/address-to-tx/change-value-type to main July 10, 2024 08:36
@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction-queue/implement-remove-method branch from 1cc6e11 to 7ad7726 Compare July 10, 2024 08:41
Copy link
Collaborator

@giladchase giladchase 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, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware)

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, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware)

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 @MohammadNassar1)


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

    /// Removes the transaction of the given account address from the queue.
    /// This is well-defined, since there is at most one transaction per address in the queue.
    pub fn _remove(&mut self, address: ContractAddress) -> Option<TransactionReference> {

I don't think we should return the reference, maybe a bool is enough?

Code quote:

Option<TransactionReference>

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction-queue/implement-remove-method branch from 7ad7726 to e56b0d1 Compare July 10, 2024 12:16
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, all discussions resolved (waiting on @ayeletstarkware, @elintul, and @giladchase)


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

Previously, elintul (Elin) wrote…

I don't think we should return the reference, maybe a bool is enough?

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


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

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Done

WDYT about:

self.address_to_tx.remove(&address).map_or(false, |tx| self.queue.remove(&tx.into()))

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, all discussions resolved (waiting on @ayeletstarkware, @elintul, and @giladchase)


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

Previously, elintul (Elin) wrote…

WDYT about:

self.address_to_tx.remove(&address).map_or(false, |tx| self.queue.remove(&tx.into()))

But we said that we dont use map in this case, right?
and it's not a simple logic, it has a side effect.

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 r6.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware)


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

Previously, MohammadNassar1 (mohammad-starkware) wrote…

But we said that we dont use map in this case, right?
and it's not a simple logic, it has a side effect.

It's the or branch, the map side is pure. @giladchase - WDYT?

@MohammadNassar1 MohammadNassar1 merged commit 3a06dd9 into main Jul 11, 2024
8 checks passed
@MohammadNassar1 MohammadNassar1 deleted the mohammad/transaction-queue/implement-remove-method branch July 11, 2024 07:19
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