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(x/auth): Add fees on batch sign #18564

Merged
merged 12 commits into from
Nov 29, 2023
Merged

fix(x/auth): Add fees on batch sign #18564

merged 12 commits into from
Nov 29, 2023

Conversation

raynaudoe
Copy link
Contributor

@raynaudoe raynaudoe commented Nov 27, 2023

Description

Closes: #18064


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
  • added ! to 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
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • 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.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue with incorrect total fees calculation when batch signing transactions.
    • Resolved a server panic related to gas configuration settings.
    • Addressed a problem where certain block finalization calls were not being passed to listeners as expected.
    • Corrected the public key utilization during transaction simulation for more accurate results.
  • Documentation

    • Updated the changelog to reflect recent bug fixes and improvements.
  • Tests

    • Added new integration tests to ensure accurate fee calculations during batch transaction signing.
    • Modified test utilities to support multiple transaction files for batch processing tests.

Copy link
Contributor

coderabbitai bot commented Nov 27, 2023

Walkthrough

Walkthrough

The changes primarily address a bug in the Cosmos SDK related to the incorrect calculation of total fees when batch signing transactions with the --append flag. The updates include modifications to the makeSignBatchCmd function to correctly aggregate fees from individual transactions and set the total fee in the transaction builder. Additionally, the TxSignBatchExec function has been updated to accept multiple filenames, facilitating the batch signing process. Integration tests have been added to ensure the correct total fee calculation during batch signing.

Changes

File Path Change Summary
x/auth/client/cli/tx_sign.go Added logic to aggregate fees from individual transactions and set the total fee for batch signing.
x/auth/CHANGELOG.md Updated the changelog to reflect the bug fix for total fees calculation when batch signing.
x/auth/client/testutil/helpers.go Modified the TxSignBatchExec function to accept a slice of strings for filenames.
tests/integration/auth/client/cli/suite_test.go Added a new test function TestCLISignBatchTotalFees to validate the total fee calculation for batch signing.
tests/e2e/auth/suite.go Updated the TxSignBatchExec function to handle a slice of strings for file parameters.

Assessment against linked issues

