better orphan handling.
This commit is contained in:
parent
e97f1d0477
commit
72e5d5fbc7
@ -1207,7 +1207,7 @@ Peer.prototype._handleGetData = function handleGetData(items) {
|
|||||||
self.emit('error', err);
|
self.emit('error', err);
|
||||||
|
|
||||||
bcoin.debug(
|
bcoin.debug(
|
||||||
'Served %d items s with getdata (notfound=%d) (%s).',
|
'Served %d items with getdata (notfound=%d) (%s).',
|
||||||
items.length - notfound.length,
|
items.length - notfound.length,
|
||||||
notfound.length,
|
notfound.length,
|
||||||
self.hostname);
|
self.hostname);
|
||||||
|
|||||||
@ -820,7 +820,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var requested;
|
var requested;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
// Fulfill our request.
|
// Fulfill our request.
|
||||||
requested = self.fulfill(block);
|
requested = self.fulfill(block);
|
||||||
@ -831,24 +831,29 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
|
|||||||
bcoin.debug(
|
bcoin.debug(
|
||||||
'Received unrequested block: %s (%s).',
|
'Received unrequested block: %s (%s).',
|
||||||
block.rhash, peer.hostname);
|
block.rhash, peer.hostname);
|
||||||
return callback();
|
return utils.nextTick(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.chain.add(block, function(err) {
|
this.chain.add(block, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err.type === 'VerifyError') {
|
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'));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.scheduleRequests(peer);
|
self.scheduleRequests(peer);
|
||||||
|
|
||||||
return callback(err);
|
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);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -857,12 +862,15 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
|
|||||||
self.emit('chain-progress', self.chain.getProgress(), peer);
|
self.emit('chain-progress', self.chain.getProgress(), peer);
|
||||||
|
|
||||||
if (self.chain.total % 20 === 0) {
|
if (self.chain.total % 20 === 0) {
|
||||||
bcoin.debug(
|
bcoin.debug('Status:'
|
||||||
'Status: tip=%s ts=%s height=%d blocks=%d orphans=%d active=%d'
|
+ ' tip=%s ts=%s height=%d progress=%s'
|
||||||
+ ' queue=%d target=%s peers=%d pending=%d highest=%d jobs=%d',
|
+ ' blocks=%d orphans=%d active=%d'
|
||||||
|
+ ' queue=%d target=%s peers=%d'
|
||||||
|
+ ' pending=%d highest=%d jobs=%d',
|
||||||
block.rhash,
|
block.rhash,
|
||||||
utils.date(block.ts),
|
utils.date(block.ts),
|
||||||
self.chain.height,
|
self.chain.height,
|
||||||
|
(Math.floor(self.chain.getProgress() * 10000) / 100) + '%',
|
||||||
self.chain.total,
|
self.chain.total,
|
||||||
self.chain.orphan.count,
|
self.chain.orphan.count,
|
||||||
self.request.activeBlocks,
|
self.request.activeBlocks,
|
||||||
|
|||||||
@ -621,7 +621,7 @@ Parser.parseInv = function parseInv(p) {
|
|||||||
|
|
||||||
count = p.readVarint();
|
count = p.readVarint();
|
||||||
|
|
||||||
assert(count < 50000, 'Item count too high.');
|
assert(count <= 50000, 'Item count too high.');
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
items.push({
|
items.push({
|
||||||
@ -1182,6 +1182,8 @@ Parser.parseAddr = function parseAddr(p) {
|
|||||||
|
|
||||||
count = p.readVarint();
|
count = p.readVarint();
|
||||||
|
|
||||||
|
assert(count <= 10000, 'Too many addresses.');
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
addrs.push(Parser.parseAddress(p, true));
|
addrs.push(Parser.parseAddress(p, true));
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user