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(textual): only enable when online and added upgrading docs #18166

Merged
merged 9 commits into from
Oct 23, 2023

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Oct 18, 2023

Description

  • only enable if the offline flag is not being passed
  • added signmode textual to legacy app.go (was missing)
  • added upgrading docs

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

  • New Feature: Introduced a new sign mode, SIGN_MODE_TEXTUAL, across the SDK for a more human-readable output, enhancing user experience especially on hardware wallets. This mode provides a string representation of transactions, formatted as screens for easy reading. Note: This mode does not support offline signing.
  • Improvement: Updated transaction configurations to handle offline scenarios more effectively.
  • Documentation: Updated the UPGRADING.md and 01-transactions.md files to provide instructions on enabling the new sign mode and to explain its benefits and limitations.
  • Refactor: Simplified code by removing unnecessary imports and configurations related to signing modes and textual coin metadata queries.

@facundomedica facundomedica marked this pull request as ready for review October 18, 2023 15:04
@facundomedica facundomedica requested a review from a team as a code owner October 18, 2023 15:04
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.

UPGRADING.md Outdated
}
```

When using `depinject` / `app v2`, it's enabled by default, and only needs to be added in the application client (`root.go`).
Copy link
Member

Choose a reason for hiding this comment

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

That is not true, unfortunately we still need to enable it for app_v2.
We can probably abstract it there with a provider in runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't this doing that?

// enable SIGN_MODE_TEXTUAL only if bank keeper is available
if in.MetadataBankKeeper != nil {
txConfigOptions.EnabledSignModes = append(txConfigOptions.EnabledSignModes, signingtypes.SignMode_SIGN_MODE_TEXTUAL)
txConfigOptions.TextualCoinMetadataQueryFn = NewBankKeeperCoinMetadataQueryFn(in.MetadataBankKeeper)
}

Copy link
Member

@julienrbrt julienrbrt Oct 18, 2023

Choose a reason for hiding this comment

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

Wow, I didn't know. It can be removed from root_v2 then.
In client/v2 let's check if set before re-setting it then (so it supports app v2 apps and legacy wiring)

@julienrbrt julienrbrt added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Oct 18, 2023
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

we should add some docs in a signing section to let teams and users know about this, the current docs are limited

https://docs.cosmos.network/main/learn/advanced/transactions#sign_mode_textual

UPGRADING.md Outdated Show resolved Hide resolved
Co-authored-by: samricotta <37125168+samricotta@users.noreply.github.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2023

Walkthrough

This update introduces a new sign mode, SIGN_MODE_TEXTUAL, in the SDK for a more human-readable output. It provides instructions on enabling this mode in both legacy and app v2 setups. The changes handle offline scenarios and update the transaction configuration accordingly. The update also enhances the signing experience on hardware wallets and provides default ValueRenderer implementations.

Changes

File(s) Summary
UPGRADING.md Introduces a new sign mode in the SDK that produces more human-readable output and provides instructions on how to enable this sign mode.
simapp/app.go, simapp/simd/cmd/root.go, simapp/simd/cmd/root_v2.go Adds support for the SIGN_MODE_TEXTUAL sign mode and updates the transaction configuration. Handles offline scenarios and updates the transaction configuration accordingly.
client/v2/autocli/msg.go Checks if the client context is offline before enabling sign mode textual and configuring transaction options.
docs/learn/advanced/01-transactions.md Introduces the SIGN_MODE_TEXTUAL sign mode for a better signing experience on hardware wallets and provides default ValueRenderer implementations.

"In the land of code, where logic is king, 🤴
A new sign mode, such joy it will bring. 🎉
More human in form, easy to read, 📖
A splendid update, indeed, indeed!" 🐰🥕


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

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

Commits Files that changed from the base of the PR and between 3a8f114 and 2d21f71.
Files selected for processing (4)
  • UPGRADING.md (1 hunks)
  • simapp/app.go (5 hunks)
  • simapp/simd/cmd/root.go (2 hunks)
  • simapp/simd/cmd/root_v2.go (1 hunks)
Additional comments (Suppressed): 15
simapp/simd/cmd/root_v2.go (3)
  • 81-95: The new sign mode SIGN_MODE_TEXTUAL is now only enabled when the client is online. This is a change from the previous behavior where it was always enabled. Ensure that this change does not affect any functionality that relies on this sign mode being available when the client is offline.

  • 81-95: The error handling for the creation of txConfigWithTextual is done correctly. If an error occurs, it is returned immediately, preventing further execution of the function.

  • 97-99: The error handling for SetCmdClientContextHandler is done correctly. If an error occurs, it is returned immediately, preventing further execution of the function.

simapp/simd/cmd/root.go (4)
  • 13-18: The import statement for "github.com/cosmos/cosmos-sdk/codec" has been removed. Ensure that this does not affect any other parts of the code that might be using it.

  • 72-92: The new sign mode SIGN_MODE_TEXTUAL is now only enabled when the client is online. This is a change in behavior from the previous version where SIGN_MODE_TEXTUAL was always enabled. Ensure that this change is intentional and that it does not break any existing functionality that relies on SIGN_MODE_TEXTUAL being available even when the client is offline.

  • 74-92: The error handling for the tx.NewTxConfigWithOptions function has been improved. Previously, the error was not checked and could potentially cause a panic if the function failed. Now, the error is properly checked and returned if it occurs. This is a good improvement in terms of error handling.

  • 74-92: The codec used in the tx.NewTxConfigWithOptions function has been changed from codec.NewProtoCodec(encodingConfig.InterfaceRegistry) to initClientCtx.Codec. Ensure that this change is intentional and that initClientCtx.Codec is equivalent to codec.NewProtoCodec(encodingConfig.InterfaceRegistry).

simapp/app.go (5)
  • 61-61: The import of sigtypes is new and is used to enable the new sign mode SIGN_MODE_TEXTUAL. This change is consistent with the PR summary.

  • 71-71: The import of txmodule is new and is used to configure the TextualCoinMetadataQueryFn for the new sign mode. This change is consistent with the PR summary.

  • 151-151: The BankKeeper type has been changed from bankkeeper.Keeper to bankkeeper.BaseKeeper. Ensure that this change does not break any existing functionality that relies on methods not present in bankkeeper.BaseKeeper.

  • 292-305: The new sign mode SIGN_MODE_TEXTUAL is being enabled here by appending it to the default sign modes. A new transaction configuration is then created with the updated sign modes and options. The TextualCoinMetadataQueryFn is configured using the NewBankKeeperCoinMetadataQueryFn function from the txmodule package. The new transaction configuration is then set as the txConfig for the SimApp. This change is consistent with the PR summary.

  • 478-478: The error handling for RegisterServices has been changed from a single line to multiple lines. This change does not affect the functionality of the code.

UPGRADING.md (3)
  • 35-42: The new sign mode, SIGN_MODE_TEXTUAL, is introduced. It's important to note that this sign mode does not support offline signing. This could potentially impact users who rely on offline signing for their transactions. Ensure that this change is communicated to all relevant stakeholders.

  • 64-77: The code snippet shows how to enable the new sign mode in the root.go file when the client is not offline. The error returned by tx.NewTxConfigWithOptions is handled correctly here, which is good practice.

  • 79-79: The new sign mode is enabled by default when using depinject / app v2. This could potentially impact users who are not expecting this change. Ensure that this change is communicated to all relevant stakeholders.

UPGRADING.md Outdated
Comment on lines 46 to 60
```golang
enabledSignModes := append(tx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := tx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
}
txConfig, err := tx.NewTxConfigWithOptions(
appCodec,
txConfigOpts,
)
if err != nil {
panic(err)
}
app.txConfig = txConfig
```
Copy link
Contributor

Choose a reason for hiding this comment

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

The code snippet shows how to enable the new sign mode in the app.go file. It's important to handle the error returned by tx.NewTxConfigWithOptions. The current code panics if there's an error. While this might be acceptable in some cases, it's generally better to handle errors gracefully. Consider logging the error and exiting the application with a non-zero status code.

-	if err != nil {
-		panic(err)
-	}
+	if err != nil {
+		log.Fatalf("Failed to create new TxConfig with options: %v", err)
+	}

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

Commits Files that changed from the base of the PR and between 2d21f71 and 83310d7.
Files selected for processing (1)
  • simapp/simd/cmd/root_v2.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • simapp/simd/cmd/root_v2.go

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

Commits Files that changed from the base of the PR and between 83310d7 and 00a9b3a.
Files selected for processing (1)
  • UPGRADING.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • UPGRADING.md

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

Commits Files that changed from the base of the PR and between 00a9b3a and 3330f1e.
Files selected for processing (1)
  • client/v2/autocli/msg.go (1 hunks)
Additional comments (Suppressed): 2
client/v2/autocli/msg.go (2)
  • 118-121: The new sign mode SIGN_MODE_TEXTUAL is now only enabled when the client is online. This is a change from the previous behavior where it was always enabled. Ensure that this change does not affect any existing functionality that relies on the sign mode being enabled regardless of the client's online status.

  • 123-130: The creation of txConfig has been moved inside the condition that checks if the client is online. This means that txConfig will not be created when the client is offline. If there are any parts of the code that rely on txConfig being available even when the client is offline, this could cause issues. Please verify.

@@ -32,6 +32,52 @@ clientCtx = clientCtx.

Refer to SimApp `root_v2.go` and `root.go` for an example with an app v2 and a legacy app.

#### Textual sign mode
Copy link
Member

Choose a reason for hiding this comment

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

Can we add this here #18166 (review) as well, as Marko said?

Copy link
Member Author

Choose a reason for hiding this comment

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

added the link to the docs section and the ADR. I've also opened a PR on the docs repo

Copy link
Member

@julienrbrt julienrbrt Oct 23, 2023

Choose a reason for hiding this comment

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

the build and learn section is still tracked from the sdk, so the changes should be here.
the docs repo manages the building of the docs and probably later tutorials.

@@ -115,17 +115,19 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor
}

// enable sign mode textual and config tx options
b.TxConfigOpts.EnabledSignModes = append(b.TxConfigOpts.EnabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
b.TxConfigOpts.TextualCoinMetadataQueryFn = authtxconfig.NewGRPCCoinMetadataQueryFn(clientCtx)
if !clientCtx.Offline {
Copy link
Member

@julienrbrt julienrbrt Oct 20, 2023

Choose a reason for hiding this comment

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

Mmmh, that does make it re-add it and re-wire for depinject enabled app.
Imho, we want an extra check like if b.TxConfigOpts.EnabledSignModes not contains signing.SignMode_SIGN_MODE_TEXTUAL

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced it with if !clientCtx.Offline && !slices.Contains(b.TxConfigOpts.EnabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) {

@github-actions github-actions bot added the C:CLI label Oct 23, 2023
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!

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 3330f1e and 5cfd79b.
Files ignored due to filter (1)
  • client/v2/go.mod
Files selected for processing (3)
  • UPGRADING.md (1 hunks)
  • client/v2/autocli/msg.go (2 hunks)
  • docs/learn/advanced/01-transactions.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • UPGRADING.md
Additional comments (Suppressed): 4
docs/learn/advanced/01-transactions.md (1)
  • 97-103: The updated documentation provides a more detailed explanation of the SIGN_MODE_TEXTUAL feature, including its purpose, how it works, and how developers can customize it. It also mentions the addition of "expert" screens for more advanced users. This is a good improvement as it provides more context and understanding for the users of the SDK. However, ensure that the link to ADR-050 is working and leads to the correct resource.
client/v2/autocli/msg.go (3)
  • 9-9: The new import "golang.org/x/exp/slices" is used for the slices.Contains function. Ensure that this package is maintained and reliable, as it's under the experimental section of the Go project.

  • 119-122: The new sign mode SIGN_MODE_TEXTUAL is now only enabled when the client is online and the sign mode is not already enabled. This is a change from the previous behavior where the sign mode was always enabled. Ensure that this change does not affect any existing functionality that relies on the sign mode being enabled.

  • 124-131: The creation of txConfig has been moved inside the condition that checks if the client is online and the sign mode is not already enabled. This means that txConfig will not be created if the client is offline or the sign mode is already enabled. Ensure that this change does not affect any existing functionality that relies on txConfig being created.

@julienrbrt julienrbrt added this pull request to the merge queue Oct 23, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 23, 2023
@julienrbrt julienrbrt added this pull request to the merge queue Oct 23, 2023
Merged via the queue into main with commit 511db52 Oct 23, 2023
51 of 54 checks passed
@julienrbrt julienrbrt deleted the facu/fix-signmode-txt branch October 23, 2023 14:33
mergify bot pushed a commit that referenced this pull request Oct 23, 2023
Co-authored-by: samricotta <37125168+samricotta@users.noreply.github.com>
(cherry picked from commit 511db52)

# Conflicts:
#	UPGRADING.md
#	client/v2/go.mod
#	simapp/simd/cmd/root.go
julienrbrt added a commit that referenced this pull request Oct 23, 2023
…ort #18166) (#18222)

Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants