From 4aac90e293109043a5384124538e3c797cf7efdc Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:01:01 +0700 Subject: [PATCH 01/12] update comments --- simapp/CHANGELOG.md | 2 +- simapp/app_config.go | 2 +- simapp/app_di.go | 2 +- simapp/genesis_account.go | 2 +- simapp/simd/cmd/config.go | 2 +- simapp/v2/genesis_account.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/simapp/CHANGELOG.md b/simapp/CHANGELOG.md index 2daff48a15f2..7ef5486f7cb0 100644 --- a/simapp/CHANGELOG.md +++ b/simapp/CHANGELOG.md @@ -24,7 +24,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog `SimApp` is an application built using the Cosmos SDK for testing and educational purposes. -It won't be tagged or intented to be imported in an application. +It won't be tagged or intended to be imported in an application. This changelog is aimed to help developers understand the wiring changes between SDK versions. It is an exautive list of changes that completes the SimApp section in the [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#simapp) diff --git a/simapp/app_config.go b/simapp/app_config.go index 8918475184e1..ecf2fdf3714a 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -284,7 +284,7 @@ var ( Name: epochstypes.ModuleName, Config: appconfig.WrapAny(&epochsmodulev1.Module{}), }, - // This module is used for testing the depinject gogo x pulsar module registration. + // This module is only used for testing the depinject gogo x pulsar module registration. { Name: countertypes.ModuleName, Config: appconfig.WrapAny(&countertypes.Module{}), diff --git a/simapp/app_di.go b/simapp/app_di.go index 63beee09ab7e..3b4d83ab0a9b 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -320,7 +320,7 @@ func NewSimApp( return app } -// overwrite default ante handlers with custom ante handlers +// setCustomAnteHandler overwrites default ante handlers with custom ante handlers // set SkipAnteHandler to true in app config and set custom ante handler on baseapp func (app *SimApp) setCustomAnteHandler() { anteHandler, err := NewAnteHandler( diff --git a/simapp/genesis_account.go b/simapp/genesis_account.go index d242ba57060c..61a8f6942f16 100644 --- a/simapp/genesis_account.go +++ b/simapp/genesis_account.go @@ -31,7 +31,7 @@ type SimGenesisAccount struct { func (sga SimGenesisAccount) Validate() error { if !sga.OriginalVesting.IsZero() { if sga.StartTime >= sga.EndTime { - return errors.New("vesting start-time cannot be before end-time") + return errors.New("vesting start-time cannot be after end-time") } } diff --git a/simapp/simd/cmd/config.go b/simapp/simd/cmd/config.go index ce6698e255b1..3d551c227666 100644 --- a/simapp/simd/cmd/config.go +++ b/simapp/simd/cmd/config.go @@ -15,7 +15,7 @@ import ( func initCometBFTConfig() *cmtcfg.Config { cfg := cmtcfg.DefaultConfig() - // only display only error logs by default except for p2p and state + // display only error logs by default except for p2p and state cfg.LogLevel = "*:error,p2p:info,state:info" // these values put a higher strain on node memory diff --git a/simapp/v2/genesis_account.go b/simapp/v2/genesis_account.go index d242ba57060c..61a8f6942f16 100644 --- a/simapp/v2/genesis_account.go +++ b/simapp/v2/genesis_account.go @@ -31,7 +31,7 @@ type SimGenesisAccount struct { func (sga SimGenesisAccount) Validate() error { if !sga.OriginalVesting.IsZero() { if sga.StartTime >= sga.EndTime { - return errors.New("vesting start-time cannot be before end-time") + return errors.New("vesting start-time cannot be after end-time") } } From 30d72a34296275fb96c915fb8f2d1046ce79424e Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:02:00 +0700 Subject: [PATCH 02/12] consensustypes --- simapp/app.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index a03a9e69f518..92116a7ad4f1 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -50,7 +50,6 @@ import ( circuittypes "cosmossdk.io/x/circuit/types" "cosmossdk.io/x/consensus" consensusparamkeeper "cosmossdk.io/x/consensus/keeper" - consensusparamtypes "cosmossdk.io/x/consensus/types" consensustypes "cosmossdk.io/x/consensus/types" distr "cosmossdk.io/x/distribution" distrkeeper "cosmossdk.io/x/distribution/keeper" @@ -265,7 +264,7 @@ func NewSimApp( keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + govtypes.StoreKey, consensustypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, circuittypes.StoreKey, authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, pooltypes.StoreKey, accounts.StoreKey, epochstypes.StoreKey, @@ -288,7 +287,7 @@ func NewSimApp( cometService := runtime.NewContextAwareCometInfoService() // set the BaseApp's parameter store - app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), logger.With(log.ModuleKey, "x/consensus")), authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensustypes.StoreKey]), logger.With(log.ModuleKey, "x/consensus")), authtypes.NewModuleAddress(govtypes.ModuleName).String()) bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) // add keepers @@ -519,7 +518,6 @@ func NewSimApp( group.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - consensusparamtypes.ModuleName, circuittypes.ModuleName, pooltypes.ModuleName, epochstypes.ModuleName, From 45d4e670bfb461d9591148265be31a9bb603c1a6 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:02:40 +0700 Subject: [PATCH 03/12] handle err --- simapp/export.go | 28 +++++++++++++--------------- simapp/simd/cmd/testnet.go | 6 +----- simapp/v2/simdv2/cmd/testnet.go | 14 +------------- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/simapp/export.go b/simapp/export.go index 2c1d401ba580..b43b984be148 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -3,7 +3,6 @@ package simapp import ( "encoding/json" "fmt" - "log" cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" @@ -50,7 +49,7 @@ func (app *SimApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAd }, err } -// prepare for fresh start at zero height +// prepForZeroHeightGenesis prepares for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated // // in favor of export at a block height @@ -67,7 +66,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] for _, addr := range jailAllowedAddrs { _, err := sdk.ValAddressFromBech32(addr) if err != nil { - log.Fatal(err) + panic(err) } allowedAddrsMap[addr] = true } @@ -80,7 +79,10 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] if err != nil { panic(err) } - _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz) + _, err = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz) + if err != nil { + panic(err) + } return false }) if err != nil { @@ -94,14 +96,13 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] } for _, delegation := range dels { - valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) + valAddr:= sdk.MustValAddressFromBech32(delegation.ValidatorAddress) + delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) + + _, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) if err != nil { panic(err) } - - delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) - - _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) } // clear validator slash events @@ -151,10 +152,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] // reinitialize all delegations for _, del := range dels { - valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress) - if err != nil { - panic(err) - } + valAddr := sdk.MustValAddressFromBech32(del.ValidatorAddress) delAddr := sdk.MustAccAddressFromBech32(del.DelegatorAddress) if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil { @@ -192,7 +190,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] err = app.StakingKeeper.UnbondingDelegations.Walk( ctx, nil, - func(key collections.Pair[[]byte, []byte], ubd stakingtypes.UnbondingDelegation) (stop bool, err error) { + func(_ collections.Pair[[]byte, []byte], ubd stakingtypes.UnbondingDelegation) (stop bool, err error) { for i := range ubd.Entries { ubd.Entries[i].CreationHeight = 0 } @@ -237,7 +235,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] _, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx) if err != nil { - log.Fatal(err) + panic(err) } /* Handle slashing state. */ diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 822fc5fe453e..f6578b637146 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -544,11 +544,7 @@ func writeFile(name, dir string, contents []byte) error { return fmt.Errorf("could not create directory %q: %w", dir, err) } - if err := os.WriteFile(file, contents, 0o600); err != nil { - return err - } - - return nil + return os.WriteFile(file, contents, 0o600) } // startTestnet starts an in-process testnet diff --git a/simapp/v2/simdv2/cmd/testnet.go b/simapp/v2/simdv2/cmd/testnet.go index ea56e3a8fe2f..2dc4a923a27a 100644 --- a/simapp/v2/simdv2/cmd/testnet.go +++ b/simapp/v2/simdv2/cmd/testnet.go @@ -176,14 +176,6 @@ func initTestnetFiles[T transaction.Tx]( nodeIDs := make([]string, args.numValidators) valPubKeys := make([]cryptotypes.PubKey, args.numValidators) - // appConfig := srvconfig.DefaultConfig() - // appConfig.MinGasPrices = args.minGasPrices - // appConfig.API.Enable = true - // appConfig.Telemetry.Enabled = true - // appConfig.Telemetry.PrometheusRetentionTime = 60 - // appConfig.Telemetry.EnableHostnameLabel = false - // appConfig.Telemetry.GlobalLabels = [][]string{{"chain_id", args.chainID}} - var ( genAccounts []authtypes.GenesisAccount genBalances []banktypes.Balance @@ -504,9 +496,5 @@ func writeFile(name, dir string, contents []byte) error { return fmt.Errorf("could not create directory %q: %w", dir, err) } - if err := os.WriteFile(file, contents, 0o600); err != nil { - return err - } - - return nil + return os.WriteFile(file, contents, 0o600) } From c907e8a3a28ef0123aa9a5ec2f8b482f6949b293 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:03:06 +0700 Subject: [PATCH 04/12] add epochs for v2 --- simapp/v2/app_config.go | 9 +++++++++ simapp/v2/app_di.go | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/simapp/v2/app_config.go b/simapp/v2/app_config.go index ab54100a3f09..5b4ccc4c2682 100644 --- a/simapp/v2/app_config.go +++ b/simapp/v2/app_config.go @@ -15,6 +15,7 @@ import ( circuitmodulev1 "cosmossdk.io/api/cosmos/circuit/module/v1" consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" + epochsmodulev1 "cosmossdk.io/api/cosmos/epochs/module/v1" evidencemodulev1 "cosmossdk.io/api/cosmos/evidence/module/v1" feegrantmodulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1" genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1" @@ -45,6 +46,8 @@ import ( consensustypes "cosmossdk.io/x/consensus/types" _ "cosmossdk.io/x/distribution" // import for side-effects distrtypes "cosmossdk.io/x/distribution/types" + _ "cosmossdk.io/x/epochs" // import for side-effects + epochstypes "cosmossdk.io/x/epochs/types" _ "cosmossdk.io/x/evidence" // import for side-effects evidencetypes "cosmossdk.io/x/evidence/types" "cosmossdk.io/x/feegrant" @@ -121,6 +124,7 @@ var ( evidencetypes.ModuleName, stakingtypes.ModuleName, authz.ModuleName, + epochstypes.ModuleName, }, EndBlockers: []string{ govtypes.ModuleName, @@ -158,6 +162,7 @@ var ( vestingtypes.ModuleName, circuittypes.ModuleName, pooltypes.ModuleName, + epochstypes.ModuleName, }, // When ExportGenesis is not specified, the export genesis module order // is equal to the init genesis order @@ -270,6 +275,10 @@ var ( Name: pooltypes.ModuleName, Config: appconfig.WrapAny(&poolmodulev1.Module{}), }, + { + Name: epochstypes.ModuleName, + Config: appconfig.WrapAny(&epochsmodulev1.Module{}), + }, }, }) ) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index 7cde4042f3c8..f7b0803edab2 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -20,6 +20,7 @@ import ( circuitkeeper "cosmossdk.io/x/circuit/keeper" consensuskeeper "cosmossdk.io/x/consensus/keeper" distrkeeper "cosmossdk.io/x/distribution/keeper" + epochskeeper "cosmossdk.io/x/epochs/keeper" evidencekeeper "cosmossdk.io/x/evidence/keeper" feegrantkeeper "cosmossdk.io/x/feegrant/keeper" govkeeper "cosmossdk.io/x/gov/keeper" @@ -70,6 +71,7 @@ type SimApp[T transaction.Tx] struct { ConsensusParamsKeeper consensuskeeper.Keeper CircuitBreakerKeeper circuitkeeper.Keeper PoolKeeper poolkeeper.Keeper + EpochsKeeper *epochskeeper.Keeper } func init() { @@ -179,6 +181,7 @@ func NewSimApp[T transaction.Tx]( &app.ConsensusParamsKeeper, &app.CircuitBreakerKeeper, &app.PoolKeeper, + &app.EpochsKeeper, ); err != nil { panic(err) } @@ -196,7 +199,6 @@ func NewSimApp[T transaction.Tx]( // TODO (here or in runtime/v2) // wire simulation manager - // wire snapshot manager // wire unordered tx manager if err := app.LoadLatest(); err != nil { From 06ea466fdaf68bc0d315880cc6f86929a23893e5 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:03:35 +0700 Subject: [PATCH 05/12] clean up --- simapp/simd/cmd/commands.go | 5 ++--- simapp/v2/simdv2/cmd/commands.go | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/simapp/simd/cmd/commands.go b/simapp/simd/cmd/commands.go index 67175d3ee31d..b43ef6a74396 100644 --- a/simapp/simd/cmd/commands.go +++ b/simapp/simd/cmd/commands.go @@ -146,17 +146,16 @@ func appExport( // overwrite the FlagInvCheckPeriod viperAppOpts.Set(server.FlagInvCheckPeriod, 1) - appOpts = viperAppOpts var simApp *simapp.SimApp if height != -1 { - simApp = simapp.NewSimApp(logger, db, traceStore, false, appOpts) + simApp = simapp.NewSimApp(logger, db, traceStore, false, viperAppOpts) if err := simApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - simApp = simapp.NewSimApp(logger, db, traceStore, true, appOpts) + simApp = simapp.NewSimApp(logger, db, traceStore, true, viperAppOpts) } return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index ec9998f5c8f2..a6eb1f98069e 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -121,11 +121,8 @@ func queryCommand() *cobra.Command { cmd.AddCommand( rpc.QueryEventForTxCmd(), - server.QueryBlockCmd(), authcmd.QueryTxsByEventsCmd(), - server.QueryBlocksCmd(), authcmd.QueryTxCmd(), - server.QueryBlockResultsCmd(), ) return cmd From f250a184c1327805ce60bb4cca917d5ffa480713 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:03:49 +0700 Subject: [PATCH 06/12] go mod & tests --- simapp/v2/genesis_account_test.go | 89 +++++++++++++++++++++++++++++++ simapp/v2/go.mod | 3 +- simapp/v2/go.sum | 2 - 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 simapp/v2/genesis_account_test.go diff --git a/simapp/v2/genesis_account_test.go b/simapp/v2/genesis_account_test.go new file mode 100644 index 000000000000..9c21dc8a38e3 --- /dev/null +++ b/simapp/v2/genesis_account_test.go @@ -0,0 +1,89 @@ +package simapp_test + +import ( + "testing" + "time" + + "github.com/cometbft/cometbft/crypto" + "github.com/stretchr/testify/require" + + "cosmossdk.io/simapp/v2" + authtypes "cosmossdk.io/x/auth/types" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func TestSimGenesisAccountValidate(t *testing.T) { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + + vestingStart := time.Now().UTC() + + coins := sdk.NewCoins(sdk.NewInt64Coin("test", 1000)) + baseAcc := authtypes.NewBaseAccount(addr, pubkey, 0, 0) + + testCases := []struct { + name string + sga simapp.SimGenesisAccount + wantErr bool + }{ + { + "valid basic account", + simapp.SimGenesisAccount{ + BaseAccount: baseAcc, + }, + false, + }, + { + "invalid basic account with mismatching address/pubkey", + simapp.SimGenesisAccount{ + BaseAccount: authtypes.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0), + }, + true, + }, + { + "valid basic account with module name", + simapp.SimGenesisAccount{ + BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(crypto.AddressHash([]byte("testmod"))), nil, 0, 0), + ModuleName: "testmod", + }, + false, + }, + { + "valid basic account with invalid module name/pubkey pair", + simapp.SimGenesisAccount{ + BaseAccount: baseAcc, + ModuleName: "testmod", + }, + true, + }, + { + "valid basic account with valid vesting attributes", + simapp.SimGenesisAccount{ + BaseAccount: baseAcc, + OriginalVesting: coins, + StartTime: vestingStart.Unix(), + EndTime: vestingStart.Add(1 * time.Hour).Unix(), + }, + false, + }, + { + "valid basic account with invalid vesting end time", + simapp.SimGenesisAccount{ + BaseAccount: baseAcc, + OriginalVesting: coins, + StartTime: vestingStart.Add(2 * time.Hour).Unix(), + EndTime: vestingStart.Add(1 * time.Hour).Unix(), + }, + true, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + require.Equal(t, tc.wantErr, tc.sga.Validate() != nil) + }) + } +} diff --git a/simapp/v2/go.mod b/simapp/v2/go.mod index a04d0705c076..3d3053349cb0 100644 --- a/simapp/v2/go.mod +++ b/simapp/v2/go.mod @@ -21,6 +21,7 @@ require ( cosmossdk.io/x/circuit v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 cosmossdk.io/x/distribution v0.0.0-20230925135524-a1bc045b3190 + cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 cosmossdk.io/x/evidence v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/feegrant v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/gov v0.0.0-20231113122742-912390d5fc4a @@ -62,7 +63,6 @@ require ( cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5 // indirect cosmossdk.io/x/accounts/defaults/multisig v0.0.0-00010101000000-000000000000 // indirect - cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 // indirect cosmossdk.io/x/tx v0.13.4 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -261,6 +261,7 @@ replace ( cosmossdk.io/x/circuit => ../../x/circuit cosmossdk.io/x/consensus => ../../x/consensus cosmossdk.io/x/distribution => ../../x/distribution + cosmossdk.io/x/epochs => ../../x/epochs cosmossdk.io/x/evidence => ../../x/evidence cosmossdk.io/x/feegrant => ../../x/feegrant cosmossdk.io/x/gov => ../../x/gov diff --git a/simapp/v2/go.sum b/simapp/v2/go.sum index 62bba6528fd7..f1bb260684ab 100644 --- a/simapp/v2/go.sum +++ b/simapp/v2/go.sum @@ -204,8 +204,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.1.1 h1:I0M6pgI7R10nq+/HCQfbO6BsGBZA8sQy+duR1Y3aKcA= cosmossdk.io/schema v0.1.1/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 h1:GuBrfHsK3RD5vlD4DuBz3DXslR6VlnzrYmHOC3L679Q= -cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337/go.mod h1:PhLn1pMBilyRC4GfRkoYhm+XVAYhF4adVrzut8AdpJI= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= From 98f70e9ebb3cea0c4e4ff63dda41893bacded6c3 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Tue, 27 Aug 2024 23:02:22 +0700 Subject: [PATCH 07/12] revert WithdrawDelegationRewards err handle --- simapp/export.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/simapp/export.go b/simapp/export.go index b43b984be148..6b278cf9feef 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -79,10 +79,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] if err != nil { panic(err) } - _, err = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz) - if err != nil { - panic(err) - } + _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz) return false }) if err != nil { @@ -99,10 +96,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] valAddr:= sdk.MustValAddressFromBech32(delegation.ValidatorAddress) delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) - _, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) - if err != nil { - panic(err) - } + _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) } // clear validator slash events From ab373f2d254ca1b1f010acef5290e062cb832f7b Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:36:07 +0700 Subject: [PATCH 08/12] read app toml config from viper --- server/v2/cometbft/commands.go | 3 ++- server/v2/cometbft/config.go | 9 +++++++++ server/v2/cometbft/server.go | 8 +------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/server/v2/cometbft/commands.go b/server/v2/cometbft/commands.go index ed8329731ac0..67eda7c586b1 100644 --- a/server/v2/cometbft/commands.go +++ b/server/v2/cometbft/commands.go @@ -29,7 +29,8 @@ import ( ) func (s *CometBFTServer[T]) rpcClient(cmd *cobra.Command) (rpc.CometRPC, error) { - if s.config.AppTomlConfig.Standalone { + appTomlConfig := getAppTomlFromViper(client.GetViperFromCmd(cmd)) + if appTomlConfig.Standalone { client, err := rpchttp.New(client.GetConfigFromCmd(cmd).RPC.ListenAddress) if err != nil { return nil, err diff --git a/server/v2/cometbft/config.go b/server/v2/cometbft/config.go index 56860a78ddaf..0f6e7d157fda 100644 --- a/server/v2/cometbft/config.go +++ b/server/v2/cometbft/config.go @@ -64,3 +64,12 @@ func getConfigTomlFromViper(v *viper.Viper) *cmtcfg.Config { return conf.SetRoot(rootDir) } + +func getAppTomlFromViper(v *viper.Viper) *AppTomlConfig { + appTomlConfig := DefaultAppTomlConfig() + if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil { + return DefaultAppTomlConfig() + } + + return appTomlConfig +} diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index c06c56c9be9e..df079fb0a69d 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -58,15 +58,9 @@ func New[T transaction.Tx](txCodec transaction.Codec[T], serverOptions ServerOpt func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error { // get configs (app.toml + config.toml) from viper - appTomlConfig := s.Config().(*AppTomlConfig) - if v != nil { - if err := serverv2.UnmarshalSubConfig(v, s.Name(), &appTomlConfig); err != nil { - return fmt.Errorf("failed to unmarshal config: %w", err) - } - } s.config = Config{ ConfigTomlConfig: getConfigTomlFromViper(v), - AppTomlConfig: appTomlConfig, + AppTomlConfig: getAppTomlFromViper(v), } chainID := v.GetString(FlagChainID) From 23c480e639e7aa686a58f904f85ee8cbc3ea5891 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:37:02 +0700 Subject: [PATCH 09/12] update simapp-v2-smoke-test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 99b3d1c1b1ee..ed4f6e218948 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -605,7 +605,7 @@ jobs: simdv2 start & SIMD_PID=$! cnt=0 - while ! simdv2 query block --type=height 5; do + while ! simdv2 query comet block --type=height 5; do cnt=$((cnt + 1)) if [ $cnt -gt 30 ]; then kill -9 "$SIMD_PID" From f2012300657c5cbfbd1ee5dc8196ea81843c3446 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 28 Aug 2024 21:05:44 +0700 Subject: [PATCH 10/12] reverted --- server/v2/cometbft/config.go | 8 -------- server/v2/cometbft/server.go | 25 ++++++++++++++++--------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/server/v2/cometbft/config.go b/server/v2/cometbft/config.go index 0f6e7d157fda..7cdc8bd08240 100644 --- a/server/v2/cometbft/config.go +++ b/server/v2/cometbft/config.go @@ -65,11 +65,3 @@ func getConfigTomlFromViper(v *viper.Viper) *cmtcfg.Config { return conf.SetRoot(rootDir) } -func getAppTomlFromViper(v *viper.Viper) *AppTomlConfig { - appTomlConfig := DefaultAppTomlConfig() - if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil { - return DefaultAppTomlConfig() - } - - return appTomlConfig -} diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index df079fb0a69d..c1b547928c8c 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -58,9 +58,15 @@ func New[T transaction.Tx](txCodec transaction.Codec[T], serverOptions ServerOpt func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error { // get configs (app.toml + config.toml) from viper + appTomlConfig := s.Config().(*AppTomlConfig) + if v != nil { + if err := serverv2.UnmarshalSubConfig(v, s.Name(), &appTomlConfig); err != nil { + return fmt.Errorf("failed to unmarshal config: %w", err) + } + } s.config = Config{ ConfigTomlConfig: getConfigTomlFromViper(v), - AppTomlConfig: getAppTomlFromViper(v), + AppTomlConfig: appTomlConfig, } chainID := v.GetString(FlagChainID) @@ -227,18 +233,19 @@ func (s *CometBFTServer[T]) StartCmdFlags() *pflag.FlagSet { func (s *CometBFTServer[T]) CLICommands() serverv2.CLIConfig { return serverv2.CLIConfig{ Commands: []*cobra.Command{ - s.StatusCommand(), - s.ShowNodeIDCmd(), - s.ShowValidatorCmd(), - s.ShowAddressCmd(), - s.VersionCmd(), + StatusCommand(), + ShowNodeIDCmd(), + ShowValidatorCmd(), + ShowAddressCmd(), + VersionCmd(), + s.BootstrapStateCmd(), cmtcmd.ResetAllCmd, cmtcmd.ResetStateCmd, }, Queries: []*cobra.Command{ - s.QueryBlockCmd(), - s.QueryBlocksCmd(), - s.QueryBlockResultsCmd(), + QueryBlockCmd(), + QueryBlocksCmd(), + QueryBlockResultsCmd(), }, } } From 24d83bac142dfc2f0aae8b0356ce3f822cf72345 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 28 Aug 2024 21:06:31 +0700 Subject: [PATCH 11/12] comet queries not relay on CometBFTServer --- server/v2/cometbft/commands.go | 53 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/server/v2/cometbft/commands.go b/server/v2/cometbft/commands.go index 67eda7c586b1..144d3baeb2a7 100644 --- a/server/v2/cometbft/commands.go +++ b/server/v2/cometbft/commands.go @@ -13,12 +13,12 @@ import ( "github.com/cometbft/cometbft/p2p" pvm "github.com/cometbft/cometbft/privval" rpchttp "github.com/cometbft/cometbft/rpc/client/http" - "github.com/cometbft/cometbft/rpc/client/local" cmtversion "github.com/cometbft/cometbft/version" "github.com/spf13/cobra" "google.golang.org/protobuf/encoding/protojson" "sigs.k8s.io/yaml" + serverv2 "cosmossdk.io/server/v2" "cosmossdk.io/server/v2/cometbft/client/rpc" "github.com/cosmos/cosmos-sdk/client" @@ -28,8 +28,14 @@ import ( "github.com/cosmos/cosmos-sdk/version" ) -func (s *CometBFTServer[T]) rpcClient(cmd *cobra.Command) (rpc.CometRPC, error) { - appTomlConfig := getAppTomlFromViper(client.GetViperFromCmd(cmd)) +func rpcClient(cmd *cobra.Command) (rpc.CometRPC, error) { + v := client.GetViperFromCmd(cmd) + appTomlConfig := AppTomlConfig{} + if v != nil { + if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil { + return nil, fmt.Errorf("failed to unmarshal config: %w", err) + } + } if appTomlConfig.Standalone { client, err := rpchttp.New(client.GetConfigFromCmd(cmd).RPC.ListenAddress) if err != nil { @@ -38,26 +44,24 @@ func (s *CometBFTServer[T]) rpcClient(cmd *cobra.Command) (rpc.CometRPC, error) return client, nil } - if s.Node == nil || cmd.Flags().Changed(FlagNode) { - rpcURI, err := cmd.Flags().GetString(FlagNode) - if err != nil { - return nil, err - } - if rpcURI != "" { - return rpchttp.New(rpcURI) - } + rpcURI, err := cmd.Flags().GetString(FlagNode) + if err != nil { + return nil, err + } + if rpcURI == "" { + return nil, fmt.Errorf("rpc URI is empty") } - return local.New(s.Node), nil + return rpchttp.New(rpcURI) } // StatusCommand returns the command to return the status of the network. -func (s *CometBFTServer[T]) StatusCommand() *cobra.Command { +func StatusCommand() *cobra.Command { cmd := &cobra.Command{ Use: "status", Short: "Query remote node for status", RunE: func(cmd *cobra.Command, _ []string) error { - rpcclient, err := s.rpcClient(cmd) + rpcclient, err := rpcClient(cmd) if err != nil { return err } @@ -83,7 +87,7 @@ func (s *CometBFTServer[T]) StatusCommand() *cobra.Command { } // ShowNodeIDCmd - ported from CometBFT, dump node ID to stdout -func (s *CometBFTServer[T]) ShowNodeIDCmd() *cobra.Command { +func ShowNodeIDCmd() *cobra.Command { return &cobra.Command{ Use: "show-node-id", Short: "Show this node's ID", @@ -101,7 +105,7 @@ func (s *CometBFTServer[T]) ShowNodeIDCmd() *cobra.Command { } // ShowValidatorCmd - ported from CometBFT, show this node's validator info -func (s *CometBFTServer[T]) ShowValidatorCmd() *cobra.Command { +func ShowValidatorCmd() *cobra.Command { cmd := cobra.Command{ Use: "show-validator", Short: "Show this node's CometBFT validator info", @@ -135,7 +139,7 @@ func (s *CometBFTServer[T]) ShowValidatorCmd() *cobra.Command { } // ShowAddressCmd - show this node's validator address -func (s *CometBFTServer[T]) ShowAddressCmd() *cobra.Command { +func ShowAddressCmd() *cobra.Command { cmd := &cobra.Command{ Use: "show-address", Short: "Shows this node's CometBFT validator consensus address", @@ -154,7 +158,7 @@ func (s *CometBFTServer[T]) ShowAddressCmd() *cobra.Command { } // VersionCmd prints CometBFT and ABCI version numbers. -func (s *CometBFTServer[T]) VersionCmd() *cobra.Command { +func VersionCmd() *cobra.Command { return &cobra.Command{ Use: "version", Short: "Print CometBFT libraries' version", @@ -182,7 +186,7 @@ func (s *CometBFTServer[T]) VersionCmd() *cobra.Command { } // QueryBlocksCmd returns a command to search through blocks by events. -func (s *CometBFTServer[T]) QueryBlocksCmd() *cobra.Command { +func QueryBlocksCmd() *cobra.Command { cmd := &cobra.Command{ Use: "blocks", Short: "Query for paginated blocks that match a set of events", @@ -197,7 +201,7 @@ for. Each module documents its respective events under 'xx_events.md'. version.AppName, ), RunE: func(cmd *cobra.Command, args []string) error { - rpcclient, err := s.rpcClient(cmd) + rpcclient, err := rpcClient(cmd) if err != nil { return err } @@ -232,7 +236,7 @@ for. Each module documents its respective events under 'xx_events.md'. } // QueryBlockCmd implements the default command for a Block query. -func (s *CometBFTServer[T]) QueryBlockCmd() *cobra.Command { +func QueryBlockCmd() *cobra.Command { cmd := &cobra.Command{ Use: "block --type={height|hash} ", Short: "Query for a committed block by height, hash, or event(s)", @@ -247,7 +251,8 @@ $ %s query block --%s=%s RunE: func(cmd *cobra.Command, args []string) error { typ, _ := cmd.Flags().GetString(FlagType) - rpcclient, err := s.rpcClient(cmd) + rpcclient, err := rpcClient(cmd) + fmt.Println("rpcclient", rpcclient, err) if err != nil { return err } @@ -319,14 +324,14 @@ $ %s query block --%s=%s } // QueryBlockResultsCmd implements the default command for a BlockResults query. -func (s *CometBFTServer[T]) QueryBlockResultsCmd() *cobra.Command { +func QueryBlockResultsCmd() *cobra.Command { cmd := &cobra.Command{ Use: "block-results [height]", Short: "Query for a committed block's results by height", Long: "Query for a specific committed block's results using the CometBFT RPC `block_results` method", Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { - node, err := s.rpcClient(cmd) + node, err := rpcClient(cmd) if err != nil { return err } From e3a98f33bfb3bd0b0b1cbb13aa4c50d081383eea Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:47:46 +0700 Subject: [PATCH 12/12] no need app.toml config read --- server/v2/cometbft/commands.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/server/v2/cometbft/commands.go b/server/v2/cometbft/commands.go index 144d3baeb2a7..49be1c969adc 100644 --- a/server/v2/cometbft/commands.go +++ b/server/v2/cometbft/commands.go @@ -18,7 +18,6 @@ import ( "google.golang.org/protobuf/encoding/protojson" "sigs.k8s.io/yaml" - serverv2 "cosmossdk.io/server/v2" "cosmossdk.io/server/v2/cometbft/client/rpc" "github.com/cosmos/cosmos-sdk/client" @@ -29,21 +28,6 @@ import ( ) func rpcClient(cmd *cobra.Command) (rpc.CometRPC, error) { - v := client.GetViperFromCmd(cmd) - appTomlConfig := AppTomlConfig{} - if v != nil { - if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil { - return nil, fmt.Errorf("failed to unmarshal config: %w", err) - } - } - if appTomlConfig.Standalone { - client, err := rpchttp.New(client.GetConfigFromCmd(cmd).RPC.ListenAddress) - if err != nil { - return nil, err - } - return client, nil - } - rpcURI, err := cmd.Flags().GetString(FlagNode) if err != nil { return nil, err