pool: load interval
This commit is contained in:
parent
2401fa2d4f
commit
b98be4b388
@ -18,6 +18,7 @@ function Pool(options) {
|
|||||||
this.redundancy = 2;
|
this.redundancy = 2;
|
||||||
this.load = {
|
this.load = {
|
||||||
timeout: options.loadTimeout || 5000,
|
timeout: options.loadTimeout || 5000,
|
||||||
|
interval: options.loadInterval || 5000,
|
||||||
window: options.loadWindow || 250,
|
window: options.loadWindow || 250,
|
||||||
timer: null,
|
timer: null,
|
||||||
lwm: options.lwm || this.parallel * 2,
|
lwm: options.lwm || this.parallel * 2,
|
||||||
@ -101,10 +102,15 @@ Pool.prototype._addLoader = function _addLoader() {
|
|||||||
peer.once('close', onclose);
|
peer.once('close', onclose);
|
||||||
function onclose() {
|
function onclose() {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
|
clearInterval(interval);
|
||||||
self._removePeer(peer);
|
self._removePeer(peer);
|
||||||
self._addLoader();
|
self._addLoader();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var interval = setInterval(function() {
|
||||||
|
self._load();
|
||||||
|
}, this.load.interval);
|
||||||
|
|
||||||
peer.once('ack', function() {
|
peer.once('ack', function() {
|
||||||
peer.updateWatch();
|
peer.updateWatch();
|
||||||
if (!self._load())
|
if (!self._load())
|
||||||
@ -115,7 +121,6 @@ Pool.prototype._addLoader = function _addLoader() {
|
|||||||
// Chain is full and up-to-date
|
// Chain is full and up-to-date
|
||||||
if (self.block.lastHash === null && self.chain.isFull()) {
|
if (self.block.lastHash === null && self.chain.isFull()) {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
peer.removeListener('close', onclose);
|
|
||||||
self._removePeer(peer);
|
self._removePeer(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,9 +10,12 @@ function TXPool() {
|
|||||||
}
|
}
|
||||||
module.exports = TXPool;
|
module.exports = TXPool;
|
||||||
|
|
||||||
TXPool.prototype.add = function add(tx) {
|
TXPool.prototype.add = function add(tx, wallet) {
|
||||||
var hash = tx.hash('hex');
|
var hash = tx.hash('hex');
|
||||||
|
|
||||||
|
if (!wallet.own(tx))
|
||||||
|
return;
|
||||||
|
|
||||||
// Do not add TX two times
|
// Do not add TX two times
|
||||||
if (this._all[hash])
|
if (this._all[hash])
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -149,7 +149,7 @@ Wallet.prototype.sign = function sign(tx, type) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.addTX = function addTX(tx) {
|
Wallet.prototype.addTX = function addTX(tx) {
|
||||||
return this.tx.add(tx);
|
return this.tx.add(tx, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.unspent = function unspent() {
|
Wallet.prototype.unspent = function unspent() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user