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))
|
if (this.request.add(hash, cb))
|
||||||
false;
|
|
||||||
this.emit('missing', hash, null, null);
|
this.emit('missing', hash, null, null);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -335,6 +334,13 @@ Chain.prototype.isFull = function isFull() {
|
|||||||
return delta < 40 * 60;
|
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) {
|
Chain.prototype.hashesInRange = function hashesInRange(start, end, cb) {
|
||||||
if (this.loading) {
|
if (this.loading) {
|
||||||
this.once('load', function() {
|
this.once('load', function() {
|
||||||
|
|||||||
@ -62,7 +62,6 @@ function Pool(options) {
|
|||||||
// getTX map
|
// getTX map
|
||||||
map: {}
|
map: {}
|
||||||
};
|
};
|
||||||
this.searching = false;
|
|
||||||
|
|
||||||
// Currently broadcasted TXs
|
// Currently broadcasted TXs
|
||||||
this.tx = {
|
this.tx = {
|
||||||
@ -356,17 +355,8 @@ Pool.prototype.unwatch = function unwatch(id) {
|
|||||||
this.peers.block[i].updateWatch();
|
this.peers.block[i].updateWatch();
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.search = function search(id, range, e) {
|
Pool.prototype.search = function search(id, range) {
|
||||||
e = e || new EventEmitter();
|
var e = new EventEmitter();
|
||||||
|
|
||||||
// Serialize searches
|
|
||||||
if (this.searching) {
|
|
||||||
this.once('_searchEnd', function() {
|
|
||||||
this.search(id, range, e);
|
|
||||||
});
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
this.searching = true;
|
|
||||||
|
|
||||||
// Optional id argument
|
// Optional id argument
|
||||||
if (typeof id === 'object' && !Array.isArray(id) ||
|
if (typeof id === 'object' && !Array.isArray(id) ||
|
||||||
@ -430,8 +420,6 @@ Pool.prototype.search = function search(id, range, e) {
|
|||||||
if (waiting === 0) {
|
if (waiting === 0) {
|
||||||
if (id)
|
if (id)
|
||||||
self.unwatch(id);
|
self.unwatch(id);
|
||||||
self.searching = false;
|
|
||||||
self.emit('_searchEnd');
|
|
||||||
e.emit('end');
|
e.emit('end');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -463,7 +451,7 @@ Pool.prototype._request = function _request(type, hash, options, cb) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Block should be not in chain, or be requested
|
// Block should be not in chain, or be requested
|
||||||
if (type === 'block')
|
if (!options.force && type === 'block')
|
||||||
return this.chain.has(hash, true, next);
|
return this.chain.has(hash, true, next);
|
||||||
else
|
else
|
||||||
return next(false);
|
return next(false);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user