Update for recent btcdb API changes.

This commit is contained in:
Dave Collins 2014-07-07 12:07:33 -05:00
parent 6f5a43d6c8
commit 07bdbd9e3d
2 changed files with 33 additions and 9 deletions

View file

@ -701,7 +701,13 @@ func (b *blockManager) fetchHeaderBlocks() {
}
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, node.sha)
if !b.haveInventory(iv) {
haveInv, err := b.haveInventory(iv)
if err != nil {
bmgrLog.Warn("Unexpected failure when checking for "+
"existing inventory during header block "+
"fetch: %v", err)
}
if !haveInv {
b.requestedBlocks[*node.sha] = struct{}{}
b.syncPeer.requestedBlocks[*node.sha] = struct{}{}
gdmsg.AddInvVect(iv)
@ -829,7 +835,7 @@ func (b *blockManager) handleHeadersMsg(hmsg *headersMsg) {
// inventory can be when it is in different states such as blocks that are part
// of the main chain, on a side chain, in the orphan pool, and transactions that
// are in the memory pool (either the main pool or orphan pool).
func (b *blockManager) haveInventory(invVect *btcwire.InvVect) bool {
func (b *blockManager) haveInventory(invVect *btcwire.InvVect) (bool, error) {
switch invVect.Type {
case btcwire.InvTypeBlock:
// Ask chain if the block is known to it in any form (main
@ -840,7 +846,7 @@ func (b *blockManager) haveInventory(invVect *btcwire.InvVect) bool {
// Ask the transaction memory pool if the transaction is known
// to it in any form (main pool or orphan).
if b.server.txMemPool.HaveTransaction(&invVect.Hash) {
return true
return true, nil
}
// Check if the transaction exists from the point of view of the
@ -850,7 +856,7 @@ func (b *blockManager) haveInventory(invVect *btcwire.InvVect) bool {
// The requested inventory is is an unsupported type, so just claim
// it is known to avoid requesting it.
return true
return true, nil
}
// handleInvMsg handles inv messages from all peers.
@ -894,7 +900,14 @@ func (b *blockManager) handleInvMsg(imsg *invMsg) {
}
// Request the inventory if we don't already have it.
if !b.haveInventory(iv) {
haveInv, err := b.haveInventory(iv)
if err != nil {
bmgrLog.Warn("Unexpected failure when checking for "+
"existing inventory during inv message "+
"processing: %v", err)
continue
}
if !haveInv {
// Add it to the request queue.
imsg.peer.requestQueue.PushBack(iv)
continue

View file

@ -108,15 +108,26 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
bi.receivedLogTx += int64(len(block.MsgBlock().Transactions))
// Skip blocks that already exist.
if bi.db.ExistsSha(blockSha) {
exists, err := bi.db.ExistsSha(blockSha)
if err != nil {
return false, err
}
if exists {
return false, nil
}
// Don't bother trying to process orphans.
prevHash := &block.MsgBlock().Header.PrevBlock
if !prevHash.IsEqual(&zeroHash) && !bi.db.ExistsSha(prevHash) {
return false, fmt.Errorf("import file contains block %v which "+
"does not link to the available block chain", blockSha)
if !prevHash.IsEqual(&zeroHash) {
exists, err := bi.db.ExistsSha(blockSha)
if err != nil {
return false, err
}
if !exists {
return false, fmt.Errorf("import file contains block "+
"%v which does not link to the available "+
"block chain", blockSha)
}
}
// Ensure the blocks follows all of the chain rules and match up to the