From f45336f67d355e7c47e7c5ba789a67d433d5ed36 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 14 Feb 2023 16:44:16 +0100 Subject: [PATCH 01/23] feat: application genesis --- server/export.go | 25 +++++----- server/mock/app.go | 6 +-- server/mock/app_test.go | 4 +- server/mock/tx.go | 3 +- simapp/simd/cmd/testnet.go | 10 ++-- testutil/network/util.go | 10 ++-- testutil/sims/address_helpers.go | 5 +- testutil/sims/state_helpers.go | 10 ++-- x/genutil/types/genesis.go | 81 ++++++++++++++++++++++++++++++++ x/genutil/types/genesis_test.go | 38 +++++++++++++++ 10 files changed, 155 insertions(+), 37 deletions(-) create mode 100644 x/genutil/types/genesis.go create mode 100644 x/genutil/types/genesis_test.go diff --git a/server/export.go b/server/export.go index a469abe9d3b..c1a57391fca 100644 --- a/server/export.go +++ b/server/export.go @@ -1,16 +1,17 @@ package server import ( + "encoding/json" "fmt" "os" - cmtjson "github.com/cometbft/cometbft/libs/json" cmttypes "github.com/cometbft/cometbft/types" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) const ( @@ -73,15 +74,15 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return fmt.Errorf("error exporting state: %v", err) } - doc, err := cmttypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) + genDoc, err := cmttypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) if err != nil { return err } - doc.AppState = exported.AppState - doc.Validators = exported.Validators - doc.InitialHeight = exported.Height - doc.ConsensusParams = &cmttypes.ConsensusParams{ + genDoc.AppState = exported.AppState + genDoc.Validators = exported.Validators + genDoc.InitialHeight = exported.Height + genDoc.ConsensusParams = &cmttypes.ConsensusParams{ Block: cmttypes.BlockParams{ MaxBytes: exported.ConsensusParams.Block.MaxBytes, MaxGas: exported.ConsensusParams.Block.MaxGas, @@ -96,10 +97,8 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com }, } - // NOTE: CometBFT uses a custom JSON decoder for GenesisDoc - // (except for stuff inside AppState). Inside AppState, we're free - // to encode as protobuf or amino. - encoded, err := cmtjson.Marshal(doc) + appGenesis := genutiltypes.NewAppGenesis(*genDoc) + encoded, err := json.Marshal(appGenesis) if err != nil { return err } @@ -113,11 +112,11 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return nil } - var exportedGenDoc cmttypes.GenesisDoc - if err = cmtjson.Unmarshal(out, &exportedGenDoc); err != nil { + var exportedAppGenesis genutiltypes.AppGenesis + if err = json.Unmarshal(out, &exportedAppGenesis); err != nil { return err } - if err = exportedGenDoc.SaveAs(outputDocument); err != nil { + if err = exportedAppGenesis.SaveAs(outputDocument); err != nil { return err } diff --git a/server/mock/app.go b/server/mock/app.go index 438c904c803..b1d78dcfd85 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -9,7 +9,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" - "github.com/cometbft/cometbft/types" db "github.com/cosmos/cosmos-db" "google.golang.org/grpc" @@ -19,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // NewApp creates a simple mock kvstore app for testing. It should work @@ -116,7 +116,7 @@ func InitChainer(key storetypes.StoreKey) func(sdk.Context, abci.RequestInitChai // AppGenState can be passed into InitCmd, returns a static string of a few // key-values that can be parsed by InitChainer -func AppGenState(_ *codec.LegacyAmino, _ types.GenesisDoc, _ []json.RawMessage) (appState json.RawMessage, err error) { +func AppGenState(_ *codec.LegacyAmino, _ genutiltypes.AppGenesis, _ []json.RawMessage) (appState json.RawMessage, err error) { appState = json.RawMessage(`{ "values": [ { @@ -133,7 +133,7 @@ func AppGenState(_ *codec.LegacyAmino, _ types.GenesisDoc, _ []json.RawMessage) } // AppGenStateEmpty returns an empty transaction state for mocking. -func AppGenStateEmpty(_ *codec.LegacyAmino, _ types.GenesisDoc, _ []json.RawMessage) (appState json.RawMessage, err error) { +func AppGenStateEmpty(_ *codec.LegacyAmino, _ genutiltypes.AppGenesis, _ []json.RawMessage) (appState json.RawMessage, err error) { appState = json.RawMessage(``) return } diff --git a/server/mock/app_test.go b/server/mock/app_test.go index 3435fe7ff37..afd60b399c6 100644 --- a/server/mock/app_test.go +++ b/server/mock/app_test.go @@ -7,10 +7,10 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - "github.com/cometbft/cometbft/types" "github.com/stretchr/testify/require" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) func TestInitApp(t *testing.T) { @@ -21,7 +21,7 @@ func TestInitApp(t *testing.T) { } require.NoError(t, err) - appState, err := AppGenState(nil, types.GenesisDoc{}, nil) + appState, err := AppGenState(nil, genutiltypes.AppGenesis{}, nil) require.NoError(t, err) req := abci.RequestInitChain{ diff --git a/server/mock/tx.go b/server/mock/tx.go index 18c42a3e927..00cdddca9a2 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/signing" + "cosmossdk.io/errors" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -126,7 +127,7 @@ func decodeTx(txBytes []byte) (sdk.Tx, error) { k, v := split[0], split[1] tx = &KVStoreTx{k, v, txBytes, nil} } else { - return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "too many '='") + return nil, errors.Wrap(sdkerrors.ErrTxDecode, "too many '='") } return tx, nil diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 9dd0c00374a..7b0734b6d69 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -11,7 +11,7 @@ import ( cmtconfig "github.com/cometbft/cometbft/config" cmtrand "github.com/cometbft/cometbft/libs/rand" - "github.com/cometbft/cometbft/types" + cmttypes "github.com/cometbft/cometbft/types" cmttime "github.com/cometbft/cometbft/types/time" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -392,15 +392,15 @@ func initGenFiles( return err } - genDoc := types.GenesisDoc{ + appGenesis := genutiltypes.NewAppGenesis(cmttypes.GenesisDoc{ ChainID: chainID, AppState: appGenStateJSON, Validators: nil, - } + }) // generate empty genesis files for each validator and save for i := 0; i < numValidators; i++ { - if err := genDoc.SaveAs(genFiles[i]); err != nil { + if err := appGenesis.SaveAs(genFiles[i]); err != nil { return err } } @@ -426,7 +426,7 @@ func collectGenFiles( nodeID, valPubKey := nodeIDs[i], valPubKeys[i] initCfg := genutiltypes.NewInitConfig(chainID, gentxsDir, nodeID, valPubKey) - genDoc, err := types.GenesisDocFromFile(nodeConfig.GenesisFile()) + genDoc, err := cmttypes.GenesisDocFromFile(nodeConfig.GenesisFile()) if err != nil { return err } diff --git a/testutil/network/util.go b/testutil/network/util.go index 7608e770da3..dd2aa87ec84 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -13,7 +13,7 @@ import ( pvm "github.com/cometbft/cometbft/privval" "github.com/cometbft/cometbft/proxy" "github.com/cometbft/cometbft/rpc/client/local" - "github.com/cometbft/cometbft/types" + cmttypes "github.com/cometbft/cometbft/types" cmttime "github.com/cometbft/cometbft/types/time" "github.com/cosmos/cosmos-sdk/server/api" @@ -123,7 +123,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { initCfg := genutiltypes.NewInitConfig(cfg.ChainID, gentxsDir, vals[i].NodeID, vals[i].PubKey) genFile := cmtCfg.GenesisFile() - genDoc, err := types.GenesisDocFromFile(genFile) + genDoc, err := cmttypes.GenesisDocFromFile(genFile) if err != nil { return err } @@ -168,15 +168,15 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance return err } - genDoc := types.GenesisDoc{ + appGenesis := genutiltypes.NewAppGenesis(cmttypes.GenesisDoc{ ChainID: cfg.ChainID, AppState: appGenStateJSON, Validators: nil, - } + }) // generate empty genesis files for each validator and save for i := 0; i < cfg.NumValidators; i++ { - if err := genDoc.SaveAs(genFiles[i]); err != nil { + if err := appGenesis.SaveAs(genFiles[i]); err != nil { return err } } diff --git a/testutil/sims/address_helpers.go b/testutil/sims/address_helpers.go index d95279c3236..1b5decb9403 100644 --- a/testutil/sims/address_helpers.go +++ b/testutil/sims/address_helpers.go @@ -6,11 +6,12 @@ import ( "fmt" "strconv" + "cosmossdk.io/errors" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" ) @@ -154,7 +155,7 @@ func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) { panic(err) } if len(pkBytes) != ed25519.PubKeySize { - panic(errors.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size")) + panic(errors.Wrap(sdkerrors.ErrInvalidPubKey, "invalid pubkey size")) } return &ed25519.PubKey{Key: pkBytes} } diff --git a/testutil/sims/state_helpers.go b/testutil/sims/state_helpers.go index 52e32406506..7143ebfbb01 100644 --- a/testutil/sims/state_helpers.go +++ b/testutil/sims/state_helpers.go @@ -9,8 +9,6 @@ import ( "time" "cosmossdk.io/math" - cmtjson "github.com/cometbft/cometbft/libs/json" - cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -19,6 +17,7 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -211,15 +210,14 @@ func AppStateRandomizedFn( // AppStateFromGenesisFileFn util function to generate the genesis AppState // from a genesis.json file. -func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile string) (cmttypes.GenesisDoc, []simtypes.Account, error) { +func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile string) (genutiltypes.AppGenesis, []simtypes.Account, error) { bytes, err := os.ReadFile(genesisFile) if err != nil { panic(err) } - var genesis cmttypes.GenesisDoc - // NOTE: CometBFT uses a custom JSON decoder for GenesisDoc - if err = cmtjson.Unmarshal(bytes, &genesis); err != nil { + var genesis genutiltypes.AppGenesis + if err = json.Unmarshal(bytes, &genesis); err != nil { return genesis, nil, err } diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go new file mode 100644 index 00000000000..3ea103f5ad1 --- /dev/null +++ b/x/genutil/types/genesis.go @@ -0,0 +1,81 @@ +package types + +import ( + "encoding/json" + "os" + + cmtjson "github.com/cometbft/cometbft/libs/json" + cmttypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/version" +) + +// AppGenesisOnly defines the app's genesis. +type AppGenesisOnly struct { + AppName string `json:"app_name"` + AppVersion string `json:"app_version"` +} + +// AppGenesis defines the app's genesis with the consensus genesis. +type AppGenesis struct { + AppGenesisOnly + + cmttypes.GenesisDoc +} + +func NewAppGenesis(genesisDoc cmttypes.GenesisDoc) *AppGenesis { + return &AppGenesis{ + AppGenesisOnly: AppGenesisOnly{ + AppName: version.AppName, + AppVersion: version.Version, + }, + GenesisDoc: genesisDoc, + } +} + +// SaveAs is a utility method for saving AppGenesis as a JSON file. +func (ag *AppGenesis) SaveAs(file string) error { + // appGenesisBytes, err := ag.MarshalIndent("", " ") + appGenesisBytes, err := json.Marshal(ag) + if err != nil { + return err + } + + return os.WriteFile(file, appGenesisBytes, 0644) +} + +// Marshal the AppGenesis. +func (ag *AppGenesis) MarshalJSON() ([]byte, error) { + // marshal the genesis doc with CometBFT lib + // if GenesisDoc was implementing MarshalJSON and UnmarshalJSON, this would be much simpler + genDoc, err := cmtjson.Marshal(ag.GenesisDoc) + if err != nil { + return nil, err + } + + appGenesis, err := json.Marshal(ag.AppGenesisOnly) + if err != nil { + return nil, err + } + + out := map[string]interface{}{} + if err = json.Unmarshal(appGenesis, &out); err != nil { + return nil, err + } + + if err = cmtjson.Unmarshal(genDoc, &out); err != nil { + return nil, err + } + + // unmarshal the genesis doc with stdlib + return cmtjson.Marshal(out) +} + +// MarshalIndent marshals the AppGenesis with the provided prefix and indent. +func (ag *AppGenesis) MarshalIndent(prefix, indent string) ([]byte, error) { + return cmtjson.MarshalIndent(ag, prefix, indent) +} + +// Unmarshal an AppGenesis from JSON. +func (ag *AppGenesis) UnmarshalJSON(bz []byte) error { + return cmtjson.Unmarshal(bz, &ag) +} diff --git a/x/genutil/types/genesis_test.go b/x/genutil/types/genesis_test.go new file mode 100644 index 00000000000..5a6030e481c --- /dev/null +++ b/x/genutil/types/genesis_test.go @@ -0,0 +1,38 @@ +package types_test + +import ( + "testing" + + "gotest.tools/v3/assert" + + cmttypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/x/genutil/types" +) + +func TestAppGenesis_Marshal(t *testing.T) { + genesis := types.AppGenesis{ + AppGenesisOnly: types.AppGenesisOnly{ + AppName: "simapp", + AppVersion: "0.1.0", + }, + GenesisDoc: cmttypes.GenesisDoc{ + ChainID: "test", + }, + } + + out, err := genesis.MarshalJSON() + assert.NilError(t, err) + + assert.Equal(t, string(out), `{"app_name":"simapp","app_version":"0.1.0","chain_id":"test"}`) +} + +func TestAppGenesis_Unmarshal(t *testing.T) { + var genesis types.AppGenesis + + err := genesis.UnmarshalJSON([]byte(`{"app_name":"simapp","app_version":"0.1.0","chain_id":"test"}`)) + assert.NilError(t, err) + + assert.Equal(t, genesis.AppName, "simapp") + assert.Equal(t, genesis.AppVersion, "0.1.0") + assert.Equal(t, genesis.ChainID, "test") +} From 6f6a96d6b02a71865eea55d25cf0c2bd923d9980 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 14 Feb 2023 18:05:12 +0100 Subject: [PATCH 02/23] updates --- x/genutil/types/genesis.go | 32 +++++++++++++++++--------------- x/genutil/types/genesis_test.go | 16 +++++++++------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 3ea103f5ad1..49acbeaa79b 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -52,22 +52,16 @@ func (ag *AppGenesis) MarshalJSON() ([]byte, error) { return nil, err } - appGenesis, err := json.Marshal(ag.AppGenesisOnly) - if err != nil { - return nil, err - } - - out := map[string]interface{}{} - if err = json.Unmarshal(appGenesis, &out); err != nil { - return nil, err - } - - if err = cmtjson.Unmarshal(genDoc, &out); err != nil { - return nil, err - } + type ConsensusGenesis []byte // unmarshal the genesis doc with stdlib - return cmtjson.Marshal(out) + return json.Marshal(&struct { + AppGenesisOnly + ConsensusGenesis + }{ + AppGenesisOnly: ag.AppGenesisOnly, + ConsensusGenesis: genDoc, + }) } // MarshalIndent marshals the AppGenesis with the provided prefix and indent. @@ -77,5 +71,13 @@ func (ag *AppGenesis) MarshalIndent(prefix, indent string) ([]byte, error) { // Unmarshal an AppGenesis from JSON. func (ag *AppGenesis) UnmarshalJSON(bz []byte) error { - return cmtjson.Unmarshal(bz, &ag) + type Alias AppGenesis // we alias for avoiding recursion in UnmarshalJSON + var result Alias + + if err := cmtjson.Unmarshal(bz, &result); err != nil { + return err + } + + ag = (*AppGenesis)(&result) + return nil } diff --git a/x/genutil/types/genesis_test.go b/x/genutil/types/genesis_test.go index 5a6030e481c..ada23f03dd8 100644 --- a/x/genutil/types/genesis_test.go +++ b/x/genutil/types/genesis_test.go @@ -1,6 +1,7 @@ package types_test import ( + "encoding/json" "testing" "gotest.tools/v3/assert" @@ -9,6 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil/types" ) +var expectedAppGenesisJSON = `{"app_name":"simapp","app_version":"0.1.0","genesis_time":"0001-01-01T00:00:00Z","chain_id":"test","initial_height":"0","app_hash":""}` + func TestAppGenesis_Marshal(t *testing.T) { genesis := types.AppGenesis{ AppGenesisOnly: types.AppGenesisOnly{ @@ -20,19 +23,18 @@ func TestAppGenesis_Marshal(t *testing.T) { }, } - out, err := genesis.MarshalJSON() + out, err := json.Marshal(&genesis) assert.NilError(t, err) - assert.Equal(t, string(out), `{"app_name":"simapp","app_version":"0.1.0","chain_id":"test"}`) + assert.Equal(t, string(out), expectedAppGenesisJSON) } func TestAppGenesis_Unmarshal(t *testing.T) { var genesis types.AppGenesis - - err := genesis.UnmarshalJSON([]byte(`{"app_name":"simapp","app_version":"0.1.0","chain_id":"test"}`)) + err := json.Unmarshal([]byte(expectedAppGenesisJSON), &genesis) assert.NilError(t, err) - assert.Equal(t, genesis.AppName, "simapp") - assert.Equal(t, genesis.AppVersion, "0.1.0") - assert.Equal(t, genesis.ChainID, "test") + assert.DeepEqual(t, genesis.AppName, "simapp") + assert.DeepEqual(t, genesis.AppVersion, "0.1.0") + assert.DeepEqual(t, genesis.ChainID, "test") } From 77688ce9f00ce5be007ec3a29cd1c1635fdf9b98 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 16 Feb 2023 14:10:32 +0100 Subject: [PATCH 03/23] wip --- api/cosmos/genutil/v1beta1/genesis.pulsar.go | 774 ++++++++++++++++++- proto/cosmos/genutil/v1beta1/genesis.proto | 17 + server/export.go | 25 +- server/start.go | 15 +- simapp/simd/cmd/testnet.go | 9 +- testutil/network/util.go | 19 +- x/auth/helpers/genaccounts.go | 6 +- x/genutil/client/cli/collect.go | 11 +- x/genutil/client/cli/gentx.go | 7 +- x/genutil/client/cli/init.go | 14 +- x/genutil/collect.go | 15 +- x/genutil/collect_test.go | 14 +- x/genutil/types/genesis.go | 106 ++- x/genutil/types/genesis.pb.go | 341 +++++++- x/genutil/types/genesis_state.go | 21 +- x/genutil/types/genesis_test.go | 28 +- x/genutil/utils.go | 27 +- x/staking/genesis.go | 21 +- 18 files changed, 1271 insertions(+), 199 deletions(-) diff --git a/api/cosmos/genutil/v1beta1/genesis.pulsar.go b/api/cosmos/genutil/v1beta1/genesis.pulsar.go index 4382a8bc801..cb25477fd03 100644 --- a/api/cosmos/genutil/v1beta1/genesis.pulsar.go +++ b/api/cosmos/genutil/v1beta1/genesis.pulsar.go @@ -4,11 +4,13 @@ package genutilv1beta1 import ( _ "cosmossdk.io/api/amino" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + anypb "google.golang.org/protobuf/types/known/anypb" io "io" reflect "reflect" sync "sync" @@ -494,6 +496,617 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { } } +var ( + md_GenesisValidator protoreflect.MessageDescriptor + fd_GenesisValidator_address protoreflect.FieldDescriptor + fd_GenesisValidator_consensus_pubkey protoreflect.FieldDescriptor + fd_GenesisValidator_voting_power protoreflect.FieldDescriptor + fd_GenesisValidator_name protoreflect.FieldDescriptor +) + +func init() { + file_cosmos_genutil_v1beta1_genesis_proto_init() + md_GenesisValidator = File_cosmos_genutil_v1beta1_genesis_proto.Messages().ByName("GenesisValidator") + fd_GenesisValidator_address = md_GenesisValidator.Fields().ByName("address") + fd_GenesisValidator_consensus_pubkey = md_GenesisValidator.Fields().ByName("consensus_pubkey") + fd_GenesisValidator_voting_power = md_GenesisValidator.Fields().ByName("voting_power") + fd_GenesisValidator_name = md_GenesisValidator.Fields().ByName("name") +} + +var _ protoreflect.Message = (*fastReflection_GenesisValidator)(nil) + +type fastReflection_GenesisValidator GenesisValidator + +func (x *GenesisValidator) ProtoReflect() protoreflect.Message { + return (*fastReflection_GenesisValidator)(x) +} + +func (x *GenesisValidator) slowProtoReflect() protoreflect.Message { + mi := &file_cosmos_genutil_v1beta1_genesis_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_GenesisValidator_messageType fastReflection_GenesisValidator_messageType +var _ protoreflect.MessageType = fastReflection_GenesisValidator_messageType{} + +type fastReflection_GenesisValidator_messageType struct{} + +func (x fastReflection_GenesisValidator_messageType) Zero() protoreflect.Message { + return (*fastReflection_GenesisValidator)(nil) +} +func (x fastReflection_GenesisValidator_messageType) New() protoreflect.Message { + return new(fastReflection_GenesisValidator) +} +func (x fastReflection_GenesisValidator_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_GenesisValidator +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_GenesisValidator) Descriptor() protoreflect.MessageDescriptor { + return md_GenesisValidator +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_GenesisValidator) Type() protoreflect.MessageType { + return _fastReflection_GenesisValidator_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_GenesisValidator) New() protoreflect.Message { + return new(fastReflection_GenesisValidator) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_GenesisValidator) Interface() protoreflect.ProtoMessage { + return (*GenesisValidator)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_GenesisValidator) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Address != "" { + value := protoreflect.ValueOfString(x.Address) + if !f(fd_GenesisValidator_address, value) { + return + } + } + if x.ConsensusPubkey != nil { + value := protoreflect.ValueOfMessage(x.ConsensusPubkey.ProtoReflect()) + if !f(fd_GenesisValidator_consensus_pubkey, value) { + return + } + } + if x.VotingPower != int64(0) { + value := protoreflect.ValueOfInt64(x.VotingPower) + if !f(fd_GenesisValidator_voting_power, value) { + return + } + } + if x.Name != "" { + value := protoreflect.ValueOfString(x.Name) + if !f(fd_GenesisValidator_name, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_GenesisValidator) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "cosmos.genutil.v1beta1.GenesisValidator.address": + return x.Address != "" + case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": + return x.ConsensusPubkey != nil + case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": + return x.VotingPower != int64(0) + case "cosmos.genutil.v1beta1.GenesisValidator.name": + return x.Name != "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) + } + panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_GenesisValidator) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "cosmos.genutil.v1beta1.GenesisValidator.address": + x.Address = "" + case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": + x.ConsensusPubkey = nil + case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": + x.VotingPower = int64(0) + case "cosmos.genutil.v1beta1.GenesisValidator.name": + x.Name = "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) + } + panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_GenesisValidator) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "cosmos.genutil.v1beta1.GenesisValidator.address": + value := x.Address + return protoreflect.ValueOfString(value) + case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": + value := x.ConsensusPubkey + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": + value := x.VotingPower + return protoreflect.ValueOfInt64(value) + case "cosmos.genutil.v1beta1.GenesisValidator.name": + value := x.Name + return protoreflect.ValueOfString(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) + } + panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_GenesisValidator) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "cosmos.genutil.v1beta1.GenesisValidator.address": + x.Address = value.Interface().(string) + case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": + x.ConsensusPubkey = value.Message().Interface().(*anypb.Any) + case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": + x.VotingPower = value.Int() + case "cosmos.genutil.v1beta1.GenesisValidator.name": + x.Name = value.Interface().(string) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) + } + panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_GenesisValidator) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": + if x.ConsensusPubkey == nil { + x.ConsensusPubkey = new(anypb.Any) + } + return protoreflect.ValueOfMessage(x.ConsensusPubkey.ProtoReflect()) + case "cosmos.genutil.v1beta1.GenesisValidator.address": + panic(fmt.Errorf("field address of message cosmos.genutil.v1beta1.GenesisValidator is not mutable")) + case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": + panic(fmt.Errorf("field voting_power of message cosmos.genutil.v1beta1.GenesisValidator is not mutable")) + case "cosmos.genutil.v1beta1.GenesisValidator.name": + panic(fmt.Errorf("field name of message cosmos.genutil.v1beta1.GenesisValidator is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) + } + panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_GenesisValidator) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "cosmos.genutil.v1beta1.GenesisValidator.address": + return protoreflect.ValueOfString("") + case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": + m := new(anypb.Any) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": + return protoreflect.ValueOfInt64(int64(0)) + case "cosmos.genutil.v1beta1.GenesisValidator.name": + return protoreflect.ValueOfString("") + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) + } + panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_GenesisValidator) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in cosmos.genutil.v1beta1.GenesisValidator", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_GenesisValidator) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_GenesisValidator) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_GenesisValidator) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_GenesisValidator) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*GenesisValidator) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Address) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.ConsensusPubkey != nil { + l = options.Size(x.ConsensusPubkey) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.VotingPower != 0 { + n += 1 + runtime.Sov(uint64(x.VotingPower)) + } + l = len(x.Name) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*GenesisValidator) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.Name) > 0 { + i -= len(x.Name) + copy(dAtA[i:], x.Name) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Name))) + i-- + dAtA[i] = 0x22 + } + if x.VotingPower != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.VotingPower)) + i-- + dAtA[i] = 0x18 + } + if x.ConsensusPubkey != nil { + encoded, err := options.Marshal(x.ConsensusPubkey) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x12 + } + if len(x.Address) > 0 { + i -= len(x.Address) + copy(dAtA[i:], x.Address) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Address))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*GenesisValidator) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: GenesisValidator: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: GenesisValidator: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ConsensusPubkey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.ConsensusPubkey == nil { + x.ConsensusPubkey = &anypb.Any{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.ConsensusPubkey); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field VotingPower", wireType) + } + x.VotingPower = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.VotingPower |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 @@ -544,36 +1157,118 @@ func (x *GenesisState) GetGenTxs() [][]byte { return nil } +// GenesisValidator defines an initial validator. +type GenesisValidator struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // address defines the validator address. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // pub_key defines the validator public key. + ConsensusPubkey *anypb.Any `protobuf:"bytes,2,opt,name=consensus_pubkey,json=consensusPubkey,proto3" json:"consensus_pubkey,omitempty"` + // power defines the validator voting power. + VotingPower int64 `protobuf:"varint,3,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` + // name defines the validator name. + Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *GenesisValidator) Reset() { + *x = GenesisValidator{} + if protoimpl.UnsafeEnabled { + mi := &file_cosmos_genutil_v1beta1_genesis_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GenesisValidator) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GenesisValidator) ProtoMessage() {} + +// Deprecated: Use GenesisValidator.ProtoReflect.Descriptor instead. +func (*GenesisValidator) Descriptor() ([]byte, []int) { + return file_cosmos_genutil_v1beta1_genesis_proto_rawDescGZIP(), []int{1} +} + +func (x *GenesisValidator) GetAddress() string { + if x != nil { + return x.Address + } + return "" +} + +func (x *GenesisValidator) GetConsensusPubkey() *anypb.Any { + if x != nil { + return x.ConsensusPubkey + } + return nil +} + +func (x *GenesisValidator) GetVotingPower() int64 { + if x != nil { + return x.VotingPower + } + return 0 +} + +func (x *GenesisValidator) GetName() string { + if x != nil { + return x.Name + } + return "" +} + var File_cosmos_genutil_v1beta1_genesis_proto protoreflect.FileDescriptor var file_cosmos_genutil_v1beta1_genesis_proto_rawDesc = []byte{ 0x0a, 0x24, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x16, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x67, - 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x14, - 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x11, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x6d, 0x69, 0x6e, - 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5f, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, - 0x69, 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x4f, 0x0a, 0x07, 0x67, 0x65, 0x6e, 0x5f, 0x74, - 0x78, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x42, 0x36, 0xea, 0xde, 0x1f, 0x06, 0x67, 0x65, - 0x6e, 0x74, 0x78, 0x73, 0xfa, 0xde, 0x1f, 0x18, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, - 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x52, 0x61, 0x77, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0xa2, 0xe7, 0xb0, 0x2a, 0x06, 0x67, 0x65, 0x6e, 0x74, 0x78, 0x73, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, - 0x52, 0x06, 0x67, 0x65, 0x6e, 0x54, 0x78, 0x73, 0x42, 0xdc, 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, - 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, - 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, - 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, - 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2f, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, - 0x3b, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, - 0x02, 0x03, 0x43, 0x47, 0x58, 0xaa, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x47, - 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, - 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, - 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x22, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x5c, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, - 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x18, 0x43, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x3a, 0x3a, - 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x19, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, + 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x11, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x1a, 0x19, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5f, 0x0a, + 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x4f, 0x0a, + 0x07, 0x67, 0x65, 0x6e, 0x5f, 0x74, 0x78, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x42, 0x36, + 0xea, 0xde, 0x1f, 0x06, 0x67, 0x65, 0x6e, 0x74, 0x78, 0x73, 0xfa, 0xde, 0x1f, 0x18, 0x65, 0x6e, + 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x52, 0x61, 0x77, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0xa2, 0xe7, 0xb0, 0x2a, 0x06, 0x67, 0x65, 0x6e, 0x74, 0x78, + 0x73, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x54, 0x78, 0x73, 0x22, 0xe2, + 0x01, 0x0a, 0x10, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, + 0x74, 0x6f, 0x72, 0x12, 0x32, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x07, + 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x59, 0x0a, 0x10, 0x63, 0x6f, 0x6e, 0x73, 0x65, + 0x6e, 0x73, 0x75, 0x73, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x42, 0x18, 0xca, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x50, 0x75, 0x62, 0x4b, 0x65, + 0x79, 0x52, 0x0f, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x50, 0x75, 0x62, 0x6b, + 0x65, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x76, 0x6f, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x70, 0x6f, 0x77, + 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x76, 0x6f, 0x74, 0x69, 0x6e, 0x67, + 0x50, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x08, 0x88, 0xa0, 0x1f, 0x00, 0xe8, + 0xa0, 0x1f, 0x00, 0x42, 0xdc, 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x50, 0x01, 0x5a, 0x36, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x67, 0x65, 0x6e, 0x75, + 0x74, 0x69, 0x6c, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x67, 0x65, 0x6e, 0x75, + 0x74, 0x69, 0x6c, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x47, 0x58, + 0xaa, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, + 0x6c, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x5c, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0xe2, 0x02, 0x22, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x65, 0x6e, 0x75, + 0x74, 0x69, 0x6c, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x3a, 0x3a, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -588,16 +1283,19 @@ func file_cosmos_genutil_v1beta1_genesis_proto_rawDescGZIP() []byte { return file_cosmos_genutil_v1beta1_genesis_proto_rawDescData } -var file_cosmos_genutil_v1beta1_genesis_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_cosmos_genutil_v1beta1_genesis_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_cosmos_genutil_v1beta1_genesis_proto_goTypes = []interface{}{ - (*GenesisState)(nil), // 0: cosmos.genutil.v1beta1.GenesisState + (*GenesisState)(nil), // 0: cosmos.genutil.v1beta1.GenesisState + (*GenesisValidator)(nil), // 1: cosmos.genutil.v1beta1.GenesisValidator + (*anypb.Any)(nil), // 2: google.protobuf.Any } var file_cosmos_genutil_v1beta1_genesis_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 2, // 0: cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey:type_name -> google.protobuf.Any + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name } func init() { file_cosmos_genutil_v1beta1_genesis_proto_init() } @@ -618,6 +1316,18 @@ func file_cosmos_genutil_v1beta1_genesis_proto_init() { return nil } } + file_cosmos_genutil_v1beta1_genesis_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GenesisValidator); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -625,7 +1335,7 @@ func file_cosmos_genutil_v1beta1_genesis_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_cosmos_genutil_v1beta1_genesis_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 2, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/cosmos/genutil/v1beta1/genesis.proto b/proto/cosmos/genutil/v1beta1/genesis.proto index 45aa6bb22d2..50b826ea4a0 100644 --- a/proto/cosmos/genutil/v1beta1/genesis.proto +++ b/proto/cosmos/genutil/v1beta1/genesis.proto @@ -1,8 +1,10 @@ syntax = "proto3"; package cosmos.genutil.v1beta1; +import "google/protobuf/any.proto"; import "gogoproto/gogo.proto"; import "amino/amino.proto"; +import "cosmos_proto/cosmos.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/genutil/types"; @@ -16,3 +18,18 @@ message GenesisState { (amino.dont_omitempty) = true ]; } + +// GenesisValidator defines an initial validator. +message GenesisValidator { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // address defines the validator address. + string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // pub_key defines the validator public key. + google.protobuf.Any consensus_pubkey = 2 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; + // power defines the validator voting power. + int64 voting_power = 3; + // name defines the validator name. + string name = 4; +} \ No newline at end of file diff --git a/server/export.go b/server/export.go index c1a57391fca..959abd95f14 100644 --- a/server/export.go +++ b/server/export.go @@ -5,7 +5,6 @@ import ( "fmt" "os" - cmttypes "github.com/cometbft/cometbft/types" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/flags" @@ -74,30 +73,16 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return fmt.Errorf("error exporting state: %v", err) } - genDoc, err := cmttypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) + appGenesis, err := genutiltypes.AppGenesisFromFile(serverCtx.Config.GenesisFile()) if err != nil { return err } - genDoc.AppState = exported.AppState - genDoc.Validators = exported.Validators - genDoc.InitialHeight = exported.Height - genDoc.ConsensusParams = &cmttypes.ConsensusParams{ - Block: cmttypes.BlockParams{ - MaxBytes: exported.ConsensusParams.Block.MaxBytes, - MaxGas: exported.ConsensusParams.Block.MaxGas, - }, - Evidence: cmttypes.EvidenceParams{ - MaxAgeNumBlocks: exported.ConsensusParams.Evidence.MaxAgeNumBlocks, - MaxAgeDuration: exported.ConsensusParams.Evidence.MaxAgeDuration, - MaxBytes: exported.ConsensusParams.Evidence.MaxBytes, - }, - Validator: cmttypes.ValidatorParams{ - PubKeyTypes: exported.ConsensusParams.Validator.PubKeyTypes, - }, - } + appGenesis.AppState = exported.AppState + appGenesis.Validators = exported.Validators + appGenesis.InitialHeight = exported.Height + appGenesis.ConsensusParams = appGenesis.ConsensusParams - appGenesis := genutiltypes.NewAppGenesis(*genDoc) encoded, err := json.Marshal(appGenesis) if err != nil { return err diff --git a/server/start.go b/server/start.go index 7ad4ca73ade..2c14d995112 100644 --- a/server/start.go +++ b/server/start.go @@ -8,12 +8,13 @@ import ( "time" "github.com/cometbft/cometbft/abci/server" - tcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" + cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" "github.com/cometbft/cometbft/node" "github.com/cometbft/cometbft/p2p" pvm "github.com/cometbft/cometbft/privval" "github.com/cometbft/cometbft/proxy" "github.com/cometbft/cometbft/rpc/client/local" + cmttypes "github.com/cometbft/cometbft/types" "github.com/spf13/cobra" "github.com/spf13/pflag" "google.golang.org/grpc" @@ -30,6 +31,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/telemetry" "github.com/cosmos/cosmos-sdk/types/mempool" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) const ( @@ -204,7 +206,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. }) // add support for all CometBFT-specific command line options - tcmd.AddNodeFlags(cmd) + cmtcmd.AddNodeFlags(cmd) return cmd } @@ -301,7 +303,14 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App if err != nil { return err } - genDocProvider := node.DefaultGenesisDocProviderFunc(cfg) + genDocProvider := func() (*cmttypes.GenesisDoc, error) { + appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile()) + if err != nil { + return nil, err + } + + return appGenesis.ToCometBFTGenesisDoc() + } var ( tmNode *node.Node diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 7b0734b6d69..3ddc4945718 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -11,7 +11,6 @@ import ( cmtconfig "github.com/cometbft/cometbft/config" cmtrand "github.com/cometbft/cometbft/libs/rand" - cmttypes "github.com/cometbft/cometbft/types" cmttime "github.com/cometbft/cometbft/types/time" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -392,11 +391,11 @@ func initGenFiles( return err } - appGenesis := genutiltypes.NewAppGenesis(cmttypes.GenesisDoc{ + appGenesis := genutiltypes.AppGenesis{ ChainID: chainID, AppState: appGenStateJSON, Validators: nil, - }) + } // generate empty genesis files for each validator and save for i := 0; i < numValidators; i++ { @@ -426,12 +425,12 @@ func collectGenFiles( nodeID, valPubKey := nodeIDs[i], valPubKeys[i] initCfg := genutiltypes.NewInitConfig(chainID, gentxsDir, nodeID, valPubKey) - genDoc, err := cmttypes.GenesisDocFromFile(nodeConfig.GenesisFile()) + appGenesis, err := genutiltypes.AppGenesisFromFile(nodeConfig.GenesisFile()) if err != nil { return err } - nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, *genDoc, genBalIterator, genutiltypes.DefaultMessageValidator) + nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, appGenesis, genBalIterator, genutiltypes.DefaultMessageValidator) if err != nil { return err } diff --git a/testutil/network/util.go b/testutil/network/util.go index dd2aa87ec84..ef29df4a8fa 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -40,14 +40,21 @@ func startInProcess(cfg Config, val *Validator) error { } app := cfg.AppConstructor(*val) - genDocProvider := node.DefaultGenesisDocProviderFunc(cmtCfg) + appGenesisProvider := func() (*cmttypes.GenesisDoc, error) { + appGenesis, err := genutiltypes.AppGenesisFromFile(cmtCfg.GenesisFile()) + if err != nil { + return nil, err + } + + return appGenesis.ToCometBFTGenesisDoc() + } tmNode, err := node.NewNode( //resleak:notresource cmtCfg, pvm.LoadOrGenFilePV(cmtCfg.PrivValidatorKeyFile(), cmtCfg.PrivValidatorStateFile()), nodeKey, proxy.NewLocalClientCreator(app), - genDocProvider, + appGenesisProvider, node.DefaultDBProvider, node.DefaultMetricsProvider(cmtCfg.Instrumentation), logger.With("module", val.Moniker), @@ -123,13 +130,13 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { initCfg := genutiltypes.NewInitConfig(cfg.ChainID, gentxsDir, vals[i].NodeID, vals[i].PubKey) genFile := cmtCfg.GenesisFile() - genDoc, err := cmttypes.GenesisDocFromFile(genFile) + appGenesis, err := genutiltypes.AppGenesisFromFile(genFile) if err != nil { return err } appState, err := genutil.GenAppStateFromConfig(cfg.Codec, cfg.TxConfig, - cmtCfg, initCfg, *genDoc, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator) + cmtCfg, initCfg, appGenesis, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator) if err != nil { return err } @@ -168,11 +175,11 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance return err } - appGenesis := genutiltypes.NewAppGenesis(cmttypes.GenesisDoc{ + appGenesis := genutiltypes.AppGenesis{ ChainID: cfg.ChainID, AppState: appGenStateJSON, Validators: nil, - }) + } // generate empty genesis files for each validator and save for i := 0; i < cfg.NumValidators; i++ { diff --git a/x/auth/helpers/genaccounts.go b/x/auth/helpers/genaccounts.go index f2af64e4c0f..817d4f71095 100644 --- a/x/auth/helpers/genaccounts.go +++ b/x/auth/helpers/genaccounts.go @@ -69,7 +69,7 @@ func AddGenesisAccount( return fmt.Errorf("failed to validate new genesis account: %w", err) } - appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genesisFileURL) + appState, appGenesis, err := genutiltypes.GenesisStateFromGenFile(genesisFileURL) if err != nil { return fmt.Errorf("failed to unmarshal genesis state: %w", err) } @@ -132,6 +132,6 @@ func AddGenesisAccount( return fmt.Errorf("failed to marshal application genesis state: %w", err) } - genDoc.AppState = appStateJSON - return genutil.ExportGenesisFile(genDoc, genesisFileURL) + appGenesis.AppState = appStateJSON + return genutil.ExportGenesisFile(appGenesis, genesisFileURL) } diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index 84860c9f515..93785a95584 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -4,7 +4,6 @@ import ( "encoding/json" "path/filepath" - cmttypes "github.com/cometbft/cometbft/types" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -36,7 +35,7 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeH return errors.Wrap(err, "failed to initialize node validator files") } - genDoc, err := cmttypes.GenesisDocFromFile(config.GenesisFile()) + appGenesis, err := types.AppGenesisFromFile(config.GenesisFile()) if err != nil { return errors.Wrap(err, "failed to read genesis doc from file") } @@ -47,12 +46,10 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeH genTxsDir = filepath.Join(config.RootDir, "config", "gentx") } - toPrint := newPrintInfo(config.Moniker, genDoc.ChainID, nodeID, genTxsDir, json.RawMessage("")) - initCfg := types.NewInitConfig(genDoc.ChainID, genTxsDir, nodeID, valPubKey) + toPrint := newPrintInfo(config.Moniker, appGenesis.ChainID, nodeID, genTxsDir, json.RawMessage("")) + initCfg := types.NewInitConfig(appGenesis.ChainID, genTxsDir, nodeID, valPubKey) - appMessage, err := genutil.GenAppStateFromConfig(cdc, - clientCtx.TxConfig, - config, initCfg, *genDoc, genBalIterator, validator) + appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config, initCfg, appGenesis, genBalIterator, validator) if err != nil { return errors.Wrap(err, "failed to get genesis app state from config") } diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 70fc4410042..58d86018371 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -9,7 +9,6 @@ import ( "os" "path/filepath" - cmttypes "github.com/cometbft/cometbft/types" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -81,13 +80,13 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o } } - genDoc, err := cmttypes.GenesisDocFromFile(config.GenesisFile()) + appGenesis, err := types.AppGenesisFromFile(config.GenesisFile()) if err != nil { return errors.Wrapf(err, "failed to read genesis doc file %s", config.GenesisFile()) } var genesisState map[string]json.RawMessage - if err = json.Unmarshal(genDoc.AppState, &genesisState); err != nil { + if err = json.Unmarshal(appGenesis.AppState, &genesisState); err != nil { return errors.Wrap(err, "failed to unmarshal genesis state") } @@ -109,7 +108,7 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o } // set flags for creating a gentx - createValCfg, err := cli.PrepareConfigForTxCreateValidator(cmd.Flags(), moniker, nodeID, genDoc.ChainID, valPubKey) + createValCfg, err := cli.PrepareConfigForTxCreateValidator(cmd.Flags(), moniker, nodeID, appGenesis.ChainID, valPubKey) if err != nil { return errors.Wrap(err, "error creating configuration to create validator msg") } diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 408fd6e396d..bcad145c10e 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -10,7 +10,6 @@ import ( cfg "github.com/cometbft/cometbft/config" "github.com/cometbft/cometbft/libs/cli" cmtrand "github.com/cometbft/cometbft/libs/rand" - "github.com/cometbft/cometbft/types" "github.com/cosmos/go-bip39" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -22,6 +21,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil" + "github.com/cosmos/cosmos-sdk/x/genutil/types" ) const ( @@ -133,23 +133,23 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { return errors.Wrap(err, "Failed to marshal default genesis state") } - genDoc := &types.GenesisDoc{} + appGenesis := types.AppGenesis{} if _, err := os.Stat(genFile); err != nil { if !os.IsNotExist(err) { return err } } else { - genDoc, err = types.GenesisDocFromFile(genFile) + appGenesis, err = types.AppGenesisFromFile(genFile) if err != nil { return errors.Wrap(err, "Failed to read genesis doc from file") } } - genDoc.ChainID = chainID - genDoc.Validators = nil - genDoc.AppState = appState + appGenesis.ChainID = chainID + appGenesis.Validators = nil + appGenesis.AppState = appState - if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil { + if err = genutil.ExportGenesisFile(appGenesis, genFile); err != nil { return errors.Wrap(err, "Failed to export genesis file") } diff --git a/x/genutil/collect.go b/x/genutil/collect.go index 8a8f856ea0f..4532d0d0a50 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -11,7 +11,6 @@ import ( "strings" cfg "github.com/cometbft/cometbft/config" - cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -23,12 +22,12 @@ import ( // GenAppStateFromConfig gets the genesis app state from the config func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodingConfig, - config *cfg.Config, initCfg types.InitConfig, genDoc cmttypes.GenesisDoc, genBalIterator types.GenesisBalancesIterator, + config *cfg.Config, initCfg types.InitConfig, genesis types.AppGenesis, genBalIterator types.GenesisBalancesIterator, validator types.MessageValidator, ) (appState json.RawMessage, err error) { // process genesis transactions, else create default genesis.json appGenTxs, persistentPeers, err := CollectTxs( - cdc, txEncodingConfig.TxJSONDecoder(), config.Moniker, initCfg.GenTxsDir, genDoc, genBalIterator, validator) + cdc, txEncodingConfig.TxJSONDecoder(), config.Moniker, initCfg.GenTxsDir, genesis, genBalIterator, validator) if err != nil { return appState, err } @@ -42,7 +41,7 @@ func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodi } // create the app state - appGenesisState, err := types.GenesisStateFromGenDoc(genDoc) + appGenesisState, err := types.GenesisStateFromAppGenesis(genesis) if err != nil { return appState, err } @@ -57,8 +56,8 @@ func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodi return appState, err } - genDoc.AppState = appState - err = ExportGenesisFile(&genDoc, config.GenesisFile()) + genesis.AppState = appState + err = ExportGenesisFile(genesis, config.GenesisFile()) return appState, err } @@ -66,13 +65,13 @@ func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodi // CollectTxs processes and validates application's genesis Txs and returns // the list of appGenTxs, and persistent peers required to generate genesis.json. func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, - genDoc cmttypes.GenesisDoc, genBalIterator types.GenesisBalancesIterator, + genesis types.AppGenesis, genBalIterator types.GenesisBalancesIterator, validator types.MessageValidator, ) (appGenTxs []sdk.Tx, persistentPeers string, err error) { // prepare a map of all balances in genesis state to then validate // against the validators addresses var appState map[string]json.RawMessage - if err := json.Unmarshal(genDoc.AppState, &appState); err != nil { + if err := json.Unmarshal(genesis.AppState, &appState); err != nil { return appGenTxs, persistentPeers, err } diff --git a/x/genutil/collect_test.go b/x/genutil/collect_test.go index ac1a9f66bbf..4179fd2230a 100644 --- a/x/genutil/collect_test.go +++ b/x/genutil/collect_test.go @@ -8,15 +8,13 @@ import ( "github.com/cosmos/gogoproto/proto" - cmttypes "github.com/cometbft/cometbft/types" - "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/types" + sdk "github.com/cosmos/cosmos-sdk/types" bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported" "github.com/cosmos/cosmos-sdk/x/genutil" - gtypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/genutil/types" ) type doNothingUnmarshalJSON struct { @@ -28,7 +26,7 @@ func (dnj *doNothingUnmarshalJSON) UnmarshalJSON(_ []byte, _ proto.Message) erro } type doNothingIterator struct { - gtypes.GenesisBalancesIterator + types.GenesisBalancesIterator } func (dni *doNothingIterator) IterateGenesisBalances(_ codec.JSONCodec, _ map[string]json.RawMessage, _ func(bankexported.GenesisBalance) bool) { @@ -49,7 +47,7 @@ func TestCollectTxsHandlesDirectories(t *testing.T) { t.Fatal(err) } - txDecoder := types.TxDecoder(func(txBytes []byte) (types.Tx, error) { + txDecoder := sdk.TxDecoder(func(txBytes []byte) (sdk.Tx, error) { return nil, nil }) @@ -57,11 +55,11 @@ func TestCollectTxsHandlesDirectories(t *testing.T) { srvCtx := server.NewDefaultContext() _ = srvCtx cdc := codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) - gdoc := cmttypes.GenesisDoc{AppState: []byte("{}")} + genesis := types.AppGenesis{AppState: []byte("{}")} balItr := new(doNothingIterator) dnc := &doNothingUnmarshalJSON{cdc} - if _, _, err := genutil.CollectTxs(dnc, txDecoder, "foo", testDir, gdoc, balItr, gtypes.DefaultMessageValidator); err != nil { + if _, _, err := genutil.CollectTxs(dnc, txDecoder, "foo", testDir, genesis, balItr, types.DefaultMessageValidator); err != nil { t.Fatal(err) } } diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 49acbeaa79b..5913c9e937f 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -2,34 +2,76 @@ package types import ( "encoding/json" + fmt "fmt" "os" + "time" cmtjson "github.com/cometbft/cometbft/libs/json" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" - "github.com/cosmos/cosmos-sdk/version" + + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) // AppGenesisOnly defines the app's genesis. -type AppGenesisOnly struct { - AppName string `json:"app_name"` - AppVersion string `json:"app_version"` +type AppGenesis struct { + AppName string `json:"app_name"` + AppVersion string `json:"app_version"` + GenesisTime time.Time `json:"genesis_time"` + ChainID string `json:"chain_id"` + InitialHeight int64 `json:"initial_height"` + ConsensusParams *cmtproto.ConsensusParams `json:"consensus_params,omitempty"` + Validators []GenesisValidator `json:"validators,omitempty"` + AppHash []byte `json:"app_hash"` + AppState json.RawMessage `json:"app_state,omitempty"` } -// AppGenesis defines the app's genesis with the consensus genesis. -type AppGenesis struct { - AppGenesisOnly +// ToCometBFTGenesisDoc converts the AppGenesis to a CometBFT GenesisDoc. +func (ag AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { + cmtValidators := make([]cmttypes.GenesisValidator, len(ag.Validators)) + for i, v := range ag.Validators { - cmttypes.GenesisDoc -} + var pubKey cryptotypes.PubKey + if err := json.Unmarshal(v.ConsensusPubkey.Value, pubKey); err != nil { + return nil, fmt.Errorf("failed to unmarshal validator consensus pubkey: %v: %w", v.ConsensusPubkey, err) + } -func NewAppGenesis(genesisDoc cmttypes.GenesisDoc) *AppGenesis { - return &AppGenesis{ - AppGenesisOnly: AppGenesisOnly{ - AppName: version.AppName, - AppVersion: version.Version, - }, - GenesisDoc: genesisDoc, + cmtPk, err := cryptocodec.ToCmtPubKeyInterface(pubKey) + if err != nil { + return nil, fmt.Errorf("failed to convert validator consensus pubkey to cmt proto: %v: %w", v.ConsensusPubkey, err) + } + + cmtValidators[i] = cmttypes.GenesisValidator{ + Address: sdk.ConsAddress(v.Address).Bytes(), + PubKey: cmtPk, + Power: v.VotingPower, + Name: v.Name, + } } + + return &cmttypes.GenesisDoc{ + ChainID: ag.ChainID, + InitialHeight: ag.InitialHeight, + ConsensusParams: &cmttypes.ConsensusParams{ + Block: cmttypes.BlockParams{ + MaxBytes: ag.ConsensusParams.Block.MaxBytes, + MaxGas: ag.ConsensusParams.Block.MaxGas, + }, + Evidence: cmttypes.EvidenceParams{ + MaxAgeNumBlocks: ag.ConsensusParams.Evidence.MaxAgeNumBlocks, + MaxAgeDuration: ag.ConsensusParams.Evidence.MaxAgeDuration, + MaxBytes: ag.ConsensusParams.Evidence.MaxBytes, + }, + Validator: cmttypes.ValidatorParams{ + PubKeyTypes: ag.ConsensusParams.Validator.PubKeyTypes, + }, + }, + Validators: cmtValidators, + AppHash: ag.AppHash, + AppState: ag.AppState, + }, nil } // SaveAs is a utility method for saving AppGenesis as a JSON file. @@ -45,23 +87,8 @@ func (ag *AppGenesis) SaveAs(file string) error { // Marshal the AppGenesis. func (ag *AppGenesis) MarshalJSON() ([]byte, error) { - // marshal the genesis doc with CometBFT lib - // if GenesisDoc was implementing MarshalJSON and UnmarshalJSON, this would be much simpler - genDoc, err := cmtjson.Marshal(ag.GenesisDoc) - if err != nil { - return nil, err - } - - type ConsensusGenesis []byte - // unmarshal the genesis doc with stdlib - return json.Marshal(&struct { - AppGenesisOnly - ConsensusGenesis - }{ - AppGenesisOnly: ag.AppGenesisOnly, - ConsensusGenesis: genDoc, - }) + return json.Marshal(&struct{}{}) } // MarshalIndent marshals the AppGenesis with the provided prefix and indent. @@ -81,3 +108,18 @@ func (ag *AppGenesis) UnmarshalJSON(bz []byte) error { ag = (*AppGenesis)(&result) return nil } + +// AppGenesisFromFile reads the AppGenesis from the provided file. +func AppGenesisFromFile(genFile string) (AppGenesis, error) { + jsonBlob, err := os.ReadFile(genFile) + if err != nil { + return AppGenesis{}, fmt.Errorf("couldn't read AppGenesis file (%s): %w", genFile, err) + } + + var appGenesis AppGenesis + if err := json.Unmarshal(jsonBlob, &appGenesis); err != nil { + return AppGenesis{}, fmt.Errorf("error unmarshalling AppGenesis at %s: %w", genFile, err) + } + + return appGenesis, nil +} diff --git a/x/genutil/types/genesis.pb.go b/x/genutil/types/genesis.pb.go index ca3ee3fed20..5c16b1cdb3e 100644 --- a/x/genutil/types/genesis.pb.go +++ b/x/genutil/types/genesis.pb.go @@ -6,6 +6,8 @@ package types import ( encoding_json "encoding/json" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" @@ -71,8 +73,54 @@ func (m *GenesisState) GetGenTxs() []encoding_json.RawMessage { return nil } +// GenesisValidator defines an initial validator. +type GenesisValidator struct { + // address defines the validator address. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // pub_key defines the validator public key. + ConsensusPubkey *types.Any `protobuf:"bytes,2,opt,name=consensus_pubkey,json=consensusPubkey,proto3" json:"consensus_pubkey,omitempty"` + // power defines the validator voting power. + VotingPower int64 `protobuf:"varint,3,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` + // name defines the validator name. + Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *GenesisValidator) Reset() { *m = GenesisValidator{} } +func (m *GenesisValidator) String() string { return proto.CompactTextString(m) } +func (*GenesisValidator) ProtoMessage() {} +func (*GenesisValidator) Descriptor() ([]byte, []int) { + return fileDescriptor_31771d25e8d8f90f, []int{1} +} +func (m *GenesisValidator) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisValidator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisValidator.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisValidator) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisValidator.Merge(m, src) +} +func (m *GenesisValidator) XXX_Size() int { + return m.Size() +} +func (m *GenesisValidator) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisValidator.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisValidator proto.InternalMessageInfo + func init() { proto.RegisterType((*GenesisState)(nil), "cosmos.genutil.v1beta1.GenesisState") + proto.RegisterType((*GenesisValidator)(nil), "cosmos.genutil.v1beta1.GenesisValidator") } func init() { @@ -80,23 +128,35 @@ func init() { } var fileDescriptor_31771d25e8d8f90f = []byte{ - // 244 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0xce, 0x2f, 0xce, - 0xcd, 0x2f, 0xd6, 0x4f, 0x4f, 0xcd, 0x2b, 0x2d, 0xc9, 0xcc, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, - 0x49, 0x34, 0x04, 0xf1, 0x53, 0x8b, 0x33, 0x8b, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xc4, - 0x20, 0xaa, 0xf4, 0xa0, 0xaa, 0xf4, 0xa0, 0xaa, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4a, - 0xf4, 0x41, 0x2c, 0x88, 0x6a, 0x29, 0xc1, 0xc4, 0xdc, 0xcc, 0xbc, 0x7c, 0x7d, 0x30, 0x09, 0x11, - 0x52, 0x8a, 0xe7, 0xe2, 0x71, 0x87, 0x98, 0x18, 0x5c, 0x92, 0x58, 0x92, 0x2a, 0xe4, 0xcf, 0xc5, - 0x9e, 0x9e, 0x9a, 0x17, 0x5f, 0x52, 0x51, 0x2c, 0xc1, 0xa8, 0xc0, 0xac, 0xc1, 0xe3, 0x64, 0xf6, - 0xea, 0x9e, 0x3c, 0x5b, 0x7a, 0x6a, 0x5e, 0x49, 0x45, 0xf1, 0xaf, 0x7b, 0xf2, 0x12, 0xa9, 0x79, - 0xc9, 0xf9, 0x29, 0x99, 0x79, 0xe9, 0xfa, 0x59, 0xc5, 0xf9, 0x79, 0x7a, 0x41, 0x89, 0xe5, 0xbe, - 0xa9, 0xc5, 0xc5, 0x89, 0xe9, 0xa9, 0x8b, 0x9e, 0x6f, 0xd0, 0x82, 0x2a, 0x5b, 0xf1, 0x7c, 0x83, - 0x16, 0x63, 0x10, 0x88, 0x13, 0x52, 0x51, 0xec, 0xe4, 0x76, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, - 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, - 0xc7, 0x72, 0x0c, 0x51, 0x3a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, - 0x50, 0xcf, 0x42, 0x28, 0xdd, 0xe2, 0x94, 0x6c, 0xfd, 0x0a, 0xb8, 0xcf, 0x4b, 0x2a, 0x0b, 0x52, - 0x8b, 0x93, 0xd8, 0xc0, 0xee, 0x35, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xb1, 0x4e, 0x6d, 0x9e, - 0x18, 0x01, 0x00, 0x00, + // 433 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x92, 0xb1, 0x6e, 0xd4, 0x40, + 0x10, 0x86, 0xbd, 0x5c, 0x94, 0x80, 0x73, 0x12, 0xc1, 0x3a, 0x21, 0x27, 0x85, 0xef, 0x88, 0x28, + 0x4e, 0x11, 0x59, 0x2b, 0x41, 0xa2, 0xa0, 0xcb, 0x15, 0x50, 0x20, 0xc4, 0xc9, 0x41, 0x48, 0xd0, + 0x58, 0x6b, 0x7b, 0x58, 0x4c, 0xee, 0x76, 0x2c, 0xcf, 0x3a, 0x39, 0xbf, 0x01, 0x25, 0x8f, 0x10, + 0x51, 0x51, 0xa6, 0xe0, 0x21, 0x10, 0x55, 0x44, 0x45, 0x15, 0x21, 0x5f, 0x11, 0xc4, 0x23, 0x50, + 0x21, 0x7b, 0x37, 0x49, 0xb3, 0x3b, 0xf3, 0xef, 0xb7, 0xff, 0xcc, 0x8e, 0xd6, 0x7d, 0x98, 0x22, + 0xcd, 0x91, 0x42, 0x09, 0xaa, 0xd2, 0xf9, 0x2c, 0x3c, 0xde, 0x4b, 0x40, 0x8b, 0xbd, 0x36, 0x07, + 0xca, 0x89, 0x17, 0x25, 0x6a, 0xf4, 0xee, 0x1b, 0x8a, 0x5b, 0x8a, 0x5b, 0x6a, 0x6b, 0x53, 0x22, + 0xca, 0x19, 0x84, 0x1d, 0x95, 0x54, 0xef, 0x43, 0xa1, 0x6a, 0x73, 0x65, 0x6b, 0x20, 0x51, 0x62, + 0x17, 0x86, 0x6d, 0x64, 0xd5, 0x7b, 0x62, 0x9e, 0x2b, 0x0c, 0xbb, 0xd5, 0x4a, 0x9b, 0xc6, 0x3b, + 0x36, 0xac, 0x2d, 0xd4, 0x25, 0xdb, 0xb1, 0xdb, 0x7f, 0x6e, 0xfa, 0x38, 0xd4, 0x42, 0x83, 0xf7, + 0xca, 0x5d, 0x93, 0xa0, 0x62, 0xbd, 0x20, 0x9f, 0x8d, 0x7a, 0xe3, 0xfe, 0xe4, 0xc9, 0xdf, 0x8b, + 0xe1, 0xaa, 0x04, 0xa5, 0x17, 0xf4, 0xef, 0x62, 0xe8, 0x83, 0x4a, 0x31, 0xcb, 0x95, 0x0c, 0x3f, + 0x12, 0x2a, 0x1e, 0x89, 0x93, 0x97, 0x40, 0x24, 0x24, 0x7c, 0xb9, 0x3c, 0xdb, 0xb1, 0xd8, 0xd7, + 0xcb, 0xb3, 0x1d, 0x16, 0xb5, 0xc9, 0xeb, 0x05, 0x6d, 0x37, 0xcc, 0xdd, 0xb0, 0x15, 0xde, 0x88, + 0x59, 0x9e, 0x09, 0x8d, 0xa5, 0xb7, 0xef, 0xae, 0x89, 0x2c, 0x2b, 0x81, 0xda, 0x2a, 0x6c, 0x7c, + 0x67, 0xe2, 0xff, 0xfc, 0xb6, 0x3b, 0xb0, 0x8d, 0x1d, 0x98, 0x93, 0x43, 0x5d, 0xe6, 0x4a, 0x46, + 0x57, 0xa0, 0xf7, 0xd6, 0xdd, 0x48, 0x51, 0x11, 0x28, 0xaa, 0x28, 0x2e, 0xaa, 0xe4, 0x08, 0x6a, + 0xff, 0xd6, 0x88, 0x8d, 0xd7, 0xf7, 0x07, 0xdc, 0xcc, 0x88, 0x5f, 0xcd, 0x88, 0x1f, 0xa8, 0x7a, + 0xe2, 0xff, 0xb8, 0xb1, 0x4c, 0xcb, 0xba, 0xd0, 0xc8, 0xa7, 0x55, 0xf2, 0x02, 0xea, 0xe8, 0xee, + 0xb5, 0xcf, 0xb4, 0xb3, 0xf1, 0x1e, 0xb8, 0xfd, 0x63, 0xd4, 0xb9, 0x92, 0x71, 0x81, 0x27, 0x50, + 0xfa, 0xbd, 0x11, 0x1b, 0xf7, 0xa2, 0x75, 0xa3, 0x4d, 0x5b, 0xc9, 0xf3, 0xdc, 0x15, 0x25, 0xe6, + 0xe0, 0xaf, 0xb4, 0xed, 0x46, 0x5d, 0xfc, 0xf4, 0xf6, 0xa7, 0xd3, 0xa1, 0xf3, 0xe7, 0x74, 0xe8, + 0x4c, 0x9e, 0x7d, 0x6f, 0x02, 0x76, 0xde, 0x04, 0xec, 0x77, 0x13, 0xb0, 0xcf, 0xcb, 0xc0, 0x39, + 0x5f, 0x06, 0xce, 0xaf, 0x65, 0xe0, 0xbc, 0x7b, 0x24, 0x73, 0xfd, 0xa1, 0x4a, 0x78, 0x8a, 0x73, + 0x3b, 0x78, 0xbb, 0xed, 0x52, 0x76, 0x14, 0x2e, 0xae, 0x3f, 0x85, 0xae, 0x0b, 0xa0, 0x64, 0xb5, + 0x7b, 0xc1, 0xe3, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb1, 0xd8, 0xdd, 0x0b, 0x33, 0x02, 0x00, + 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -131,6 +191,60 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *GenesisValidator) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisValidator) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x22 + } + if m.VotingPower != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.VotingPower)) + i-- + dAtA[i] = 0x18 + } + if m.ConsensusPubkey != nil { + { + size, err := m.ConsensusPubkey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -157,6 +271,30 @@ func (m *GenesisState) Size() (n int) { return n } +func (m *GenesisValidator) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.ConsensusPubkey != nil { + l = m.ConsensusPubkey.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + if m.VotingPower != 0 { + n += 1 + sovGenesis(uint64(m.VotingPower)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + func sovGenesis(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -245,6 +383,175 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } +func (m *GenesisValidator) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisValidator: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisValidator: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusPubkey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.ConsensusPubkey == nil { + m.ConsensusPubkey = &types.Any{} + } + if err := m.ConsensusPubkey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VotingPower", wireType) + } + m.VotingPower = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.VotingPower |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipGenesis(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/genutil/types/genesis_state.go b/x/genutil/types/genesis_state.go index f1b4f6884de..d3e624c9447 100644 --- a/x/genutil/types/genesis_state.go +++ b/x/genutil/types/genesis_state.go @@ -5,8 +5,6 @@ import ( "fmt" "os" - cmttypes "github.com/cometbft/cometbft/types" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -62,12 +60,12 @@ func SetGenesisStateInAppState( return appState } -// GenesisStateFromGenDoc creates the core parameters for genesis initialization +// GenesisStateFromAppGenesis creates the core parameters for genesis initialization // for the application. // // NOTE: The pubkey input is this machines pubkey. -func GenesisStateFromGenDoc(genDoc cmttypes.GenesisDoc) (genesisState map[string]json.RawMessage, err error) { - if err = json.Unmarshal(genDoc.AppState, &genesisState); err != nil { +func GenesisStateFromAppGenesis(gesnsis AppGenesis) (genesisState map[string]json.RawMessage, err error) { + if err = json.Unmarshal(gesnsis.AppState, &genesisState); err != nil { return genesisState, err } return genesisState, nil @@ -77,19 +75,18 @@ func GenesisStateFromGenDoc(genDoc cmttypes.GenesisDoc) (genesisState map[string // for the application. // // NOTE: The pubkey input is this machines pubkey. -func GenesisStateFromGenFile(genFile string) (genesisState map[string]json.RawMessage, genDoc *cmttypes.GenesisDoc, err error) { +func GenesisStateFromGenFile(genFile string) (genesisState map[string]json.RawMessage, genesis AppGenesis, err error) { if _, err := os.Stat(genFile); os.IsNotExist(err) { - return genesisState, genDoc, - fmt.Errorf("%s does not exist, run `init` first", genFile) + return genesisState, genesis, fmt.Errorf("%s does not exist, run `init` first", genFile) } - genDoc, err = cmttypes.GenesisDocFromFile(genFile) + genesis, err = AppGenesisFromFile(genFile) if err != nil { - return genesisState, genDoc, err + return genesisState, genesis, err } - genesisState, err = GenesisStateFromGenDoc(*genDoc) - return genesisState, genDoc, err + genesisState, err = GenesisStateFromAppGenesis(genesis) + return genesisState, genesis, err } // ValidateGenesis validates GenTx transactions diff --git a/x/genutil/types/genesis_test.go b/x/genutil/types/genesis_test.go index ada23f03dd8..184a2dc7df2 100644 --- a/x/genutil/types/genesis_test.go +++ b/x/genutil/types/genesis_test.go @@ -4,23 +4,17 @@ import ( "encoding/json" "testing" - "gotest.tools/v3/assert" - - cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/x/genutil/types" + "gotest.tools/v3/assert" ) var expectedAppGenesisJSON = `{"app_name":"simapp","app_version":"0.1.0","genesis_time":"0001-01-01T00:00:00Z","chain_id":"test","initial_height":"0","app_hash":""}` func TestAppGenesis_Marshal(t *testing.T) { genesis := types.AppGenesis{ - AppGenesisOnly: types.AppGenesisOnly{ - AppName: "simapp", - AppVersion: "0.1.0", - }, - GenesisDoc: cmttypes.GenesisDoc{ - ChainID: "test", - }, + AppName: "simapp", + AppVersion: "0.1.0", + ChainID: "test", } out, err := json.Marshal(&genesis) @@ -38,3 +32,17 @@ func TestAppGenesis_Unmarshal(t *testing.T) { assert.DeepEqual(t, genesis.AppVersion, "0.1.0") assert.DeepEqual(t, genesis.ChainID, "test") } + +func TestAppGenesis_ToCometBFTGenesisDoc(t *testing.T) { + genesis := types.AppGenesis{ + AppName: "simapp", + AppVersion: "0.1.0", + ChainID: "test", + AppHash: []byte{5, 34, 11, 3, 23}, + } + + cmtGenesis, err := genesis.ToCometBFTGenesisDoc() + assert.NilError(t, err) + assert.DeepEqual(t, cmtGenesis.ChainID, "test") + assert.DeepEqual(t, cmtGenesis.AppHash.String(), "05220B0317") +} diff --git a/x/genutil/utils.go b/x/genutil/utils.go index 6c7617bda41..abb860a42be 100644 --- a/x/genutil/utils.go +++ b/x/genutil/utils.go @@ -11,41 +11,38 @@ import ( tmed25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/p2p" "github.com/cometbft/cometbft/privval" - cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/go-bip39" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // ExportGenesisFile creates and writes the genesis configuration to disk. An // error is returned if building or writing the configuration to file fails. -func ExportGenesisFile(genDoc *cmttypes.GenesisDoc, genFile string) error { - if err := genDoc.ValidateAndComplete(); err != nil { - return err - } +func ExportGenesisFile(genesis types.AppGenesis, genFile string) error { + // if err := genDoc.ValidateAndComplete(); err != nil { + // return err + // } - return genDoc.SaveAs(genFile) + return genesis.SaveAs(genFile) } // ExportGenesisFileWithTime creates and writes the genesis configuration to disk. // An error is returned if building or writing the configuration to file fails. -func ExportGenesisFileWithTime( - genFile, chainID string, validators []cmttypes.GenesisValidator, - appState json.RawMessage, genTime time.Time, -) error { - genDoc := cmttypes.GenesisDoc{ +func ExportGenesisFileWithTime(genFile, chainID string, validators []types.GenesisValidator, appState json.RawMessage, genTime time.Time) error { + appGenesis := types.AppGenesis{ GenesisTime: genTime, ChainID: chainID, Validators: validators, AppState: appState, } - if err := genDoc.ValidateAndComplete(); err != nil { - return err - } + // if err := genDoc.ValidateAndComplete(); err != nil { + // return err + // } - return genDoc.SaveAs(genFile) + return appGenesis.SaveAs(genFile) } // InitializeNodeValidatorFiles creates private validator and p2p configuration files. diff --git a/x/staking/genesis.go b/x/staking/genesis.go index 7e2cf1efe04..9fb2b6270cc 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -3,33 +3,34 @@ package staking import ( "fmt" - cmttypes "github.com/cometbft/cometbft/types" - - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" + + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // WriteValidators returns a slice of bonded genesis validators. -func WriteValidators(ctx sdk.Context, keeper *keeper.Keeper) (vals []cmttypes.GenesisValidator, returnErr error) { +func WriteValidators(ctx sdk.Context, keeper *keeper.Keeper) (vals []genutiltypes.GenesisValidator, returnErr error) { keeper.IterateLastValidators(ctx, func(_ int64, validator types.ValidatorI) (stop bool) { pk, err := validator.ConsPubKey() if err != nil { returnErr = err return true } - cmtPk, err := cryptocodec.ToCmtPubKeyInterface(pk) + + pkAny, err := codectypes.NewAnyWithValue(pk) if err != nil { returnErr = err return true } - vals = append(vals, cmttypes.GenesisValidator{ - Address: sdk.ConsAddress(cmtPk.Address()).Bytes(), - PubKey: cmtPk, - Power: validator.GetConsensusPower(keeper.PowerReduction(ctx)), - Name: validator.GetMoniker(), + vals = append(vals, genutiltypes.GenesisValidator{ + Address: pk.Address().String(), + ConsensusPubkey: pkAny, + VotingPower: validator.GetConsensusPower(keeper.PowerReduction(ctx)), + Name: validator.GetMoniker(), }) return false From 95db1bc06caa0ffd0d4ff9f889d5136fd7425f47 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 16 Feb 2023 14:40:38 +0100 Subject: [PATCH 04/23] updates --- server/export.go | 2 +- .../staking/keeper/genesis_test.go | 2 +- x/genutil/types/genesis.go | 42 ++++++++----------- x/staking/genesis.go | 3 +- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/server/export.go b/server/export.go index 959abd95f14..248847b0b90 100644 --- a/server/export.go +++ b/server/export.go @@ -81,7 +81,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com appGenesis.AppState = exported.AppState appGenesis.Validators = exported.Validators appGenesis.InitialHeight = exported.Height - appGenesis.ConsensusParams = appGenesis.ConsensusParams + appGenesis.ConsensusParams = exported.ConsensusParams encoded, err := json.Marshal(appGenesis) if err != nil { diff --git a/tests/integration/staking/keeper/genesis_test.go b/tests/integration/staking/keeper/genesis_test.go index 95cc4c2e179..5baa30faec9 100644 --- a/tests/integration/staking/keeper/genesis_test.go +++ b/tests/integration/staking/keeper/genesis_test.go @@ -92,7 +92,7 @@ func TestInitGenesis(t *testing.T) { assert.NilError(t, err) for _, val := range vals2 { - assert.Assert(t, val.Address.String() != "") + assert.Assert(t, val.Address != "") } // now make sure the validators are bonded and intra-tx counters are correct diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 5913c9e937f..758aeb1bb7f 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -6,10 +6,8 @@ import ( "os" "time" - cmtjson "github.com/cometbft/cometbft/libs/json" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,15 +15,16 @@ import ( // AppGenesisOnly defines the app's genesis. type AppGenesis struct { - AppName string `json:"app_name"` - AppVersion string `json:"app_version"` - GenesisTime time.Time `json:"genesis_time"` - ChainID string `json:"chain_id"` - InitialHeight int64 `json:"initial_height"` - ConsensusParams *cmtproto.ConsensusParams `json:"consensus_params,omitempty"` + AppName string `json:"app_name"` + AppVersion string `json:"app_version"` + GenesisTime time.Time `json:"genesis_time"` + ChainID string `json:"chain_id"` + InitialHeight int64 `json:"initial_height"` + AppHash []byte `json:"app_hash"` + AppState json.RawMessage `json:"app_state,omitempty"` + Validators []GenesisValidator `json:"validators,omitempty"` - AppHash []byte `json:"app_hash"` - AppState json.RawMessage `json:"app_state,omitempty"` + ConsensusParams *cmtproto.ConsensusParams `json:"consensus_params,omitempty"` } // ToCometBFTGenesisDoc converts the AppGenesis to a CometBFT GenesisDoc. @@ -54,6 +53,8 @@ func (ag AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { return &cmttypes.GenesisDoc{ ChainID: ag.ChainID, InitialHeight: ag.InitialHeight, + AppHash: ag.AppHash, + AppState: ag.AppState, ConsensusParams: &cmttypes.ConsensusParams{ Block: cmttypes.BlockParams{ MaxBytes: ag.ConsensusParams.Block.MaxBytes, @@ -69,43 +70,34 @@ func (ag AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { }, }, Validators: cmtValidators, - AppHash: ag.AppHash, - AppState: ag.AppState, }, nil } // SaveAs is a utility method for saving AppGenesis as a JSON file. func (ag *AppGenesis) SaveAs(file string) error { - // appGenesisBytes, err := ag.MarshalIndent("", " ") - appGenesisBytes, err := json.Marshal(ag) + appGenesisBytes, err := ag.MarshalIndent("", " ") if err != nil { return err } - return os.WriteFile(file, appGenesisBytes, 0644) + return os.WriteFile(file, appGenesisBytes, 0600) } // Marshal the AppGenesis. func (ag *AppGenesis) MarshalJSON() ([]byte, error) { - // unmarshal the genesis doc with stdlib + // TODO to fix return json.Marshal(&struct{}{}) } // MarshalIndent marshals the AppGenesis with the provided prefix and indent. func (ag *AppGenesis) MarshalIndent(prefix, indent string) ([]byte, error) { - return cmtjson.MarshalIndent(ag, prefix, indent) + // TODO to fix + return json.Marshal(&struct{}{}) } // Unmarshal an AppGenesis from JSON. func (ag *AppGenesis) UnmarshalJSON(bz []byte) error { - type Alias AppGenesis // we alias for avoiding recursion in UnmarshalJSON - var result Alias - - if err := cmtjson.Unmarshal(bz, &result); err != nil { - return err - } - - ag = (*AppGenesis)(&result) + // TODO to fix return nil } diff --git a/x/staking/genesis.go b/x/staking/genesis.go index 9fb2b6270cc..ef337eec9b3 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -5,10 +5,9 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" - - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // WriteValidators returns a slice of bonded genesis validators. From c59867004b3b1a506a4c85c5d1772a36d208ebfa Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 16 Feb 2023 16:19:55 +0100 Subject: [PATCH 05/23] revert sdk genesis validator --- api/cosmos/genutil/v1beta1/genesis.pulsar.go | 754 +------------------ proto/cosmos/genutil/v1beta1/genesis.proto | 15 - x/genutil/types/genesis.go | 31 +- x/genutil/types/genesis.pb.go | 342 +-------- x/genutil/utils.go | 3 +- x/staking/genesis.go | 20 +- 6 files changed, 60 insertions(+), 1105 deletions(-) diff --git a/api/cosmos/genutil/v1beta1/genesis.pulsar.go b/api/cosmos/genutil/v1beta1/genesis.pulsar.go index cb25477fd03..8e418799dcf 100644 --- a/api/cosmos/genutil/v1beta1/genesis.pulsar.go +++ b/api/cosmos/genutil/v1beta1/genesis.pulsar.go @@ -10,7 +10,7 @@ import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - anypb "google.golang.org/protobuf/types/known/anypb" + _ "google.golang.org/protobuf/types/known/anypb" io "io" reflect "reflect" sync "sync" @@ -496,617 +496,6 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { } } -var ( - md_GenesisValidator protoreflect.MessageDescriptor - fd_GenesisValidator_address protoreflect.FieldDescriptor - fd_GenesisValidator_consensus_pubkey protoreflect.FieldDescriptor - fd_GenesisValidator_voting_power protoreflect.FieldDescriptor - fd_GenesisValidator_name protoreflect.FieldDescriptor -) - -func init() { - file_cosmos_genutil_v1beta1_genesis_proto_init() - md_GenesisValidator = File_cosmos_genutil_v1beta1_genesis_proto.Messages().ByName("GenesisValidator") - fd_GenesisValidator_address = md_GenesisValidator.Fields().ByName("address") - fd_GenesisValidator_consensus_pubkey = md_GenesisValidator.Fields().ByName("consensus_pubkey") - fd_GenesisValidator_voting_power = md_GenesisValidator.Fields().ByName("voting_power") - fd_GenesisValidator_name = md_GenesisValidator.Fields().ByName("name") -} - -var _ protoreflect.Message = (*fastReflection_GenesisValidator)(nil) - -type fastReflection_GenesisValidator GenesisValidator - -func (x *GenesisValidator) ProtoReflect() protoreflect.Message { - return (*fastReflection_GenesisValidator)(x) -} - -func (x *GenesisValidator) slowProtoReflect() protoreflect.Message { - mi := &file_cosmos_genutil_v1beta1_genesis_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_GenesisValidator_messageType fastReflection_GenesisValidator_messageType -var _ protoreflect.MessageType = fastReflection_GenesisValidator_messageType{} - -type fastReflection_GenesisValidator_messageType struct{} - -func (x fastReflection_GenesisValidator_messageType) Zero() protoreflect.Message { - return (*fastReflection_GenesisValidator)(nil) -} -func (x fastReflection_GenesisValidator_messageType) New() protoreflect.Message { - return new(fastReflection_GenesisValidator) -} -func (x fastReflection_GenesisValidator_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_GenesisValidator -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_GenesisValidator) Descriptor() protoreflect.MessageDescriptor { - return md_GenesisValidator -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_GenesisValidator) Type() protoreflect.MessageType { - return _fastReflection_GenesisValidator_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_GenesisValidator) New() protoreflect.Message { - return new(fastReflection_GenesisValidator) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_GenesisValidator) Interface() protoreflect.ProtoMessage { - return (*GenesisValidator)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_GenesisValidator) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.Address != "" { - value := protoreflect.ValueOfString(x.Address) - if !f(fd_GenesisValidator_address, value) { - return - } - } - if x.ConsensusPubkey != nil { - value := protoreflect.ValueOfMessage(x.ConsensusPubkey.ProtoReflect()) - if !f(fd_GenesisValidator_consensus_pubkey, value) { - return - } - } - if x.VotingPower != int64(0) { - value := protoreflect.ValueOfInt64(x.VotingPower) - if !f(fd_GenesisValidator_voting_power, value) { - return - } - } - if x.Name != "" { - value := protoreflect.ValueOfString(x.Name) - if !f(fd_GenesisValidator_name, value) { - return - } - } -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_GenesisValidator) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - case "cosmos.genutil.v1beta1.GenesisValidator.address": - return x.Address != "" - case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": - return x.ConsensusPubkey != nil - case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": - return x.VotingPower != int64(0) - case "cosmos.genutil.v1beta1.GenesisValidator.name": - return x.Name != "" - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) - } - panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_GenesisValidator) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - case "cosmos.genutil.v1beta1.GenesisValidator.address": - x.Address = "" - case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": - x.ConsensusPubkey = nil - case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": - x.VotingPower = int64(0) - case "cosmos.genutil.v1beta1.GenesisValidator.name": - x.Name = "" - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) - } - panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_GenesisValidator) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - case "cosmos.genutil.v1beta1.GenesisValidator.address": - value := x.Address - return protoreflect.ValueOfString(value) - case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": - value := x.ConsensusPubkey - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": - value := x.VotingPower - return protoreflect.ValueOfInt64(value) - case "cosmos.genutil.v1beta1.GenesisValidator.name": - value := x.Name - return protoreflect.ValueOfString(value) - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) - } - panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_GenesisValidator) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - case "cosmos.genutil.v1beta1.GenesisValidator.address": - x.Address = value.Interface().(string) - case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": - x.ConsensusPubkey = value.Message().Interface().(*anypb.Any) - case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": - x.VotingPower = value.Int() - case "cosmos.genutil.v1beta1.GenesisValidator.name": - x.Name = value.Interface().(string) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) - } - panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_GenesisValidator) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": - if x.ConsensusPubkey == nil { - x.ConsensusPubkey = new(anypb.Any) - } - return protoreflect.ValueOfMessage(x.ConsensusPubkey.ProtoReflect()) - case "cosmos.genutil.v1beta1.GenesisValidator.address": - panic(fmt.Errorf("field address of message cosmos.genutil.v1beta1.GenesisValidator is not mutable")) - case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": - panic(fmt.Errorf("field voting_power of message cosmos.genutil.v1beta1.GenesisValidator is not mutable")) - case "cosmos.genutil.v1beta1.GenesisValidator.name": - panic(fmt.Errorf("field name of message cosmos.genutil.v1beta1.GenesisValidator is not mutable")) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) - } - panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_GenesisValidator) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "cosmos.genutil.v1beta1.GenesisValidator.address": - return protoreflect.ValueOfString("") - case "cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey": - m := new(anypb.Any) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "cosmos.genutil.v1beta1.GenesisValidator.voting_power": - return protoreflect.ValueOfInt64(int64(0)) - case "cosmos.genutil.v1beta1.GenesisValidator.name": - return protoreflect.ValueOfString("") - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.genutil.v1beta1.GenesisValidator")) - } - panic(fmt.Errorf("message cosmos.genutil.v1beta1.GenesisValidator does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_GenesisValidator) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in cosmos.genutil.v1beta1.GenesisValidator", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_GenesisValidator) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_GenesisValidator) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_GenesisValidator) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_GenesisValidator) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*GenesisValidator) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - l = len(x.Address) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.ConsensusPubkey != nil { - l = options.Size(x.ConsensusPubkey) - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.VotingPower != 0 { - n += 1 + runtime.Sov(uint64(x.VotingPower)) - } - l = len(x.Name) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*GenesisValidator) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if len(x.Name) > 0 { - i -= len(x.Name) - copy(dAtA[i:], x.Name) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Name))) - i-- - dAtA[i] = 0x22 - } - if x.VotingPower != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.VotingPower)) - i-- - dAtA[i] = 0x18 - } - if x.ConsensusPubkey != nil { - encoded, err := options.Marshal(x.ConsensusPubkey) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x12 - } - if len(x.Address) > 0 { - i -= len(x.Address) - copy(dAtA[i:], x.Address) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Address))) - i-- - dAtA[i] = 0xa - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*GenesisValidator) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: GenesisValidator: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: GenesisValidator: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ConsensusPubkey", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.ConsensusPubkey == nil { - x.ConsensusPubkey = &anypb.Any{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.ConsensusPubkey); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field VotingPower", wireType) - } - x.VotingPower = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.VotingPower |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 @@ -1157,70 +546,6 @@ func (x *GenesisState) GetGenTxs() [][]byte { return nil } -// GenesisValidator defines an initial validator. -type GenesisValidator struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // address defines the validator address. - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - // pub_key defines the validator public key. - ConsensusPubkey *anypb.Any `protobuf:"bytes,2,opt,name=consensus_pubkey,json=consensusPubkey,proto3" json:"consensus_pubkey,omitempty"` - // power defines the validator voting power. - VotingPower int64 `protobuf:"varint,3,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` - // name defines the validator name. - Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` -} - -func (x *GenesisValidator) Reset() { - *x = GenesisValidator{} - if protoimpl.UnsafeEnabled { - mi := &file_cosmos_genutil_v1beta1_genesis_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GenesisValidator) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GenesisValidator) ProtoMessage() {} - -// Deprecated: Use GenesisValidator.ProtoReflect.Descriptor instead. -func (*GenesisValidator) Descriptor() ([]byte, []int) { - return file_cosmos_genutil_v1beta1_genesis_proto_rawDescGZIP(), []int{1} -} - -func (x *GenesisValidator) GetAddress() string { - if x != nil { - return x.Address - } - return "" -} - -func (x *GenesisValidator) GetConsensusPubkey() *anypb.Any { - if x != nil { - return x.ConsensusPubkey - } - return nil -} - -func (x *GenesisValidator) GetVotingPower() int64 { - if x != nil { - return x.VotingPower - } - return 0 -} - -func (x *GenesisValidator) GetName() string { - if x != nil { - return x.Name - } - return "" -} - var File_cosmos_genutil_v1beta1_genesis_proto protoreflect.FileDescriptor var file_cosmos_genutil_v1beta1_genesis_proto_rawDesc = []byte{ @@ -1239,36 +564,22 @@ var file_cosmos_genutil_v1beta1_genesis_proto_rawDesc = []byte{ 0xea, 0xde, 0x1f, 0x06, 0x67, 0x65, 0x6e, 0x74, 0x78, 0x73, 0xfa, 0xde, 0x1f, 0x18, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x52, 0x61, 0x77, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0xa2, 0xe7, 0xb0, 0x2a, 0x06, 0x67, 0x65, 0x6e, 0x74, 0x78, - 0x73, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x54, 0x78, 0x73, 0x22, 0xe2, - 0x01, 0x0a, 0x10, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, - 0x74, 0x6f, 0x72, 0x12, 0x32, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x07, - 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x59, 0x0a, 0x10, 0x63, 0x6f, 0x6e, 0x73, 0x65, - 0x6e, 0x73, 0x75, 0x73, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x42, 0x18, 0xca, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x50, 0x75, 0x62, 0x4b, 0x65, - 0x79, 0x52, 0x0f, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x50, 0x75, 0x62, 0x6b, - 0x65, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x76, 0x6f, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x70, 0x6f, 0x77, - 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x76, 0x6f, 0x74, 0x69, 0x6e, 0x67, - 0x50, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x08, 0x88, 0xa0, 0x1f, 0x00, 0xe8, - 0xa0, 0x1f, 0x00, 0x42, 0xdc, 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2e, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, - 0x61, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x50, 0x01, 0x5a, 0x36, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, - 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x67, 0x65, 0x6e, 0x75, - 0x74, 0x69, 0x6c, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x67, 0x65, 0x6e, 0x75, - 0x74, 0x69, 0x6c, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x47, 0x58, - 0xaa, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, - 0x6c, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x5c, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, - 0x61, 0x31, 0xe2, 0x02, 0x22, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x65, 0x6e, 0x75, - 0x74, 0x69, 0x6c, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x3a, 0x3a, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, - 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x54, 0x78, 0x73, 0x42, 0xdc, + 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x67, 0x65, + 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x42, 0x0c, 0x47, + 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x76, + 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x76, 0x31, + 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x47, 0x58, 0xaa, 0x02, 0x16, 0x43, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x56, 0x31, 0x62, + 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x65, + 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x22, + 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, 0x56, + 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0xea, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x47, 0x65, 0x6e, + 0x75, 0x74, 0x69, 0x6c, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1283,19 +594,16 @@ func file_cosmos_genutil_v1beta1_genesis_proto_rawDescGZIP() []byte { return file_cosmos_genutil_v1beta1_genesis_proto_rawDescData } -var file_cosmos_genutil_v1beta1_genesis_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_cosmos_genutil_v1beta1_genesis_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_cosmos_genutil_v1beta1_genesis_proto_goTypes = []interface{}{ - (*GenesisState)(nil), // 0: cosmos.genutil.v1beta1.GenesisState - (*GenesisValidator)(nil), // 1: cosmos.genutil.v1beta1.GenesisValidator - (*anypb.Any)(nil), // 2: google.protobuf.Any + (*GenesisState)(nil), // 0: cosmos.genutil.v1beta1.GenesisState } var file_cosmos_genutil_v1beta1_genesis_proto_depIdxs = []int32{ - 2, // 0: cosmos.genutil.v1beta1.GenesisValidator.consensus_pubkey:type_name -> google.protobuf.Any - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } func init() { file_cosmos_genutil_v1beta1_genesis_proto_init() } @@ -1316,18 +624,6 @@ func file_cosmos_genutil_v1beta1_genesis_proto_init() { return nil } } - file_cosmos_genutil_v1beta1_genesis_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GenesisValidator); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1335,7 +631,7 @@ func file_cosmos_genutil_v1beta1_genesis_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_cosmos_genutil_v1beta1_genesis_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 1, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/cosmos/genutil/v1beta1/genesis.proto b/proto/cosmos/genutil/v1beta1/genesis.proto index 50b826ea4a0..12ba3936ee6 100644 --- a/proto/cosmos/genutil/v1beta1/genesis.proto +++ b/proto/cosmos/genutil/v1beta1/genesis.proto @@ -17,19 +17,4 @@ message GenesisState { (amino.field_name) = "gentxs", (amino.dont_omitempty) = true ]; -} - -// GenesisValidator defines an initial validator. -message GenesisValidator { - option (gogoproto.equal) = false; - option (gogoproto.goproto_getters) = false; - - // address defines the validator address. - string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - // pub_key defines the validator public key. - google.protobuf.Any consensus_pubkey = 2 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; - // power defines the validator voting power. - int64 voting_power = 3; - // name defines the validator name. - string name = 4; } \ No newline at end of file diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 758aeb1bb7f..13de252d31f 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -8,9 +8,6 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) // AppGenesisOnly defines the app's genesis. @@ -23,33 +20,13 @@ type AppGenesis struct { AppHash []byte `json:"app_hash"` AppState json.RawMessage `json:"app_state,omitempty"` - Validators []GenesisValidator `json:"validators,omitempty"` - ConsensusParams *cmtproto.ConsensusParams `json:"consensus_params,omitempty"` + // TODO eventually abstract from CometBFT types + Validators []cmttypes.GenesisValidator `json:"validators,omitempty"` + ConsensusParams *cmtproto.ConsensusParams `json:"consensus_params,omitempty"` } // ToCometBFTGenesisDoc converts the AppGenesis to a CometBFT GenesisDoc. func (ag AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { - cmtValidators := make([]cmttypes.GenesisValidator, len(ag.Validators)) - for i, v := range ag.Validators { - - var pubKey cryptotypes.PubKey - if err := json.Unmarshal(v.ConsensusPubkey.Value, pubKey); err != nil { - return nil, fmt.Errorf("failed to unmarshal validator consensus pubkey: %v: %w", v.ConsensusPubkey, err) - } - - cmtPk, err := cryptocodec.ToCmtPubKeyInterface(pubKey) - if err != nil { - return nil, fmt.Errorf("failed to convert validator consensus pubkey to cmt proto: %v: %w", v.ConsensusPubkey, err) - } - - cmtValidators[i] = cmttypes.GenesisValidator{ - Address: sdk.ConsAddress(v.Address).Bytes(), - PubKey: cmtPk, - Power: v.VotingPower, - Name: v.Name, - } - } - return &cmttypes.GenesisDoc{ ChainID: ag.ChainID, InitialHeight: ag.InitialHeight, @@ -69,7 +46,7 @@ func (ag AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { PubKeyTypes: ag.ConsensusParams.Validator.PubKeyTypes, }, }, - Validators: cmtValidators, + Validators: ag.Validators, }, nil } diff --git a/x/genutil/types/genesis.pb.go b/x/genutil/types/genesis.pb.go index 5c16b1cdb3e..ca7dabb7027 100644 --- a/x/genutil/types/genesis.pb.go +++ b/x/genutil/types/genesis.pb.go @@ -7,7 +7,7 @@ import ( encoding_json "encoding/json" fmt "fmt" _ "github.com/cosmos/cosmos-proto" - types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" @@ -73,54 +73,8 @@ func (m *GenesisState) GetGenTxs() []encoding_json.RawMessage { return nil } -// GenesisValidator defines an initial validator. -type GenesisValidator struct { - // address defines the validator address. - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - // pub_key defines the validator public key. - ConsensusPubkey *types.Any `protobuf:"bytes,2,opt,name=consensus_pubkey,json=consensusPubkey,proto3" json:"consensus_pubkey,omitempty"` - // power defines the validator voting power. - VotingPower int64 `protobuf:"varint,3,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` - // name defines the validator name. - Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *GenesisValidator) Reset() { *m = GenesisValidator{} } -func (m *GenesisValidator) String() string { return proto.CompactTextString(m) } -func (*GenesisValidator) ProtoMessage() {} -func (*GenesisValidator) Descriptor() ([]byte, []int) { - return fileDescriptor_31771d25e8d8f90f, []int{1} -} -func (m *GenesisValidator) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *GenesisValidator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_GenesisValidator.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *GenesisValidator) XXX_Merge(src proto.Message) { - xxx_messageInfo_GenesisValidator.Merge(m, src) -} -func (m *GenesisValidator) XXX_Size() int { - return m.Size() -} -func (m *GenesisValidator) XXX_DiscardUnknown() { - xxx_messageInfo_GenesisValidator.DiscardUnknown(m) -} - -var xxx_messageInfo_GenesisValidator proto.InternalMessageInfo - func init() { proto.RegisterType((*GenesisState)(nil), "cosmos.genutil.v1beta1.GenesisState") - proto.RegisterType((*GenesisValidator)(nil), "cosmos.genutil.v1beta1.GenesisValidator") } func init() { @@ -128,35 +82,24 @@ func init() { } var fileDescriptor_31771d25e8d8f90f = []byte{ - // 433 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x92, 0xb1, 0x6e, 0xd4, 0x40, - 0x10, 0x86, 0xbd, 0x5c, 0x94, 0x80, 0x73, 0x12, 0xc1, 0x3a, 0x21, 0x27, 0x85, 0xef, 0x88, 0x28, - 0x4e, 0x11, 0x59, 0x2b, 0x41, 0xa2, 0xa0, 0xcb, 0x15, 0x50, 0x20, 0xc4, 0xc9, 0x41, 0x48, 0xd0, - 0x58, 0x6b, 0x7b, 0x58, 0x4c, 0xee, 0x76, 0x2c, 0xcf, 0x3a, 0x39, 0xbf, 0x01, 0x25, 0x8f, 0x10, - 0x51, 0x51, 0xa6, 0xe0, 0x21, 0x10, 0x55, 0x44, 0x45, 0x15, 0x21, 0x5f, 0x11, 0xc4, 0x23, 0x50, - 0x21, 0x7b, 0x37, 0x49, 0xb3, 0x3b, 0xf3, 0xef, 0xb7, 0xff, 0xcc, 0x8e, 0xd6, 0x7d, 0x98, 0x22, - 0xcd, 0x91, 0x42, 0x09, 0xaa, 0xd2, 0xf9, 0x2c, 0x3c, 0xde, 0x4b, 0x40, 0x8b, 0xbd, 0x36, 0x07, - 0xca, 0x89, 0x17, 0x25, 0x6a, 0xf4, 0xee, 0x1b, 0x8a, 0x5b, 0x8a, 0x5b, 0x6a, 0x6b, 0x53, 0x22, - 0xca, 0x19, 0x84, 0x1d, 0x95, 0x54, 0xef, 0x43, 0xa1, 0x6a, 0x73, 0x65, 0x6b, 0x20, 0x51, 0x62, - 0x17, 0x86, 0x6d, 0x64, 0xd5, 0x7b, 0x62, 0x9e, 0x2b, 0x0c, 0xbb, 0xd5, 0x4a, 0x9b, 0xc6, 0x3b, - 0x36, 0xac, 0x2d, 0xd4, 0x25, 0xdb, 0xb1, 0xdb, 0x7f, 0x6e, 0xfa, 0x38, 0xd4, 0x42, 0x83, 0xf7, - 0xca, 0x5d, 0x93, 0xa0, 0x62, 0xbd, 0x20, 0x9f, 0x8d, 0x7a, 0xe3, 0xfe, 0xe4, 0xc9, 0xdf, 0x8b, - 0xe1, 0xaa, 0x04, 0xa5, 0x17, 0xf4, 0xef, 0x62, 0xe8, 0x83, 0x4a, 0x31, 0xcb, 0x95, 0x0c, 0x3f, - 0x12, 0x2a, 0x1e, 0x89, 0x93, 0x97, 0x40, 0x24, 0x24, 0x7c, 0xb9, 0x3c, 0xdb, 0xb1, 0xd8, 0xd7, - 0xcb, 0xb3, 0x1d, 0x16, 0xb5, 0xc9, 0xeb, 0x05, 0x6d, 0x37, 0xcc, 0xdd, 0xb0, 0x15, 0xde, 0x88, - 0x59, 0x9e, 0x09, 0x8d, 0xa5, 0xb7, 0xef, 0xae, 0x89, 0x2c, 0x2b, 0x81, 0xda, 0x2a, 0x6c, 0x7c, - 0x67, 0xe2, 0xff, 0xfc, 0xb6, 0x3b, 0xb0, 0x8d, 0x1d, 0x98, 0x93, 0x43, 0x5d, 0xe6, 0x4a, 0x46, - 0x57, 0xa0, 0xf7, 0xd6, 0xdd, 0x48, 0x51, 0x11, 0x28, 0xaa, 0x28, 0x2e, 0xaa, 0xe4, 0x08, 0x6a, - 0xff, 0xd6, 0x88, 0x8d, 0xd7, 0xf7, 0x07, 0xdc, 0xcc, 0x88, 0x5f, 0xcd, 0x88, 0x1f, 0xa8, 0x7a, - 0xe2, 0xff, 0xb8, 0xb1, 0x4c, 0xcb, 0xba, 0xd0, 0xc8, 0xa7, 0x55, 0xf2, 0x02, 0xea, 0xe8, 0xee, - 0xb5, 0xcf, 0xb4, 0xb3, 0xf1, 0x1e, 0xb8, 0xfd, 0x63, 0xd4, 0xb9, 0x92, 0x71, 0x81, 0x27, 0x50, - 0xfa, 0xbd, 0x11, 0x1b, 0xf7, 0xa2, 0x75, 0xa3, 0x4d, 0x5b, 0xc9, 0xf3, 0xdc, 0x15, 0x25, 0xe6, - 0xe0, 0xaf, 0xb4, 0xed, 0x46, 0x5d, 0xfc, 0xf4, 0xf6, 0xa7, 0xd3, 0xa1, 0xf3, 0xe7, 0x74, 0xe8, - 0x4c, 0x9e, 0x7d, 0x6f, 0x02, 0x76, 0xde, 0x04, 0xec, 0x77, 0x13, 0xb0, 0xcf, 0xcb, 0xc0, 0x39, - 0x5f, 0x06, 0xce, 0xaf, 0x65, 0xe0, 0xbc, 0x7b, 0x24, 0x73, 0xfd, 0xa1, 0x4a, 0x78, 0x8a, 0x73, - 0x3b, 0x78, 0xbb, 0xed, 0x52, 0x76, 0x14, 0x2e, 0xae, 0x3f, 0x85, 0xae, 0x0b, 0xa0, 0x64, 0xb5, - 0x7b, 0xc1, 0xe3, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb1, 0xd8, 0xdd, 0x0b, 0x33, 0x02, 0x00, - 0x00, + // 272 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x4f, 0xcd, 0x2b, 0x2d, 0xc9, 0xcc, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, + 0x49, 0x34, 0x04, 0xf1, 0x53, 0x8b, 0x33, 0x8b, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xc4, + 0x20, 0xaa, 0xf4, 0xa0, 0xaa, 0xf4, 0xa0, 0xaa, 0xa4, 0x24, 0xd3, 0xf3, 0xf3, 0xd3, 0x73, 0x52, + 0xf5, 0xc1, 0xaa, 0x92, 0x4a, 0xd3, 0xf4, 0x13, 0xf3, 0x2a, 0x21, 0x5a, 0xa4, 0x44, 0xd2, 0xf3, + 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x2a, 0x2a, 0x98, 0x98, 0x9b, 0x99, 0x97, 0xaf, 0x0f, + 0x26, 0xa1, 0x42, 0x92, 0x10, 0xb3, 0xe3, 0x21, 0x6a, 0xa1, 0x16, 0x81, 0x39, 0x4a, 0xf1, 0x5c, + 0x3c, 0xee, 0x10, 0x77, 0x04, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0xf9, 0x73, 0xb1, 0xa7, 0xa7, 0xe6, + 0xc5, 0x97, 0x54, 0x14, 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0xf0, 0x38, 0x99, 0xbd, 0xba, 0x27, 0xcf, + 0x96, 0x9e, 0x9a, 0x57, 0x52, 0x51, 0xfc, 0xeb, 0x9e, 0xbc, 0x44, 0x6a, 0x5e, 0x72, 0x7e, 0x4a, + 0x66, 0x5e, 0xba, 0x7e, 0x56, 0x71, 0x7e, 0x9e, 0x5e, 0x50, 0x62, 0xb9, 0x6f, 0x6a, 0x71, 0x71, + 0x62, 0x7a, 0xea, 0xa2, 0xe7, 0x1b, 0xb4, 0xa0, 0xca, 0x56, 0x3c, 0xdf, 0xa0, 0xc5, 0x18, 0x04, + 0xe2, 0x84, 0x54, 0x14, 0x3b, 0xb9, 0x9d, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, + 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, + 0x94, 0x4e, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0x2e, 0xd4, 0x4d, 0x50, 0x4a, + 0xb7, 0x38, 0x25, 0x5b, 0xbf, 0x02, 0x1e, 0x5e, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, + 0xf7, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x59, 0x51, 0xda, 0x28, 0x4e, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -191,60 +134,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *GenesisValidator) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *GenesisValidator) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *GenesisValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0x22 - } - if m.VotingPower != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.VotingPower)) - i-- - dAtA[i] = 0x18 - } - if m.ConsensusPubkey != nil { - { - size, err := m.ConsensusPubkey.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -271,30 +160,6 @@ func (m *GenesisState) Size() (n int) { return n } -func (m *GenesisValidator) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Address) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } - if m.ConsensusPubkey != nil { - l = m.ConsensusPubkey.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - if m.VotingPower != 0 { - n += 1 + sovGenesis(uint64(m.VotingPower)) - } - l = len(m.Name) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } - return n -} - func sovGenesis(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -383,175 +248,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } -func (m *GenesisValidator) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: GenesisValidator: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: GenesisValidator: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ConsensusPubkey", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.ConsensusPubkey == nil { - m.ConsensusPubkey = &types.Any{} - } - if err := m.ConsensusPubkey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field VotingPower", wireType) - } - m.VotingPower = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.VotingPower |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenesis(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipGenesis(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/genutil/utils.go b/x/genutil/utils.go index abb860a42be..d2bf8bb521b 100644 --- a/x/genutil/utils.go +++ b/x/genutil/utils.go @@ -11,6 +11,7 @@ import ( tmed25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/p2p" "github.com/cometbft/cometbft/privval" + cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/go-bip39" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -30,7 +31,7 @@ func ExportGenesisFile(genesis types.AppGenesis, genFile string) error { // ExportGenesisFileWithTime creates and writes the genesis configuration to disk. // An error is returned if building or writing the configuration to file fails. -func ExportGenesisFileWithTime(genFile, chainID string, validators []types.GenesisValidator, appState json.RawMessage, genTime time.Time) error { +func ExportGenesisFileWithTime(genFile, chainID string, validators []cmttypes.GenesisValidator, appState json.RawMessage, genTime time.Time) error { appGenesis := types.AppGenesis{ GenesisTime: genTime, ChainID: chainID, diff --git a/x/staking/genesis.go b/x/staking/genesis.go index ef337eec9b3..7e2cf1efe04 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -3,33 +3,33 @@ package staking import ( "fmt" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cmttypes "github.com/cometbft/cometbft/types" + + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" ) // WriteValidators returns a slice of bonded genesis validators. -func WriteValidators(ctx sdk.Context, keeper *keeper.Keeper) (vals []genutiltypes.GenesisValidator, returnErr error) { +func WriteValidators(ctx sdk.Context, keeper *keeper.Keeper) (vals []cmttypes.GenesisValidator, returnErr error) { keeper.IterateLastValidators(ctx, func(_ int64, validator types.ValidatorI) (stop bool) { pk, err := validator.ConsPubKey() if err != nil { returnErr = err return true } - - pkAny, err := codectypes.NewAnyWithValue(pk) + cmtPk, err := cryptocodec.ToCmtPubKeyInterface(pk) if err != nil { returnErr = err return true } - vals = append(vals, genutiltypes.GenesisValidator{ - Address: pk.Address().String(), - ConsensusPubkey: pkAny, - VotingPower: validator.GetConsensusPower(keeper.PowerReduction(ctx)), - Name: validator.GetMoniker(), + vals = append(vals, cmttypes.GenesisValidator{ + Address: sdk.ConsAddress(cmtPk.Address()).Bytes(), + PubKey: cmtPk, + Power: validator.GetConsensusPower(keeper.PowerReduction(ctx)), + Name: validator.GetMoniker(), }) return false From 96e1e3d1788c724a4c2df6bf36c86215eb4459a5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 16 Feb 2023 16:20:51 +0100 Subject: [PATCH 06/23] updates --- proto/cosmos/genutil/v1beta1/genesis.proto | 2 -- 1 file changed, 2 deletions(-) diff --git a/proto/cosmos/genutil/v1beta1/genesis.proto b/proto/cosmos/genutil/v1beta1/genesis.proto index 12ba3936ee6..dfd34943ea5 100644 --- a/proto/cosmos/genutil/v1beta1/genesis.proto +++ b/proto/cosmos/genutil/v1beta1/genesis.proto @@ -1,10 +1,8 @@ syntax = "proto3"; package cosmos.genutil.v1beta1; -import "google/protobuf/any.proto"; import "gogoproto/gogo.proto"; import "amino/amino.proto"; -import "cosmos_proto/cosmos.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/genutil/types"; From 5bdb70d1c1304461c482a36de24ae5a47bd3d867 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 17 Feb 2023 00:40:23 +0100 Subject: [PATCH 07/23] updates --- x/genutil/types/genesis.go | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 13de252d31f..12e0942bf9c 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -52,7 +52,7 @@ func (ag AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { // SaveAs is a utility method for saving AppGenesis as a JSON file. func (ag *AppGenesis) SaveAs(file string) error { - appGenesisBytes, err := ag.MarshalIndent("", " ") + appGenesisBytes, err := json.MarshalIndent(ag, "", " ") if err != nil { return err } @@ -60,24 +60,6 @@ func (ag *AppGenesis) SaveAs(file string) error { return os.WriteFile(file, appGenesisBytes, 0600) } -// Marshal the AppGenesis. -func (ag *AppGenesis) MarshalJSON() ([]byte, error) { - // TODO to fix - return json.Marshal(&struct{}{}) -} - -// MarshalIndent marshals the AppGenesis with the provided prefix and indent. -func (ag *AppGenesis) MarshalIndent(prefix, indent string) ([]byte, error) { - // TODO to fix - return json.Marshal(&struct{}{}) -} - -// Unmarshal an AppGenesis from JSON. -func (ag *AppGenesis) UnmarshalJSON(bz []byte) error { - // TODO to fix - return nil -} - // AppGenesisFromFile reads the AppGenesis from the provided file. func AppGenesisFromFile(genFile string) (AppGenesis, error) { jsonBlob, err := os.ReadFile(genFile) From 3faf4254e998e9386c612a4c9873fcf2cc263c10 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 17 Feb 2023 00:50:39 +0100 Subject: [PATCH 08/23] updates --- x/genutil/types/genesis.go | 21 +++++++++++++-------- x/genutil/types/genesis_test.go | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 12e0942bf9c..b8bec60d22f 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -27,12 +27,9 @@ type AppGenesis struct { // ToCometBFTGenesisDoc converts the AppGenesis to a CometBFT GenesisDoc. func (ag AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { - return &cmttypes.GenesisDoc{ - ChainID: ag.ChainID, - InitialHeight: ag.InitialHeight, - AppHash: ag.AppHash, - AppState: ag.AppState, - ConsensusParams: &cmttypes.ConsensusParams{ + var consensusParams *cmttypes.ConsensusParams + if ag.ConsensusParams != nil { + consensusParams = &cmttypes.ConsensusParams{ Block: cmttypes.BlockParams{ MaxBytes: ag.ConsensusParams.Block.MaxBytes, MaxGas: ag.ConsensusParams.Block.MaxGas, @@ -45,8 +42,16 @@ func (ag AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { Validator: cmttypes.ValidatorParams{ PubKeyTypes: ag.ConsensusParams.Validator.PubKeyTypes, }, - }, - Validators: ag.Validators, + } + } + + return &cmttypes.GenesisDoc{ + ChainID: ag.ChainID, + InitialHeight: ag.InitialHeight, + AppHash: ag.AppHash, + AppState: ag.AppState, + ConsensusParams: consensusParams, + Validators: ag.Validators, }, nil } diff --git a/x/genutil/types/genesis_test.go b/x/genutil/types/genesis_test.go index 184a2dc7df2..2ba1ef80bef 100644 --- a/x/genutil/types/genesis_test.go +++ b/x/genutil/types/genesis_test.go @@ -8,7 +8,7 @@ import ( "gotest.tools/v3/assert" ) -var expectedAppGenesisJSON = `{"app_name":"simapp","app_version":"0.1.0","genesis_time":"0001-01-01T00:00:00Z","chain_id":"test","initial_height":"0","app_hash":""}` +var expectedAppGenesisJSON = `{"app_name":"simapp","app_version":"0.1.0","genesis_time":"0001-01-01T00:00:00Z","chain_id":"test","initial_height":0,"app_hash":null}` func TestAppGenesis_Marshal(t *testing.T) { genesis := types.AppGenesis{ From 39fcba8fa7445a47f19ec2cb6cd2274f366cedde Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 17 Feb 2023 00:53:43 +0100 Subject: [PATCH 09/23] updates --- x/genutil/client/cli/migrate.go | 2 ++ x/genutil/migrations/v048/migrate.go | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 x/genutil/migrations/v048/migrate.go diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index b041449c1e7..6a9de6f79c6 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -18,6 +18,7 @@ import ( v043 "github.com/cosmos/cosmos-sdk/x/genutil/migrations/v043" v046 "github.com/cosmos/cosmos-sdk/x/genutil/migrations/v046" v047 "github.com/cosmos/cosmos-sdk/x/genutil/migrations/v047" + v048 "github.com/cosmos/cosmos-sdk/x/genutil/migrations/v048" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -30,6 +31,7 @@ var migrationMap = types.MigrationMap{ "v0.43": v043.Migrate, // NOTE: v0.43, v0.44 and v0.45 are genesis compatible. "v0.46": v046.Migrate, "v0.47": v047.Migrate, + "v0.48": v048.Migrate, } // GetMigrationCallback returns a MigrationCallback for a given version. diff --git a/x/genutil/migrations/v048/migrate.go b/x/genutil/migrations/v048/migrate.go new file mode 100644 index 00000000000..544b641ea33 --- /dev/null +++ b/x/genutil/migrations/v048/migrate.go @@ -0,0 +1,11 @@ +package v048 + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/x/genutil/types" +) + +// Migrate migrates exported state from v0.47 to a v0.48 genesis state. +func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap { + return nil +} From 1ae07d548aafe6cc2cca1fd8f4027394da5a5cfe Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 17 Feb 2023 01:04:24 +0100 Subject: [PATCH 10/23] more revert --- api/cosmos/genutil/v1beta1/genesis.pulsar.go | 54 +++++++++----------- x/genutil/types/genesis.pb.go | 31 +++++------ 2 files changed, 38 insertions(+), 47 deletions(-) diff --git a/api/cosmos/genutil/v1beta1/genesis.pulsar.go b/api/cosmos/genutil/v1beta1/genesis.pulsar.go index 8e418799dcf..4382a8bc801 100644 --- a/api/cosmos/genutil/v1beta1/genesis.pulsar.go +++ b/api/cosmos/genutil/v1beta1/genesis.pulsar.go @@ -4,13 +4,11 @@ package genutilv1beta1 import ( _ "cosmossdk.io/api/amino" fmt "fmt" - _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - _ "google.golang.org/protobuf/types/known/anypb" io "io" reflect "reflect" sync "sync" @@ -552,34 +550,30 @@ var file_cosmos_genutil_v1beta1_genesis_proto_rawDesc = []byte{ 0x0a, 0x24, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x16, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x67, - 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x19, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, - 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, - 0x11, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x1a, 0x19, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5f, 0x0a, - 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x4f, 0x0a, - 0x07, 0x67, 0x65, 0x6e, 0x5f, 0x74, 0x78, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x42, 0x36, - 0xea, 0xde, 0x1f, 0x06, 0x67, 0x65, 0x6e, 0x74, 0x78, 0x73, 0xfa, 0xde, 0x1f, 0x18, 0x65, 0x6e, - 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x52, 0x61, 0x77, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0xa2, 0xe7, 0xb0, 0x2a, 0x06, 0x67, 0x65, 0x6e, 0x74, 0x78, - 0x73, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x54, 0x78, 0x73, 0x42, 0xdc, - 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x67, 0x65, - 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x42, 0x0c, 0x47, - 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x63, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x76, - 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x76, 0x31, - 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x47, 0x58, 0xaa, 0x02, 0x16, 0x43, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x56, 0x31, 0x62, - 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x65, - 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x22, - 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, 0x56, - 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0xea, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x47, 0x65, 0x6e, - 0x75, 0x74, 0x69, 0x6c, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x14, + 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x11, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x6d, 0x69, 0x6e, + 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5f, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, + 0x69, 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x4f, 0x0a, 0x07, 0x67, 0x65, 0x6e, 0x5f, 0x74, + 0x78, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x42, 0x36, 0xea, 0xde, 0x1f, 0x06, 0x67, 0x65, + 0x6e, 0x74, 0x78, 0x73, 0xfa, 0xde, 0x1f, 0x18, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, + 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x52, 0x61, 0x77, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0xa2, 0xe7, 0xb0, 0x2a, 0x06, 0x67, 0x65, 0x6e, 0x74, 0x78, 0x73, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, + 0x52, 0x06, 0x67, 0x65, 0x6e, 0x54, 0x78, 0x73, 0x42, 0xdc, 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, + 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, + 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, + 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, + 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2f, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, + 0x3b, 0x67, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, + 0x02, 0x03, 0x43, 0x47, 0x58, 0xaa, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x47, + 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, + 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, + 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x22, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x5c, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, + 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x18, 0x43, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x47, 0x65, 0x6e, 0x75, 0x74, 0x69, 0x6c, 0x3a, 0x3a, + 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/x/genutil/types/genesis.pb.go b/x/genutil/types/genesis.pb.go index ca7dabb7027..ca3ee3fed20 100644 --- a/x/genutil/types/genesis.pb.go +++ b/x/genutil/types/genesis.pb.go @@ -6,8 +6,6 @@ package types import ( encoding_json "encoding/json" fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - _ "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" @@ -82,24 +80,23 @@ func init() { } var fileDescriptor_31771d25e8d8f90f = []byte{ - // 272 bytes of a gzipped FileDescriptorProto + // 244 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x4f, 0xcd, 0x2b, 0x2d, 0xc9, 0xcc, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x04, 0xf1, 0x53, 0x8b, 0x33, 0x8b, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xc4, - 0x20, 0xaa, 0xf4, 0xa0, 0xaa, 0xf4, 0xa0, 0xaa, 0xa4, 0x24, 0xd3, 0xf3, 0xf3, 0xd3, 0x73, 0x52, - 0xf5, 0xc1, 0xaa, 0x92, 0x4a, 0xd3, 0xf4, 0x13, 0xf3, 0x2a, 0x21, 0x5a, 0xa4, 0x44, 0xd2, 0xf3, - 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x2a, 0x2a, 0x98, 0x98, 0x9b, 0x99, 0x97, 0xaf, 0x0f, - 0x26, 0xa1, 0x42, 0x92, 0x10, 0xb3, 0xe3, 0x21, 0x6a, 0xa1, 0x16, 0x81, 0x39, 0x4a, 0xf1, 0x5c, - 0x3c, 0xee, 0x10, 0x77, 0x04, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0xf9, 0x73, 0xb1, 0xa7, 0xa7, 0xe6, - 0xc5, 0x97, 0x54, 0x14, 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0xf0, 0x38, 0x99, 0xbd, 0xba, 0x27, 0xcf, - 0x96, 0x9e, 0x9a, 0x57, 0x52, 0x51, 0xfc, 0xeb, 0x9e, 0xbc, 0x44, 0x6a, 0x5e, 0x72, 0x7e, 0x4a, - 0x66, 0x5e, 0xba, 0x7e, 0x56, 0x71, 0x7e, 0x9e, 0x5e, 0x50, 0x62, 0xb9, 0x6f, 0x6a, 0x71, 0x71, - 0x62, 0x7a, 0xea, 0xa2, 0xe7, 0x1b, 0xb4, 0xa0, 0xca, 0x56, 0x3c, 0xdf, 0xa0, 0xc5, 0x18, 0x04, - 0xe2, 0x84, 0x54, 0x14, 0x3b, 0xb9, 0x9d, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, - 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, - 0x94, 0x4e, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0x2e, 0xd4, 0x4d, 0x50, 0x4a, - 0xb7, 0x38, 0x25, 0x5b, 0xbf, 0x02, 0x1e, 0x5e, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, - 0xf7, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x59, 0x51, 0xda, 0x28, 0x4e, 0x01, 0x00, 0x00, + 0x20, 0xaa, 0xf4, 0xa0, 0xaa, 0xf4, 0xa0, 0xaa, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4a, + 0xf4, 0x41, 0x2c, 0x88, 0x6a, 0x29, 0xc1, 0xc4, 0xdc, 0xcc, 0xbc, 0x7c, 0x7d, 0x30, 0x09, 0x11, + 0x52, 0x8a, 0xe7, 0xe2, 0x71, 0x87, 0x98, 0x18, 0x5c, 0x92, 0x58, 0x92, 0x2a, 0xe4, 0xcf, 0xc5, + 0x9e, 0x9e, 0x9a, 0x17, 0x5f, 0x52, 0x51, 0x2c, 0xc1, 0xa8, 0xc0, 0xac, 0xc1, 0xe3, 0x64, 0xf6, + 0xea, 0x9e, 0x3c, 0x5b, 0x7a, 0x6a, 0x5e, 0x49, 0x45, 0xf1, 0xaf, 0x7b, 0xf2, 0x12, 0xa9, 0x79, + 0xc9, 0xf9, 0x29, 0x99, 0x79, 0xe9, 0xfa, 0x59, 0xc5, 0xf9, 0x79, 0x7a, 0x41, 0x89, 0xe5, 0xbe, + 0xa9, 0xc5, 0xc5, 0x89, 0xe9, 0xa9, 0x8b, 0x9e, 0x6f, 0xd0, 0x82, 0x2a, 0x5b, 0xf1, 0x7c, 0x83, + 0x16, 0x63, 0x10, 0x88, 0x13, 0x52, 0x51, 0xec, 0xe4, 0x76, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, + 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, + 0xc7, 0x72, 0x0c, 0x51, 0x3a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, + 0x50, 0xcf, 0x42, 0x28, 0xdd, 0xe2, 0x94, 0x6c, 0xfd, 0x0a, 0xb8, 0xcf, 0x4b, 0x2a, 0x0b, 0x52, + 0x8b, 0x93, 0xd8, 0xc0, 0xee, 0x35, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xb1, 0x4e, 0x6d, 0x9e, + 0x18, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { From 5bd86022df55ec1bde01e475689dae6ab01aaad0 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 17 Feb 2023 12:10:41 +0100 Subject: [PATCH 11/23] updates --- CHANGELOG.md | 3 +- server/export.go | 9 +-- simapp/simd/cmd/testnet.go | 8 +-- x/genutil/client/cli/init.go | 7 ++- x/genutil/client/cli/migrate.go | 52 +++++++++-------- x/genutil/client/cli/validate_genesis.go | 32 +++++++---- x/genutil/collect.go | 4 +- x/genutil/collect_test.go | 2 +- x/genutil/migrations/v048/migrate.go | 11 ---- x/genutil/types/genesis.go | 71 ++++++++++++++++++++++-- x/genutil/types/genesis_state.go | 4 +- x/genutil/utils.go | 23 ++++---- 12 files changed, 141 insertions(+), 85 deletions(-) delete mode 100644 x/genutil/migrations/v048/migrate.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f8aeb8d502..89b799bbc26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features -* (cli) [#14659](https://github.com/cosmos/cosmos-sdk/pull/14659) Added ability to query blocks by events with queries directly passed to Tendermint, which will allow for full query operator support, e.g. `>`. +* (x/genutil) [#15301](https://github.com/cosmos/cosmos-sdk/pull/15031) Add application genesis. The genesis is now entirely managed by the application and passed to CometBFT at note instantiation. Functions that were taking a `cmttypes.GenesisDoc{}` now takes a `genutiltypes.AppGenesis{}`. +* (cli) [#14659](https://github.com/cosmos/cosmos-sdk/pull/14659) Added ability to query blocks by events with queries directly passed to Tendermint, which will allow for full query operator support, e.g. `>`. * [#14897](https://github.com/cosmos/cosmos-sdk/pull/14897) Migrate the Cosmos SDK to CometBFT. * (x/gov) [#14720](https://github.com/cosmos/cosmos-sdk/pull/14720) Upstream expedited proposals from Osmosis. * (x/auth) [#14650](https://github.com/cosmos/cosmos-sdk/pull/14650) Add Textual SignModeHandler. It is however **NOT** enabled by default, and should only be used for **TESTING** purposes until `SIGN_MODE_TEXTUAL` is fully released. diff --git a/server/export.go b/server/export.go index 248847b0b90..42d70927d2a 100644 --- a/server/export.go +++ b/server/export.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" - sdk "github.com/cosmos/cosmos-sdk/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -18,7 +17,6 @@ const ( FlagForZeroHeight = "for-zero-height" FlagJailAllowedAddrs = "jail-allowed-addrs" FlagModulesToExport = "modules-to-export" - FlagOutputDocument = "output-document" ) // ExportCmd dumps app state to JSON. @@ -66,7 +64,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight) jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs) modulesToExport, _ := cmd.Flags().GetStringSlice(FlagModulesToExport) - outputDocument, _ := cmd.Flags().GetString(FlagOutputDocument) + outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument) exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, modulesToExport) if err != nil { @@ -83,14 +81,13 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com appGenesis.InitialHeight = exported.Height appGenesis.ConsensusParams = exported.ConsensusParams - encoded, err := json.Marshal(appGenesis) + out, err := json.Marshal(appGenesis) if err != nil { return err } cmd.SetOut(cmd.OutOrStdout()) cmd.SetErr(cmd.OutOrStderr()) - out := sdk.MustSortJSON(encoded) if outputDocument == "" { cmd.Println(string(out)) @@ -114,7 +111,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com cmd.Flags().Bool(FlagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)") cmd.Flags().StringSlice(FlagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail") cmd.Flags().StringSlice(FlagModulesToExport, []string{}, "Comma-separated list of modules to export. If empty, will export all modules") - cmd.Flags().String(FlagOutputDocument, "", "Exported state is written to the given file instead of STDOUT") + cmd.Flags().String(flags.FlagOutputDocument, "", "Exported state is written to the given file instead of STDOUT") return cmd } diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 3ddc4945718..539f82baa06 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -16,7 +16,6 @@ import ( "github.com/spf13/pflag" "cosmossdk.io/math" - "cosmossdk.io/simapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -391,12 +390,7 @@ func initGenFiles( return err } - appGenesis := genutiltypes.AppGenesis{ - ChainID: chainID, - AppState: appGenStateJSON, - Validators: nil, - } - + appGenesis := genutiltypes.NewAppGenesisWithVersion(chainID, appGenStateJSON) // generate empty genesis files for each validator and save for i := 0; i < numValidators; i++ { if err := appGenesis.SaveAs(genFiles[i]); err != nil { diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index bcad145c10e..3e60049f189 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -20,6 +20,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -133,7 +134,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { return errors.Wrap(err, "Failed to marshal default genesis state") } - appGenesis := types.AppGenesis{} + appGenesis := &types.AppGenesis{} if _, err := os.Stat(genFile); err != nil { if !os.IsNotExist(err) { return err @@ -145,9 +146,11 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { } } + appGenesis.AppName = version.AppName + appGenesis.AppVersion = version.Version appGenesis.ChainID = chainID - appGenesis.Validators = nil appGenesis.AppState = appState + appGenesis.Validators = nil if err = genutil.ExportGenesisFile(appGenesis, genFile); err != nil { return errors.Wrap(err, "Failed to export genesis file") diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index 6a9de6f79c6..52ad7d75559 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -6,19 +6,15 @@ import ( "sort" "time" - cmtjson "github.com/cometbft/cometbft/libs/json" - "github.com/pkg/errors" "github.com/spf13/cobra" "golang.org/x/exp/maps" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" v043 "github.com/cosmos/cosmos-sdk/x/genutil/migrations/v043" v046 "github.com/cosmos/cosmos-sdk/x/genutil/migrations/v046" v047 "github.com/cosmos/cosmos-sdk/x/genutil/migrations/v047" - v048 "github.com/cosmos/cosmos-sdk/x/genutil/migrations/v048" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -31,7 +27,6 @@ var migrationMap = types.MigrationMap{ "v0.43": v043.Migrate, // NOTE: v0.43, v0.44 and v0.45 are genesis compatible. "v0.46": v046.Migrate, "v0.47": v047.Migrate, - "v0.48": v048.Migrate, } // GetMigrationCallback returns a MigrationCallback for a given version. @@ -66,22 +61,26 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 target := args[0] importGenesis := args[1] - genDoc, err := validateGenDoc(importGenesis) + appGenesis, err := types.AppGenesisFromFile(importGenesis) if err != nil { return err } + if err := validateGenDoc(appGenesis); err != nil { + return err + } + // Since some default values are valid values, we just print to // make sure the user didn't forget to update these values. - if genDoc.ConsensusParams.Evidence.MaxBytes == 0 { + if appGenesis.ConsensusParams.Evidence.MaxBytes == 0 { fmt.Printf("Warning: consensus_params.evidence.max_bytes is set to 0. If this is"+ " deliberate, feel free to ignore this warning. If not, please have a look at the chain"+ " upgrade guide at %s.\n", chainUpgradeGuide) } var initialState types.AppMap - if err := json.Unmarshal(genDoc.AppState, &initialState); err != nil { - return errors.Wrap(err, "failed to JSON unmarshal initial genesis state") + if err := json.Unmarshal(appGenesis.AppState, &initialState); err != nil { + return fmt.Errorf("failed to JSON unmarshal initial genesis state: %w", err) } migrationFunc := GetMigrationCallback(target) @@ -92,9 +91,9 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 // TODO: handler error from migrationFunc call newGenState := migrationFunc(initialState, clientCtx) - genDoc.AppState, err = json.Marshal(newGenState) + appGenesis.AppState, err = json.Marshal(newGenState) if err != nil { - return errors.Wrap(err, "failed to JSON marshal migrated genesis state") + return fmt.Errorf("failed to JSON marshal migrated genesis state: %w", err) } genesisTime, _ := cmd.Flags().GetString(flagGenesisTime) @@ -103,34 +102,43 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 err := t.UnmarshalText([]byte(genesisTime)) if err != nil { - return errors.Wrap(err, "failed to unmarshal genesis time") + return fmt.Errorf("failed to unmarshal genesis time: %w", err) } - genDoc.GenesisTime = t + appGenesis.GenesisTime = t } chainID, _ := cmd.Flags().GetString(flags.FlagChainID) if chainID != "" { - genDoc.ChainID = chainID + appGenesis.ChainID = chainID } - bz, err := cmtjson.Marshal(genDoc) + bz, err := json.Marshal(appGenesis) if err != nil { - return errors.Wrap(err, "failed to marshal genesis doc") + return fmt.Errorf("failed to marshal app genesis: %w", err) } - sortedBz, err := sdk.SortJSON(bz) - if err != nil { - return errors.Wrap(err, "failed to sort JSON genesis doc") + outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument) + if outputDocument == "" { + cmd.Println(string(bz)) + return nil + } + + var exportedAppGenesis types.AppGenesis + if err = json.Unmarshal(bz, &exportedAppGenesis); err != nil { + return err + } + if err = exportedAppGenesis.SaveAs(outputDocument); err != nil { + return err } - cmd.Println(string(sortedBz)) return nil }, } - cmd.Flags().String(flagGenesisTime, "", "override genesis_time with this flag") - cmd.Flags().String(flags.FlagChainID, "", "override chain_id with this flag") + cmd.Flags().String(flagGenesisTime, "", "Override genesis_time with this flag") + cmd.Flags().String(flags.FlagChainID, "", "Override chain_id with this flag") + cmd.Flags().String(flags.FlagOutputDocument, "", "Exported state is written to the given file instead of STDOUT") return cmd } diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 062e2304dad..db6dd8eeb1b 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -4,12 +4,12 @@ import ( "encoding/json" "fmt" - cmttypes "github.com/cometbft/cometbft/types" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/genutil/types" ) const chainUpgradeGuide = "https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md" @@ -17,9 +17,10 @@ const chainUpgradeGuide = "https://github.com/cosmos/cosmos-sdk/blob/main/UPGRAD // ValidateGenesisCmd takes a genesis file, and makes sure that it is valid. func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { return &cobra.Command{ - Use: "validate-genesis [file]", - Args: cobra.RangeArgs(0, 1), - Short: "validates the genesis file at the default location or at the location passed as an arg", + Use: "validate [file]", + Aliases: []string{"validate-genesis"}, + Args: cobra.RangeArgs(0, 1), + Short: "validates the genesis file at the default location or at the location passed as an arg", RunE: func(cmd *cobra.Command, args []string) (err error) { serverCtx := server.GetServerContextFromCmd(cmd) clientCtx := client.GetClientContextFromCmd(cmd) @@ -34,13 +35,17 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { genesis = args[0] } - genDoc, err := validateGenDoc(genesis) + appGenesis, err := types.AppGenesisFromFile(genesis) if err != nil { return err } + if err := validateGenDoc(appGenesis); err != nil { + return err + } + var genState map[string]json.RawMessage - if err = json.Unmarshal(genDoc.AppState, &genState); err != nil { + if err = json.Unmarshal(appGenesis.AppState, &genState); err != nil { return fmt.Errorf("error unmarshalling genesis doc %s: %s", genesis, err.Error()) } @@ -57,15 +62,18 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { // validateGenDoc reads a genesis file and validates that it is a correct // CometBFT GenesisDoc. This function does not do any cosmos-related // validation. -func validateGenDoc(importGenesisFile string) (*cmttypes.GenesisDoc, error) { - genDoc, err := cmttypes.GenesisDocFromFile(importGenesisFile) +func validateGenDoc(appGenesis *types.AppGenesis) error { + genDoc, err := appGenesis.ToCometBFTGenesisDoc() if err != nil { - return nil, fmt.Errorf("%s. Make sure that"+ + return err + } + + if err := genDoc.ValidateAndComplete(); err != nil { + return fmt.Errorf("%w. Make sure that"+ " you have correctly migrated all CometBFT consensus params, please see the"+ " chain migration guide at %s for more info", - err.Error(), chainUpgradeGuide, - ) + err, chainUpgradeGuide) } - return genDoc, nil + return nil } diff --git a/x/genutil/collect.go b/x/genutil/collect.go index 4532d0d0a50..de01c071551 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -22,7 +22,7 @@ import ( // GenAppStateFromConfig gets the genesis app state from the config func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodingConfig, - config *cfg.Config, initCfg types.InitConfig, genesis types.AppGenesis, genBalIterator types.GenesisBalancesIterator, + config *cfg.Config, initCfg types.InitConfig, genesis *types.AppGenesis, genBalIterator types.GenesisBalancesIterator, validator types.MessageValidator, ) (appState json.RawMessage, err error) { // process genesis transactions, else create default genesis.json @@ -65,7 +65,7 @@ func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodi // CollectTxs processes and validates application's genesis Txs and returns // the list of appGenTxs, and persistent peers required to generate genesis.json. func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, - genesis types.AppGenesis, genBalIterator types.GenesisBalancesIterator, + genesis *types.AppGenesis, genBalIterator types.GenesisBalancesIterator, validator types.MessageValidator, ) (appGenTxs []sdk.Tx, persistentPeers string, err error) { // prepare a map of all balances in genesis state to then validate diff --git a/x/genutil/collect_test.go b/x/genutil/collect_test.go index 4179fd2230a..3f0a32a0791 100644 --- a/x/genutil/collect_test.go +++ b/x/genutil/collect_test.go @@ -55,7 +55,7 @@ func TestCollectTxsHandlesDirectories(t *testing.T) { srvCtx := server.NewDefaultContext() _ = srvCtx cdc := codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) - genesis := types.AppGenesis{AppState: []byte("{}")} + genesis := &types.AppGenesis{AppState: []byte("{}")} balItr := new(doNothingIterator) dnc := &doNothingUnmarshalJSON{cdc} diff --git a/x/genutil/migrations/v048/migrate.go b/x/genutil/migrations/v048/migrate.go deleted file mode 100644 index 544b641ea33..00000000000 --- a/x/genutil/migrations/v048/migrate.go +++ /dev/null @@ -1,11 +0,0 @@ -package v048 - -import ( - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/x/genutil/types" -) - -// Migrate migrates exported state from v0.47 to a v0.48 genesis state. -func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap { - return nil -} diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index b8bec60d22f..37ea4a5c2ec 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -2,12 +2,21 @@ package types import ( "encoding/json" - fmt "fmt" + "errors" + "fmt" "os" "time" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" + cmttime "github.com/cometbft/cometbft/types/time" + + "github.com/cosmos/cosmos-sdk/version" +) + +const ( + // MaxChainIDLen is the maximum length of a chain ID. + MaxChainIDLen = cmttypes.MaxChainIDLen ) // AppGenesisOnly defines the app's genesis. @@ -25,8 +34,19 @@ type AppGenesis struct { ConsensusParams *cmtproto.ConsensusParams `json:"consensus_params,omitempty"` } +// NewAppGenesisWithVersion returns a new AppGenesis with the app name and app version already. +func NewAppGenesisWithVersion(chainID string, appState json.RawMessage) *AppGenesis { + return &AppGenesis{ + AppName: version.AppName, + AppVersion: version.Version, + ChainID: chainID, + AppState: appState, + Validators: nil, + } +} + // ToCometBFTGenesisDoc converts the AppGenesis to a CometBFT GenesisDoc. -func (ag AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { +func (ag *AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { var consensusParams *cmttypes.ConsensusParams if ag.ConsensusParams != nil { consensusParams = &cmttypes.ConsensusParams{ @@ -65,17 +85,56 @@ func (ag *AppGenesis) SaveAs(file string) error { return os.WriteFile(file, appGenesisBytes, 0600) } +// ValidateAndComplete performs validation and completes the AppGenesis. +func (ag *AppGenesis) ValidateAndComplete() error { + if ag.ChainID == "" { + return errors.New("genesis doc must include non-empty chain_id") + } + + if len(ag.ChainID) > MaxChainIDLen { + return fmt.Errorf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen) + } + + if ag.InitialHeight < 0 { + return fmt.Errorf("initial_height cannot be negative (got %v)", ag.InitialHeight) + } + + if ag.InitialHeight == 0 { + ag.InitialHeight = 1 + } + + if ag.GenesisTime.IsZero() { + ag.GenesisTime = cmttime.Now() + } + + // verify that genesis parameters are valid for ABCI + cmtGenesis, err := ag.ToCometBFTGenesisDoc() + if err != nil { + return err + } + + if err := cmtGenesis.ValidateAndComplete(); err != nil { + return err + } + + ag.Validators = cmtGenesis.Validators + consensusParams := cmtGenesis.ConsensusParams.ToProto() + ag.ConsensusParams = &consensusParams + + return nil +} + // AppGenesisFromFile reads the AppGenesis from the provided file. -func AppGenesisFromFile(genFile string) (AppGenesis, error) { +func AppGenesisFromFile(genFile string) (*AppGenesis, error) { jsonBlob, err := os.ReadFile(genFile) if err != nil { - return AppGenesis{}, fmt.Errorf("couldn't read AppGenesis file (%s): %w", genFile, err) + return nil, fmt.Errorf("couldn't read AppGenesis file (%s): %w", genFile, err) } var appGenesis AppGenesis if err := json.Unmarshal(jsonBlob, &appGenesis); err != nil { - return AppGenesis{}, fmt.Errorf("error unmarshalling AppGenesis at %s: %w", genFile, err) + return nil, fmt.Errorf("error unmarshalling AppGenesis at %s: %w", genFile, err) } - return appGenesis, nil + return &appGenesis, nil } diff --git a/x/genutil/types/genesis_state.go b/x/genutil/types/genesis_state.go index d3e624c9447..421319adc3a 100644 --- a/x/genutil/types/genesis_state.go +++ b/x/genutil/types/genesis_state.go @@ -64,7 +64,7 @@ func SetGenesisStateInAppState( // for the application. // // NOTE: The pubkey input is this machines pubkey. -func GenesisStateFromAppGenesis(gesnsis AppGenesis) (genesisState map[string]json.RawMessage, err error) { +func GenesisStateFromAppGenesis(gesnsis *AppGenesis) (genesisState map[string]json.RawMessage, err error) { if err = json.Unmarshal(gesnsis.AppState, &genesisState); err != nil { return genesisState, err } @@ -75,7 +75,7 @@ func GenesisStateFromAppGenesis(gesnsis AppGenesis) (genesisState map[string]jso // for the application. // // NOTE: The pubkey input is this machines pubkey. -func GenesisStateFromGenFile(genFile string) (genesisState map[string]json.RawMessage, genesis AppGenesis, err error) { +func GenesisStateFromGenFile(genFile string) (genesisState map[string]json.RawMessage, genesis *AppGenesis, err error) { if _, err := os.Stat(genFile); os.IsNotExist(err) { return genesisState, genesis, fmt.Errorf("%s does not exist, run `init` first", genFile) } diff --git a/x/genutil/utils.go b/x/genutil/utils.go index d2bf8bb521b..fcbe8e4ec80 100644 --- a/x/genutil/utils.go +++ b/x/genutil/utils.go @@ -21,10 +21,10 @@ import ( // ExportGenesisFile creates and writes the genesis configuration to disk. An // error is returned if building or writing the configuration to file fails. -func ExportGenesisFile(genesis types.AppGenesis, genFile string) error { - // if err := genDoc.ValidateAndComplete(); err != nil { - // return err - // } +func ExportGenesisFile(genesis *types.AppGenesis, genFile string) error { + if err := genesis.ValidateAndComplete(); err != nil { + return err + } return genesis.SaveAs(genFile) } @@ -32,16 +32,13 @@ func ExportGenesisFile(genesis types.AppGenesis, genFile string) error { // ExportGenesisFileWithTime creates and writes the genesis configuration to disk. // An error is returned if building or writing the configuration to file fails. func ExportGenesisFileWithTime(genFile, chainID string, validators []cmttypes.GenesisValidator, appState json.RawMessage, genTime time.Time) error { - appGenesis := types.AppGenesis{ - GenesisTime: genTime, - ChainID: chainID, - Validators: validators, - AppState: appState, - } + appGenesis := types.NewAppGenesisWithVersion(chainID, appState) + appGenesis.GenesisTime = genTime + appGenesis.Validators = validators - // if err := genDoc.ValidateAndComplete(); err != nil { - // return err - // } + if err := appGenesis.ValidateAndComplete(); err != nil { + return err + } return appGenesis.SaveAs(genFile) } From 0b66aabb4842a4f56a81aa78e47fa8020958636c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 17 Feb 2023 12:25:11 +0100 Subject: [PATCH 12/23] updates --- x/genutil/types/genesis.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 37ea4a5c2ec..2c88ef49bd4 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -7,6 +7,7 @@ import ( "os" "time" + cmtjson "github.com/cometbft/cometbft/libs/json" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" cmttime "github.com/cometbft/cometbft/types/time" @@ -133,8 +134,30 @@ func AppGenesisFromFile(genFile string) (*AppGenesis, error) { var appGenesis AppGenesis if err := json.Unmarshal(jsonBlob, &appGenesis); err != nil { - return nil, fmt.Errorf("error unmarshalling AppGenesis at %s: %w", genFile, err) + // fallback to tendermint genesis + var tmGenesis cmttypes.GenesisDoc + if err2 := cmtjson.Unmarshal(jsonBlob, &tmGenesis); err2 != nil { + // here we ignore the error from the fallback + return nil, fmt.Errorf("error unmarshalling AppGenesis at %s: %w and failed fallback to CometBFT GenDoc: %w", genFile, err, err2) + } + + return AppGenesisFromCometBFTGenesisDoc(&tmGenesis), nil } return &appGenesis, nil } + +func AppGenesisFromCometBFTGenesisDoc(genDoc *cmttypes.GenesisDoc) *AppGenesis { + consensusParams := genDoc.ConsensusParams.ToProto() + return &AppGenesis{ + AppName: version.AppName, + AppVersion: version.Version, + GenesisTime: genDoc.GenesisTime, + ChainID: genDoc.ChainID, + InitialHeight: genDoc.InitialHeight, + AppHash: genDoc.AppHash, + AppState: genDoc.AppState, + Validators: genDoc.Validators, + ConsensusParams: &consensusParams, + } +} From 3360f153d25a9cdd551e5aa9caf60ae9ca314e2b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 17 Feb 2023 12:30:51 +0100 Subject: [PATCH 13/23] updates --- x/genutil/types/genesis.go | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 2c88ef49bd4..2c1ffb63d9d 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -108,7 +108,7 @@ func (ag *AppGenesis) ValidateAndComplete() error { ag.GenesisTime = cmttime.Now() } - // verify that genesis parameters are valid for ABCI + // verify that consesus and validators parameters are valid for CometBFT cmtGenesis, err := ag.ToCometBFTGenesisDoc() if err != nil { return err @@ -127,37 +127,30 @@ func (ag *AppGenesis) ValidateAndComplete() error { // AppGenesisFromFile reads the AppGenesis from the provided file. func AppGenesisFromFile(genFile string) (*AppGenesis, error) { - jsonBlob, err := os.ReadFile(genFile) + jsonBlob, err := os.ReadFile(genFile) //nolint:gosec if err != nil { return nil, fmt.Errorf("couldn't read AppGenesis file (%s): %w", genFile, err) } var appGenesis AppGenesis if err := json.Unmarshal(jsonBlob, &appGenesis); err != nil { - // fallback to tendermint genesis - var tmGenesis cmttypes.GenesisDoc - if err2 := cmtjson.Unmarshal(jsonBlob, &tmGenesis); err2 != nil { - // here we ignore the error from the fallback + // fallback to CometBFT genesis + var ctmGenesis cmttypes.GenesisDoc + if err2 := cmtjson.Unmarshal(jsonBlob, &ctmGenesis); err2 != nil { return nil, fmt.Errorf("error unmarshalling AppGenesis at %s: %w and failed fallback to CometBFT GenDoc: %w", genFile, err, err2) } - return AppGenesisFromCometBFTGenesisDoc(&tmGenesis), nil + consensusParams := ctmGenesis.ConsensusParams.ToProto() + appGenesis = AppGenesis{ + GenesisTime: ctmGenesis.GenesisTime, + ChainID: ctmGenesis.ChainID, + InitialHeight: ctmGenesis.InitialHeight, + AppHash: ctmGenesis.AppHash, + AppState: ctmGenesis.AppState, + Validators: ctmGenesis.Validators, + ConsensusParams: &consensusParams, + } } return &appGenesis, nil } - -func AppGenesisFromCometBFTGenesisDoc(genDoc *cmttypes.GenesisDoc) *AppGenesis { - consensusParams := genDoc.ConsensusParams.ToProto() - return &AppGenesis{ - AppName: version.AppName, - AppVersion: version.Version, - GenesisTime: genDoc.GenesisTime, - ChainID: genDoc.ChainID, - InitialHeight: genDoc.InitialHeight, - AppHash: genDoc.AppHash, - AppState: genDoc.AppState, - Validators: genDoc.Validators, - ConsensusParams: &consensusParams, - } -} From e18849834053f8882d41b28334cff785648daea5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 17 Feb 2023 12:32:13 +0100 Subject: [PATCH 14/23] updates --- x/genutil/types/genesis.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 2c1ffb63d9d..df7254e85bd 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -109,6 +109,7 @@ func (ag *AppGenesis) ValidateAndComplete() error { } // verify that consesus and validators parameters are valid for CometBFT + // TODO eventually generalize this for every consensus engine cmtGenesis, err := ag.ToCometBFTGenesisDoc() if err != nil { return err From 7d4cb65127bb376f15d1f7dfb2d49d4de3275492 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 20 Feb 2023 11:55:44 +0100 Subject: [PATCH 15/23] feedback and fix --- tests/integration/staking/keeper/genesis_test.go | 2 +- x/genutil/README.md | 13 +++++++++++++ x/genutil/doc.go | 7 ++++--- x/genutil/types/genesis.go | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 x/genutil/README.md diff --git a/tests/integration/staking/keeper/genesis_test.go b/tests/integration/staking/keeper/genesis_test.go index 5baa30faec9..95cc4c2e179 100644 --- a/tests/integration/staking/keeper/genesis_test.go +++ b/tests/integration/staking/keeper/genesis_test.go @@ -92,7 +92,7 @@ func TestInitGenesis(t *testing.T) { assert.NilError(t, err) for _, val := range vals2 { - assert.Assert(t, val.Address != "") + assert.Assert(t, val.Address.String() != "") } // now make sure the validators are bonded and intra-tx counters are correct diff --git a/x/genutil/README.md b/x/genutil/README.md new file mode 100644 index 00000000000..2d421272591 --- /dev/null +++ b/x/genutil/README.md @@ -0,0 +1,13 @@ +# `x/genutil` + +## Concepts + +The `genutil` package contains a variaety of genesis utility functionalities for usage within a blockchain application. Namely: + +* Genesis transactions related (gentx) +* Commands for collection and creation of gentxs +* `InitChain` processing of gentxs +* Genesis file validation +* Genesis file migration +* CometBFT related initialization + * Translation of an app genesis to a CometBFT genesis diff --git a/x/genutil/doc.go b/x/genutil/doc.go index 43b713b145f..daec4032a9c 100644 --- a/x/genutil/doc.go +++ b/x/genutil/doc.go @@ -2,9 +2,10 @@ Package genutil contains a variety of genesis utility functionality for usage within a blockchain application. Namely: - Genesis transactions related (gentx) - - commands for collection and creation of gentxs - - initchain processing of gentxs + - Commands for collection and creation of gentxs + - `InitChain` processing of gentxs - Genesis file validation - - CometBFT related initialization + - Genesis file migration + - CometBFT related initialization (Translation of an app genesis to a CometBFT genesis) */ package genutil diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index df7254e85bd..33c724b12e5 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -83,7 +83,7 @@ func (ag *AppGenesis) SaveAs(file string) error { return err } - return os.WriteFile(file, appGenesisBytes, 0600) + return os.WriteFile(file, appGenesisBytes, 0o600) } // ValidateAndComplete performs validation and completes the AppGenesis. From 9f83600fb9ff55cdcc4e547c2fdc059dd408fbbe Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 20 Feb 2023 12:02:14 +0100 Subject: [PATCH 16/23] better docs --- x/genutil/README.md | 47 ++++++++++++++++++++++++ x/genutil/client/cli/validate_genesis.go | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/x/genutil/README.md b/x/genutil/README.md index 2d421272591..90db9f49421 100644 --- a/x/genutil/README.md +++ b/x/genutil/README.md @@ -11,3 +11,50 @@ The `genutil` package contains a variaety of genesis utility functionalities for * Genesis file migration * CometBFT related initialization * Translation of an app genesis to a CometBFT genesis + +## Client + +### CLI + +The genutil commands are available under the `genesis` subcommand. + +#### add-genesis-account + +Add a genesis account to `genesis.json`. Learn more [here](https://docs.cosmos.network/main/run-node/run-node#adding-genesis-accounts). + +#### collect-gentxs + +Collect genesis txs and output a `genesis.json` file. + +```shell +simd genesis collect-gentxs +``` + +This will create a new `genesis.json` file that includes data from all the validators (we sometimes call it the "super genesis file" to distinguish it from single-validator genesis files). + +#### gentx + +Generate a genesis tx carrying a self delegation. + +```shell +simd genesis gentx [key_name] [amount] --chain-id [chain-id] +``` + +This will create the genesis transaction for your new chain. Here `amount` should be at least `1000000000stake`. +If you provide too much or too little, you will encounter an error when starting a node. + +#### migrate + +Migrate genesis to a specified target (SDK) version. + +```shell +simd genesis migrate [target-version] +``` + +#### validate-genesis + +Validates the genesis file at the default location or at the location passed as an argument. + +```shell +simd genesis validate-genesis +``` diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index db6dd8eeb1b..1cdbb5487a0 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -20,7 +20,7 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { Use: "validate [file]", Aliases: []string{"validate-genesis"}, Args: cobra.RangeArgs(0, 1), - Short: "validates the genesis file at the default location or at the location passed as an arg", + Short: "Validates the genesis file at the default location or at the location passed as an arg", RunE: func(cmd *cobra.Command, args []string) (err error) { serverCtx := server.GetServerContextFromCmd(cmd) clientCtx := client.GetClientContextFromCmd(cmd) From eb83d6ae94693e2e07a0941b0a4888112aa1dfc8 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 20 Feb 2023 12:25:23 +0100 Subject: [PATCH 17/23] add tests --- x/genutil/types/genesis.go | 1 + x/genutil/types/genesis_test.go | 30 +++++++++++++++-------- x/genutil/types/testdata/app_genesis.json | 1 + x/genutil/types/testdata/cmt_genesis.json | 1 + 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 x/genutil/types/testdata/app_genesis.json create mode 100644 x/genutil/types/testdata/cmt_genesis.json diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 33c724b12e5..7f73d64ae6f 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -67,6 +67,7 @@ func (ag *AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { } return &cmttypes.GenesisDoc{ + GenesisTime: ag.GenesisTime, ChainID: ag.ChainID, InitialHeight: ag.InitialHeight, AppHash: ag.AppHash, diff --git a/x/genutil/types/genesis_test.go b/x/genutil/types/genesis_test.go index 2ba1ef80bef..59547ab0b28 100644 --- a/x/genutil/types/genesis_test.go +++ b/x/genutil/types/genesis_test.go @@ -4,8 +4,11 @@ import ( "encoding/json" "testing" - "github.com/cosmos/cosmos-sdk/x/genutil/types" "gotest.tools/v3/assert" + "gotest.tools/v3/golden" + + cmttypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/x/genutil/types" ) var expectedAppGenesisJSON = `{"app_name":"simapp","app_version":"0.1.0","genesis_time":"0001-01-01T00:00:00Z","chain_id":"test","initial_height":0,"app_hash":null}` @@ -33,16 +36,23 @@ func TestAppGenesis_Unmarshal(t *testing.T) { assert.DeepEqual(t, genesis.ChainID, "test") } -func TestAppGenesis_ToCometBFTGenesisDoc(t *testing.T) { - genesis := types.AppGenesis{ - AppName: "simapp", - AppVersion: "0.1.0", - ChainID: "test", - AppHash: []byte{5, 34, 11, 3, 23}, - } +func TestAppGenesis_ValidCometBFTGenesis(t *testing.T) { + // validate can read cometbft genesis file + genesis, err := types.AppGenesisFromFile("testdata/cmt_genesis.json") + assert.NilError(t, err) + + assert.DeepEqual(t, genesis.ChainID, "demo") + assert.DeepEqual(t, genesis.Validators[0].Name, "test") + // validate the app genesis can be translated properly to cometbft genesis cmtGenesis, err := genesis.ToCometBFTGenesisDoc() assert.NilError(t, err) - assert.DeepEqual(t, cmtGenesis.ChainID, "test") - assert.DeepEqual(t, cmtGenesis.AppHash.String(), "05220B0317") + rawCmtGenesis, err := cmttypes.GenesisDocFromFile("testdata/cmt_genesis.json") + assert.NilError(t, err) + assert.DeepEqual(t, cmtGenesis, rawCmtGenesis) + + // validate can properly marshal to app genesis file + rawAppGenesis, err := json.Marshal(&genesis) + assert.NilError(t, err) + golden.Assert(t, string(rawAppGenesis), "app_genesis.json") } diff --git a/x/genutil/types/testdata/app_genesis.json b/x/genutil/types/testdata/app_genesis.json new file mode 100644 index 00000000000..ae6fc67006e --- /dev/null +++ b/x/genutil/types/testdata/app_genesis.json @@ -0,0 +1 @@ +{"app_name":"","app_version":"","genesis_time":"2023-02-20T11:08:30.588307671Z","chain_id":"demo","initial_height":48,"app_hash":"","app_state":{"auth":{"accounts":[{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"1","address":"cosmos1qmkksxlxqdslq6kkca25m4jn344nx29lytq8f9","pub_key":null,"sequence":"0"},{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"8","address":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8","pub_key":null,"sequence":"0"},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"4","address":"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh","pub_key":null,"sequence":"0"},"name":"bonded_tokens_pool","permissions":["burner","staking"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"5","address":"cosmos1tygms3xhhs3yv487phx3dw4a95jn7t7lpm470r","pub_key":null,"sequence":"0"},"name":"not_bonded_tokens_pool","permissions":["burner","staking"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"6","address":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","pub_key":null,"sequence":"0"},"name":"gov","permissions":["burner"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"3","address":"cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl","pub_key":null,"sequence":"0"},"name":"distribution","permissions":[]},{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"0","address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","pub_key":{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A3uyZdXedyvYx9VCL6xRjkxtcFpgxjhXFIz9b2mWz+aV"},"sequence":"4"},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"7","address":"cosmos1m3h30wlvsf8llruxtpukdvsy0km2kum8g38c8q","pub_key":null,"sequence":"0"},"name":"mint","permissions":["minter"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"2","address":"cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta","pub_key":null,"sequence":"0"},"name":"fee_collector","permissions":[]}],"params":{"max_memo_characters":"256","sig_verify_cost_ed25519":"590","sig_verify_cost_secp256k1":"1000","tx_sig_limit":"7","tx_size_cost_per_byte":"10"}},"authz":{"authorization":[]},"bank":{"balances":[{"address":"cosmos1qmkksxlxqdslq6kkca25m4jn344nx29lytq8f9","coins":[{"amount":"5000000000","denom":"stake"}]},{"address":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8","coins":[{"amount":"1000","denom":"stake"}]},{"address":"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh","coins":[{"amount":"1000000","denom":"stake"}]},{"address":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","coins":[{"amount":"10010000","denom":"stake"}]},{"address":"cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl","coins":[{"amount":"9635","denom":"stake"}]},{"address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","coins":[{"amount":"4988989000","denom":"stake"}]}],"denom_metadata":[],"params":{"default_send_enabled":true,"send_enabled":[]},"send_enabled":[],"supply":[{"amount":"10000009635","denom":"stake"}]},"capability":{"index":"1","owners":[]},"consensus":null,"crisis":{"constant_fee":{"amount":"1000","denom":"stake"}},"distribution":{"delegator_starting_infos":[{"delegator_address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","starting_info":{"height":"0","previous_period":"1","stake":"1000000.000000000000000000"},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"delegator_withdraw_infos":[],"fee_pool":{"community_pool":[{"amount":"192.700000000000000000","denom":"stake"}]},"outstanding_rewards":[{"outstanding_rewards":[{"amount":"9442.300000000000000000","denom":"stake"}],"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"params":{"base_proposer_reward":"0.000000000000000000","bonus_proposer_reward":"0.000000000000000000","community_tax":"0.020000000000000000","withdraw_addr_enabled":true},"previous_proposer":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","validator_accumulated_commissions":[{"accumulated":{"commission":[{"amount":"944.230000000000000000","denom":"stake"}]},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_current_rewards":[{"rewards":{"period":"2","rewards":[{"amount":"8498.070000000000000000","denom":"stake"}]},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_historical_rewards":[{"period":"1","rewards":{"cumulative_reward_ratio":[],"reference_count":2},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_slash_events":[]},"evidence":{"evidence":[]},"feegrant":{"allowances":[]},"genutil":{"gen_txs":[]},"gov":{"deposit_params":null,"deposits":[{"amount":[{"amount":"10010000","denom":"stake"}],"depositor":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","proposal_id":"1"}],"params":{"expedited_min_deposit":[{"amount":"50000000","denom":"stake"}],"expedited_threshold":"0.667000000000000000","expedited_voting_period":"86400s","max_deposit_period":"172800s","min_deposit":[{"amount":"10000000","denom":"stake"}],"min_initial_deposit_ratio":"0.000000000000000000","proposal_cancel_dest":"","proposal_cancel_ratio":"0.500000000000000000","quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000","voting_period":"172800s"},"proposals":[{"deposit_end_time":"2023-02-22T11:11:52.776167376Z","expedited":false,"final_tally_result":{"abstain_count":"0","no_count":"0","no_with_veto_count":"0","yes_count":"0"},"id":"1","messages":[{"@type":"/cosmos.distribution.v1beta1.MsgCommunityPoolSpend","amount":[],"authority":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","recipient":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8"}],"metadata":"ipfs://CID","proposer":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","status":"PROPOSAL_STATUS_VOTING_PERIOD","submit_time":"2023-02-20T11:11:52.776167376Z","summary":"test proposal","title":"test proposal","total_deposit":[{"amount":"10010000","denom":"stake"}],"voting_end_time":"2023-02-22T11:12:07.801161984Z","voting_start_time":"2023-02-20T11:12:07.801161984Z"}],"starting_proposal_id":"2","tally_params":null,"votes":[],"voting_params":null},"group":{"group_members":[],"group_policies":[],"group_policy_seq":"0","group_seq":"0","groups":[],"proposal_seq":"0","proposals":[],"votes":[]},"mint":{"minter":{"annual_provisions":"1300010905.175073197786747950","inflation":"0.130000967926594565"},"params":{"blocks_per_year":"6311520","goal_bonded":"0.670000000000000000","inflation_max":"0.200000000000000000","inflation_min":"0.070000000000000000","inflation_rate_change":"0.130000000000000000","mint_denom":"stake"}},"nft":{"classes":[],"entries":[]},"params":null,"slashing":{"missed_blocks":[{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","missed_blocks":[]}],"params":{"downtime_jail_duration":"600s","min_signed_per_window":"0.500000000000000000","signed_blocks_window":"100","slash_fraction_double_sign":"0.050000000000000000","slash_fraction_downtime":"0.010000000000000000"},"signing_infos":[{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","validator_signing_info":{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","index_offset":"46","jailed_until":"1970-01-01T00:00:00Z","missed_blocks_counter":"0","start_height":"0","tombstoned":false}}]},"staking":{"delegations":[{"delegator_address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","shares":"1000000.000000000000000000","validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"exported":true,"last_total_power":"1","last_validator_powers":[{"address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp","power":"1"}],"params":{"bond_denom":"stake","historical_entries":10000,"max_entries":7,"max_validators":100,"min_commission_rate":"0.000000000000000000","unbonding_time":"1814400s"},"redelegations":[],"unbonding_delegations":[],"validators":[{"commission":{"commission_rates":{"max_change_rate":"0.010000000000000000","max_rate":"0.200000000000000000","rate":"0.100000000000000000"},"update_time":"2023-02-20T11:08:30.588307671Z"},"consensus_pubkey":{"@type":"/cosmos.crypto.ed25519.PubKey","key":"tMZonPQYoooG/xbFVhHg95pTLxx7aO43/qgHFxDagWM="},"delegator_shares":"1000000.000000000000000000","description":{"details":"","identity":"","moniker":"test","security_contact":"","website":""},"jailed":false,"min_self_delegation":"1","operator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp","status":"BOND_STATUS_BONDED","tokens":"1000000","unbonding_height":"0","unbonding_ids":[],"unbonding_on_hold_ref_count":"0","unbonding_time":"1970-01-01T00:00:00Z"}]},"upgrade":{},"vesting":{}},"validators":[{"address":"D336F99AA5CF77503CDD8366E68A0DFE89B4124B","pub_key":"tMZonPQYoooG/xbFVhHg95pTLxx7aO43/qgHFxDagWM=","power":1,"name":"test"}],"consensus_params":{"block":{"max_bytes":22020096,"max_gas":-1},"evidence":{"max_age_num_blocks":100000,"max_age_duration":172800000000000,"max_bytes":1048576},"validator":{"pub_key_types":["ed25519"]},"version":{}}} \ No newline at end of file diff --git a/x/genutil/types/testdata/cmt_genesis.json b/x/genutil/types/testdata/cmt_genesis.json new file mode 100644 index 00000000000..96275f71806 --- /dev/null +++ b/x/genutil/types/testdata/cmt_genesis.json @@ -0,0 +1 @@ +{"app_hash":"","app_state":{"auth":{"accounts":[{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"1","address":"cosmos1qmkksxlxqdslq6kkca25m4jn344nx29lytq8f9","pub_key":null,"sequence":"0"},{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"8","address":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8","pub_key":null,"sequence":"0"},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"4","address":"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh","pub_key":null,"sequence":"0"},"name":"bonded_tokens_pool","permissions":["burner","staking"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"5","address":"cosmos1tygms3xhhs3yv487phx3dw4a95jn7t7lpm470r","pub_key":null,"sequence":"0"},"name":"not_bonded_tokens_pool","permissions":["burner","staking"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"6","address":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","pub_key":null,"sequence":"0"},"name":"gov","permissions":["burner"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"3","address":"cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl","pub_key":null,"sequence":"0"},"name":"distribution","permissions":[]},{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"0","address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","pub_key":{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A3uyZdXedyvYx9VCL6xRjkxtcFpgxjhXFIz9b2mWz+aV"},"sequence":"4"},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"7","address":"cosmos1m3h30wlvsf8llruxtpukdvsy0km2kum8g38c8q","pub_key":null,"sequence":"0"},"name":"mint","permissions":["minter"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"2","address":"cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta","pub_key":null,"sequence":"0"},"name":"fee_collector","permissions":[]}],"params":{"max_memo_characters":"256","sig_verify_cost_ed25519":"590","sig_verify_cost_secp256k1":"1000","tx_sig_limit":"7","tx_size_cost_per_byte":"10"}},"authz":{"authorization":[]},"bank":{"balances":[{"address":"cosmos1qmkksxlxqdslq6kkca25m4jn344nx29lytq8f9","coins":[{"amount":"5000000000","denom":"stake"}]},{"address":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8","coins":[{"amount":"1000","denom":"stake"}]},{"address":"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh","coins":[{"amount":"1000000","denom":"stake"}]},{"address":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","coins":[{"amount":"10010000","denom":"stake"}]},{"address":"cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl","coins":[{"amount":"9635","denom":"stake"}]},{"address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","coins":[{"amount":"4988989000","denom":"stake"}]}],"denom_metadata":[],"params":{"default_send_enabled":true,"send_enabled":[]},"send_enabled":[],"supply":[{"amount":"10000009635","denom":"stake"}]},"capability":{"index":"1","owners":[]},"consensus":null,"crisis":{"constant_fee":{"amount":"1000","denom":"stake"}},"distribution":{"delegator_starting_infos":[{"delegator_address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","starting_info":{"height":"0","previous_period":"1","stake":"1000000.000000000000000000"},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"delegator_withdraw_infos":[],"fee_pool":{"community_pool":[{"amount":"192.700000000000000000","denom":"stake"}]},"outstanding_rewards":[{"outstanding_rewards":[{"amount":"9442.300000000000000000","denom":"stake"}],"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"params":{"base_proposer_reward":"0.000000000000000000","bonus_proposer_reward":"0.000000000000000000","community_tax":"0.020000000000000000","withdraw_addr_enabled":true},"previous_proposer":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","validator_accumulated_commissions":[{"accumulated":{"commission":[{"amount":"944.230000000000000000","denom":"stake"}]},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_current_rewards":[{"rewards":{"period":"2","rewards":[{"amount":"8498.070000000000000000","denom":"stake"}]},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_historical_rewards":[{"period":"1","rewards":{"cumulative_reward_ratio":[],"reference_count":2},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_slash_events":[]},"evidence":{"evidence":[]},"feegrant":{"allowances":[]},"genutil":{"gen_txs":[]},"gov":{"deposit_params":null,"deposits":[{"amount":[{"amount":"10010000","denom":"stake"}],"depositor":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","proposal_id":"1"}],"params":{"expedited_min_deposit":[{"amount":"50000000","denom":"stake"}],"expedited_threshold":"0.667000000000000000","expedited_voting_period":"86400s","max_deposit_period":"172800s","min_deposit":[{"amount":"10000000","denom":"stake"}],"min_initial_deposit_ratio":"0.000000000000000000","proposal_cancel_dest":"","proposal_cancel_ratio":"0.500000000000000000","quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000","voting_period":"172800s"},"proposals":[{"deposit_end_time":"2023-02-22T11:11:52.776167376Z","expedited":false,"final_tally_result":{"abstain_count":"0","no_count":"0","no_with_veto_count":"0","yes_count":"0"},"id":"1","messages":[{"@type":"/cosmos.distribution.v1beta1.MsgCommunityPoolSpend","amount":[],"authority":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","recipient":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8"}],"metadata":"ipfs://CID","proposer":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","status":"PROPOSAL_STATUS_VOTING_PERIOD","submit_time":"2023-02-20T11:11:52.776167376Z","summary":"test proposal","title":"test proposal","total_deposit":[{"amount":"10010000","denom":"stake"}],"voting_end_time":"2023-02-22T11:12:07.801161984Z","voting_start_time":"2023-02-20T11:12:07.801161984Z"}],"starting_proposal_id":"2","tally_params":null,"votes":[],"voting_params":null},"group":{"group_members":[],"group_policies":[],"group_policy_seq":"0","group_seq":"0","groups":[],"proposal_seq":"0","proposals":[],"votes":[]},"mint":{"minter":{"annual_provisions":"1300010905.175073197786747950","inflation":"0.130000967926594565"},"params":{"blocks_per_year":"6311520","goal_bonded":"0.670000000000000000","inflation_max":"0.200000000000000000","inflation_min":"0.070000000000000000","inflation_rate_change":"0.130000000000000000","mint_denom":"stake"}},"nft":{"classes":[],"entries":[]},"params":null,"slashing":{"missed_blocks":[{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","missed_blocks":[]}],"params":{"downtime_jail_duration":"600s","min_signed_per_window":"0.500000000000000000","signed_blocks_window":"100","slash_fraction_double_sign":"0.050000000000000000","slash_fraction_downtime":"0.010000000000000000"},"signing_infos":[{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","validator_signing_info":{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","index_offset":"46","jailed_until":"1970-01-01T00:00:00Z","missed_blocks_counter":"0","start_height":"0","tombstoned":false}}]},"staking":{"delegations":[{"delegator_address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","shares":"1000000.000000000000000000","validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"exported":true,"last_total_power":"1","last_validator_powers":[{"address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp","power":"1"}],"params":{"bond_denom":"stake","historical_entries":10000,"max_entries":7,"max_validators":100,"min_commission_rate":"0.000000000000000000","unbonding_time":"1814400s"},"redelegations":[],"unbonding_delegations":[],"validators":[{"commission":{"commission_rates":{"max_change_rate":"0.010000000000000000","max_rate":"0.200000000000000000","rate":"0.100000000000000000"},"update_time":"2023-02-20T11:08:30.588307671Z"},"consensus_pubkey":{"@type":"/cosmos.crypto.ed25519.PubKey","key":"tMZonPQYoooG/xbFVhHg95pTLxx7aO43/qgHFxDagWM="},"delegator_shares":"1000000.000000000000000000","description":{"details":"","identity":"","moniker":"test","security_contact":"","website":""},"jailed":false,"min_self_delegation":"1","operator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp","status":"BOND_STATUS_BONDED","tokens":"1000000","unbonding_height":"0","unbonding_ids":[],"unbonding_on_hold_ref_count":"0","unbonding_time":"1970-01-01T00:00:00Z"}]},"upgrade":{},"vesting":{}},"chain_id":"demo","consensus_params":{"block":{"max_bytes":"22020096","max_gas":"-1"},"evidence":{"max_age_duration":"172800000000000","max_age_num_blocks":"100000","max_bytes":"1048576"},"validator":{"pub_key_types":["ed25519"]},"version":{"app":"0"}},"genesis_time":"2023-02-20T11:08:30.588307671Z","initial_height":"48","validators":[{"address":"D336F99AA5CF77503CDD8366E68A0DFE89B4124B","name":"test","power":"1","pub_key":{"type":"tendermint/PubKeyEd25519","value":"tMZonPQYoooG/xbFVhHg95pTLxx7aO43/qgHFxDagWM="}}]} \ No newline at end of file From 84394a743fa7a15329b21544dca4db64ea88ac4e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Feb 2023 11:46:34 +0100 Subject: [PATCH 18/23] fix merge --- x/genutil/client/cli/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 5d10fd9a250..40455594455 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -153,7 +153,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { appGenesis.AppState = appState appGenesis.Validators = nil - if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil { + if err = genutil.ExportGenesisFile(appGenesis, genFile); err != nil { return errorsmod.Wrap(err, "Failed to export genesis file") } From eec52206739d993faf588b345b13bf388b351e00 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Feb 2023 14:36:40 +0100 Subject: [PATCH 19/23] updates --- server/export.go | 6 +- tests/e2e/server/export_test.go | 103 +++++++++++++------------------- 2 files changed, 42 insertions(+), 67 deletions(-) diff --git a/server/export.go b/server/export.go index 42d70927d2a..658b5287161 100644 --- a/server/export.go +++ b/server/export.go @@ -94,11 +94,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return nil } - var exportedAppGenesis genutiltypes.AppGenesis - if err = json.Unmarshal(out, &exportedAppGenesis); err != nil { - return err - } - if err = exportedAppGenesis.SaveAs(outputDocument); err != nil { + if err = appGenesis.SaveAs(outputDocument); err != nil { return err } diff --git a/tests/e2e/server/export_test.go b/tests/e2e/server/export_test.go index 5b911c904dc..5c6b212ad97 100644 --- a/tests/e2e/server/export_test.go +++ b/tests/e2e/server/export_test.go @@ -1,28 +1,23 @@ -//go:build e2e -// +build e2e - package server_test import ( "bytes" "context" + "encoding/json" "fmt" "io" "os" "path" "testing" - "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" - cmtjson "github.com/cometbft/cometbft/libs/json" cmtlog "github.com/cometbft/cometbft/libs/log" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - cmttypes "github.com/cometbft/cometbft/types" dbm "github.com/cosmos/cosmos-db" "github.com/spf13/cobra" - "github.com/stretchr/testify/require" + "gotest.tools/v3/assert" - errorsmod "cosmossdk.io/errors" + "cosmossdk.io/log" "cosmossdk.io/simapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -30,31 +25,29 @@ import ( "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) func TestExportCmd_ConsensusParams(t *testing.T) { tempDir := t.TempDir() - _, ctx, _, cmd := setupApp(t, tempDir) output := &bytes.Buffer{} cmd.SetOut(output) cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)}) - require.NoError(t, cmd.ExecuteContext(ctx)) + assert.NilError(t, cmd.ExecuteContext(ctx)) - var exportedGenDoc cmttypes.GenesisDoc - err := cmtjson.Unmarshal(output.Bytes(), &exportedGenDoc) - if err != nil { - t.Fatalf("error unmarshaling exported genesis doc: %s", err) - } + var exportedAppGenesis genutiltypes.AppGenesis + err := json.Unmarshal(output.Bytes(), &exportedAppGenesis) + assert.NilError(t, err) - require.Equal(t, simtestutil.DefaultConsensusParams.Block.MaxBytes, exportedGenDoc.ConsensusParams.Block.MaxBytes) - require.Equal(t, simtestutil.DefaultConsensusParams.Block.MaxGas, exportedGenDoc.ConsensusParams.Block.MaxGas) + assert.Equal(t, simtestutil.DefaultConsensusParams.Block.MaxBytes, exportedAppGenesis.ConsensusParams.Block.MaxBytes) + assert.Equal(t, simtestutil.DefaultConsensusParams.Block.MaxGas, exportedAppGenesis.ConsensusParams.Block.MaxGas) - require.Equal(t, simtestutil.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedGenDoc.ConsensusParams.Evidence.MaxAgeDuration) - require.Equal(t, simtestutil.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedGenDoc.ConsensusParams.Evidence.MaxAgeNumBlocks) + assert.Equal(t, simtestutil.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedAppGenesis.ConsensusParams.Evidence.MaxAgeDuration) + assert.Equal(t, simtestutil.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedAppGenesis.ConsensusParams.Evidence.MaxAgeNumBlocks) - require.Equal(t, simtestutil.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes) + assert.Equal(t, simtestutil.DefaultConsensusParams.Validator.PubKeyTypes, exportedAppGenesis.ConsensusParams.Validator.PubKeyTypes) } func TestExportCmd_HomeDir(t *testing.T) { @@ -63,7 +56,7 @@ func TestExportCmd_HomeDir(t *testing.T) { cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, "foobar")}) err := cmd.ExecuteContext(ctx) - require.EqualError(t, err, "stat foobar/config/genesis.json: no such file or directory") + assert.ErrorContains(t, err, "stat foobar/config/genesis.json: no such file or directory") } func TestExportCmd_Height(t *testing.T) { @@ -109,15 +102,12 @@ func TestExportCmd_Height(t *testing.T) { cmd.SetOut(output) args := append(tc.flags, fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)) cmd.SetArgs(args) - require.NoError(t, cmd.ExecuteContext(ctx)) + assert.NilError(t, cmd.ExecuteContext(ctx)) - var exportedGenDoc cmttypes.GenesisDoc - err := cmtjson.Unmarshal(output.Bytes(), &exportedGenDoc) - if err != nil { - t.Fatalf("error unmarshaling exported genesis doc: %s", err) - } - - require.Equal(t, tc.expHeight, exportedGenDoc.InitialHeight) + var exportedAppGenesis genutiltypes.AppGenesis + err := json.Unmarshal(output.Bytes(), &exportedAppGenesis) + assert.NilError(t, err) + assert.Equal(t, tc.expHeight, exportedAppGenesis.InitialHeight) }) } } @@ -131,7 +121,7 @@ func TestExportCmd_Output(t *testing.T) { { "should export state to the specified file", []string{ - fmt.Sprintf("--%s=%s", server.FlagOutputDocument, "foobar.json"), + fmt.Sprintf("--%s=%s", flags.FlagOutputDocument, "foobar.json"), }, "foobar.json", }, @@ -146,53 +136,52 @@ func TestExportCmd_Output(t *testing.T) { cmd.SetOut(output) args := append(tc.flags, fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)) cmd.SetArgs(args) - require.NoError(t, cmd.ExecuteContext(ctx)) + assert.NilError(t, cmd.ExecuteContext(ctx)) - var exportedGenDoc cmttypes.GenesisDoc + var exportedAppGenesis genutiltypes.AppGenesis f, err := os.ReadFile(tc.outputDocument) - if err != nil { - t.Fatalf("error reading exported genesis doc: %s", err) - } - require.NoError(t, cmtjson.Unmarshal(f, &exportedGenDoc)) + assert.NilError(t, err) + assert.NilError(t, json.Unmarshal(f, &exportedAppGenesis)) // Cleanup - if err = os.Remove(tc.outputDocument); err != nil { - t.Fatalf("error removing exported genesis doc: %s", err) - } + assert.NilError(t, os.Remove(tc.outputDocument)) }) } } -func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *cmttypes.GenesisDoc, *cobra.Command) { +func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, genutiltypes.AppGenesis, *cobra.Command) { t.Helper() - if err := createConfigFolder(tempDir); err != nil { - t.Fatalf("error creating config folder: %s", err) - } + err := createConfigFolder(tempDir) + assert.NilError(t, err) logger := cmtlog.NewTMLogger(cmtlog.NewSyncWriter(os.Stdout)) db := dbm.NewMemDB() app := simapp.NewSimApp(logger, db, nil, true, simtestutil.NewAppOptionsWithFlagHome(tempDir)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) - stateBytes, err := cmtjson.MarshalIndent(genesisState, "", " ") - require.NoError(t, err) + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + assert.NilError(t, err) serverCtx := server.NewDefaultContext() serverCtx.Config.RootDir = tempDir clientCtx := client.Context{}.WithCodec(app.AppCodec()) - genDoc := &cmttypes.GenesisDoc{} - genDoc.ChainID = "theChainId" - genDoc.Validators = nil - genDoc.AppState = stateBytes + appGenesis := genutiltypes.AppGenesis{ + ChainID: "theChainId", + Validators: nil, + AppState: stateBytes, + } + + // save genesis file + err = genutil.ExportGenesisFile(&appGenesis, serverCtx.Config.GenesisFile()) + assert.NilError(t, err) - require.NoError(t, saveGenesisFile(genDoc, serverCtx.Config.GenesisFile())) app.InitChain( abci.RequestInitChain{ Validators: []abci.ValidatorUpdate{}, ConsensusParams: simtestutil.DefaultConsensusParams, - AppStateBytes: genDoc.AppState, + AppStateBytes: appGenesis.AppState, }, ) app.Commit() @@ -202,7 +191,6 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *c var simApp *simapp.SimApp if height != -1 { simApp = simapp.NewSimApp(logger, db, nil, false, appOptions) - if err := simApp.LoadHeight(height); err != nil { return types.ExportedApp{}, err } @@ -217,18 +205,9 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *c ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) - return app, ctx, genDoc, cmd + return app, ctx, appGenesis, cmd } func createConfigFolder(dir string) error { return os.Mkdir(path.Join(dir, "config"), 0o700) } - -func saveGenesisFile(genDoc *cmttypes.GenesisDoc, dir string) error { - err := genutil.ExportGenesisFile(genDoc, dir) - if err != nil { - return errorsmod.Wrap(err, "error creating file") - } - - return nil -} From 4f6d24f812eac72af5b31d4e257385d0a954d5b7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Feb 2023 18:24:32 +0100 Subject: [PATCH 20/23] fix test and have better split logic --- server/export.go | 3 +- server/start.go | 2 +- tests/e2e/server/export_test.go | 18 +- testutil/network/util.go | 10 +- x/genutil/client/cli/init.go | 4 +- x/genutil/client/cli/migrate.go | 4 +- x/genutil/client/cli/validate_genesis.go | 2 +- x/genutil/types/genesis.go | 197 ++++++++++++++-------- x/genutil/types/genesis_test.go | 33 ++-- x/genutil/types/testdata/app_genesis.json | 2 +- x/genutil/utils.go | 2 +- 11 files changed, 171 insertions(+), 106 deletions(-) diff --git a/server/export.go b/server/export.go index 658b5287161..056686c9f71 100644 --- a/server/export.go +++ b/server/export.go @@ -77,9 +77,8 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com } appGenesis.AppState = exported.AppState - appGenesis.Validators = exported.Validators appGenesis.InitialHeight = exported.Height - appGenesis.ConsensusParams = exported.ConsensusParams + appGenesis.Consensus = genutiltypes.NewConsensusGenesis(exported.ConsensusParams, exported.Validators) out, err := json.Marshal(appGenesis) if err != nil { diff --git a/server/start.go b/server/start.go index 2c14d995112..b9d886956ea 100644 --- a/server/start.go +++ b/server/start.go @@ -309,7 +309,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App return nil, err } - return appGenesis.ToCometBFTGenesisDoc() + return appGenesis.ToGenesisDoc() } var ( diff --git a/tests/e2e/server/export_test.go b/tests/e2e/server/export_test.go index 5c6b212ad97..f8a97f9316c 100644 --- a/tests/e2e/server/export_test.go +++ b/tests/e2e/server/export_test.go @@ -41,13 +41,13 @@ func TestExportCmd_ConsensusParams(t *testing.T) { err := json.Unmarshal(output.Bytes(), &exportedAppGenesis) assert.NilError(t, err) - assert.Equal(t, simtestutil.DefaultConsensusParams.Block.MaxBytes, exportedAppGenesis.ConsensusParams.Block.MaxBytes) - assert.Equal(t, simtestutil.DefaultConsensusParams.Block.MaxGas, exportedAppGenesis.ConsensusParams.Block.MaxGas) + assert.DeepEqual(t, simtestutil.DefaultConsensusParams.Block.MaxBytes, exportedAppGenesis.Consensus.Params.Block.MaxBytes) + assert.DeepEqual(t, simtestutil.DefaultConsensusParams.Block.MaxGas, exportedAppGenesis.Consensus.Params.Block.MaxGas) - assert.Equal(t, simtestutil.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedAppGenesis.ConsensusParams.Evidence.MaxAgeDuration) - assert.Equal(t, simtestutil.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedAppGenesis.ConsensusParams.Evidence.MaxAgeNumBlocks) + assert.DeepEqual(t, simtestutil.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedAppGenesis.Consensus.Params.Evidence.MaxAgeDuration) + assert.DeepEqual(t, simtestutil.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedAppGenesis.Consensus.Params.Evidence.MaxAgeNumBlocks) - assert.Equal(t, simtestutil.DefaultConsensusParams.Validator.PubKeyTypes, exportedAppGenesis.ConsensusParams.Validator.PubKeyTypes) + assert.DeepEqual(t, simtestutil.DefaultConsensusParams.Validator.PubKeyTypes, exportedAppGenesis.Consensus.Params.Validator.PubKeyTypes) } func TestExportCmd_HomeDir(t *testing.T) { @@ -168,9 +168,11 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge clientCtx := client.Context{}.WithCodec(app.AppCodec()) appGenesis := genutiltypes.AppGenesis{ - ChainID: "theChainId", - Validators: nil, - AppState: stateBytes, + ChainID: "theChainId", + AppState: stateBytes, + Consensus: &genutiltypes.ConsensusGenesis{ + Validators: nil, + }, } // save genesis file diff --git a/testutil/network/util.go b/testutil/network/util.go index ef29df4a8fa..81accb7859c 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -46,7 +46,7 @@ func startInProcess(cfg Config, val *Validator) error { return nil, err } - return appGenesis.ToCometBFTGenesisDoc() + return appGenesis.ToGenesisDoc() } tmNode, err := node.NewNode( //resleak:notresource @@ -176,9 +176,11 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance } appGenesis := genutiltypes.AppGenesis{ - ChainID: cfg.ChainID, - AppState: appGenStateJSON, - Validators: nil, + ChainID: cfg.ChainID, + AppState: appGenStateJSON, + Consensus: &genutiltypes.ConsensusGenesis{ + Validators: nil, + }, } // generate empty genesis files for each validator and save diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 40455594455..592a3a5546d 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -151,7 +151,9 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { appGenesis.AppVersion = version.Version appGenesis.ChainID = chainID appGenesis.AppState = appState - appGenesis.Validators = nil + appGenesis.Consensus = &types.ConsensusGenesis{ + Validators: nil, + } if err = genutil.ExportGenesisFile(appGenesis, genFile); err != nil { return errorsmod.Wrap(err, "Failed to export genesis file") diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index 52ad7d75559..9e7a28a1a68 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -72,8 +72,8 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 // Since some default values are valid values, we just print to // make sure the user didn't forget to update these values. - if appGenesis.ConsensusParams.Evidence.MaxBytes == 0 { - fmt.Printf("Warning: consensus_params.evidence.max_bytes is set to 0. If this is"+ + if appGenesis.Consensus.Params.Evidence.MaxBytes == 0 { + fmt.Printf("Warning: consensus.params.evidence.max_bytes is set to 0. If this is"+ " deliberate, feel free to ignore this warning. If not, please have a look at the chain"+ " upgrade guide at %s.\n", chainUpgradeGuide) } diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 1cdbb5487a0..2565bc0c739 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -63,7 +63,7 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { // CometBFT GenesisDoc. This function does not do any cosmos-related // validation. func validateGenDoc(appGenesis *types.AppGenesis) error { - genDoc, err := appGenesis.ToCometBFTGenesisDoc() + genDoc, err := appGenesis.ToGenesisDoc() if err != nil { return err } diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 7f73d64ae6f..ed07ccdc990 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -1,6 +1,7 @@ package types import ( + "bytes" "encoding/json" "errors" "fmt" @@ -20,19 +21,16 @@ const ( MaxChainIDLen = cmttypes.MaxChainIDLen ) -// AppGenesisOnly defines the app's genesis. +// AppGenesis defines the app's genesis. type AppGenesis struct { - AppName string `json:"app_name"` - AppVersion string `json:"app_version"` - GenesisTime time.Time `json:"genesis_time"` - ChainID string `json:"chain_id"` - InitialHeight int64 `json:"initial_height"` - AppHash []byte `json:"app_hash"` - AppState json.RawMessage `json:"app_state,omitempty"` - - // TODO eventually abstract from CometBFT types - Validators []cmttypes.GenesisValidator `json:"validators,omitempty"` - ConsensusParams *cmtproto.ConsensusParams `json:"consensus_params,omitempty"` + AppName string `json:"app_name"` + AppVersion string `json:"app_version"` + GenesisTime time.Time `json:"genesis_time"` + ChainID string `json:"chain_id"` + InitialHeight int64 `json:"initial_height"` + AppHash []byte `json:"app_hash"` + AppState json.RawMessage `json:"app_state,omitempty"` + Consensus *ConsensusGenesis `json:"consensus,omitempty"` } // NewAppGenesisWithVersion returns a new AppGenesis with the app name and app version already. @@ -42,51 +40,12 @@ func NewAppGenesisWithVersion(chainID string, appState json.RawMessage) *AppGene AppVersion: version.Version, ChainID: chainID, AppState: appState, - Validators: nil, + Consensus: &ConsensusGenesis{ + Validators: nil, + }, } } -// ToCometBFTGenesisDoc converts the AppGenesis to a CometBFT GenesisDoc. -func (ag *AppGenesis) ToCometBFTGenesisDoc() (*cmttypes.GenesisDoc, error) { - var consensusParams *cmttypes.ConsensusParams - if ag.ConsensusParams != nil { - consensusParams = &cmttypes.ConsensusParams{ - Block: cmttypes.BlockParams{ - MaxBytes: ag.ConsensusParams.Block.MaxBytes, - MaxGas: ag.ConsensusParams.Block.MaxGas, - }, - Evidence: cmttypes.EvidenceParams{ - MaxAgeNumBlocks: ag.ConsensusParams.Evidence.MaxAgeNumBlocks, - MaxAgeDuration: ag.ConsensusParams.Evidence.MaxAgeDuration, - MaxBytes: ag.ConsensusParams.Evidence.MaxBytes, - }, - Validator: cmttypes.ValidatorParams{ - PubKeyTypes: ag.ConsensusParams.Validator.PubKeyTypes, - }, - } - } - - return &cmttypes.GenesisDoc{ - GenesisTime: ag.GenesisTime, - ChainID: ag.ChainID, - InitialHeight: ag.InitialHeight, - AppHash: ag.AppHash, - AppState: ag.AppState, - ConsensusParams: consensusParams, - Validators: ag.Validators, - }, nil -} - -// SaveAs is a utility method for saving AppGenesis as a JSON file. -func (ag *AppGenesis) SaveAs(file string) error { - appGenesisBytes, err := json.MarshalIndent(ag, "", " ") - if err != nil { - return err - } - - return os.WriteFile(file, appGenesisBytes, 0o600) -} - // ValidateAndComplete performs validation and completes the AppGenesis. func (ag *AppGenesis) ValidateAndComplete() error { if ag.ChainID == "" { @@ -109,27 +68,26 @@ func (ag *AppGenesis) ValidateAndComplete() error { ag.GenesisTime = cmttime.Now() } - // verify that consesus and validators parameters are valid for CometBFT - // TODO eventually generalize this for every consensus engine - cmtGenesis, err := ag.ToCometBFTGenesisDoc() - if err != nil { + if err := ag.Consensus.ValidateAndComplete(); err != nil { return err } - if err := cmtGenesis.ValidateAndComplete(); err != nil { + return nil +} + +// SaveAs is a utility method for saving AppGenesis as a JSON file. +func (ag *AppGenesis) SaveAs(file string) error { + appGenesisBytes, err := json.MarshalIndent(ag, "", " ") + if err != nil { return err } - ag.Validators = cmtGenesis.Validators - consensusParams := cmtGenesis.ConsensusParams.ToProto() - ag.ConsensusParams = &consensusParams - - return nil + return os.WriteFile(file, appGenesisBytes, 0o600) } // AppGenesisFromFile reads the AppGenesis from the provided file. func AppGenesisFromFile(genFile string) (*AppGenesis, error) { - jsonBlob, err := os.ReadFile(genFile) //nolint:gosec + jsonBlob, err := os.ReadFile(genFile) if err != nil { return nil, fmt.Errorf("couldn't read AppGenesis file (%s): %w", genFile, err) } @@ -139,20 +97,111 @@ func AppGenesisFromFile(genFile string) (*AppGenesis, error) { // fallback to CometBFT genesis var ctmGenesis cmttypes.GenesisDoc if err2 := cmtjson.Unmarshal(jsonBlob, &ctmGenesis); err2 != nil { - return nil, fmt.Errorf("error unmarshalling AppGenesis at %s: %w and failed fallback to CometBFT GenDoc: %w", genFile, err, err2) + return nil, fmt.Errorf("error unmarshalling AppGenesis at %s: %w\n failed fallback to CometBFT GenDoc: %w", genFile, err, err2) } - consensusParams := ctmGenesis.ConsensusParams.ToProto() appGenesis = AppGenesis{ - GenesisTime: ctmGenesis.GenesisTime, - ChainID: ctmGenesis.ChainID, - InitialHeight: ctmGenesis.InitialHeight, - AppHash: ctmGenesis.AppHash, - AppState: ctmGenesis.AppState, - Validators: ctmGenesis.Validators, - ConsensusParams: &consensusParams, + GenesisTime: ctmGenesis.GenesisTime, + ChainID: ctmGenesis.ChainID, + InitialHeight: ctmGenesis.InitialHeight, + AppHash: ctmGenesis.AppHash, + AppState: ctmGenesis.AppState, + Consensus: &ConsensusGenesis{ + Validators: ctmGenesis.Validators, + Params: ctmGenesis.ConsensusParams, + }, } } return &appGenesis, nil } + +// -------------------------- +// CometBFT Genesis Handling +// -------------------------- + +// ToGenesisDoc converts the AppGenesis to a CometBFT GenesisDoc. +func (ag *AppGenesis) ToGenesisDoc() (*cmttypes.GenesisDoc, error) { + return &cmttypes.GenesisDoc{ + GenesisTime: ag.GenesisTime, + ChainID: ag.ChainID, + InitialHeight: ag.InitialHeight, + AppHash: ag.AppHash, + AppState: ag.AppState, + Validators: ag.Consensus.Validators, + ConsensusParams: ag.Consensus.Params, + }, nil +} + +// ConsensusGenesis defines the consensus layer's genesis. +// TODO(@julienrbrt) eventually abstract from CometBFT types +type ConsensusGenesis struct { + Validators []cmttypes.GenesisValidator `json:"validators,omitempty"` + Params *cmttypes.ConsensusParams `json:"params,omitempty"` +} + +// NewConsensusGenesis returns a ConsensusGenesis with given values. +// It takes a proto consensus params so it can called from server export command. +func NewConsensusGenesis(params *cmtproto.ConsensusParams, validators []cmttypes.GenesisValidator) *ConsensusGenesis { + return &ConsensusGenesis{ + Params: &cmttypes.ConsensusParams{ + Block: cmttypes.BlockParams{ + MaxBytes: params.Block.MaxBytes, + MaxGas: params.Block.MaxGas, + }, + Evidence: cmttypes.EvidenceParams{ + MaxAgeNumBlocks: params.Evidence.MaxAgeNumBlocks, + MaxAgeDuration: params.Evidence.MaxAgeDuration, + MaxBytes: params.Evidence.MaxBytes, + }, + Validator: cmttypes.ValidatorParams{ + PubKeyTypes: params.Validator.PubKeyTypes, + }, + }, + Validators: validators, + } +} + +func (cs *ConsensusGenesis) MarshalJSON() ([]byte, error) { + type Alias ConsensusGenesis + return cmtjson.Marshal(&Alias{ + Validators: cs.Validators, + Params: cs.Params, + }) +} + +func (cs *ConsensusGenesis) UnmarshalJSON(b []byte) error { + type Alias ConsensusGenesis + + result := Alias{} + if err := cmtjson.Unmarshal(b, &result); err != nil { + return err + } + + cs.Params = result.Params + cs.Validators = result.Validators + + return nil +} + +func (cs *ConsensusGenesis) ValidateAndComplete() error { + if cs.Params == nil { + cs.Params = cmttypes.DefaultConsensusParams() + } else if err := cs.Params.ValidateBasic(); err != nil { + return err + } + + for i, v := range cs.Validators { + if v.Power == 0 { + return fmt.Errorf("the genesis file cannot contain validators with no voting power: %v", v) + } + if len(v.Address) > 0 && !bytes.Equal(v.PubKey.Address(), v.Address) { + return fmt.Errorf("incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address()) + } + if len(v.Address) == 0 { + cs.Validators[i].Address = v.PubKey.Address() + } + } + + return nil +} diff --git a/x/genutil/types/genesis_test.go b/x/genutil/types/genesis_test.go index 59547ab0b28..9f0d14743fc 100644 --- a/x/genutil/types/genesis_test.go +++ b/x/genutil/types/genesis_test.go @@ -2,6 +2,7 @@ package types_test import ( "encoding/json" + "os" "testing" "gotest.tools/v3/assert" @@ -11,8 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil/types" ) -var expectedAppGenesisJSON = `{"app_name":"simapp","app_version":"0.1.0","genesis_time":"0001-01-01T00:00:00Z","chain_id":"test","initial_height":0,"app_hash":null}` - func TestAppGenesis_Marshal(t *testing.T) { genesis := types.AppGenesis{ AppName: "simapp", @@ -22,30 +21,31 @@ func TestAppGenesis_Marshal(t *testing.T) { out, err := json.Marshal(&genesis) assert.NilError(t, err) - - assert.Equal(t, string(out), expectedAppGenesisJSON) + assert.Equal(t, string(out), `{"app_name":"simapp","app_version":"0.1.0","genesis_time":"0001-01-01T00:00:00Z","chain_id":"test","initial_height":0,"app_hash":null,"consensus":{}}`) } func TestAppGenesis_Unmarshal(t *testing.T) { + jsonBlob, err := os.ReadFile("testdata/app_genesis.json") + assert.NilError(t, err) + var genesis types.AppGenesis - err := json.Unmarshal([]byte(expectedAppGenesisJSON), &genesis) + err = json.Unmarshal(jsonBlob, &genesis) assert.NilError(t, err) - assert.DeepEqual(t, genesis.AppName, "simapp") - assert.DeepEqual(t, genesis.AppVersion, "0.1.0") - assert.DeepEqual(t, genesis.ChainID, "test") + assert.DeepEqual(t, genesis.ChainID, "demo") + assert.DeepEqual(t, genesis.Consensus.Params.Block.MaxBytes, int64(22020096)) } -func TestAppGenesis_ValidCometBFTGenesis(t *testing.T) { +func TestAppGenesis_ValidGenesis(t *testing.T) { // validate can read cometbft genesis file genesis, err := types.AppGenesisFromFile("testdata/cmt_genesis.json") assert.NilError(t, err) assert.DeepEqual(t, genesis.ChainID, "demo") - assert.DeepEqual(t, genesis.Validators[0].Name, "test") + assert.DeepEqual(t, genesis.Consensus.Validators[0].Name, "test") // validate the app genesis can be translated properly to cometbft genesis - cmtGenesis, err := genesis.ToCometBFTGenesisDoc() + cmtGenesis, err := genesis.ToGenesisDoc() assert.NilError(t, err) rawCmtGenesis, err := cmttypes.GenesisDocFromFile("testdata/cmt_genesis.json") assert.NilError(t, err) @@ -55,4 +55,15 @@ func TestAppGenesis_ValidCometBFTGenesis(t *testing.T) { rawAppGenesis, err := json.Marshal(&genesis) assert.NilError(t, err) golden.Assert(t, string(rawAppGenesis), "app_genesis.json") + + // validate the app genesis can be unmarshalled properly + var appGenesis types.AppGenesis + err = json.Unmarshal(rawAppGenesis, &appGenesis) + assert.NilError(t, err) + assert.DeepEqual(t, appGenesis.Consensus.Params, genesis.Consensus.Params) + + // validate marshalling of app genesis + rawAppGenesis, err = json.Marshal(&appGenesis) + assert.NilError(t, err) + golden.Assert(t, string(rawAppGenesis), "app_genesis.json") } diff --git a/x/genutil/types/testdata/app_genesis.json b/x/genutil/types/testdata/app_genesis.json index ae6fc67006e..450a8f27817 100644 --- a/x/genutil/types/testdata/app_genesis.json +++ b/x/genutil/types/testdata/app_genesis.json @@ -1 +1 @@ -{"app_name":"","app_version":"","genesis_time":"2023-02-20T11:08:30.588307671Z","chain_id":"demo","initial_height":48,"app_hash":"","app_state":{"auth":{"accounts":[{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"1","address":"cosmos1qmkksxlxqdslq6kkca25m4jn344nx29lytq8f9","pub_key":null,"sequence":"0"},{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"8","address":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8","pub_key":null,"sequence":"0"},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"4","address":"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh","pub_key":null,"sequence":"0"},"name":"bonded_tokens_pool","permissions":["burner","staking"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"5","address":"cosmos1tygms3xhhs3yv487phx3dw4a95jn7t7lpm470r","pub_key":null,"sequence":"0"},"name":"not_bonded_tokens_pool","permissions":["burner","staking"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"6","address":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","pub_key":null,"sequence":"0"},"name":"gov","permissions":["burner"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"3","address":"cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl","pub_key":null,"sequence":"0"},"name":"distribution","permissions":[]},{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"0","address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","pub_key":{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A3uyZdXedyvYx9VCL6xRjkxtcFpgxjhXFIz9b2mWz+aV"},"sequence":"4"},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"7","address":"cosmos1m3h30wlvsf8llruxtpukdvsy0km2kum8g38c8q","pub_key":null,"sequence":"0"},"name":"mint","permissions":["minter"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"2","address":"cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta","pub_key":null,"sequence":"0"},"name":"fee_collector","permissions":[]}],"params":{"max_memo_characters":"256","sig_verify_cost_ed25519":"590","sig_verify_cost_secp256k1":"1000","tx_sig_limit":"7","tx_size_cost_per_byte":"10"}},"authz":{"authorization":[]},"bank":{"balances":[{"address":"cosmos1qmkksxlxqdslq6kkca25m4jn344nx29lytq8f9","coins":[{"amount":"5000000000","denom":"stake"}]},{"address":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8","coins":[{"amount":"1000","denom":"stake"}]},{"address":"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh","coins":[{"amount":"1000000","denom":"stake"}]},{"address":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","coins":[{"amount":"10010000","denom":"stake"}]},{"address":"cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl","coins":[{"amount":"9635","denom":"stake"}]},{"address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","coins":[{"amount":"4988989000","denom":"stake"}]}],"denom_metadata":[],"params":{"default_send_enabled":true,"send_enabled":[]},"send_enabled":[],"supply":[{"amount":"10000009635","denom":"stake"}]},"capability":{"index":"1","owners":[]},"consensus":null,"crisis":{"constant_fee":{"amount":"1000","denom":"stake"}},"distribution":{"delegator_starting_infos":[{"delegator_address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","starting_info":{"height":"0","previous_period":"1","stake":"1000000.000000000000000000"},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"delegator_withdraw_infos":[],"fee_pool":{"community_pool":[{"amount":"192.700000000000000000","denom":"stake"}]},"outstanding_rewards":[{"outstanding_rewards":[{"amount":"9442.300000000000000000","denom":"stake"}],"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"params":{"base_proposer_reward":"0.000000000000000000","bonus_proposer_reward":"0.000000000000000000","community_tax":"0.020000000000000000","withdraw_addr_enabled":true},"previous_proposer":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","validator_accumulated_commissions":[{"accumulated":{"commission":[{"amount":"944.230000000000000000","denom":"stake"}]},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_current_rewards":[{"rewards":{"period":"2","rewards":[{"amount":"8498.070000000000000000","denom":"stake"}]},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_historical_rewards":[{"period":"1","rewards":{"cumulative_reward_ratio":[],"reference_count":2},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_slash_events":[]},"evidence":{"evidence":[]},"feegrant":{"allowances":[]},"genutil":{"gen_txs":[]},"gov":{"deposit_params":null,"deposits":[{"amount":[{"amount":"10010000","denom":"stake"}],"depositor":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","proposal_id":"1"}],"params":{"expedited_min_deposit":[{"amount":"50000000","denom":"stake"}],"expedited_threshold":"0.667000000000000000","expedited_voting_period":"86400s","max_deposit_period":"172800s","min_deposit":[{"amount":"10000000","denom":"stake"}],"min_initial_deposit_ratio":"0.000000000000000000","proposal_cancel_dest":"","proposal_cancel_ratio":"0.500000000000000000","quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000","voting_period":"172800s"},"proposals":[{"deposit_end_time":"2023-02-22T11:11:52.776167376Z","expedited":false,"final_tally_result":{"abstain_count":"0","no_count":"0","no_with_veto_count":"0","yes_count":"0"},"id":"1","messages":[{"@type":"/cosmos.distribution.v1beta1.MsgCommunityPoolSpend","amount":[],"authority":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","recipient":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8"}],"metadata":"ipfs://CID","proposer":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","status":"PROPOSAL_STATUS_VOTING_PERIOD","submit_time":"2023-02-20T11:11:52.776167376Z","summary":"test proposal","title":"test proposal","total_deposit":[{"amount":"10010000","denom":"stake"}],"voting_end_time":"2023-02-22T11:12:07.801161984Z","voting_start_time":"2023-02-20T11:12:07.801161984Z"}],"starting_proposal_id":"2","tally_params":null,"votes":[],"voting_params":null},"group":{"group_members":[],"group_policies":[],"group_policy_seq":"0","group_seq":"0","groups":[],"proposal_seq":"0","proposals":[],"votes":[]},"mint":{"minter":{"annual_provisions":"1300010905.175073197786747950","inflation":"0.130000967926594565"},"params":{"blocks_per_year":"6311520","goal_bonded":"0.670000000000000000","inflation_max":"0.200000000000000000","inflation_min":"0.070000000000000000","inflation_rate_change":"0.130000000000000000","mint_denom":"stake"}},"nft":{"classes":[],"entries":[]},"params":null,"slashing":{"missed_blocks":[{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","missed_blocks":[]}],"params":{"downtime_jail_duration":"600s","min_signed_per_window":"0.500000000000000000","signed_blocks_window":"100","slash_fraction_double_sign":"0.050000000000000000","slash_fraction_downtime":"0.010000000000000000"},"signing_infos":[{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","validator_signing_info":{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","index_offset":"46","jailed_until":"1970-01-01T00:00:00Z","missed_blocks_counter":"0","start_height":"0","tombstoned":false}}]},"staking":{"delegations":[{"delegator_address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","shares":"1000000.000000000000000000","validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"exported":true,"last_total_power":"1","last_validator_powers":[{"address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp","power":"1"}],"params":{"bond_denom":"stake","historical_entries":10000,"max_entries":7,"max_validators":100,"min_commission_rate":"0.000000000000000000","unbonding_time":"1814400s"},"redelegations":[],"unbonding_delegations":[],"validators":[{"commission":{"commission_rates":{"max_change_rate":"0.010000000000000000","max_rate":"0.200000000000000000","rate":"0.100000000000000000"},"update_time":"2023-02-20T11:08:30.588307671Z"},"consensus_pubkey":{"@type":"/cosmos.crypto.ed25519.PubKey","key":"tMZonPQYoooG/xbFVhHg95pTLxx7aO43/qgHFxDagWM="},"delegator_shares":"1000000.000000000000000000","description":{"details":"","identity":"","moniker":"test","security_contact":"","website":""},"jailed":false,"min_self_delegation":"1","operator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp","status":"BOND_STATUS_BONDED","tokens":"1000000","unbonding_height":"0","unbonding_ids":[],"unbonding_on_hold_ref_count":"0","unbonding_time":"1970-01-01T00:00:00Z"}]},"upgrade":{},"vesting":{}},"validators":[{"address":"D336F99AA5CF77503CDD8366E68A0DFE89B4124B","pub_key":"tMZonPQYoooG/xbFVhHg95pTLxx7aO43/qgHFxDagWM=","power":1,"name":"test"}],"consensus_params":{"block":{"max_bytes":22020096,"max_gas":-1},"evidence":{"max_age_num_blocks":100000,"max_age_duration":172800000000000,"max_bytes":1048576},"validator":{"pub_key_types":["ed25519"]},"version":{}}} \ No newline at end of file +{"app_name":"","app_version":"","genesis_time":"2023-02-20T11:08:30.588307671Z","chain_id":"demo","initial_height":48,"app_hash":"","app_state":{"auth":{"accounts":[{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"1","address":"cosmos1qmkksxlxqdslq6kkca25m4jn344nx29lytq8f9","pub_key":null,"sequence":"0"},{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"8","address":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8","pub_key":null,"sequence":"0"},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"4","address":"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh","pub_key":null,"sequence":"0"},"name":"bonded_tokens_pool","permissions":["burner","staking"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"5","address":"cosmos1tygms3xhhs3yv487phx3dw4a95jn7t7lpm470r","pub_key":null,"sequence":"0"},"name":"not_bonded_tokens_pool","permissions":["burner","staking"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"6","address":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","pub_key":null,"sequence":"0"},"name":"gov","permissions":["burner"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"3","address":"cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl","pub_key":null,"sequence":"0"},"name":"distribution","permissions":[]},{"@type":"/cosmos.auth.v1beta1.BaseAccount","account_number":"0","address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","pub_key":{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A3uyZdXedyvYx9VCL6xRjkxtcFpgxjhXFIz9b2mWz+aV"},"sequence":"4"},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"7","address":"cosmos1m3h30wlvsf8llruxtpukdvsy0km2kum8g38c8q","pub_key":null,"sequence":"0"},"name":"mint","permissions":["minter"]},{"@type":"/cosmos.auth.v1beta1.ModuleAccount","base_account":{"account_number":"2","address":"cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta","pub_key":null,"sequence":"0"},"name":"fee_collector","permissions":[]}],"params":{"max_memo_characters":"256","sig_verify_cost_ed25519":"590","sig_verify_cost_secp256k1":"1000","tx_sig_limit":"7","tx_size_cost_per_byte":"10"}},"authz":{"authorization":[]},"bank":{"balances":[{"address":"cosmos1qmkksxlxqdslq6kkca25m4jn344nx29lytq8f9","coins":[{"amount":"5000000000","denom":"stake"}]},{"address":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8","coins":[{"amount":"1000","denom":"stake"}]},{"address":"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh","coins":[{"amount":"1000000","denom":"stake"}]},{"address":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","coins":[{"amount":"10010000","denom":"stake"}]},{"address":"cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl","coins":[{"amount":"9635","denom":"stake"}]},{"address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","coins":[{"amount":"4988989000","denom":"stake"}]}],"denom_metadata":[],"params":{"default_send_enabled":true,"send_enabled":[]},"send_enabled":[],"supply":[{"amount":"10000009635","denom":"stake"}]},"capability":{"index":"1","owners":[]},"consensus":null,"crisis":{"constant_fee":{"amount":"1000","denom":"stake"}},"distribution":{"delegator_starting_infos":[{"delegator_address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","starting_info":{"height":"0","previous_period":"1","stake":"1000000.000000000000000000"},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"delegator_withdraw_infos":[],"fee_pool":{"community_pool":[{"amount":"192.700000000000000000","denom":"stake"}]},"outstanding_rewards":[{"outstanding_rewards":[{"amount":"9442.300000000000000000","denom":"stake"}],"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"params":{"base_proposer_reward":"0.000000000000000000","bonus_proposer_reward":"0.000000000000000000","community_tax":"0.020000000000000000","withdraw_addr_enabled":true},"previous_proposer":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","validator_accumulated_commissions":[{"accumulated":{"commission":[{"amount":"944.230000000000000000","denom":"stake"}]},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_current_rewards":[{"rewards":{"period":"2","rewards":[{"amount":"8498.070000000000000000","denom":"stake"}]},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_historical_rewards":[{"period":"1","rewards":{"cumulative_reward_ratio":[],"reference_count":2},"validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"validator_slash_events":[]},"evidence":{"evidence":[]},"feegrant":{"allowances":[]},"genutil":{"gen_txs":[]},"gov":{"deposit_params":null,"deposits":[{"amount":[{"amount":"10010000","denom":"stake"}],"depositor":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","proposal_id":"1"}],"params":{"expedited_min_deposit":[{"amount":"50000000","denom":"stake"}],"expedited_threshold":"0.667000000000000000","expedited_voting_period":"86400s","max_deposit_period":"172800s","min_deposit":[{"amount":"10000000","denom":"stake"}],"min_initial_deposit_ratio":"0.000000000000000000","proposal_cancel_dest":"","proposal_cancel_ratio":"0.500000000000000000","quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000","voting_period":"172800s"},"proposals":[{"deposit_end_time":"2023-02-22T11:11:52.776167376Z","expedited":false,"final_tally_result":{"abstain_count":"0","no_count":"0","no_with_veto_count":"0","yes_count":"0"},"id":"1","messages":[{"@type":"/cosmos.distribution.v1beta1.MsgCommunityPoolSpend","amount":[],"authority":"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","recipient":"cosmos1pnt5523etwtzv6mj7haryfw6w8h5tkcuhd99m8"}],"metadata":"ipfs://CID","proposer":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","status":"PROPOSAL_STATUS_VOTING_PERIOD","submit_time":"2023-02-20T11:11:52.776167376Z","summary":"test proposal","title":"test proposal","total_deposit":[{"amount":"10010000","denom":"stake"}],"voting_end_time":"2023-02-22T11:12:07.801161984Z","voting_start_time":"2023-02-20T11:12:07.801161984Z"}],"starting_proposal_id":"2","tally_params":null,"votes":[],"voting_params":null},"group":{"group_members":[],"group_policies":[],"group_policy_seq":"0","group_seq":"0","groups":[],"proposal_seq":"0","proposals":[],"votes":[]},"mint":{"minter":{"annual_provisions":"1300010905.175073197786747950","inflation":"0.130000967926594565"},"params":{"blocks_per_year":"6311520","goal_bonded":"0.670000000000000000","inflation_max":"0.200000000000000000","inflation_min":"0.070000000000000000","inflation_rate_change":"0.130000000000000000","mint_denom":"stake"}},"nft":{"classes":[],"entries":[]},"params":null,"slashing":{"missed_blocks":[{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","missed_blocks":[]}],"params":{"downtime_jail_duration":"600s","min_signed_per_window":"0.500000000000000000","signed_blocks_window":"100","slash_fraction_double_sign":"0.050000000000000000","slash_fraction_downtime":"0.010000000000000000"},"signing_infos":[{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","validator_signing_info":{"address":"cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr","index_offset":"46","jailed_until":"1970-01-01T00:00:00Z","missed_blocks_counter":"0","start_height":"0","tombstoned":false}}]},"staking":{"delegations":[{"delegator_address":"cosmos15jenkldw6348lpgdev3vjzw90zzknxa9a3vg0j","shares":"1000000.000000000000000000","validator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp"}],"exported":true,"last_total_power":"1","last_validator_powers":[{"address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp","power":"1"}],"params":{"bond_denom":"stake","historical_entries":10000,"max_entries":7,"max_validators":100,"min_commission_rate":"0.000000000000000000","unbonding_time":"1814400s"},"redelegations":[],"unbonding_delegations":[],"validators":[{"commission":{"commission_rates":{"max_change_rate":"0.010000000000000000","max_rate":"0.200000000000000000","rate":"0.100000000000000000"},"update_time":"2023-02-20T11:08:30.588307671Z"},"consensus_pubkey":{"@type":"/cosmos.crypto.ed25519.PubKey","key":"tMZonPQYoooG/xbFVhHg95pTLxx7aO43/qgHFxDagWM="},"delegator_shares":"1000000.000000000000000000","description":{"details":"","identity":"","moniker":"test","security_contact":"","website":""},"jailed":false,"min_self_delegation":"1","operator_address":"cosmosvaloper15jenkldw6348lpgdev3vjzw90zzknxa9c9carp","status":"BOND_STATUS_BONDED","tokens":"1000000","unbonding_height":"0","unbonding_ids":[],"unbonding_on_hold_ref_count":"0","unbonding_time":"1970-01-01T00:00:00Z"}]},"upgrade":{},"vesting":{}},"consensus":{"validators":[{"address":"D336F99AA5CF77503CDD8366E68A0DFE89B4124B","pub_key":{"type":"tendermint/PubKeyEd25519","value":"tMZonPQYoooG/xbFVhHg95pTLxx7aO43/qgHFxDagWM="},"power":"1","name":"test"}],"params":{"block":{"max_bytes":"22020096","max_gas":"-1"},"evidence":{"max_age_num_blocks":"100000","max_age_duration":"172800000000000","max_bytes":"1048576"},"validator":{"pub_key_types":["ed25519"]},"version":{"app":"0"}}}} \ No newline at end of file diff --git a/x/genutil/utils.go b/x/genutil/utils.go index fcbe8e4ec80..880aa7bdc1c 100644 --- a/x/genutil/utils.go +++ b/x/genutil/utils.go @@ -34,7 +34,7 @@ func ExportGenesisFile(genesis *types.AppGenesis, genFile string) error { func ExportGenesisFileWithTime(genFile, chainID string, validators []cmttypes.GenesisValidator, appState json.RawMessage, genTime time.Time) error { appGenesis := types.NewAppGenesisWithVersion(chainID, appState) appGenesis.GenesisTime = genTime - appGenesis.Validators = validators + appGenesis.Consensus.Validators = validators if err := appGenesis.ValidateAndComplete(); err != nil { return err From 2c72a0fef5646657dfcf9a13eb0038e99f23d26c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Feb 2023 21:40:44 +0100 Subject: [PATCH 21/23] updates --- tests/e2e/genutil/migrate.go | 61 ----------- tests/e2e/genutil/validate_genesis.go | 101 ------------------ tests/e2e/server/export_test.go | 3 + x/genutil/client/cli/init_test.go | 2 +- x/genutil/client/cli/migrate.go | 10 +- x/genutil/client/cli/migrate_test.go | 44 +++++--- x/genutil/client/cli/validate_genesis.go | 23 +--- x/genutil/client/cli/validate_genesis_test.go | 68 ++++-------- x/genutil/types/genesis.go | 4 + 9 files changed, 61 insertions(+), 255 deletions(-) delete mode 100644 tests/e2e/genutil/migrate.go delete mode 100644 tests/e2e/genutil/validate_genesis.go diff --git a/tests/e2e/genutil/migrate.go b/tests/e2e/genutil/migrate.go deleted file mode 100644 index 4a2a7579b54..00000000000 --- a/tests/e2e/genutil/migrate.go +++ /dev/null @@ -1,61 +0,0 @@ -package genutil - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/testutil" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" -) - -func TestGetMigrationCallback(t *testing.T) { - for _, version := range cli.GetMigrationVersions() { - require.NotNil(t, cli.GetMigrationCallback(version)) - } -} - -func (s *E2ETestSuite) TestMigrateGenesis() { - val0 := s.network.Validators[0] - - testCases := []struct { - name string - genesis string - target string - expErr bool - expErrMsg string - check func(jsonOut string) - }{ - { - "migrate 0.37 to 0.42", - v037Exported, - "v0.42", - true, "Make sure that you have correctly migrated all CometBFT consensus params", func(_ string) {}, - }, - { - "migrate 0.42 to 0.43", - v040Valid, - "v0.43", - false, "", - func(jsonOut string) { - // Make sure the json output contains the ADR-037 gov weighted votes. - s.Require().Contains(jsonOut, "\"weight\":\"1.000000000000000000\"") - }, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis) - jsonOutput, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.MigrateGenesisCmd(), []string{tc.target, genesisFile.Name()}) - if tc.expErr { - s.Require().Contains(err.Error(), tc.expErrMsg) - } else { - s.Require().NoError(err) - tc.check(jsonOutput.String()) - } - }) - } -} diff --git a/tests/e2e/genutil/validate_genesis.go b/tests/e2e/genutil/validate_genesis.go deleted file mode 100644 index 5561b0b9d60..00000000000 --- a/tests/e2e/genutil/validate_genesis.go +++ /dev/null @@ -1,101 +0,0 @@ -package genutil - -import ( - "github.com/cosmos/cosmos-sdk/testutil" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" -) - -// An example exported genesis file from a 0.37 chain. Note that evidence -// parameters only contains `max_age`. -var v037Exported = `{ - "app_hash": "", - "app_state": {}, - "chain_id": "test", - "consensus_params": { - "block": { - "max_bytes": "22020096", - "max_gas": "-1", - "time_iota_ms": "1000" - }, - "evidence": { "max_age": "100000" }, - "validator": { "pub_key_types": ["ed25519"] } - }, - "genesis_time": "2020-09-29T20:16:29.172362037Z", - "validators": [] -}` - -// An example exported genesis file that's 0.40 compatible. -// We added the following app_state: -// -// - x/gov: added votes to test ADR-037 split votes migration. -var v040Valid = `{ - "app_hash": "", - "app_state": { - "gov": { - "starting_proposal_id": "0", - "deposits": [], - "votes": [ - { - "proposal_id": "5", - "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh", - "option": "VOTE_OPTION_YES" - } - ], - "proposals": [], - "deposit_params": { "min_deposit": [], "max_deposit_period": "0s" }, - "voting_params": { "voting_period": "0s" }, - "tally_params": { "quorum": "0", "threshold": "0", "veto_threshold": "0" } - } - }, - "chain_id": "test", - "consensus_params": { - "block": { - "max_bytes": "22020096", - "max_gas": "-1", - "time_iota_ms": "1000" - }, - "evidence": { - "max_age_num_blocks": "100000", - "max_age_duration": "172800000000000", - "max_bytes": "0" - }, - "validator": { "pub_key_types": ["ed25519"] } - }, - "genesis_time": "2020-09-29T20:16:29.172362037Z", - "validators": [] -}` - -func (s *E2ETestSuite) TestValidateGenesis() { - val0 := s.network.Validators[0] - - testCases := []struct { - name string - genesis string - expErr bool - }{ - { - "exported 0.37 genesis file", - v037Exported, - true, - }, - { - "valid 0.40 genesis file", - v040Valid, - false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis) - _, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.ValidateGenesisCmd(nil), []string{genesisFile.Name()}) - if tc.expErr { - s.Require().Contains(err.Error(), "Make sure that you have correctly migrated all CometBFT consensus params") - } else { - s.Require().NoError(err) - } - }) - } -} diff --git a/tests/e2e/server/export_test.go b/tests/e2e/server/export_test.go index f8a97f9316c..11f2a190abc 100644 --- a/tests/e2e/server/export_test.go +++ b/tests/e2e/server/export_test.go @@ -1,3 +1,6 @@ +//go:build e2e +// +build e2e + package server_test import ( diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index af610bff004..551ccb882a4 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -193,7 +193,7 @@ func TestEmptyState(t *testing.T) { require.Contains(t, out, "genesis_time") require.Contains(t, out, "chain_id") - require.Contains(t, out, "consensus_params") + require.Contains(t, out, "consensus") require.Contains(t, out, "app_hash") require.Contains(t, out, "app_state") } diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index 9e7a28a1a68..6ab54b8e968 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -66,8 +66,8 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 return err } - if err := validateGenDoc(appGenesis); err != nil { - return err + if err := appGenesis.ValidateAndComplete(); err != nil { + return fmt.Errorf("make sure that you have correctly migrated all CometBFT consensus params. Refer the UPGRADING.md (%s): %w", chainUpgradeGuide, err) } // Since some default values are valid values, we just print to @@ -124,11 +124,7 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 return nil } - var exportedAppGenesis types.AppGenesis - if err = json.Unmarshal(bz, &exportedAppGenesis); err != nil { - return err - } - if err = exportedAppGenesis.SaveAs(outputDocument); err != nil { + if err = appGenesis.SaveAs(outputDocument); err != nil { return err } diff --git a/x/genutil/client/cli/migrate_test.go b/x/genutil/client/cli/migrate_test.go index fa60f80cd57..9a569a8b6ed 100644 --- a/x/genutil/client/cli/migrate_test.go +++ b/x/genutil/client/cli/migrate_test.go @@ -1,10 +1,12 @@ package cli_test import ( + "os" "testing" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" @@ -16,7 +18,7 @@ func TestGetMigrationCallback(t *testing.T) { } } -func (s *CLITestSuite) TestMigrateGenesis() { +func TestMigrateGenesis(t *testing.T) { testCases := []struct { name string genesis string @@ -29,29 +31,41 @@ func (s *CLITestSuite) TestMigrateGenesis() { "migrate 0.37 to 0.42", v037Exported, "v0.42", - true, "Make sure that you have correctly migrated all CometBFT consensus params", func(_ string) {}, + true, "make sure that you have correctly migrated all CometBFT consensus params", func(_ string) {}, }, { - "migrate 0.42 to 0.43", - v040Valid, - "v0.43", - false, "", - func(jsonOut string) { - // Make sure the json output contains the ADR-037 gov weighted votes. - s.Require().Contains(jsonOut, "\"weight\":\"1.000000000000000000\"") - }, + "invalid target version", + func() string { + bz, err := os.ReadFile("../../types/testdata/app_genesis.json") + require.NoError(t, err) + + return string(bz) + }(), + "v0.10", + true, "unknown migration function for version: v0.10", func(_ string) {}, + }, + { + "invalid target version", + func() string { + bz, err := os.ReadFile("../../types/testdata/cmt_genesis.json") + require.NoError(t, err) + + return string(bz) + }(), + "v0.10", + true, "unknown migration function for version: v0.10", func(_ string) {}, }, } for _, tc := range testCases { tc := tc - s.Run(tc.name, func() { - genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis) - jsonOutput, err := clitestutil.ExecTestCLICmd(s.clientCtx, cli.MigrateGenesisCmd(), []string{tc.target, genesisFile.Name()}) + t.Run(tc.name, func(t *testing.T) { + genesisFile := testutil.WriteToNewTempFile(t, tc.genesis) + jsonOutput, err := clitestutil.ExecTestCLICmd(client.Context{}, cli.MigrateGenesisCmd(), []string{tc.target, genesisFile.Name()}) if tc.expErr { - s.Require().Contains(err.Error(), tc.expErrMsg) + require.Contains(t, err.Error(), tc.expErrMsg) } else { - s.Require().NoError(err) + require.NoError(t, err) tc.check(jsonOutput.String()) } }) diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 2565bc0c739..a565a37f368 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -40,8 +40,8 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { return err } - if err := validateGenDoc(appGenesis); err != nil { - return err + if err := appGenesis.ValidateAndComplete(); err != nil { + return fmt.Errorf("make sure that you have correctly migrated all CometBFT consensus params. Refer the UPGRADING.md (%s): %w", chainUpgradeGuide, err) } var genState map[string]json.RawMessage @@ -58,22 +58,3 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { }, } } - -// validateGenDoc reads a genesis file and validates that it is a correct -// CometBFT GenesisDoc. This function does not do any cosmos-related -// validation. -func validateGenDoc(appGenesis *types.AppGenesis) error { - genDoc, err := appGenesis.ToGenesisDoc() - if err != nil { - return err - } - - if err := genDoc.ValidateAndComplete(); err != nil { - return fmt.Errorf("%w. Make sure that"+ - " you have correctly migrated all CometBFT consensus params, please see the"+ - " chain migration guide at %s for more info", - err, chainUpgradeGuide) - } - - return nil -} diff --git a/x/genutil/client/cli/validate_genesis_test.go b/x/genutil/client/cli/validate_genesis_test.go index 90223ea45f6..a241bf1f9b9 100644 --- a/x/genutil/client/cli/validate_genesis_test.go +++ b/x/genutil/client/cli/validate_genesis_test.go @@ -1,9 +1,14 @@ package cli_test import ( + "os" + "testing" + + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + "github.com/stretchr/testify/require" ) // An example exported genesis file from a 0.37 chain. Note that evidence @@ -25,48 +30,7 @@ var v037Exported = `{ "validators": [] }` -// An example exported genesis file that's 0.40 compatible. -// We added the following app_state: -// -// - x/gov: added votes to test ADR-037 split votes migration. -var v040Valid = `{ - "app_hash": "", - "app_state": { - "gov": { - "starting_proposal_id": "0", - "deposits": [], - "votes": [ - { - "proposal_id": "5", - "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh", - "option": "VOTE_OPTION_YES" - } - ], - "proposals": [], - "deposit_params": { "min_deposit": [], "max_deposit_period": "0s" }, - "voting_params": { "voting_period": "0s" }, - "tally_params": { "quorum": "0", "threshold": "0", "veto_threshold": "0" } - } - }, - "chain_id": "test", - "consensus_params": { - "block": { - "max_bytes": "22020096", - "max_gas": "-1", - "time_iota_ms": "1000" - }, - "evidence": { - "max_age_num_blocks": "100000", - "max_age_duration": "172800000000000", - "max_bytes": "0" - }, - "validator": { "pub_key_types": ["ed25519"] } - }, - "genesis_time": "2020-09-29T20:16:29.172362037Z", - "validators": [] -}` - -func (s *CLITestSuite) TestValidateGenesis() { +func TestValidateGenesis(t *testing.T) { testCases := []struct { name string genesis string @@ -78,21 +42,27 @@ func (s *CLITestSuite) TestValidateGenesis() { true, }, { - "valid 0.40 genesis file", - v040Valid, + "valid 0.48 genesis file", + func() string { + bz, err := os.ReadFile("../../types/testdata/app_genesis.json") + require.NoError(t, err) + + return string(bz) + }(), false, }, } for _, tc := range testCases { tc := tc - s.Run(tc.name, func() { - genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis) - _, err := clitestutil.ExecTestCLICmd(s.clientCtx, cli.ValidateGenesisCmd(nil), []string{genesisFile.Name()}) + + t.Run(tc.name, func(t *testing.T) { + genesisFile := testutil.WriteToNewTempFile(t, tc.genesis) + _, err := clitestutil.ExecTestCLICmd(client.Context{}, cli.ValidateGenesisCmd(nil), []string{genesisFile.Name()}) if tc.expErr { - s.Require().Contains(err.Error(), "Make sure that you have correctly migrated all CometBFT consensus params") + require.Contains(t, err.Error(), "make sure that you have correctly migrated all CometBFT consensus params") } else { - s.Require().NoError(err) + require.NoError(t, err) } }) } diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index ed07ccdc990..ffd601d2b70 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -185,6 +185,10 @@ func (cs *ConsensusGenesis) UnmarshalJSON(b []byte) error { } func (cs *ConsensusGenesis) ValidateAndComplete() error { + if cs == nil { + return fmt.Errorf("consensus genesis cannot be nil") + } + if cs.Params == nil { cs.Params = cmttypes.DefaultConsensusParams() } else if err := cs.Params.ValidateBasic(); err != nil { From 1fe618965d9559d4b48193a4b6e33ad92b7d26f2 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Feb 2023 21:41:30 +0100 Subject: [PATCH 22/23] remove e2e genutil --- tests/e2e/genutil/cli_test.go | 19 ----- tests/e2e/genutil/suite.go | 143 ---------------------------------- 2 files changed, 162 deletions(-) delete mode 100644 tests/e2e/genutil/cli_test.go delete mode 100644 tests/e2e/genutil/suite.go diff --git a/tests/e2e/genutil/cli_test.go b/tests/e2e/genutil/cli_test.go deleted file mode 100644 index ad7c8dfc367..00000000000 --- a/tests/e2e/genutil/cli_test.go +++ /dev/null @@ -1,19 +0,0 @@ -//go:build e2e -// +build e2e - -package genutil - -import ( - "testing" - - "cosmossdk.io/simapp" - "github.com/cosmos/cosmos-sdk/testutil/network" - - "github.com/stretchr/testify/suite" -) - -func TestE2ETestSuite(t *testing.T) { - cfg := network.DefaultConfig(simapp.NewTestNetworkFixture) - cfg.NumValidators = 1 - suite.Run(t, NewE2ETestSuite(cfg)) -} diff --git a/tests/e2e/genutil/suite.go b/tests/e2e/genutil/suite.go deleted file mode 100644 index 882f63dbc26..00000000000 --- a/tests/e2e/genutil/suite.go +++ /dev/null @@ -1,143 +0,0 @@ -package genutil - -import ( - "fmt" - "io" - "os" - "path/filepath" - - "github.com/stretchr/testify/suite" - - "github.com/cosmos/cosmos-sdk/client/flags" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/cosmos/cosmos-sdk/testutil/network" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli" - "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -type E2ETestSuite struct { - suite.Suite - - cfg network.Config - network *network.Network -} - -func NewE2ETestSuite(cfg network.Config) *E2ETestSuite { - return &E2ETestSuite{cfg: cfg} -} - -func (s *E2ETestSuite) SetupSuite() { - s.T().Log("setting up e2e test suite") - - var err error - s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) - s.Require().NoError(err) - - s.Require().NoError(s.network.WaitForNextBlock()) -} - -func (s *E2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suite") - s.network.Cleanup() -} - -func (s *E2ETestSuite) TestGenTxCmd() { - val := s.network.Validators[0] - clientCtx := val.ClientCtx - amount := sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(12)) - - tests := []struct { - name string - args []string - expError bool - }{ - { - name: "invalid commission rate returns error", - args: []string{ - fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID), - fmt.Sprintf("--%s=1", stakingcli.FlagCommissionRate), - val.Moniker, - amount.String(), - }, - expError: true, - }, - { - name: "valid gentx", - args: []string{ - fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID), - val.Moniker, - amount.String(), - }, - expError: false, - }, - { - name: "invalid pubkey", - args: []string{ - fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID), - fmt.Sprintf("--%s={\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"}", stakingcli.FlagPubKey), - val.Moniker, - amount.String(), - }, - expError: true, - }, - { - name: "valid pubkey flag", - args: []string{ - fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID), - fmt.Sprintf("--%s={\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"}", stakingcli.FlagPubKey), - val.Moniker, - amount.String(), - }, - expError: false, - }, - } - - for _, tc := range tests { - tc := tc - - dir := s.T().TempDir() - genTxFile := filepath.Join(dir, "myTx") - tc.args = append(tc.args, fmt.Sprintf("--%s=%s", flags.FlagOutputDocument, genTxFile)) - - s.Run(tc.name, func() { - cmd := cli.GenTxCmd( - module.NewBasicManager(), - val.ClientCtx.TxConfig, - banktypes.GenesisBalancesIterator{}, - val.ClientCtx.HomeDir) - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - - if tc.expError { - s.Require().Error(err) - - _, err = os.Open(genTxFile) - s.Require().Error(err) - } else { - s.Require().NoError(err, "test: %s\noutput: %s", tc.name, out.String()) - - // validate generated transaction. - open, err := os.Open(genTxFile) - s.Require().NoError(err) - - all, err := io.ReadAll(open) - s.Require().NoError(err) - - tx, err := val.ClientCtx.TxConfig.TxJSONDecoder()(all) - s.Require().NoError(err) - - msgs := tx.GetMsgs() - s.Require().Len(msgs, 1) - - s.Require().Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(msgs[0])) - s.Require().True(val.Address.Equals(msgs[0].GetSigners()[0])) - s.Require().Equal(amount, msgs[0].(*types.MsgCreateValidator).Value) - s.Require().NoError(tx.ValidateBasic()) - } - }) - } -} From 2c767bf6a3c2f4bf68ef802ab5f0113b7bd2b568 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 22 Feb 2023 11:06:13 +0100 Subject: [PATCH 23/23] typo --- x/genutil/types/genesis_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/genutil/types/genesis_test.go b/x/genutil/types/genesis_test.go index 9f0d14743fc..811c285cee4 100644 --- a/x/genutil/types/genesis_test.go +++ b/x/genutil/types/genesis_test.go @@ -21,7 +21,7 @@ func TestAppGenesis_Marshal(t *testing.T) { out, err := json.Marshal(&genesis) assert.NilError(t, err) - assert.Equal(t, string(out), `{"app_name":"simapp","app_version":"0.1.0","genesis_time":"0001-01-01T00:00:00Z","chain_id":"test","initial_height":0,"app_hash":null,"consensus":{}}`) + assert.Equal(t, string(out), `{"app_name":"simapp","app_version":"0.1.0","genesis_time":"0001-01-01T00:00:00Z","chain_id":"test","initial_height":0,"app_hash":null}`) } func TestAppGenesis_Unmarshal(t *testing.T) {