Skip to content

Commit

Permalink
add backfill flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbhat1 committed Feb 3, 2025
1 parent 6f9d2ce commit 909276d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion tools/hash_verification/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ func GeneratePebbleHashCmd() *cobra.Command {
}
cmd.PersistentFlags().String("home-dir", "/root/.sei", "Sei home directory")
cmd.PersistentFlags().Int64("blocks-interval", 1_000_000, "Generate a hash every N blocks")
cmd.PersistentFlags().Bool("backfill", false, "Whether to write block range hashes back to the database")
return cmd
}

func generatePebbleHash(cmd *cobra.Command, _ []string) {
homeDir, _ := cmd.Flags().GetString("home-dir")
blocksInterval, _ := cmd.Flags().GetInt64("blocks-interval")
backfill, _ := cmd.Flags().GetBool("backfill")

ssConfig := config.DefaultStateStoreConfig()
ssConfig.Enable = true
Expand All @@ -60,6 +62,6 @@ func generatePebbleHash(cmd *cobra.Command, _ []string) {
panic(err)
}

scanner := pebbledb.NewHashScanner(stateStore, blocksInterval)
scanner := pebbledb.NewHashScanner(stateStore, blocksInterval, backfill)
scanner.ScanAllModules()
}
12 changes: 8 additions & 4 deletions tools/hash_verification/pebbledb/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ type HashScanner struct {
latestVersion int64
blocksInterval int64
hashResult map[string][][]byte
backfill bool
}

func NewHashScanner(db types.StateStore, blocksInterval int64) *HashScanner {
func NewHashScanner(db types.StateStore, blocksInterval int64, backfill bool) *HashScanner {
latestVersion, err := db.GetLatestVersion()
if err != nil {
panic(err)
Expand All @@ -26,6 +27,7 @@ func NewHashScanner(db types.StateStore, blocksInterval int64) *HashScanner {
latestVersion: latestVersion,
blocksInterval: blocksInterval,
hashResult: make(map[string][][]byte),
backfill: backfill,
}
}

Expand All @@ -39,9 +41,11 @@ func (s *HashScanner) ScanAllModules() {

fmt.Printf("Module %s block range %d-%d hash is: %X\n", moduleName, beginBlockRange, endBlockRange, hashResult)

// Write the block range hash to the database.
if err := s.db.WriteBlockRangeHash(moduleName, beginBlockRange, endBlockRange, hashResult); err != nil {
panic(fmt.Errorf("failed to write block range hash: %w", err))
// Write the block range hash to the database only if backfill is enabled
if s.backfill {
if err := s.db.WriteBlockRangeHash(moduleName, beginBlockRange, endBlockRange, hashResult); err != nil {
panic(fmt.Errorf("failed to write block range hash: %w", err))
}
}
}
}
Expand Down

0 comments on commit 909276d

Please sign in to comment.