Skip to content

Commit 6019acb

Browse files
committed
fix the protocol db initialization
1 parent 01f62e9 commit 6019acb

File tree

1 file changed

+17
-2
lines changed
  • cmd/util/cmd/storehouse-checkpoint-validator

1 file changed

+17
-2
lines changed

cmd/util/cmd/storehouse-checkpoint-validator/cmd.go

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

1717
var (
1818
flagPebbleDir string
19+
flagDataDir string
1920
flagCheckpointDir string
2021
flagBlockHeight uint64
2122
flagWorkerCount int
@@ -35,6 +36,9 @@ func init() {
3536
"directory containing the Pebble database with register store")
3637
_ = Cmd.MarkFlagRequired("pebble-dir")
3738

39+
Cmd.Flags().StringVar(&flagDataDir, "datadir", "/var/flow/data/protocol",
40+
"directory containing the protocol database")
41+
3842
Cmd.Flags().StringVar(&flagCheckpointDir, "checkpoint-dir", "",
3943
"directory containing the checkpoint file (must have root.checkpoint)")
4044
_ = Cmd.MarkFlagRequired("checkpoint-dir")
@@ -50,6 +54,7 @@ func init() {
5054
func runE(*cobra.Command, []string) error {
5155
log.Info().
5256
Str("pebble-dir", flagPebbleDir).
57+
Str("datadir", flagDataDir).
5358
Str("checkpoint-dir", flagCheckpointDir).
5459
Uint64("block-height", flagBlockHeight).
5560
Int("worker-count", flagWorkerCount).
@@ -74,8 +79,18 @@ func runE(*cobra.Command, []string) error {
7479
return fmt.Errorf("failed to initialize register store: %w", err)
7580
}
7681

77-
// Convert pebble DB to storage.DB for protocol storage
78-
protocolDB := pebbleimpl.ToDB(pebbleDB)
82+
// Open protocol database from datadir
83+
protocolPebbleDB, err := pebblestorage.ShouldOpenDefaultPebbleDB(log.Logger, flagDataDir)
84+
if err != nil {
85+
return fmt.Errorf("failed to open protocol database at %s: %w", flagDataDir, err)
86+
}
87+
defer func() {
88+
if closeErr := protocolPebbleDB.Close(); closeErr != nil {
89+
log.Error().Err(closeErr).Msg("failed to close protocol database")
90+
}
91+
}()
92+
93+
protocolDB := pebbleimpl.ToDB(protocolPebbleDB)
7994

8095
// Initialize storage components
8196
metricsCollector := &metrics.NoopCollector{}

0 commit comments

Comments
 (0)