From 5b697947a711c34fcc1b51c52676b975cebb5886 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 1 Aug 2013 12:32:58 -0500 Subject: [PATCH] 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. --- chain.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/chain.go b/chain.go index b63d6d0a..bbd65f37 100644 --- a/chain.go +++ b/chain.go @@ -359,17 +359,9 @@ func (b *BlockChain) getPrevNodeFromNode(node *blockNode) (*blockNode, error) { 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 // a new block node for it, and update the memory chain accordingly. - prevHash := &block.MsgBlock().Header.PrevBlock - prevBlockNode, err := b.loadBlockNode(prevHash) + prevBlockNode, err := b.loadBlockNode(node.parentHash) if err != nil { return nil, err }