From b844bb9f4e609fae2587933eee0f46ec0e4fe08b Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Wed, 19 Jun 2024 16:06:04 -0400 Subject: [PATCH 01/28] boilerplate code --- server/export.go | 5 +++++ server/types/app.go | 5 +++++ server/util.go | 2 ++ 3 files changed, 12 insertions(+) diff --git a/server/export.go b/server/export.go index 3dc5b8eba..4c0f4e1f6 100644 --- a/server/export.go +++ b/server/export.go @@ -116,3 +116,8 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return cmd } + +func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome string) *cobra.Command { + // TODO + return nil +} diff --git a/server/types/app.go b/server/types/app.go index c95a8b3a2..18f5d9605 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -85,4 +85,9 @@ 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, AppOptions) (ExportedApp, error) + + // AppExporterToFile is a function that dumps all app state to + // JSON-serializable structure and writes the result to a file. + // This is useful when the output is too large to fit in memory. + AppExporterToFile func(log.Logger, dbm.DB, io.Writer, int64, bool, []string, AppOptions, string) error ) diff --git a/server/util.go b/server/util.go index 5158f0e32..539cd8e66 100644 --- a/server/util.go +++ b/server/util.go @@ -304,6 +304,7 @@ func AddCommands( defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, + appExportToFile types.AppExporterToFile, addStartFlags types.ModuleInitFlags, tracerProviderOptions []trace.TracerProviderOption, ) { @@ -348,6 +349,7 @@ func AddCommands( startCmd, tendermintCmd, ExportCmd(appExport, defaultNodeHome), + ExportToFileCmd(appExportToFile, defaultNodeHome), version.NewVersionCommand(), NewRollbackCmd(appCreator, defaultNodeHome), LatestVersionCmd(defaultNodeHome), From 6bf36e065da606d1482075a836f330d9b0a5674c Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Thu, 20 Jun 2024 13:45:02 -0400 Subject: [PATCH 02/28] able to write the modules in proper json --- server/export.go | 61 ++++++++++++++++++++++++++++++++++++++++-- types/module/module.go | 6 +++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/server/export.go b/server/export.go index 4c0f4e1f6..ef495d3e9 100644 --- a/server/export.go +++ b/server/export.go @@ -118,6 +118,63 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com } func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome string) *cobra.Command { - // TODO - return nil + cmd := &cobra.Command{ + Use: "export-to-file [jsonfile]", + Short: "Export state to JSON file", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + serverCtx := GetServerContextFromCmd(cmd) + config := serverCtx.Config + + 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 + } + + if appExporterToFile == nil { + if _, err := fmt.Fprintln(os.Stderr, "WARNING: App exporter not defined. Returning genesis file."); err != nil { + return err + } + + genesis, err := ioutil.ReadFile(config.GenesisFile()) + if err != nil { + return err + } + + fmt.Println(string(genesis)) + return nil + } + + traceWriterFile, _ := cmd.Flags().GetString(flagTraceStore) + traceWriter, err := openTraceWriter(traceWriterFile) + if err != nil { + return err + } + + height, _ := cmd.Flags().GetInt64(FlagHeight) + forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight) + jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs) + + err = appExporterToFile(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, args[0]) + if err != nil { + return fmt.Errorf("error exporting state: %v", err) + } + return nil + }, + } + + cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") + cmd.Flags().Int64(FlagHeight, -1, "Export state from a particular height (-1 means latest height)") + cmd.Flags().Bool(FlagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)") + cmd.Flags().StringSlice(FlagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail") + cmd.Flags().String(FlagChainID, "", "Chain ID") + + return cmd } diff --git a/types/module/module.go b/types/module/module.go index b4eecec86..690ac1a66 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -365,6 +365,12 @@ func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string return genesisData } +func (m *Manager) ProcessGenesisPerModule(ctx sdk.Context, cdc codec.JSONCodec, process func(string, json.RawMessage)) { + for _, moduleName := range m.OrderExportGenesis { + process(moduleName, m.Modules[moduleName].ExportGenesis(ctx, cdc)) + } +} + // assertNoForgottenModules checks that we didn't forget any modules in the // SetOrder* functions. func (m *Manager) assertNoForgottenModules(setOrderFnName string, moduleNames []string) { From afcca8099595df308c7b8ae262af53ded9691282 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Thu, 20 Jun 2024 23:12:33 -0400 Subject: [PATCH 03/28] all params in --- server/export.go | 54 ++++++++++++++++++++++++++++++++++++++++++++- server/types/app.go | 3 ++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/server/export.go b/server/export.go index ef495d3e9..253437e57 100644 --- a/server/export.go +++ b/server/export.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "os" + "time" "github.com/spf13/cobra" tmtypes "github.com/tendermint/tendermint/types" @@ -117,6 +118,15 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return cmd } +type GenesisDocNoAppHash struct { + GenesisTime time.Time `json:"genesis_time"` + ChainID string `json:"chain_id"` + InitialHeight int64 `json:"initial_height,string"` + ConsensusParams *tmtypes.ConsensusParams `json:"consensus_params,omitempty"` + Validators []tmtypes.GenesisValidator `json:"validators,omitempty"` + AppState json.RawMessage `json:"app_state,omitempty"` +} + func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ Use: "export-to-file [jsonfile]", @@ -125,6 +135,11 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome RunE: func(cmd *cobra.Command, args []string) error { serverCtx := GetServerContextFromCmd(cmd) config := serverCtx.Config + filePath := args[0] + file, err := os.Create(filePath) + if err != nil { + return err + } homeDir, _ := cmd.Flags().GetString(flags.FlagHome) config.SetRoot(homeDir) @@ -162,10 +177,47 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight) jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs) - err = appExporterToFile(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, args[0]) + file.Write([]byte("{")) + exported, err := appExporterToFile(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, file) if err != nil { return fmt.Errorf("error exporting state: %v", err) } + + doc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) + if err != nil { + return err + } + + genesisDocNoAppHash := GenesisDocNoAppHash{ + GenesisTime: doc.GenesisTime, + ChainID: doc.ChainID, + InitialHeight: exported.Height, + ConsensusParams: &tmtypes.ConsensusParams{ + Block: tmtypes.BlockParams{ + MaxBytes: exported.ConsensusParams.Block.MaxBytes, + MaxGas: exported.ConsensusParams.Block.MaxGas, + }, + Evidence: tmtypes.EvidenceParams{ + MaxAgeNumBlocks: exported.ConsensusParams.Evidence.MaxAgeNumBlocks, + MaxAgeDuration: exported.ConsensusParams.Evidence.MaxAgeDuration, + MaxBytes: exported.ConsensusParams.Evidence.MaxBytes, + }, + Validator: tmtypes.ValidatorParams{ + PubKeyTypes: exported.ConsensusParams.Validator.PubKeyTypes, + }, + }, + Validators: exported.Validators, + } + + // 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 := json.Marshal(genesisDocNoAppHash) + if err != nil { + return err + } + + file.Write([]byte(fmt.Sprintf(",%s",string(sdk.MustSortJSON(encoded))[1:]))) return nil }, } diff --git a/server/types/app.go b/server/types/app.go index 18f5d9605..21cff8f12 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -3,6 +3,7 @@ package types import ( "encoding/json" "io" + "os" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -89,5 +90,5 @@ type ( // AppExporterToFile is a function that dumps all app state to // JSON-serializable structure and writes the result to a file. // This is useful when the output is too large to fit in memory. - AppExporterToFile func(log.Logger, dbm.DB, io.Writer, int64, bool, []string, AppOptions, string) error + AppExporterToFile func(log.Logger, dbm.DB, io.Writer, int64, bool, []string, AppOptions, *os.File) (ExportedApp, error) ) From ba56b81884b1a6a39b29ec244a4b05989409203a Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Fri, 21 Jun 2024 09:32:21 -0400 Subject: [PATCH 04/28] some fixes --- server/export.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server/export.go b/server/export.go index 253437e57..ac0edf3e8 100644 --- a/server/export.go +++ b/server/export.go @@ -10,6 +10,7 @@ import ( "time" "github.com/spf13/cobra" + tmbytes "github.com/tendermint/tendermint/libs/bytes" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client/flags" @@ -118,15 +119,17 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return cmd } -type GenesisDocNoAppHash struct { +type GenesisDocNoAppState struct { GenesisTime time.Time `json:"genesis_time"` ChainID string `json:"chain_id"` InitialHeight int64 `json:"initial_height,string"` ConsensusParams *tmtypes.ConsensusParams `json:"consensus_params,omitempty"` Validators []tmtypes.GenesisValidator `json:"validators,omitempty"` - AppState json.RawMessage `json:"app_state,omitempty"` + AppHash tmbytes.HexBytes `json:"app_hash"` } +// ExportToFileCmd dumps app state to JSON. It appends the app state module by module to the file. +// This is especially useful when the output is too large to fit in memory. func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ Use: "export-to-file [jsonfile]", @@ -163,7 +166,7 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome return err } - fmt.Println(string(genesis)) + file.Write(genesis) return nil } @@ -188,9 +191,10 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome return err } - genesisDocNoAppHash := GenesisDocNoAppHash{ + genesisDocNoAppHash := GenesisDocNoAppState{ GenesisTime: doc.GenesisTime, ChainID: doc.ChainID, + AppHash: doc.AppHash, InitialHeight: exported.Height, ConsensusParams: &tmtypes.ConsensusParams{ Block: tmtypes.BlockParams{ @@ -217,7 +221,7 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome return err } - file.Write([]byte(fmt.Sprintf(",%s",string(sdk.MustSortJSON(encoded))[1:]))) + file.Write([]byte(fmt.Sprintf(",%s", string(sdk.MustSortJSON(encoded))[1:]))) return nil }, } From 778d35ee885c2a62bbb9e009095ec65aa825eb23 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Fri, 21 Jun 2024 09:44:09 -0400 Subject: [PATCH 05/28] fix simapp --- simapp/simd/cmd/root.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 4b3f5dfee..c4a8e9e0c 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -170,7 +170,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { panic(err) } - server.AddCommands(rootCmd, simapp.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags, []trace.TracerProviderOption{ + server.AddCommands(rootCmd, simapp.DefaultNodeHome, a.newApp, a.appExport, a.appExporterToFile, addModuleInitFlags, []trace.TracerProviderOption{ trace.WithBatcher(exp), // Record information about this application in a Resource. trace.WithResource(resource.NewWithAttributes( @@ -333,3 +333,9 @@ func (a appCreator) appExport( return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) } + +func (a appCreator) appExporterToFile( + logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, + appOpts servertypes.AppOptions, file *os.File) (servertypes.ExportedApp, error) { + return a.appExport(logger, db, traceStore, height, forZeroHeight, jailAllowedAddrs, appOpts) +} From 57374b8e5318b960cc994da25dadca07415bc0b7 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Fri, 21 Jun 2024 09:46:00 -0400 Subject: [PATCH 06/28] minor fix --- server/export.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/export.go b/server/export.go index ac0edf3e8..87bbe1c02 100644 --- a/server/export.go +++ b/server/export.go @@ -119,7 +119,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return cmd } -type GenesisDocNoAppState struct { +type GenesisDocNoAppHash struct { GenesisTime time.Time `json:"genesis_time"` ChainID string `json:"chain_id"` InitialHeight int64 `json:"initial_height,string"` @@ -191,7 +191,7 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome return err } - genesisDocNoAppHash := GenesisDocNoAppState{ + genesisDocNoAppHash := GenesisDocNoAppHash{ GenesisTime: doc.GenesisTime, ChainID: doc.ChainID, AppHash: doc.AppHash, From 7d5d8588754db057fcbf5758421d5ae9dcc456c8 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Fri, 21 Jun 2024 16:35:34 -0400 Subject: [PATCH 07/28] debug --- types/module/module.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/module/module.go b/types/module/module.go index 690ac1a66..b8709ca23 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -367,7 +367,10 @@ func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string func (m *Manager) ProcessGenesisPerModule(ctx sdk.Context, cdc codec.JSONCodec, process func(string, json.RawMessage)) { for _, moduleName := range m.OrderExportGenesis { - process(moduleName, m.Modules[moduleName].ExportGenesis(ctx, cdc)) + fmt.Println("Processing module: ", moduleName) + jsonRawMsg := m.Modules[moduleName].ExportGenesis(ctx, cdc) + fmt.Println("len of jsonRawMsg: ", len(jsonRawMsg)) + process(moduleName, jsonRawMsg) } } From e9ece1fe733c800a371db3a44182b045a065fc6f Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Thu, 27 Jun 2024 10:32:24 -0400 Subject: [PATCH 08/28] debug --- server/export.go | 7 +++---- tests/mocks/types_module_module.go | 7 +++++++ types/module/module.go | 12 +++++++++--- x/accesscontrol/module.go | 9 +++++++++ x/auth/module.go | 9 +++++++++ x/auth/vesting/module.go | 9 +++++++++ x/authz/module/module.go | 9 +++++++++ x/bank/module.go | 9 +++++++++ x/capability/module.go | 9 +++++++++ x/crisis/module.go | 9 +++++++++ x/distribution/module.go | 9 +++++++++ x/evidence/module.go | 9 +++++++++ x/feegrant/module/module.go | 9 +++++++++ x/genutil/module.go | 9 +++++++++ x/gov/module.go | 9 +++++++++ x/mint/module.go | 9 +++++++++ x/params/module.go | 9 +++++++++ x/slashing/module.go | 9 +++++++++ x/staking/module.go | 9 +++++++++ x/upgrade/module.go | 9 +++++++++ 20 files changed, 172 insertions(+), 7 deletions(-) diff --git a/server/export.go b/server/export.go index 87bbe1c02..6b52ff3f1 100644 --- a/server/export.go +++ b/server/export.go @@ -119,7 +119,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return cmd } -type GenesisDocNoAppHash struct { +type GenesisDocNoAppState struct { GenesisTime time.Time `json:"genesis_time"` ChainID string `json:"chain_id"` InitialHeight int64 `json:"initial_height,string"` @@ -180,7 +180,6 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight) jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs) - file.Write([]byte("{")) exported, err := appExporterToFile(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, file) if err != nil { return fmt.Errorf("error exporting state: %v", err) @@ -191,7 +190,7 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome return err } - genesisDocNoAppHash := GenesisDocNoAppHash{ + genesisDocNoAppHash := GenesisDocNoAppState{ GenesisTime: doc.GenesisTime, ChainID: doc.ChainID, AppHash: doc.AppHash, @@ -221,7 +220,7 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome return err } - file.Write([]byte(fmt.Sprintf(",%s", string(sdk.MustSortJSON(encoded))[1:]))) + file.Write([]byte(fmt.Sprintf("%s", string(sdk.MustSortJSON(encoded))))) return nil }, } diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index 9a7dd5572..1fa8ef672 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -207,6 +207,13 @@ func (m *MockAppModuleGenesis) ExportGenesis(arg0 types0.Context, arg1 codec.JSO return ret0 } +func (m *MockAppModuleGenesis) StreamGenesis(arg0 types0.Context, arg1 codec.JSONCodec) <-chan json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StreamGenesis", arg0, arg1) + ret0, _ := ret[0].(<-chan json.RawMessage) + return ret0 +} + // ExportGenesis indicates an expected call of ExportGenesis. func (mr *MockAppModuleGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() diff --git a/types/module/module.go b/types/module/module.go index b8709ca23..3214cb8e3 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -154,6 +154,7 @@ type AppModuleGenesis interface { InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage + StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage } // AppModule is the standard form for an application module @@ -355,6 +356,10 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData } } +// TODO: make an initGenesisFromFile, instead of looping over modules, loop over each row/document +// - the name of the module will be in each row +// - make sure to stream each line, iostream kind of thing + // ExportGenesis performs export genesis functionality for modules func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string]json.RawMessage { genesisData := make(map[string]json.RawMessage) @@ -368,9 +373,10 @@ func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string func (m *Manager) ProcessGenesisPerModule(ctx sdk.Context, cdc codec.JSONCodec, process func(string, json.RawMessage)) { for _, moduleName := range m.OrderExportGenesis { fmt.Println("Processing module: ", moduleName) - jsonRawMsg := m.Modules[moduleName].ExportGenesis(ctx, cdc) - fmt.Println("len of jsonRawMsg: ", len(jsonRawMsg)) - process(moduleName, jsonRawMsg) + ch := m.Modules[moduleName].StreamGenesis(ctx, cdc) + for msg := range ch { + process(moduleName, msg) + } } } diff --git a/x/accesscontrol/module.go b/x/accesscontrol/module.go index 922c6a091..b01c0a43d 100644 --- a/x/accesscontrol/module.go +++ b/x/accesscontrol/module.go @@ -151,6 +151,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(genState) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 2 } diff --git a/x/auth/module.go b/x/auth/module.go index ef2d1f2e2..359604bf1 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -156,6 +156,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 78296fdd6..006b86752 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -120,5 +120,14 @@ func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMe return am.DefaultGenesis(cdc) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 2c652e1d8..e105d2408 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -150,6 +150,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/bank/module.go b/x/bank/module.go index 000c72070..ae654882d 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -160,6 +160,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 2 } diff --git a/x/capability/module.go b/x/capability/module.go index d448f0db4..8746f2c1f 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -138,6 +138,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(genState) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/crisis/module.go b/x/crisis/module.go index 445ef6860..a32744109 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -156,6 +156,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/distribution/module.go b/x/distribution/module.go index bb958b2c6..c88c204b6 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -161,6 +161,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 2 } diff --git a/x/evidence/module.go b/x/evidence/module.go index f7ce284b1..8f5be4d73 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -175,6 +175,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper)) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 421ecfca1..215750fd1 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -170,6 +170,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/genutil/module.go b/x/genutil/module.go index 4b8bcc72e..8b8710dc0 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -109,5 +109,14 @@ func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMe return am.DefaultGenesis(cdc) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/gov/module.go b/x/gov/module.go index be43b06ba..af5c161b0 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -183,6 +183,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } diff --git a/x/mint/module.go b/x/mint/module.go index 3cd0337ec..b9d34dfec 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -144,6 +144,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/params/module.go b/x/params/module.go index 4d41565db..0091e721e 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -110,6 +110,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + func (AppModule) Route() sdk.Route { return sdk.Route{} } // GenerateGenesisState performs a no-op. diff --git a/x/slashing/module.go b/x/slashing/module.go index 05b67abe0..991a30096 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -161,6 +161,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 4 } diff --git a/x/staking/module.go b/x/staking/module.go index 3892a8aa9..9c894a503 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -160,6 +160,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 2 } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index cb1dc05c6..b02c36f77 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -120,6 +120,15 @@ func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMe return am.DefaultGenesis(cdc) } +func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + ch := make(chan json.RawMessage) + go func() { + ch <- am.ExportGenesis(ctx, cdc) + close(ch) + }() + return ch +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } From c1d67504b8153182c4ada1519b6af61b224a3e8d Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Fri, 5 Jul 2024 13:50:22 -0700 Subject: [PATCH 09/28] validate-genesis using streaming works --- types/module/module.go | 34 +++++ x/accesscontrol/module.go | 10 ++ x/auth/module.go | 10 ++ x/auth/vesting/module.go | 9 ++ x/authz/module/module.go | 10 ++ x/bank/module.go | 10 ++ x/bank/types/genesis.go | 61 ++++++--- x/bank/types/metadata.go | 17 ++- x/capability/module.go | 10 ++ x/crisis/module.go | 10 ++ x/distribution/module.go | 10 ++ x/evidence/module.go | 10 ++ x/feegrant/module/module.go | 11 ++ x/genutil/client/cli/validate_genesis.go | 165 +++++++++++++++++++++++ x/genutil/module.go | 21 +++ x/gov/module.go | 10 ++ x/mint/module.go | 10 ++ x/params/module.go | 10 ++ x/slashing/module.go | 10 ++ x/staking/module.go | 10 ++ x/upgrade/module.go | 10 ++ 21 files changed, 436 insertions(+), 22 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index 3214cb8e3..74eb60176 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -55,6 +55,7 @@ type AppModuleBasic interface { DefaultGenesis(codec.JSONCodec) json.RawMessage ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error + ValidateGenesisStream(codec.JSONCodec, client.TxEncodingConfig, <-chan json.RawMessage) error // client functionality RegisterRESTRoutes(client.Context, *mux.Router) @@ -110,6 +111,39 @@ func (bm BasicManager) ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEn return nil } +func (bm BasicManager) ValidateGenesisStream(cdc codec.JSONCodec, txEncCfg client.TxEncodingConfig, moduleName string, genesisCh <-chan json.RawMessage, doneCh <-chan struct{}, errCh chan<- error) { + fmt.Println("In BasicManager.ValidateGenesisStream for module: ", moduleName) + // we have a stream of genesis data for a module + // will be told when we're done + // can signal for any errors + moduleGenesisCh := make(chan json.RawMessage) + moduleDoneCh := make(chan struct{}) + + var err error + + go func() { + fmt.Println("In BasicManager.ValidateGenesisStream kicked off go routine for module: ", moduleName) + err = bm[moduleName].ValidateGenesisStream(cdc, txEncCfg, moduleGenesisCh) + fmt.Println("In BasicManager.ValidateGenesisStream goroutine got err: ", err) + if err != nil { + errCh <- err + } + moduleDoneCh <- struct{}{} + }() + + for { + select { + case <-doneCh: + fmt.Println("In BasicManager.ValidateGenesisStream received from doneCh") + close(moduleGenesisCh) + return + case genesisChunk := <-genesisCh: + fmt.Println("In BasicManager.ValidateGenesisStream received from genesisCh") + moduleGenesisCh <- genesisChunk + } + } +} + // RegisterRESTRoutes registers all module rest routes func (bm BasicManager) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { for _, b := range bm { diff --git a/x/accesscontrol/module.go b/x/accesscontrol/module.go index b01c0a43d..6cc180388 100644 --- a/x/accesscontrol/module.go +++ b/x/accesscontrol/module.go @@ -68,6 +68,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return data.Params.Validate() } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the accesscontrol module. func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {} diff --git a/x/auth/module.go b/x/auth/module.go index 359604bf1..32d23faee 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -60,6 +60,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return types.ValidateGenesis(data) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the auth module. func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { rest.RegisterRoutes(clientCtx, rtr, types.StoreKey) diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 006b86752..a26f389c0 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -54,6 +54,15 @@ func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConf return nil } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} // RegisterRESTRoutes registers module's REST handlers. Currently, this is a no-op. func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} diff --git a/x/authz/module/module.go b/x/authz/module/module.go index e105d2408..05a6a635a 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -70,6 +70,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEn return authz.ValidateGenesis(data) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the authz module. func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, r *mux.Router) { } diff --git a/x/bank/module.go b/x/bank/module.go index ae654882d..aad8aeeae 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -66,6 +66,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingCo return data.Validate() } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the bank module. func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { rest.RegisterHandlers(clientCtx, rtr) diff --git a/x/bank/types/genesis.go b/x/bank/types/genesis.go index 68419eaab..5a4b981f5 100644 --- a/x/bank/types/genesis.go +++ b/x/bank/types/genesis.go @@ -15,23 +15,10 @@ func (gs GenesisState) Validate() error { return err } - seenBalances := make(map[string]bool) seenMetadatas := make(map[string]bool) - - totalSupply := sdk.Coins{} - - for _, balance := range gs.Balances { - if seenBalances[balance.Address] { - return fmt.Errorf("duplicate balance for address %s", balance.Address) - } - - if err := balance.Validate(); err != nil { - return err - } - - seenBalances[balance.Address] = true - - totalSupply = totalSupply.Add(balance.Coins...) + totalSupply, err := getTotalSupply(&gs) + if err != nil { + return err } for _, metadata := range gs.DenomMetadata { @@ -61,6 +48,48 @@ func (gs GenesisState) Validate() error { return nil } +func getTotalSupply(genState *GenesisState) (sdk.Coins, error) { + totalSupply := sdk.Coins{} + totalWeiBalance := sdk.ZeroInt() + + genState.Balances = SanitizeGenesisBalances(genState.Balances) + seenBalances := make(map[string]bool) + for _, balance := range genState.Balances { + if seenBalances[balance.Address] { + return nil, fmt.Errorf("duplicate balance for address %s", balance.Address) + } + seenBalances[balance.Address] = true + coins := balance.Coins + err := balance.Validate() + if err != nil { + return nil, err + } + totalSupply = totalSupply.Add(coins...) + } + for _, weiBalance := range genState.WeiBalances { + totalWeiBalance = totalWeiBalance.Add(weiBalance.Amount) + } + weiInUsei, weiRemainder := SplitUseiWeiAmount(totalWeiBalance) + if !weiRemainder.IsZero() { + return nil, fmt.Errorf("non-zero wei remainder %s", weiRemainder) + } + baseDenom, err := sdk.GetBaseDenom() + if err != nil { + if !weiInUsei.IsZero() { + return nil, fmt.Errorf("base denom is not registered %s yet there exists wei balance %s", err, weiInUsei) + } + } else { + totalSupply = totalSupply.Add(sdk.NewCoin(baseDenom, weiInUsei)) + } + return totalSupply, nil +} + +var OneUseiInWei sdk.Int = sdk.NewInt(1_000_000_000_000) + +func SplitUseiWeiAmount(amt sdk.Int) (sdk.Int, sdk.Int) { + return amt.Quo(OneUseiInWei), amt.Mod(OneUseiInWei) +} + // NewGenesisState creates a new genesis state. func NewGenesisState(params Params, balances []Balance, supply sdk.Coins, denomMetaData []Metadata, weiBalances []WeiBalance) *GenesisState { return &GenesisState{ diff --git a/x/bank/types/metadata.go b/x/bank/types/metadata.go index 9583b85ce..26ed56a65 100644 --- a/x/bank/types/metadata.go +++ b/x/bank/types/metadata.go @@ -9,12 +9,12 @@ import ( ) // Validate performs a basic validation of the coin metadata fields. It checks: -// - Name and Symbol are not blank -// - Base and Display denominations are valid coin denominations -// - Base and Display denominations are present in the DenomUnit slice -// - Base denomination has exponent 0 -// - Denomination units are sorted in ascending order -// - Denomination units not duplicated +// - Name and Symbol are not blank +// - Base and Display denominations are valid coin denominations +// - Base and Display denominations are present in the DenomUnit slice +// - Base denomination has exponent 0 +// - Denomination units are sorted in ascending order +// - Denomination units not duplicated func (m Metadata) Validate() error { if strings.TrimSpace(m.Name) == "" { return errors.New("name field cannot be blank") @@ -39,13 +39,18 @@ func (m Metadata) Validate() error { seenUnits := make(map[string]bool) + fmt.Printf("m = %+v\n", m) + fmt.Println("m.DenomUnits = ", m.DenomUnits) + for i, denomUnit := range m.DenomUnits { // The first denomination unit MUST be the base if i == 0 { // validate denomination and exponent if denomUnit.Denom != m.Base { + fmt.Println("denomUnit.Denom = ", denomUnit.Denom) return fmt.Errorf("metadata's first denomination unit must be the one with base denom '%s'", m.Base) } + fmt.Println("denomUnit.Exponent = ", denomUnit.Exponent) if denomUnit.Exponent != 0 { return fmt.Errorf("the exponent for base denomination unit %s must be 0", m.Base) } diff --git a/x/capability/module.go b/x/capability/module.go index 8746f2c1f..2457737e7 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -68,6 +68,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return genState.Validate() } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the capability module's REST service handlers. func (a AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} diff --git a/x/crisis/module.go b/x/crisis/module.go index a32744109..1a238e213 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -60,6 +60,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return types.ValidateGenesis(&data) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers no REST routes for the crisis module. func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} diff --git a/x/distribution/module.go b/x/distribution/module.go index c88c204b6..a62e2e9ca 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -62,6 +62,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEn return types.ValidateGenesis(&data) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the distribution module. func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, rtr *mux.Router) { rest.RegisterHandlers(clientCtx, rtr) diff --git a/x/evidence/module.go b/x/evidence/module.go index 8f5be4d73..7dc683180 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -74,6 +74,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return gs.Validate() } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the evidence module's REST service handlers. func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { evidenceRESTHandlers := make([]rest.EvidenceRESTHandler, len(a.evidenceHandlers)) diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 215750fd1..15bca9ee3 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -11,6 +11,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/client" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -81,6 +82,16 @@ func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.Tx return feegrant.ValidateGenesis(data) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the feegrant module. func (AppModuleBasic) RegisterRESTRoutes(ctx sdkclient.Context, rtr *mux.Router) {} diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 6c8e27dda..b1615c789 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -1,8 +1,13 @@ package cli import ( + "bufio" + "bytes" "encoding/json" "fmt" + "io" + "os" + "strings" "github.com/spf13/cobra" tmtypes "github.com/tendermint/tendermint/types" @@ -54,6 +59,166 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { } } +type AppState struct { + Module string `json:"module"` + Data json.RawMessage `json:"data"` +} + +type ModuleState struct { + AppState AppState `json:"app_state"` +} + +func parseModule(jsonStr string) (*ModuleState, error) { + var module ModuleState + err := json.Unmarshal([]byte(jsonStr), &module) + if err != nil { + return nil, err + } + if module.AppState.Module == "" { + return nil, fmt.Errorf("module name is empty") + } + return &module, nil +} + +// ValidateGenesisCmd takes a genesis file, and makes sure that it is valid. +func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { + return &cobra.Command{ + Use: "validate-genesis-stream [file]", + Args: cobra.RangeArgs(0, 1), + Short: "validates the genesis file at the default location or at the location passed as an arg", + RunE: func(cmd *cobra.Command, args []string) (err error) { + serverCtx := server.GetServerContextFromCmd(cmd) + clientCtx := client.GetClientContextFromCmd(cmd) + + cdc := clientCtx.Codec + + // Load default if passed no args, otherwise load passed file + var genesis string + if len(args) == 0 { + genesis = serverCtx.Config.GenesisFile() + } else { + genesis = args[0] + } + + lines := ingestGenesisFileLineByLine(genesis) + if err != nil { + return err + } + fmt.Println("lines = ", lines) + + // for each line, parse it as a module first + // if it's a new module then open up a new channel for this module + // call mbm.ValidateGenesisStream for this new module + // mbm.ValidateGenesisStream should be in a goroutine?? + // it should remain open until we see the next module OR GenDoc + // if we see the same module again, we should send the data to the same channel + // also make sure you don't see a module twice--that's an error + + genesisCh := make(chan json.RawMessage) + doneCh := make(chan struct{}) + errCh := make(chan error, 1) + seenModules := make(map[string]bool) + prevModule := "" + var moduleName string + var genDoc *tmtypes.GenesisDoc + go func() { + for line := range lines { + moduleState, err := parseModule(line) + // determine module name or genesisDoc + if err != nil { + genDoc, err = tmtypes.GenesisDocFromJSON([]byte(line)) + if err != nil { + errCh <- fmt.Errorf("error unmarshalling genesis doc %s: %s", genesis, err.Error()) + return + } + moduleName = "genesisDoc" + } else { + moduleName = moduleState.AppState.Module + } + if seenModules[moduleName] { + errCh <- fmt.Errorf("module %s seen twice in genesis file", moduleName) + return + } + if prevModule != moduleName { // new module + if prevModule != "" && prevModule != "genesisDoc" { + doneCh <- struct{}{} + } + seenModules[prevModule] = true + if moduleName != "genesisDoc" { + fmt.Println("In ValidateGenesisStreamCmd, kicking off mbm.ValidateGenesisStream for module ", moduleName) + go mbm.ValidateGenesisStream(cdc, clientCtx.TxConfig, moduleName, genesisCh, doneCh, errCh) + genesisCh <- moduleState.AppState.Data + } else { + err = genDoc.ValidateAndComplete() + if err != nil { + errCh <- fmt.Errorf("error validating genesis doc %s: %s", genesis, err.Error()) + } + } + } else { // same module + genesisCh <- moduleState.AppState.Data + } + prevModule = moduleName + } + errCh <- nil + }() + err = <-errCh + return err + }, + } +} + +const bufferSize = 100000 + +func ingestGenesisFileLineByLine(filename string) <-chan string { + lines := make(chan string) + + go func() { + defer close(lines) + + file, err := os.Open(filename) + if err != nil { + fmt.Println("Error opening file:", err) + return + } + defer file.Close() + + reader := bufio.NewReader(file) + buffer := make([]byte, bufferSize) + lineBuf := new(strings.Builder) + + for { + bytesRead, err := reader.Read(buffer) + if err != nil && err != io.EOF { + fmt.Println("Error reading file:", err) + return + } + + chunk := buffer[:bytesRead] + for len(chunk) > 0 { + i := bytes.IndexByte(chunk, '\n') + if i >= 0 { + lineBuf.Write(chunk[:i]) + lines <- lineBuf.String() + lineBuf.Reset() + chunk = chunk[i+1:] + } else { + lineBuf.Write(chunk) + break + } + } + + if err == io.EOF { + if lineBuf.Len() > 0 { + lines <- lineBuf.String() + } + break + } + } + }() + + return lines +} + // validateGenDoc reads a genesis file and validates that it is a correct // Tendermint GenesisDoc. This function does not do any cosmos-related // validation. diff --git a/x/genutil/module.go b/x/genutil/module.go index 8b8710dc0..b9cd37f87 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -45,6 +45,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { // ValidateGenesis performs genesis state validation for the genutil module. func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, txEncodingConfig client.TxEncodingConfig, bz json.RawMessage) error { + fmt.Println("In genutil ValidateGenesis") var data types.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) @@ -53,6 +54,16 @@ func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, txEncodingConfig cl return types.ValidateGenesis(&data, txEncodingConfig.TxJSONDecoder()) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the genutil module. func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} @@ -118,5 +129,15 @@ func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan j return ch } +func (am AppModule) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/gov/module.go b/x/gov/module.go index af5c161b0..733576c15 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -72,6 +72,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return types.ValidateGenesis(&data) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the gov module. func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { proposalRESTHandlers := make([]rest.ProposalRESTHandler, 0, len(a.proposalHandlers)) diff --git a/x/mint/module.go b/x/mint/module.go index b9d34dfec..037302895 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -64,6 +64,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return types.ValidateGenesis(data) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the mint module. func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { rest.RegisterRoutes(clientCtx, rtr) diff --git a/x/params/module.go b/x/params/module.go index 0091e721e..b5d2e211c 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -60,6 +60,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return data.Validate() } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the params module. func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} diff --git a/x/slashing/module.go b/x/slashing/module.go index 991a30096..d24292e6b 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -70,6 +70,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return types.ValidateGenesis(data) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the slashing module. func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { rest.RegisterHandlers(clientCtx, rtr) diff --git a/x/staking/module.go b/x/staking/module.go index 9c894a503..30b7704ab 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -69,6 +69,16 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return ValidateGenesis(&data) } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // RegisterRESTRoutes registers the REST routes for the staking module. func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { rest.RegisterHandlers(clientCtx, rtr) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index b02c36f77..293344521 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -115,6 +115,16 @@ func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, config client.TxEncodin return nil } +func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config client.TxEncodingConfig, genesisCh <-chan json.RawMessage) error { + for genesis := range genesisCh { + err := am.ValidateGenesis(cdc, config, genesis) + if err != nil { + return err + } + } + return nil +} + // ExportGenesis is always empty, as InitGenesis does nothing either func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { return am.DefaultGenesis(cdc) From 748bdf1ce3673863c7644a927f7b22174d650edf Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Mon, 8 Jul 2024 22:42:27 -0400 Subject: [PATCH 10/28] only validate genesis for ibc --- x/genutil/client/cli/validate_genesis.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index b1615c789..7a62f6312 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -135,6 +135,9 @@ func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { } else { moduleName = moduleState.AppState.Module } + if moduleName != "ibc" { + continue + } if seenModules[moduleName] { errCh <- fmt.Errorf("module %s seen twice in genesis file", moduleName) return @@ -155,6 +158,7 @@ func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { } } } else { // same module + fmt.Println("Sending data to channel for module ", moduleName) genesisCh <- moduleState.AppState.Data } prevModule = moduleName From 0177e036b74569088f480c202b757c09b6e11db8 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Tue, 9 Jul 2024 18:47:31 -0400 Subject: [PATCH 11/28] do all modules --- x/genutil/client/cli/validate_genesis.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 7a62f6312..6f27501a2 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -135,9 +135,6 @@ func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { } else { moduleName = moduleState.AppState.Module } - if moduleName != "ibc" { - continue - } if seenModules[moduleName] { errCh <- fmt.Errorf("module %s seen twice in genesis file", moduleName) return From 227160509c14958d3abc621fe6975f17631a7f86 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Fri, 12 Jul 2024 09:42:36 -0400 Subject: [PATCH 12/28] checkpoint -- get import to work --- baseapp/abci.go | 1 + server/export.go | 1 + server/rollback.go | 1 + server/start.go | 34 +++++++++-- simapp/app.go | 3 +- types/module/module.go | 78 ++++++++++++++++++++---- x/genutil/client/cli/validate_genesis.go | 73 +--------------------- 7 files changed, 105 insertions(+), 86 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index ad420d0c2..bea67ac5f 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -31,6 +31,7 @@ import ( // InitChain implements the ABCI interface. It runs the initialization logic // directly on the CommitMultiStore. +// JEREMYFLAG: Tendermint calls here func (app *BaseApp) InitChain(ctx context.Context, req *abci.RequestInitChain) (res *abci.ResponseInitChain, err error) { // On a new chain, we consider the init chain block height as 0, even though // req.InitialHeight is 1 by default. diff --git a/server/export.go b/server/export.go index 6b52ff3f1..56701146a 100644 --- a/server/export.go +++ b/server/export.go @@ -130,6 +130,7 @@ type GenesisDocNoAppState struct { // ExportToFileCmd dumps app state to JSON. It appends the app state module by module to the file. // This is especially useful when the output is too large to fit in memory. +// TODO: change name to ExportStream, also can make it a flag under export func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ Use: "export-to-file [jsonfile]", diff --git a/server/rollback.go b/server/rollback.go index 7d95e96dc..55bbb7545 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -9,6 +9,7 @@ import ( tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" ) + var removeBlock = false // NewRollbackCmd creates a command to rollback tendermint and multistore state by one height. diff --git a/server/start.go b/server/start.go index aedc274e4..aa814dae0 100644 --- a/server/start.go +++ b/server/start.go @@ -13,6 +13,7 @@ import ( clientconfig "github.com/cosmos/cosmos-sdk/client/config" + genesistypes "github.com/cosmos/cosmos-sdk/types/genesis" "github.com/spf13/cobra" abciclient "github.com/tendermint/tendermint/abci/client" "github.com/tendermint/tendermint/abci/server" @@ -84,6 +85,10 @@ const ( flagGRPCWebEnable = "grpc-web.enable" flagGRPCWebAddress = "grpc-web.address" + // genesis import method + FlagGenesisImportStream = "genesis-import-stream" + FlagGenesisImportFile = "genesis-import-file" + // archival related flags FlagArchivalVersion = "archival-version" FlagArchivalDBType = "archival-db-type" @@ -170,9 +175,14 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. serverCtx.Viper.Set(flags.FlagChainID, chainID) - genesisFile, _ := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) - if genesisFile.ChainID != clientCtx.ChainID { - panic(fmt.Sprintf("genesis file chain-id=%s does not equal config.toml chain-id=%s", genesisFile.ChainID, clientCtx.ChainID)) + genesisStreaming, _ := cmd.Flags().GetBool(FlagGenesisImportStream) + serverCtx.Viper.Set(FlagGenesisImportStream, genesisStreaming) + serverCtx.Viper.Set(FlagGenesisImportFile, serverCtx.Config.GenesisFile()) + if !genesisStreaming { + genesisFile, _ := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) + if genesisFile.ChainID != clientCtx.ChainID { + panic(fmt.Sprintf("genesis file chain-id=%s does not equal config.toml chain-id=%s", genesisFile.ChainID, clientCtx.ChainID)) + } } if enableTracing, _ := cmd.Flags().GetBool(tracing.FlagTracing); !enableTracing { @@ -271,6 +281,8 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().String(FlagArchivalArweaveNodeURL, "", "Arweave Node URL that stores archived data") cmd.Flags().Bool(FlagIAVLFastNode, true, "Enable fast node for IAVL tree") + cmd.Flags().Bool(FlagGenesisImportStream, false, "Enable streaming genesis file import, useful for large genesis files") + cmd.Flags().String(FlagChainID, "", "Chain ID") // add support for all Tendermint-specific command line options @@ -386,13 +398,27 @@ func startInProcess( config.GRPC.Enable = true } else { ctx.Logger.Info("starting node with ABCI Tendermint in-process") + var gen *tmtypes.GenesisDoc + if ctx.Viper.Get(FlagGenesisImportStream).(bool) { + lines := genesistypes.IngestGenesisFileLineByLine(ctx.Viper.GetString(FlagGenesisImportFile)) + for line := range lines { + genDoc, err := tmtypes.GenesisDocFromJSON([]byte(line)) + if err != nil { + continue + } + if gen != nil { + return fmt.Errorf("error: multiple genesis docs found in stream") + } + gen = genDoc + } + } tmNode, err = node.New( goCtx, ctx.Config, ctx.Logger, restartCh, abciclient.NewLocalClient(ctx.Logger, app), - nil, + gen, tracerProviderOptions, nodeMetricsProvider, ) diff --git a/simapp/app.go b/simapp/app.go index 521584fa4..dae4e9e0b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -32,6 +32,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/streaming" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + genesistypes "github.com/cosmos/cosmos-sdk/types/genesis" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/utils" "github.com/cosmos/cosmos-sdk/version" @@ -594,7 +595,7 @@ func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci. panic(err) } app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()) - return app.mm.InitGenesis(ctx, app.appCodec, genesisState) + return app.mm.InitGenesis(ctx, app.appCodec, genesisState, genesistypes.GenesisImportConfig{}) } // LoadHeight loads a particular height diff --git a/types/module/module.go b/types/module/module.go index 74eb60176..a9e7471a1 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -45,6 +45,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + genesistypes "github.com/cosmos/cosmos-sdk/types/genesis" ) // AppModuleBasic is the standard form for basic non-dependant elements of an application module. @@ -187,7 +188,9 @@ type AppModuleGenesis interface { AppModuleBasic InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate + // InitGenesisStream(sdk.Context, codec.JSONCodec, <-chan json.RawMessage) error ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage + // TODO: change to ExportGenesisStream StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage } @@ -365,23 +368,76 @@ func (m *Manager) RegisterServices(cfg Configurator) { } } +type AppState struct { + Module string `json:"module"` + Data json.RawMessage `json:"data"` +} + +type ModuleState struct { + AppState AppState `json:"app_state"` +} + +func parseModule(jsonStr string) (*ModuleState, error) { + var module ModuleState + err := json.Unmarshal([]byte(jsonStr), &module) + if err != nil { + return nil, err + } + if module.AppState.Module == "" { + return nil, fmt.Errorf("module name is empty") + } + return &module, nil +} + // InitGenesis performs init genesis functionality for modules -func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData map[string]json.RawMessage) abci.ResponseInitChain { +// JEREMYFLAG: Manager InitGenesis - Will call InitGenesis to all modules +func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData map[string]json.RawMessage, genesisImportConfig genesistypes.GenesisImportConfig) abci.ResponseInitChain { var validatorUpdates []abci.ValidatorUpdate - for _, moduleName := range m.OrderInitGenesis { - if genesisData[moduleName] == nil { - continue + // if we're streaming it, then I want to + if genesisImportConfig.StreamGenesisImport { + lines := genesistypes.IngestGenesisFileLineByLine(genesisImportConfig.GenesisStreamFile) + errCh := make(chan error, 1) + seenModules := make(map[string]bool) + var moduleName string + go func() { + for line := range lines { + moduleState, err := parseModule(line) + if err != nil { + moduleName = "genesisDoc" + } else { + moduleName = moduleState.AppState.Module + } + if moduleName == "genesisDoc" { + continue + } + if seenModules[moduleName] { + errCh <- fmt.Errorf("module %s seen twice in genesis file", moduleName) + return + } + m.Modules[moduleName].InitGenesis(ctx, cdc, moduleState.AppState.Data) + } + errCh <- nil + }() + err := <-errCh + if err != nil { + panic(err) } + } else { + for _, moduleName := range m.OrderInitGenesis { + if genesisData[moduleName] == nil { + continue + } - moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, cdc, genesisData[moduleName]) + moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, cdc, genesisData[moduleName]) - // use these validator updates if provided, the module manager assumes - // only one module will update the validator set - if len(moduleValUpdates) > 0 { - if len(validatorUpdates) > 0 { - panic("validator InitGenesis updates already set by a previous module") + // use these validator updates if provided, the module manager assumes + // only one module will update the validator set + if len(moduleValUpdates) > 0 { + if len(validatorUpdates) > 0 { + panic("validator InitGenesis updates already set by a previous module") + } + validatorUpdates = moduleValUpdates } - validatorUpdates = moduleValUpdates } } diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 6f27501a2..6a79a00ad 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -1,14 +1,10 @@ package cli import ( - "bufio" - "bytes" "encoding/json" "fmt" - "io" - "os" - "strings" + genesistypes "github.com/cosmos/cosmos-sdk/types/genesis" "github.com/spf13/cobra" tmtypes "github.com/tendermint/tendermint/types" @@ -80,6 +76,7 @@ func parseModule(jsonStr string) (*ModuleState, error) { return &module, nil } +// TODO: change to flag under validate-genesis instead of own command // ValidateGenesisCmd takes a genesis file, and makes sure that it is valid. func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { return &cobra.Command{ @@ -100,19 +97,7 @@ func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { genesis = args[0] } - lines := ingestGenesisFileLineByLine(genesis) - if err != nil { - return err - } - fmt.Println("lines = ", lines) - - // for each line, parse it as a module first - // if it's a new module then open up a new channel for this module - // call mbm.ValidateGenesisStream for this new module - // mbm.ValidateGenesisStream should be in a goroutine?? - // it should remain open until we see the next module OR GenDoc - // if we see the same module again, we should send the data to the same channel - // also make sure you don't see a module twice--that's an error + lines := genesistypes.IngestGenesisFileLineByLine(genesis) genesisCh := make(chan json.RawMessage) doneCh := make(chan struct{}) @@ -168,58 +153,6 @@ func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { } } -const bufferSize = 100000 - -func ingestGenesisFileLineByLine(filename string) <-chan string { - lines := make(chan string) - - go func() { - defer close(lines) - - file, err := os.Open(filename) - if err != nil { - fmt.Println("Error opening file:", err) - return - } - defer file.Close() - - reader := bufio.NewReader(file) - buffer := make([]byte, bufferSize) - lineBuf := new(strings.Builder) - - for { - bytesRead, err := reader.Read(buffer) - if err != nil && err != io.EOF { - fmt.Println("Error reading file:", err) - return - } - - chunk := buffer[:bytesRead] - for len(chunk) > 0 { - i := bytes.IndexByte(chunk, '\n') - if i >= 0 { - lineBuf.Write(chunk[:i]) - lines <- lineBuf.String() - lineBuf.Reset() - chunk = chunk[i+1:] - } else { - lineBuf.Write(chunk) - break - } - } - - if err == io.EOF { - if lineBuf.Len() > 0 { - lines <- lineBuf.String() - } - break - } - } - }() - - return lines -} - // validateGenDoc reads a genesis file and validates that it is a correct // Tendermint GenesisDoc. This function does not do any cosmos-related // validation. From f8685be7ca2c7efee14e1e6fd4d743379d26e1e8 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Fri, 12 Jul 2024 09:44:51 -0400 Subject: [PATCH 13/28] forgot a file --- types/genesis/genesis.go | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 types/genesis/genesis.go diff --git a/types/genesis/genesis.go b/types/genesis/genesis.go new file mode 100644 index 000000000..d7bc04f1c --- /dev/null +++ b/types/genesis/genesis.go @@ -0,0 +1,68 @@ +package genesis + +import ( + "bufio" + "bytes" + "fmt" + "io" + "os" + "strings" +) + +type GenesisImportConfig struct { + StreamGenesisImport bool + GenesisStreamFile string +} + +const bufferSize = 100000 + +func IngestGenesisFileLineByLine(filename string) <-chan string { + lines := make(chan string) + + go func() { + defer close(lines) + + file, err := os.Open(filename) + if err != nil { + fmt.Println("Error opening file:", err) + return + } + defer file.Close() + + reader := bufio.NewReader(file) + + buffer := make([]byte, bufferSize) + lineBuf := new(strings.Builder) + + for { + bytesRead, err := reader.Read(buffer) + if err != nil && err != io.EOF { + fmt.Println("Error reading file:", err) + return + } + + chunk := buffer[:bytesRead] + for len(chunk) > 0 { + i := bytes.IndexByte(chunk, '\n') + if i >= 0 { + lineBuf.Write(chunk[:i]) + lines <- lineBuf.String() + lineBuf.Reset() + chunk = chunk[i+1:] + } else { + lineBuf.Write(chunk) + break + } + } + + if err == io.EOF { + if lineBuf.Len() > 0 { + lines <- lineBuf.String() + } + break + } + } + }() + + return lines +} From 8aa4ec09bd0bae2eaded56df6b733c913897e5b2 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Tue, 16 Jul 2024 17:16:55 -0400 Subject: [PATCH 14/28] export, validate, import work locally --- server/start.go | 3 +++ types/module/module.go | 15 +++++++++++++-- x/crisis/module.go | 1 + x/distribution/keeper/store.go | 3 +++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/server/start.go b/server/start.go index aa814dae0..8c4ac7e3c 100644 --- a/server/start.go +++ b/server/start.go @@ -402,16 +402,19 @@ func startInProcess( if ctx.Viper.Get(FlagGenesisImportStream).(bool) { lines := genesistypes.IngestGenesisFileLineByLine(ctx.Viper.GetString(FlagGenesisImportFile)) for line := range lines { + fmt.Println("checking line = ", line) genDoc, err := tmtypes.GenesisDocFromJSON([]byte(line)) if err != nil { continue } + fmt.Println("found valid genDoc") if gen != nil { return fmt.Errorf("error: multiple genesis docs found in stream") } gen = genDoc } } + fmt.Printf("gen = %+v\n", gen) tmNode, err = node.New( goCtx, ctx.Config, diff --git a/types/module/module.go b/types/module/module.go index a9e7471a1..384721de7 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -414,7 +414,14 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData errCh <- fmt.Errorf("module %s seen twice in genesis file", moduleName) return } - m.Modules[moduleName].InitGenesis(ctx, cdc, moduleState.AppState.Data) + fmt.Println("Calling initGenesis for module: ", moduleName, " with data: ", string(moduleState.AppState.Data)) + moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, cdc, moduleState.AppState.Data) + if len(moduleValUpdates) > 0 { + if len(validatorUpdates) > 0 { + panic("validator InitGenesis updates already set by a previous module") + } + validatorUpdates = moduleValUpdates + } } errCh <- nil }() @@ -423,6 +430,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData panic(err) } } else { + fmt.Println("order init genesis = ", m.OrderInitGenesis) for _, moduleName := range m.OrderInitGenesis { if genesisData[moduleName] == nil { continue @@ -461,7 +469,10 @@ func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string } func (m *Manager) ProcessGenesisPerModule(ctx sdk.Context, cdc codec.JSONCodec, process func(string, json.RawMessage)) { - for _, moduleName := range m.OrderExportGenesis { + // It's important that we use OrderInitGenesis here instead of OrderExportGenesis because the order of exporting + // doesn't matter much but the order of importing does due to invariant checks and how we are streaming the genesis + // file here + for _, moduleName := range m.OrderInitGenesis { fmt.Println("Processing module: ", moduleName) ch := m.Modules[moduleName].StreamGenesis(ctx, cdc) for msg := range ch { diff --git a/x/crisis/module.go b/x/crisis/module.go index 1a238e213..fdc042d09 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -147,6 +147,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the crisis module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + fmt.Println("data = ", string(data)) start := time.Now() var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) diff --git a/x/distribution/keeper/store.go b/x/distribution/keeper/store.go index 0203ee13f..dc19baec1 100644 --- a/x/distribution/keeper/store.go +++ b/x/distribution/keeper/store.go @@ -1,6 +1,8 @@ package keeper import ( + "fmt" + gogotypes "github.com/gogo/protobuf/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -47,6 +49,7 @@ func (k Keeper) IterateDelegatorWithdrawAddrs(ctx sdk.Context, handler func(del func (k Keeper) GetFeePool(ctx sdk.Context) (feePool types.FeePool) { store := ctx.KVStore(k.storeKey) b := store.Get(types.FeePoolKey) + fmt.Println("fee pool key = ", b, ", is b == nil?", b == nil) if b == nil { panic("Stored fee pool should not have been nil") } From 290e5e79e611377d8bf514a53443e38e64f0c314 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Wed, 17 Jul 2024 09:10:59 -0400 Subject: [PATCH 15/28] remove prints --- server/start.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/server/start.go b/server/start.go index 8c4ac7e3c..aa814dae0 100644 --- a/server/start.go +++ b/server/start.go @@ -402,19 +402,16 @@ func startInProcess( if ctx.Viper.Get(FlagGenesisImportStream).(bool) { lines := genesistypes.IngestGenesisFileLineByLine(ctx.Viper.GetString(FlagGenesisImportFile)) for line := range lines { - fmt.Println("checking line = ", line) genDoc, err := tmtypes.GenesisDocFromJSON([]byte(line)) if err != nil { continue } - fmt.Println("found valid genDoc") if gen != nil { return fmt.Errorf("error: multiple genesis docs found in stream") } gen = genDoc } } - fmt.Printf("gen = %+v\n", gen) tmNode, err = node.New( goCtx, ctx.Config, From 91e6100e465a414c92e9cfbd70a145ea8eb85031 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Wed, 17 Jul 2024 14:32:00 -0400 Subject: [PATCH 16/28] remove some prints --- types/module/module.go | 1 - 1 file changed, 1 deletion(-) diff --git a/types/module/module.go b/types/module/module.go index 384721de7..6fe3b584d 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -414,7 +414,6 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData errCh <- fmt.Errorf("module %s seen twice in genesis file", moduleName) return } - fmt.Println("Calling initGenesis for module: ", moduleName, " with data: ", string(moduleState.AppState.Data)) moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, cdc, moduleState.AppState.Data) if len(moduleValUpdates) > 0 { if len(validatorUpdates) > 0 { From 37ed60a7006029278549b6e0368383902b035ff6 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Sat, 20 Jul 2024 06:50:27 -0400 Subject: [PATCH 17/28] change seid start flag to config in app.toml --- server/config/config.go | 18 ++++++++++++++++++ server/config/toml.go | 14 ++++++++++++++ server/start.go | 26 ++++++++------------------ types/module/module.go | 1 - 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index c34408006..e7a663ca5 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -192,6 +192,15 @@ type StateSyncConfig struct { SnapshotDirectory string `mapstructure:"snapshot-directory"` } +// GenesisConfig defines the genesis export, validation, and import configuration +type GenesisConfig struct { + // StreamImport defines if the genesis.json is in stream form or not. + StreamImport bool `mapstructure:"stream-import"` + + // ImportFile sets the genesis json file from which to stream from + ImportFile string `mapstructure:"import-file"` +} + // Config defines the server's top level configuration type Config struct { BaseConfig `mapstructure:",squash"` @@ -205,6 +214,7 @@ type Config struct { StateSync StateSyncConfig `mapstructure:"state-sync"` StateCommit config.StateCommitConfig `mapstructure:"state-commit"` StateStore config.StateStoreConfig `mapstructure:"state-store"` + Genesis GenesisConfig `mapstructure:genesis` } // SetMinGasPrices sets the validator's minimum gas prices. @@ -288,6 +298,10 @@ func DefaultConfig() *Config { }, StateCommit: config.DefaultStateCommitConfig(), StateStore: config.DefaultStateStoreConfig(), + Genesis: GenesisConfig{ + StreamImport: false, + ImportFile: "", + }, } } @@ -391,6 +405,10 @@ func GetConfig(v *viper.Viper) (Config, error) { PruneIntervalSeconds: v.GetInt("state-store.prune-interval-seconds"), ImportNumWorkers: v.GetInt("state-store.import-num-workers"), }, + Genesis: GenesisConfig{ + StreamImport: v.GetBool("genesis.stream-import"), + ImportFile: v.GetString("genesis.import-file"), + }, }, nil } diff --git a/server/config/toml.go b/server/config/toml.go index 6e1addfc4..3e9cd9104 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -246,6 +246,20 @@ snapshot-keep-recent = {{ .StateSync.SnapshotKeepRecent }} # default is emtpy which will then store under the app home directory same as before. snapshot-directory = "{{ .StateSync.SnapshotDirectory }}" +############################################################################### +### Genesis Configuration ### +############################################################################### + + +# Genesis config allows configuring whether to stream from an genesis json file in streamed form +[genesis] + +# stream-import specifies whether to the stream the import from the genesis json file. The genesis +# file must be in stream form and exported in a streaming fashion. +stream-import = {{ .Genesis.StreamImport }} + +# import-file specifies the path of the genesis json file to stream from. +import-file = "{{ .Genesis.ImportFile }}" ` + config.DefaultConfigTemplate var configTemplate *template.Template diff --git a/server/start.go b/server/start.go index aa814dae0..ff0c1eca2 100644 --- a/server/start.go +++ b/server/start.go @@ -85,10 +85,6 @@ const ( flagGRPCWebEnable = "grpc-web.enable" flagGRPCWebAddress = "grpc-web.address" - // genesis import method - FlagGenesisImportStream = "genesis-import-stream" - FlagGenesisImportFile = "genesis-import-file" - // archival related flags FlagArchivalVersion = "archival-version" FlagArchivalDBType = "archival-db-type" @@ -175,16 +171,6 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. serverCtx.Viper.Set(flags.FlagChainID, chainID) - genesisStreaming, _ := cmd.Flags().GetBool(FlagGenesisImportStream) - serverCtx.Viper.Set(FlagGenesisImportStream, genesisStreaming) - serverCtx.Viper.Set(FlagGenesisImportFile, serverCtx.Config.GenesisFile()) - if !genesisStreaming { - genesisFile, _ := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) - if genesisFile.ChainID != clientCtx.ChainID { - panic(fmt.Sprintf("genesis file chain-id=%s does not equal config.toml chain-id=%s", genesisFile.ChainID, clientCtx.ChainID)) - } - } - if enableTracing, _ := cmd.Flags().GetBool(tracing.FlagTracing); !enableTracing { serverCtx.Logger.Info("--tracing not passed in, tracing is not enabled") tracerProviderOptions = []trace.TracerProviderOption{} @@ -207,6 +193,12 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. if err != nil { return fmt.Errorf("failed to initialize telemetry: %w", err) } + if !config.Genesis.StreamImport { + genesisFile, _ := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) + if genesisFile.ChainID != clientCtx.ChainID { + panic(fmt.Sprintf("genesis file chain-id=%s does not equal config.toml chain-id=%s", genesisFile.ChainID, clientCtx.ChainID)) + } + } restartCoolDownDuration := time.Second * time.Duration(serverCtx.Config.SelfRemediation.RestartCooldownSeconds) // Set the first restart time to be now - restartCoolDownDuration so that the first restart can trigger whenever @@ -281,8 +273,6 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().String(FlagArchivalArweaveNodeURL, "", "Arweave Node URL that stores archived data") cmd.Flags().Bool(FlagIAVLFastNode, true, "Enable fast node for IAVL tree") - cmd.Flags().Bool(FlagGenesisImportStream, false, "Enable streaming genesis file import, useful for large genesis files") - cmd.Flags().String(FlagChainID, "", "Chain ID") // add support for all Tendermint-specific command line options @@ -399,8 +389,8 @@ func startInProcess( } else { ctx.Logger.Info("starting node with ABCI Tendermint in-process") var gen *tmtypes.GenesisDoc - if ctx.Viper.Get(FlagGenesisImportStream).(bool) { - lines := genesistypes.IngestGenesisFileLineByLine(ctx.Viper.GetString(FlagGenesisImportFile)) + if config.Genesis.StreamImport { + lines := genesistypes.IngestGenesisFileLineByLine(config.Genesis.ImportFile) for line := range lines { genDoc, err := tmtypes.GenesisDocFromJSON([]byte(line)) if err != nil { diff --git a/types/module/module.go b/types/module/module.go index 6fe3b584d..a9480237b 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -393,7 +393,6 @@ func parseModule(jsonStr string) (*ModuleState, error) { // JEREMYFLAG: Manager InitGenesis - Will call InitGenesis to all modules func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData map[string]json.RawMessage, genesisImportConfig genesistypes.GenesisImportConfig) abci.ResponseInitChain { var validatorUpdates []abci.ValidatorUpdate - // if we're streaming it, then I want to if genesisImportConfig.StreamGenesisImport { lines := genesistypes.IngestGenesisFileLineByLine(genesisImportConfig.GenesisStreamFile) errCh := make(chan error, 1) From 6ff8124d3aed99b5f31d4f53109ccaf949c5cfaa Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Sat, 20 Jul 2024 07:59:55 -0400 Subject: [PATCH 18/28] cleanup --- baseapp/abci.go | 1 - server/rollback.go | 1 - types/module/module.go | 18 +----------------- x/bank/types/metadata.go | 5 ----- x/crisis/module.go | 1 - x/distribution/keeper/store.go | 2 -- x/genutil/client/cli/validate_genesis.go | 2 -- 7 files changed, 1 insertion(+), 29 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index d32298b75..c112db5a7 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -31,7 +31,6 @@ import ( // InitChain implements the ABCI interface. It runs the initialization logic // directly on the CommitMultiStore. -// JEREMYFLAG: Tendermint calls here func (app *BaseApp) InitChain(ctx context.Context, req *abci.RequestInitChain) (res *abci.ResponseInitChain, err error) { // On a new chain, we consider the init chain block height as 0, even though // req.InitialHeight is 1 by default. diff --git a/server/rollback.go b/server/rollback.go index 55bbb7545..7d95e96dc 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -9,7 +9,6 @@ import ( tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" ) - var removeBlock = false // NewRollbackCmd creates a command to rollback tendermint and multistore state by one height. diff --git a/types/module/module.go b/types/module/module.go index a9480237b..fa0332456 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -112,20 +112,15 @@ func (bm BasicManager) ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEn return nil } +// ValidateGenesisStream performs genesis state validation on all modules in a streaming fashion. func (bm BasicManager) ValidateGenesisStream(cdc codec.JSONCodec, txEncCfg client.TxEncodingConfig, moduleName string, genesisCh <-chan json.RawMessage, doneCh <-chan struct{}, errCh chan<- error) { - fmt.Println("In BasicManager.ValidateGenesisStream for module: ", moduleName) - // we have a stream of genesis data for a module - // will be told when we're done - // can signal for any errors moduleGenesisCh := make(chan json.RawMessage) moduleDoneCh := make(chan struct{}) var err error go func() { - fmt.Println("In BasicManager.ValidateGenesisStream kicked off go routine for module: ", moduleName) err = bm[moduleName].ValidateGenesisStream(cdc, txEncCfg, moduleGenesisCh) - fmt.Println("In BasicManager.ValidateGenesisStream goroutine got err: ", err) if err != nil { errCh <- err } @@ -135,11 +130,9 @@ func (bm BasicManager) ValidateGenesisStream(cdc codec.JSONCodec, txEncCfg clien for { select { case <-doneCh: - fmt.Println("In BasicManager.ValidateGenesisStream received from doneCh") close(moduleGenesisCh) return case genesisChunk := <-genesisCh: - fmt.Println("In BasicManager.ValidateGenesisStream received from genesisCh") moduleGenesisCh <- genesisChunk } } @@ -188,9 +181,7 @@ type AppModuleGenesis interface { AppModuleBasic InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate - // InitGenesisStream(sdk.Context, codec.JSONCodec, <-chan json.RawMessage) error ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage - // TODO: change to ExportGenesisStream StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage } @@ -390,7 +381,6 @@ func parseModule(jsonStr string) (*ModuleState, error) { } // InitGenesis performs init genesis functionality for modules -// JEREMYFLAG: Manager InitGenesis - Will call InitGenesis to all modules func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData map[string]json.RawMessage, genesisImportConfig genesistypes.GenesisImportConfig) abci.ResponseInitChain { var validatorUpdates []abci.ValidatorUpdate if genesisImportConfig.StreamGenesisImport { @@ -428,7 +418,6 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData panic(err) } } else { - fmt.Println("order init genesis = ", m.OrderInitGenesis) for _, moduleName := range m.OrderInitGenesis { if genesisData[moduleName] == nil { continue @@ -452,10 +441,6 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData } } -// TODO: make an initGenesisFromFile, instead of looping over modules, loop over each row/document -// - the name of the module will be in each row -// - make sure to stream each line, iostream kind of thing - // ExportGenesis performs export genesis functionality for modules func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string]json.RawMessage { genesisData := make(map[string]json.RawMessage) @@ -471,7 +456,6 @@ func (m *Manager) ProcessGenesisPerModule(ctx sdk.Context, cdc codec.JSONCodec, // doesn't matter much but the order of importing does due to invariant checks and how we are streaming the genesis // file here for _, moduleName := range m.OrderInitGenesis { - fmt.Println("Processing module: ", moduleName) ch := m.Modules[moduleName].StreamGenesis(ctx, cdc) for msg := range ch { process(moduleName, msg) diff --git a/x/bank/types/metadata.go b/x/bank/types/metadata.go index 26ed56a65..a6df1bf42 100644 --- a/x/bank/types/metadata.go +++ b/x/bank/types/metadata.go @@ -39,18 +39,13 @@ func (m Metadata) Validate() error { seenUnits := make(map[string]bool) - fmt.Printf("m = %+v\n", m) - fmt.Println("m.DenomUnits = ", m.DenomUnits) - for i, denomUnit := range m.DenomUnits { // The first denomination unit MUST be the base if i == 0 { // validate denomination and exponent if denomUnit.Denom != m.Base { - fmt.Println("denomUnit.Denom = ", denomUnit.Denom) return fmt.Errorf("metadata's first denomination unit must be the one with base denom '%s'", m.Base) } - fmt.Println("denomUnit.Exponent = ", denomUnit.Exponent) if denomUnit.Exponent != 0 { return fmt.Errorf("the exponent for base denomination unit %s must be 0", m.Base) } diff --git a/x/crisis/module.go b/x/crisis/module.go index fdc042d09..1a238e213 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -147,7 +147,6 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the crisis module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - fmt.Println("data = ", string(data)) start := time.Now() var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) diff --git a/x/distribution/keeper/store.go b/x/distribution/keeper/store.go index dc19baec1..48b6ea9a0 100644 --- a/x/distribution/keeper/store.go +++ b/x/distribution/keeper/store.go @@ -1,7 +1,6 @@ package keeper import ( - "fmt" gogotypes "github.com/gogo/protobuf/types" @@ -49,7 +48,6 @@ func (k Keeper) IterateDelegatorWithdrawAddrs(ctx sdk.Context, handler func(del func (k Keeper) GetFeePool(ctx sdk.Context) (feePool types.FeePool) { store := ctx.KVStore(k.storeKey) b := store.Get(types.FeePoolKey) - fmt.Println("fee pool key = ", b, ", is b == nil?", b == nil) if b == nil { panic("Stored fee pool should not have been nil") } diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 6a79a00ad..dbcc1e762 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -130,7 +130,6 @@ func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { } seenModules[prevModule] = true if moduleName != "genesisDoc" { - fmt.Println("In ValidateGenesisStreamCmd, kicking off mbm.ValidateGenesisStream for module ", moduleName) go mbm.ValidateGenesisStream(cdc, clientCtx.TxConfig, moduleName, genesisCh, doneCh, errCh) genesisCh <- moduleState.AppState.Data } else { @@ -140,7 +139,6 @@ func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { } } } else { // same module - fmt.Println("Sending data to channel for module ", moduleName) genesisCh <- moduleState.AppState.Data } prevModule = moduleName From 85677297345c9b4246cf81d206d37a536165efce Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Sat, 20 Jul 2024 08:07:22 -0400 Subject: [PATCH 19/28] add err to ProcessGenesisPerModule --- types/module/module.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index fa0332456..e33c86ecf 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -451,16 +451,20 @@ func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string return genesisData } -func (m *Manager) ProcessGenesisPerModule(ctx sdk.Context, cdc codec.JSONCodec, process func(string, json.RawMessage)) { +func (m *Manager) ProcessGenesisPerModule(ctx sdk.Context, cdc codec.JSONCodec, process func(string, json.RawMessage) error) error { // It's important that we use OrderInitGenesis here instead of OrderExportGenesis because the order of exporting // doesn't matter much but the order of importing does due to invariant checks and how we are streaming the genesis // file here for _, moduleName := range m.OrderInitGenesis { ch := m.Modules[moduleName].StreamGenesis(ctx, cdc) for msg := range ch { - process(moduleName, msg) + err := process(moduleName, msg) + if err != nil { + return err + } } } + return nil } // assertNoForgottenModules checks that we didn't forget any modules in the From dbb74366bf8494360d7a014e2a12c3fdd717359b Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Sun, 21 Jul 2024 08:23:55 -0400 Subject: [PATCH 20/28] change name of StreamGenesis to ExportGenesisStream --- tests/mocks/types_module_module.go | 4 ++-- types/module/module.go | 4 ++-- x/accesscontrol/module.go | 2 +- x/auth/module.go | 2 +- x/auth/vesting/module.go | 3 ++- x/authz/module/module.go | 2 +- x/bank/module.go | 2 +- x/capability/module.go | 2 +- x/crisis/module.go | 2 +- x/distribution/module.go | 2 +- x/evidence/module.go | 2 +- x/feegrant/module/module.go | 2 +- x/genutil/module.go | 2 +- x/gov/module.go | 2 +- x/mint/module.go | 2 +- x/params/module.go | 2 +- x/slashing/module.go | 2 +- x/staking/module.go | 2 +- x/upgrade/module.go | 2 +- 19 files changed, 22 insertions(+), 21 deletions(-) diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index 1fa8ef672..da52a9258 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -207,9 +207,9 @@ func (m *MockAppModuleGenesis) ExportGenesis(arg0 types0.Context, arg1 codec.JSO return ret0 } -func (m *MockAppModuleGenesis) StreamGenesis(arg0 types0.Context, arg1 codec.JSONCodec) <-chan json.RawMessage { +func (m *MockAppModuleGenesis) ExportGenesisStream(arg0 types0.Context, arg1 codec.JSONCodec) <-chan json.RawMessage { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StreamGenesis", arg0, arg1) + ret := m.ctrl.Call(m, "ExportGenesisStream", arg0, arg1) ret0, _ := ret[0].(<-chan json.RawMessage) return ret0 } diff --git a/types/module/module.go b/types/module/module.go index e33c86ecf..f7e305453 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -182,7 +182,7 @@ type AppModuleGenesis interface { InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage - StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage + ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage } // AppModule is the standard form for an application module @@ -456,7 +456,7 @@ func (m *Manager) ProcessGenesisPerModule(ctx sdk.Context, cdc codec.JSONCodec, // doesn't matter much but the order of importing does due to invariant checks and how we are streaming the genesis // file here for _, moduleName := range m.OrderInitGenesis { - ch := m.Modules[moduleName].StreamGenesis(ctx, cdc) + ch := m.Modules[moduleName].ExportGenesisStream(ctx, cdc) for msg := range ch { err := process(moduleName, msg) if err != nil { diff --git a/x/accesscontrol/module.go b/x/accesscontrol/module.go index 6cc180388..6ee494b42 100644 --- a/x/accesscontrol/module.go +++ b/x/accesscontrol/module.go @@ -161,7 +161,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(genState) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/auth/module.go b/x/auth/module.go index 32d23faee..35289a2e0 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -166,7 +166,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index a26f389c0..b50fb1c6e 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -63,6 +63,7 @@ func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config clien } return nil } + // RegisterRESTRoutes registers module's REST handlers. Currently, this is a no-op. func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} @@ -129,7 +130,7 @@ func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMe return am.DefaultGenesis(cdc) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 05a6a635a..da2b54b9b 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -160,7 +160,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/bank/module.go b/x/bank/module.go index aad8aeeae..4a9aabe50 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -170,7 +170,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/capability/module.go b/x/capability/module.go index 2457737e7..c64d55d65 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -148,7 +148,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(genState) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/crisis/module.go b/x/crisis/module.go index 1a238e213..42c39ca31 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -166,7 +166,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/distribution/module.go b/x/distribution/module.go index a62e2e9ca..2fcc4601b 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -171,7 +171,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/evidence/module.go b/x/evidence/module.go index 7dc683180..76abae56d 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -185,7 +185,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper)) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 15bca9ee3..fd7556142 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -181,7 +181,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/genutil/module.go b/x/genutil/module.go index b9cd37f87..2430c7b1d 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -120,7 +120,7 @@ func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMe return am.DefaultGenesis(cdc) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/gov/module.go b/x/gov/module.go index 733576c15..be10664ef 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -193,7 +193,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/mint/module.go b/x/mint/module.go index 037302895..849368026 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -154,7 +154,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/params/module.go b/x/params/module.go index b5d2e211c..a0332470e 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -120,7 +120,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/slashing/module.go b/x/slashing/module.go index d24292e6b..5600ae563 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -171,7 +171,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/staking/module.go b/x/staking/module.go index 30b7704ab..c5b81823d 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -170,7 +170,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(gs) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 293344521..3a8b79652 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -130,7 +130,7 @@ func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMe return am.DefaultGenesis(cdc) } -func (am AppModule) StreamGenesis(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { +func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-chan json.RawMessage { ch := make(chan json.RawMessage) go func() { ch <- am.ExportGenesis(ctx, cdc) From a3e49412f6555eff0d836316668ec3f2ef8396fd Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Sun, 21 Jul 2024 08:34:47 -0400 Subject: [PATCH 21/28] change name of AppExporterToFile to AppExporterStream --- server/export.go | 6 +++--- server/types/app.go | 4 ++-- server/util.go | 2 +- simapp/simd/cmd/root.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/export.go b/server/export.go index 56701146a..7445143c0 100644 --- a/server/export.go +++ b/server/export.go @@ -131,7 +131,7 @@ type GenesisDocNoAppState struct { // ExportToFileCmd dumps app state to JSON. It appends the app state module by module to the file. // This is especially useful when the output is too large to fit in memory. // TODO: change name to ExportStream, also can make it a flag under export -func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome string) *cobra.Command { +func ExportToFileCmd(appExporterStream types.AppExporterStream, defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ Use: "export-to-file [jsonfile]", Short: "Export state to JSON file", @@ -157,7 +157,7 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome return err } - if appExporterToFile == nil { + if appExporterStream == nil { if _, err := fmt.Fprintln(os.Stderr, "WARNING: App exporter not defined. Returning genesis file."); err != nil { return err } @@ -181,7 +181,7 @@ func ExportToFileCmd(appExporterToFile types.AppExporterToFile, defaultNodeHome forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight) jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs) - exported, err := appExporterToFile(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, file) + exported, err := appExporterStream(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, file) if err != nil { return fmt.Errorf("error exporting state: %v", err) } diff --git a/server/types/app.go b/server/types/app.go index 21cff8f12..d6ace4399 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -87,8 +87,8 @@ type ( // JSON-serializable structure and returns the current validator set. AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string, AppOptions) (ExportedApp, error) - // AppExporterToFile is a function that dumps all app state to + // AppExporterStream is a function that dumps all app state to // JSON-serializable structure and writes the result to a file. // This is useful when the output is too large to fit in memory. - AppExporterToFile func(log.Logger, dbm.DB, io.Writer, int64, bool, []string, AppOptions, *os.File) (ExportedApp, error) + AppExporterStream func(log.Logger, dbm.DB, io.Writer, int64, bool, []string, AppOptions, *os.File) (ExportedApp, error) ) diff --git a/server/util.go b/server/util.go index 539cd8e66..7ee740f20 100644 --- a/server/util.go +++ b/server/util.go @@ -304,7 +304,7 @@ func AddCommands( defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, - appExportToFile types.AppExporterToFile, + appExportToFile types.AppExporterStream, addStartFlags types.ModuleInitFlags, tracerProviderOptions []trace.TracerProviderOption, ) { diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index c4a8e9e0c..994d23914 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -170,7 +170,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { panic(err) } - server.AddCommands(rootCmd, simapp.DefaultNodeHome, a.newApp, a.appExport, a.appExporterToFile, addModuleInitFlags, []trace.TracerProviderOption{ + server.AddCommands(rootCmd, simapp.DefaultNodeHome, a.newApp, a.appExport, a.appExporterStream, addModuleInitFlags, []trace.TracerProviderOption{ trace.WithBatcher(exp), // Record information about this application in a Resource. trace.WithResource(resource.NewWithAttributes( @@ -334,7 +334,7 @@ func (a appCreator) appExport( return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) } -func (a appCreator) appExporterToFile( +func (a appCreator) appExporterStream( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOpts servertypes.AppOptions, file *os.File) (servertypes.ExportedApp, error) { return a.appExport(logger, db, traceStore, height, forZeroHeight, jailAllowedAddrs, appOpts) From 8da6f31abc4a97a65bf0a1572fc75194128f5f29 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Sun, 21 Jul 2024 14:38:17 -0400 Subject: [PATCH 22/28] make validate-gensis streaming a flag --- x/genutil/client/cli/validate_genesis.go | 142 ++++++++++++----------- x/genutil/module.go | 1 - 2 files changed, 74 insertions(+), 69 deletions(-) diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index dbcc1e762..d28669577 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -13,11 +13,14 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" ) -const chainUpgradeGuide = "https://docs.cosmos.network/master/migrations/chain-upgrade-guide-040.html" +const ( + chainUpgradeGuide = "https://docs.cosmos.network/master/migrations/chain-upgrade-guide-040.html" + flagStreaming = "streaming" +) // ValidateGenesisCmd takes a genesis file, and makes sure that it is valid. func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "validate-genesis [file]", Args: cobra.RangeArgs(0, 1), Short: "validates the genesis file at the default location or at the location passed as an arg", @@ -27,6 +30,15 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { cdc := clientCtx.Codec + isStream, err := cmd.Flags().GetBool(flagStreaming) + if err != nil { + panic(err) + } + + if isStream { + return validateGenesisStream(mbm, cmd, args) + } + // Load default if passed no args, otherwise load passed file var genesis string if len(args) == 0 { @@ -53,6 +65,8 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { return nil }, } + cmd.Flags().Bool(flagStreaming, false, "turn on streaming mode with this flag") + return cmd } type AppState struct { @@ -76,79 +90,71 @@ func parseModule(jsonStr string) (*ModuleState, error) { return &module, nil } -// TODO: change to flag under validate-genesis instead of own command -// ValidateGenesisCmd takes a genesis file, and makes sure that it is valid. -func ValidateGenesisStreamCmd(mbm module.BasicManager) *cobra.Command { - return &cobra.Command{ - Use: "validate-genesis-stream [file]", - Args: cobra.RangeArgs(0, 1), - Short: "validates the genesis file at the default location or at the location passed as an arg", - RunE: func(cmd *cobra.Command, args []string) (err error) { - serverCtx := server.GetServerContextFromCmd(cmd) - clientCtx := client.GetClientContextFromCmd(cmd) +func validateGenesisStream(mbm module.BasicManager, cmd *cobra.Command, args []string) error { + serverCtx := server.GetServerContextFromCmd(cmd) + clientCtx := client.GetClientContextFromCmd(cmd) - cdc := clientCtx.Codec + cdc := clientCtx.Codec - // Load default if passed no args, otherwise load passed file - var genesis string - if len(args) == 0 { - genesis = serverCtx.Config.GenesisFile() + // Load default if passed no args, otherwise load passed file + var genesis string + if len(args) == 0 { + genesis = serverCtx.Config.GenesisFile() + } else { + genesis = args[0] + } + + lines := genesistypes.IngestGenesisFileLineByLine(genesis) + + genesisCh := make(chan json.RawMessage) + doneCh := make(chan struct{}) + errCh := make(chan error, 1) + seenModules := make(map[string]bool) + prevModule := "" + var moduleName string + var genDoc *tmtypes.GenesisDoc + go func() { + for line := range lines { + moduleState, err := parseModule(line) + // determine module name or genesisDoc + if err != nil { + genDoc, err = tmtypes.GenesisDocFromJSON([]byte(line)) + if err != nil { + errCh <- fmt.Errorf("error unmarshalling genesis doc %s: %s", genesis, err.Error()) + return + } + moduleName = "genesisDoc" } else { - genesis = args[0] + moduleName = moduleState.AppState.Module } - - lines := genesistypes.IngestGenesisFileLineByLine(genesis) - - genesisCh := make(chan json.RawMessage) - doneCh := make(chan struct{}) - errCh := make(chan error, 1) - seenModules := make(map[string]bool) - prevModule := "" - var moduleName string - var genDoc *tmtypes.GenesisDoc - go func() { - for line := range lines { - moduleState, err := parseModule(line) - // determine module name or genesisDoc + if seenModules[moduleName] { + errCh <- fmt.Errorf("module %s seen twice in genesis file", moduleName) + return + } + if prevModule != moduleName { // new module + if prevModule != "" && prevModule != "genesisDoc" { + doneCh <- struct{}{} + } + seenModules[prevModule] = true + if moduleName != "genesisDoc" { + go mbm.ValidateGenesisStream(cdc, clientCtx.TxConfig, moduleName, genesisCh, doneCh, errCh) + genesisCh <- moduleState.AppState.Data + } else { + err = genDoc.ValidateAndComplete() if err != nil { - genDoc, err = tmtypes.GenesisDocFromJSON([]byte(line)) - if err != nil { - errCh <- fmt.Errorf("error unmarshalling genesis doc %s: %s", genesis, err.Error()) - return - } - moduleName = "genesisDoc" - } else { - moduleName = moduleState.AppState.Module - } - if seenModules[moduleName] { - errCh <- fmt.Errorf("module %s seen twice in genesis file", moduleName) - return - } - if prevModule != moduleName { // new module - if prevModule != "" && prevModule != "genesisDoc" { - doneCh <- struct{}{} - } - seenModules[prevModule] = true - if moduleName != "genesisDoc" { - go mbm.ValidateGenesisStream(cdc, clientCtx.TxConfig, moduleName, genesisCh, doneCh, errCh) - genesisCh <- moduleState.AppState.Data - } else { - err = genDoc.ValidateAndComplete() - if err != nil { - errCh <- fmt.Errorf("error validating genesis doc %s: %s", genesis, err.Error()) - } - } - } else { // same module - genesisCh <- moduleState.AppState.Data + errCh <- fmt.Errorf("error validating genesis doc %s: %s", genesis, err.Error()) } - prevModule = moduleName } - errCh <- nil - }() - err = <-errCh - return err - }, - } + } else { // same module + genesisCh <- moduleState.AppState.Data + } + prevModule = moduleName + } + fmt.Printf("File at %s is a valid genesis file\n", genesis) + errCh <- nil + }() + err := <-errCh + return err } // validateGenDoc reads a genesis file and validates that it is a correct diff --git a/x/genutil/module.go b/x/genutil/module.go index 2430c7b1d..3cacfb6a2 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -45,7 +45,6 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { // ValidateGenesis performs genesis state validation for the genutil module. func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, txEncodingConfig client.TxEncodingConfig, bz json.RawMessage) error { - fmt.Println("In genutil ValidateGenesis") var data types.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) From e93401917d8862255d4bcb7a4ef669c0e889273c Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Sun, 21 Jul 2024 21:44:49 -0400 Subject: [PATCH 23/28] change export-to-file to a flag in export cmd --- server/export.go | 194 ++++++++++++++++------------------------ server/types/app.go | 8 +- server/util.go | 2 - simapp/simd/cmd/root.go | 10 +-- 4 files changed, 81 insertions(+), 133 deletions(-) diff --git a/server/export.go b/server/export.go index 7445143c0..9dcb6e5de 100644 --- a/server/export.go +++ b/server/export.go @@ -19,11 +19,22 @@ import ( ) const ( + FlagIsStreaming = "streaming" + FlagStreamingFile = "streaming-file" FlagHeight = "height" FlagForZeroHeight = "for-zero-height" FlagJailAllowedAddrs = "jail-allowed-addrs" ) +type GenesisDocNoAppState struct { + GenesisTime time.Time `json:"genesis_time"` + ChainID string `json:"chain_id"` + InitialHeight int64 `json:"initial_height,string"` + ConsensusParams *tmtypes.ConsensusParams `json:"consensus_params,omitempty"` + Validators []tmtypes.GenesisValidator `json:"validators,omitempty"` + AppHash tmbytes.HexBytes `json:"app_hash"` +} + // ExportCmd dumps app state to JSON. func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ @@ -40,6 +51,20 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return err } + isStreaming, err := cmd.Flags().GetBool(FlagIsStreaming) + if err != nil { + return err + } + + streamingFile, err := cmd.Flags().GetString(FlagStreamingFile) + if err != nil { + return err + } + + if isStreaming && streamingFile == "" { + return fmt.Errorf("file to export stream to not provided") + } + db, err := openDB(config.RootDir) if err != nil { return err @@ -69,7 +94,56 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight) jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs) - exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper) + if isStreaming { + file, err := os.Create(streamingFile) + if err != nil { + return err + } + exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, file) + if err != nil { + return fmt.Errorf("error exporting state: %v", err) + } + + doc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) + if err != nil { + return err + } + + genesisDocNoAppHash := GenesisDocNoAppState{ + GenesisTime: doc.GenesisTime, + ChainID: doc.ChainID, + AppHash: doc.AppHash, + InitialHeight: exported.Height, + ConsensusParams: &tmtypes.ConsensusParams{ + Block: tmtypes.BlockParams{ + MaxBytes: exported.ConsensusParams.Block.MaxBytes, + MaxGas: exported.ConsensusParams.Block.MaxGas, + }, + Evidence: tmtypes.EvidenceParams{ + MaxAgeNumBlocks: exported.ConsensusParams.Evidence.MaxAgeNumBlocks, + MaxAgeDuration: exported.ConsensusParams.Evidence.MaxAgeDuration, + MaxBytes: exported.ConsensusParams.Evidence.MaxBytes, + }, + Validator: tmtypes.ValidatorParams{ + PubKeyTypes: exported.ConsensusParams.Validator.PubKeyTypes, + }, + }, + Validators: exported.Validators, + } + + // 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 := json.Marshal(genesisDocNoAppHash) + if err != nil { + return err + } + + file.Write([]byte(fmt.Sprintf("%s", string(sdk.MustSortJSON(encoded))))) + return nil + } + + exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, nil) if err != nil { return fmt.Errorf("error exporting state: %v", err) } @@ -110,122 +184,8 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com }, } - cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") - cmd.Flags().Int64(FlagHeight, -1, "Export state from a particular height (-1 means latest height)") - cmd.Flags().Bool(FlagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)") - cmd.Flags().StringSlice(FlagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail") - cmd.Flags().String(FlagChainID, "", "Chain ID") - - return cmd -} - -type GenesisDocNoAppState struct { - GenesisTime time.Time `json:"genesis_time"` - ChainID string `json:"chain_id"` - InitialHeight int64 `json:"initial_height,string"` - ConsensusParams *tmtypes.ConsensusParams `json:"consensus_params,omitempty"` - Validators []tmtypes.GenesisValidator `json:"validators,omitempty"` - AppHash tmbytes.HexBytes `json:"app_hash"` -} - -// ExportToFileCmd dumps app state to JSON. It appends the app state module by module to the file. -// This is especially useful when the output is too large to fit in memory. -// TODO: change name to ExportStream, also can make it a flag under export -func ExportToFileCmd(appExporterStream types.AppExporterStream, defaultNodeHome string) *cobra.Command { - cmd := &cobra.Command{ - Use: "export-to-file [jsonfile]", - Short: "Export state to JSON file", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := GetServerContextFromCmd(cmd) - config := serverCtx.Config - filePath := args[0] - file, err := os.Create(filePath) - if err != nil { - return err - } - - 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 - } - - if appExporterStream == nil { - if _, err := fmt.Fprintln(os.Stderr, "WARNING: App exporter not defined. Returning genesis file."); err != nil { - return err - } - - genesis, err := ioutil.ReadFile(config.GenesisFile()) - if err != nil { - return err - } - - file.Write(genesis) - return nil - } - - traceWriterFile, _ := cmd.Flags().GetString(flagTraceStore) - traceWriter, err := openTraceWriter(traceWriterFile) - if err != nil { - return err - } - - height, _ := cmd.Flags().GetInt64(FlagHeight) - forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight) - jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs) - - exported, err := appExporterStream(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, file) - if err != nil { - return fmt.Errorf("error exporting state: %v", err) - } - - doc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) - if err != nil { - return err - } - - genesisDocNoAppHash := GenesisDocNoAppState{ - GenesisTime: doc.GenesisTime, - ChainID: doc.ChainID, - AppHash: doc.AppHash, - InitialHeight: exported.Height, - ConsensusParams: &tmtypes.ConsensusParams{ - Block: tmtypes.BlockParams{ - MaxBytes: exported.ConsensusParams.Block.MaxBytes, - MaxGas: exported.ConsensusParams.Block.MaxGas, - }, - Evidence: tmtypes.EvidenceParams{ - MaxAgeNumBlocks: exported.ConsensusParams.Evidence.MaxAgeNumBlocks, - MaxAgeDuration: exported.ConsensusParams.Evidence.MaxAgeDuration, - MaxBytes: exported.ConsensusParams.Evidence.MaxBytes, - }, - Validator: tmtypes.ValidatorParams{ - PubKeyTypes: exported.ConsensusParams.Validator.PubKeyTypes, - }, - }, - Validators: exported.Validators, - } - - // 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 := json.Marshal(genesisDocNoAppHash) - if err != nil { - return err - } - - file.Write([]byte(fmt.Sprintf("%s", string(sdk.MustSortJSON(encoded))))) - return nil - }, - } - + cmd.Flags().Bool(FlagIsStreaming, false, "Whether to stream the export in chunks. Useful when genesis is extremely large and cannot fit into memory.") + cmd.Flags().String(FlagStreamingFile, "genesis-stream.json", "The file to export the streamed genesis to") cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") cmd.Flags().Int64(FlagHeight, -1, "Export state from a particular height (-1 means latest height)") cmd.Flags().Bool(FlagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)") diff --git a/server/types/app.go b/server/types/app.go index d6ace4399..82ac40cb1 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -85,10 +85,6 @@ 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, AppOptions) (ExportedApp, error) - - // AppExporterStream is a function that dumps all app state to - // JSON-serializable structure and writes the result to a file. - // This is useful when the output is too large to fit in memory. - AppExporterStream func(log.Logger, dbm.DB, io.Writer, int64, bool, []string, AppOptions, *os.File) (ExportedApp, error) + // If a file is specified, + AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string, AppOptions, *os.File) (ExportedApp, error) ) diff --git a/server/util.go b/server/util.go index 7ee740f20..5158f0e32 100644 --- a/server/util.go +++ b/server/util.go @@ -304,7 +304,6 @@ func AddCommands( defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, - appExportToFile types.AppExporterStream, addStartFlags types.ModuleInitFlags, tracerProviderOptions []trace.TracerProviderOption, ) { @@ -349,7 +348,6 @@ func AddCommands( startCmd, tendermintCmd, ExportCmd(appExport, defaultNodeHome), - ExportToFileCmd(appExportToFile, defaultNodeHome), version.NewVersionCommand(), NewRollbackCmd(appCreator, defaultNodeHome), LatestVersionCmd(defaultNodeHome), diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 994d23914..40e9e7933 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -170,7 +170,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { panic(err) } - server.AddCommands(rootCmd, simapp.DefaultNodeHome, a.newApp, a.appExport, a.appExporterStream, addModuleInitFlags, []trace.TracerProviderOption{ + server.AddCommands(rootCmd, simapp.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags, []trace.TracerProviderOption{ trace.WithBatcher(exp), // Record information about this application in a Resource. trace.WithResource(resource.NewWithAttributes( @@ -313,7 +313,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, t // and exports state. func (a appCreator) appExport( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, - appOpts servertypes.AppOptions) (servertypes.ExportedApp, error) { + appOpts servertypes.AppOptions, file *os.File) (servertypes.ExportedApp, error) { var simApp *simapp.SimApp homePath, ok := appOpts.Get(flags.FlagHome).(string) @@ -333,9 +333,3 @@ func (a appCreator) appExport( return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) } - -func (a appCreator) appExporterStream( - logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, - appOpts servertypes.AppOptions, file *os.File) (servertypes.ExportedApp, error) { - return a.appExport(logger, db, traceStore, height, forZeroHeight, jailAllowedAddrs, appOpts) -} From e1800c46013aab729daf04e9cc10b40fc0151507 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Mon, 22 Jul 2024 09:15:32 -0400 Subject: [PATCH 24/28] regenerate mocks --- server/export_test.go | 2 +- tests/mocks/types_module_module.go | 982 +++++++++++++++++++++++++++-- 2 files changed, 938 insertions(+), 46 deletions(-) diff --git a/server/export_test.go b/server/export_test.go index c59ca9b2b..e4d4964b5 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -147,7 +147,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t app.Commit(context.Background()) cmd := server.ExportCmd( - func(_ log.Logger, _ dbm.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOptons types.AppOptions) (types.ExportedApp, error) { + func(_ log.Logger, _ dbm.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOptons types.AppOptions, file *os.File) (types.ExportedApp, error) { encCfg := simapp.MakeTestEncodingConfig() var simApp *simapp.SimApp diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index da52a9258..1771bbfdf 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -8,7 +8,6 @@ import ( json "encoding/json" reflect "reflect" - abci "github.com/tendermint/tendermint/abci/types" client "github.com/cosmos/cosmos-sdk/client" codec "github.com/cosmos/cosmos-sdk/codec" types "github.com/cosmos/cosmos-sdk/codec/types" @@ -162,6 +161,20 @@ func (mr *MockAppModuleBasicMockRecorder) ValidateGenesis(arg0, arg1, arg2 inter return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModuleBasic)(nil).ValidateGenesis), arg0, arg1, arg2) } +// ValidateGenesisStream mocks base method. +func (m *MockAppModuleBasic) ValidateGenesisStream(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 <-chan json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesisStream", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesisStream indicates an expected call of ValidateGenesisStream. +func (mr *MockAppModuleBasicMockRecorder) ValidateGenesisStream(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesisStream", reflect.TypeOf((*MockAppModuleBasic)(nil).ValidateGenesisStream), arg0, arg1, arg2) +} + // MockAppModuleGenesis is a mock of AppModuleGenesis interface. type MockAppModuleGenesis struct { ctrl *gomock.Controller @@ -207,17 +220,24 @@ func (m *MockAppModuleGenesis) ExportGenesis(arg0 types0.Context, arg1 codec.JSO return ret0 } -func (m *MockAppModuleGenesis) ExportGenesisStream(arg0 types0.Context, arg1 codec.JSONCodec) <-chan json.RawMessage { +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockAppModuleGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).ExportGenesis), arg0, arg1) +} + +// ExportGenesisStream mocks base method. +func (m *MockAppModuleGenesis) ExportGenesisStream(ctx types0.Context, cdc codec.JSONCodec) <-chan json.RawMessage { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExportGenesisStream", arg0, arg1) + ret := m.ctrl.Call(m, "ExportGenesisStream", ctx, cdc) ret0, _ := ret[0].(<-chan json.RawMessage) return ret0 } -// ExportGenesis indicates an expected call of ExportGenesis. -func (mr *MockAppModuleGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { +// ExportGenesisStream indicates an expected call of ExportGenesisStream. +func (mr *MockAppModuleGenesisMockRecorder) ExportGenesisStream(ctx, cdc interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).ExportGenesis), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesisStream", reflect.TypeOf((*MockAppModuleGenesis)(nil).ExportGenesisStream), ctx, cdc) } // GetQueryCmd mocks base method. @@ -338,6 +358,20 @@ func (mr *MockAppModuleGenesisMockRecorder) ValidateGenesis(arg0, arg1, arg2 int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).ValidateGenesis), arg0, arg1, arg2) } +// ValidateGenesisStream mocks base method. +func (m *MockAppModuleGenesis) ValidateGenesisStream(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 <-chan json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesisStream", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesisStream indicates an expected call of ValidateGenesisStream. +func (mr *MockAppModuleGenesisMockRecorder) ValidateGenesisStream(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesisStream", reflect.TypeOf((*MockAppModuleGenesis)(nil).ValidateGenesisStream), arg0, arg1, arg2) +} + // MockAppModule is a mock of AppModule interface. type MockAppModule struct { ctrl *gomock.Controller @@ -361,18 +395,6 @@ func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder { return m.recorder } -// BeginBlock mocks base method. -func (m *MockAppModule) BeginBlock(arg0 types0.Context, arg1 abci.RequestBeginBlock) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "BeginBlock", arg0, arg1) -} - -// BeginBlock indicates an expected call of BeginBlock. -func (mr *MockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockAppModule)(nil).BeginBlock), arg0, arg1) -} - // ConsensusVersion mocks base method. func (m *MockAppModule) ConsensusVersion() uint64 { m.ctrl.T.Helper() @@ -401,33 +423,6 @@ func (mr *MockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModule)(nil).DefaultGenesis), arg0) } -// EndBlock mocks base method. -func (m *MockAppModule) MidBlock(arg0 types0.Context, arg1 int64) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "MidBlock", arg0, arg1) -} - -// EndBlock indicates an expected call of EndBlock. -func (mr *MockAppModuleMockRecorder) MidBlock(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MidBlock", reflect.TypeOf((*MockAppModule)(nil).MidBlock), arg0, arg1) -} - - -// EndBlock mocks base method. -func (m *MockAppModule) EndBlock(arg0 types0.Context, arg1 abci.RequestEndBlock) []abci.ValidatorUpdate { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EndBlock", arg0, arg1) - ret0, _ := ret[0].([]abci.ValidatorUpdate) - return ret0 -} - -// EndBlock indicates an expected call of EndBlock. -func (mr *MockAppModuleMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockAppModule)(nil).EndBlock), arg0, arg1) -} - // ExportGenesis mocks base method. func (m *MockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() @@ -442,6 +437,20 @@ func (mr *MockAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModule)(nil).ExportGenesis), arg0, arg1) } +// ExportGenesisStream mocks base method. +func (m *MockAppModule) ExportGenesisStream(ctx types0.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesisStream", ctx, cdc) + ret0, _ := ret[0].(<-chan json.RawMessage) + return ret0 +} + +// ExportGenesisStream indicates an expected call of ExportGenesisStream. +func (mr *MockAppModuleMockRecorder) ExportGenesisStream(ctx, cdc interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesisStream", reflect.TypeOf((*MockAppModule)(nil).ExportGenesisStream), ctx, cdc) +} + // GetQueryCmd mocks base method. func (m *MockAppModule) GetQueryCmd() *cobra.Command { m.ctrl.T.Helper() @@ -625,3 +634,886 @@ func (mr *MockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{ mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) } + +// ValidateGenesisStream mocks base method. +func (m *MockAppModule) ValidateGenesisStream(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 <-chan json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesisStream", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesisStream indicates an expected call of ValidateGenesisStream. +func (mr *MockAppModuleMockRecorder) ValidateGenesisStream(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesisStream", reflect.TypeOf((*MockAppModule)(nil).ValidateGenesisStream), arg0, arg1, arg2) +} + +// MockBeginBlockAppModule is a mock of BeginBlockAppModule interface. +type MockBeginBlockAppModule struct { + ctrl *gomock.Controller + recorder *MockBeginBlockAppModuleMockRecorder +} + +// MockBeginBlockAppModuleMockRecorder is the mock recorder for MockBeginBlockAppModule. +type MockBeginBlockAppModuleMockRecorder struct { + mock *MockBeginBlockAppModule +} + +// NewMockBeginBlockAppModule creates a new mock instance. +func NewMockBeginBlockAppModule(ctrl *gomock.Controller) *MockBeginBlockAppModule { + mock := &MockBeginBlockAppModule{ctrl: ctrl} + mock.recorder = &MockBeginBlockAppModuleMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBeginBlockAppModule) EXPECT() *MockBeginBlockAppModuleMockRecorder { + return m.recorder +} + +// BeginBlock mocks base method. +func (m *MockBeginBlockAppModule) BeginBlock(arg0 types0.Context, arg1 types1.RequestBeginBlock) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "BeginBlock", arg0, arg1) +} + +// BeginBlock indicates an expected call of BeginBlock. +func (mr *MockBeginBlockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockBeginBlockAppModule)(nil).BeginBlock), arg0, arg1) +} + +// ConsensusVersion mocks base method. +func (m *MockBeginBlockAppModule) ConsensusVersion() uint64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConsensusVersion") + ret0, _ := ret[0].(uint64) + return ret0 +} + +// ConsensusVersion indicates an expected call of ConsensusVersion. +func (mr *MockBeginBlockAppModuleMockRecorder) ConsensusVersion() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ConsensusVersion)) +} + +// DefaultGenesis mocks base method. +func (m *MockBeginBlockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis", arg0) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockBeginBlockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).DefaultGenesis), arg0) +} + +// ExportGenesis mocks base method. +func (m *MockBeginBlockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockBeginBlockAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ExportGenesis), arg0, arg1) +} + +// ExportGenesisStream mocks base method. +func (m *MockBeginBlockAppModule) ExportGenesisStream(ctx types0.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesisStream", ctx, cdc) + ret0, _ := ret[0].(<-chan json.RawMessage) + return ret0 +} + +// ExportGenesisStream indicates an expected call of ExportGenesisStream. +func (mr *MockBeginBlockAppModuleMockRecorder) ExportGenesisStream(ctx, cdc interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesisStream", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ExportGenesisStream), ctx, cdc) +} + +// GetQueryCmd mocks base method. +func (m *MockBeginBlockAppModule) GetQueryCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetQueryCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetQueryCmd indicates an expected call of GetQueryCmd. +func (mr *MockBeginBlockAppModuleMockRecorder) GetQueryCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockBeginBlockAppModule)(nil).GetQueryCmd)) +} + +// GetTxCmd mocks base method. +func (m *MockBeginBlockAppModule) GetTxCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTxCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetTxCmd indicates an expected call of GetTxCmd. +func (mr *MockBeginBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockBeginBlockAppModule)(nil).GetTxCmd)) +} + +// InitGenesis mocks base method. +func (m *MockBeginBlockAppModule) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockBeginBlockAppModuleMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).InitGenesis), arg0, arg1, arg2) +} + +// LegacyQuerierHandler mocks base method. +func (m *MockBeginBlockAppModule) LegacyQuerierHandler(arg0 *codec.LegacyAmino) types0.Querier { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyQuerierHandler", arg0) + ret0, _ := ret[0].(types0.Querier) + return ret0 +} + +// LegacyQuerierHandler indicates an expected call of LegacyQuerierHandler. +func (mr *MockBeginBlockAppModuleMockRecorder) LegacyQuerierHandler(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyQuerierHandler", reflect.TypeOf((*MockBeginBlockAppModule)(nil).LegacyQuerierHandler), arg0) +} + +// Name mocks base method. +func (m *MockBeginBlockAppModule) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockBeginBlockAppModuleMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockBeginBlockAppModule)(nil).Name)) +} + +// QuerierRoute mocks base method. +func (m *MockBeginBlockAppModule) QuerierRoute() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QuerierRoute") + ret0, _ := ret[0].(string) + return ret0 +} + +// QuerierRoute indicates an expected call of QuerierRoute. +func (mr *MockBeginBlockAppModuleMockRecorder) QuerierRoute() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QuerierRoute", reflect.TypeOf((*MockBeginBlockAppModule)(nil).QuerierRoute)) +} + +// RegisterGRPCGatewayRoutes mocks base method. +func (m *MockBeginBlockAppModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1) +} + +// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) +} + +// RegisterInterfaces mocks base method. +func (m *MockBeginBlockAppModule) RegisterInterfaces(arg0 types.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterInterfaces), arg0) +} + +// RegisterInvariants mocks base method. +func (m *MockBeginBlockAppModule) RegisterInvariants(arg0 types0.InvariantRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInvariants", arg0) +} + +// RegisterInvariants indicates an expected call of RegisterInvariants. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterInvariants), arg0) +} + +// RegisterLegacyAminoCodec mocks base method. +func (m *MockBeginBlockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) +} + +// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0) +} + +// RegisterRESTRoutes mocks base method. +func (m *MockBeginBlockAppModule) RegisterRESTRoutes(arg0 client.Context, arg1 *mux.Router) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterRESTRoutes", arg0, arg1) +} + +// RegisterRESTRoutes indicates an expected call of RegisterRESTRoutes. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterRESTRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRESTRoutes", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterRESTRoutes), arg0, arg1) +} + +// RegisterServices mocks base method. +func (m *MockBeginBlockAppModule) RegisterServices(arg0 module.Configurator) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterServices", arg0) +} + +// RegisterServices indicates an expected call of RegisterServices. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterServices), arg0) +} + +// Route mocks base method. +func (m *MockBeginBlockAppModule) Route() types0.Route { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Route") + ret0, _ := ret[0].(types0.Route) + return ret0 +} + +// Route indicates an expected call of Route. +func (mr *MockBeginBlockAppModuleMockRecorder) Route() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Route", reflect.TypeOf((*MockBeginBlockAppModule)(nil).Route)) +} + +// ValidateGenesis mocks base method. +func (m *MockBeginBlockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockBeginBlockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) +} + +// ValidateGenesisStream mocks base method. +func (m *MockBeginBlockAppModule) ValidateGenesisStream(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 <-chan json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesisStream", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesisStream indicates an expected call of ValidateGenesisStream. +func (mr *MockBeginBlockAppModuleMockRecorder) ValidateGenesisStream(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesisStream", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ValidateGenesisStream), arg0, arg1, arg2) +} + +// MockMidBlockAppModule is a mock of MidBlockAppModule interface. +type MockMidBlockAppModule struct { + ctrl *gomock.Controller + recorder *MockMidBlockAppModuleMockRecorder +} + +// MockMidBlockAppModuleMockRecorder is the mock recorder for MockMidBlockAppModule. +type MockMidBlockAppModuleMockRecorder struct { + mock *MockMidBlockAppModule +} + +// NewMockMidBlockAppModule creates a new mock instance. +func NewMockMidBlockAppModule(ctrl *gomock.Controller) *MockMidBlockAppModule { + mock := &MockMidBlockAppModule{ctrl: ctrl} + mock.recorder = &MockMidBlockAppModuleMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockMidBlockAppModule) EXPECT() *MockMidBlockAppModuleMockRecorder { + return m.recorder +} + +// ConsensusVersion mocks base method. +func (m *MockMidBlockAppModule) ConsensusVersion() uint64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConsensusVersion") + ret0, _ := ret[0].(uint64) + return ret0 +} + +// ConsensusVersion indicates an expected call of ConsensusVersion. +func (mr *MockMidBlockAppModuleMockRecorder) ConsensusVersion() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockMidBlockAppModule)(nil).ConsensusVersion)) +} + +// DefaultGenesis mocks base method. +func (m *MockMidBlockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis", arg0) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockMidBlockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockMidBlockAppModule)(nil).DefaultGenesis), arg0) +} + +// ExportGenesis mocks base method. +func (m *MockMidBlockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockMidBlockAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockMidBlockAppModule)(nil).ExportGenesis), arg0, arg1) +} + +// ExportGenesisStream mocks base method. +func (m *MockMidBlockAppModule) ExportGenesisStream(ctx types0.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesisStream", ctx, cdc) + ret0, _ := ret[0].(<-chan json.RawMessage) + return ret0 +} + +// ExportGenesisStream indicates an expected call of ExportGenesisStream. +func (mr *MockMidBlockAppModuleMockRecorder) ExportGenesisStream(ctx, cdc interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesisStream", reflect.TypeOf((*MockMidBlockAppModule)(nil).ExportGenesisStream), ctx, cdc) +} + +// GetQueryCmd mocks base method. +func (m *MockMidBlockAppModule) GetQueryCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetQueryCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetQueryCmd indicates an expected call of GetQueryCmd. +func (mr *MockMidBlockAppModuleMockRecorder) GetQueryCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockMidBlockAppModule)(nil).GetQueryCmd)) +} + +// GetTxCmd mocks base method. +func (m *MockMidBlockAppModule) GetTxCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTxCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetTxCmd indicates an expected call of GetTxCmd. +func (mr *MockMidBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockMidBlockAppModule)(nil).GetTxCmd)) +} + +// InitGenesis mocks base method. +func (m *MockMidBlockAppModule) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockMidBlockAppModuleMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockMidBlockAppModule)(nil).InitGenesis), arg0, arg1, arg2) +} + +// LegacyQuerierHandler mocks base method. +func (m *MockMidBlockAppModule) LegacyQuerierHandler(arg0 *codec.LegacyAmino) types0.Querier { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyQuerierHandler", arg0) + ret0, _ := ret[0].(types0.Querier) + return ret0 +} + +// LegacyQuerierHandler indicates an expected call of LegacyQuerierHandler. +func (mr *MockMidBlockAppModuleMockRecorder) LegacyQuerierHandler(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyQuerierHandler", reflect.TypeOf((*MockMidBlockAppModule)(nil).LegacyQuerierHandler), arg0) +} + +// MidBlock mocks base method. +func (m *MockMidBlockAppModule) MidBlock(arg0 types0.Context, arg1 int64) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "MidBlock", arg0, arg1) +} + +// MidBlock indicates an expected call of MidBlock. +func (mr *MockMidBlockAppModuleMockRecorder) MidBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MidBlock", reflect.TypeOf((*MockMidBlockAppModule)(nil).MidBlock), arg0, arg1) +} + +// Name mocks base method. +func (m *MockMidBlockAppModule) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockMidBlockAppModuleMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockMidBlockAppModule)(nil).Name)) +} + +// QuerierRoute mocks base method. +func (m *MockMidBlockAppModule) QuerierRoute() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QuerierRoute") + ret0, _ := ret[0].(string) + return ret0 +} + +// QuerierRoute indicates an expected call of QuerierRoute. +func (mr *MockMidBlockAppModuleMockRecorder) QuerierRoute() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QuerierRoute", reflect.TypeOf((*MockMidBlockAppModule)(nil).QuerierRoute)) +} + +// RegisterGRPCGatewayRoutes mocks base method. +func (m *MockMidBlockAppModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1) +} + +// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes. +func (mr *MockMidBlockAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockMidBlockAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) +} + +// RegisterInterfaces mocks base method. +func (m *MockMidBlockAppModule) RegisterInterfaces(arg0 types.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces. +func (mr *MockMidBlockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockMidBlockAppModule)(nil).RegisterInterfaces), arg0) +} + +// RegisterInvariants mocks base method. +func (m *MockMidBlockAppModule) RegisterInvariants(arg0 types0.InvariantRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInvariants", arg0) +} + +// RegisterInvariants indicates an expected call of RegisterInvariants. +func (mr *MockMidBlockAppModuleMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockMidBlockAppModule)(nil).RegisterInvariants), arg0) +} + +// RegisterLegacyAminoCodec mocks base method. +func (m *MockMidBlockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) +} + +// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. +func (mr *MockMidBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockMidBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0) +} + +// RegisterRESTRoutes mocks base method. +func (m *MockMidBlockAppModule) RegisterRESTRoutes(arg0 client.Context, arg1 *mux.Router) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterRESTRoutes", arg0, arg1) +} + +// RegisterRESTRoutes indicates an expected call of RegisterRESTRoutes. +func (mr *MockMidBlockAppModuleMockRecorder) RegisterRESTRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRESTRoutes", reflect.TypeOf((*MockMidBlockAppModule)(nil).RegisterRESTRoutes), arg0, arg1) +} + +// RegisterServices mocks base method. +func (m *MockMidBlockAppModule) RegisterServices(arg0 module.Configurator) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterServices", arg0) +} + +// RegisterServices indicates an expected call of RegisterServices. +func (mr *MockMidBlockAppModuleMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockMidBlockAppModule)(nil).RegisterServices), arg0) +} + +// Route mocks base method. +func (m *MockMidBlockAppModule) Route() types0.Route { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Route") + ret0, _ := ret[0].(types0.Route) + return ret0 +} + +// Route indicates an expected call of Route. +func (mr *MockMidBlockAppModuleMockRecorder) Route() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Route", reflect.TypeOf((*MockMidBlockAppModule)(nil).Route)) +} + +// ValidateGenesis mocks base method. +func (m *MockMidBlockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockMidBlockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockMidBlockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) +} + +// ValidateGenesisStream mocks base method. +func (m *MockMidBlockAppModule) ValidateGenesisStream(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 <-chan json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesisStream", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesisStream indicates an expected call of ValidateGenesisStream. +func (mr *MockMidBlockAppModuleMockRecorder) ValidateGenesisStream(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesisStream", reflect.TypeOf((*MockMidBlockAppModule)(nil).ValidateGenesisStream), arg0, arg1, arg2) +} + +// MockEndBlockAppModule is a mock of EndBlockAppModule interface. +type MockEndBlockAppModule struct { + ctrl *gomock.Controller + recorder *MockEndBlockAppModuleMockRecorder +} + +// MockEndBlockAppModuleMockRecorder is the mock recorder for MockEndBlockAppModule. +type MockEndBlockAppModuleMockRecorder struct { + mock *MockEndBlockAppModule +} + +// NewMockEndBlockAppModule creates a new mock instance. +func NewMockEndBlockAppModule(ctrl *gomock.Controller) *MockEndBlockAppModule { + mock := &MockEndBlockAppModule{ctrl: ctrl} + mock.recorder = &MockEndBlockAppModuleMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEndBlockAppModule) EXPECT() *MockEndBlockAppModuleMockRecorder { + return m.recorder +} + +// ConsensusVersion mocks base method. +func (m *MockEndBlockAppModule) ConsensusVersion() uint64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConsensusVersion") + ret0, _ := ret[0].(uint64) + return ret0 +} + +// ConsensusVersion indicates an expected call of ConsensusVersion. +func (mr *MockEndBlockAppModuleMockRecorder) ConsensusVersion() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockEndBlockAppModule)(nil).ConsensusVersion)) +} + +// DefaultGenesis mocks base method. +func (m *MockEndBlockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis", arg0) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockEndBlockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).DefaultGenesis), arg0) +} + +// EndBlock mocks base method. +func (m *MockEndBlockAppModule) EndBlock(arg0 types0.Context, arg1 types1.RequestEndBlock) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EndBlock", arg0, arg1) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// EndBlock indicates an expected call of EndBlock. +func (mr *MockEndBlockAppModuleMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockEndBlockAppModule)(nil).EndBlock), arg0, arg1) +} + +// ExportGenesis mocks base method. +func (m *MockEndBlockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockEndBlockAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).ExportGenesis), arg0, arg1) +} + +// ExportGenesisStream mocks base method. +func (m *MockEndBlockAppModule) ExportGenesisStream(ctx types0.Context, cdc codec.JSONCodec) <-chan json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesisStream", ctx, cdc) + ret0, _ := ret[0].(<-chan json.RawMessage) + return ret0 +} + +// ExportGenesisStream indicates an expected call of ExportGenesisStream. +func (mr *MockEndBlockAppModuleMockRecorder) ExportGenesisStream(ctx, cdc interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesisStream", reflect.TypeOf((*MockEndBlockAppModule)(nil).ExportGenesisStream), ctx, cdc) +} + +// GetQueryCmd mocks base method. +func (m *MockEndBlockAppModule) GetQueryCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetQueryCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetQueryCmd indicates an expected call of GetQueryCmd. +func (mr *MockEndBlockAppModuleMockRecorder) GetQueryCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockEndBlockAppModule)(nil).GetQueryCmd)) +} + +// GetTxCmd mocks base method. +func (m *MockEndBlockAppModule) GetTxCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTxCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetTxCmd indicates an expected call of GetTxCmd. +func (mr *MockEndBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockEndBlockAppModule)(nil).GetTxCmd)) +} + +// InitGenesis mocks base method. +func (m *MockEndBlockAppModule) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockEndBlockAppModuleMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).InitGenesis), arg0, arg1, arg2) +} + +// LegacyQuerierHandler mocks base method. +func (m *MockEndBlockAppModule) LegacyQuerierHandler(arg0 *codec.LegacyAmino) types0.Querier { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyQuerierHandler", arg0) + ret0, _ := ret[0].(types0.Querier) + return ret0 +} + +// LegacyQuerierHandler indicates an expected call of LegacyQuerierHandler. +func (mr *MockEndBlockAppModuleMockRecorder) LegacyQuerierHandler(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyQuerierHandler", reflect.TypeOf((*MockEndBlockAppModule)(nil).LegacyQuerierHandler), arg0) +} + +// Name mocks base method. +func (m *MockEndBlockAppModule) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockEndBlockAppModuleMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockEndBlockAppModule)(nil).Name)) +} + +// QuerierRoute mocks base method. +func (m *MockEndBlockAppModule) QuerierRoute() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QuerierRoute") + ret0, _ := ret[0].(string) + return ret0 +} + +// QuerierRoute indicates an expected call of QuerierRoute. +func (mr *MockEndBlockAppModuleMockRecorder) QuerierRoute() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QuerierRoute", reflect.TypeOf((*MockEndBlockAppModule)(nil).QuerierRoute)) +} + +// RegisterGRPCGatewayRoutes mocks base method. +func (m *MockEndBlockAppModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1) +} + +// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) +} + +// RegisterInterfaces mocks base method. +func (m *MockEndBlockAppModule) RegisterInterfaces(arg0 types.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterInterfaces), arg0) +} + +// RegisterInvariants mocks base method. +func (m *MockEndBlockAppModule) RegisterInvariants(arg0 types0.InvariantRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInvariants", arg0) +} + +// RegisterInvariants indicates an expected call of RegisterInvariants. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterInvariants), arg0) +} + +// RegisterLegacyAminoCodec mocks base method. +func (m *MockEndBlockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) +} + +// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0) +} + +// RegisterRESTRoutes mocks base method. +func (m *MockEndBlockAppModule) RegisterRESTRoutes(arg0 client.Context, arg1 *mux.Router) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterRESTRoutes", arg0, arg1) +} + +// RegisterRESTRoutes indicates an expected call of RegisterRESTRoutes. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterRESTRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRESTRoutes", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterRESTRoutes), arg0, arg1) +} + +// RegisterServices mocks base method. +func (m *MockEndBlockAppModule) RegisterServices(arg0 module.Configurator) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterServices", arg0) +} + +// RegisterServices indicates an expected call of RegisterServices. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterServices), arg0) +} + +// Route mocks base method. +func (m *MockEndBlockAppModule) Route() types0.Route { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Route") + ret0, _ := ret[0].(types0.Route) + return ret0 +} + +// Route indicates an expected call of Route. +func (mr *MockEndBlockAppModuleMockRecorder) Route() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Route", reflect.TypeOf((*MockEndBlockAppModule)(nil).Route)) +} + +// ValidateGenesis mocks base method. +func (m *MockEndBlockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockEndBlockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) +} + +// ValidateGenesisStream mocks base method. +func (m *MockEndBlockAppModule) ValidateGenesisStream(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 <-chan json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesisStream", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesisStream indicates an expected call of ValidateGenesisStream. +func (mr *MockEndBlockAppModuleMockRecorder) ValidateGenesisStream(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesisStream", reflect.TypeOf((*MockEndBlockAppModule)(nil).ValidateGenesisStream), arg0, arg1, arg2) +} From 900346b45c59f0fa42aac89ba9e90e67bd82f71b Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Mon, 22 Jul 2024 09:30:29 -0400 Subject: [PATCH 25/28] minor fix --- simapp/sim_test.go | 3 ++- types/module/module_test.go | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 7c8670fbd..0baa7950f 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp/helpers" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/genesis" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" @@ -155,7 +156,7 @@ func TestAppImportExport(t *testing.T) { 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.mm.InitGenesis(ctxB, app.AppCodec(), genesisState, genesis.GenesisImportConfig{}) newApp.StoreConsensusParams(ctxB, exported.ConsensusParams) fmt.Printf("comparing stores...\n") diff --git a/types/module/module_test.go b/types/module/module_test.go index fab8c7049..41ff61186 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -3,9 +3,10 @@ package module_test import ( "encoding/json" "errors" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "testing" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/golang/mock/gomock" @@ -18,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/tests/mocks" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/genesis" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -210,7 +212,7 @@ func TestManager_InitGenesis(t *testing.T) { genesisData := map[string]json.RawMessage{"module1": json.RawMessage(`{"key": "value"}`)} mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module1"])).Times(1).Return(nil) - require.Equal(t, abci.ResponseInitChain{Validators: []abci.ValidatorUpdate(nil)}, mm.InitGenesis(ctx, cdc, genesisData)) + require.Equal(t, abci.ResponseInitChain{Validators: []abci.ValidatorUpdate(nil)}, mm.InitGenesis(ctx, cdc, genesisData, genesis.GenesisImportConfig{})) // test panic genesisData = map[string]json.RawMessage{ @@ -218,7 +220,7 @@ func TestManager_InitGenesis(t *testing.T) { "module2": json.RawMessage(`{"key": "value"}`)} mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module1"])).Times(1).Return([]abci.ValidatorUpdate{{}}) mockAppModule2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module2"])).Times(1).Return([]abci.ValidatorUpdate{{}}) - require.Panics(t, func() { mm.InitGenesis(ctx, cdc, genesisData) }) + require.Panics(t, func() { mm.InitGenesis(ctx, cdc, genesisData, genesis.GenesisImportConfig{}) }) } func TestManager_ExportGenesis(t *testing.T) { From db06037d7c060410625c37c7f4a1c9821d6fd41a Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Mon, 22 Jul 2024 09:37:04 -0400 Subject: [PATCH 26/28] add begin block, mid block, end block to mock --- tests/mocks/types_module_module.go | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index 1771bbfdf..32d136c4d 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -8,6 +8,7 @@ import ( json "encoding/json" reflect "reflect" + abci "github.com/tendermint/tendermint/abci/types" client "github.com/cosmos/cosmos-sdk/client" codec "github.com/cosmos/cosmos-sdk/codec" types "github.com/cosmos/cosmos-sdk/codec/types" @@ -395,6 +396,18 @@ func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder { return m.recorder } +// BeginBlock mocks base method. +func (m *MockAppModule) BeginBlock(arg0 types0.Context, arg1 abci.RequestBeginBlock) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "BeginBlock", arg0, arg1) +} + +// BeginBlock indicates an expected call of BeginBlock. +func (mr *MockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockAppModule)(nil).BeginBlock), arg0, arg1) +} + // ConsensusVersion mocks base method. func (m *MockAppModule) ConsensusVersion() uint64 { m.ctrl.T.Helper() @@ -423,6 +436,33 @@ func (mr *MockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModule)(nil).DefaultGenesis), arg0) } +// EndBlock mocks base method. +func (m *MockAppModule) MidBlock(arg0 types0.Context, arg1 int64) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "MidBlock", arg0, arg1) +} + +// EndBlock indicates an expected call of EndBlock. +func (mr *MockAppModuleMockRecorder) MidBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MidBlock", reflect.TypeOf((*MockAppModule)(nil).MidBlock), arg0, arg1) +} + + +// EndBlock mocks base method. +func (m *MockAppModule) EndBlock(arg0 types0.Context, arg1 abci.RequestEndBlock) []abci.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EndBlock", arg0, arg1) + ret0, _ := ret[0].([]abci.ValidatorUpdate) + return ret0 +} + +// EndBlock indicates an expected call of EndBlock. +func (mr *MockAppModuleMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockAppModule)(nil).EndBlock), arg0, arg1) +} + // ExportGenesis mocks base method. func (m *MockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() From 5b0783a2bf939b6f634a26b5de32700c36d0ea2a Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Mon, 29 Jul 2024 13:15:25 -0400 Subject: [PATCH 27/28] small fixes --- server/config/config.go | 12 ++++++------ server/config/toml.go | 4 ++-- server/export.go | 2 +- server/start.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index e7a663ca5..893ba6fdc 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -197,8 +197,8 @@ type GenesisConfig struct { // StreamImport defines if the genesis.json is in stream form or not. StreamImport bool `mapstructure:"stream-import"` - // ImportFile sets the genesis json file from which to stream from - ImportFile string `mapstructure:"import-file"` + // GenesisStreamFile sets the genesis json file from which to stream from + GenesisStreamFile string `mapstructure:"genesis-stream-file"` } // Config defines the server's top level configuration @@ -299,8 +299,8 @@ func DefaultConfig() *Config { StateCommit: config.DefaultStateCommitConfig(), StateStore: config.DefaultStateStoreConfig(), Genesis: GenesisConfig{ - StreamImport: false, - ImportFile: "", + StreamImport: false, + GenesisStreamFile: "", }, } } @@ -406,8 +406,8 @@ func GetConfig(v *viper.Viper) (Config, error) { ImportNumWorkers: v.GetInt("state-store.import-num-workers"), }, Genesis: GenesisConfig{ - StreamImport: v.GetBool("genesis.stream-import"), - ImportFile: v.GetString("genesis.import-file"), + StreamImport: v.GetBool("genesis.stream-import"), + GenesisStreamFile: v.GetString("genesis.genesis-stream-file"), }, }, nil } diff --git a/server/config/toml.go b/server/config/toml.go index 3e9cd9104..25cc84c9e 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -258,8 +258,8 @@ snapshot-directory = "{{ .StateSync.SnapshotDirectory }}" # file must be in stream form and exported in a streaming fashion. stream-import = {{ .Genesis.StreamImport }} -# import-file specifies the path of the genesis json file to stream from. -import-file = "{{ .Genesis.ImportFile }}" +# genesis-stream-file specifies the path of the genesis json file to stream from. +genesis-stream-file = "{{ .Genesis.ImportFile }}" ` + config.DefaultConfigTemplate var configTemplate *template.Template diff --git a/server/export.go b/server/export.go index 9dcb6e5de..cf25eea42 100644 --- a/server/export.go +++ b/server/export.go @@ -62,7 +62,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com } if isStreaming && streamingFile == "" { - return fmt.Errorf("file to export stream to not provided") + return fmt.Errorf("file to export stream to not provided, please specify --streaming-file") } db, err := openDB(config.RootDir) diff --git a/server/start.go b/server/start.go index ff0c1eca2..907c25c47 100644 --- a/server/start.go +++ b/server/start.go @@ -390,11 +390,11 @@ func startInProcess( ctx.Logger.Info("starting node with ABCI Tendermint in-process") var gen *tmtypes.GenesisDoc if config.Genesis.StreamImport { - lines := genesistypes.IngestGenesisFileLineByLine(config.Genesis.ImportFile) + lines := genesistypes.IngestGenesisFileLineByLine(config.Genesis.GenesisStreamFile) for line := range lines { genDoc, err := tmtypes.GenesisDocFromJSON([]byte(line)) if err != nil { - continue + return err } if gen != nil { return fmt.Errorf("error: multiple genesis docs found in stream") From 9e74e30bd11a38d8dd9476663f8e3a3ac32f37ce Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Mon, 29 Jul 2024 15:14:20 -0400 Subject: [PATCH 28/28] fix --- server/config/toml.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/config/toml.go b/server/config/toml.go index 25cc84c9e..ec6d683a9 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -259,7 +259,7 @@ snapshot-directory = "{{ .StateSync.SnapshotDirectory }}" stream-import = {{ .Genesis.StreamImport }} # genesis-stream-file specifies the path of the genesis json file to stream from. -genesis-stream-file = "{{ .Genesis.ImportFile }}" +genesis-stream-file = "{{ .Genesis.GenesisStreamFile }}" ` + config.DefaultConfigTemplate var configTemplate *template.Template