Replace HaveInventory with HaveBlock.
The original thought was that chain would also house the transaction memory pool, but that ultimately was decided against. As a result, it only makes sense to query chain for blocks rather than generic inventory.
This commit is contained in:
parent
0b334bc841
commit
b911e7e455
1 changed files with 6 additions and 31 deletions
37
chain.go
37
chain.go
|
@ -167,38 +167,13 @@ func (b *BlockChain) DisableVerify(disable bool) {
|
|||
b.noVerify = disable
|
||||
}
|
||||
|
||||
// HaveInventory returns whether or not the chain instance has the inventory
|
||||
// represented by the passed inventory vector. This includes checking all of
|
||||
// the various places inventory can be when it is in different states such as
|
||||
// part of the main chain, on a side chain, and orphans.
|
||||
// HaveBlock returns whether or not the chain instance has the block represented
|
||||
// by the passed hash. This includes checking the various places a block can
|
||||
// be like part of the main chain, on a side chain, or in the orphan pool.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) HaveInventory(inventoryVector *btcwire.InvVect) bool {
|
||||
switch inventoryVector.Type {
|
||||
case btcwire.InvVect_Block:
|
||||
// Check the main chain and side chains.
|
||||
if b.blockExists(&inventoryVector.Hash) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check orphan blocks.
|
||||
if b.IsKnownOrphan(&inventoryVector.Hash) {
|
||||
return true
|
||||
}
|
||||
|
||||
case btcwire.InvVect_Tx:
|
||||
// TODO(davec): Need to ultimately maintain a transaction pool
|
||||
// of transactions that are not already in a block and check
|
||||
// for the existing transaction there too.
|
||||
|
||||
// Check if the transaction exists from the point of view of the
|
||||
// end of the main chain.
|
||||
return b.db.ExistsTxSha(&inventoryVector.Hash)
|
||||
}
|
||||
|
||||
// The requested inventory is either not known or is an unsupported
|
||||
// type (which also implies it is not known).
|
||||
return false
|
||||
// This function is NOT safe for concurrent access.
|
||||
func (b *BlockChain) HaveBlock(hash *btcwire.ShaHash) bool {
|
||||
return b.IsKnownOrphan(hash) && b.blockExists(hash)
|
||||
}
|
||||
|
||||
// IsKnownOrphan returns whether the passed hash is currently a known orphan.
|
||||
|
|
Loading…
Reference in a new issue