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: sequence should be higher or equal than expected during checktx and equal during deliver tx #22299

Merged
merged 4 commits into from
Oct 17, 2024

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented Oct 17, 2024

Description

This is a QOL change where TX sequence will be expected to be higher equal than sequence during checktx, and equal during deliver tx.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Enhanced account structure to support transaction functionalities.
    • Improved signature verification logic with execution mode handling.
    • Expanded test coverage for transaction simulation, error handling, and signature verification.
  • Bug Fixes

    • Clarified error messages for sequence mismatches during signature verification.
  • Refactor

    • Simplified logic in transaction signing and broadcasting tests for better uniformity.

Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the Account structure by integrating a new TransactionService. Key updates include the addition of a ts field within the Account struct, modifications to the Authenticate method to incorporate execution mode checks, and changes to the verifySig method in the SigVerificationDecorator struct to align signature verification logic with the new execution modes. These adjustments improve the handling of transaction sequences and streamline the verification process.

Changes

File Path Change Summary
x/accounts/defaults/base/account.go - Added ts transaction.Service field to Account struct.
- Updated NewAccount method to initialize ts.
- Modified Authenticate method to check execution mode for sequence number validation.
x/auth/ante/sigverify.go - Modified verifySig method to handle execution modes for signature sequence verification.
- Simplified conditional checks for signature verification.
- Updated error messages for sequence mismatches.
tests/systemtests/auth_test.go - Updated TestAuthSignAndBroadcastTxCmd and TestAuthMultisigTxCmds to remove version 2 support checks for multi-message transactions.
x/auth/ante/ante_test.go - Added new test cases for transaction simulation and signature verification.
- Enhanced error handling tests and memo/gas limit tests.
x/auth/ante/sigverify_test.go - Updated tests for signature verification logic, including execution mode changes and edge case handling.

Possibly related PRs

  • feat(client/v2): factory #20623: The changes in the main PR regarding the Account structure and its methods may relate to the new features introduced in the client version 2, particularly in how accounts are managed and interacted with in transactions.
  • ci: actually enable v2 system test #21539: The modifications in the main PR regarding transaction handling and sequence validation are relevant to the improvements made in the CI configuration for system tests, ensuring that the new transaction logic is properly tested.
  • fix(x/accounts/lockup): prevent double withdraw #21619: The changes to the WithdrawUnlockedCoins method in the lockup functionality may relate to the overall improvements in account management and transaction handling introduced in the main PR.
  • chore(x/authz)!: Remove account keeper dependency #21632: The removal of the account keeper dependency in the authz module may connect with the changes in the main PR that enhance account handling and transaction validation.
  • test: migrate e2e/authz to system tests #21819: The migration of e2e tests to system tests may relate to the changes in the main PR that enhance transaction handling and account management, ensuring that these functionalities are thoroughly tested.
  • test: migrate e2e/auth to system tests and fix sign-batch #22149: The migration of e2e tests related to authentication to system tests aligns with the enhancements made in the main PR regarding transaction signing and broadcasting.
  • docs: fix rendering issue #22211: The fixes to the documentation regarding core components may indirectly relate to the changes in the main PR that enhance the understanding of account and transaction handling.
  • chore(doc): Update sims doc #22258: The updates to the simulation documentation may connect with the changes in the main PR that enhance transaction simulation and account management.
  • chore: add crisis changelog #22280: The addition of a changelog for crisis-related updates may relate to the overall improvements in transaction handling and account management introduced in the main PR.
  • feat(baseapp): Abort OE in PrepareProposal (Upstream dydx) #22287: The refactor of the baseapp to handle optimistic execution during proposal preparation may directly relate to the changes in the main PR that enhance transaction handling and account management.

Suggested labels

C:x/tx

Suggested reviewers

  • akhilkumarpilli
  • sontrinh16
  • tac0turtle

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e029976 and b0411da.

📒 Files selected for processing (1)
  • x/auth/ante/sigverify.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/auth/ante/sigverify.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@testinginprod your pull request is missing a changelog!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
x/auth/ante/sigverify.go (1)

309-320: Sequence number verification logic is correct, but standardize error messages

The changes correctly implement the desired sequence number checks:

  • During ExecModeCheck, transactions with a sequence number greater than or equal to the account sequence are accepted.
  • During other execution modes, the sequence number must exactly match the account sequence.

However, there is a minor inconsistency in the error messages' punctuation and phrasing:

  • First error message uses a comma and specifies "expected higher than or equal to %d":

    "account sequence mismatch, expected higher than or equal to %d, got %d", acc.GetSequence(), sig.Sequence,
  • Second error message uses a colon and specifies "expected %d":

    "account sequence mismatch: expected %d, got %d", acc.GetSequence(), sig.Sequence,

For consistency and clarity, consider standardizing both the punctuation (either use a comma or a colon) and the phrasing of the error messages.

Apply this diff to unify the error messages:

-                "account sequence mismatch, expected higher than or equal to %d, got %d", acc.GetSequence(), sig.Sequence,
+                "account sequence mismatch: expected sequence >= %d, got %d", acc.GetSequence(), sig.Sequence,
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f01baf3 and 9dc5acf.

