network: add block batch size.
This commit is contained in:
parent
83c1f8853d
commit
d68d79841a
@ -55,6 +55,7 @@ function Network(options) {
|
|||||||
this.maxRate = options.maxRate;
|
this.maxRate = options.maxRate;
|
||||||
this.selfConnect = options.selfConnect;
|
this.selfConnect = options.selfConnect;
|
||||||
this.requestMempool = options.requestMempool;
|
this.requestMempool = options.requestMempool;
|
||||||
|
this.batchSize = options.batchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,6 +128,26 @@ Network.prototype.getRate = function getRate() {
|
|||||||
return Math.min(this.feeRate, this.maxRate);
|
return Math.min(this.feeRate, this.maxRate);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine how many blocks to request
|
||||||
|
* based on current height of the chain.
|
||||||
|
* @param {Number} height
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Network.prototype.getBatchSize = function getBatchSize(height) {
|
||||||
|
var batch = this.batchSize;
|
||||||
|
var last = batch.length - 1;
|
||||||
|
var i;
|
||||||
|
|
||||||
|
for (i = 0; i < last; i++) {
|
||||||
|
if (height <= batch[i][0])
|
||||||
|
return batch[i][1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return batch[last][0];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a network. Get existing network if possible.
|
* Create a network. Get existing network if possible.
|
||||||
* @param {NetworkType|Object} options
|
* @param {NetworkType|Object} options
|
||||||
|
|||||||
@ -1600,17 +1600,7 @@ Pool.prototype._sendRequests = function _sendRequests(peer) {
|
|||||||
items = peer.queue.block.slice();
|
items = peer.queue.block.slice();
|
||||||
peer.queue.block.length = 0;
|
peer.queue.block.length = 0;
|
||||||
} else {
|
} else {
|
||||||
// Blocks start getting big after 150k.
|
size = this.network.getBatchSize(this.chain.height);
|
||||||
if (this.chain.height <= 100000)
|
|
||||||
size = 500;
|
|
||||||
else if (this.chain.height <= 150000)
|
|
||||||
size = 250;
|
|
||||||
else if (this.chain.height <= 250000)
|
|
||||||
size = 150;
|
|
||||||
else if (this.chain.height <= 350000)
|
|
||||||
size = 50;
|
|
||||||
else
|
|
||||||
size = 20;
|
|
||||||
|
|
||||||
if (this.request.activeBlocks >= size)
|
if (this.request.activeBlocks >= size)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -444,6 +444,19 @@ main.selfConnect = false;
|
|||||||
|
|
||||||
main.requestMempool = false;
|
main.requestMempool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of blocks to request based on chain height.
|
||||||
|
* @const {Array}
|
||||||
|
*/
|
||||||
|
|
||||||
|
main.batchSize = [
|
||||||
|
[100000, 500],
|
||||||
|
[150000, 250],
|
||||||
|
[250000, 150],
|
||||||
|
[350000, 50],
|
||||||
|
[20]
|
||||||
|
];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Testnet (v3)
|
* Testnet (v3)
|
||||||
* https://en.bitcoin.it/wiki/Testnet
|
* https://en.bitcoin.it/wiki/Testnet
|
||||||
@ -591,6 +604,11 @@ testnet.selfConnect = false;
|
|||||||
|
|
||||||
testnet.requestMempool = true;
|
testnet.requestMempool = true;
|
||||||
|
|
||||||
|
testnet.batchSize = [
|
||||||
|
[100000, 500],
|
||||||
|
[250]
|
||||||
|
];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Regtest
|
* Regtest
|
||||||
*/
|
*/
|
||||||
@ -731,6 +749,10 @@ regtest.selfConnect = false;
|
|||||||
|
|
||||||
regtest.requestMempool = true;
|
regtest.requestMempool = true;
|
||||||
|
|
||||||
|
regtest.batchSize = [
|
||||||
|
[500]
|
||||||
|
];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* segnet3
|
* segnet3
|
||||||
*/
|
*/
|
||||||
@ -850,6 +872,11 @@ segnet3.selfConnect = false;
|
|||||||
|
|
||||||
segnet3.requestMempool = true;
|
segnet3.requestMempool = true;
|
||||||
|
|
||||||
|
segnet3.batchSize = [
|
||||||
|
[20000, 500],
|
||||||
|
[250]
|
||||||
|
];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* segnet4
|
* segnet4
|
||||||
*/
|
*/
|
||||||
@ -983,3 +1010,8 @@ segnet4.maxRate = 40000;
|
|||||||
segnet4.selfConnect = false;
|
segnet4.selfConnect = false;
|
||||||
|
|
||||||
segnet4.requestMempool = true;
|
segnet4.requestMempool = true;
|
||||||
|
|
||||||
|
segnet4.batchSize = [
|
||||||
|
[17000, 500],
|
||||||
|
[250]
|
||||||
|
];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user