From a876c086e2ec92c66a8aa7f313694255648458e5 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 14 May 2025 18:12:14 +0800 Subject: [PATCH 1/5] Problem: unsuppored sign mode SIGN_MODE_TEXTUAL in bank transfer --- CHANGELOG.md | 1 + app/app.go | 22 ++++++++++++++++++++-- cmd/chain-maind/app/app.go | 33 +++++++++++++++++++++++++++++++-- integration_tests/test_basic.py | 11 +++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3949f99f2..e02972215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * [#1091](https://github.com/crypto-org-chain/chain-main/pull/1091) Update cometbft to `0.38.13`, sdk to `v0.50.10` and memiavl to latest. - [#1091](https://github.com/crypto-org-chain/chain-main/pull/1091) Upgrade cometbft to v0.38.13, cosmos-sdk to `v0.50.10`. - [#1099](https://github.com/crypto-org-chain/chain-main/pull/1099) Avoid negative coin amount error when query supply liquid of non BaseCoinUnit. +- [#1152](https://github.com/crypto-org-chain/chain-main/pull/1152) Fix unsuppored sign mode SIGN_MODE_TEXTUAL for bank transfer. *Dec 6, 2023* diff --git a/app/app.go b/app/app.go index 98d0bdd91..03aab896d 100644 --- a/app/app.go +++ b/app/app.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "path/filepath" + "slices" "github.com/gorilla/mux" "github.com/spf13/cast" @@ -55,6 +56,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" mempool "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/cosmos/cosmos-sdk/types/module" + sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -63,6 +65,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -361,6 +364,21 @@ func New( authAddr, logger, ) + // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) + enabledSignModes := slices.Clone(authtx.DefaultSignModes) + enabledSignModes = append(enabledSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := authtx.ConfigOptions{ + EnabledSignModes: enabledSignModes, + TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), + } + txConfig, err := authtx.NewTxConfigWithOptions( + appCodec, + txConfigOpts, + ) + if err != nil { + panic(err) + } + app.txConfig = txConfig app.StakingKeeper = stakingkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), @@ -549,7 +567,7 @@ func New( app.ModuleManager = module.NewManager( genutil.NewAppModule( app.AccountKeeper, app.StakingKeeper, app, - encodingConfig.TxConfig, + txConfig, ), auth.NewAppModule(appCodec, app.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)), vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), @@ -745,7 +763,7 @@ func New( AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper, FeegrantKeeper: app.FeeGrantKeeper, - SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), + SignModeHandler: txConfig.SignModeHandler(), SigGasConsumer: ante.DefaultSigVerificationGasConsumer, }, IBCKeeper: app.IBCKeeper, diff --git a/cmd/chain-maind/app/app.go b/cmd/chain-maind/app/app.go index 5716c6da6..c1678d2db 100644 --- a/cmd/chain-maind/app/app.go +++ b/cmd/chain-maind/app/app.go @@ -6,12 +6,14 @@ import ( "io" "os" "path/filepath" + "slices" "time" clientcfg "github.com/cosmos/cosmos-sdk/client/config" serverconfig "github.com/cosmos/cosmos-sdk/server/config" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/types/tx/signing" "cosmossdk.io/log" tmcfg "github.com/cometbft/cometbft/config" @@ -34,6 +36,8 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" + "github.com/cosmos/cosmos-sdk/x/auth/tx" + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" @@ -70,6 +74,11 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { WithHomeDir(app.DefaultNodeHome). WithViper(EnvPrefix) + initClientCtx, err := clientcfg.ReadDefaultValuesFromDefaultClientConfig(initClientCtx) + if err != nil { + panic(err) + } + rootCmd := &cobra.Command{ Use: "chain-maind", Short: "Cronos.org Chain app", @@ -78,6 +87,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { cmd.SetOut(cmd.OutOrStdout()) cmd.SetErr(cmd.ErrOrStderr()) + initClientCtx = initClientCtx.WithCmdContext(cmd.Context()) initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags()) if err != nil { return err @@ -86,6 +96,27 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { if err != nil { return err } + + // This needs to go after ReadFromClientConfig, as that function + // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode + // is only available if the client is online. + if !initClientCtx.Offline { + enabledSignModes := slices.Clone(tx.DefaultSignModes) + enabledSignModes = append(enabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := tx.ConfigOptions{ + EnabledSignModes: enabledSignModes, + TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx), + } + txConfig, err := tx.NewTxConfigWithOptions( + initClientCtx.Codec, + txConfigOpts, + ) + if err != nil { + return err + } + + initClientCtx = initClientCtx.WithTxConfig(txConfig) + } if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err } @@ -99,8 +130,6 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { initRootCmd(rootCmd, encodingConfig, tempApp.BasicModuleManager) autoCliOpts := tempApp.AutoCliOpts() - initClientCtx, _ = clientcfg.ReadDefaultValuesFromDefaultClientConfig(initClientCtx) - // autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring) autoCliOpts.ClientCtx = initClientCtx if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index 79eacf33f..554ae8dbf 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -104,3 +104,14 @@ def test_statesync(cluster): # discovery_time is set to 5 seconds, add extra seconds for processing wait_for_block(cluster.cosmos_cli(i), 10) print("successfully syncing") + + +def test_textual(cluster): + cli = cluster.cosmos_cli() + rsp = cli.transfer( + cli.address("community"), + cli.address("signer2"), + "1cro", + sign_mode="textual", + ) + assert rsp["code"] == 0, rsp["raw_log"] From b909ef3dbefada27efdf470d316b4e78bb37f220 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 20 May 2025 17:22:42 +0800 Subject: [PATCH 2/5] fix upload --- .github/workflows/nix.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 3a1b1e5ba..ac25b8a73 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -125,7 +125,7 @@ jobs: flags: integration_tests_upgrade - name: Tar debug files if: failure() - run: tar cfz debug_files_upgrade.tar.gz -C ${TMPDIR-/tmp}/pytest-of-runner . + run: tar cfz debug_files_upgrade.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -160,7 +160,7 @@ jobs: flags: integration_tests_ledger - name: Tar debug files if: failure() - run: tar cfz debug_files_ledger.tar.gz -C ${TMPDIR-/tmp}/pytest-of-runner . + run: tar cfz debug_files_ledger.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -195,7 +195,7 @@ jobs: flags: integration_tests_solomachine - name: Tar debug files if: failure() - run: tar cfz debug_files_solomachine.tar.gz -C ${TMPDIR-/tmp}/pytest-of-runner . + run: tar cfz debug_files_solomachine.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -230,7 +230,7 @@ jobs: flags: integration_tests_slow - name: Tar debug files if: failure() - run: tar cfz debug_files_slow.tar.gz -C ${TMPDIR-/tmp}/pytest-of-runner . + run: tar cfz debug_files_slow.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -265,7 +265,7 @@ jobs: flags: integration_tests_ibc - name: Tar debug files if: failure() - run: tar cfz debug_files_ibc.tar.gz -C ${TMPDIR-/tmp}/pytest-of-runner . + run: tar cfz debug_files_ibc.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -300,7 +300,7 @@ jobs: flags: integration_tests_byzantine - name: Tar debug files if: failure() - run: tar cfz debug_files_byzantine.tar.gz -C ${TMPDIR-/tmp}/pytest-of-runner . + run: tar cfz debug_files_byzantine.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -335,7 +335,7 @@ jobs: flags: integration_tests_gov - name: Tar debug files if: failure() - run: tar cfz debug_files_gov.tar.gz -C ${TMPDIR-/tmp}/pytest-of-runner . + run: tar cfz debug_files_gov.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -371,7 +371,7 @@ jobs: flags: integration_tests_grpc - name: Tar debug files if: failure() - run: tar cfz debug_files_grpc.tar.gz -C ${TMPDIR-/tmp}/pytest-of-runner . + run: tar cfz debug_files_grpc.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: From e3fcf9b3d6fda45b67e01e603599f88801c4fb12 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 20 May 2025 17:24:05 +0800 Subject: [PATCH 3/5] test --- cmd/chain-maind/app/app.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/chain-maind/app/app.go b/cmd/chain-maind/app/app.go index c1678d2db..887815bc8 100644 --- a/cmd/chain-maind/app/app.go +++ b/cmd/chain-maind/app/app.go @@ -107,7 +107,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx), } - txConfig, err := tx.NewTxConfigWithOptions( + _, err := tx.NewTxConfigWithOptions( initClientCtx.Codec, txConfigOpts, ) @@ -115,7 +115,6 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { return err } - initClientCtx = initClientCtx.WithTxConfig(txConfig) } if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err From b968ea9a26898a2e5dbdf086aab9745521f40dfd Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 20 May 2025 18:33:40 +0800 Subject: [PATCH 4/5] fix empty --- .github/workflows/nix.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index ac25b8a73..de2a45812 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -64,7 +64,7 @@ jobs: flags: integration_tests - name: Tar debug files if: failure() - run: tar cfz debug_files.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . + run: tar cfz debug_files.tar.gz -C "${TMPDIR-/run/user/1001}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -125,7 +125,7 @@ jobs: flags: integration_tests_upgrade - name: Tar debug files if: failure() - run: tar cfz debug_files_upgrade.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . + run: tar cfz debug_files_upgrade.tar.gz -C "${TMPDIR-/run/user/1001}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -160,7 +160,7 @@ jobs: flags: integration_tests_ledger - name: Tar debug files if: failure() - run: tar cfz debug_files_ledger.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . + run: tar cfz debug_files_ledger.tar.gz -C "${TMPDIR-/run/user/1001}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -195,7 +195,7 @@ jobs: flags: integration_tests_solomachine - name: Tar debug files if: failure() - run: tar cfz debug_files_solomachine.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . + run: tar cfz debug_files_solomachine.tar.gz -C "${TMPDIR-/run/user/1001}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -230,7 +230,7 @@ jobs: flags: integration_tests_slow - name: Tar debug files if: failure() - run: tar cfz debug_files_slow.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . + run: tar cfz debug_files_slow.tar.gz -C "${TMPDIR-/run/user/1001}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -265,7 +265,7 @@ jobs: flags: integration_tests_ibc - name: Tar debug files if: failure() - run: tar cfz debug_files_ibc.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . + run: tar cfz debug_files_ibc.tar.gz -C "${TMPDIR-/run/user/1001}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -300,7 +300,7 @@ jobs: flags: integration_tests_byzantine - name: Tar debug files if: failure() - run: tar cfz debug_files_byzantine.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . + run: tar cfz debug_files_byzantine.tar.gz -C "${TMPDIR-/run/user/1001}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -335,7 +335,7 @@ jobs: flags: integration_tests_gov - name: Tar debug files if: failure() - run: tar cfz debug_files_gov.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . + run: tar cfz debug_files_gov.tar.gz -C "${TMPDIR-/run/user/1001}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: @@ -371,7 +371,7 @@ jobs: flags: integration_tests_grpc - name: Tar debug files if: failure() - run: tar cfz debug_files_grpc.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" . + run: tar cfz debug_files_grpc.tar.gz -C "${TMPDIR-/run/user/1001}/pytest-of-runner" . - uses: actions/upload-artifact@v4 if: failure() with: From b8bdbdc4162fa6a3ccc0da612c42e72d1b424508 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 21 May 2025 16:07:20 +0800 Subject: [PATCH 5/5] Revert "test" This reverts commit e3fcf9b3d6fda45b67e01e603599f88801c4fb12. --- cmd/chain-maind/app/app.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/chain-maind/app/app.go b/cmd/chain-maind/app/app.go index 887815bc8..c1678d2db 100644 --- a/cmd/chain-maind/app/app.go +++ b/cmd/chain-maind/app/app.go @@ -107,7 +107,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx), } - _, err := tx.NewTxConfigWithOptions( + txConfig, err := tx.NewTxConfigWithOptions( initClientCtx.Codec, txConfigOpts, ) @@ -115,6 +115,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { return err } + initClientCtx = initClientCtx.WithTxConfig(txConfig) } if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err