better orphan handling.

This commit is contained in:
Christopher Jeffrey 2016-05-20 04:15:01 -07:00
parent e97f1d0477
commit 72e5d5fbc7
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 27 additions and 17 deletions

View File

@ -1207,7 +1207,7 @@ Peer.prototype._handleGetData = function handleGetData(items) {
self.emit('error', err);
bcoin.debug(
'Served %d items s with getdata (notfound=%d) (%s).',
'Served %d items with getdata (notfound=%d) (%s).',
items.length - notfound.length,
notfound.length,
self.hostname);

View File

@ -820,7 +820,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
var self = this;
var requested;
callback = utils.asyncify(callback);
callback = utils.ensure(callback);
// Fulfill our request.
requested = self.fulfill(block);
@ -831,24 +831,29 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
bcoin.debug(
'Received unrequested block: %s (%s).',
block.rhash, peer.hostname);
return callback();
return utils.nextTick(callback);
}
this.chain.add(block, function(err) {
if (err) {
if (err.type === 'VerifyError') {
if (err.score >= 0)
peer.sendReject(block, err.code, err.reason, err.score);
if (err.reason === 'bad-prevblk') {
if (peer === self.peers.load)
self.resolveOrphan(peer, null, block.hash('hex'));
}
if (err.type !== 'VerifyError') {
self.scheduleRequests(peer);
return callback(err);
}
if (err.score >= 0)
peer.sendReject(block, err.code, err.reason, err.score);
if (err.reason === 'bad-prevblk' && peer === self.peers.load) {
self.resolveOrphan(peer, null, block.hash('hex'), function(e) {
self.scheduleRequests(peer);
return callback(e || err);
});
return;
}
self.scheduleRequests(peer);
return callback(err);
}
@ -857,12 +862,15 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
self.emit('chain-progress', self.chain.getProgress(), peer);
if (self.chain.total % 20 === 0) {
bcoin.debug(
'Status: tip=%s ts=%s height=%d blocks=%d orphans=%d active=%d'
+ ' queue=%d target=%s peers=%d pending=%d highest=%d jobs=%d',
bcoin.debug('Status:'
+ ' tip=%s ts=%s height=%d progress=%s'
+ ' blocks=%d orphans=%d active=%d'
+ ' queue=%d target=%s peers=%d'
+ ' pending=%d highest=%d jobs=%d',
block.rhash,
utils.date(block.ts),
self.chain.height,
(Math.floor(self.chain.getProgress() * 10000) / 100) + '%',
self.chain.total,
self.chain.orphan.count,
self.request.activeBlocks,

View File

@ -621,7 +621,7 @@ Parser.parseInv = function parseInv(p) {
count = p.readVarint();
assert(count < 50000, 'Item count too high.');
assert(count <= 50000, 'Item count too high.');
for (i = 0; i < count; i++) {
items.push({
@ -1182,6 +1182,8 @@ Parser.parseAddr = function parseAddr(p) {
count = p.readVarint();
assert(count <= 10000, 'Too many addresses.');
for (i = 0; i < count; i++)
addrs.push(Parser.parseAddress(p, true));