Fix an issue causing excessive memory consumption.

This commit resolves an issue where the block node index was forcing
entire blocks to be kept in memory thereby forcing excessive memory usage.
For example, prior to this change, the memory usage could consume upwards
of 1.5GB while importing bootstrap.dat via the addblock utility.  With
this change the entire import takes <150MB.  This also has the same memory
reduction to btcd since it uses the same code path.
This commit is contained in:
Dave Collins 2014-02-09 01:34:08 -06:00
parent 190ef70ace
commit 149d8176b0

View file

@ -78,9 +78,13 @@ type blockNode struct {
// for the passed block. The work sum is updated accordingly when the node is
// inserted into a chain.
func newBlockNode(blockHeader *btcwire.BlockHeader, blockSha *btcwire.ShaHash, height int64) *blockNode {
// Make a copy of the hash so the node doesn't keep a reference to part
// of the full block/block header preventing it from being garbage
// collected.
prevHash := blockHeader.PrevBlock
node := blockNode{
hash: blockSha,
parentHash: &blockHeader.PrevBlock,
parentHash: &prevHash,
workSum: CalcWork(blockHeader.Bits),
height: height,
version: blockHeader.Version,