pool: fix search
This commit is contained in:
parent
9b765d9959
commit
a672b955c9
@ -322,7 +322,6 @@ Chain.prototype.get = function get(hash, force, cb) {
|
||||
}
|
||||
|
||||
if (this.request.add(hash, cb))
|
||||
false;
|
||||
this.emit('missing', hash, null, null);
|
||||
};
|
||||
|
||||
@ -335,6 +334,13 @@ Chain.prototype.isFull = function isFull() {
|
||||
return delta < 40 * 60;
|
||||
};
|
||||
|
||||
Chain.prototype.fillPercent = function fillPercent() {
|
||||
var first = this.index.ts[0];
|
||||
var now = (+new Date() / 1000 - 40 * 60) - first;
|
||||
var last = this.index.ts[this.index.ts.length - 1] - first;
|
||||
return Math.min(0, Math.max(last / now, 1));
|
||||
};
|
||||
|
||||
Chain.prototype.hashesInRange = function hashesInRange(start, end, cb) {
|
||||
if (this.loading) {
|
||||
this.once('load', function() {
|
||||
|
||||
@ -62,7 +62,6 @@ function Pool(options) {
|
||||
// getTX map
|
||||
map: {}
|
||||
};
|
||||
this.searching = false;
|
||||
|
||||
// Currently broadcasted TXs
|
||||
this.tx = {
|
||||
@ -356,17 +355,8 @@ Pool.prototype.unwatch = function unwatch(id) {
|
||||
this.peers.block[i].updateWatch();
|
||||
};
|
||||
|
||||
Pool.prototype.search = function search(id, range, e) {
|
||||
e = e || new EventEmitter();
|
||||
|
||||
// Serialize searches
|
||||
if (this.searching) {
|
||||
this.once('_searchEnd', function() {
|
||||
this.search(id, range, e);
|
||||
});
|
||||
return e;
|
||||
}
|
||||
this.searching = true;
|
||||
Pool.prototype.search = function search(id, range) {
|
||||
var e = new EventEmitter();
|
||||
|
||||
// Optional id argument
|
||||
if (typeof id === 'object' && !Array.isArray(id) ||
|
||||
@ -430,8 +420,6 @@ Pool.prototype.search = function search(id, range, e) {
|
||||
if (waiting === 0) {
|
||||
if (id)
|
||||
self.unwatch(id);
|
||||
self.searching = false;
|
||||
self.emit('_searchEnd');
|
||||
e.emit('end');
|
||||
}
|
||||
}
|
||||
@ -463,7 +451,7 @@ Pool.prototype._request = function _request(type, hash, options, cb) {
|
||||
var self = this;
|
||||
|
||||
// Block should be not in chain, or be requested
|
||||
if (type === 'block')
|
||||
if (!options.force && type === 'block')
|
||||
return this.chain.has(hash, true, next);
|
||||
else
|
||||
return next(false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user