-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add this in AutoCLI: https://github.com/cosmos/cosmos-sdk/blob/3690d9f/client/v2/autocli/msg.go#L117-L128 ?
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`). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
cosmos-sdk/x/auth/tx/config/config.go
Lines 83 to 87 in 3a8f114
// 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) | |
} |
There was a problem hiding this comment.
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)
There was a problem hiding this 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
Co-authored-by: samricotta <37125168+samricotta@users.noreply.github.com>
WalkthroughThis update introduces a new sign mode, Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this 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
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 whereSIGN_MODE_TEXTUAL
was always enabled. Ensure that this change is intentional and that it does not break any existing functionality that relies onSIGN_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 fromcodec.NewProtoCodec(encodingConfig.InterfaceRegistry)
toinitClientCtx.Codec
. Ensure that this change is intentional and thatinitClientCtx.Codec
is equivalent tocodec.NewProtoCodec(encodingConfig.InterfaceRegistry)
.simapp/app.go (5)
61-61: The import of
sigtypes
is new and is used to enable the new sign modeSIGN_MODE_TEXTUAL
. This change is consistent with the PR summary.71-71: The import of
txmodule
is new and is used to configure theTextualCoinMetadataQueryFn
for the new sign mode. This change is consistent with the PR summary.151-151: The
BankKeeper
type has been changed frombankkeeper.Keeper
tobankkeeper.BaseKeeper
. Ensure that this change does not break any existing functionality that relies on methods not present inbankkeeper.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. TheTextualCoinMetadataQueryFn
is configured using theNewBankKeeperCoinMetadataQueryFn
function from thetxmodule
package. The new transaction configuration is then set as thetxConfig
for theSimApp
. 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 bytx.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
```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 | ||
``` |
There was a problem hiding this comment.
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)
+ }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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
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 thattxConfig
will not be created when the client is offline. If there are any parts of the code that rely ontxConfig
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
client/v2/autocli/msg.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK!
There was a problem hiding this 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
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 theslices.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 thattxConfig
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 ontxConfig
being created.
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
Description
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
make lint
andmake test
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...
!
in the type prefix if API or client breaking changeSummary by CodeRabbit
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.UPGRADING.md
and01-transactions.md
files to provide instructions on enabling the new sign mode and to explain its benefits and limitations.