chain: move some methods.

This commit is contained in:
Christopher Jeffrey 2016-11-30 01:05:28 -08:00
parent 74ec6a29fb
commit ff5eddbebb
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1200,40 +1200,6 @@ Chain.prototype.add = co(function* add(block) {
}
});
Chain.prototype.storeOrphan = function storeOrphan(block) {
var hash = block.hash('hex');
var height = block.getCoinbaseHeight();
this.orphan.count++;
this.orphan.size += block.getSize();
this.orphan.map[block.prevBlock] = block;
this.orphan.bmap[hash] = block;
// Update the best height based on the coinbase.
// We do this even for orphans (peers will send
// us their highest block during the initial
// getblocks sync, making it an orphan).
if (height > this.bestHeight)
this.bestHeight = height;
this.emit('orphan', block, height);
};
Chain.prototype.resolveOrphan = function resolveOrphan(hash) {
var block = this.orphan.map[hash];
if (!block)
return;
delete this.orphan.bmap[block.hash('hex')];
delete this.orphan.map[hash];
this.orphan.count--;
this.orphan.size -= block.getSize();
return block;
};
/**
* Add a block to the chain without a lock.
* @private
@ -1480,6 +1446,53 @@ Chain.prototype.finish = function finish(block, entry) {
time);
};
/**
* Store an orphan.
* @private
* @param {Block} block
*/
Chain.prototype.storeOrphan = function storeOrphan(block) {
var hash = block.hash('hex');
var height = block.getCoinbaseHeight();
this.orphan.count++;
this.orphan.size += block.getSize();
this.orphan.map[block.prevBlock] = block;
this.orphan.bmap[hash] = block;
// Update the best height based on the coinbase.
// We do this even for orphans (peers will send
// us their highest block during the initial
// getblocks sync, making it an orphan).
if (height > this.bestHeight)
this.bestHeight = height;
this.emit('orphan', block, height);
};
/**
* Resolve an orphan.
* @private
* @param {Hash} hash - Previous block hash.
* @returns {Block}
*/
Chain.prototype.resolveOrphan = function resolveOrphan(hash) {
var block = this.orphan.map[hash];
if (!block)
return;
delete this.orphan.bmap[block.hash('hex')];
delete this.orphan.map[hash];
this.orphan.count--;
this.orphan.size -= block.getSize();
return block;
};
/**
* Purge any waiting orphans.
*/