chain and search fixes. options.
This commit is contained in:
parent
0f8819c78e
commit
6758d4fe8a
@ -564,13 +564,13 @@ Chain.prototype.fillPercent = function fillPercent() {
|
|||||||
Chain.prototype.hashRange = function hashRange(start, end) {
|
Chain.prototype.hashRange = function hashRange(start, end) {
|
||||||
var hashes;
|
var hashes;
|
||||||
|
|
||||||
start = this.chain.byTime(start);
|
start = this.byTime(start);
|
||||||
end = this.chain.byTime(end);
|
end = this.byTime(end);
|
||||||
|
|
||||||
if (!start || !end)
|
if (!start || !end)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
hashes = this.chain.index.hashes.slice(start.index, end.index + 1);
|
hashes = this.index.hashes.slice(start.index, end.index + 1);
|
||||||
|
|
||||||
return hashes;
|
return hashes;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -396,13 +396,13 @@ Chain.prototype.fillPercent = function fillPercent() {
|
|||||||
Chain.prototype.hashRange = function hashRange(start, end) {
|
Chain.prototype.hashRange = function hashRange(start, end) {
|
||||||
var hashes;
|
var hashes;
|
||||||
|
|
||||||
start = this.chain.byTime(start);
|
start = this.byTime(start);
|
||||||
end = this.chain.byTime(end);
|
end = this.byTime(end);
|
||||||
|
|
||||||
if (!start || !end)
|
if (!start || !end)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
hashes = this.chain.index.hashes.slice(start.height, end.height + 1);
|
hashes = this.index.hashes.slice(start.height, end.height + 1);
|
||||||
|
|
||||||
return hashes;
|
return hashes;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -33,15 +33,22 @@ function Pool(options) {
|
|||||||
|
|
||||||
this.options.fullNode = !!this.options.fullNode;
|
this.options.fullNode = !!this.options.fullNode;
|
||||||
this.options.headers = !!this.options.headers;
|
this.options.headers = !!this.options.headers;
|
||||||
|
this.options.multiplePeers = !!this.options.multiplePeers;
|
||||||
this.options.relay = this.options.relay == null
|
this.options.relay = this.options.relay == null
|
||||||
? (this.options.fullNode ? true : false)
|
? (this.options.fullNode ? true : false)
|
||||||
: this.options.relay;
|
: this.options.relay;
|
||||||
|
|
||||||
this.storage = this.options.storage;
|
this.storage = this.options.storage;
|
||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
this.size = options.size || 32;
|
this.size = options.size || 32;
|
||||||
this.parallel = options.parallel || 2000;
|
this.parallel = options.parallel || 2000;
|
||||||
this.redundancy = options.redundancy || 2;
|
this.redundancy = options.redundancy || 2;
|
||||||
|
|
||||||
|
if (!this.options.fullNode) {
|
||||||
|
this.options.headers = true;
|
||||||
|
this.options.multiplePeers = true;
|
||||||
|
}
|
||||||
|
|
||||||
this.backoff = {
|
this.backoff = {
|
||||||
delta: options.backoffDelta || 500,
|
delta: options.backoffDelta || 500,
|
||||||
max: options.backoffMax || 5000
|
max: options.backoffMax || 5000
|
||||||
@ -296,7 +303,7 @@ Pool.prototype._addLoader = function _addLoader() {
|
|||||||
this._startTimer();
|
this._startTimer();
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype._handleHeaders = function _handleHeaders(hashes, peer) {
|
Pool.prototype._handleHeaders = function _handleHeaders(headers, peer) {
|
||||||
var i, header, last, block;
|
var i, header, last, block;
|
||||||
|
|
||||||
assert(this.options.headers);
|
assert(this.options.headers);
|
||||||
@ -457,10 +464,12 @@ Pool.prototype._addIndex = function _addIndex(block, peer) {
|
|||||||
|
|
||||||
if (this.chain.hasOrphan(block)) {
|
if (this.chain.hasOrphan(block)) {
|
||||||
// Resolve orphan chain
|
// Resolve orphan chain
|
||||||
peer.loadBlocks(
|
if (!this.options.headers) {
|
||||||
this.chain.locatorHashes(),
|
peer.loadBlocks(
|
||||||
this.chain.getOrphanRoot(block)
|
this.chain.locatorHashes(),
|
||||||
);
|
this.chain.getOrphanRoot(block)
|
||||||
|
);
|
||||||
|
}
|
||||||
// Emit our orphan if it is new
|
// Emit our orphan if it is new
|
||||||
if (!orphan)
|
if (!orphan)
|
||||||
return true;
|
return true;
|
||||||
@ -898,6 +907,7 @@ Pool.prototype.searchWallet = function(w) {
|
|||||||
self.emit('debug', 'Wallet time: %s', new Date(ts * 1000));
|
self.emit('debug', 'Wallet time: %s', new Date(ts * 1000));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// this.search(ts);
|
||||||
this.chain.resetTime(ts);
|
this.chain.resetTime(ts);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -911,9 +921,9 @@ Pool.prototype.search = function search(id, range, e) {
|
|||||||
e = e || new EventEmitter();
|
e = e || new EventEmitter();
|
||||||
|
|
||||||
// Optional id argument
|
// Optional id argument
|
||||||
if (id !== null
|
if ((id !== null
|
||||||
&& typeof id === 'object'
|
&& typeof id === 'object'
|
||||||
&& !Array.isArray(id)
|
&& !Array.isArray(id))
|
||||||
|| typeof id === 'number') {
|
|| typeof id === 'number') {
|
||||||
range = id;
|
range = id;
|
||||||
id = null;
|
id = null;
|
||||||
@ -936,7 +946,7 @@ Pool.prototype.search = function search(id, range, e) {
|
|||||||
if (!range.start)
|
if (!range.start)
|
||||||
range.start = utils.now() - 432000;
|
range.start = utils.now() - 432000;
|
||||||
|
|
||||||
if (range.start < this.chain.lastTs) {
|
if (range.start < this.chain.index.lastTs) {
|
||||||
if (id)
|
if (id)
|
||||||
this.watch(id);
|
this.watch(id);
|
||||||
|
|
||||||
@ -953,11 +963,19 @@ Pool.prototype.search = function search(id, range, e) {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Estimated number of blocks in time range
|
||||||
total = (range.end - range.start) / network.powTargetSpacing | 0;
|
total = (range.end - range.start) / network.powTargetSpacing | 0;
|
||||||
|
|
||||||
if (total === 0)
|
if (total === 0)
|
||||||
total = 1;
|
total = 1;
|
||||||
|
|
||||||
timeout = setTimeout(done.bind(null, true), total * 10 * 1000);
|
// 500 blocks every 3 seconds
|
||||||
|
total = (total / 500 | 0) * 3;
|
||||||
|
|
||||||
|
// Add half the total time and convert to ms
|
||||||
|
total = (total + Math.ceil(total / 2)) * 1000;
|
||||||
|
|
||||||
|
timeout = setTimeout(done.bind(null, true), total);
|
||||||
|
|
||||||
this.chain.resetTime(range.start);
|
this.chain.resetTime(range.start);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user