ignore orphan soil for request map. fix block delta.

This commit is contained in:
Christopher Jeffrey 2016-02-29 01:53:08 -08:00
parent 58d2f66a70
commit 5b1ee4cccb
3 changed files with 18 additions and 13 deletions

View File

@ -64,6 +64,8 @@ Block.prototype.renderWitness = function renderWitness() {
};
Block.prototype.getRaw = function getRaw() {
var raw;
if (this._raw) {
assert(this._size > 0);
assert(this._witnessSize >= 0);

View File

@ -48,7 +48,6 @@ function Chain(options) {
this.invalid = {};
this.bestHeight = -1;
this.lastUpdate = utils.now();
this.blockDelta = 0;
this.orphan = {
map: {},
@ -795,7 +794,6 @@ Chain.prototype._addEntry = function _addEntry(entry, block, callback) {
return callback(null, false);
now = utils.now();
this.blockDelta = now - this.lastUpdate;
this.lastUpdate = now;
this._saveBlock(block, function(err) {
@ -1621,15 +1619,20 @@ Chain.prototype.isFull = function isFull() {
delta = utils.now() - this.tip.ts;
return delta < 40 * 60;
return delta < 4 * 60 * 60;
};
Chain.prototype.isInitial = function isInitial() {
var now, delta;
if (!this.tip)
return true;
now = utils.now();
delta = now - this.lastUpdate;
// Should mimic the original IsInitialBlockDownload() function
return this.blockDelta < 10 && this.tip.ts < utils.now() - 24 * 60 * 60;
return delta < 10 && this.tip.ts < now - 24 * 60 * 60;
};
Chain.prototype.getProgress = function getProgress() {

View File

@ -74,7 +74,7 @@ function Pool(options) {
interval: options.loadInterval || 20000
};
this.requestTimeout = options.requestTimeout || 600000;
this.requestTimeout = options.requestTimeout || 2 * 60000;
this.chain = new bcoin.chain({
spv: options.spv,
@ -271,10 +271,10 @@ Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan) {
// If we're already processing the block
// that would resolve this, ignore.
if (self.request.map[orphan.soil]) {
utils.debug('Already requested orphan "soil".');
return;
}
// if (self.request.map[orphan.soil]) {
// utils.debug('Already requested orphan "soil".');
// return;
// }
if (self.chain.hasPending(orphan.soil)) {
utils.debug('Already processing orphan "soil".');
@ -441,6 +441,7 @@ Pool.prototype._addLoader = function _addLoader() {
peer.on('merkleblock', function(block) {
if (!self.options.spv)
return;
if (!self.syncing)
return;
@ -460,6 +461,7 @@ Pool.prototype._addLoader = function _addLoader() {
peer.on('block', function(block) {
if (self.options.spv)
return;
if (!self.syncing)
return;
@ -708,8 +710,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
if (self.chain.height % 20 === 0) {
utils.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'
+ ' blockdelta=%d',
+ ' queue=%d target=%s peers=%d pending=%d highest=%d jobs=%d',
block.rhash,
new Date(block.ts * 1000).toISOString().slice(0, -5) + 'Z',
self.chain.height,
@ -721,8 +722,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
self.peers.all.length,
self.chain.pending.length,
self.chain.bestHeight,
self.chain.jobs.length,
self.chain.blockDelta);
self.chain.jobs.length);
}
return callback(null, true);