Objective Addressed Explanation
Bug fix for sign-batch not merging fees with --append flag (Issue #18064)
Ensure fee.amount contains merged result of transactions when using sign-batch with --append (Issue #18064)
Update TxSignBatchExec to handle multiple transactions for batch signing (Issue #18064)
Add integration tests for total fee calculation in batch signing (Issue #18064)

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@raynaudoe raynaudoe marked this pull request as ready for review November 27, 2023 11:50
@raynaudoe raynaudoe requested a review from a team as a code owner November 27, 2023 11:50
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 02b1b00 and e15e946.
Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • x/auth/client/cli/tx_sign.go (3 hunks)
Additional comments: 7
CHANGELOG.md (1)
  • 72-72: The changelog entries correctly summarize the bug fixes made in the respective pull requests.
x/auth/client/cli/tx_sign.go (6)
  • 130-140: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [120-137]

The implementation of fee accumulation using the feeAmount variable and setting it in the txBuilder appears to be correct and aligns with the summary provided.

  • 130-140: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [132-153]

The logic for incrementing the gas limit and setting it in the txBuilder is correctly implemented.

  • 147-150: The memo, feeGranter, and feePayer are being set in the txBuilder from the command flags as expected.

  • 159-160: The call to sigTxOrMultisig is correctly passing the necessary parameters, and error handling is implemented.

  • 160-160: The signed transaction or signature is correctly being printed to the command's output.

  • 146-160: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [120-160]

Overall, the changes made to the makeSignBatchCmd function for handling fees in batch transactions are correctly implemented and should improve the functionality as described in the summary.

CHANGELOG.md Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e15e946 and c5e60e4.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments: 1
CHANGELOG.md (1)
  • 72-72: The changelog entry for the server config fix correctly specifies the use of a comma , as the delimiter, addressing the previous comment.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Would be nice to ensure we have test coverage for this.

x/auth/client/cli/tx_sign.go Outdated Show resolved Hide resolved
x/auth/client/cli/tx_sign.go Outdated Show resolved Hide resolved
@raynaudoe
Copy link
Contributor Author

raynaudoe commented Nov 27, 2023

Would be nice to ensure we have test coverage for this.

yes, happy to add them, I couldn't find any test file where makeSignBatchCmd (or similar) is being tested.
Should I create auth/cli/tx_sign_test.go ?

@alexanderbez
Copy link
Contributor

Would be nice to ensure we have test coverage for this.

yes, happy to add them, I couldn't find any test file were makeSignBatchCmd (or similar) is being tested. Should I create auth/cli/tx_sign_test.go ?

Yes pls :)

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c5e60e4 and 0b4a990.
Files selected for processing (1)
  • x/auth/client/cli/tx_sign.go (3 hunks)
Additional comments: 5
x/auth/client/cli/tx_sign.go (5)
  • 117-123: The introduction of the appendMessagesToSingleTx flag and the subsequent logic to accumulate fees and gas limits for batch signing is a good enhancement. It allows for the creation of a single signed transaction from multiple messages, which can be more efficient in certain scenarios.

  • 130-136: The logic to increment the gas limit and accumulate the fees for each transaction in the batch is correctly implemented. This ensures that the resulting single transaction has the correct gas limit and fee amount.

  • 146-155: The code correctly sets the transaction builder's memo, fee granter, fee payer, gas limit, and fee amount based on the command flags and the accumulated values. This ensures that the single signed transaction is constructed with the correct parameters.

  • 158-159: The call to sigTxOrMultisig to sign the transaction is appropriate. It handles both regular and multisig accounts, which is necessary for a flexible signing command.

  • 158-159: The code correctly marshals the signed transaction or signature to JSON and prints it to STDOUT or the specified output file. This is the expected behavior for a sign-batch command.

@julienrbrt julienrbrt changed the title fix: Add fees on batch sign fix(x/auth): Add fees on batch sign Nov 27, 2023
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Nice work and thanks for the fix @raynaudoe! I've added some suggestions to the code but also please send a test that'll catch this regression if it ever creeps up again: the lack of a test means that even if the logic radically changes or is wrong, we'd never catch the problem until someone catches it in production. Thank you

x/auth/client/cli/tx_sign.go Outdated Show resolved Hide resolved
x/auth/client/cli/tx_sign.go Outdated Show resolved Hide resolved
x/auth/client/cli/tx_sign.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0b4a990 and 108f677.
Files selected for processing (2)
  • x/auth/CHANGELOG.md (1 hunks)
  • x/auth/client/cli/tx_sign.go (3 hunks)
Additional comments: 4
x/auth/CHANGELOG.md (1)
  • 34-36: The changelog entry for the bug fix related to batch signing fees is correctly formatted and placed under the "Bug Fixes" section with the appropriate tag and GitHub issue reference.
x/auth/client/cli/tx_sign.go (3)
  • 117-123: The initialization of totalFees, txBuilder, msgs, and newGasLimit is correct and sets up the necessary variables for aggregating transaction fees and messages.

  • 130-140: The logic for aggregating the gas limit and fees from individual transactions is correct. However, it's important to ensure that the sdk.Coins type used for totalFees can handle the addition of fees correctly without any overflow or other issues.

  • 147-161: The setting of transaction properties such as memo, fee granter, fee payer, gas limit, and fee amount is done correctly. However, it's important to verify that the SetFeeAmount method correctly handles the sdk.Coins type and that the totalFees variable contains the correct aggregated fee amount.

Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Thank you @raynaudoe, LGTM with some comments and also please submit that regression test.

x/auth/CHANGELOG.md Outdated Show resolved Hide resolved
x/auth/client/cli/tx_sign.go Outdated Show resolved Hide resolved
@raynaudoe
Copy link
Contributor Author

Thank you @raynaudoe, LGTM with some comments and also please submit that regression test.

Yes, I'm currently working on those tests

Allow batch sign helper function to receive a slice of txs filenames
@raynaudoe
Copy link
Contributor Author

Would be nice to ensure we have test coverage for this.

Done!

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 108f677 and e1cc0f8.
Files selected for processing (4)
  • tests/integration/auth/client/cli/suite_test.go (3 hunks)
  • x/auth/CHANGELOG.md (1 hunks)
  • x/auth/client/cli/tx_sign.go (3 hunks)
  • x/auth/client/testutil/helpers.go (1 hunks)
Additional comments: 10
tests/integration/auth/client/cli/suite_test.go (4)
  • 159-171: The changes to the TestCLISignBatch function reflect the necessary adjustments for testing the new batch signing functionality with different flags. The home directory replacement and the execution of the TxSignBatchExec function with various combinations of flags are consistent with the expected behavior for testing the batch signing feature.

  • 174-229: The new test function TestCLISignBatchTotalFees is a valuable addition to the test suite. It properly tests the batch signing functionality by creating multiple transactions, writing them to separate files, and verifying that the expected total fee matches the actual total fee after batch signing. This ensures that the total fee calculation for batched transactions is correct.

  • 796-802: The changes in the TestSignBatchMultisig function correctly reflect the updated TxSignBatchExec function signature, which now accepts a slice of strings representing file names. This allows the function to handle multiple transaction files, which is necessary for testing batch signing with multisig.

  • 806-812: The continuation of the TestSignBatchMultisig function with the signing of the batch file with a second account is also correctly implemented. The test ensures that the batch signing process works with multiple signers, which is a critical aspect of multisig functionality.

x/auth/CHANGELOG.md (1)
  • 36-36: The changelog entry correctly summarizes the bug fix and includes the appropriate link to the pull request.
x/auth/client/cli/tx_sign.go (4)
  • 117-123: The initialization of variables for combining messages into a single transaction and calculating total fees appears to be correctly implemented.

  • 130-142: The logic for incrementing the gas limit, aggregating fees, and appending messages for batch transactions is correctly implemented. Ensure that the gas limit and fees are calculated correctly and that the messages are compatible when combined.

  • 148-162: The code correctly sets transaction properties and signs the transaction. Verify that the properties such as memo, fee granter, and fee payer are being set as intended and that the signing process is secure and error-free.

  • 148-162: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [117-162]

The changes made to x/auth/client/cli/tx_sign.go are consistent with the summaries provided, addressing the correct aggregation of fees for batch-signed transactions and setting the appropriate transaction properties before signing.

x/auth/client/testutil/helpers.go (1)
  • 66-68: The changes to TxSignBatchExec to accept multiple filenames are correctly implemented and match the summary description. Ensure that all calls to this function are updated to pass a slice of filenames where necessary.

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.

utACK

@raynaudoe raynaudoe added this pull request to the merge queue Nov 29, 2023
@julienrbrt julienrbrt added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Nov 29, 2023
Merged via the queue into main with commit 7bdbc46 Nov 29, 2023
62 of 63 checks passed
@raynaudoe raynaudoe deleted the eze/fix-fee-batch-sign branch November 29, 2023 14:39
mergify bot pushed a commit that referenced this pull request Nov 29, 2023
(cherry picked from commit 7bdbc46)

# Conflicts:
#	tests/e2e/auth/suite.go
#	x/auth/CHANGELOG.md
#	x/auth/client/cli/tx_sign.go
julienrbrt added a commit that referenced this pull request Nov 30, 2023
Co-authored-by: Ezequiel Raynaudo <raynaudo.ee@gmail.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
@faddat faddat mentioned this pull request Nov 8, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release C:CLI C:x/auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: sign-batch does not merge fees when --append flag is present
4 participants