only start calculating startHeight and locatorHashes after chain load.
This commit is contained in:
parent
3f2d53b414
commit
db0da78ae5
@ -413,18 +413,14 @@ Chain.prototype.getLast = function getLast(cb) {
|
|||||||
return cb(this.index.hashes[this.index.hashes.length - 1]);
|
return cb(this.index.hashes[this.index.hashes.length - 1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.getStartHeight = function getLast(cb) {
|
Chain.prototype.getStartHeight = function getStartHeight() {
|
||||||
if (!this.options.fullNode) {
|
if (!this.options.fullNode) {
|
||||||
if (this.options.startHeight != null) {
|
if (this.options.startHeight != null) {
|
||||||
return this.options.startHeight;
|
return this.options.startHeight;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (var i = 0; i < this.index.heights.length; i++) {
|
return this.index.heights[this.index.heights.length - 1];
|
||||||
if (this.index.heights[i + 1] !== this.index.heights[i] + 1) {
|
|
||||||
return this.index.heights[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.locatorHashes = function(index) {
|
Chain.prototype.locatorHashes = function(index) {
|
||||||
|
|||||||
@ -96,9 +96,7 @@ Peer.prototype._init = function init() {
|
|||||||
'Sent version (%s): height=%s',
|
'Sent version (%s): height=%s',
|
||||||
ip, this.pool.chain.getStartHeight());
|
ip, this.pool.chain.getStartHeight());
|
||||||
self.pool.emit('debug', 'version (%s): sending locator hashes', ip);
|
self.pool.emit('debug', 'version (%s): sending locator hashes', ip);
|
||||||
self.chain.on('load', function() {
|
self.loadHeaders(self.chain.locatorHashes(), 0);
|
||||||
self.loadHeaders(self.chain.locatorHashes(), 0);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,8 @@ var utils = bcoin.utils;
|
|||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
|
|
||||||
function Pool(options) {
|
function Pool(options) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (!(this instanceof Pool))
|
if (!(this instanceof Pool))
|
||||||
return new Pool(options);
|
return new Pool(options);
|
||||||
|
|
||||||
@ -90,7 +92,18 @@ function Pool(options) {
|
|||||||
this.createConnection = options.createConnection;
|
this.createConnection = options.createConnection;
|
||||||
assert(this.createConnection);
|
assert(this.createConnection);
|
||||||
|
|
||||||
this._init();
|
this.chain.on('debug', function() {
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
self.emit.apply(self, ['debug'].concat(args));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!this.chain.loading) {
|
||||||
|
this._init();
|
||||||
|
} else {
|
||||||
|
this.chain.once('load', function() {
|
||||||
|
self._init();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
inherits(Pool, EventEmitter);
|
inherits(Pool, EventEmitter);
|
||||||
module.exports = Pool;
|
module.exports = Pool;
|
||||||
@ -109,11 +122,6 @@ Pool.prototype._init = function _init() {
|
|||||||
self._scheduleRequests();
|
self._scheduleRequests();
|
||||||
self._loadRange(preload);
|
self._loadRange(preload);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.chain.on('debug', function() {
|
|
||||||
var args = Array.prototype.slice.call(arguments);
|
|
||||||
self.emit.apply(self, ['debug'].concat(args));
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype._addLoader = function _addLoader() {
|
Pool.prototype._addLoader = function _addLoader() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user