From 7b56ee3a3560581d6abf6473ad6711333dddf180 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 18 Aug 2020 18:39:26 +0200 Subject: [PATCH 01/44] Add height in exported genesis --- server/export.go | 3 ++- server/export_test.go | 2 +- server/types/app.go | 2 +- simapp/app_test.go | 2 +- simapp/export.go | 6 +++--- simapp/sim_test.go | 4 ++-- simapp/simd/cmd/root.go | 4 ++-- simapp/types.go | 2 +- simapp/utils.go | 2 +- x/genutil/client/cli/validate_genesis.go | 2 +- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/server/export.go b/server/export.go index d54a859addf..a99df89fe87 100644 --- a/server/export.go +++ b/server/export.go @@ -64,7 +64,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com forZeroHeight, _ := cmd.Flags().GetBool(flagForZeroHeight) jailWhiteList, _ := cmd.Flags().GetStringSlice(flagJailWhitelist) - appState, validators, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList) + appState, validators, appHeight, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList) if err != nil { return fmt.Errorf("error exporting state: %v", err) } @@ -76,6 +76,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com doc.AppState = appState doc.Validators = validators + doc.InitialHeight = appHeight doc.ConsensusParams = &tmproto.ConsensusParams{ Block: tmproto.BlockParams{ MaxBytes: cp.Block.MaxBytes, diff --git a/server/export_test.go b/server/export_test.go index 58580781265..7542373f99e 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -56,7 +56,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) { app.Commit() cmd := ExportCmd( - func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) { + func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) { return app.ExportAppStateAndValidators(true, []string{}) }, tempDir) diff --git a/server/types/app.go b/server/types/app.go index f68a9320763..4aabb0a6bfe 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -44,5 +44,5 @@ type ( // AppExporter is a function that dumps all app state to // JSON-serializable structure and returns the current validator set. - AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) + AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) ) diff --git a/simapp/app_test.go b/simapp/app_test.go index 84ba317d716..79d40562ad1 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -31,7 +31,7 @@ func TestSimAppExport(t *testing.T) { // Making a new app object with the db, so that initchain hasn't been called app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig()) - _, _, _, err = app2.ExportAppStateAndValidators(false, []string{}) + _, _, _, _, err = app2.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } diff --git a/simapp/export.go b/simapp/export.go index 7f4a2036cbb..3fb3bb94764 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -19,7 +19,7 @@ import ( // file. func (app *SimApp) ExportAppStateAndValidators( forZeroHeight bool, jailWhiteList []string, -) (appState json.RawMessage, validators []tmtypes.GenesisValidator, cp *abci.ConsensusParams, err error) { +) (appState json.RawMessage, validators []tmtypes.GenesisValidator, height int64, cp *abci.ConsensusParams, err error) { // as if they could withdraw from the start of the next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) @@ -31,11 +31,11 @@ func (app *SimApp) ExportAppStateAndValidators( genState := app.mm.ExportGenesis(ctx, app.appCodec) appState, err = json.MarshalIndent(genState, "", " ") if err != nil { - return nil, nil, nil, err + return nil, nil, 0, nil, err } validators = staking.WriteValidators(ctx, app.StakingKeeper) - return appState, validators, app.BaseApp.GetConsensusParams(ctx), nil + return appState, validators, app.LastBlockHeight(), app.BaseApp.GetConsensusParams(ctx), nil } // prepare for fresh start at zero height diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 6428e1a656a..09fa54c05b2 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -120,7 +120,7 @@ func TestAppImportExport(t *testing.T) { fmt.Printf("exporting genesis...\n") - appState, _, consensusParams, err := app.ExportAppStateAndValidators(false, []string{}) + appState, _, _, consensusParams, err := app.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err) fmt.Printf("importing genesis...\n") @@ -216,7 +216,7 @@ func TestAppSimulationAfterImport(t *testing.T) { fmt.Printf("exporting genesis...\n") - appState, _, _, err := app.ExportAppStateAndValidators(true, []string{}) + appState, _, _, _, err := app.ExportAppStateAndValidators(true, []string{}) require.NoError(t, err) fmt.Printf("importing genesis...\n") diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 1cdee260deb..1c758c3db2d 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -192,7 +192,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty func exportAppStateAndTMValidators( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string, -) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) { +) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) { encCfg := simapp.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd. encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry) @@ -201,7 +201,7 @@ func exportAppStateAndTMValidators( simApp = simapp.NewSimApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), encCfg) if err := simApp.LoadHeight(height); err != nil { - return nil, nil, nil, err + return nil, nil, 0, nil, err } } else { simApp = simapp.NewSimApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), encCfg) diff --git a/simapp/types.go b/simapp/types.go index 94fac5b77db..29061522c08 100644 --- a/simapp/types.go +++ b/simapp/types.go @@ -36,7 +36,7 @@ type App interface { // Exports the state of the application for a genesis file. ExportAppStateAndValidators( forZeroHeight bool, jailWhiteList []string, - ) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) + ) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) // All the registered module account addreses. ModuleAccountAddrs() map[string]bool diff --git a/simapp/utils.go b/simapp/utils.go index 1409310a043..9dfa6fe5e54 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -79,7 +79,7 @@ func CheckExportSimulation( ) error { if config.ExportStatePath != "" { fmt.Println("exporting app state...") - appState, _, _, err := app.ExportAppStateAndValidators(false, nil) + appState, _, _, _, err := app.ExportAppStateAndValidators(false, nil) if err != nil { return err } diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 756b06a26ea..a2e148b24be 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -41,7 +41,7 @@ func ValidateGenesisCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfi } var genState map[string]json.RawMessage - if err = cdc.UnmarshalJSON(genDoc.AppState, &genState); err != nil { + if err = json.Unmarshal(genDoc.AppState, &genState); err != nil { return fmt.Errorf("error unmarshalling genesis doc %s: %s", genesis, err.Error()) } From 167cc8becae0932b3b1c6c9def0321928730a62b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 18 Aug 2020 18:40:52 +0200 Subject: [PATCH 02/44] +1 --- server/export.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/export.go b/server/export.go index a99df89fe87..92db3b19117 100644 --- a/server/export.go +++ b/server/export.go @@ -76,7 +76,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com doc.AppState = appState doc.Validators = validators - doc.InitialHeight = appHeight + doc.InitialHeight = appHeight + 1 doc.ConsensusParams = &tmproto.ConsensusParams{ Block: tmproto.BlockParams{ MaxBytes: cp.Block.MaxBytes, From e17275c2eeeaf9f1facba469d5b2d0f687f02e6e Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 19 Aug 2020 11:19:15 +0200 Subject: [PATCH 03/44] Add test --- server/export_test.go | 87 +++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/server/export_test.go b/server/export_test.go index 7542373f99e..261c5965bbd 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -10,10 +10,12 @@ import ( "path" "testing" + "github.com/spf13/cobra" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -25,10 +27,69 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" ) -func TestExportCmd_ConsensusParams(t *testing.T) { +func TestConsensusParams(t *testing.T) { tempDir, clean := testutil.NewTestCaseDir(t) defer clean() + _, serverCtx, clientCtx, genDoc, cmd := setupApp(t, tempDir) + + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + ctx = context.WithValue(ctx, ServerContextKey, serverCtx) + + output := &bytes.Buffer{} + cmd.SetOut(output) + cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)}) + require.NoError(t, cmd.ExecuteContext(ctx)) + + var exportedGenDoc tmtypes.GenesisDoc + err := json.Unmarshal(output.Bytes(), &exportedGenDoc) + if err != nil { + t.Fatalf("error unmarshaling exported genesis doc: %s", err) + } + + require.Equal(t, genDoc.ConsensusParams.Block.TimeIotaMs, exportedGenDoc.ConsensusParams.Block.TimeIotaMs) + require.Equal(t, simapp.DefaultConsensusParams.Block.MaxBytes, exportedGenDoc.ConsensusParams.Block.MaxBytes) + require.Equal(t, simapp.DefaultConsensusParams.Block.MaxGas, exportedGenDoc.ConsensusParams.Block.MaxGas) + + require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedGenDoc.ConsensusParams.Evidence.MaxAgeDuration) + require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedGenDoc.ConsensusParams.Evidence.MaxAgeNumBlocks) + + require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes) +} + +func TestHeight(t *testing.T) { + tempDir, clean := testutil.NewTestCaseDir(t) + defer clean() + + app, serverCtx, clientCtx, _, cmd := setupApp(t, tempDir) + + // Fast forward to block 3. + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}}) + app.Commit() + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}}) + app.Commit() + + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + ctx = context.WithValue(ctx, ServerContextKey, serverCtx) + + output := &bytes.Buffer{} + cmd.SetOut(output) + cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)}) + require.NoError(t, cmd.ExecuteContext(ctx)) + + var exportedGenDoc tmtypes.GenesisDoc + err := json.Unmarshal(output.Bytes(), &exportedGenDoc) + if err != nil { + t.Fatalf("error unmarshaling exported genesis doc: %s", err) + } + + require.Equal(t, int64(4), exportedGenDoc.InitialHeight) +} + +func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, *Context, client.Context, *tmtypes.GenesisDoc, *cobra.Command) { + err := createConfigFolder(tempDir) if err != nil { t.Fatalf("error creating config folder: %s", err) @@ -60,29 +121,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) { return app.ExportAppStateAndValidators(true, []string{}) }, tempDir) - ctx := context.Background() - ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, ServerContextKey, serverCtx) - - output := &bytes.Buffer{} - cmd.SetOut(output) - cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)}) - require.NoError(t, cmd.ExecuteContext(ctx)) - - var exportedGenDoc tmtypes.GenesisDoc - err = json.Unmarshal(output.Bytes(), &exportedGenDoc) - if err != nil { - t.Fatalf("error unmarshaling exported genesis doc: %s", err) - } - - require.Equal(t, genDoc.ConsensusParams.Block.TimeIotaMs, exportedGenDoc.ConsensusParams.Block.TimeIotaMs) - require.Equal(t, simapp.DefaultConsensusParams.Block.MaxBytes, exportedGenDoc.ConsensusParams.Block.MaxBytes) - require.Equal(t, simapp.DefaultConsensusParams.Block.MaxGas, exportedGenDoc.ConsensusParams.Block.MaxGas) - - require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedGenDoc.ConsensusParams.Evidence.MaxAgeDuration) - require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedGenDoc.ConsensusParams.Evidence.MaxAgeNumBlocks) - - require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes) + return app, serverCtx, clientCtx, genDoc, cmd } func createConfigFolder(dir string) error { From 64e828b563fc06abdf1962dddf4b1810005d9711 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 19 Aug 2020 11:23:41 +0200 Subject: [PATCH 04/44] Refactor ctx in setupApp --- server/export_test.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/server/export_test.go b/server/export_test.go index 261c5965bbd..7fef6db1e19 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -27,15 +27,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" ) -func TestConsensusParams(t *testing.T) { +func TestExportCmd_ConsensusParams(t *testing.T) { tempDir, clean := testutil.NewTestCaseDir(t) defer clean() - _, serverCtx, clientCtx, genDoc, cmd := setupApp(t, tempDir) - - ctx := context.Background() - ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, ServerContextKey, serverCtx) + _, ctx, genDoc, cmd := setupApp(t, tempDir) output := &bytes.Buffer{} cmd.SetOut(output) @@ -58,11 +54,11 @@ func TestConsensusParams(t *testing.T) { require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes) } -func TestHeight(t *testing.T) { +func TestExportCmd_Height(t *testing.T) { tempDir, clean := testutil.NewTestCaseDir(t) defer clean() - app, serverCtx, clientCtx, _, cmd := setupApp(t, tempDir) + app, ctx, _, cmd := setupApp(t, tempDir) // Fast forward to block 3. app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}}) @@ -70,10 +66,6 @@ func TestHeight(t *testing.T) { app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}}) app.Commit() - ctx := context.Background() - ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, ServerContextKey, serverCtx) - output := &bytes.Buffer{} cmd.SetOut(output) cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)}) @@ -88,7 +80,7 @@ func TestHeight(t *testing.T) { require.Equal(t, int64(4), exportedGenDoc.InitialHeight) } -func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, *Context, client.Context, *tmtypes.GenesisDoc, *cobra.Command) { +func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *tmtypes.GenesisDoc, *cobra.Command) { err := createConfigFolder(tempDir) if err != nil { @@ -121,7 +113,11 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, *Context, client.Co return app.ExportAppStateAndValidators(true, []string{}) }, tempDir) - return app, serverCtx, clientCtx, genDoc, cmd + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + ctx = context.WithValue(ctx, ServerContextKey, serverCtx) + + return app, ctx, genDoc, cmd } func createConfigFolder(dir string) error { From a04a42cc10c04b2174b40f0b237a92c644cea0a9 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 20 Aug 2020 11:33:03 +0200 Subject: [PATCH 05/44] Use amino in export --- server/export.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/export.go b/server/export.go index 92db3b19117..53fed564c4f 100644 --- a/server/export.go +++ b/server/export.go @@ -3,7 +3,6 @@ package server // DONTCOVER import ( - "encoding/json" "fmt" "io/ioutil" "os" @@ -12,6 +11,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,6 +29,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com Use: "export", Short: "Export state to JSON", RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) serverCtx := GetServerContextFromCmd(cmd) config := serverCtx.Config @@ -94,10 +95,10 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com }, } - // NOTE: for now we're just using standard JSON marshaling for the root GenesisDoc. - // These types are in Tendermint, don't support proto and as far as we know, don't need it. - // All of the protobuf/amino state is inside AppState - encoded, err := json.MarshalIndent(doc, "", " ") + // NOTE: Tendermint uses an Amino JSON decoder for GenesisDoc + // (except for stuff inside AppState). Inside AppState, we're free + // to encode as protobuf or amino. + encoded, err := clientCtx.LegacyAmino.MarshalJSON(doc) if err != nil { return err } From 1749ca8fa416a5a8fb6d5d79a494df47d568b928 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 21 Aug 2020 10:32:07 +0200 Subject: [PATCH 06/44] Use tmjson --- server/export.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/export.go b/server/export.go index 53fed564c4f..6f6bf68e621 100644 --- a/server/export.go +++ b/server/export.go @@ -8,10 +8,10 @@ import ( "os" "github.com/spf13/cobra" + tmjson "github.com/tendermint/tendermint/libs/json" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,7 +29,6 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com Use: "export", Short: "Export state to JSON", RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) serverCtx := GetServerContextFromCmd(cmd) config := serverCtx.Config @@ -95,10 +94,10 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com }, } - // NOTE: Tendermint uses an Amino JSON decoder for GenesisDoc + // NOTE: Tendermint 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 := clientCtx.LegacyAmino.MarshalJSON(doc) + encoded, err := tmjson.Marshal(doc) if err != nil { return err } From a4ac0fc7d8fb401ffb0891a2b57fc7e32d7ae620 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 24 Aug 2020 16:14:56 +0200 Subject: [PATCH 07/44] Add custom initialVersion (set to 0 for now) --- baseapp/abci.go | 8 +++--- baseapp/baseapp.go | 28 ++++++++------------ baseapp/baseapp_test.go | 18 ++++++------- server/mock/app.go | 2 +- server/mock/store.go | 2 +- server/mock/store_test.go | 2 +- simapp/app.go | 2 +- store/iavl/store.go | 4 +-- store/rootmulti/proof_test.go | 6 ++--- store/rootmulti/store.go | 20 ++++++++------ store/rootmulti/store_test.go | 24 ++++++++--------- store/types/iterator_test.go | 2 +- store/types/store.go | 2 +- store/types/utils_test.go | 4 +-- types/context_test.go | 2 +- types/module/module.go | 2 ++ types/store_test.go | 4 +-- x/ibc/03-connection/types/msgs_test.go | 2 +- x/ibc/04-channel/types/msgs_test.go | 2 +- x/ibc/23-commitment/types/commitment_test.go | 2 +- x/params/keeper/common_test.go | 4 +-- x/params/proposal_handler_test.go | 4 +-- x/params/types/subspace_test.go | 4 +-- x/upgrade/types/storeloader_test.go | 8 +++--- 24 files changed, 79 insertions(+), 79 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index dc64fb96058..88f9ce6182b 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -23,7 +23,7 @@ import ( // InitChain implements the ABCI interface. It runs the initialization logic // directly on the CommitMultiStore. func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { - initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time} + initHeader := tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} // initialize the deliver state and check state with a correct header app.setDeliverState(initHeader) @@ -60,13 +60,13 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC sort.Sort(abci.ValidatorUpdates(res.Validators)) for i := range res.Validators { - if proto.Equal(&res.Validators[i], &req.Validators[i]) { + if !proto.Equal(&res.Validators[i], &req.Validators[i]) { panic(fmt.Errorf("genesisValidators[%d] != req.Validators[%d] ", i, i)) } } } - // NOTE: We don't commit, but BeginBlock for block 1 starts from this + // NOTE: We don't commit, but BeginBlock for block `initial_height` starts from this // deliverState. return res } @@ -97,7 +97,7 @@ func (app *BaseApp) FilterPeerByAddrPort(info string) abci.ResponseQuery { return abci.ResponseQuery{} } -// FilterPeerByIDfilters peers by node ID. +// FilterPeerByID filters peers by node ID. func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery { if app.idPeerFilter != nil { return app.idPeerFilter(info) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 4455696afb6..2298cfdcd87 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -155,20 +155,20 @@ func (app *BaseApp) Logger() log.Logger { // MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp // multistore. -func (app *BaseApp) MountStores(keys ...sdk.StoreKey) { +func (app *BaseApp) MountStores(initialVersion int64, keys ...sdk.StoreKey) { for _, key := range keys { switch key.(type) { case *sdk.KVStoreKey: if !app.fauxMerkleMode { - app.MountStore(key, sdk.StoreTypeIAVL) + app.MountStore(key, sdk.StoreTypeIAVL, initialVersion) } else { // StoreTypeDB doesn't do anything upon commit, and it doesn't // retain history, but it's useful for faster simulation. - app.MountStore(key, sdk.StoreTypeDB) + app.MountStore(key, sdk.StoreTypeDB, 0) } case *sdk.TransientStoreKey: - app.MountStore(key, sdk.StoreTypeTransient) + app.MountStore(key, sdk.StoreTypeTransient, 0) default: panic("Unrecognized store key type " + reflect.TypeOf(key).Name()) @@ -178,14 +178,14 @@ func (app *BaseApp) MountStores(keys ...sdk.StoreKey) { // MountKVStores mounts all IAVL or DB stores to the provided keys in the // BaseApp multistore. -func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey) { +func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey, initialVersion int64) { for _, key := range keys { if !app.fauxMerkleMode { - app.MountStore(key, sdk.StoreTypeIAVL) + app.MountStore(key, sdk.StoreTypeIAVL, initialVersion) } else { // StoreTypeDB doesn't do anything upon commit, and it doesn't // retain history, but it's useful for faster simulation. - app.MountStore(key, sdk.StoreTypeDB) + app.MountStore(key, sdk.StoreTypeDB, 0) } } } @@ -194,7 +194,7 @@ func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey) { // the BaseApp multistore. func (app *BaseApp) MountTransientStores(keys map[string]*sdk.TransientStoreKey) { for _, key := range keys { - app.MountStore(key, sdk.StoreTypeTransient) + app.MountStore(key, sdk.StoreTypeTransient, 0) } } @@ -202,20 +202,14 @@ func (app *BaseApp) MountTransientStores(keys map[string]*sdk.TransientStoreKey) // commit multi-store. func (app *BaseApp) MountMemoryStores(keys map[string]*sdk.MemoryStoreKey) { for _, memKey := range keys { - app.MountStore(memKey, sdk.StoreTypeMemory) + app.MountStore(memKey, sdk.StoreTypeMemory, 0) } } -// MountStoreWithDB mounts a store to the provided key in the BaseApp -// multistore, using a specified DB. -func (app *BaseApp) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) { - app.cms.MountStoreWithDB(key, typ, db) -} - // MountStore mounts a store to the provided key in the BaseApp multistore, // using the default DB. -func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) { - app.cms.MountStoreWithDB(key, typ, nil) +func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType, initialVersion int64) { + app.cms.MountStoreWithDB(key, typ, nil, initialVersion) } // LoadLatestVersion loads the latest application version. It will panic if diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 931e7ef5002..7a22d9b152f 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -96,7 +96,7 @@ func setupBaseApp(t *testing.T, options ...func(*BaseApp)) *BaseApp { app := newBaseApp(t.Name(), options...) require.Equal(t, t.Name(), app.Name()) - app.MountStores(capKey1, capKey2) + app.MountStores(0, capKey1, capKey2) app.SetParamStore(¶mStore{db: dbm.NewMemDB()}) // stores are mounted @@ -150,7 +150,7 @@ func TestLoadVersion(t *testing.T) { // reload with LoadLatestVersion app = NewBaseApp(name, logger, db, nil, pruningOpt) - app.MountStores() + app.MountStores(0) err = app.LoadLatestVersion() require.Nil(t, err) testLoadVersionHelper(t, app, int64(2), commitID2) @@ -174,7 +174,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, int64(0), rs.LastCommitID().Version) @@ -191,7 +191,7 @@ func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneDefault) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, ver, rs.LastCommitID().Version) @@ -237,7 +237,7 @@ func TestSetLoader(t *testing.T) { opts = append(opts, tc.setLoader) } app := NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) - app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) + app.MountStores(0, sdk.NewKVStoreKey(tc.loadStoreKey)) err := app.LoadLatestVersion() require.Nil(t, err) @@ -319,7 +319,7 @@ func TestLoadVersionPruning(t *testing.T) { // make a cap key and mount the store capKey := sdk.NewKVStoreKey("key1") - app.MountStores(capKey) + app.MountStores(0, capKey) err := app.LoadLatestVersion() // needed to make stores non-nil require.Nil(t, err) @@ -354,7 +354,7 @@ func TestLoadVersionPruning(t *testing.T) { // reload with LoadLatestVersion, check it loads last version app = NewBaseApp(name, logger, db, nil, pruningOpt) - app.MountStores(capKey) + app.MountStores(0, capKey) err = app.LoadLatestVersion() require.Nil(t, err) @@ -472,7 +472,7 @@ func TestInitChainer(t *testing.T) { app := NewBaseApp(name, logger, db, nil) capKey := sdk.NewKVStoreKey("main") capKey2 := sdk.NewKVStoreKey("key2") - app.MountStores(capKey, capKey2) + app.MountStores(0, capKey, capKey2) // set a value in the store on init chain key, value := []byte("hello"), []byte("goodbye") @@ -517,7 +517,7 @@ func TestInitChainer(t *testing.T) { // reload app app = NewBaseApp(name, logger, db, nil) app.SetInitChainer(initChainer) - app.MountStores(capKey, capKey2) + app.MountStores(0, capKey, capKey2) err = app.LoadLatestVersion() // needed to make stores non-nil require.Nil(t, err) require.Equal(t, int64(1), app.LastBlockHeight()) diff --git a/server/mock/app.go b/server/mock/app.go index e3fdd2c9147..8dedc9746e2 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -32,7 +32,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx) // Set mounts for BaseApp's MultiStore. - baseApp.MountStores(capKeyMainStore) + baseApp.MountStores(0, capKeyMainStore) baseApp.SetInitChainer(InitChainer(capKeyMainStore)) diff --git a/server/mock/store.go b/server/mock/store.go index d8e9cee1c20..3377c28e7fb 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -63,7 +63,7 @@ func (ms multiStore) GetCommitStore(key sdk.StoreKey) sdk.CommitStore { panic("not implemented") } -func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) { +func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB, initialVersion int64) { ms.kv[key] = kvStore{store: make(map[string][]byte)} } diff --git a/server/mock/store_test.go b/server/mock/store_test.go index b945cd30599..2265fd3b242 100644 --- a/server/mock/store_test.go +++ b/server/mock/store_test.go @@ -15,7 +15,7 @@ func TestStore(t *testing.T) { cms := NewCommitMultiStore() key := sdk.NewKVStoreKey("test") - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db, 0) err := cms.LoadLatestVersion() require.Nil(t, err) diff --git a/simapp/app.go b/simapp/app.go index 3d0bd699a48..0caf0597f79 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -358,7 +358,7 @@ func NewSimApp( app.sm.RegisterStoreDecoders() // initialize stores - app.MountKVStores(keys) + app.MountKVStores(keys, 0) app.MountTransientStores(tkeys) app.MountMemoryStores(memKeys) diff --git a/store/iavl/store.go b/store/iavl/store.go index 2e389f68978..dd334d82e16 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -40,8 +40,8 @@ type Store struct { // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the // store's version (id) from the provided DB. An error is returned if the version // fails to load. -func LoadStore(db dbm.DB, id types.CommitID, lazyLoading bool) (types.CommitKVStore, error) { - tree, err := iavl.NewMutableTree(db, defaultIAVLCacheSize) +func LoadStore(db dbm.DB, id types.CommitID, lazyLoading bool, initialVersion uint64) (types.CommitKVStore, error) { + tree, err := iavl.NewMutableTreeWithOpts(db, defaultIAVLCacheSize, &iavl.Options{InitialVersion: initialVersion}) if err != nil { return nil, err } diff --git a/store/rootmulti/proof_test.go b/store/rootmulti/proof_test.go index f0bd29063ad..830f392048b 100644 --- a/store/rootmulti/proof_test.go +++ b/store/rootmulti/proof_test.go @@ -14,7 +14,7 @@ import ( func TestVerifyIAVLStoreQueryProof(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - iStore, err := iavl.LoadStore(db, types.CommitID{}, false) + iStore, err := iavl.LoadStore(db, types.CommitID{}, false, 0) store := iStore.(*iavl.Store) require.Nil(t, err) store.Set([]byte("MYKEY"), []byte("MYVALUE")) @@ -60,7 +60,7 @@ func TestVerifyMultiStoreQueryProof(t *testing.T) { store := NewStore(db) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") - store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil) + store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil, 0) require.NoError(t, store.LoadVersion(0)) iavlStore := store.GetCommitStore(iavlStoreKey).(*iavl.Store) @@ -115,7 +115,7 @@ func TestVerifyMultiStoreQueryProofAbsence(t *testing.T) { store := NewStore(db) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") - store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil) + store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil, 0) err := store.LoadVersion(0) require.NoError(t, err) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index a07c8257e6b..4427e8d7e17 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -85,7 +85,7 @@ func (rs *Store) GetStoreType() types.StoreType { } // MountStoreWithDB implements CommitMultiStore. -func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db dbm.DB) { +func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db dbm.DB, initialVersion int64) { if key == nil { panic("MountIAVLStore() key cannot be nil") } @@ -95,10 +95,12 @@ func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db db if _, ok := rs.keysByName[key.Name()]; ok { panic(fmt.Sprintf("store duplicate store key name %v", key)) } + fmt.Println("MountStoreWithDB key=", key, "type=", typ) rs.storesParams[key] = storeParams{ - key: key, - typ: typ, - db: db, + key: key, + typ: typ, + db: db, + initialVersion: initialVersion, } rs.keysByName[key.Name()] = key } @@ -147,6 +149,7 @@ func (rs *Store) LoadVersion(ver int64) error { } func (rs *Store) loadVersion(ver int64, upgrades *types.StoreUpgrades) error { + fmt.Println("Store loadVersion ver=", ver) infos := make(map[string]types.StoreInfo) cInfo := &types.CommitInfo{} @@ -534,7 +537,7 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID panic("recursive MultiStores not yet supported") case types.StoreTypeIAVL: - store, err := iavl.LoadStore(db, id, rs.lazyLoading) + store, err := iavl.LoadStore(db, id, rs.lazyLoading, uint64(params.initialVersion)) if err != nil { return nil, err } @@ -572,9 +575,10 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID } type storeParams struct { - key types.StoreKey - db dbm.DB - typ types.StoreType + key types.StoreKey + db dbm.DB + typ types.StoreType + initialVersion int64 } func getLatestVersion(db dbm.DB) int64 { diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index 1166adcc64a..8f9c567402f 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -17,7 +17,7 @@ import ( func TestStoreType(t *testing.T) { db := dbm.NewMemDB() store := NewStore(db) - store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, db) + store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, db, 0) } func TestGetCommitKVStore(t *testing.T) { @@ -45,12 +45,12 @@ func TestStoreMount(t *testing.T) { key2 := types.NewKVStoreKey("store2") dup1 := types.NewKVStoreKey("store1") - require.NotPanics(t, func() { store.MountStoreWithDB(key1, types.StoreTypeIAVL, db) }) - require.NotPanics(t, func() { store.MountStoreWithDB(key2, types.StoreTypeIAVL, db) }) + require.NotPanics(t, func() { store.MountStoreWithDB(key1, types.StoreTypeIAVL, db, 0) }) + require.NotPanics(t, func() { store.MountStoreWithDB(key2, types.StoreTypeIAVL, db, 0) }) - require.Panics(t, func() { store.MountStoreWithDB(key1, types.StoreTypeIAVL, db) }) - require.Panics(t, func() { store.MountStoreWithDB(nil, types.StoreTypeIAVL, db) }) - require.Panics(t, func() { store.MountStoreWithDB(dup1, types.StoreTypeIAVL, db) }) + require.Panics(t, func() { store.MountStoreWithDB(key1, types.StoreTypeIAVL, db, 0) }) + require.Panics(t, func() { store.MountStoreWithDB(nil, types.StoreTypeIAVL, db, 0) }) + require.Panics(t, func() { store.MountStoreWithDB(dup1, types.StoreTypeIAVL, db, 0) }) } func TestCacheMultiStoreWithVersion(t *testing.T) { @@ -512,9 +512,9 @@ func newMultiStoreWithMounts(db dbm.DB, pruningOpts types.PruningOptions) *Store store := NewStore(db) store.pruningOpts = pruningOpts - store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil) - store.MountStoreWithDB(types.NewKVStoreKey("store2"), types.StoreTypeIAVL, nil) - store.MountStoreWithDB(types.NewKVStoreKey("store3"), types.StoreTypeIAVL, nil) + store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(types.NewKVStoreKey("store2"), types.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(types.NewKVStoreKey("store3"), types.StoreTypeIAVL, nil, 0) return store } @@ -523,9 +523,9 @@ func newMultiStoreWithModifiedMounts(db dbm.DB, pruningOpts types.PruningOptions store := NewStore(db) store.pruningOpts = pruningOpts - store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil) - store.MountStoreWithDB(types.NewKVStoreKey("restore2"), types.StoreTypeIAVL, nil) - store.MountStoreWithDB(types.NewKVStoreKey("store3"), types.StoreTypeIAVL, nil) + store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(types.NewKVStoreKey("restore2"), types.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(types.NewKVStoreKey("store3"), types.StoreTypeIAVL, nil, 0) upgrades := &types.StoreUpgrades{ Renamed: []types.StoreRename{{ diff --git a/store/types/iterator_test.go b/store/types/iterator_test.go index 3086917b605..e4fa5ccc559 100644 --- a/store/types/iterator_test.go +++ b/store/types/iterator_test.go @@ -12,7 +12,7 @@ import ( func newMemTestKVStore(t *testing.T) types.KVStore { db := dbm.NewMemDB() - store, err := iavl.LoadStore(db, types.CommitID{}, false) + store, err := iavl.LoadStore(db, types.CommitID{}, false, 0) require.NoError(t, err) return store } diff --git a/store/types/store.go b/store/types/store.go index 4ca8f442c05..ec5fac0be47 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -134,7 +134,7 @@ type CommitMultiStore interface { // Mount a store of type using the given db. // If db == nil, the new store will use the CommitMultiStore db. - MountStoreWithDB(key StoreKey, typ StoreType, db dbm.DB) + MountStoreWithDB(key StoreKey, typ StoreType, db dbm.DB, initialVersion int64) // Panics on a nil key. GetCommitStore(key StoreKey) CommitStore diff --git a/store/types/utils_test.go b/store/types/utils_test.go index 32064d7e182..93f453e1faa 100644 --- a/store/types/utils_test.go +++ b/store/types/utils_test.go @@ -17,8 +17,8 @@ func initTestStores(t *testing.T) (types.KVStore, types.KVStore) { key1 := types.NewKVStoreKey("store1") key2 := types.NewKVStoreKey("store2") - require.NotPanics(t, func() { ms.MountStoreWithDB(key1, types.StoreTypeIAVL, db) }) - require.NotPanics(t, func() { ms.MountStoreWithDB(key2, types.StoreTypeIAVL, db) }) + require.NotPanics(t, func() { ms.MountStoreWithDB(key1, types.StoreTypeIAVL, db, 0) }) + require.NotPanics(t, func() { ms.MountStoreWithDB(key2, types.StoreTypeIAVL, db, 0) }) require.NoError(t, ms.LoadLatestVersion()) return ms.GetKVStore(key1), ms.GetKVStore(key2) } diff --git a/types/context_test.go b/types/context_test.go index 0698199a0a6..03194e43644 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -46,7 +46,7 @@ func (l MockLogger) With(kvs ...interface{}) log.Logger { func defaultContext(t *testing.T, key types.StoreKey) types.Context { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, types.StoreTypeIAVL, db) + cms.MountStoreWithDB(key, types.StoreTypeIAVL, db, 0) err := cms.LoadLatestVersion() require.NoError(t, err) ctx := types.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/types/module/module.go b/types/module/module.go index 27401c64a52..c35443c58f9 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -30,6 +30,7 @@ package module import ( "encoding/json" + "fmt" "github.com/gogo/protobuf/grpc" @@ -296,6 +297,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, genesisD // use these validator updates if provided, the module manager assumes // only one module will update the validator set if len(moduleValUpdates) > 0 { + fmt.Println("InitGenesis moduleName=", moduleName, "moduleValUpdates=", moduleValUpdates) if len(validatorUpdates) > 0 { panic("validator InitGenesis updates already set by a previous module") } diff --git a/types/store_test.go b/types/store_test.go index a4af3a663f6..800d52aa2c4 100644 --- a/types/store_test.go +++ b/types/store_test.go @@ -110,8 +110,8 @@ func initTestStores(t *testing.T) (types.KVStore, types.KVStore) { key1 := types.NewKVStoreKey("store1") key2 := types.NewKVStoreKey("store2") - require.NotPanics(t, func() { ms.MountStoreWithDB(key1, types.StoreTypeIAVL, db) }) - require.NotPanics(t, func() { ms.MountStoreWithDB(key2, types.StoreTypeIAVL, db) }) + require.NotPanics(t, func() { ms.MountStoreWithDB(key1, types.StoreTypeIAVL, db, 0) }) + require.NotPanics(t, func() { ms.MountStoreWithDB(key2, types.StoreTypeIAVL, db, 0) }) require.NoError(t, ms.LoadLatestVersion()) return ms.GetKVStore(key1), ms.GetKVStore(key2) } diff --git a/x/ibc/03-connection/types/msgs_test.go b/x/ibc/03-connection/types/msgs_test.go index 42d36e7bdc5..a5d46800ecf 100644 --- a/x/ibc/03-connection/types/msgs_test.go +++ b/x/ibc/03-connection/types/msgs_test.go @@ -39,7 +39,7 @@ func (suite *MsgTestSuite) SetupTest() { store := rootmulti.NewStore(db) storeKey := storetypes.NewKVStoreKey("iavlStoreKey") - store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil) + store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil, 0) store.LoadVersion(0) iavlStore := store.GetCommitStore(storeKey).(*iavl.Store) diff --git a/x/ibc/04-channel/types/msgs_test.go b/x/ibc/04-channel/types/msgs_test.go index b6c9c477431..c1f2b5feb13 100644 --- a/x/ibc/04-channel/types/msgs_test.go +++ b/x/ibc/04-channel/types/msgs_test.go @@ -77,7 +77,7 @@ func (suite *MsgTestSuite) SetupTest() { store := rootmulti.NewStore(db) storeKey := storetypes.NewKVStoreKey("iavlStoreKey") - store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil) + store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil, 0) store.LoadVersion(0) iavlStore := store.GetCommitStore(storeKey).(*iavl.Store) diff --git a/x/ibc/23-commitment/types/commitment_test.go b/x/ibc/23-commitment/types/commitment_test.go index 932599e539c..9dbbde33b20 100644 --- a/x/ibc/23-commitment/types/commitment_test.go +++ b/x/ibc/23-commitment/types/commitment_test.go @@ -26,7 +26,7 @@ func (suite *MerkleTestSuite) SetupTest() { suite.storeKey = storetypes.NewKVStoreKey("iavlStoreKey") - suite.store.MountStoreWithDB(suite.storeKey, storetypes.StoreTypeIAVL, nil) + suite.store.MountStoreWithDB(suite.storeKey, storetypes.StoreTypeIAVL, nil, 0) suite.store.LoadVersion(0) suite.iavlStore = suite.store.GetCommitStore(suite.storeKey).(*iavl.Store) diff --git a/x/params/keeper/common_test.go b/x/params/keeper/common_test.go index 139aaccc9ab..fe51dda5417 100644 --- a/x/params/keeper/common_test.go +++ b/x/params/keeper/common_test.go @@ -41,8 +41,8 @@ func createTestCodec() *codec.LegacyAmino { func defaultContext(key sdk.StoreKey, tkey sdk.StoreKey) sdk.Context { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) - cms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) + cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db, 0) + cms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db, 0) err := cms.LoadLatestVersion() if err != nil { panic(err) diff --git a/x/params/proposal_handler_test.go b/x/params/proposal_handler_test.go index 163182d9c02..8166aaf24d6 100644 --- a/x/params/proposal_handler_test.go +++ b/x/params/proposal_handler_test.go @@ -70,8 +70,8 @@ func newTestInput(t *testing.T) testInput { keyParams := sdk.NewKVStoreKey("params") tKeyParams := sdk.NewTransientStoreKey("transient_params") - cms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db) - cms.MountStoreWithDB(tKeyParams, sdk.StoreTypeTransient, db) + cms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db, 0) + cms.MountStoreWithDB(tKeyParams, sdk.StoreTypeTransient, db, 0) err := cms.LoadLatestVersion() require.Nil(t, err) diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index f9a816641f8..eab30f5f190 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -30,8 +30,8 @@ func (suite *SubspaceTestSuite) SetupTest() { db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) - ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) + ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db, 0) + ms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db, 0) suite.NoError(ms.LoadLatestVersion()) encCfg := simapp.MakeEncodingConfig() diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 7fd147013e5..0c63df343d2 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -34,7 +34,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, int64(0), rs.LastCommitID().Version) @@ -51,7 +51,7 @@ func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, ver, rs.LastCommitID().Version) @@ -123,8 +123,8 @@ func TestSetLoader(t *testing.T) { app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) capKey := sdk.NewKVStoreKey("main") - app.MountStores(capKey) - app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) + app.MountStores(0, capKey) + app.MountStores(0, sdk.NewKVStoreKey(tc.loadStoreKey)) err := app.LoadLatestVersion() require.Nil(t, err) From 6a9e6bc23875881d3066828a8dd20648bdace281 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 24 Aug 2020 16:25:39 +0200 Subject: [PATCH 08/44] Add comment --- store/rootmulti/store.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 4427e8d7e17..f957d22da3c 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -575,9 +575,11 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID } type storeParams struct { - key types.StoreKey - db dbm.DB - typ types.StoreType + key types.StoreKey + db dbm.DB + typ types.StoreType + // intialVersion is the initial version of the IAVL store. It is only used + // when `typ` is StoreTypeIAVL. initialVersion int64 } From a04b438963d4408c4ec38bf5bfdc0644f758fe78 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 25 Aug 2020 16:04:23 +0200 Subject: [PATCH 09/44] Add mount in initChainer --- baseapp/abci.go | 14 ++--- server/export_test.go | 7 ++- simapp/app.go | 25 +++++--- simapp/export_test.go | 133 +++++++++++++++++++++++++++++++++++++++ store/rootmulti/store.go | 2 - 5 files changed, 161 insertions(+), 20 deletions(-) create mode 100644 simapp/export_test.go diff --git a/baseapp/abci.go b/baseapp/abci.go index 88f9ce6182b..cf7a4645e81 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -29,13 +29,6 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC app.setDeliverState(initHeader) app.setCheckState(initHeader) - // Store the consensus params in the BaseApp's paramstore. Note, this must be - // done after the deliver state and context have been set as it's persisted - // to state. - if req.ConsensusParams != nil { - app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams) - } - if app.initChainer == nil { return } @@ -45,6 +38,13 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC res = app.initChainer(app.deliverState.ctx, req) + // Store the consensus params in the BaseApp's paramstore. Note, this must be + // done after the deliver state and context have been set as it's persisted + // to state. + if req.ConsensusParams != nil { + app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams) + } + // sanity check if len(req.Validators) > 0 { if len(req.Validators) != len(res.Validators) { diff --git a/server/export_test.go b/server/export_test.go index 7fef6db1e19..9f31216d7a5 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" @@ -39,7 +40,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) { require.NoError(t, cmd.ExecuteContext(ctx)) var exportedGenDoc tmtypes.GenesisDoc - err := json.Unmarshal(output.Bytes(), &exportedGenDoc) + err := tmjson.Unmarshal(output.Bytes(), &exportedGenDoc) if err != nil { t.Fatalf("error unmarshaling exported genesis doc: %s", err) } @@ -72,7 +73,7 @@ func TestExportCmd_Height(t *testing.T) { require.NoError(t, cmd.ExecuteContext(ctx)) var exportedGenDoc tmtypes.GenesisDoc - err := json.Unmarshal(output.Bytes(), &exportedGenDoc) + err := tmjson.Unmarshal(output.Bytes(), &exportedGenDoc) if err != nil { t.Fatalf("error unmarshaling exported genesis doc: %s", err) } @@ -81,7 +82,6 @@ func TestExportCmd_Height(t *testing.T) { } func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *tmtypes.GenesisDoc, *cobra.Command) { - err := createConfigFolder(tempDir) if err != nil { t.Fatalf("error creating config folder: %s", err) @@ -97,6 +97,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t genDoc := newDefaultGenesisDoc() err = saveGenesisFile(genDoc, serverCtx.Config.GenesisFile()) + require.NoError(t, err) app.InitChain( abci.RequestInitChain{ diff --git a/simapp/app.go b/simapp/app.go index 0caf0597f79..411947bde8d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -358,9 +358,9 @@ func NewSimApp( app.sm.RegisterStoreDecoders() // initialize stores - app.MountKVStores(keys, 0) - app.MountTransientStores(tkeys) - app.MountMemoryStores(memKeys) + // app.MountKVStores(keys, 0) + // app.MountTransientStores(tkeys) + // app.MountMemoryStores(memKeys) // initialize BaseApp app.SetInitChainer(app.InitChainer) @@ -373,11 +373,12 @@ func NewSimApp( ) app.SetEndBlocker(app.EndBlocker) - if loadLatest { - if err := app.LoadLatestVersion(); err != nil { - tmos.Exit(err.Error()) - } - } + // TODO When to load store? + // if loadLatest { + // if err := app.LoadLatestVersion(); err != nil { + // tmos.Exit(err.Error()) + // } + // } // Initialize and seal the capability keeper so all persistent capabilities // are loaded in-memory and prevent any further modules from creating scoped @@ -416,6 +417,14 @@ func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Re // InitChainer application update at chain initialization func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { + app.MountKVStores(app.keys, req.InitialHeight) + app.MountTransientStores(app.tkeys) + app.MountMemoryStores(app.memKeys) + err := app.LoadVersion(req.InitialHeight) + if err != nil { + tmos.Exit(err.Error()) + } + var genesisState GenesisState app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState) return app.mm.InitGenesis(ctx, app.appCodec, genesisState) diff --git a/simapp/export_test.go b/simapp/export_test.go new file mode 100644 index 00000000000..ec3f5eaa048 --- /dev/null +++ b/simapp/export_test.go @@ -0,0 +1,133 @@ +package simapp_test + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "os" + "path" + "testing" + + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmtypes "github.com/tendermint/tendermint/types" + dbm "github.com/tendermint/tm-db" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/testutil" + "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/genutil" +) + +func TestSimappInitialHeight(t *testing.T) { + // Create new simapp with a new genesis doc. + tempDir1, clean := testutil.NewTestCaseDir(t) + defer clean() + app, clientCtx, serverCtx := setupApp(t, tempDir1) + genDoc := newDefaultGenesisDoc() + err := saveGenesisFile(genDoc, serverCtx.Config.GenesisFile()) + require.NoError(t, err) + + // Fast forward to block 3. + app.InitChain( + abci.RequestInitChain{ + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: simapp.DefaultConsensusParams, + AppStateBytes: genDoc.AppState, + }, + ) + app.Commit() + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}}) + app.Commit() + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}}) + app.Commit() + + // Create the export command. + cmd := server.ExportCmd( + func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) { + return app.ExportAppStateAndValidators(true, []string{}) + }, tempDir1) + + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + + // Run the export command, save the genesis file to another folder. + output := &bytes.Buffer{} + cmd.SetOut(output) + cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir1)}) + require.NoError(t, cmd.ExecuteContext(ctx)) + tempDir2, clean := testutil.NewTestCaseDir(t) + defer clean() + var exportedGenDoc tmtypes.GenesisDoc + err = tmjson.Unmarshal(output.Bytes(), &exportedGenDoc) + if err != nil { + t.Fatalf("error unmarshaling exported genesis doc: %s", err) + } + err = saveGenesisFile(genDoc, tempDir2) + + // Run a new app, with exported genesis. + app, clientCtx, serverCtx = setupApp(t, tempDir2) + app.InitChain( + abci.RequestInitChain{ + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: simapp.DefaultConsensusParams, + AppStateBytes: exportedGenDoc.AppState, + InitialHeight: exportedGenDoc.InitialHeight, + }, + ) + app.Commit() + + // Check that initial height is taken into account. + require.Equal(t, 4, app.LastBlockHeight()) +} + +func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, client.Context, *server.Context) { + err := os.Mkdir(path.Join(tempDir, "config"), 0700) + if err != nil { + t.Fatalf("error creating config folder: %s", err) + } + + db := dbm.NewMemDB() + app := simapp.NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, tempDir, 0, simapp.MakeEncodingConfig()) + + serverCtx := server.NewDefaultContext() + serverCtx.Config.RootDir = tempDir + + clientCtx := client.Context{}.WithJSONMarshaler(app.AppCodec()) + + return app, clientCtx, serverCtx +} + +func newDefaultGenesisDoc() *tmtypes.GenesisDoc { + genesisState := simapp.NewDefaultGenesisState() + + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + if err != nil { + panic(err) + } + + genDoc := &tmtypes.GenesisDoc{} + genDoc.ChainID = "theChainId" + genDoc.Validators = nil + genDoc.AppState = stateBytes + + return genDoc +} + +func saveGenesisFile(genDoc *tmtypes.GenesisDoc, dir string) error { + err := genutil.ExportGenesisFile(genDoc, dir) + if err != nil { + return errors.Wrap(err, "error creating file") + } + + return nil +} diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index f957d22da3c..07c5b0add22 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -95,7 +95,6 @@ func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db db if _, ok := rs.keysByName[key.Name()]; ok { panic(fmt.Sprintf("store duplicate store key name %v", key)) } - fmt.Println("MountStoreWithDB key=", key, "type=", typ) rs.storesParams[key] = storeParams{ key: key, typ: typ, @@ -149,7 +148,6 @@ func (rs *Store) LoadVersion(ver int64) error { } func (rs *Store) loadVersion(ver int64, upgrades *types.StoreUpgrades) error { - fmt.Println("Store loadVersion ver=", ver) infos := make(map[string]types.StoreInfo) cInfo := &types.CommitInfo{} From bf549ecfcaa690347341a7eac780d117156b8d98 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 25 Aug 2020 16:11:37 +0200 Subject: [PATCH 10/44] app.LastBlockheight --- simapp/app.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 411947bde8d..e7f3d5dd663 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -358,9 +358,9 @@ func NewSimApp( app.sm.RegisterStoreDecoders() // initialize stores - // app.MountKVStores(keys, 0) - // app.MountTransientStores(tkeys) - // app.MountMemoryStores(memKeys) + app.MountKVStores(keys, app.LastBlockHeight()) + app.MountTransientStores(tkeys) + app.MountMemoryStores(memKeys) // initialize BaseApp app.SetInitChainer(app.InitChainer) From fb99bb353e197e6dd714cc92a1d92a330126cdcf Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 25 Aug 2020 17:44:36 +0200 Subject: [PATCH 11/44] InitializeAndSeal in InitChain? --- simapp/app.go | 30 +++++++++++++++++------------- store/rootmulti/store.go | 4 +++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 0dfb52a6ec0..25a0f1f98b9 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -359,7 +359,7 @@ func NewSimApp( app.sm.RegisterStoreDecoders() // initialize stores - app.MountKVStores(keys, app.LastBlockHeight()) + app.MountKVStores(keys, 0) app.MountTransientStores(tkeys) app.MountMemoryStores(memKeys) @@ -381,14 +381,6 @@ func NewSimApp( // } // } - // Initialize and seal the capability keeper so all persistent capabilities - // are loaded in-memory and prevent any further modules from creating scoped - // sub-keepers. - // This must be done during creation of baseapp rather than in InitChain so - // that in-memory capabilities get regenerated on app restart - ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{}) - app.CapabilityKeeper.InitializeAndSeal(ctx) - app.ScopedIBCKeeper = scopedIBCKeeper app.ScopedTransferKeeper = scopedTransferKeeper @@ -418,14 +410,26 @@ func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Re // InitChainer application update at chain initialization func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - app.MountKVStores(app.keys, req.InitialHeight) - app.MountTransientStores(app.tkeys) - app.MountMemoryStores(app.memKeys) - err := app.LoadVersion(req.InitialHeight) + // If we get a non-null initial height from ABCI InitChain, then we mount + // the stores (again) at that height. + if req.InitialHeight != 0 { + app.MountKVStores(app.keys, req.InitialHeight) + } + + err := app.LoadLatestVersion() if err != nil { tmos.Exit(err.Error()) } + // TODO... but how? + // Initialize and seal the capability keeper so all persistent capabilities + // are loaded in-memory and prevent any further modules from creating scoped + // sub-keepers. + // This must be done during creation of baseapp rather than in InitChain so + // that in-memory capabilities get regenerated on app restart + ctx = app.BaseApp.NewUncachedContext(true, tmproto.Header{}) + app.CapabilityKeeper.InitializeAndSeal(ctx) + var genesisState GenesisState app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState) return app.mm.InitGenesis(ctx, app.appCodec, genesisState) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 07c5b0add22..933763cd1db 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -89,7 +89,9 @@ func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db db if key == nil { panic("MountIAVLStore() key cannot be nil") } - if _, ok := rs.storesParams[key]; ok { + // If we mount the store again with the same initial version, panic with + // duplicate key error. + if _, ok := rs.storesParams[key]; ok && initialVersion == rs.storesParams[key].initialVersion { panic(fmt.Sprintf("store duplicate store key %v", key)) } if _, ok := rs.keysByName[key.Name()]; ok { From 270c32382c9ab14a62ec52e8bbb8bc9305906749 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 26 Aug 2020 16:24:37 +0200 Subject: [PATCH 12/44] Revert create store with initial version --- baseapp/abci.go | 14 ++++----- baseapp/baseapp.go | 20 ++++++------ baseapp/baseapp_test.go | 4 +-- server/mock/store.go | 2 +- server/mock/store_test.go | 2 +- simapp/app.go | 32 +++++++++----------- store/iavl/store.go | 4 +-- store/rootmulti/proof_test.go | 6 ++-- store/rootmulti/store.go | 16 ++++------ store/rootmulti/store_test.go | 24 +++++++-------- store/types/iterator_test.go | 2 +- store/types/store.go | 2 +- store/types/utils_test.go | 4 +-- types/context_test.go | 2 +- types/store_test.go | 4 +-- x/ibc/03-connection/types/msgs_test.go | 2 +- x/ibc/04-channel/types/msgs_test.go | 2 +- x/ibc/23-commitment/types/commitment_test.go | 2 +- x/params/keeper/common_test.go | 4 +-- x/params/proposal_handler_test.go | 4 +-- x/params/types/subspace_test.go | 4 +-- x/upgrade/types/storeloader_test.go | 4 +-- 22 files changed, 77 insertions(+), 83 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index cf7a4645e81..88f9ce6182b 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -29,6 +29,13 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC app.setDeliverState(initHeader) app.setCheckState(initHeader) + // Store the consensus params in the BaseApp's paramstore. Note, this must be + // done after the deliver state and context have been set as it's persisted + // to state. + if req.ConsensusParams != nil { + app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams) + } + if app.initChainer == nil { return } @@ -38,13 +45,6 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC res = app.initChainer(app.deliverState.ctx, req) - // Store the consensus params in the BaseApp's paramstore. Note, this must be - // done after the deliver state and context have been set as it's persisted - // to state. - if req.ConsensusParams != nil { - app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams) - } - // sanity check if len(req.Validators) > 0 { if len(req.Validators) != len(res.Validators) { diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 2298cfdcd87..1dd9630df30 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -160,15 +160,15 @@ func (app *BaseApp) MountStores(initialVersion int64, keys ...sdk.StoreKey) { switch key.(type) { case *sdk.KVStoreKey: if !app.fauxMerkleMode { - app.MountStore(key, sdk.StoreTypeIAVL, initialVersion) + app.MountStore(key, sdk.StoreTypeIAVL) } else { // StoreTypeDB doesn't do anything upon commit, and it doesn't // retain history, but it's useful for faster simulation. - app.MountStore(key, sdk.StoreTypeDB, 0) + app.MountStore(key, sdk.StoreTypeDB) } case *sdk.TransientStoreKey: - app.MountStore(key, sdk.StoreTypeTransient, 0) + app.MountStore(key, sdk.StoreTypeTransient) default: panic("Unrecognized store key type " + reflect.TypeOf(key).Name()) @@ -178,14 +178,14 @@ func (app *BaseApp) MountStores(initialVersion int64, keys ...sdk.StoreKey) { // MountKVStores mounts all IAVL or DB stores to the provided keys in the // BaseApp multistore. -func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey, initialVersion int64) { +func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey) { for _, key := range keys { if !app.fauxMerkleMode { - app.MountStore(key, sdk.StoreTypeIAVL, initialVersion) + app.MountStore(key, sdk.StoreTypeIAVL) } else { // StoreTypeDB doesn't do anything upon commit, and it doesn't // retain history, but it's useful for faster simulation. - app.MountStore(key, sdk.StoreTypeDB, 0) + app.MountStore(key, sdk.StoreTypeDB) } } } @@ -194,7 +194,7 @@ func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey, initialVersio // the BaseApp multistore. func (app *BaseApp) MountTransientStores(keys map[string]*sdk.TransientStoreKey) { for _, key := range keys { - app.MountStore(key, sdk.StoreTypeTransient, 0) + app.MountStore(key, sdk.StoreTypeTransient) } } @@ -202,14 +202,14 @@ func (app *BaseApp) MountTransientStores(keys map[string]*sdk.TransientStoreKey) // commit multi-store. func (app *BaseApp) MountMemoryStores(keys map[string]*sdk.MemoryStoreKey) { for _, memKey := range keys { - app.MountStore(memKey, sdk.StoreTypeMemory, 0) + app.MountStore(memKey, sdk.StoreTypeMemory) } } // MountStore mounts a store to the provided key in the BaseApp multistore, // using the default DB. -func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType, initialVersion int64) { - app.cms.MountStoreWithDB(key, typ, nil, initialVersion) +func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) { + app.cms.MountStoreWithDB(key, typ, nil) } // LoadLatestVersion loads the latest application version. It will panic if diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index bf211cd1681..c3191390780 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -174,7 +174,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0) + rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, int64(0), rs.LastCommitID().Version) @@ -191,7 +191,7 @@ func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneDefault) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0) + rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, ver, rs.LastCommitID().Version) diff --git a/server/mock/store.go b/server/mock/store.go index 3377c28e7fb..d8e9cee1c20 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -63,7 +63,7 @@ func (ms multiStore) GetCommitStore(key sdk.StoreKey) sdk.CommitStore { panic("not implemented") } -func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB, initialVersion int64) { +func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) { ms.kv[key] = kvStore{store: make(map[string][]byte)} } diff --git a/server/mock/store_test.go b/server/mock/store_test.go index 2265fd3b242..b945cd30599 100644 --- a/server/mock/store_test.go +++ b/server/mock/store_test.go @@ -15,7 +15,7 @@ func TestStore(t *testing.T) { cms := NewCommitMultiStore() key := sdk.NewKVStoreKey("test") - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db, 0) + cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) err := cms.LoadLatestVersion() require.Nil(t, err) diff --git a/simapp/app.go b/simapp/app.go index 4fb66f5424b..4edfef5579a 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -359,7 +359,7 @@ func NewSimApp( app.sm.RegisterStoreDecoders() // initialize stores - app.MountKVStores(keys, 0) + app.MountKVStores(keys) app.MountTransientStores(tkeys) app.MountMemoryStores(memKeys) @@ -374,12 +374,19 @@ func NewSimApp( ) app.SetEndBlocker(app.EndBlocker) - // TODO When to load store? - // if loadLatest { - // if err := app.LoadLatestVersion(); err != nil { - // tmos.Exit(err.Error()) - // } - // } + if loadLatest { + if err := app.LoadLatestVersion(); err != nil { + tmos.Exit(err.Error()) + } + } + + // Initialize and seal the capability keeper so all persistent capabilities + // are loaded in-memory and prevent any further modules from creating scoped + // sub-keepers. + // This must be done during creation of baseapp rather than in InitChain so + // that in-memory capabilities get regenerated on app restart + ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{}) + app.CapabilityKeeper.InitializeAndSeal(ctx) app.ScopedIBCKeeper = scopedIBCKeeper app.ScopedTransferKeeper = scopedTransferKeeper @@ -413,7 +420,7 @@ func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci. // If we get a non-null initial height from ABCI InitChain, then we mount // the stores (again) at that height. if req.InitialHeight != 0 { - app.MountKVStores(app.keys, req.InitialHeight) + app.MountKVStores(app.keys) } err := app.LoadLatestVersion() @@ -421,15 +428,6 @@ func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci. tmos.Exit(err.Error()) } - // TODO... but how? - // Initialize and seal the capability keeper so all persistent capabilities - // are loaded in-memory and prevent any further modules from creating scoped - // sub-keepers. - // This must be done during creation of baseapp rather than in InitChain so - // that in-memory capabilities get regenerated on app restart - ctx = app.BaseApp.NewUncachedContext(true, tmproto.Header{}) - app.CapabilityKeeper.InitializeAndSeal(ctx) - var genesisState GenesisState app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState) return app.mm.InitGenesis(ctx, app.appCodec, genesisState) diff --git a/store/iavl/store.go b/store/iavl/store.go index dd334d82e16..2e389f68978 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -40,8 +40,8 @@ type Store struct { // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the // store's version (id) from the provided DB. An error is returned if the version // fails to load. -func LoadStore(db dbm.DB, id types.CommitID, lazyLoading bool, initialVersion uint64) (types.CommitKVStore, error) { - tree, err := iavl.NewMutableTreeWithOpts(db, defaultIAVLCacheSize, &iavl.Options{InitialVersion: initialVersion}) +func LoadStore(db dbm.DB, id types.CommitID, lazyLoading bool) (types.CommitKVStore, error) { + tree, err := iavl.NewMutableTree(db, defaultIAVLCacheSize) if err != nil { return nil, err } diff --git a/store/rootmulti/proof_test.go b/store/rootmulti/proof_test.go index 830f392048b..f0bd29063ad 100644 --- a/store/rootmulti/proof_test.go +++ b/store/rootmulti/proof_test.go @@ -14,7 +14,7 @@ import ( func TestVerifyIAVLStoreQueryProof(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - iStore, err := iavl.LoadStore(db, types.CommitID{}, false, 0) + iStore, err := iavl.LoadStore(db, types.CommitID{}, false) store := iStore.(*iavl.Store) require.Nil(t, err) store.Set([]byte("MYKEY"), []byte("MYVALUE")) @@ -60,7 +60,7 @@ func TestVerifyMultiStoreQueryProof(t *testing.T) { store := NewStore(db) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") - store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil) require.NoError(t, store.LoadVersion(0)) iavlStore := store.GetCommitStore(iavlStoreKey).(*iavl.Store) @@ -115,7 +115,7 @@ func TestVerifyMultiStoreQueryProofAbsence(t *testing.T) { store := NewStore(db) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") - store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil) err := store.LoadVersion(0) require.NoError(t, err) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 933763cd1db..66b3ab51b2d 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -85,23 +85,22 @@ func (rs *Store) GetStoreType() types.StoreType { } // MountStoreWithDB implements CommitMultiStore. -func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db dbm.DB, initialVersion int64) { +func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db dbm.DB) { if key == nil { panic("MountIAVLStore() key cannot be nil") } // If we mount the store again with the same initial version, panic with // duplicate key error. - if _, ok := rs.storesParams[key]; ok && initialVersion == rs.storesParams[key].initialVersion { + if _, ok := rs.storesParams[key]; ok { panic(fmt.Sprintf("store duplicate store key %v", key)) } if _, ok := rs.keysByName[key.Name()]; ok { panic(fmt.Sprintf("store duplicate store key name %v", key)) } rs.storesParams[key] = storeParams{ - key: key, - typ: typ, - db: db, - initialVersion: initialVersion, + key: key, + typ: typ, + db: db, } rs.keysByName[key.Name()] = key } @@ -537,7 +536,7 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID panic("recursive MultiStores not yet supported") case types.StoreTypeIAVL: - store, err := iavl.LoadStore(db, id, rs.lazyLoading, uint64(params.initialVersion)) + store, err := iavl.LoadStore(db, id, rs.lazyLoading) if err != nil { return nil, err } @@ -578,9 +577,6 @@ type storeParams struct { key types.StoreKey db dbm.DB typ types.StoreType - // intialVersion is the initial version of the IAVL store. It is only used - // when `typ` is StoreTypeIAVL. - initialVersion int64 } func getLatestVersion(db dbm.DB) int64 { diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index 8f9c567402f..1166adcc64a 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -17,7 +17,7 @@ import ( func TestStoreType(t *testing.T) { db := dbm.NewMemDB() store := NewStore(db) - store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, db, 0) + store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, db) } func TestGetCommitKVStore(t *testing.T) { @@ -45,12 +45,12 @@ func TestStoreMount(t *testing.T) { key2 := types.NewKVStoreKey("store2") dup1 := types.NewKVStoreKey("store1") - require.NotPanics(t, func() { store.MountStoreWithDB(key1, types.StoreTypeIAVL, db, 0) }) - require.NotPanics(t, func() { store.MountStoreWithDB(key2, types.StoreTypeIAVL, db, 0) }) + require.NotPanics(t, func() { store.MountStoreWithDB(key1, types.StoreTypeIAVL, db) }) + require.NotPanics(t, func() { store.MountStoreWithDB(key2, types.StoreTypeIAVL, db) }) - require.Panics(t, func() { store.MountStoreWithDB(key1, types.StoreTypeIAVL, db, 0) }) - require.Panics(t, func() { store.MountStoreWithDB(nil, types.StoreTypeIAVL, db, 0) }) - require.Panics(t, func() { store.MountStoreWithDB(dup1, types.StoreTypeIAVL, db, 0) }) + require.Panics(t, func() { store.MountStoreWithDB(key1, types.StoreTypeIAVL, db) }) + require.Panics(t, func() { store.MountStoreWithDB(nil, types.StoreTypeIAVL, db) }) + require.Panics(t, func() { store.MountStoreWithDB(dup1, types.StoreTypeIAVL, db) }) } func TestCacheMultiStoreWithVersion(t *testing.T) { @@ -512,9 +512,9 @@ func newMultiStoreWithMounts(db dbm.DB, pruningOpts types.PruningOptions) *Store store := NewStore(db) store.pruningOpts = pruningOpts - store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil, 0) - store.MountStoreWithDB(types.NewKVStoreKey("store2"), types.StoreTypeIAVL, nil, 0) - store.MountStoreWithDB(types.NewKVStoreKey("store3"), types.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil) + store.MountStoreWithDB(types.NewKVStoreKey("store2"), types.StoreTypeIAVL, nil) + store.MountStoreWithDB(types.NewKVStoreKey("store3"), types.StoreTypeIAVL, nil) return store } @@ -523,9 +523,9 @@ func newMultiStoreWithModifiedMounts(db dbm.DB, pruningOpts types.PruningOptions store := NewStore(db) store.pruningOpts = pruningOpts - store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil, 0) - store.MountStoreWithDB(types.NewKVStoreKey("restore2"), types.StoreTypeIAVL, nil, 0) - store.MountStoreWithDB(types.NewKVStoreKey("store3"), types.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil) + store.MountStoreWithDB(types.NewKVStoreKey("restore2"), types.StoreTypeIAVL, nil) + store.MountStoreWithDB(types.NewKVStoreKey("store3"), types.StoreTypeIAVL, nil) upgrades := &types.StoreUpgrades{ Renamed: []types.StoreRename{{ diff --git a/store/types/iterator_test.go b/store/types/iterator_test.go index e4fa5ccc559..3086917b605 100644 --- a/store/types/iterator_test.go +++ b/store/types/iterator_test.go @@ -12,7 +12,7 @@ import ( func newMemTestKVStore(t *testing.T) types.KVStore { db := dbm.NewMemDB() - store, err := iavl.LoadStore(db, types.CommitID{}, false, 0) + store, err := iavl.LoadStore(db, types.CommitID{}, false) require.NoError(t, err) return store } diff --git a/store/types/store.go b/store/types/store.go index ec5fac0be47..4ca8f442c05 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -134,7 +134,7 @@ type CommitMultiStore interface { // Mount a store of type using the given db. // If db == nil, the new store will use the CommitMultiStore db. - MountStoreWithDB(key StoreKey, typ StoreType, db dbm.DB, initialVersion int64) + MountStoreWithDB(key StoreKey, typ StoreType, db dbm.DB) // Panics on a nil key. GetCommitStore(key StoreKey) CommitStore diff --git a/store/types/utils_test.go b/store/types/utils_test.go index 93f453e1faa..32064d7e182 100644 --- a/store/types/utils_test.go +++ b/store/types/utils_test.go @@ -17,8 +17,8 @@ func initTestStores(t *testing.T) (types.KVStore, types.KVStore) { key1 := types.NewKVStoreKey("store1") key2 := types.NewKVStoreKey("store2") - require.NotPanics(t, func() { ms.MountStoreWithDB(key1, types.StoreTypeIAVL, db, 0) }) - require.NotPanics(t, func() { ms.MountStoreWithDB(key2, types.StoreTypeIAVL, db, 0) }) + require.NotPanics(t, func() { ms.MountStoreWithDB(key1, types.StoreTypeIAVL, db) }) + require.NotPanics(t, func() { ms.MountStoreWithDB(key2, types.StoreTypeIAVL, db) }) require.NoError(t, ms.LoadLatestVersion()) return ms.GetKVStore(key1), ms.GetKVStore(key2) } diff --git a/types/context_test.go b/types/context_test.go index 03194e43644..0698199a0a6 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -46,7 +46,7 @@ func (l MockLogger) With(kvs ...interface{}) log.Logger { func defaultContext(t *testing.T, key types.StoreKey) types.Context { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, types.StoreTypeIAVL, db, 0) + cms.MountStoreWithDB(key, types.StoreTypeIAVL, db) err := cms.LoadLatestVersion() require.NoError(t, err) ctx := types.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/types/store_test.go b/types/store_test.go index 800d52aa2c4..a4af3a663f6 100644 --- a/types/store_test.go +++ b/types/store_test.go @@ -110,8 +110,8 @@ func initTestStores(t *testing.T) (types.KVStore, types.KVStore) { key1 := types.NewKVStoreKey("store1") key2 := types.NewKVStoreKey("store2") - require.NotPanics(t, func() { ms.MountStoreWithDB(key1, types.StoreTypeIAVL, db, 0) }) - require.NotPanics(t, func() { ms.MountStoreWithDB(key2, types.StoreTypeIAVL, db, 0) }) + require.NotPanics(t, func() { ms.MountStoreWithDB(key1, types.StoreTypeIAVL, db) }) + require.NotPanics(t, func() { ms.MountStoreWithDB(key2, types.StoreTypeIAVL, db) }) require.NoError(t, ms.LoadLatestVersion()) return ms.GetKVStore(key1), ms.GetKVStore(key2) } diff --git a/x/ibc/03-connection/types/msgs_test.go b/x/ibc/03-connection/types/msgs_test.go index a5d46800ecf..42d36e7bdc5 100644 --- a/x/ibc/03-connection/types/msgs_test.go +++ b/x/ibc/03-connection/types/msgs_test.go @@ -39,7 +39,7 @@ func (suite *MsgTestSuite) SetupTest() { store := rootmulti.NewStore(db) storeKey := storetypes.NewKVStoreKey("iavlStoreKey") - store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil) store.LoadVersion(0) iavlStore := store.GetCommitStore(storeKey).(*iavl.Store) diff --git a/x/ibc/04-channel/types/msgs_test.go b/x/ibc/04-channel/types/msgs_test.go index c1f2b5feb13..b6c9c477431 100644 --- a/x/ibc/04-channel/types/msgs_test.go +++ b/x/ibc/04-channel/types/msgs_test.go @@ -77,7 +77,7 @@ func (suite *MsgTestSuite) SetupTest() { store := rootmulti.NewStore(db) storeKey := storetypes.NewKVStoreKey("iavlStoreKey") - store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil, 0) + store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil) store.LoadVersion(0) iavlStore := store.GetCommitStore(storeKey).(*iavl.Store) diff --git a/x/ibc/23-commitment/types/commitment_test.go b/x/ibc/23-commitment/types/commitment_test.go index 9dbbde33b20..932599e539c 100644 --- a/x/ibc/23-commitment/types/commitment_test.go +++ b/x/ibc/23-commitment/types/commitment_test.go @@ -26,7 +26,7 @@ func (suite *MerkleTestSuite) SetupTest() { suite.storeKey = storetypes.NewKVStoreKey("iavlStoreKey") - suite.store.MountStoreWithDB(suite.storeKey, storetypes.StoreTypeIAVL, nil, 0) + suite.store.MountStoreWithDB(suite.storeKey, storetypes.StoreTypeIAVL, nil) suite.store.LoadVersion(0) suite.iavlStore = suite.store.GetCommitStore(suite.storeKey).(*iavl.Store) diff --git a/x/params/keeper/common_test.go b/x/params/keeper/common_test.go index fe51dda5417..139aaccc9ab 100644 --- a/x/params/keeper/common_test.go +++ b/x/params/keeper/common_test.go @@ -41,8 +41,8 @@ func createTestCodec() *codec.LegacyAmino { func defaultContext(key sdk.StoreKey, tkey sdk.StoreKey) sdk.Context { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db, 0) - cms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db, 0) + cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + cms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) err := cms.LoadLatestVersion() if err != nil { panic(err) diff --git a/x/params/proposal_handler_test.go b/x/params/proposal_handler_test.go index 8166aaf24d6..163182d9c02 100644 --- a/x/params/proposal_handler_test.go +++ b/x/params/proposal_handler_test.go @@ -70,8 +70,8 @@ func newTestInput(t *testing.T) testInput { keyParams := sdk.NewKVStoreKey("params") tKeyParams := sdk.NewTransientStoreKey("transient_params") - cms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db, 0) - cms.MountStoreWithDB(tKeyParams, sdk.StoreTypeTransient, db, 0) + cms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db) + cms.MountStoreWithDB(tKeyParams, sdk.StoreTypeTransient, db) err := cms.LoadLatestVersion() require.Nil(t, err) diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index eab30f5f190..f9a816641f8 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -30,8 +30,8 @@ func (suite *SubspaceTestSuite) SetupTest() { db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) - ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db, 0) - ms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db, 0) + ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) suite.NoError(ms.LoadLatestVersion()) encCfg := simapp.MakeEncodingConfig() diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 0c63df343d2..853c98c92dc 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -34,7 +34,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0) + rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, int64(0), rs.LastCommitID().Version) @@ -51,7 +51,7 @@ func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil, 0) + rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, ver, rs.LastCommitID().Version) From 5df162620e8b37585a27a808f97ce216937587e1 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 26 Aug 2020 19:04:27 +0200 Subject: [PATCH 13/44] Update to latest iavl --- baseapp/abci.go | 7 +++++++ baseapp/baseapp.go | 2 +- baseapp/baseapp_test.go | 14 +++++++------- go.mod | 2 +- go.sum | 13 +++++++++++++ server/mock/app.go | 2 +- server/mock/store.go | 4 ++++ simapp/app.go | 11 ----------- simapp/export_test.go | 2 +- store/iavl/store.go | 26 ++++++++++++++++++++------ store/iavl/tree.go | 15 +++++++++++---- store/rootmulti/store.go | 17 +++++++++++++++++ store/types/store.go | 11 +++++++++++ x/upgrade/types/storeloader_test.go | 4 ++-- 14 files changed, 96 insertions(+), 34 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 88f9ce6182b..ef145ac540c 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -25,6 +25,13 @@ import ( func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { initHeader := tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} + if req.InitialHeight > 0 { + err := app.cms.SetInitialVersion(uint64(req.InitialHeight)) + if err != nil { + panic(err) + } + } + // initialize the deliver state and check state with a correct header app.setDeliverState(initHeader) app.setCheckState(initHeader) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 1dd9630df30..e4115184156 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -155,7 +155,7 @@ func (app *BaseApp) Logger() log.Logger { // MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp // multistore. -func (app *BaseApp) MountStores(initialVersion int64, keys ...sdk.StoreKey) { +func (app *BaseApp) MountStores(keys ...sdk.StoreKey) { for _, key := range keys { switch key.(type) { case *sdk.KVStoreKey: diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index c3191390780..05038ce2c36 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -96,7 +96,7 @@ func setupBaseApp(t *testing.T, options ...func(*BaseApp)) *BaseApp { app := newBaseApp(t.Name(), options...) require.Equal(t, t.Name(), app.Name()) - app.MountStores(0, capKey1, capKey2) + app.MountStores(capKey1, capKey2) app.SetParamStore(¶mStore{db: dbm.NewMemDB()}) // stores are mounted @@ -150,7 +150,7 @@ func TestLoadVersion(t *testing.T) { // reload with LoadLatestVersion app = NewBaseApp(name, logger, db, nil, pruningOpt) - app.MountStores(0) + app.MountStores() err = app.LoadLatestVersion() require.Nil(t, err) testLoadVersionHelper(t, app, int64(2), commitID2) @@ -237,7 +237,7 @@ func TestSetLoader(t *testing.T) { opts = append(opts, tc.setLoader) } app := NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) - app.MountStores(0, sdk.NewKVStoreKey(tc.loadStoreKey)) + app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) err := app.LoadLatestVersion() require.Nil(t, err) @@ -319,7 +319,7 @@ func TestLoadVersionPruning(t *testing.T) { // make a cap key and mount the store capKey := sdk.NewKVStoreKey("key1") - app.MountStores(0, capKey) + app.MountStores(capKey) err := app.LoadLatestVersion() // needed to make stores non-nil require.Nil(t, err) @@ -354,7 +354,7 @@ func TestLoadVersionPruning(t *testing.T) { // reload with LoadLatestVersion, check it loads last version app = NewBaseApp(name, logger, db, nil, pruningOpt) - app.MountStores(0, capKey) + app.MountStores(capKey) err = app.LoadLatestVersion() require.Nil(t, err) @@ -472,7 +472,7 @@ func TestInitChainer(t *testing.T) { app := NewBaseApp(name, logger, db, nil) capKey := sdk.NewKVStoreKey("main") capKey2 := sdk.NewKVStoreKey("key2") - app.MountStores(0, capKey, capKey2) + app.MountStores(capKey, capKey2) // set a value in the store on init chain key, value := []byte("hello"), []byte("goodbye") @@ -517,7 +517,7 @@ func TestInitChainer(t *testing.T) { // reload app app = NewBaseApp(name, logger, db, nil) app.SetInitChainer(initChainer) - app.MountStores(0, capKey, capKey2) + app.MountStores(capKey, capKey2) err = app.LoadLatestVersion() // needed to make stores non-nil require.Nil(t, err) require.Equal(t, int64(1), app.LastBlockHeight()) diff --git a/go.mod b/go.mod index 76105464a64..17ddb239a47 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/btcsuite/btcutil v1.0.2 github.com/confio/ics23/go v0.0.0-20200804135932-65ad804e8539 github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d - github.com/cosmos/iavl v0.15.0-rc2 + github.com/cosmos/iavl v0.15.0-rc2.0.20200826144708-9ea987bad050 github.com/cosmos/ledger-cosmos-go v0.11.1 github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25 github.com/gogo/gateway v1.1.0 diff --git a/go.sum b/go.sum index 512a0c04046..e9b3ce8499a 100644 --- a/go.sum +++ b/go.sum @@ -109,6 +109,8 @@ github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fj github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/iavl v0.15.0-rc2 h1:4HI/LYLjWUnou8dehPD+NqEsDc8uamJOU2yHcqdTKv8= github.com/cosmos/iavl v0.15.0-rc2/go.mod h1:bXLXbwmww0kYtAYRCYNXR/k44lWaK8rIZJlCmqSK8lQ= +github.com/cosmos/iavl v0.15.0-rc2.0.20200826144708-9ea987bad050 h1:BUVAB5KQg+uH/dTuaXhm+AKh/LC9OoYJqPezPKvONnY= +github.com/cosmos/iavl v0.15.0-rc2.0.20200826144708-9ea987bad050/go.mod h1:tzsrhsQoOLtkvm1ASF1MpiipQDw0EMGcQWtAgo6S56Y= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI= @@ -165,6 +167,7 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.10.0 h1:dXFJfIHVvUcpSgDOV+Ne6t7jXri8Tfv2uOLHUZ2XNuo= @@ -246,11 +249,13 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.1/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw= github.com/grpc-ecosystem/grpc-gateway v1.14.7 h1:Nk5kuHrnWUTf/0GL1a/vchH/om9Ap2/HnVna+jYZgTY= github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= @@ -596,6 +601,7 @@ golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxT golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 h1:A1gGSx58LAGVHUUsOf7IiR0u8Xb6W51gRwfDBhkdcaw= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -611,6 +617,7 @@ golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCc golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -633,6 +640,7 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -668,12 +676,14 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= @@ -709,6 +719,7 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= @@ -738,6 +749,7 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= @@ -755,6 +767,7 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI= google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.31.1 h1:SfXqXS5hkufcdZ/mHtYCh53P2b+92WQq/DZcKLgsFRs= diff --git a/server/mock/app.go b/server/mock/app.go index 8dedc9746e2..e3fdd2c9147 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -32,7 +32,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx) // Set mounts for BaseApp's MultiStore. - baseApp.MountStores(0, capKeyMainStore) + baseApp.MountStores(capKeyMainStore) baseApp.SetInitChainer(InitChainer(capKeyMainStore)) diff --git a/server/mock/store.go b/server/mock/store.go index d8e9cee1c20..a8dd0edaa68 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -99,6 +99,10 @@ func (ms multiStore) SetInterBlockCache(_ sdk.MultiStorePersistentCache) { panic("not implemented") } +func (ms multiStore) SetInitialVersion(version uint64) error { + panic("not implemented") +} + var _ sdk.KVStore = kvStore{} type kvStore struct { diff --git a/simapp/app.go b/simapp/app.go index 4edfef5579a..48c25ecbb33 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -417,17 +417,6 @@ func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Re // InitChainer application update at chain initialization func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - // If we get a non-null initial height from ABCI InitChain, then we mount - // the stores (again) at that height. - if req.InitialHeight != 0 { - app.MountKVStores(app.keys) - } - - err := app.LoadLatestVersion() - if err != nil { - tmos.Exit(err.Error()) - } - var genesisState GenesisState app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState) return app.mm.InitGenesis(ctx, app.appCodec, genesisState) diff --git a/simapp/export_test.go b/simapp/export_test.go index ec3f5eaa048..ef757f8ddd7 100644 --- a/simapp/export_test.go +++ b/simapp/export_test.go @@ -87,7 +87,7 @@ func TestSimappInitialHeight(t *testing.T) { app.Commit() // Check that initial height is taken into account. - require.Equal(t, 4, app.LastBlockHeight()) + require.Equal(t, int64(4), app.LastBlockHeight()) } func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, client.Context, *server.Context) { diff --git a/store/iavl/store.go b/store/iavl/store.go index 2e389f68978..f7449318d23 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -26,15 +26,16 @@ const ( ) var ( - _ types.KVStore = (*Store)(nil) - _ types.CommitStore = (*Store)(nil) - _ types.CommitKVStore = (*Store)(nil) - _ types.Queryable = (*Store)(nil) + _ types.KVStore = (*Store)(nil) + _ types.CommitStore = (*Store)(nil) + _ types.CommitKVStore = (*Store)(nil) + _ types.Queryable = (*Store)(nil) + _ types.StoreWithVersion = (*Store)(nil) ) // Store Implements types.KVStore and CommitKVStore. type Store struct { - tree Tree + tree ImmutableTree } // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the @@ -205,8 +206,21 @@ func (st *Store) ReverseIterator(start, end []byte) types.Iterator { return newIAVLIterator(iTree, start, end, false) } +// SetInitialVersion sets the initial version of the IAVL tree. It is used when +// starting a new chain at an arbitrary height. +func (st *Store) SetInitialVersion(version uint64) error { + mutableTree, ok := st.tree.(MutableTree) + if !ok { + return fmt.Errorf("cannot set initial version on an immutable tree") + } + + mutableTree.SetInitialVersion(version) + + return nil +} + // Handle gatest the latest height, if height is 0 -func getHeight(tree Tree, req abci.RequestQuery) int64 { +func getHeight(tree ImmutableTree, req abci.RequestQuery) int64 { height := req.Height if height == 0 { latest := tree.Version() diff --git a/store/iavl/tree.go b/store/iavl/tree.go index 66e209bcdd5..d9f8b51659d 100644 --- a/store/iavl/tree.go +++ b/store/iavl/tree.go @@ -7,16 +7,16 @@ import ( ) var ( - _ Tree = (*immutableTree)(nil) - _ Tree = (*iavl.MutableTree)(nil) + _ ImmutableTree = (*immutableTree)(nil) + _ MutableTree = (*iavl.MutableTree)(nil) ) type ( - // Tree defines an interface that both mutable and immutable IAVL trees + // ImmutableTree defines an interface that immutable IAVL trees // must implement. For mutable IAVL trees, the interface is directly // implemented by an iavl.MutableTree. For an immutable IAVL tree, a wrapper // must be made. - Tree interface { + ImmutableTree interface { Has(key []byte) bool Get(key []byte) (index int64, value []byte) Set(key, value []byte) bool @@ -32,6 +32,13 @@ type ( GetImmutable(version int64) (*iavl.ImmutableTree, error) } + // MutableTree defines an interface that mutable IAVL trees + // must implement. + MutableTree interface { + ImmutableTree + SetInitialVersion(version uint64) + } + // immutableTree is a simple wrapper around a reference to an iavl.ImmutableTree // that implements the Tree interface. It should only be used for querying // and iteration, specifically at previous heights. diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 66b3ab51b2d..ca8b7987bdc 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -503,6 +503,23 @@ func (rs *Store) Query(req abci.RequestQuery) abci.ResponseQuery { return res } +// SetInitialVersion sets the initial version of the IAVL tree. It is used when +// starting a new chain at an arbitrary height. +func (rs *Store) SetInitialVersion(version uint64) error { + // Loop through all the stores, if it's a KV store, then set initial + // version on it. + for _, commitKVStore := range rs.stores { + if storeWithVersion, ok := commitKVStore.(types.StoreWithVersion); ok { + err := storeWithVersion.SetInitialVersion(version) + if err != nil { + return err + } + } + } + + return nil +} + // parsePath expects a format like /[/] // Must start with /, subpath may be empty // Returns error if it doesn't start with / diff --git a/store/types/store.go b/store/types/store.go index 4ca8f442c05..85c260b3e39 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -165,6 +165,10 @@ type CommitMultiStore interface { // Set an inter-block (persistent) cache that maintains a mapping from // StoreKeys to CommitKVStores. SetInterBlockCache(MultiStorePersistentCache) + + // SetInitialVersion sets the initial version of the IAVL tree. It is used when + // starting a new chain at an arbitrary height. + SetInitialVersion(version uint64) error } //---------subsp------------------------------- @@ -394,3 +398,10 @@ type MultiStorePersistentCache interface { // Reset the entire set of internal caches. Reset() } + +// StoreWithVersion is a store that has versions. +type StoreWithVersion interface { + // SetInitialVersion sets the initial version of the IAVL tree. It is used when + // starting a new chain at an arbitrary height. + SetInitialVersion(version uint64) error +} diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 853c98c92dc..7fd147013e5 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -123,8 +123,8 @@ func TestSetLoader(t *testing.T) { app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) capKey := sdk.NewKVStoreKey("main") - app.MountStores(0, capKey) - app.MountStores(0, sdk.NewKVStoreKey(tc.loadStoreKey)) + app.MountStores(capKey) + app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) err := app.LoadLatestVersion() require.Nil(t, err) From 9d16e9e76760af72fd57cdb1c55184c2cc951732 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 26 Aug 2020 19:06:16 +0200 Subject: [PATCH 14/44] Check height in test --- simapp/export_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/simapp/export_test.go b/simapp/export_test.go index ef757f8ddd7..fc4fcdd71c0 100644 --- a/simapp/export_test.go +++ b/simapp/export_test.go @@ -72,6 +72,7 @@ func TestSimappInitialHeight(t *testing.T) { if err != nil { t.Fatalf("error unmarshaling exported genesis doc: %s", err) } + require.Equal(t, int64(4), exportedGenDoc.InitialHeight) err = saveGenesisFile(genDoc, tempDir2) // Run a new app, with exported genesis. From 5dfa9556313d10e2a5d69f8ec2f92760afa650b5 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 27 Aug 2020 09:45:40 +0200 Subject: [PATCH 15/44] Make it work --- server/export.go | 2 +- simapp/export_test.go | 10 +++++----- store/iavl/store.go | 2 +- store/rootmulti/store.go | 17 +++++++++++++++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/server/export.go b/server/export.go index 4d4365fe6be..fcb3098a1db 100644 --- a/server/export.go +++ b/server/export.go @@ -76,7 +76,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com doc.AppState = appState doc.Validators = validators - doc.InitialHeight = appHeight + 1 + doc.InitialHeight = appHeight doc.ConsensusParams = &tmproto.ConsensusParams{ Block: tmproto.BlockParams{ MaxBytes: cp.Block.MaxBytes, diff --git a/simapp/export_test.go b/simapp/export_test.go index fc4fcdd71c0..814edae50a3 100644 --- a/simapp/export_test.go +++ b/simapp/export_test.go @@ -72,12 +72,12 @@ func TestSimappInitialHeight(t *testing.T) { if err != nil { t.Fatalf("error unmarshaling exported genesis doc: %s", err) } - require.Equal(t, int64(4), exportedGenDoc.InitialHeight) + require.Equal(t, int64(3), exportedGenDoc.InitialHeight) err = saveGenesisFile(genDoc, tempDir2) // Run a new app, with exported genesis. - app, clientCtx, serverCtx = setupApp(t, tempDir2) - app.InitChain( + newApp, _, _ := setupApp(t, tempDir2) + newApp.InitChain( abci.RequestInitChain{ Validators: []abci.ValidatorUpdate{}, ConsensusParams: simapp.DefaultConsensusParams, @@ -85,10 +85,10 @@ func TestSimappInitialHeight(t *testing.T) { InitialHeight: exportedGenDoc.InitialHeight, }, ) - app.Commit() + newApp.Commit() // Check that initial height is taken into account. - require.Equal(t, int64(4), app.LastBlockHeight()) + require.Equal(t, int64(4), newApp.LastBlockHeight()) } func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, client.Context, *server.Context) { diff --git a/store/iavl/store.go b/store/iavl/store.go index f7449318d23..c45ef26a3bd 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -110,7 +110,7 @@ func (st *Store) Commit() types.CommitID { } } -// Implements Committer. +// LastCommitID implements Committer. func (st *Store) LastCommitID() types.CommitID { return types.CommitID{ Version: st.tree.Version(), diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index ca8b7987bdc..564816b8ca5 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -40,6 +40,7 @@ type Store struct { keysByName map[string]types.StoreKey lazyLoading bool pruneHeights []int64 + initialVersion uint64 traceWriter io.Writer traceContext types.TraceContext @@ -300,7 +301,17 @@ func (rs *Store) LastCommitID() types.CommitID { // Commit implements Committer/CommitStore. func (rs *Store) Commit() types.CommitID { - previousHeight := rs.lastCommitInfo.Version + var previousHeight int64 + if rs.lastCommitInfo.GetVersion() > 0 { + // This case means that there was already a previous commit in the + // store. we continue from this commit version. + previousHeight = rs.lastCommitInfo.Version + } else { + // This case means that no commit has been registered in the store, we + // start from initialVersion (or 0 if not set). + previousHeight = int64(rs.initialVersion) + } + version := previousHeight + 1 rs.lastCommitInfo = commitStores(version, rs.stores) @@ -506,7 +517,9 @@ func (rs *Store) Query(req abci.RequestQuery) abci.ResponseQuery { // SetInitialVersion sets the initial version of the IAVL tree. It is used when // starting a new chain at an arbitrary height. func (rs *Store) SetInitialVersion(version uint64) error { - // Loop through all the stores, if it's a KV store, then set initial + rs.initialVersion = version + + // Loop through all the stores, if it's an IAVL store, then set initial // version on it. for _, commitKVStore := range rs.stores { if storeWithVersion, ok := commitKVStore.(types.StoreWithVersion); ok { From 4aa9bcc20347e7cfc4fa43ea6de8e08f3f9d4580 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 27 Aug 2020 10:28:25 +0200 Subject: [PATCH 16/44] Add more tests --- baseapp/abci.go | 2 +- server/mock/store.go | 2 +- store/iavl/store.go | 4 +-- store/iavl/store_test.go | 53 +++++++++++++++++++++++++++++++++++ store/rootmulti/store.go | 4 +-- store/rootmulti/store_test.go | 11 ++++++++ store/types/store.go | 4 +-- 7 files changed, 72 insertions(+), 8 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index ef145ac540c..894d2da543b 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -26,7 +26,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC initHeader := tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} if req.InitialHeight > 0 { - err := app.cms.SetInitialVersion(uint64(req.InitialHeight)) + err := app.cms.SetInitialVersion(req.InitialHeight) if err != nil { panic(err) } diff --git a/server/mock/store.go b/server/mock/store.go index a8dd0edaa68..7bc42d94b30 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -99,7 +99,7 @@ func (ms multiStore) SetInterBlockCache(_ sdk.MultiStorePersistentCache) { panic("not implemented") } -func (ms multiStore) SetInitialVersion(version uint64) error { +func (ms multiStore) SetInitialVersion(version int64) error { panic("not implemented") } diff --git a/store/iavl/store.go b/store/iavl/store.go index c45ef26a3bd..1c77407c64c 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -208,13 +208,13 @@ func (st *Store) ReverseIterator(start, end []byte) types.Iterator { // SetInitialVersion sets the initial version of the IAVL tree. It is used when // starting a new chain at an arbitrary height. -func (st *Store) SetInitialVersion(version uint64) error { +func (st *Store) SetInitialVersion(version int64) error { mutableTree, ok := st.tree.(MutableTree) if !ok { return fmt.Errorf("cannot set initial version on an immutable tree") } - mutableTree.SetInitialVersion(version) + mutableTree.SetInitialVersion(uint64(version)) return nil } diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index 56d439c3915..7fcdd8dcbf0 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -526,3 +526,56 @@ func BenchmarkIAVLIteratorNext(b *testing.B) { } } } + +func TestSetInitialVersion(t *testing.T) { + testCases := []struct { + name string + storeFn func(db *dbm.MemDB) *Store + expErr bool + expErrMsg string + }{ + { + "work with a mutable tree", + func(db *dbm.MemDB) *Store { + tree, err := iavl.NewMutableTree(db, cacheSize) + require.NoError(t, err) + store := UnsafeNewStore(tree) + + return store + }, false, "", + }, + { + "throws error on immutable tree", + func(db *dbm.MemDB) *Store { + tree, err := iavl.NewMutableTree(db, cacheSize) + require.NoError(t, err) + store := UnsafeNewStore(tree) + _, version, err := store.tree.SaveVersion() + require.NoError(t, err) + require.Equal(t, int64(1), version) + store, err = store.GetImmutable(1) + require.NoError(t, err) + + return store + }, true, "cannot set initial version on an immutable tree", + }, + } + + for _, tc := range testCases { + tc := tc + + t.Run(tc.name, func(t *testing.T) { + db := dbm.NewMemDB() + store := tc.storeFn(db) + err := store.SetInitialVersion(5) + + if tc.expErr { + require.Error(t, err) + require.EqualError(t, err, tc.expErrMsg) + } else { + cid := store.Commit() + require.Equal(t, int64(5), cid.GetVersion()) + } + }) + } +} diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 564816b8ca5..494504bb443 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -40,7 +40,7 @@ type Store struct { keysByName map[string]types.StoreKey lazyLoading bool pruneHeights []int64 - initialVersion uint64 + initialVersion int64 traceWriter io.Writer traceContext types.TraceContext @@ -516,7 +516,7 @@ func (rs *Store) Query(req abci.RequestQuery) abci.ResponseQuery { // SetInitialVersion sets the initial version of the IAVL tree. It is used when // starting a new chain at an arbitrary height. -func (rs *Store) SetInitialVersion(version uint64) error { +func (rs *Store) SetInitialVersion(version int64) error { rs.initialVersion = version // Loop through all the stores, if it's an IAVL store, then set initial diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index 1166adcc64a..bf9b408dfe3 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -505,6 +505,17 @@ func TestMultiStore_PruningRestart(t *testing.T) { } } +func TestSetInitialVersion(t *testing.T) { + db := dbm.NewMemDB() + multi := newMultiStoreWithMounts(db, types.PruneNothing) + + multi.SetInitialVersion(5) + require.Equal(t, int64(5), multi.initialVersion) + + multi.Commit() + require.Equal(t, int64(6), multi.LastCommitID().Version) +} + //----------------------------------------------------------------------- // utils diff --git a/store/types/store.go b/store/types/store.go index 85c260b3e39..7dcffc5f51d 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -168,7 +168,7 @@ type CommitMultiStore interface { // SetInitialVersion sets the initial version of the IAVL tree. It is used when // starting a new chain at an arbitrary height. - SetInitialVersion(version uint64) error + SetInitialVersion(version int64) error } //---------subsp------------------------------- @@ -403,5 +403,5 @@ type MultiStorePersistentCache interface { type StoreWithVersion interface { // SetInitialVersion sets the initial version of the IAVL tree. It is used when // starting a new chain at an arbitrary height. - SetInitialVersion(version uint64) error + SetInitialVersion(version int64) error } From bcbb2438b0668cc596658aa464b5d5633e979153 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 27 Aug 2020 10:29:58 +0200 Subject: [PATCH 17/44] Rename interface --- store/iavl/store.go | 10 +++++----- store/rootmulti/store.go | 2 +- store/types/store.go | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/store/iavl/store.go b/store/iavl/store.go index 1c77407c64c..45a7e82e114 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -26,11 +26,11 @@ const ( ) var ( - _ types.KVStore = (*Store)(nil) - _ types.CommitStore = (*Store)(nil) - _ types.CommitKVStore = (*Store)(nil) - _ types.Queryable = (*Store)(nil) - _ types.StoreWithVersion = (*Store)(nil) + _ types.KVStore = (*Store)(nil) + _ types.CommitStore = (*Store)(nil) + _ types.CommitKVStore = (*Store)(nil) + _ types.Queryable = (*Store)(nil) + _ types.StoreWithInitialVersion = (*Store)(nil) ) // Store Implements types.KVStore and CommitKVStore. diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 494504bb443..f092ce37abd 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -522,7 +522,7 @@ func (rs *Store) SetInitialVersion(version int64) error { // Loop through all the stores, if it's an IAVL store, then set initial // version on it. for _, commitKVStore := range rs.stores { - if storeWithVersion, ok := commitKVStore.(types.StoreWithVersion); ok { + if storeWithVersion, ok := commitKVStore.(types.StoreWithInitialVersion); ok { err := storeWithVersion.SetInitialVersion(version) if err != nil { return err diff --git a/store/types/store.go b/store/types/store.go index 7dcffc5f51d..edb4f8ce056 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -399,8 +399,9 @@ type MultiStorePersistentCache interface { Reset() } -// StoreWithVersion is a store that has versions. -type StoreWithVersion interface { +// StoreWithInitialVersion is a store that can have an arbitrary initial +// version. +type StoreWithInitialVersion interface { // SetInitialVersion sets the initial version of the IAVL tree. It is used when // starting a new chain at an arbitrary height. SetInitialVersion(version int64) error From 7fdab5d4c6662ace6a0909dab67606866f1f1930 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 27 Aug 2020 12:03:48 +0200 Subject: [PATCH 18/44] Use struct isntead of 6 args --- server/export.go | 22 +++++++++++----------- server/export_test.go | 3 ++- server/types/app.go | 15 ++++++++++++++- simapp/app_test.go | 2 +- simapp/export.go | 18 +++++++++++------- simapp/export_test.go | 3 ++- simapp/sim_test.go | 10 +++++----- simapp/simd/cmd/root.go | 7 ++----- simapp/types.go | 6 ++---- simapp/utils.go | 4 ++-- 10 files changed, 52 insertions(+), 38 deletions(-) diff --git a/server/export.go b/server/export.go index fcb3098a1db..a0bec979617 100644 --- a/server/export.go +++ b/server/export.go @@ -64,7 +64,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight) jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs) - appState, validators, appHeight, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs) + exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs) if err != nil { return fmt.Errorf("error exporting state: %v", err) } @@ -74,23 +74,23 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return err } - doc.AppState = appState - doc.Validators = validators - doc.InitialHeight = appHeight + doc.AppState = exported.AppState + doc.Validators = exported.Validators + doc.InitialHeight = exported.Height doc.ConsensusParams = &tmproto.ConsensusParams{ Block: tmproto.BlockParams{ - MaxBytes: cp.Block.MaxBytes, - MaxGas: cp.Block.MaxGas, + MaxBytes: exported.ConsensusParams.Block.MaxBytes, + MaxGas: exported.ConsensusParams.Block.MaxGas, TimeIotaMs: doc.ConsensusParams.Block.TimeIotaMs, }, Evidence: tmproto.EvidenceParams{ - MaxAgeNumBlocks: cp.Evidence.MaxAgeNumBlocks, - MaxAgeDuration: cp.Evidence.MaxAgeDuration, - MaxNum: cp.Evidence.MaxNum, - ProofTrialPeriod: cp.Evidence.ProofTrialPeriod, + MaxAgeNumBlocks: exported.ConsensusParams.Evidence.MaxAgeNumBlocks, + MaxAgeDuration: exported.ConsensusParams.Evidence.MaxAgeDuration, + MaxNum: exported.ConsensusParams.Evidence.MaxNum, + ProofTrialPeriod: exported.ConsensusParams.Evidence.ProofTrialPeriod, }, Validator: tmproto.ValidatorParams{ - PubKeyTypes: cp.Validator.PubKeyTypes, + PubKeyTypes: exported.ConsensusParams.Validator.PubKeyTypes, }, } diff --git a/server/export_test.go b/server/export_test.go index 9f31216d7a5..84c813cd1bc 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/types/errors" @@ -110,7 +111,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t app.Commit() cmd := ExportCmd( - func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) { + func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (types.ExportedApp, error) { return app.ExportAppStateAndValidators(true, []string{}) }, tempDir) diff --git a/server/types/app.go b/server/types/app.go index 4aabb0a6bfe..db1b2af8c77 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -42,7 +42,20 @@ type ( // application using various configurations. AppCreator func(log.Logger, dbm.DB, io.Writer, AppOptions) Application + // ExportedApp represents an exported app state, along with + // validators, consensus params and latest app height. + ExportedApp struct { + // AppState is the application state as JSON. + AppState json.RawMessage + // Validators is the exported validator set. + Validators []tmtypes.GenesisValidator + // Height is the app's latest block height. + Height int64 + // ConsensusParams are the exported consensus params for ABCI. + ConsensusParams *abci.ConsensusParams + } + // AppExporter is a function that dumps all app state to // JSON-serializable structure and returns the current validator set. - AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) + AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (ExportedApp, error) ) diff --git a/simapp/app_test.go b/simapp/app_test.go index 79d40562ad1..4a879756228 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -31,7 +31,7 @@ func TestSimAppExport(t *testing.T) { // Making a new app object with the db, so that initchain hasn't been called app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig()) - _, _, _, _, err = app2.ExportAppStateAndValidators(false, []string{}) + _, err = app2.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } diff --git a/simapp/export.go b/simapp/export.go index 56c87750d03..ac284857d63 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -4,10 +4,9 @@ import ( "encoding/json" "log" - abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmtypes "github.com/tendermint/tendermint/types" + servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" @@ -19,7 +18,7 @@ import ( // file. func (app *SimApp) ExportAppStateAndValidators( forZeroHeight bool, jailAllowedAddrs []string, -) (appState json.RawMessage, validators []tmtypes.GenesisValidator, height int64, cp *abci.ConsensusParams, err error) { +) (servertypes.ExportedApp, error) { // as if they could withdraw from the start of the next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) @@ -29,13 +28,18 @@ func (app *SimApp) ExportAppStateAndValidators( } genState := app.mm.ExportGenesis(ctx, app.appCodec) - appState, err = json.MarshalIndent(genState, "", " ") + appState, err := json.MarshalIndent(genState, "", " ") if err != nil { - return nil, nil, 0, nil, err + return servertypes.ExportedApp{}, err } - validators = staking.WriteValidators(ctx, app.StakingKeeper) - return appState, validators, app.LastBlockHeight(), app.BaseApp.GetConsensusParams(ctx), nil + validators := staking.WriteValidators(ctx, app.StakingKeeper) + return servertypes.ExportedApp{ + AppState: appState, + Validators: validators, + Height: app.LastBlockHeight(), + ConsensusParams: app.BaseApp.GetConsensusParams(ctx), + }, nil } // prepare for fresh start at zero height diff --git a/simapp/export_test.go b/simapp/export_test.go index 814edae50a3..bb8b494ab3f 100644 --- a/simapp/export_test.go +++ b/simapp/export_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" + servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/types/errors" @@ -52,7 +53,7 @@ func TestSimappInitialHeight(t *testing.T) { // Create the export command. cmd := server.ExportCmd( - func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) { + func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (servertypes.ExportedApp, error) { return app.ExportAppStateAndValidators(true, []string{}) }, tempDir1) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 3ad15167015..b11090c1465 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -131,7 +131,7 @@ func TestAppImportExport(t *testing.T) { fmt.Printf("exporting genesis...\n") - appState, _, _, consensusParams, err := app.ExportAppStateAndValidators(false, []string{}) + exported, err := app.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err) fmt.Printf("importing genesis...\n") @@ -148,13 +148,13 @@ func TestAppImportExport(t *testing.T) { require.Equal(t, "SimApp", newApp.Name()) var genesisState GenesisState - err = json.Unmarshal(appState, &genesisState) + err = json.Unmarshal(exported.AppState, &genesisState) require.NoError(t, err) ctxA := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) ctxB := newApp.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) newApp.mm.InitGenesis(ctxB, app.AppCodec(), genesisState) - newApp.StoreConsensusParams(ctxB, consensusParams) + newApp.StoreConsensusParams(ctxB, exported.ConsensusParams) fmt.Printf("comparing stores...\n") @@ -232,7 +232,7 @@ func TestAppSimulationAfterImport(t *testing.T) { fmt.Printf("exporting genesis...\n") - appState, _, _, _, err := app.ExportAppStateAndValidators(true, []string{}) + exported, err := app.ExportAppStateAndValidators(true, []string{}) require.NoError(t, err) fmt.Printf("importing genesis...\n") @@ -249,7 +249,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.Equal(t, "SimApp", newApp.Name()) newApp.InitChain(abci.RequestInitChain{ - AppStateBytes: appState, + AppStateBytes: exported.AppState, }) _, _, err = simulation.SimulateFromSeed( diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 10ab61c5e52..3770be6dfdb 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -2,7 +2,6 @@ package cmd import ( "context" - "encoding/json" "io" "os" @@ -11,10 +10,8 @@ import ( "github.com/spf13/cast" "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" - tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" @@ -193,7 +190,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty func exportAppStateAndTMValidators( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, -) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) { +) (servertypes.ExportedApp, error) { encCfg := simapp.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd. encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry) @@ -202,7 +199,7 @@ func exportAppStateAndTMValidators( simApp = simapp.NewSimApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), encCfg) if err := simApp.LoadHeight(height); err != nil { - return nil, nil, 0, nil, err + return servertypes.ExportedApp{}, err } } else { simApp = simapp.NewSimApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), encCfg) diff --git a/simapp/types.go b/simapp/types.go index dfb19eb0df7..0e190af1bc9 100644 --- a/simapp/types.go +++ b/simapp/types.go @@ -1,12 +1,10 @@ package simapp import ( - "encoding/json" - abci "github.com/tendermint/tendermint/abci/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -36,7 +34,7 @@ type App interface { // Exports the state of the application for a genesis file. ExportAppStateAndValidators( forZeroHeight bool, jailAllowedAddrs []string, - ) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) + ) (types.ExportedApp, error) // All the registered module account addreses. ModuleAccountAddrs() map[string]bool diff --git a/simapp/utils.go b/simapp/utils.go index 9dfa6fe5e54..2067ed54b10 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -79,12 +79,12 @@ func CheckExportSimulation( ) error { if config.ExportStatePath != "" { fmt.Println("exporting app state...") - appState, _, _, _, err := app.ExportAppStateAndValidators(false, nil) + exported, err := app.ExportAppStateAndValidators(false, nil) if err != nil { return err } - if err := ioutil.WriteFile(config.ExportStatePath, []byte(appState), 0600); err != nil { + if err := ioutil.WriteFile(config.ExportStatePath, []byte(exported.AppState), 0600); err != nil { return err } } From 68390810e475df81cbb9b49d13eab07ed61a9f30 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 27 Aug 2020 12:07:37 +0200 Subject: [PATCH 19/44] Fix lint --- store/rootmulti/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index f092ce37abd..180450db45f 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -309,7 +309,7 @@ func (rs *Store) Commit() types.CommitID { } else { // This case means that no commit has been registered in the store, we // start from initialVersion (or 0 if not set). - previousHeight = int64(rs.initialVersion) + previousHeight = rs.initialVersion } version := previousHeight + 1 From 0b82fec83e7d849833a0f86fb3bef2063b55e035 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 27 Aug 2020 12:15:14 +0200 Subject: [PATCH 20/44] Remove stray fmt --- types/module/module.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index 0e91b6c7a02..34904f5d797 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -30,7 +30,6 @@ package module import ( "encoding/json" - "fmt" "github.com/gogo/protobuf/grpc" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -306,7 +305,6 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, genesisD // use these validator updates if provided, the module manager assumes // only one module will update the validator set if len(moduleValUpdates) > 0 { - fmt.Println("InitGenesis moduleName=", moduleName, "moduleValUpdates=", moduleValUpdates) if len(validatorUpdates) > 0 { panic("validator InitGenesis updates already set by a previous module") } From ca6b7c131e001a39ad47472b644f1dfba931dfe9 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 27 Aug 2020 16:05:03 +0200 Subject: [PATCH 21/44] Revert go mod/sum --- go.mod | 2 +- go.sum | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 040578fbf54..f10eee221ec 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/btcsuite/btcutil v1.0.2 github.com/confio/ics23/go v0.0.0-20200804135932-65ad804e8539 github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d - github.com/cosmos/iavl v0.15.0-rc2.0.20200826144708-9ea987bad050 + github.com/cosmos/iavl v0.15.0-rc2 github.com/cosmos/ledger-cosmos-go v0.11.1 github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25 github.com/gogo/gateway v1.1.0 diff --git a/go.sum b/go.sum index 812129d8302..85c103b1ecd 100644 --- a/go.sum +++ b/go.sum @@ -109,8 +109,6 @@ github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fj github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/iavl v0.15.0-rc2 h1:4HI/LYLjWUnou8dehPD+NqEsDc8uamJOU2yHcqdTKv8= github.com/cosmos/iavl v0.15.0-rc2/go.mod h1:bXLXbwmww0kYtAYRCYNXR/k44lWaK8rIZJlCmqSK8lQ= -github.com/cosmos/iavl v0.15.0-rc2.0.20200826144708-9ea987bad050 h1:BUVAB5KQg+uH/dTuaXhm+AKh/LC9OoYJqPezPKvONnY= -github.com/cosmos/iavl v0.15.0-rc2.0.20200826144708-9ea987bad050/go.mod h1:tzsrhsQoOLtkvm1ASF1MpiipQDw0EMGcQWtAgo6S56Y= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI= @@ -167,7 +165,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.10.0 h1:dXFJfIHVvUcpSgDOV+Ne6t7jXri8Tfv2uOLHUZ2XNuo= @@ -249,13 +246,11 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-middleware v1.2.1/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw= github.com/grpc-ecosystem/grpc-gateway v1.14.7 h1:Nk5kuHrnWUTf/0GL1a/vchH/om9Ap2/HnVna+jYZgTY= github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= @@ -605,7 +600,6 @@ golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxT golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 h1:A1gGSx58LAGVHUUsOf7IiR0u8Xb6W51gRwfDBhkdcaw= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -621,7 +615,6 @@ golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCc golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -644,7 +637,6 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -680,14 +672,12 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= @@ -723,7 +713,6 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= @@ -753,7 +742,6 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= @@ -771,7 +759,6 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI= google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.31.1 h1:SfXqXS5hkufcdZ/mHtYCh53P2b+92WQq/DZcKLgsFRs= From 7f0b5739790786ee3df043e13706068ef673c193 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 27 Aug 2020 16:12:13 +0200 Subject: [PATCH 22/44] Install iavl rc3 --- go.mod | 12 +++++------- go.sum | 58 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index f10eee221ec..7dbacf93bdb 100644 --- a/go.mod +++ b/go.mod @@ -9,9 +9,9 @@ require ( github.com/bgentry/speakeasy v0.1.0 github.com/btcsuite/btcd v0.20.1-beta github.com/btcsuite/btcutil v1.0.2 - github.com/confio/ics23/go v0.0.0-20200804135932-65ad804e8539 + github.com/confio/ics23/go v0.0.0-20200817220745-f173e6211efb github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d - github.com/cosmos/iavl v0.15.0-rc2 + github.com/cosmos/iavl v0.15.0-rc3 github.com/cosmos/ledger-cosmos-go v0.11.1 github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25 github.com/gogo/gateway v1.1.0 @@ -24,8 +24,6 @@ require ( github.com/hashicorp/golang-lru v0.5.4 github.com/magiconair/properties v1.8.2 github.com/mattn/go-isatty v0.0.12 - github.com/onsi/ginkgo v1.8.0 // indirect - github.com/onsi/gomega v1.5.0 // indirect github.com/otiai10/copy v1.2.0 github.com/pelletier/go-toml v1.8.0 // indirect github.com/pkg/errors v0.9.1 @@ -44,9 +42,9 @@ require ( github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 github.com/tendermint/go-amino v0.15.1 github.com/tendermint/tendermint v0.34.0-rc3 - github.com/tendermint/tm-db v0.6.1 - golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 - google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 + github.com/tendermint/tm-db v0.6.2 + golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a + google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 google.golang.org/grpc v1.31.1 google.golang.org/protobuf v1.25.0 gopkg.in/yaml.v2 v2.3.0 diff --git a/go.sum b/go.sum index 85c103b1ecd..5362e53fd2b 100644 --- a/go.sum +++ b/go.sum @@ -92,9 +92,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/confio/ics23/go v0.0.0-20200610201322-18c7bd6b2dd3/go.mod h1:W1I3XC8d9N8OTu/ct5VJ84ylcOunZwMXsWkd27nvVts= -github.com/confio/ics23/go v0.0.0-20200804135932-65ad804e8539 h1:4AuX7KNUVdNa/am9yCQRqWMfdDJ86EtFJk/xwf6ntgc= -github.com/confio/ics23/go v0.0.0-20200804135932-65ad804e8539/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg= +github.com/confio/ics23/go v0.0.0-20200817220745-f173e6211efb h1:+7FsS1gZ1Km5LRjGV2hztpier/5i6ngNjvNpxbWP5I0= +github.com/confio/ics23/go v0.0.0-20200817220745-f173e6211efb/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= @@ -107,8 +106,8 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= -github.com/cosmos/iavl v0.15.0-rc2 h1:4HI/LYLjWUnou8dehPD+NqEsDc8uamJOU2yHcqdTKv8= -github.com/cosmos/iavl v0.15.0-rc2/go.mod h1:bXLXbwmww0kYtAYRCYNXR/k44lWaK8rIZJlCmqSK8lQ= +github.com/cosmos/iavl v0.15.0-rc3 h1:rSm60IFfDCD9qDfvXKEmaJhcv0rB5uCbVlBDKsynxqw= +github.com/cosmos/iavl v0.15.0-rc3/go.mod h1:rQ2zK/LuivThMjve3Yr6VkjvCqCXl+fgHCY7quiUA68= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI= @@ -125,8 +124,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger/v2 v2.0.3 h1:inzdf6VF/NZ+tJ8RwwYMjJMvsOALTHYdozn0qSl6XJI= github.com/dgraph-io/badger/v2 v2.0.3/go.mod h1:3KY8+bsP8wI0OEnQJAKpd4wIJW/Mm32yw2j/9FUVnIM= +github.com/dgraph-io/badger/v2 v2.2007.1 h1:t36VcBCpo4SsmAD5M8wVv1ieVzcALyGfaJ92z4ccULM= +github.com/dgraph-io/badger/v2 v2.2007.1/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3 h1:MQLRM35Pp0yAyBYksjbj1nZI/w6eyRY/mWoM1sFf4kU= github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= +github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de h1:t0UHb5vdojIDUqktM6+xJAfScFBsVpXZmqC9dsgJmeA= +github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= @@ -162,9 +165,12 @@ github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVB github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.10.0 h1:dXFJfIHVvUcpSgDOV+Ne6t7jXri8Tfv2uOLHUZ2XNuo= @@ -246,6 +252,7 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.1/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= @@ -381,6 +388,8 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= @@ -388,12 +397,14 @@ github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:v github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= -github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= +github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= -github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= @@ -537,6 +548,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= +github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca h1:Ld/zXl5t4+D69SiV4JoN7kkfvJdOWlPpfxrzxpLMoUk= +github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM= github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s= @@ -549,6 +562,8 @@ github.com/tendermint/tendermint v0.34.0-rc3 h1:d7Fsd5rdbxq4GmJ0kRfx7l7LesQM7e70 github.com/tendermint/tendermint v0.34.0-rc3/go.mod h1:BoHcEpjfpBHc1Be7RQz3AHaXFNObcDG7SNHCev6Or4g= github.com/tendermint/tm-db v0.6.1 h1:w3X87itMPXopcRPlFiqspEKhw4FXihPk2rnFFkP0zGk= github.com/tendermint/tm-db v0.6.1/go.mod h1:m3x9kRP4UFd7JODJL0yBAZqE7wTw+S37uAE90cTx7OA= +github.com/tendermint/tm-db v0.6.2 h1:DOn8jwCdjJblrCFJbtonEIPD1IuJWpbRUUdR8GWE4RM= +github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= @@ -594,12 +609,15 @@ golang.org/x/crypto v0.0.0-20200406173513-056763e48d71/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 h1:A1gGSx58LAGVHUUsOf7IiR0u8Xb6W51gRwfDBhkdcaw= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -615,6 +633,7 @@ golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCc golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -637,8 +656,12 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc h1:zK/HqS5bZxDptfPJNq8v7vJfXtkU7r9TLIoSr1bXaP4= +golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= @@ -672,20 +695,30 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ= +golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -713,10 +746,13 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -742,9 +778,12 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 h1:PDIOdWxZ8eRizhKa1AAvY53xsvLB1cWorMjslvY3VA8= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -759,6 +798,7 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI= google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.31.1 h1:SfXqXS5hkufcdZ/mHtYCh53P2b+92WQq/DZcKLgsFRs= From 76c7a129616095e91d4bff49ef9e2def8ead0367 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 28 Aug 2020 11:51:36 +0200 Subject: [PATCH 23/44] Update comments --- store/rootmulti/store.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 180450db45f..6b50f5caa37 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -90,8 +90,6 @@ func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db db if key == nil { panic("MountIAVLStore() key cannot be nil") } - // If we mount the store again with the same initial version, panic with - // duplicate key error. if _, ok := rs.storesParams[key]; ok { panic(fmt.Sprintf("store duplicate store key %v", key)) } @@ -304,10 +302,10 @@ func (rs *Store) Commit() types.CommitID { var previousHeight int64 if rs.lastCommitInfo.GetVersion() > 0 { // This case means that there was already a previous commit in the - // store. we continue from this commit version. + // store. We continue from that commit version. previousHeight = rs.lastCommitInfo.Version } else { - // This case means that no commit has been registered in the store, we + // This case means that no commit has been made in the store, we // start from initialVersion (or 0 if not set). previousHeight = rs.initialVersion } From 10bc9e6f36e55e449b11b207db76b8d2794f23d5 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 31 Aug 2020 12:24:36 +0200 Subject: [PATCH 24/44] Add fee in network --- testutil/network/network.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testutil/network/network.go b/testutil/network/network.go index 83478271cd5..995d7349421 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -301,8 +301,11 @@ func New(t *testing.T, cfg Config) *Network { require.NoError(t, err) memo := fmt.Sprintf("%s@%s:%s", nodeIDs[i], p2pURL.Hostname(), p2pURL.Port()) + fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdk.NewInt(150))) txBuilder := cfg.TxConfig.NewTxBuilder() require.NoError(t, txBuilder.SetMsgs(createValMsg)) + txBuilder.SetFeeAmount(fee) // Arbitrary fee + txBuilder.SetGasLimit(1000000) // Need at least 100386 txBuilder.SetMemo(memo) txFactory := tx.Factory{} From 255aaa7bc8b461a1f143abaf06187d163b18a329 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 31 Aug 2020 12:35:11 +0200 Subject: [PATCH 25/44] Typo --- store/iavl/store_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index 7fcdd8dcbf0..3037994beb8 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -535,7 +535,7 @@ func TestSetInitialVersion(t *testing.T) { expErrMsg string }{ { - "work with a mutable tree", + "works with a mutable tree", func(db *dbm.MemDB) *Store { tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(t, err) From f6216f67fea8cb3b43d95158682db1cd38b9b5e5 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 31 Aug 2020 13:00:39 +0200 Subject: [PATCH 26/44] Fix logic in commit --- store/rootmulti/store.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 6b50f5caa37..4bb1846f2f9 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -299,18 +299,18 @@ func (rs *Store) LastCommitID() types.CommitID { // Commit implements Committer/CommitStore. func (rs *Store) Commit() types.CommitID { - var previousHeight int64 + var previousHeight, version int64 if rs.lastCommitInfo.GetVersion() > 0 { // This case means that there was already a previous commit in the - // store. We continue from that commit version. - previousHeight = rs.lastCommitInfo.Version + // store. We increment from that commit version. + previousHeight := rs.lastCommitInfo.GetVersion() + version = previousHeight + 1 } else { // This case means that no commit has been made in the store, we // start from initialVersion (or 0 if not set). - previousHeight = rs.initialVersion + version = rs.initialVersion } - version := previousHeight + 1 rs.lastCommitInfo = commitStores(version, rs.stores) // Determine if pruneHeight height needs to be added to the list of heights to From 1f1b6026b91db525acb1ae837ecd93808b9684ab Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 31 Aug 2020 13:03:16 +0200 Subject: [PATCH 27/44] Fix tests --- server/export_test.go | 2 +- testutil/network/network.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/export_test.go b/server/export_test.go index 84c813cd1bc..7c967200761 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -79,7 +79,7 @@ func TestExportCmd_Height(t *testing.T) { t.Fatalf("error unmarshaling exported genesis doc: %s", err) } - require.Equal(t, int64(4), exportedGenDoc.InitialHeight) + require.Equal(t, int64(3), exportedGenDoc.InitialHeight) } func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *tmtypes.GenesisDoc, *cobra.Command) { diff --git a/testutil/network/network.go b/testutil/network/network.go index 995d7349421..3ee11cb7a67 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -301,7 +301,7 @@ func New(t *testing.T, cfg Config) *Network { require.NoError(t, err) memo := fmt.Sprintf("%s@%s:%s", nodeIDs[i], p2pURL.Hostname(), p2pURL.Port()) - fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdk.NewInt(150))) + fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdk.NewInt(0))) txBuilder := cfg.TxConfig.NewTxBuilder() require.NoError(t, txBuilder.SetMsgs(createValMsg)) txBuilder.SetFeeAmount(fee) // Arbitrary fee From 789842a6e7bcf6ad137cdfa00d9e8b9f10b4052b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 31 Aug 2020 14:22:37 +0200 Subject: [PATCH 28/44] Only set initial version on > 1 --- baseapp/abci.go | 2 +- store/rootmulti/store.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 894d2da543b..5db9915aa87 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -25,7 +25,7 @@ import ( func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { initHeader := tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} - if req.InitialHeight > 0 { + if req.InitialHeight > 1 { err := app.cms.SetInitialVersion(req.InitialHeight) if err != nil { panic(err) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 4bb1846f2f9..8e8aa8eace1 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -299,18 +299,18 @@ func (rs *Store) LastCommitID() types.CommitID { // Commit implements Committer/CommitStore. func (rs *Store) Commit() types.CommitID { - var previousHeight, version int64 + var previousHeight int64 if rs.lastCommitInfo.GetVersion() > 0 { // This case means that there was already a previous commit in the // store. We increment from that commit version. - previousHeight := rs.lastCommitInfo.GetVersion() - version = previousHeight + 1 + previousHeight = rs.lastCommitInfo.GetVersion() } else { // This case means that no commit has been made in the store, we // start from initialVersion (or 0 if not set). - version = rs.initialVersion + previousHeight = rs.initialVersion } + version := previousHeight + 1 rs.lastCommitInfo = commitStores(version, rs.stores) // Determine if pruneHeight height needs to be added to the list of heights to From fac4d5e3d72d02b4a46174780721520252118da6 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 31 Aug 2020 15:31:44 +0200 Subject: [PATCH 29/44] Genesis block num = 1 --- x/auth/ante/sigverify.go | 4 ++-- x/slashing/client/cli/cli_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index fc783c6b852..bd73ab66541 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -215,7 +215,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul } // retrieve signer data - genesis := ctx.BlockHeight() == 0 + genesis := ctx.BlockHeight() <= 1 chainID := ctx.ChainID() var accNum uint64 if !genesis { @@ -232,7 +232,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul if err != nil { return ctx, sdkerrors.Wrapf( sdkerrors.ErrUnauthorized, - "signature verification failed; please verify account number (%d) and chain-id (%s)", acc.GetAccountNumber(), ctx.ChainID()) + "signature verification failed; please verify account number (%d) and chain-id (%s)", accNum, chainID) } } } diff --git a/x/slashing/client/cli/cli_test.go b/x/slashing/client/cli/cli_test.go index e925e64336b..fad3c5c2d6e 100644 --- a/x/slashing/client/cli/cli_test.go +++ b/x/slashing/client/cli/cli_test.go @@ -66,7 +66,7 @@ func (s *IntegrationTestSuite) TestGetCmdQuerySigningInfo() { fmt.Sprintf("--%s=1", flags.FlagHeight), }, false, - fmt.Sprintf("{\"address\":\"%s\",\"start_height\":\"0\",\"index_offset\":\"0\",\"jailed_until\":\"1970-01-01T00:00:00Z\",\"tombstoned\":false,\"missed_blocks_counter\":\"0\"}", sdk.ConsAddress(val.PubKey.Address())), + fmt.Sprintf("{\"address\":\"%s\",\"start_height\":\"1\",\"index_offset\":\"0\",\"jailed_until\":\"1970-01-01T00:00:00Z\",\"tombstoned\":false,\"missed_blocks_counter\":\"0\"}", sdk.ConsAddress(val.PubKey.Address())), }, { "valid address (text output)", @@ -80,7 +80,7 @@ func (s *IntegrationTestSuite) TestGetCmdQuerySigningInfo() { index_offset: "0" jailed_until: "1970-01-01T00:00:00Z" missed_blocks_counter: "0" -start_height: "0" +start_height: "1" tombstoned: false`, sdk.ConsAddress(val.PubKey.Address())), }, } From b532d0dd64a7c09fff153ac3d10caa6db1caf278 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 31 Aug 2020 15:44:48 +0200 Subject: [PATCH 30/44] Fresh chain, genesis block = 0 --- baseapp/abci.go | 5 ++++- x/auth/ante/sigverify.go | 2 +- x/slashing/client/cli/cli_test.go | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 5db9915aa87..6aa62505ae3 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -23,9 +23,12 @@ import ( // InitChain implements the ABCI interface. It runs the initialization logic // directly on the CommitMultiStore. func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { - initHeader := tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} + // On a new chain, we consider the init chain block height as 0, even though + // req.InitialHeight is 1. + initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time} if req.InitialHeight > 1 { + initHeader = tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} err := app.cms.SetInitialVersion(req.InitialHeight) if err != nil { panic(err) diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index bd73ab66541..e1d11ebc9b5 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -215,7 +215,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul } // retrieve signer data - genesis := ctx.BlockHeight() <= 1 + genesis := ctx.BlockHeight() == 0 chainID := ctx.ChainID() var accNum uint64 if !genesis { diff --git a/x/slashing/client/cli/cli_test.go b/x/slashing/client/cli/cli_test.go index fad3c5c2d6e..e925e64336b 100644 --- a/x/slashing/client/cli/cli_test.go +++ b/x/slashing/client/cli/cli_test.go @@ -66,7 +66,7 @@ func (s *IntegrationTestSuite) TestGetCmdQuerySigningInfo() { fmt.Sprintf("--%s=1", flags.FlagHeight), }, false, - fmt.Sprintf("{\"address\":\"%s\",\"start_height\":\"1\",\"index_offset\":\"0\",\"jailed_until\":\"1970-01-01T00:00:00Z\",\"tombstoned\":false,\"missed_blocks_counter\":\"0\"}", sdk.ConsAddress(val.PubKey.Address())), + fmt.Sprintf("{\"address\":\"%s\",\"start_height\":\"0\",\"index_offset\":\"0\",\"jailed_until\":\"1970-01-01T00:00:00Z\",\"tombstoned\":false,\"missed_blocks_counter\":\"0\"}", sdk.ConsAddress(val.PubKey.Address())), }, { "valid address (text output)", @@ -80,7 +80,7 @@ func (s *IntegrationTestSuite) TestGetCmdQuerySigningInfo() { index_offset: "0" jailed_until: "1970-01-01T00:00:00Z" missed_blocks_counter: "0" -start_height: "1" +start_height: "0" tombstoned: false`, sdk.ConsAddress(val.PubKey.Address())), }, } From 54b0a97ca4874fafd0b81377239d2da7990676b3 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 31 Aug 2020 15:53:10 +0200 Subject: [PATCH 31/44] Add comments --- baseapp/abci.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 6aa62505ae3..53705b9f219 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -24,9 +24,11 @@ import ( // directly on the CommitMultiStore. func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { // On a new chain, we consider the init chain block height as 0, even though - // req.InitialHeight is 1. + // req.InitialHeight is 1 by default. initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time} + // If req.InitialHeight is > 1, then we set the initial version in the + // stores. if req.InitialHeight > 1 { initHeader = tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} err := app.cms.SetInitialVersion(req.InitialHeight) From dbc92b72c51fd2fed5163c85c1432280f7cd141b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 1 Sep 2020 17:02:00 +0200 Subject: [PATCH 32/44] Revert Mutable/ImmutableTree --- store/iavl/store.go | 15 ++++----------- store/iavl/store_test.go | 18 ++++++++---------- store/iavl/tree.go | 18 ++++++++---------- store/rootmulti/store.go | 5 +---- store/types/store.go | 2 +- 5 files changed, 22 insertions(+), 36 deletions(-) diff --git a/store/iavl/store.go b/store/iavl/store.go index 45a7e82e114..d826c730c4e 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -35,7 +35,7 @@ var ( // Store Implements types.KVStore and CommitKVStore. type Store struct { - tree ImmutableTree + tree Tree } // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the @@ -208,19 +208,12 @@ func (st *Store) ReverseIterator(start, end []byte) types.Iterator { // SetInitialVersion sets the initial version of the IAVL tree. It is used when // starting a new chain at an arbitrary height. -func (st *Store) SetInitialVersion(version int64) error { - mutableTree, ok := st.tree.(MutableTree) - if !ok { - return fmt.Errorf("cannot set initial version on an immutable tree") - } - - mutableTree.SetInitialVersion(uint64(version)) - - return nil +func (st *Store) SetInitialVersion(version int64) { + st.tree.SetInitialVersion(uint64(version)) } // Handle gatest the latest height, if height is 0 -func getHeight(tree ImmutableTree, req abci.RequestQuery) int64 { +func getHeight(tree Tree, req abci.RequestQuery) int64 { height := req.Height if height == 0 { latest := tree.Version() diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index 3037994beb8..052021310f9 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -529,10 +529,9 @@ func BenchmarkIAVLIteratorNext(b *testing.B) { func TestSetInitialVersion(t *testing.T) { testCases := []struct { - name string - storeFn func(db *dbm.MemDB) *Store - expErr bool - expErrMsg string + name string + storeFn func(db *dbm.MemDB) *Store + expPanic bool }{ { "works with a mutable tree", @@ -542,7 +541,7 @@ func TestSetInitialVersion(t *testing.T) { store := UnsafeNewStore(tree) return store - }, false, "", + }, false, }, { "throws error on immutable tree", @@ -557,7 +556,7 @@ func TestSetInitialVersion(t *testing.T) { require.NoError(t, err) return store - }, true, "cannot set initial version on an immutable tree", + }, true, }, } @@ -567,12 +566,11 @@ func TestSetInitialVersion(t *testing.T) { t.Run(tc.name, func(t *testing.T) { db := dbm.NewMemDB() store := tc.storeFn(db) - err := store.SetInitialVersion(5) - if tc.expErr { - require.Error(t, err) - require.EqualError(t, err, tc.expErrMsg) + if tc.expPanic { + require.Panics(t, func() { store.SetInitialVersion(5) }) } else { + store.SetInitialVersion(5) cid := store.Commit() require.Equal(t, int64(5), cid.GetVersion()) } diff --git a/store/iavl/tree.go b/store/iavl/tree.go index d9f8b51659d..83d1ada301f 100644 --- a/store/iavl/tree.go +++ b/store/iavl/tree.go @@ -7,16 +7,16 @@ import ( ) var ( - _ ImmutableTree = (*immutableTree)(nil) - _ MutableTree = (*iavl.MutableTree)(nil) + _ Tree = (*immutableTree)(nil) + _ Tree = (*iavl.MutableTree)(nil) ) type ( - // ImmutableTree defines an interface that immutable IAVL trees + // Tree defines an interface that both mutable and immutable IAVL trees // must implement. For mutable IAVL trees, the interface is directly // implemented by an iavl.MutableTree. For an immutable IAVL tree, a wrapper // must be made. - ImmutableTree interface { + Tree interface { Has(key []byte) bool Get(key []byte) (index int64, value []byte) Set(key, value []byte) bool @@ -30,12 +30,6 @@ type ( GetVersioned(key []byte, version int64) (int64, []byte) GetVersionedWithProof(key []byte, version int64) ([]byte, *iavl.RangeProof, error) GetImmutable(version int64) (*iavl.ImmutableTree, error) - } - - // MutableTree defines an interface that mutable IAVL trees - // must implement. - MutableTree interface { - ImmutableTree SetInitialVersion(version uint64) } @@ -67,6 +61,10 @@ func (it *immutableTree) DeleteVersions(_ ...int64) error { panic("cannot call 'DeleteVersions' on an immutable IAVL tree") } +func (it *immutableTree) SetInitialVersion(_ uint64) { + panic("cannot call 'SetInitialVersion' on an immutable IAVL tree") +} + func (it *immutableTree) VersionExists(version int64) bool { return it.Version() == version } diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 8e8aa8eace1..db50adcbb8b 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -521,10 +521,7 @@ func (rs *Store) SetInitialVersion(version int64) error { // version on it. for _, commitKVStore := range rs.stores { if storeWithVersion, ok := commitKVStore.(types.StoreWithInitialVersion); ok { - err := storeWithVersion.SetInitialVersion(version) - if err != nil { - return err - } + storeWithVersion.SetInitialVersion(version) } } diff --git a/store/types/store.go b/store/types/store.go index edb4f8ce056..087a28de6bc 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -404,5 +404,5 @@ type MultiStorePersistentCache interface { type StoreWithInitialVersion interface { // SetInitialVersion sets the initial version of the IAVL tree. It is used when // starting a new chain at an arbitrary height. - SetInitialVersion(version int64) error + SetInitialVersion(version int64) } From e238ebe3d7a652ad992768d5c14f6a527a4975eb Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 1 Sep 2020 17:42:35 +0200 Subject: [PATCH 33/44] Allow for zero height --- server/export_test.go | 69 +++++++++++++++++++++++++++++-------------- simapp/export.go | 4 ++- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/server/export_test.go b/server/export_test.go index 7c967200761..4754e5fe5ae 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -57,29 +57,54 @@ func TestExportCmd_ConsensusParams(t *testing.T) { } func TestExportCmd_Height(t *testing.T) { - tempDir, clean := testutil.NewTestCaseDir(t) - defer clean() - - app, ctx, _, cmd := setupApp(t, tempDir) - - // Fast forward to block 3. - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}}) - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}}) - app.Commit() - - output := &bytes.Buffer{} - cmd.SetOut(output) - cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)}) - require.NoError(t, cmd.ExecuteContext(ctx)) + testCases := []struct { + name string + flags []string + expHeight int64 + }{ + { + "should export correct height", + []string{}, + 3, + }, + { + "should export height 0 with --for-zero-height", + []string{ + fmt.Sprintf("--%s=%s", FlagForZeroHeight, "true"), + }, + 0, + }, + } - var exportedGenDoc tmtypes.GenesisDoc - err := tmjson.Unmarshal(output.Bytes(), &exportedGenDoc) - if err != nil { - t.Fatalf("error unmarshaling exported genesis doc: %s", err) + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + tempDir, clean := testutil.NewTestCaseDir(t) + defer clean() + + app, ctx, _, cmd := setupApp(t, tempDir) + + // Fast forward to block 3. + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}}) + app.Commit() + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}}) + app.Commit() + + output := &bytes.Buffer{} + cmd.SetOut(output) + args := append(tc.flags, fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)) + cmd.SetArgs(args) + require.NoError(t, cmd.ExecuteContext(ctx)) + + var exportedGenDoc tmtypes.GenesisDoc + err := tmjson.Unmarshal(output.Bytes(), &exportedGenDoc) + if err != nil { + t.Fatalf("error unmarshaling exported genesis doc: %s", err) + } + + require.Equal(t, tc.expHeight, exportedGenDoc.InitialHeight) + }) } - require.Equal(t, int64(3), exportedGenDoc.InitialHeight) } func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *tmtypes.GenesisDoc, *cobra.Command) { @@ -111,8 +136,8 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t app.Commit() cmd := ExportCmd( - func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (types.ExportedApp, error) { - return app.ExportAppStateAndValidators(true, []string{}) + func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, forZeroHeight bool, jailAllowedAddrs []string) (types.ExportedApp, error) { + return app.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) }, tempDir) ctx := context.Background() diff --git a/simapp/export.go b/simapp/export.go index ac284857d63..6c73269c01d 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -23,7 +23,9 @@ func (app *SimApp) ExportAppStateAndValidators( // as if they could withdraw from the start of the next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + height := app.LastBlockHeight() if forZeroHeight { + height = 0 app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) } @@ -37,7 +39,7 @@ func (app *SimApp) ExportAppStateAndValidators( return servertypes.ExportedApp{ AppState: appState, Validators: validators, - Height: app.LastBlockHeight(), + Height: height, ConsensusParams: app.BaseApp.GetConsensusParams(ctx), }, nil } From b8ba3e29757630604027ae6163ae81fe5d781efc Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 1 Sep 2020 18:53:32 +0200 Subject: [PATCH 34/44] Fix restart --- baseapp/abci.go | 1 + baseapp/baseapp.go | 21 +++++- baseapp/baseapp_test.go | 38 ++++++++++ simapp/export.go | 2 +- simapp/export_test.go | 135 ---------------------------------- store/rootmulti/store.go | 6 +- store/rootmulti/store_test.go | 2 +- 7 files changed, 62 insertions(+), 143 deletions(-) delete mode 100644 simapp/export_test.go diff --git a/baseapp/abci.go b/baseapp/abci.go index 53705b9f219..9107b847e97 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -30,6 +30,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC // If req.InitialHeight is > 1, then we set the initial version in the // stores. if req.InitialHeight > 1 { + app.initialHeight = req.InitialHeight initHeader = tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} err := app.cms.SetInitialVersion(req.InitialHeight) if err != nil { diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index e4115184156..a8dbee3f713 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -81,6 +81,9 @@ type BaseApp struct { // nolint: maligned // transaction. This is mainly used for DoS and spam prevention. minGasPrices sdk.DecCoins + // initialHeight is the initial height at which we start the baseapp + initialHeight int64 + // flag for sealing options and parameters to a BaseApp sealed bool @@ -416,9 +419,21 @@ func (app *BaseApp) validateHeight(req abci.RequestBeginBlock) error { return fmt.Errorf("invalid height: %d", req.Header.Height) } - prevHeight := app.LastBlockHeight() - if req.Header.Height != prevHeight+1 { - return fmt.Errorf("invalid height: %d; expected: %d", req.Header.Height, prevHeight+1) + // expectedHeight holds the expected height to validate. + var expectedHeight int64 + if app.LastBlockHeight() == 0 && app.initialHeight > 1 { + // In this case, we're validating the first block of the chain (no + // previous commit). The height we're expecting is the initial height + // (can be 0). + expectedHeight = app.initialHeight + } else { + // This case means that we committed, so we just increment from the + // previous height. + expectedHeight = app.LastBlockHeight() + 1 + } + + if req.Header.Height != expectedHeight { + return fmt.Errorf("invalid height: %d; expected: %d", req.Header.Height, expectedHeight) } return nil diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 05038ce2c36..92248f8e73f 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -535,6 +535,44 @@ func TestInitChainer(t *testing.T) { require.Equal(t, value, res.Value) } +func TestInitChain_WithInitialHeight(t *testing.T) { + name := t.Name() + db := dbm.NewMemDB() + logger := defaultLogger() + app := NewBaseApp(name, logger, db, nil) + + app.InitChain( + abci.RequestInitChain{ + InitialHeight: 3, + }, + ) + app.Commit() + + require.Equal(t, int64(4), app.LastBlockHeight()) +} + +func TestBeginBlock_WithInitialHeight(t *testing.T) { + name := t.Name() + db := dbm.NewMemDB() + logger := defaultLogger() + app := NewBaseApp(name, logger, db, nil) + + app.InitChain( + abci.RequestInitChain{ + InitialHeight: 3, + }, + ) + + app.BeginBlock(abci.RequestBeginBlock{ + Header: tmproto.Header{ + Height: 3, + }, + }) + app.Commit() + + require.Equal(t, int64(4), app.LastBlockHeight()) +} + // Simple tx with a list of Msgs. type txTest struct { Msgs []sdk.Msg diff --git a/simapp/export.go b/simapp/export.go index 6c73269c01d..6bd6d8e3c07 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -23,7 +23,7 @@ func (app *SimApp) ExportAppStateAndValidators( // as if they could withdraw from the start of the next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) - height := app.LastBlockHeight() + height := app.LastBlockHeight() + 1 if forZeroHeight { height = 0 app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) diff --git a/simapp/export_test.go b/simapp/export_test.go deleted file mode 100644 index bb8b494ab3f..00000000000 --- a/simapp/export_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package simapp_test - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "io" - "os" - "path" - "testing" - - "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - tmjson "github.com/tendermint/tendermint/libs/json" - "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmtypes "github.com/tendermint/tendermint/types" - dbm "github.com/tendermint/tm-db" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/server" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/genutil" -) - -func TestSimappInitialHeight(t *testing.T) { - // Create new simapp with a new genesis doc. - tempDir1, clean := testutil.NewTestCaseDir(t) - defer clean() - app, clientCtx, serverCtx := setupApp(t, tempDir1) - genDoc := newDefaultGenesisDoc() - err := saveGenesisFile(genDoc, serverCtx.Config.GenesisFile()) - require.NoError(t, err) - - // Fast forward to block 3. - app.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: simapp.DefaultConsensusParams, - AppStateBytes: genDoc.AppState, - }, - ) - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}}) - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}}) - app.Commit() - - // Create the export command. - cmd := server.ExportCmd( - func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (servertypes.ExportedApp, error) { - return app.ExportAppStateAndValidators(true, []string{}) - }, tempDir1) - - ctx := context.Background() - ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) - - // Run the export command, save the genesis file to another folder. - output := &bytes.Buffer{} - cmd.SetOut(output) - cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir1)}) - require.NoError(t, cmd.ExecuteContext(ctx)) - tempDir2, clean := testutil.NewTestCaseDir(t) - defer clean() - var exportedGenDoc tmtypes.GenesisDoc - err = tmjson.Unmarshal(output.Bytes(), &exportedGenDoc) - if err != nil { - t.Fatalf("error unmarshaling exported genesis doc: %s", err) - } - require.Equal(t, int64(3), exportedGenDoc.InitialHeight) - err = saveGenesisFile(genDoc, tempDir2) - - // Run a new app, with exported genesis. - newApp, _, _ := setupApp(t, tempDir2) - newApp.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: simapp.DefaultConsensusParams, - AppStateBytes: exportedGenDoc.AppState, - InitialHeight: exportedGenDoc.InitialHeight, - }, - ) - newApp.Commit() - - // Check that initial height is taken into account. - require.Equal(t, int64(4), newApp.LastBlockHeight()) -} - -func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, client.Context, *server.Context) { - err := os.Mkdir(path.Join(tempDir, "config"), 0700) - if err != nil { - t.Fatalf("error creating config folder: %s", err) - } - - db := dbm.NewMemDB() - app := simapp.NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, tempDir, 0, simapp.MakeEncodingConfig()) - - serverCtx := server.NewDefaultContext() - serverCtx.Config.RootDir = tempDir - - clientCtx := client.Context{}.WithJSONMarshaler(app.AppCodec()) - - return app, clientCtx, serverCtx -} - -func newDefaultGenesisDoc() *tmtypes.GenesisDoc { - genesisState := simapp.NewDefaultGenesisState() - - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - if err != nil { - panic(err) - } - - genDoc := &tmtypes.GenesisDoc{} - genDoc.ChainID = "theChainId" - genDoc.Validators = nil - genDoc.AppState = stateBytes - - return genDoc -} - -func saveGenesisFile(genDoc *tmtypes.GenesisDoc, dir string) error { - err := genutil.ExportGenesisFile(genDoc, dir) - if err != nil { - return errors.Wrap(err, "error creating file") - } - - return nil -} diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index db50adcbb8b..850b9ae563d 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -299,18 +299,18 @@ func (rs *Store) LastCommitID() types.CommitID { // Commit implements Committer/CommitStore. func (rs *Store) Commit() types.CommitID { - var previousHeight int64 + var previousHeight, version int64 if rs.lastCommitInfo.GetVersion() > 0 { // This case means that there was already a previous commit in the // store. We increment from that commit version. previousHeight = rs.lastCommitInfo.GetVersion() + version = previousHeight + 1 } else { // This case means that no commit has been made in the store, we // start from initialVersion (or 0 if not set). - previousHeight = rs.initialVersion + version = rs.initialVersion } - version := previousHeight + 1 rs.lastCommitInfo = commitStores(version, rs.stores) // Determine if pruneHeight height needs to be added to the list of heights to diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index bf9b408dfe3..573d198daf1 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -513,7 +513,7 @@ func TestSetInitialVersion(t *testing.T) { require.Equal(t, int64(5), multi.initialVersion) multi.Commit() - require.Equal(t, int64(6), multi.LastCommitID().Version) + require.Equal(t, int64(5), multi.LastCommitID().Version) } //----------------------------------------------------------------------- From 57485ee83d913b8e1bdf8a3767c366f6d58d4e6c Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 1 Sep 2020 19:02:18 +0200 Subject: [PATCH 35/44] Add comments --- simapp/export.go | 3 ++- simapp/simd/cmd/root.go | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/simapp/export.go b/simapp/export.go index 6bd6d8e3c07..08deec4619a 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -19,10 +19,11 @@ import ( func (app *SimApp) ExportAppStateAndValidators( forZeroHeight bool, jailAllowedAddrs []string, ) (servertypes.ExportedApp, error) { - // as if they could withdraw from the start of the next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + // We export at last height + 1, because that's the height at which + // Tendermint will start InitChain. height := app.LastBlockHeight() + 1 if forZeroHeight { height = 0 diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 3770be6dfdb..2ddd22efbca 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -191,7 +191,6 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty func exportAppStateAndTMValidators( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, ) (servertypes.ExportedApp, error) { - encCfg := simapp.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd. encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry) var simApp *simapp.SimApp From 7c6ba4d1e5201a5fa6e694e7e002e00d66c16251 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 1 Sep 2020 19:07:12 +0200 Subject: [PATCH 36/44] Add comments, fix test --- baseapp/baseapp.go | 7 +++++-- store/rootmulti/store.go | 18 +++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index a8dbee3f713..2614823e3aa 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -427,8 +427,11 @@ func (app *BaseApp) validateHeight(req abci.RequestBeginBlock) error { // (can be 0). expectedHeight = app.initialHeight } else { - // This case means that we committed, so we just increment from the - // previous height. + // This case can means two things: + // - either there was already a previous commit in the store, in which + // case we increment the version from there, + // - or there was no previous commit, and initial version was not set, + // in which case we start at version 1. expectedHeight = app.LastBlockHeight() + 1 } diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 850b9ae563d..bb6db32da48 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -300,15 +300,19 @@ func (rs *Store) LastCommitID() types.CommitID { // Commit implements Committer/CommitStore. func (rs *Store) Commit() types.CommitID { var previousHeight, version int64 - if rs.lastCommitInfo.GetVersion() > 0 { - // This case means that there was already a previous commit in the - // store. We increment from that commit version. - previousHeight = rs.lastCommitInfo.GetVersion() - version = previousHeight + 1 - } else { + if rs.lastCommitInfo.GetVersion() == 0 && rs.initialVersion > 1 { // This case means that no commit has been made in the store, we - // start from initialVersion (or 0 if not set). + // start from initialVersion. version = rs.initialVersion + + } else { + // This case can means two things: + // - either there was already a previous commit in the store, in which + // case we increment the version from there, + // - or there was no previous commit, and initial version was not set, + // in which case we start at version 1. + previousHeight = rs.lastCommitInfo.GetVersion() + version = previousHeight + 1 } rs.lastCommitInfo = commitStores(version, rs.stores) From 66a0dc8e69e2b58e0e86285a6610e314ae42b64d Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 1 Sep 2020 19:13:34 +0200 Subject: [PATCH 37/44] Fix remaining one test --- server/export_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/export_test.go b/server/export_test.go index 4754e5fe5ae..dfb7301d040 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -65,7 +65,7 @@ func TestExportCmd_Height(t *testing.T) { { "should export correct height", []string{}, - 3, + 4, }, { "should export height 0 with --for-zero-height", From f7cd6d2e13e30a7dfdabfc5a7cb4144d73bf5aaa Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 1 Sep 2020 19:23:39 +0200 Subject: [PATCH 38/44] Add panic test --- baseapp/baseapp_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 92248f8e73f..4371be44f6e 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -548,7 +548,7 @@ func TestInitChain_WithInitialHeight(t *testing.T) { ) app.Commit() - require.Equal(t, int64(4), app.LastBlockHeight()) + require.Equal(t, int64(3), app.LastBlockHeight()) } func TestBeginBlock_WithInitialHeight(t *testing.T) { @@ -563,6 +563,14 @@ func TestBeginBlock_WithInitialHeight(t *testing.T) { }, ) + require.PanicsWithError(t, "invalid height: 4; expected: 3", func() { + app.BeginBlock(abci.RequestBeginBlock{ + Header: tmproto.Header{ + Height: 4, + }, + }) + }) + app.BeginBlock(abci.RequestBeginBlock{ Header: tmproto.Header{ Height: 3, @@ -570,7 +578,7 @@ func TestBeginBlock_WithInitialHeight(t *testing.T) { }) app.Commit() - require.Equal(t, int64(4), app.LastBlockHeight()) + require.Equal(t, int64(3), app.LastBlockHeight()) } // Simple tx with a list of Msgs. @@ -1330,7 +1338,6 @@ func TestCustomRunTxPanicHandler(t *testing.T) { anteOpt := func(bapp *BaseApp) { bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { panic(sdkerrors.Wrap(anteErr, "anteHandler")) - return }) } routerOpt := func(bapp *BaseApp) { From af26c5b2cc91b1bdb9f8bece56837682da6cd02b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 1 Sep 2020 19:25:38 +0200 Subject: [PATCH 39/44] Update comment --- baseapp/baseapp.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 2614823e3aa..7a4316e7ef6 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -423,8 +423,7 @@ func (app *BaseApp) validateHeight(req abci.RequestBeginBlock) error { var expectedHeight int64 if app.LastBlockHeight() == 0 && app.initialHeight > 1 { // In this case, we're validating the first block of the chain (no - // previous commit). The height we're expecting is the initial height - // (can be 0). + // previous commit). The height we're expecting is the initial height. expectedHeight = app.initialHeight } else { // This case can means two things: From 57c1f9fee3ffac6c807ab56ae15fbaad041538e2 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 2 Sep 2020 12:25:28 +0200 Subject: [PATCH 40/44] Add test for --height --- server/export_test.go | 61 +++++++++++++++++++++++++++++------------ simapp/app.go | 18 ++++++------ simapp/simd/cmd/root.go | 6 ++-- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/server/export_test.go b/server/export_test.go index dfb7301d040..aaa9c10ec3c 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -1,4 +1,4 @@ -package server +package server_test import ( "bytes" @@ -22,7 +22,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" + servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/types/errors" @@ -58,21 +60,29 @@ func TestExportCmd_ConsensusParams(t *testing.T) { func TestExportCmd_Height(t *testing.T) { testCases := []struct { - name string - flags []string - expHeight int64 + name string + flags []string + fastForward int64 + expHeight int64 }{ { "should export correct height", []string{}, - 4, + 5, 6, + }, + { + "should export correct height with --height", + []string{ + fmt.Sprintf("--%s=%d", server.FlagHeight, 3), + }, + 5, 4, }, { "should export height 0 with --for-zero-height", []string{ - fmt.Sprintf("--%s=%s", FlagForZeroHeight, "true"), + fmt.Sprintf("--%s=%s", server.FlagForZeroHeight, "true"), }, - 0, + 2, 0, }, } @@ -83,11 +93,11 @@ func TestExportCmd_Height(t *testing.T) { app, ctx, _, cmd := setupApp(t, tempDir) - // Fast forward to block 3. - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}}) - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}}) - app.Commit() + // Fast forward to block `tc.fastForward`. + for i := int64(2); i <= tc.fastForward; i++ { + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: int64(i)}}) + app.Commit() + } output := &bytes.Buffer{} cmd.SetOut(output) @@ -113,10 +123,12 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t t.Fatalf("error creating config folder: %s", err) } + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) db := dbm.NewMemDB() - app := simapp.NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, tempDir, 0, simapp.MakeEncodingConfig()) + encCfg := simapp.MakeEncodingConfig() + app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg) - serverCtx := NewDefaultContext() + serverCtx := server.NewDefaultContext() serverCtx.Config.RootDir = tempDir clientCtx := client.Context{}.WithJSONMarshaler(app.AppCodec()) @@ -135,14 +147,27 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t app.Commit() - cmd := ExportCmd( - func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, forZeroHeight bool, jailAllowedAddrs []string) (types.ExportedApp, error) { - return app.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) + cmd := server.ExportCmd( + func(_ log.Logger, _ dbm.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string) (types.ExportedApp, error) { + encCfg := simapp.MakeEncodingConfig() + + var simApp *simapp.SimApp + if height != -1 { + simApp = simapp.NewSimApp(logger, db, nil, false, map[int64]bool{}, "", 0, encCfg) + + if err := simApp.LoadHeight(height); err != nil { + return servertypes.ExportedApp{}, err + } + } else { + simApp = simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, "", 0, encCfg) + } + + return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) }, tempDir) ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) return app, ctx, genDoc, cmd } diff --git a/simapp/app.go b/simapp/app.go index 10351e6dd61..feac2187209 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -383,15 +383,17 @@ func NewSimApp( if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) } - } - // Initialize and seal the capability keeper so all persistent capabilities - // are loaded in-memory and prevent any further modules from creating scoped - // sub-keepers. - // This must be done during creation of baseapp rather than in InitChain so - // that in-memory capabilities get regenerated on app restart - ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{}) - app.CapabilityKeeper.InitializeAndSeal(ctx) + // Initialize and seal the capability keeper so all persistent capabilities + // are loaded in-memory and prevent any further modules from creating scoped + // sub-keepers. + // This must be done during creation of baseapp rather than in InitChain so + // that in-memory capabilities get regenerated on app restart. + // Note that since this reads from the store, we can only perform it when + // `loadLatest` is set to true. + ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{}) + app.CapabilityKeeper.InitializeAndSeal(ctx) + } app.ScopedIBCKeeper = scopedIBCKeeper app.ScopedTransferKeeper = scopedTransferKeeper diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 2ddd22efbca..cd9649ed082 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -94,7 +94,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { debug.Cmd(), ) - server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, exportAppStateAndTMValidators) + server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, createSimappAndExport) // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( @@ -188,7 +188,9 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty ) } -func exportAppStateAndTMValidators( +// createSimappAndExport creates a new simapp (optionally at a given height) +// and exports state. +func createSimappAndExport( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, ) (servertypes.ExportedApp, error) { encCfg := simapp.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd. From aeec99fa2ee867608edaf5d703e3415543792c4f Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 2 Sep 2020 12:30:20 +0200 Subject: [PATCH 41/44] No cast --- server/export_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/export_test.go b/server/export_test.go index aaa9c10ec3c..9262edb6329 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -95,7 +95,7 @@ func TestExportCmd_Height(t *testing.T) { // Fast forward to block `tc.fastForward`. for i := int64(2); i <= tc.fastForward; i++ { - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: int64(i)}}) + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: i}}) app.Commit() } From c2d41b5bb16cceda2ac126185f67a7f9ee3afee1 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 2 Sep 2020 12:33:01 +0200 Subject: [PATCH 42/44] Add check that genesis file exists --- server/export.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/export.go b/server/export.go index a0bec979617..b244adbfa31 100644 --- a/server/export.go +++ b/server/export.go @@ -69,6 +69,10 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return fmt.Errorf("error exporting state: %v", err) } + if _, err := os.Stat(serverCtx.Config.GenesisFile()); os.IsNotExist(err) { + return err + } + doc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) if err != nil { return err From d7f43535f220faf691086c5dfac14d3f9c63ac03 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 2 Sep 2020 12:38:30 +0200 Subject: [PATCH 43/44] Remove duplicate imports --- server/export_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/export_test.go b/server/export_test.go index 9262edb6329..d64b4873ce5 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -24,7 +24,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" - servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/types/errors" @@ -156,7 +155,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t simApp = simapp.NewSimApp(logger, db, nil, false, map[int64]bool{}, "", 0, encCfg) if err := simApp.LoadHeight(height); err != nil { - return servertypes.ExportedApp{}, err + return types.ExportedApp{}, err } } else { simApp = simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, "", 0, encCfg) From 6bf735ccf61c85fd303e45e7c5262ec42c067d0d Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 2 Sep 2020 20:22:41 +0200 Subject: [PATCH 44/44] Fail early --- server/export.go | 8 ++++---- server/export_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/server/export.go b/server/export.go index b244adbfa31..55746d9aa93 100644 --- a/server/export.go +++ b/server/export.go @@ -35,6 +35,10 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com homeDir, _ := cmd.Flags().GetString(flags.FlagHome) config.SetRoot(homeDir) + if _, err := os.Stat(config.GenesisFile()); os.IsNotExist(err) { + return err + } + db, err := openDB(config.RootDir) if err != nil { return err @@ -69,10 +73,6 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return fmt.Errorf("error exporting state: %v", err) } - if _, err := os.Stat(serverCtx.Config.GenesisFile()); os.IsNotExist(err) { - return err - } - doc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) if err != nil { return err diff --git a/server/export_test.go b/server/export_test.go index d64b4873ce5..4e96d811488 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -57,6 +57,17 @@ func TestExportCmd_ConsensusParams(t *testing.T) { require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes) } +func TestExportCmd_HomeDir(t *testing.T) { + tempDir, clean := testutil.NewTestCaseDir(t) + defer clean() + + _, ctx, _, cmd := setupApp(t, tempDir) + + 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") +} + func TestExportCmd_Height(t *testing.T) { testCases := []struct { name string