📒 Files selected for processing (2)
  • x/accounts/defaults/base/account.go (4 hunks)
  • x/auth/ante/sigverify.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
x/accounts/defaults/base/account.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/auth/ante/sigverify.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🔇 Additional comments (2)
x/accounts/defaults/base/account.go (1)

115-116: ⚠️ Potential issue

Error message does not accurately reflect the condition

The error message on line 116 states:

sequence number must be higher than: %d, got: %d

This implies that the gotSeq must be greater than signerData.Sequence. However, the condition allows gotSeq to be equal to signerData.Sequence (i.e., gotSeq >= signerData.Sequence).

To align the error message with the condition, consider updating it to:

  • "sequence number must be greater than or equal to: %d, got: %d"
  • "sequence number must be at least: %d, got: %d"

Apply this diff to correct the error message:

-			return nil, fmt.Errorf("sequence number must be higher than: %d, got: %d", signerData.Sequence, gotSeq)
+			return nil, fmt.Errorf("sequence number must be greater than or equal to: %d, got: %d", signerData.Sequence, gotSeq)

Likely invalid or redundant comment.

x/auth/ante/sigverify.go (1)

327-329: Condition for skipping signature verification is appropriate

The condition to skip signature verification:

if execMode == transaction.ExecModeSimulate ||
    isRecheckTx(ctx, svd.ak.GetEnvironment().TransactionService) ||
    !isSigverifyTx(ctx) {
    return nil
}

correctly identifies scenarios where signature verification is unnecessary, including simulation mode, re-check transactions, and contexts where signature verification is not required.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
x/accounts/defaults/base/utils_test.go (2)

69-74: Consider adding comments to explain the purpose of transactionService.

While the implementation looks correct, it would be beneficial to add comments explaining the purpose of transactionService and its ExecMode method. This will improve code readability and make the testing setup more clear for other developers.

Consider adding comments like this:

// transactionService is a mock implementation of the transaction service for testing purposes.
type transactionService struct{}

// ExecMode always returns ExecModeFinalize for testing scenarios.
func (t transactionService) ExecMode(ctx context.Context) transaction.ExecMode {
	return transaction.ExecModeFinalize
}

84-86: LGTM! Consider aligning field assignments for better readability.

The addition of TransactionService to the Environment struct is correct and consistent with the newly introduced type. To improve readability and maintain consistency, consider aligning the field assignments vertically:

Environment: appmodulev2.Environment{
	EventService:       eventService{},
	HeaderService:      headerService{},
	TransactionService: transactionService{},
},
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5696991 and e029976.

📒 Files selected for processing (3)
  • x/accounts/defaults/base/utils_test.go (2 hunks)
  • x/auth/ante/ante_test.go (2 hunks)
  • x/auth/ante/sigverify_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
x/accounts/defaults/base/utils_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/auth/ante/ante_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/auth/ante/sigverify_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

🔇 Additional comments (4)
x/accounts/defaults/base/utils_test.go (1)

Line range hint 69-86: Consider adding or updating tests for the new transactionService.

While the changes enhance the mock dependencies by adding the transactionService, there are no explicit tests covering this new functionality. To ensure comprehensive test coverage:

  1. Add unit tests for the transactionService.ExecMode method.
  2. Update existing tests that use makeMockDependencies to verify that the TransactionService is correctly included and utilized.

This will help maintain the robustness of the test suite and ensure that the new functionality is working as expected in various scenarios.

To help identify existing tests that might need updating, you can run the following command:

Would you like assistance in drafting the additional test cases?

x/auth/ante/sigverify_test.go (1)

234-234: Correctly setting execution mode to ExecModeFinalize for non-recheck test cases

By explicitly setting ctx = ctx.WithExecMode(sdk.ExecModeFinalize) in the else block, the test ensures that when tc.recheck is false, the execution mode is appropriately set to ExecModeFinalize. This accurately simulates transaction processing during the deliver tx phase, which aligns with the PR's objective to adjust transaction sequence validation during this phase.

x/auth/ante/ante_test.go (2)

918-919: LGTM! Setting execution mode for test accuracy.

The context is correctly updated to sdk.ExecModeFinalize to simulate the finalize execution mode during testing, ensuring the test case reflects the intended behavior.


1086-1087: LGTM! Context execution mode appropriately updated.

Setting suite.ctx to sdk.ExecModeFinalize ensures the test operates under the correct execution mode, accurately reflecting the finalization process in this scenario.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 17, 2024
Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@julienrbrt julienrbrt added this pull request to the merge queue Oct 17, 2024
Merged via the queue into main with commit c1707b8 Oct 17, 2024
72 of 73 checks passed
@julienrbrt julienrbrt deleted the tip/app_manager_cache branch October 17, 2024 15:51
mergify bot pushed a commit that referenced this pull request Oct 17, 2024
…and equal during deliver tx (#22299)

Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
(cherry picked from commit c1707b8)
julienrbrt pushed a commit that referenced this pull request Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:x/accounts/base C:x/accounts C:x/auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants