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

test(mempool): test_add_tx_fills_nonce_gap #511

Conversation

MohammadNassar1
Copy link
Contributor

@MohammadNassar1 MohammadNassar1 commented Jul 22, 2024

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.87%. Comparing base (a7accbd) to head (c3cb8a5).

Additional details and impacted files
@@                           Coverage Diff                            @@
##           mohammad/mempool/fix/add-tx/input-state     #511   +/-   ##
========================================================================
  Coverage                                    81.87%   81.87%           
========================================================================
  Files                                           42       42           
  Lines                                         1826     1826           
  Branches                                      1826     1826           
========================================================================
  Hits                                          1495     1495           
  Misses                                         256      256           
  Partials                                        75       75           

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

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


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

    add_tx(&mut mempool, &tx_input_nonce_2);
    assert_eq_mempool_queue(&mempool, &[tx_input_nonce_1.tx]);
}

Make sure Ayelet haven't written this case already.

Suggestion:

fn test_add_tx_fills_hole(mut mempool: Mempool) {
    // Setup.
    let tx_input_nonce_1 = add_tx_input!(tx_hash: 1, tx_nonce: 1_u8, account_nonce: 0_u8);
    // Input that increments the account state.
    let tx_input_nonce_2 = add_tx_input!(tx_hash: 2, tx_nonce: 2_u8, account_nonce: 1_u8);
    let tx_input_nonce_3 = add_tx_input!(tx_hash: 3, tx_nonce: 3_u8, account_nonce: 0_u8);

    // Test and assert.
    
    // First, with gap.
    add_tx(&mut mempool, &tx_input_nonce_1);
    add_tx(&mut mempool, &tx_input_nonce_3);
    assert_eq_mempool_queue(&mempool, &[]);

    // Then, fill it.
    add_tx(&mut mempool, &tx_input_nonce_2);
    assert_eq_mempool_queue(&mempool, &[tx_input_nonce_1.tx]);
}

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/fix/add-tx/input-state branch 2 times, most recently from d096c6d to 10015be Compare July 24, 2024 05:00
@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/add-tx/test-add-tx-fills-nonce-gap branch from df4b1a1 to 8c5412f Compare July 24, 2024 05:06
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/mempool_test.rs line 327 at r1 (raw file):

Previously, elintul (Elin) wrote…

Make sure Ayelet haven't written this case already.

Done.
I don't see a similar test.
@ayeletstarkware, can you please approve?

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, 1 unresolved discussion (waiting on @ayeletstarkware and @giladchase)

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


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

    add_tx(&mut mempool, &tx_input_nonce_3);
    // Queue is empty due to a nonce gap.
    assert_eq_mempool_queue(&mempool, &[]);

add a todo to use mempool state


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

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Done.
I don't see a similar test.
@ayeletstarkware, can you please approve?

I haven't written this case. But I think the test's name could be more informative by indicating that the hole is filled from a transaction carrying a more recent account state.

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/add-tx/test-add-tx-fills-nonce-gap branch from 8c5412f to b266a59 Compare July 24, 2024 08:00
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_test.rs line 322 at r1 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

add a todo to use mempool state

Why I need to use mempool state?


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

Previously, ayeletstarkware (Ayelet Zilber) wrote…

I haven't written this case. But I think the test's name could be more informative by indicating that the hole is filled from a transaction carrying a more recent account state.

Changed to test_add_tx_account_state_fills_hole.

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)


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

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Changed to test_add_tx_account_state_fills_hole.

That's the only way add_tx can close a hole, so seems redundant to me. Your call.

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.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @giladchase and @MohammadNassar1)


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

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Why I need to use mempool state?

assert_eq_mempool_queue will be deleted soon. we will use mempool partial state to check mempool queue instead.

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, 1 unresolved discussion (waiting on @giladchase)


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

Previously, elintul (Elin) wrote…

That's the only way add_tx can close a hole, so seems redundant to me. Your call.

This scenario can close a hole:

  1. AddTx(Tx(nonce=1), State(0))
  2. AddTx(Tx(nonce=0), State(0))

The first tx would create a hole.
The second tx would close 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.

:lgtm:

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @giladchase and @MohammadNassar1)


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

Previously, MohammadNassar1 (mohammad-starkware) wrote…

This scenario can close a hole:

  1. AddTx(Tx(nonce=1), State(0))
  2. AddTx(Tx(nonce=0), State(0))

The first tx would create a hole.
The second tx would close it.

Right. 🤦

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, 1 unresolved discussion (waiting on @ayeletstarkware and @giladchase)


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

Previously, ayeletstarkware (Ayelet Zilber) wrote…

assert_eq_mempool_queue will be deleted soon. we will use mempool partial state to check mempool queue instead.

Added

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 force-pushed the mohammad/mempool/fix/add-tx/input-state branch 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 2 files at r4, all commit messages.
Reviewable status: 1 of 2 files reviewed, all discussions resolved (waiting on @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.

Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @giladchase and @MohammadNassar1)


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

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

Remove.

Code quote:

        // Invalid input.
        // TODO(Mohammad): use `should_insert` method.
        if tx.nonce < nonce {
            return Err(MempoolError::DuplicateTransaction { tx_hash: tx.tx_hash });
        }

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/mempool/add-tx/test-add-tx-fills-nonce-gap branch from ad1226d to c3cb8a5 Compare July 24, 2024 13:19
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: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @elintul and @giladchase)


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

Previously, elintul (Elin) wrote…

Remove.

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

@MohammadNassar1 MohammadNassar1 merged commit 88c9d2e into mohammad/mempool/fix/add-tx/input-state Jul 24, 2024
8 checks passed
@MohammadNassar1 MohammadNassar1 deleted the mohammad/mempool/add-tx/test-add-tx-fills-nonce-gap branch July 24, 2024 13:29
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