Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update genesis_time upon genesis export [Experimental] #174

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
// DONTCOVER

import (
"errors"
"fmt"

Check failure on line 7 in server/export.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
"os"

"github.com/spf13/cobra"
cfg "github.com/tendermint/tendermint/config"
tmjson "github.com/tendermint/tendermint/libs/json"
tmnode "github.com/tendermint/tendermint/node"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/store"
tmtypes "github.com/tendermint/tendermint/types"
"os"

Check failure on line 15 in server/export.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server/types"
Expand All @@ -22,6 +25,28 @@
FlagJailAllowedAddrs = "jail-allowed-addrs"
)

// GetLatestBlockHeaderFromDB returns the latest block header from the blockstore database
func GetLatestBlockHeaderFromDB() (*tmtypes.Header, error) {
// Load the blockstore
blockStoreDB, err := tmnode.DefaultDBProvider(&tmnode.DBContext{ID: "blockstore", Config: cfg.DefaultConfig()})
if err != nil {
return nil, err
}
defer blockStoreDB.Close()

blockStore := store.NewBlockStore(blockStoreDB)

// 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 +102,12 @@
return err
}

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

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