@@ -12,27 +12,21 @@ import (
1212 "strings"
1313 "time"
1414
15- cmtconfig "github.com/cometbft/cometbft/config"
16- cmtBlockstore "github.com/cometbft/cometbft/store"
1715 badgerDB "github.com/dgraph-io/badger/v4"
1816 "github.com/spf13/cobra"
1917
2018 "github.com/oasisprotocol/oasis-core/go/common"
2119 "github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
2220 "github.com/oasisprotocol/oasis-core/go/common/logging"
2321 "github.com/oasisprotocol/oasis-core/go/config"
24- "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/abci"
25- cmtCommon "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/common"
2622 cmtConfig "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/config"
27- cmtDB "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/db"
2823 cmtDBProvider "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/db/badger"
2924 cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
3025 roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
3126 "github.com/oasisprotocol/oasis-core/go/runtime/bundle"
3227 runtimeConfig "github.com/oasisprotocol/oasis-core/go/runtime/config"
3328 "github.com/oasisprotocol/oasis-core/go/runtime/history"
3429 "github.com/oasisprotocol/oasis-core/go/runtime/registry"
35- "github.com/oasisprotocol/oasis-core/go/storage/api"
3630 db "github.com/oasisprotocol/oasis-core/go/storage/mkvs/db/api"
3731 "github.com/oasisprotocol/oasis-core/go/storage/mkvs/db/badger"
3832 "github.com/oasisprotocol/oasis-core/go/storage/mkvs/node"
@@ -195,9 +189,7 @@ func doMigrate(_ *cobra.Command, args []string) error {
195189 }
196190 err := func () error {
197191 runtimeDir := runtimeConfig .GetRuntimeStateDir (dataDir , rt )
198-
199- prunerFactory := history .NewNonePrunerFactory ()
200- history , err := history .New (rt , runtimeDir , prunerFactory , false )
192+ history , err := openRuntimeLightHistory (dataDir , rt )
201193 if err != nil {
202194 return fmt .Errorf ("error creating history provider: %w" , err )
203195 }
@@ -417,30 +409,6 @@ func compactConsensusNodeDB(dataDir string) error {
417409 return ndb .Compact ()
418410}
419411
420- func openConsensusNodeDB (dataDir string ) (api.NodeDB , func (), error ) {
421- ldb , ndb , _ , err := abci .InitStateStorage (
422- & abci.ApplicationConfig {
423- DataDir : filepath .Join (dataDir , cmtCommon .StateDir ),
424- StorageBackend : config .GlobalConfig .Storage .Backend ,
425- MemoryOnlyStorage : false ,
426- ReadOnlyStorage : false ,
427- DisableCheckpointer : true ,
428- },
429- )
430- if err != nil {
431- return nil , nil , fmt .Errorf ("failed to initialize ABCI storage backend: %w" , err )
432- }
433-
434- // Close and Cleanup both only close NodeDB. Still closing both explicitly,
435- // to prevent resource leaks if things change in the future.
436- close := func () {
437- ndb .Close ()
438- ldb .Cleanup ()
439- }
440-
441- return ndb , close , nil
442- }
443-
444412func doPrune (_ * cobra.Command , args []string ) error {
445413 if err := cmdCommon .Init (); err != nil {
446414 cmdCommon .EarlyLogAndExit (err )
@@ -554,11 +522,9 @@ func pruneConsensusNodeDB(ndb db.NodeDB, retainHeight uint64) error {
554522// In case of no configured runtimes it returns max int64.
555523func minReindexedHeight (dataDir string , runtimes []common.Namespace ) (int64 , error ) {
556524 fetchLastReindexedHeight := func (runtimeID common.Namespace ) (int64 , error ) {
557- rtDir := runtimeConfig .GetRuntimeStateDir (dataDir , runtimeID )
558-
559- history , err := history .New (runtimeID , rtDir , history .NewNonePrunerFactory (), true )
525+ history , err := openRuntimeLightHistory (dataDir , runtimeID )
560526 if err != nil {
561- return 0 , fmt .Errorf ("failed to open new light history: %w" , err )
527+ return 0 , fmt .Errorf ("failed to open runtime light history: %w" , err )
562528 }
563529 defer history .Close ()
564530
@@ -586,19 +552,10 @@ func minReindexedHeight(dataDir string, runtimes []common.Namespace) (int64, err
586552}
587553
588554func pruneCometDBs (dataDir string , retainHeight int64 ) error {
589- cmtConfig := cmtconfig .DefaultConfig ()
590- cmtConfig .SetRoot (filepath .Join (dataDir , cmtCommon .StateDir ))
591-
592- dbProvider , err := cmtDB .Provider ()
593- if err != nil {
594- return fmt .Errorf ("failed to obtain db provider: %w" , err )
595- }
596-
597- blockstoreDB , err := cmtDB .OpenBlockstoreDB (dbProvider , cmtConfig )
555+ blockstore , err := openConsensusBlockstore (dataDir )
598556 if err != nil {
599- return fmt .Errorf ("failed to open blockstore: %w" , err )
557+ return fmt .Errorf ("failed to open consensus blockstore: %w" , err )
600558 }
601- blockstore := cmtBlockstore .NewBlockStore (blockstoreDB )
602559 defer blockstore .Close ()
603560
604561 // Mimic the upstream pruning logic from CometBFT
@@ -623,11 +580,10 @@ func pruneCometDBs(dataDir string, retainHeight int64) error {
623580 }
624581 logger .Info ("blockstore pruning finished" , "pruned" , n )
625582
626- stateDB , err := cmtDB . OpenStateDB ( dbProvider , cmtConfig )
583+ state , err := openConsensusStatestore ( dataDir )
627584 if err != nil {
628- return fmt .Errorf ("failed to open state db : %w" , err )
585+ return fmt .Errorf ("failed to open consensus state store : %w" , err )
629586 }
630- state := cmtDB .OpenStateStore (stateDB )
631587 defer state .Close ()
632588
633589 logger .Info ("pruning consensus states" , "base" , base , "retain_height" , retainHeight )
0 commit comments