Update for recent btcchain and btcnet API changes.
This commit is contained in:
parent
009c4bcd76
commit
4328461f36
5 changed files with 21 additions and 12 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"github.com/conformal/btcchain"
|
"github.com/conformal/btcchain"
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
|
"github.com/conformal/btcnet"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"net"
|
"net"
|
||||||
|
@ -178,7 +179,7 @@ type blockManager struct {
|
||||||
headersFirstMode bool
|
headersFirstMode bool
|
||||||
headerList *list.List
|
headerList *list.List
|
||||||
startHeader *list.Element
|
startHeader *list.Element
|
||||||
nextCheckpoint *btcchain.Checkpoint
|
nextCheckpoint *btcnet.Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
// resetHeaderState sets the headers-first mode state to values appropriate for
|
// 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
|
// 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
|
// later than the final checkpoint or some other reason such as disabled
|
||||||
// checkpoints.
|
// checkpoints.
|
||||||
func (b *blockManager) findNextHeaderCheckpoint(height int64) *btcchain.Checkpoint {
|
func (b *blockManager) findNextHeaderCheckpoint(height int64) *btcnet.Checkpoint {
|
||||||
checkpoints := b.blockChain.Checkpoints()
|
// There is no next checkpoint if checkpoints are disabled or there are
|
||||||
if checkpoints == nil {
|
// none for this current network.
|
||||||
|
if cfg.DisableCheckpoints {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
checkpoints := b.server.netParams.Checkpoints
|
||||||
|
if len(checkpoints) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1321,7 +1327,7 @@ func newBlockManager(s *server) (*blockManager, error) {
|
||||||
headerList: list.New(),
|
headerList: list.New(),
|
||||||
quit: make(chan bool),
|
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)
|
bm.blockChain.DisableCheckpoints(cfg.DisableCheckpoints)
|
||||||
if !cfg.DisableCheckpoints {
|
if !cfg.DisableCheckpoints {
|
||||||
// Initialize the next checkpoint based on the current height.
|
// Initialize the next checkpoint based on the current height.
|
||||||
|
|
|
@ -215,7 +215,7 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int64, addr btcutil
|
||||||
})
|
})
|
||||||
tx.AddTxOut(&btcwire.TxOut{
|
tx.AddTxOut(&btcwire.TxOut{
|
||||||
Value: btcchain.CalcBlockSubsidy(nextBlockHeight,
|
Value: btcchain.CalcBlockSubsidy(nextBlockHeight,
|
||||||
activeNetParams.Net),
|
activeNetParams.Params),
|
||||||
PkScript: pkScript,
|
PkScript: pkScript,
|
||||||
})
|
})
|
||||||
return btcutil.NewTx(tx), nil
|
return btcutil.NewTx(tx), nil
|
||||||
|
|
|
@ -63,6 +63,7 @@ type broadcastInventoryDel *btcwire.InvVect
|
||||||
type server struct {
|
type server struct {
|
||||||
nonce uint64
|
nonce uint64
|
||||||
listeners []net.Listener
|
listeners []net.Listener
|
||||||
|
netParams *btcnet.Params
|
||||||
btcnet btcwire.BitcoinNet
|
btcnet btcwire.BitcoinNet
|
||||||
started int32 // atomic
|
started int32 // atomic
|
||||||
shutdown int32 // atomic
|
shutdown int32 // atomic
|
||||||
|
@ -1129,6 +1130,7 @@ func newServer(listenAddrs []string, db btcdb.Db, netParams *btcnet.Params) (*se
|
||||||
s := server{
|
s := server{
|
||||||
nonce: nonce,
|
nonce: nonce,
|
||||||
listeners: listeners,
|
listeners: listeners,
|
||||||
|
netParams: netParams,
|
||||||
btcnet: netParams.Net,
|
btcnet: netParams.Net,
|
||||||
addrManager: amgr,
|
addrManager: amgr,
|
||||||
newPeers: make(chan *peer, cfg.MaxPeers),
|
newPeers: make(chan *peer, cfg.MaxPeers),
|
||||||
|
|
|
@ -288,7 +288,7 @@ func newBlockImporter(db btcdb.Db, r io.ReadSeeker) *blockImporter {
|
||||||
doneChan: make(chan bool),
|
doneChan: make(chan bool),
|
||||||
errChan: make(chan error),
|
errChan: make(chan error),
|
||||||
quit: make(chan bool),
|
quit: make(chan bool),
|
||||||
chain: btcchain.New(db, activeNetwork.Net, nil),
|
chain: btcchain.New(db, activeNetwork, nil),
|
||||||
lastLogTime: time.Now(),
|
lastLogTime: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/conformal/btcchain"
|
"github.com/conformal/btcchain"
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
_ "github.com/conformal/btcdb/ldb"
|
_ "github.com/conformal/btcdb/ldb"
|
||||||
|
"github.com/conformal/btcnet"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -42,7 +43,7 @@ func loadBlockDB() (btcdb.Db, error) {
|
||||||
// candidates at the last checkpoint that is already hard coded into btcchain
|
// candidates at the last checkpoint that is already hard coded into btcchain
|
||||||
// since there is no point in finding candidates before already existing
|
// since there is no point in finding candidates before already existing
|
||||||
// checkpoints.
|
// 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.
|
// Start with the latest block of the main chain.
|
||||||
block, err := db.FetchBlockBySha(latestHash)
|
block, err := db.FetchBlockBySha(latestHash)
|
||||||
if err != nil {
|
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
|
// Setup chain and get the latest checkpoint. Ignore notifications
|
||||||
// since they aren't needed for this util.
|
// since they aren't needed for this util.
|
||||||
chain := btcchain.New(db, activeNetwork.Net, nil)
|
chain := btcchain.New(db, activeNetwork, nil)
|
||||||
latestCheckpoint := chain.LatestCheckpoint()
|
latestCheckpoint := chain.LatestCheckpoint()
|
||||||
if latestCheckpoint == nil {
|
if latestCheckpoint == nil {
|
||||||
return nil, fmt.Errorf("unable to retrieve latest checkpoint")
|
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()
|
defer fmt.Println()
|
||||||
|
|
||||||
// Loop backwards through the chain to find checkpoint candidates.
|
// 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)
|
numTested := int64(0)
|
||||||
for len(candidates) < cfg.NumCandidates && block.Height() > requiredHeight {
|
for len(candidates) < cfg.NumCandidates && block.Height() > requiredHeight {
|
||||||
// Display progress.
|
// Display progress.
|
||||||
|
@ -97,7 +98,7 @@ func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcchain.Check
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
checkpoint := btcchain.Checkpoint{
|
checkpoint := btcnet.Checkpoint{
|
||||||
Height: block.Height(),
|
Height: block.Height(),
|
||||||
Hash: candidateHash,
|
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
|
// showCandidate display a checkpoint candidate using and output format
|
||||||
// determined by the configuration parameters. The Go syntax output
|
// determined by the configuration parameters. The Go syntax output
|
||||||
// uses the format the btcchain code expects for checkpoints added to the list.
|
// 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 {
|
if cfg.UseGoOutput {
|
||||||
fmt.Printf("Candidate %d -- {%d, newShaHashFromStr(\"%v\")},\n",
|
fmt.Printf("Candidate %d -- {%d, newShaHashFromStr(\"%v\")},\n",
|
||||||
candidateNum, checkpoint.Height, checkpoint.Hash)
|
candidateNum, checkpoint.Height, checkpoint.Hash)
|
||||||
|
|
Loading…
Reference in a new issue