@@ -20,6 +20,7 @@ import (
2020 "fmt"
2121 "os"
2222 "path/filepath"
23+ "sort"
2324 "strconv"
2425 "time"
2526
@@ -60,6 +61,7 @@ Remove blockchain and state databases`,
6061 dbDeleteCmd ,
6162 dbPutCmd ,
6263 dbGetSlotsCmd ,
64+ dbDumpFreezerIndex ,
6365 },
6466 }
6567 dbInspectCmd = cli.Command {
@@ -177,6 +179,22 @@ WARNING: This is a low-level operation which may cause database corruption!`,
177179 },
178180 Description : "This command looks up the specified database key from the database." ,
179181 }
182+ dbDumpFreezerIndex = cli.Command {
183+ Action : utils .MigrateFlags (freezerInspect ),
184+ Name : "freezer-index" ,
185+ Usage : "Dump out the index of a given freezer type" ,
186+ ArgsUsage : "<type> <start (int)> <end (int)>" ,
187+ Flags : []cli.Flag {
188+ utils .DataDirFlag ,
189+ utils .SyncModeFlag ,
190+ utils .MainnetFlag ,
191+ utils .RopstenFlag ,
192+ utils .RinkebyFlag ,
193+ utils .GoerliFlag ,
194+ utils .YoloV3Flag ,
195+ },
196+ Description : "This command displays information about the freezer index." ,
197+ }
180198)
181199
182200func removeDB (ctx * cli.Context ) error {
@@ -449,3 +467,43 @@ func dbDumpTrie(ctx *cli.Context) error {
449467 }
450468 return it .Err
451469}
470+
471+ func freezerInspect (ctx * cli.Context ) error {
472+ var (
473+ start , end int64
474+ disableSnappy bool
475+ err error
476+ )
477+ if ctx .NArg () < 3 {
478+ return fmt .Errorf ("required arguments: %v" , ctx .Command .ArgsUsage )
479+ }
480+ kind := ctx .Args ().Get (0 )
481+ if noSnap , ok := rawdb .FreezerNoSnappy [kind ]; ! ok {
482+ var options []string
483+ for opt := range rawdb .FreezerNoSnappy {
484+ options = append (options , opt )
485+ }
486+ sort .Strings (options )
487+ return fmt .Errorf ("Could read freezer-type '%v'. Available options: %v" , kind , options )
488+ } else {
489+ disableSnappy = noSnap
490+ }
491+ if start , err = strconv .ParseInt (ctx .Args ().Get (1 ), 10 , 64 ); err != nil {
492+ log .Info ("Could read start-param" , "error" , err )
493+ return err
494+ }
495+ if end , err = strconv .ParseInt (ctx .Args ().Get (2 ), 10 , 64 ); err != nil {
496+ log .Info ("Could read count param" , "error" , err )
497+ return err
498+ }
499+ stack , _ := makeConfigNode (ctx )
500+ defer stack .Close ()
501+ path := filepath .Join (stack .ResolvePath ("chaindata" ), "ancient" )
502+ log .Info ("Opening freezer" , "location" , path , "name" , kind )
503+ if f , err := rawdb .NewFreezerTable (path , kind , disableSnappy ); err != nil {
504+ return err
505+ } else {
506+ f .DumpIndex (start , end )
507+ }
508+ return nil
509+ }
0 commit comments