chain: move some methods.
This commit is contained in:
parent
74ec6a29fb
commit
ff5eddbebb
@ -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.
|
* Add a block to the chain without a lock.
|
||||||
* @private
|
* @private
|
||||||
@ -1480,6 +1446,53 @@ Chain.prototype.finish = function finish(block, entry) {
|
|||||||
time);
|
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.
|
* Purge any waiting orphans.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user