Skip to content

Commit

Permalink
feat: update genesis_time upon export
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathansumner committed Jun 5, 2024
1 parent fa16e36 commit 3777f3b
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package server
// DONTCOVER

import (
"errors"
"fmt"
"os"
"time"

"github.com/spf13/cobra"
tmjson "github.com/tendermint/tendermint/libs/json"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmstore "github.com/tendermint/tendermint/store"
tmtypes "github.com/tendermint/tendermint/types"
tmdb "github.com/tendermint/tm-db"
"os"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server/types"
Expand All @@ -20,8 +24,25 @@ const (
FlagHeight = "height"
FlagForZeroHeight = "for-zero-height"
FlagJailAllowedAddrs = "jail-allowed-addrs"
RoundingInterval = 5 * time.Minute
)

// GetLatestBlockHeaderFromDB returns the latest block header from the blockstore database
func GetLatestBlockHeaderFromDB(blockStoreDB tmdb.DB) (*tmtypes.Header, error) {
// Load the blockstore
blockStore := tmstore.NewBlockStore(blockStoreDB)
defer blockStoreDB.Close()

// Get the latest block meta
latestHeight := blockStore.Height()
blockMeta := blockStore.LoadBlockMeta(latestHeight)
if blockMeta == nil {
return nil, errors.New("latest block metadata not found in blockstore")
}

return &blockMeta.Header, nil
}

// ExportCmd dumps app state to JSON.
func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -77,6 +98,12 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
return err
}

latestBlockHeader, err := GetLatestBlockHeaderFromDB(db)
if err != nil {
return err
}
doc.GenesisTime = latestBlockHeader.Time.Round(RoundingInterval)

doc.AppState = exported.AppState
doc.Validators = exported.Validators
doc.InitialHeight = exported.Height
Expand Down

0 comments on commit 3777f3b

Please sign in to comment.