From 71c9228a36f730c1f31e921128be016f74834e97 Mon Sep 17 00:00:00 2001 From: kienn6034 Date: Thu, 28 Mar 2024 16:51:17 +0700 Subject: [PATCH] feat: fix interface registry --- app/app.go | 49 +++++++++++++++++++++++++++++++-------- app/encoding.go | 21 ++++++++++++++++- cmd/centaurid/cmd/root.go | 13 +++++++++-- go.mod | 5 ++-- go.sum | 8 +++---- scripts/testnode.sh | 12 +++++----- 6 files changed, 83 insertions(+), 25 deletions(-) diff --git a/app/app.go b/app/app.go index 9d62ec7d2..db469dfa5 100644 --- a/app/app.go +++ b/app/app.go @@ -7,10 +7,12 @@ import ( "path/filepath" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" + "github.com/cosmos/cosmos-sdk/std" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/consensus" + "github.com/cosmos/gogoproto/proto" wasm08 "github.com/cosmos/ibc-go/modules/light-clients/08-wasm" wasm08keeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" @@ -21,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" @@ -38,11 +41,11 @@ import ( "github.com/notional-labs/composable/v6/app/upgrades/v6_5_0" // bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - "cosmossdk.io/x/evidence" evidencetypes "cosmossdk.io/x/evidence/types" "cosmossdk.io/x/feegrant" feegrantmodule "cosmossdk.io/x/feegrant/module" + "cosmossdk.io/x/tx/signing" authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" @@ -241,12 +244,13 @@ type ComposableApp struct { cdc *codec.LegacyAmino appCodec codec.Codec interfaceRegistry types.InterfaceRegistry + txConfig client.TxConfig + invCheckPeriod uint - invCheckPeriod uint - - mm *module.Manager - sm *module.SimulationManager - configurator module.Configurator + mm *module.Manager + basicModuleManger module.BasicManager + sm *module.SimulationManager + configurator module.Configurator } // RUN GOSEC @@ -265,22 +269,43 @@ func NewComposableApp( devnetGov *string, baseAppOptions ...func(*baseapp.BaseApp), ) *ComposableApp { - appCodec := encodingConfig.Marshaler cdc := encodingConfig.Amino - interfaceRegistry := encodingConfig.InterfaceRegistry + interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + SigningOptions: signing.Options{ + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + }, + }, + }) + + if err != nil { + panic(err) + } + + appCodec := codec.NewProtoCodec(interfaceRegistry) + legacyAmino := codec.NewLegacyAmino() + txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes) + + std.RegisterLegacyAminoCodec(legacyAmino) + std.RegisterInterfaces(interfaceRegistry) bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetInterfaceRegistry(interfaceRegistry) - bApp.SetTxEncoder(encodingConfig.TxConfig.TxEncoder()) + bApp.SetTxEncoder(txConfig.TxEncoder()) app := &ComposableApp{ BaseApp: bApp, AppKeepers: keepers.AppKeepers{}, - cdc: cdc, + cdc: legacyAmino, appCodec: appCodec, interfaceRegistry: interfaceRegistry, invCheckPeriod: invCheckPeriod, + txConfig: txConfig, } app.InitSpecialKeepers( @@ -361,6 +386,10 @@ func NewComposableApp( // this line is used by starport scaffolding # stargate/app/appModule ) + app.basicModuleManger = ModuleBasics + app.basicModuleManger.RegisterLegacyAminoCodec(legacyAmino) + app.basicModuleManger.RegisterInterfaces(interfaceRegistry) + // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the // CanWithdrawInvariant invariant. diff --git a/app/encoding.go b/app/encoding.go index 60535a84c..7e397e3a5 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -1,11 +1,15 @@ package app import ( + "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/tx" + "github.com/cosmos/gogoproto/proto" ) // This data structure (EncodingConfig) is heavily inspired by Quicksilver. https://github.com/ingenuity-build/quicksilver/blob/main/app/encoding.go @@ -19,7 +23,22 @@ type EncodingConfig struct { // MakeEncodingConfig creates an EncodingConfig for an amino based test configuration. func MakeEncodingConfig() EncodingConfig { amino := codec.NewLegacyAmino() - interfaceRegistry := types.NewInterfaceRegistry() + interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + SigningOptions: signing.Options{ + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + }, + }, + }) + + if err != nil { + panic(err) + } + marshaler := codec.NewProtoCodec(interfaceRegistry) txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes) diff --git a/cmd/centaurid/cmd/root.go b/cmd/centaurid/cmd/root.go index 1efb20e30..8e25f239b 100644 --- a/cmd/centaurid/cmd/root.go +++ b/cmd/centaurid/cmd/root.go @@ -33,6 +33,7 @@ import ( genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/notional-labs/composable/v6/app" // "github.com/notional-labs/composable/v6/app/params" // this line is used by starport scaffolding # stargate/root/import @@ -192,6 +193,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) { // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( server.StatusCommand(), + genesisCommand(encodingConfig.TxConfig, app.ModuleBasics), queryCommand(), txCommand(), keys.Commands(), @@ -250,8 +252,6 @@ func txCommand() *cobra.Command { flags.LineBreak, ) - app.ModuleBasics.AddTxCommands(cmd) - cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") return cmd } @@ -343,3 +343,12 @@ func (a appCreator) appExport( return anApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) } + +func genesisCommand(txConfig client.TxConfig, basicManager module.BasicManager, cmds ...*cobra.Command) *cobra.Command { + cmd := genutilcli.Commands(txConfig, basicManager, app.DefaultNodeHome) + + for _, subCmd := range cmds { + cmd.AddCommand(subCmd) + } + return cmd +} diff --git a/go.mod b/go.mod index 6266a8dd8..5d64c0feb 100644 --- a/go.mod +++ b/go.mod @@ -14,8 +14,8 @@ require ( github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2 github.com/cosmos/ibc-apps/modules/async-icq/v8 v8.0.0 github.com/cosmos/ibc-go/modules/capability v1.0.0 - github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240307202658-3f7320cd66dc - github.com/cosmos/ibc-go/v8 v8.1.1 + github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d + github.com/cosmos/ibc-go/v8 v8.0.0 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.4 github.com/golangci/golangci-lint v1.52.0 @@ -372,4 +372,5 @@ replace ( github.com/prometheus/common => github.com/prometheus/common v0.47.0 github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 + ) diff --git a/go.sum b/go.sum index 81ad5007d..a3ad1bbd1 100644 --- a/go.sum +++ b/go.sum @@ -836,10 +836,10 @@ github.com/cosmos/ibc-apps/modules/async-icq/v8 v8.0.0 h1:nKP2+Rzlz2iyvTosY5mvP+ github.com/cosmos/ibc-apps/modules/async-icq/v8 v8.0.0/go.mod h1:D3Q380FpWRFtmUQWLosPxachi6w24Og2t5u/Tww5wtY= github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo8ci1mVZNO9+V0xsLE= github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco= -github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240307202658-3f7320cd66dc h1:Y8ooMzd4YJGCSKRTMTMatp1/09bJPdnAmnPoM/ff2vw= -github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240307202658-3f7320cd66dc/go.mod h1:TSp/mbQtVR4lwh+69Q0etnVB6JeZl4Rym4F4bRtStHI= -github.com/cosmos/ibc-go/v8 v8.1.1 h1:N2+GA86yACcXnKWCKtqdbCwP0/Eo8pH79+6e7TicULU= -github.com/cosmos/ibc-go/v8 v8.1.1/go.mod h1:o1ipS95xpdjqNcB8Drq0eI3Sn4FRLigjll42ec1ECuU= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d h1:F4mhR61RZU4KJ38n5CeZrnNINU/KxMfP1sKfk5fTlHA= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d/go.mod h1:u2FXNcSxzzn5IwjWBA51HKMwiYMRK6/G35VmSJULhP0= +github.com/cosmos/ibc-go/v8 v8.0.0 h1:QKipnr/NGwc+9L7NZipURvmSIu+nw9jOIWTJuDBqOhg= +github.com/cosmos/ibc-go/v8 v8.0.0/go.mod h1:C6IiJom0F3cIQCD5fKwVPDrDK9j/xTu563AWuOmXois= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU= diff --git a/scripts/testnode.sh b/scripts/testnode.sh index 3cb62ce86..ea434822e 100755 --- a/scripts/testnode.sh +++ b/scripts/testnode.sh @@ -13,20 +13,20 @@ TRACE="" # remove existing daemon rm -rf ~/.banksy* -centaurid config keyring-backend $KEYRING -centaurid config chain-id $CHAINID +# centaurid config keyring-backend $KEYRING +# centaurid config chain-id $CHAINID # if $KEY exists it should be deleted echo "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" | centaurid keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover -centaurid init $MONIKER --chain-id $CHAINID +centaurid init $MONIKER --chain-id $CHAINID > /dev/null 2>&1 + # Allocate genesis accounts (cosmos formatted addresses) -centaurid add-genesis-account $KEY 100000000000000000000000000stake --keyring-backend $KEYRING +centaurid genesis add-genesis-account $KEY 100000000000000000000000000stake --keyring-backend $KEYRING # Sign genesis transaction -centaurid gentx $KEY 1000000000000000000000stake --keyring-backend $KEYRING --chain-id $CHAINID - +centaurid genesis gentx $KEY 1000000000000000000000stake --keyring-backend $KEYRING --chain-id $CHAINID # Collect genesis tx centaurid collect-gentxs