diff --git a/blockmanager.go b/blockmanager.go index d9d3b3b3..be083ac7 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -8,6 +8,7 @@ import ( "container/list" "github.com/conformal/btcchain" "github.com/conformal/btcdb" + "github.com/conformal/btcnet" "github.com/conformal/btcutil" "github.com/conformal/btcwire" "net" @@ -178,7 +179,7 @@ type blockManager struct { headersFirstMode bool headerList *list.List startHeader *list.Element - nextCheckpoint *btcchain.Checkpoint + nextCheckpoint *btcnet.Checkpoint } // resetHeaderState sets the headers-first mode state to values appropriate for @@ -219,9 +220,14 @@ func (b *blockManager) updateChainState(newestHash *btcwire.ShaHash, newestHeigh // It returns nil when there is not one either because the height is already // later than the final checkpoint or some other reason such as disabled // checkpoints. -func (b *blockManager) findNextHeaderCheckpoint(height int64) *btcchain.Checkpoint { - checkpoints := b.blockChain.Checkpoints() - if checkpoints == nil { +func (b *blockManager) findNextHeaderCheckpoint(height int64) *btcnet.Checkpoint { + // There is no next checkpoint if checkpoints are disabled or there are + // none for this current network. + if cfg.DisableCheckpoints { + return nil + } + checkpoints := b.server.netParams.Checkpoints + if len(checkpoints) == 0 { return nil } @@ -1321,7 +1327,7 @@ func newBlockManager(s *server) (*blockManager, error) { headerList: list.New(), quit: make(chan bool), } - bm.blockChain = btcchain.New(s.db, s.btcnet, bm.handleNotifyMsg) + bm.blockChain = btcchain.New(s.db, s.netParams, bm.handleNotifyMsg) bm.blockChain.DisableCheckpoints(cfg.DisableCheckpoints) if !cfg.DisableCheckpoints { // Initialize the next checkpoint based on the current height. diff --git a/mining.go b/mining.go index 77789c65..abeb9525 100644 --- a/mining.go +++ b/mining.go @@ -215,7 +215,7 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int64, addr btcutil }) tx.AddTxOut(&btcwire.TxOut{ Value: btcchain.CalcBlockSubsidy(nextBlockHeight, - activeNetParams.Net), + activeNetParams.Params), PkScript: pkScript, }) return btcutil.NewTx(tx), nil diff --git a/server.go b/server.go index 4dd9a027..08fcba72 100644 --- a/server.go +++ b/server.go @@ -63,6 +63,7 @@ type broadcastInventoryDel *btcwire.InvVect type server struct { nonce uint64 listeners []net.Listener + netParams *btcnet.Params btcnet btcwire.BitcoinNet started int32 // atomic shutdown int32 // atomic @@ -1129,6 +1130,7 @@ func newServer(listenAddrs []string, db btcdb.Db, netParams *btcnet.Params) (*se s := server{ nonce: nonce, listeners: listeners, + netParams: netParams, btcnet: netParams.Net, addrManager: amgr, newPeers: make(chan *peer, cfg.MaxPeers), diff --git a/util/addblock/import.go b/util/addblock/import.go index c64b14a2..2b58b49e 100644 --- a/util/addblock/import.go +++ b/util/addblock/import.go @@ -288,7 +288,7 @@ func newBlockImporter(db btcdb.Db, r io.ReadSeeker) *blockImporter { doneChan: make(chan bool), errChan: make(chan error), quit: make(chan bool), - chain: btcchain.New(db, activeNetwork.Net, nil), + chain: btcchain.New(db, activeNetwork, nil), lastLogTime: time.Now(), } } diff --git a/util/findcheckpoint/findcheckpoint.go b/util/findcheckpoint/findcheckpoint.go index 9a0e036a..1812583a 100644 --- a/util/findcheckpoint/findcheckpoint.go +++ b/util/findcheckpoint/findcheckpoint.go @@ -9,6 +9,7 @@ import ( "github.com/conformal/btcchain" "github.com/conformal/btcdb" _ "github.com/conformal/btcdb/ldb" + "github.com/conformal/btcnet" "github.com/conformal/btcwire" "os" "path/filepath" @@ -42,7 +43,7 @@ func loadBlockDB() (btcdb.Db, error) { // candidates at the last checkpoint that is already hard coded into btcchain // since there is no point in finding candidates before already existing // checkpoints. -func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcchain.Checkpoint, error) { +func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcnet.Checkpoint, error) { // Start with the latest block of the main chain. block, err := db.FetchBlockBySha(latestHash) if err != nil { @@ -51,7 +52,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.Net, nil) + chain := btcchain.New(db, activeNetwork, nil) latestCheckpoint := chain.LatestCheckpoint() if latestCheckpoint == nil { return nil, fmt.Errorf("unable to retrieve latest checkpoint") @@ -76,7 +77,7 @@ func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcchain.Check defer fmt.Println() // Loop backwards through the chain to find checkpoint candidates. - candidates := make([]*btcchain.Checkpoint, 0, cfg.NumCandidates) + candidates := make([]*btcnet.Checkpoint, 0, cfg.NumCandidates) numTested := int64(0) for len(candidates) < cfg.NumCandidates && block.Height() > requiredHeight { // Display progress. @@ -97,7 +98,7 @@ func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcchain.Check if err != nil { return nil, err } - checkpoint := btcchain.Checkpoint{ + checkpoint := btcnet.Checkpoint{ Height: block.Height(), Hash: candidateHash, } @@ -117,7 +118,7 @@ func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcchain.Check // showCandidate display a checkpoint candidate using and output format // determined by the configuration parameters. The Go syntax output // uses the format the btcchain code expects for checkpoints added to the list. -func showCandidate(candidateNum int, checkpoint *btcchain.Checkpoint) { +func showCandidate(candidateNum int, checkpoint *btcnet.Checkpoint) { if cfg.UseGoOutput { fmt.Printf("Candidate %d -- {%d, newShaHashFromStr(\"%v\")},\n", candidateNum, checkpoint.Height, checkpoint.Hash)