diff --git a/util/findcheckpoint/config.go b/util/findcheckpoint/config.go index 63a5075a1..f025c5027 100644 --- a/util/findcheckpoint/config.go +++ b/util/findcheckpoint/config.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/conformal/btcdb" _ "github.com/conformal/btcdb/ldb" + "github.com/conformal/btcnet" "github.com/conformal/btcutil" "github.com/conformal/btcwire" "github.com/conformal/go-flags" @@ -26,7 +27,7 @@ var ( btcdHomeDir = btcutil.AppDataDir("btcd", false) defaultDataDir = filepath.Join(btcdHomeDir, "data") knownDbTypes = btcdb.SupportedDBs() - activeNetwork = btcwire.MainNet + activeNetwork = &btcnet.MainNetParams ) // config defines the configuration options for findcheckpoint. @@ -51,13 +52,22 @@ func validDbType(dbType string) bool { return false } -// netName returns a human-readable name for the passed bitcoin network. -func netName(btcnet btcwire.BitcoinNet) string { - net := "mainnet" - if btcnet == btcwire.TestNet3 { - net = "testnet" +// netName returns the name used when referring to a bitcoin network. At the +// time of writing, btcd currently places blocks for testnet version 3 in the +// data and log directory "testnet", which does not match the Name field of the +// btcnet parameters. This function can be used to override this directory name +// as "testnet" when the passed active network matches btcwire.TestNet3. +// +// A proper upgrade to move the data and log directories for this network to +// "testnet3" is planned for the future, at which point this function can be +// removed and the network parameter's name used instead. +func netName(netParams *btcnet.Params) string { + switch netParams.Net { + case btcwire.TestNet3: + return "testnet" + default: + return netParams.Name } - return net } // loadConfig initializes and parses the config using command line options. @@ -81,7 +91,7 @@ func loadConfig() (*config, []string, error) { // Choose the active network based on the flags. if cfg.TestNet3 { - activeNetwork = btcwire.TestNet3 + activeNetwork = &btcnet.TestNet3Params } // Validate database type. diff --git a/util/findcheckpoint/findcheckpoint.go b/util/findcheckpoint/findcheckpoint.go index a71dd676d..9a0e036a9 100644 --- a/util/findcheckpoint/findcheckpoint.go +++ b/util/findcheckpoint/findcheckpoint.go @@ -51,7 +51,7 @@ func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcchain.Check // Setup chain and get the latest checkpoint. Ignore notifications // since they aren't needed for this util. - chain := btcchain.New(db, activeNetwork, nil) + chain := btcchain.New(db, activeNetwork.Net, nil) latestCheckpoint := chain.LatestCheckpoint() if latestCheckpoint == nil { return nil, fmt.Errorf("unable to retrieve latest checkpoint") @@ -76,7 +76,7 @@ func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcchain.Check defer fmt.Println() // Loop backwards through the chain to find checkpoint candidates. - var candidates []*btcchain.Checkpoint + candidates := make([]*btcchain.Checkpoint, 0, cfg.NumCandidates) numTested := int64(0) for len(candidates) < cfg.NumCandidates && block.Height() > requiredHeight { // Display progress.