Skip to content

Commit

Permalink
feat: initial borfsck stub
Browse files Browse the repository at this point in the history
  • Loading branch information
praetoriansentry committed Jan 10, 2024
1 parent 822d658 commit 94917b3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
62 changes: 62 additions & 0 deletions cmd/borfsck/borfsck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package borfsck

import (
"fmt"
"github.com/spf13/cobra"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/filter"
"github.com/syndtr/goleveldb/leveldb/opt"
)

type fsckParamsType struct {
dbPath string
cacheSize *int
openFilesCacheCapacity *int
}

var fsckParams = fsckParamsType{}

var BorFsckCmd = &cobra.Command{
Use: "bor-fsck /path/to/leveldb",
Short: "bor-fsck /path/to/leveldb",
Long: "TODO",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("bor-fsck expects exactly one argument: a path to leveldb")
}

fsckParams.dbPath = args[0]
db, err := openLevelDB()
if err != nil {
return err
}
_ = db
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
return nil
},
}

func openLevelDB() (*leveldb.DB, error) {
db, err := leveldb.OpenFile(fsckParams.dbPath, &opt.Options{
Filter: filter.NewBloomFilter(10),
DisableSeeksCompaction: true,
OpenFilesCacheCapacity: *fsckParams.openFilesCacheCapacity,
BlockCacheCapacity: *fsckParams.cacheSize / 2 * opt.MiB,
// This tool should not be doing writes
ReadOnly: true,
})
if err != nil {
return nil, err
}
return db, nil

}

func init() {
flagSet := BorFsckCmd.PersistentFlags()
fsckParams.cacheSize = flagSet.Int("cache-size", 512, "the number of megabytes to use as our internal cache size")
fsckParams.openFilesCacheCapacity = flagSet.Int("handles", 500, "defines the capacity of the open files caching. Use -1 for zero, this has same effect as specifying NoCacher to OpenFilesCacher.")

}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/spf13/viper"

"github.com/maticnetwork/polygon-cli/cmd/abi"
"github.com/maticnetwork/polygon-cli/cmd/borfsck"
"github.com/maticnetwork/polygon-cli/cmd/dbbench"
"github.com/maticnetwork/polygon-cli/cmd/dumpblocks"
"github.com/maticnetwork/polygon-cli/cmd/enr"
Expand Down Expand Up @@ -106,6 +107,7 @@ func NewPolycliCommand() *cobra.Command {
// Define commands.
cmd.AddCommand(
abi.ABICmd,
borfsck.BorFsckCmd,
dumpblocks.DumpblocksCmd,
fork.ForkCmd,
fund.FundCmd,
Expand Down

0 comments on commit 94917b3

Please sign in to comment.