From a91e7de2edb8639ef5adb1642efd25af0589e8ff Mon Sep 17 00:00:00 2001 From: akhilkumarpilli Date: Tue, 10 Sep 2024 11:36:50 +0530 Subject: [PATCH] address comments --- runtime/v2/builder.go | 2 +- runtime/v2/manager.go | 3 ++- server/v2/appmanager/appmanager.go | 19 +++---------------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/runtime/v2/builder.go b/runtime/v2/builder.go index 55c75ac4b0c0..0fc2c596cdd7 100644 --- a/runtime/v2/builder.go +++ b/runtime/v2/builder.go @@ -176,7 +176,7 @@ func (a *AppBuilder[T]) Build(opts ...AppBuilderOption[T]) (*App[T], error) { ExportGenesis: func(ctx context.Context, version uint64) ([]byte, error) { state, err := a.app.db.StateAt(version) if err != nil { - return nil, fmt.Errorf("failed to export genesis: %w", err) + return nil, fmt.Errorf("unable to get latest state: %w", err) } genesisJson, err := a.app.moduleManager.ExportGenesisForModules(ctx, a.app.stf, state) diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 587498e582b1..ed031a8587c6 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -25,6 +25,7 @@ import ( "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" "cosmossdk.io/log" + "cosmossdk.io/server/v2/appmanager" "cosmossdk.io/server/v2/stf" ) @@ -195,7 +196,7 @@ func (m *MM[T]) InitGenesisJSON( // ExportGenesisForModules performs export genesis functionality for modules func (m *MM[T]) ExportGenesisForModules( ctx context.Context, - appStf *stf.STF[T], + appStf appmanager.StateTransitionFunction[T], state store.ReaderMap, modulesToExport ...string, ) (map[string]json.RawMessage, error) { diff --git a/server/v2/appmanager/appmanager.go b/server/v2/appmanager/appmanager.go index 023f76bd2067..e2b7af328b39 100644 --- a/server/v2/appmanager/appmanager.go +++ b/server/v2/appmanager/appmanager.go @@ -89,24 +89,11 @@ func (a AppManager[T]) InitGenesis( // ExportGenesis exports the genesis state of the application. func (a AppManager[T]) ExportGenesis(ctx context.Context, version uint64) ([]byte, error) { - zeroState, err := a.db.StateAt(version) - if err != nil { - return nil, fmt.Errorf("unable to get latest state: %w", err) + if a.exportGenesis == nil { + return nil, errors.New("export genesis function not set") } - bz := make([]byte, 0) - _, err = a.stf.RunWithCtx(ctx, zeroState, func(ctx context.Context) error { - if a.exportGenesis == nil { - return errors.New("export genesis function not set") - } - - bz, err = a.exportGenesis(ctx, version) - if err != nil { - return fmt.Errorf("failed to export genesis state: %w", err) - } - - return nil - }) + bz, err := a.exportGenesis(ctx, version) if err != nil { return nil, fmt.Errorf("failed to export genesis state: %w", err) }