From e97fda6e023dd7982923127754381eb83f662f3c Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 7 Aug 2024 17:11:26 +0200 Subject: [PATCH] add version on export --- server/v2/appmanager/appmanager.go | 4 ++-- simapp/v2/app_test.go | 5 +---- simapp/v2/export.go | 10 ++-------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/server/v2/appmanager/appmanager.go b/server/v2/appmanager/appmanager.go index 724594b42bf8..3c1718c17bed 100644 --- a/server/v2/appmanager/appmanager.go +++ b/server/v2/appmanager/appmanager.go @@ -91,7 +91,7 @@ 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) { - v, zeroState, err := a.db.StateLatest() + zeroState, err := a.db.StateAt(version) if err != nil { return nil, fmt.Errorf("unable to get latest state: %w", err) } @@ -102,7 +102,7 @@ func (a AppManager[T]) ExportGenesis(ctx context.Context, version uint64) ([]byt return errors.New("export genesis function not set") } - bz, err = a.exportGenesis(ctx, v) + bz, err = a.exportGenesis(ctx, version) if err != nil { return fmt.Errorf("failed to export genesis state: %w", err) } diff --git a/simapp/v2/app_test.go b/simapp/v2/app_test.go index 0498c513a7e6..3304b8a4b87f 100644 --- a/simapp/v2/app_test.go +++ b/simapp/v2/app_test.go @@ -8,7 +8,6 @@ import ( serverv2 "cosmossdk.io/server/v2" "crypto/sha256" "encoding/json" - "fmt" "testing" "time" @@ -107,8 +106,6 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { MoveNextBlock(t, app, ctx) - gen, err := app.ExportAppStateAndValidators(false, nil, nil) + _, err := app.ExportAppStateAndValidators(false, nil, nil) require.NoError(t, err) - - fmt.Printf("Exported genesis: %s\n", gen.AppState) } diff --git a/simapp/v2/export.go b/simapp/v2/export.go index a2b02ed1b82f..17768c0ea080 100644 --- a/simapp/v2/export.go +++ b/simapp/v2/export.go @@ -13,20 +13,14 @@ func (app *SimApp[T]) ExportAppStateAndValidators(forZeroHeight bool, jailAllowe // as if they could withdraw from the start of the next block ctx := context.Background() - // We export at last height + 1, because that's the height at which - // CometBFT will start InitChain. latestHeight, err := app.LoadLatestHeight() if err != nil { return servertypes.ExportedApp{}, err } - height := latestHeight + 1 - // if forZeroHeight { - // height = 0 - // app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) - // } + height := latestHeight - genesis, err := app.ExportGenesis(ctx, height) + genesis, err := app.ExportGenesis(ctx, latestHeight) if err != nil { return servertypes.ExportedApp{}, err }