Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add application genesis #15031

Merged
merged 35 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f45336f
feat: application genesis
julienrbrt Feb 14, 2023
6f6a96d
updates
julienrbrt Feb 14, 2023
77688ce
wip
julienrbrt Feb 16, 2023
0c520dd
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 16, 2023
95db1bc
updates
julienrbrt Feb 16, 2023
c598670
revert sdk genesis validator
julienrbrt Feb 16, 2023
96e1e3d
updates
julienrbrt Feb 16, 2023
5bdb70d
updates
julienrbrt Feb 16, 2023
3faf425
updates
julienrbrt Feb 16, 2023
39fcba8
updates
julienrbrt Feb 16, 2023
1ae07d5
more revert
julienrbrt Feb 17, 2023
f925b2f
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 17, 2023
5bd8602
updates
julienrbrt Feb 17, 2023
0b66aab
updates
julienrbrt Feb 17, 2023
3360f15
updates
julienrbrt Feb 17, 2023
e188498
updates
julienrbrt Feb 17, 2023
bb242b9
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 18, 2023
cb820c5
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 19, 2023
5407f9d
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 19, 2023
7d4cb65
feedback and fix
julienrbrt Feb 20, 2023
9f83600
better docs
julienrbrt Feb 20, 2023
eb83d6a
add tests
julienrbrt Feb 20, 2023
2f99ca0
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 20, 2023
db55093
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 20, 2023
7f20c2c
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 21, 2023
84394a7
fix merge
julienrbrt Feb 21, 2023
eec5220
updates
julienrbrt Feb 21, 2023
618e845
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 21, 2023
4f6d24f
fix test and have better split logic
julienrbrt Feb 21, 2023
2c72a0f
updates
julienrbrt Feb 21, 2023
1fe6189
remove e2e genutil
julienrbrt Feb 21, 2023
6a51882
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 21, 2023
92c23e9
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 22, 2023
2c767bf
typo
julienrbrt Feb 22, 2023
8957f0f
Merge branch 'main' into julien/app-genesis
julienrbrt Feb 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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{}`.
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
* (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.
Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/genutil/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ message GenesisState {
(amino.field_name) = "gentxs",
(amino.dont_omitempty) = true
];
}
}
44 changes: 10 additions & 34 deletions server/export.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
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 (
FlagHeight = "height"
FlagForZeroHeight = "for-zero-height"
FlagJailAllowedAddrs = "jail-allowed-addrs"
FlagModulesToExport = "modules-to-export"
FlagOutputDocument = "output-document"
)

// ExportCmd dumps app state to JSON.
Expand Down Expand Up @@ -66,58 +64,36 @@ 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 {
return fmt.Errorf("error exporting state: %v", err)
}

doc, err := cmttypes.GenesisDocFromFile(serverCtx.Config.GenesisFile())
appGenesis, err := genutiltypes.AppGenesisFromFile(serverCtx.Config.GenesisFile())
if err != nil {
return err
}

doc.AppState = exported.AppState
doc.Validators = exported.Validators
doc.InitialHeight = exported.Height
doc.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.InitialHeight = exported.Height
appGenesis.Consensus = genutiltypes.NewConsensusGenesis(exported.ConsensusParams, exported.Validators)

// 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)
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))
return nil
}

var exportedGenDoc cmttypes.GenesisDoc
if err = cmtjson.Unmarshal(out, &exportedGenDoc); err != nil {
return err
}
if err = exportedGenDoc.SaveAs(outputDocument); err != nil {
if err = appGenesis.SaveAs(outputDocument); err != nil {
return err
}

Expand All @@ -130,7 +106,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
}
6 changes: 3 additions & 3 deletions server/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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": [
{
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions server/mock/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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{
Expand Down
15 changes: 12 additions & 3 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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.ToGenesisDoc()
}

var (
tmNode *node.Node
Expand Down
19 changes: 7 additions & 12 deletions simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"os"
"path/filepath"

"cosmossdk.io/math"
"cosmossdk.io/math/unsafe"
cmtconfig "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/types"
cmttime "github.com/cometbft/cometbft/types/time"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"cosmossdk.io/math"
"cosmossdk.io/math/unsafe"
"cosmossdk.io/simapp"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand Down Expand Up @@ -391,15 +391,10 @@ func initGenFiles(
return err
}

genDoc := types.GenesisDoc{
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 := genDoc.SaveAs(genFiles[i]); err != nil {
if err := appGenesis.SaveAs(genFiles[i]); err != nil {
return err
}
}
Expand All @@ -425,12 +420,12 @@ func collectGenFiles(
nodeID, valPubKey := nodeIDs[i], valPubKeys[i]
initCfg := genutiltypes.NewInitConfig(chainID, gentxsDir, nodeID, valPubKey)

genDoc, err := types.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
}
Expand Down
19 changes: 0 additions & 19 deletions tests/e2e/genutil/cli_test.go

This file was deleted.

61 changes: 0 additions & 61 deletions tests/e2e/genutil/migrate.go

This file was deleted.

Loading