Update for recent btcdb API changes.
This commit is contained in:
parent
6f5a43d6c8
commit
07bdbd9e3d
2 changed files with 33 additions and 9 deletions
|
@ -701,7 +701,13 @@ func (b *blockManager) fetchHeaderBlocks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, node.sha)
|
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.requestedBlocks[*node.sha] = struct{}{}
|
||||||
b.syncPeer.requestedBlocks[*node.sha] = struct{}{}
|
b.syncPeer.requestedBlocks[*node.sha] = struct{}{}
|
||||||
gdmsg.AddInvVect(iv)
|
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
|
// 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
|
// 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).
|
// 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 {
|
switch invVect.Type {
|
||||||
case btcwire.InvTypeBlock:
|
case btcwire.InvTypeBlock:
|
||||||
// Ask chain if the block is known to it in any form (main
|
// 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
|
// Ask the transaction memory pool if the transaction is known
|
||||||
// to it in any form (main pool or orphan).
|
// to it in any form (main pool or orphan).
|
||||||
if b.server.txMemPool.HaveTransaction(&invVect.Hash) {
|
if b.server.txMemPool.HaveTransaction(&invVect.Hash) {
|
||||||
return true
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the transaction exists from the point of view of the
|
// 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
|
// The requested inventory is is an unsupported type, so just claim
|
||||||
// it is known to avoid requesting it.
|
// it is known to avoid requesting it.
|
||||||
return true
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleInvMsg handles inv messages from all peers.
|
// 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.
|
// 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.
|
// Add it to the request queue.
|
||||||
imsg.peer.requestQueue.PushBack(iv)
|
imsg.peer.requestQueue.PushBack(iv)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -108,15 +108,26 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
|
||||||
bi.receivedLogTx += int64(len(block.MsgBlock().Transactions))
|
bi.receivedLogTx += int64(len(block.MsgBlock().Transactions))
|
||||||
|
|
||||||
// Skip blocks that already exist.
|
// 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
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't bother trying to process orphans.
|
// Don't bother trying to process orphans.
|
||||||
prevHash := &block.MsgBlock().Header.PrevBlock
|
prevHash := &block.MsgBlock().Header.PrevBlock
|
||||||
if !prevHash.IsEqual(&zeroHash) && !bi.db.ExistsSha(prevHash) {
|
if !prevHash.IsEqual(&zeroHash) {
|
||||||
return false, fmt.Errorf("import file contains block %v which "+
|
exists, err := bi.db.ExistsSha(blockSha)
|
||||||
"does not link to the available block chain", 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
|
// Ensure the blocks follows all of the chain rules and match up to the
|
||||||
|
|
Loading…
Add table
Reference in a new issue