Skip to content

Commit 02dde66

Browse files
committed
Fixup: Persist blockstore state during bootstrap
1 parent 6526c08 commit 02dde66

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

go/oasis-node/cmd/storage/checkpoint.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
cmtCfg "github.com/cometbft/cometbft/config"
1414
cmtProtoState "github.com/cometbft/cometbft/proto/tendermint/state"
15+
cmtstore "github.com/cometbft/cometbft/proto/tendermint/store"
1516
cmtProto "github.com/cometbft/cometbft/proto/tendermint/types"
1617
cmtState "github.com/cometbft/cometbft/state"
1718
"github.com/cometbft/cometbft/store"
@@ -420,11 +421,12 @@ func bootstrapTrustedState(dataDir string, meta bootstrapMeta) error {
420421
}
421422
defer stateDB.Close()
422423

423-
blockStore, err := openConsensusBlockstore(dataDir)
424+
blockStoreDB, err := openConsensusBlockstoreDB(dataDir)
424425
if err != nil {
425426
return fmt.Errorf("failed to open consensus blockstore: %w", err)
426427
}
427-
defer blockStore.Close()
428+
defer blockStoreDB.Close()
429+
blockStore := store.NewBlockStore(blockStoreDB)
428430

429431
if !blockStore.IsEmpty() {
430432
return fmt.Errorf("blockstore not empty, trying to initialize non empty state")
@@ -471,6 +473,19 @@ func bootstrapTrustedState(dataDir string, meta bootstrapMeta) error {
471473
return err
472474
}
473475

476+
// SaveSeenCommit (as used by the upstream) does not persist the BlockStoreState (height/base),
477+
// so we save it explicitly here. This ways the blockstore reports the correct height after bootstrap,
478+
// so that status works as expected. If this is not done, this blockstore base is kept as unitialized,
479+
// and is initialized as soon as the first block is fetche. However we would cut last retained height by 1,
480+
// which is the current case for consensus checkpoint sync.
481+
store.SaveBlockStoreState(
482+
&cmtstore.BlockStoreState{
483+
Base: metaState.LastBlockHeight,
484+
Height: metaState.LastBlockHeight,
485+
},
486+
blockStoreDB,
487+
)
488+
474489
// Once the stores are bootstrapped, we need to set the height at which the node has finished
475490
// statesyncing. This will allow the blocksync reactor to fetch blocks at a proper height.
476491
// In case this operation fails, it is equivalent to a failure in online state sync where the operator

go/oasis-node/cmd/storage/dbs.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,23 @@ func openConsensusNodeDB(dataDir string) (api.NodeDB, func(), error) {
4444
return ndb, close, nil
4545
}
4646

47-
func openConsensusBlockstore(dataDir string) (*store.BlockStore, error) {
47+
func openConsensusBlockstoreDB(dataDir string) (cometbftDB.DB, error) {
4848
cmtConfig := cmtCfg.DefaultConfig()
4949
cmtConfig.SetRoot(filepath.Join(dataDir, cmtCommon.StateDir))
5050

5151
dbProvider, err := cmtDB.Provider()
5252
if err != nil {
5353
return nil, fmt.Errorf("failed to obtain db provider: %w", err)
5454
}
55+
return cmtDB.OpenBlockstoreDB(dbProvider, cmtConfig)
56+
}
5557

56-
blockstoreDB, err := cmtDB.OpenBlockstoreDB(dbProvider, cmtConfig)
58+
func openConsensusBlockstore(dataDir string) (*store.BlockStore, error) {
59+
blockstoreDB, err := openConsensusBlockstoreDB(dataDir)
5760
if err != nil {
5861
return nil, fmt.Errorf("failed to open blockstore: %w", err)
5962
}
60-
blockstore := store.NewBlockStore(blockstoreDB)
61-
62-
return blockstore, nil
63+
return store.NewBlockStore(blockstoreDB), nil
6364
}
6465

6566
func openConsensusStateDB(dataDir string) (cometbftDB.DB, error) {

0 commit comments

Comments
 (0)