minor refactoring.
This commit is contained in:
parent
d4aa15f9a3
commit
f7ac99d24d
@ -45,7 +45,10 @@ function Chain(options) {
|
|||||||
this.locked = false;
|
this.locked = false;
|
||||||
this.pending = [];
|
this.pending = [];
|
||||||
this.pendingBlocks = {};
|
this.pendingBlocks = {};
|
||||||
|
this.pendingSize = 0;
|
||||||
|
this.total = 0;
|
||||||
this.orphanLimit = options.orphanLimit || 20 * 1024 * 1024;
|
this.orphanLimit = options.orphanLimit || 20 * 1024 * 1024;
|
||||||
|
this.pendingLimit = options.pendingLimit || 20 * 1024 * 1024;
|
||||||
this.invalid = {};
|
this.invalid = {};
|
||||||
|
|
||||||
this.orphan = {
|
this.orphan = {
|
||||||
@ -106,6 +109,10 @@ Chain.prototype._init = function _init() {
|
|||||||
utils.debug('Handled orphan %s (%s)', utils.revHex(data.hash), host);
|
utils.debug('Handled orphan %s (%s)', utils.revHex(data.hash), host);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.on('purge', function(count, size) {
|
||||||
|
utils.debug('Warning: %dmb of orphans cleared!', utils.mb(size));
|
||||||
|
});
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
utils.debug('Chain is loading.');
|
utils.debug('Chain is loading.');
|
||||||
@ -813,6 +820,11 @@ Chain.prototype.add = function add(initial, peer, callback) {
|
|||||||
if (this.locked) {
|
if (this.locked) {
|
||||||
this.pending.push([initial, peer, callback]);
|
this.pending.push([initial, peer, callback]);
|
||||||
this.pendingBlocks[initial.hash('hex')] = true;
|
this.pendingBlocks[initial.hash('hex')] = true;
|
||||||
|
this.pendingSize += initial.getSize();
|
||||||
|
if (this.pendingSize > this.pendingLimit) {
|
||||||
|
utils.debug('Warning: %dmb of pending blocks.',
|
||||||
|
utils.mb(this.pendingSize));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -863,6 +875,7 @@ Chain.prototype.add = function add(initial, peer, callback) {
|
|||||||
// If the orphan chain forked, simply
|
// If the orphan chain forked, simply
|
||||||
// reset the orphans and find a new peer.
|
// reset the orphans and find a new peer.
|
||||||
if (orphan.hash('hex') !== hash) {
|
if (orphan.hash('hex') !== hash) {
|
||||||
|
self.emit('purge', self.orphan.count, self.orphan.size);
|
||||||
self.orphan.map = {};
|
self.orphan.map = {};
|
||||||
self.orphan.bmap = {};
|
self.orphan.bmap = {};
|
||||||
self.orphan.count = 0;
|
self.orphan.count = 0;
|
||||||
@ -1079,7 +1092,6 @@ Chain.prototype.add = function add(initial, peer, callback) {
|
|||||||
self.orphan.bmap = {};
|
self.orphan.bmap = {};
|
||||||
self.orphan.count = 0;
|
self.orphan.count = 0;
|
||||||
self.orphan.size = 0;
|
self.orphan.size = 0;
|
||||||
utils.debug('Warning: 20mb of orphans cleared!');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We intentionally did not asyncify the
|
// We intentionally did not asyncify the
|
||||||
@ -1094,6 +1106,7 @@ Chain.prototype.add = function add(initial, peer, callback) {
|
|||||||
else
|
else
|
||||||
callback(null, total);
|
callback(null, total);
|
||||||
|
|
||||||
|
self.total += total;
|
||||||
self.locked = false;
|
self.locked = false;
|
||||||
|
|
||||||
// Start resolving the queue
|
// Start resolving the queue
|
||||||
@ -1103,6 +1116,7 @@ Chain.prototype.add = function add(initial, peer, callback) {
|
|||||||
|
|
||||||
item = self.pending.shift();
|
item = self.pending.shift();
|
||||||
delete self.pendingBlocks[item[0].hash('hex')];
|
delete self.pendingBlocks[item[0].hash('hex')];
|
||||||
|
self.pendingSize -= item[0].getSize();
|
||||||
|
|
||||||
self.add(item[0], item[1], item[2]);
|
self.add(item[0], item[1], item[2]);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -120,9 +120,7 @@ function Pool(options) {
|
|||||||
this.block = {
|
this.block = {
|
||||||
bestHeight: 0,
|
bestHeight: 0,
|
||||||
bestHash: null,
|
bestHash: null,
|
||||||
type: !options.spv ? 'block' : 'filtered',
|
type: !options.spv ? 'block' : 'filtered'
|
||||||
invalid: {},
|
|
||||||
total: 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.tx = {
|
this.tx = {
|
||||||
@ -650,15 +648,13 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
|
|||||||
|
|
||||||
self.emit('chain-progress', self.chain.fillPercent(), peer);
|
self.emit('chain-progress', self.chain.fillPercent(), peer);
|
||||||
|
|
||||||
self.block.total += added;
|
|
||||||
|
|
||||||
if (self.chain.height % 20 === 0) {
|
if (self.chain.height % 20 === 0) {
|
||||||
utils.debug(
|
utils.debug(
|
||||||
'Got: %s from %s chain len %d blocks %d orp %d act %d queue %d target %s peers %d pending %d',
|
'Got: %s from %s chain len %d blocks %d orp %d act %d queue %d target %s peers %d pending %d',
|
||||||
block.rhash,
|
block.rhash,
|
||||||
new Date(block.ts * 1000).toString(),
|
new Date(block.ts * 1000).toString(),
|
||||||
self.chain.height,
|
self.chain.height,
|
||||||
self.block.total,
|
self.chain.total,
|
||||||
self.chain.orphan.count,
|
self.chain.orphan.count,
|
||||||
self.request.activeBlocks,
|
self.request.activeBlocks,
|
||||||
peer._blockQueue.length,
|
peer._blockQueue.length,
|
||||||
@ -1799,7 +1795,9 @@ Pool.prototype.removeSeed = function removeSeed(seed) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.isOrphaning = function isOrphaning(peer) {
|
Pool.prototype.isOrphaning = function isOrphaning(peer) {
|
||||||
return false;
|
if (!this.options.orphanDOS)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (utils.now() > peer.orphanTime + 3 * 60) {
|
if (utils.now() > peer.orphanTime + 3 * 60) {
|
||||||
peer.orphans = 0;
|
peer.orphans = 0;
|
||||||
peer.orphanTime = utils.now();
|
peer.orphanTime = utils.now();
|
||||||
|
|||||||
@ -1456,3 +1456,7 @@ utils.forEach = function forEach(arr, iter, callback) {
|
|||||||
iter(item, next);
|
iter(item, next);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
utils.mb = function mb(size) {
|
||||||
|
return size / 1024 / 1024 | 0;
|
||||||
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user