Skip to content

Commit

Permalink
[lbry] claimtrie: enable debug level for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
roylee17 committed May 27, 2022
1 parent 88cee2d commit e3ab278
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
1 change: 0 additions & 1 deletion claimtrie/cmd/cmd/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func NewBlocCommands() *cobra.Command {

return cmd
}

func NewBlockBestCommand() *cobra.Command {

cmd := &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions claimtrie/cmd/cmd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func loadBlocksDB() (database.DB, error) {

dbPath := filepath.Join(dataDir, netName, "blocks_ffldb")
log.Infof("Loading blocks database: %s", dbPath)
log.Debugf("Loading blocks database: %s", dbPath)
db, err := database.Open("ffldb", dbPath, chainPramas().Net)
if err != nil {
return nil, errors.Wrapf(err, "open blocks database")
Expand All @@ -27,7 +27,7 @@ func loadBlocksDB() (database.DB, error) {
func loadChain(db database.DB) (*blockchain.BlockChain, error) {
paramsCopy := chaincfg.MainNetParams

log.Infof("Loading chain from database")
log.Debugf("Loading chain from database")

startTime := time.Now()
chain, err := blockchain.New(&blockchain.Config{
Expand All @@ -40,7 +40,7 @@ func loadChain(db database.DB) (*blockchain.BlockChain, error) {
return nil, errors.Wrapf(err, "create blockchain")
}

log.Infof("Loaded chain from database (%s)", time.Since(startTime))
log.Debugf("Loaded chain from database (%s)", time.Since(startTime))

return chain, err

Expand Down
23 changes: 13 additions & 10 deletions claimtrie/cmd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ package cmd
import (
"os"

"github.com/btcsuite/btclog"
"github.com/lbryio/lbcd/claimtrie/config"
"github.com/lbryio/lbcd/claimtrie/param"
"github.com/lbryio/lbcd/limits"
"github.com/lbryio/lbcd/wire"

"github.com/btcsuite/btclog"
"github.com/spf13/cobra"
)

var (
log btclog.Logger
cfg = config.DefaultConfig
netName string
dataDir string
log = btclog.NewBackend(os.Stdout).Logger("CMDL")
cfg = config.DefaultConfig
netName string
dataDir string
debugLevel string
)

var rootCmd = NewRootCommand()
Expand All @@ -28,6 +29,9 @@ func NewRootCommand() *cobra.Command {
Short: "ClaimTrie Command Line Interface",
SilenceUsage: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
level, _ := btclog.LevelFromString(debugLevel)
log.SetLevel(level)

switch netName {
case "mainnet":
param.SetNetwork(wire.MainNet)
Expand All @@ -37,21 +41,20 @@ func NewRootCommand() *cobra.Command {
param.SetNetwork(wire.TestNet)
}
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
os.Stdout.Sync()
},
}

cmd.PersistentFlags().StringVar(&netName, "netname", "mainnet", "Net name")
cmd.PersistentFlags().StringVarP(&dataDir, "datadir", "b", cfg.DataDir, "Data dir")
cmd.PersistentFlags().StringVarP(&debugLevel, "debuglevel", "d", cfg.DebugLevel, "Debug level")

return cmd
}

func Execute() {

backendLogger := btclog.NewBackend(os.Stdout)
defer os.Stdout.Sync()
log = backendLogger.Logger("CMDL")
log.SetLevel(btclog.LevelDebug)

// Up some limits.
if err := limits.SetLimits(); err != nil {
log.Errorf("failed to set limits: %v\n", err)
Expand Down
18 changes: 8 additions & 10 deletions claimtrie/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
)

var DefaultConfig = Config{
Params: param.MainNet,

RamTrie: true, // as it stands the other trie uses more RAM, more time, and 40GB+ of disk space

DataDir: filepath.Join(btcutil.AppDataDir("lbcd", false), "data"),
Params: param.MainNet,
RamTrie: true, // as it stands the other trie uses more RAM, more time, and 40GB+ of disk space
DebugLevel: "info",
DataDir: filepath.Join(btcutil.AppDataDir("lbcd", false), "data"),

BlockRepoPebble: pebbleConfig{
Path: "blocks_pebble_db",
Expand All @@ -30,11 +29,10 @@ var DefaultConfig = Config{

// Config is the container of all configurations.
type Config struct {
Params param.ClaimTrieParams

RamTrie bool

DataDir string
Params param.ClaimTrieParams
RamTrie bool
DataDir string
DebugLevel string

BlockRepoPebble pebbleConfig
NodeRepoPebble pebbleConfig
Expand Down

0 comments on commit e3ab278

Please sign in to comment.