Skip to content

Commit

Permalink
chore: amend loading blockstore
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathansumner committed Jun 10, 2024
1 parent d357ab1 commit 8cc8e1a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ 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)
"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"
tmstore "github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/store"
tmtypes "github.com/tendermint/tendermint/types"
tmdb "github.com/tendermint/tm-db"
"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"
Expand All @@ -25,14 +26,20 @@ const (
)

// GetLatestBlockHeaderFromDB returns the latest block header from the blockstore database
func GetLatestBlockHeaderFromDB(blockStoreDB tmdb.DB) (*tmtypes.Header, error) {
func GetLatestBlockHeaderFromDB() (*tmtypes.Header, error) {
// Load the blockstore
blockStore := tmstore.NewBlockStore(blockStoreDB)
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")
}
Expand Down Expand Up @@ -95,7 +102,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
return err
}

latestBlockHeader, err := GetLatestBlockHeaderFromDB(db)
latestBlockHeader, err := GetLatestBlockHeaderFromDB()
if err != nil {
return err
}
Expand Down

0 comments on commit 8cc8e1a

Please sign in to comment.