Optimize getPrevNodeFromNode.

The recent pruning code made the parent hash for a node available directly
as a field in the node.  Make use of this in the getPrevNodeFromNode
function to avoid having to load the full block data associated with the
node to get the parent hash.
This commit is contained in:
Dave Collins 2013-08-01 12:32:58 -05:00
parent 2988289d2e
commit 5b697947a7

View file

@ -359,17 +359,9 @@ func (b *BlockChain) getPrevNodeFromNode(node *blockNode) (*blockNode, error) {
return nil, nil return nil, nil
} }
// Load the actual block for this block node from the db to ascertain
// the previous hash.
block, err := b.db.FetchBlockBySha(node.hash)
if err != nil {
return nil, err
}
// Dynamically load the previous block from the block database, create // Dynamically load the previous block from the block database, create
// a new block node for it, and update the memory chain accordingly. // a new block node for it, and update the memory chain accordingly.
prevHash := &block.MsgBlock().Header.PrevBlock prevBlockNode, err := b.loadBlockNode(node.parentHash)
prevBlockNode, err := b.loadBlockNode(prevHash)
if err != nil { if err != nil {
return nil, err return nil, err
} }