fix notfound bug. ensure fast properties for network object.
This commit is contained in:
parent
5773d5b445
commit
aec1ebbdd3
@ -24,8 +24,6 @@ var PolicyEstimator = require('./fees');
|
||||
*/
|
||||
|
||||
function Network(options) {
|
||||
var i, keys, key, value;
|
||||
|
||||
if (!(this instanceof Network))
|
||||
return new Network(options);
|
||||
|
||||
@ -37,13 +35,33 @@ function Network(options) {
|
||||
if (Network[options.type])
|
||||
return Network[options.type];
|
||||
|
||||
keys = Object.keys(options);
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
key = keys[i];
|
||||
value = options[key];
|
||||
this[key] = value;
|
||||
}
|
||||
this.type = options.type;
|
||||
this.height = options.height;
|
||||
this.seeds = options.seeds;
|
||||
this.magic = options.magic;
|
||||
this.port = options.port;
|
||||
this.alertKey = options.alertKey;
|
||||
this.checkpoints = options.checkpoints;
|
||||
this.halvingInterval = options.halvingInterval;
|
||||
this.genesis = options.genesis;
|
||||
this.genesisBlock = options.genesisBlock;
|
||||
this.pow = options.pow;
|
||||
this.block = options.block;
|
||||
this.witness = options.witness;
|
||||
this.segwitHeight = options.segwitHeight;
|
||||
this.ruleChangeActivationThreshold = options.ruleChangeActivationThreshold;
|
||||
this.minerConfirmationWindow = options.minerConfirmationWindow;
|
||||
this.deployments = options.deployments;
|
||||
this.prefixes = options.prefixes;
|
||||
this.address = options.address;
|
||||
this.requireStandard = options.requireStandard;
|
||||
this.rpcPort = options.rpcPort;
|
||||
this.minRelay = options.minRelay;
|
||||
this.feeRate = options.feeRate;
|
||||
this.minRate = options.minRate;
|
||||
this.maxRate = options.maxRate;
|
||||
this.selfConnect = options.selfConnect;
|
||||
this.requestMempool = options.requestMempool;
|
||||
|
||||
this.fees = new PolicyEstimator(constants.tx.MIN_RELAY, this);
|
||||
|
||||
|
||||
@ -282,8 +282,10 @@ Peer.prototype._onConnect = function _onConnect() {
|
||||
self.sync();
|
||||
|
||||
// Ask for the mempool if we're synced.
|
||||
if (self.loader && self.pool.synced)
|
||||
self.sendMempool();
|
||||
if (self.network.requestMempool) {
|
||||
if (self.loader && self.pool.synced)
|
||||
self.sendMempool();
|
||||
}
|
||||
|
||||
bcoin.debug('Received verack (%s).', self.hostname);
|
||||
|
||||
@ -1227,7 +1229,7 @@ Peer.prototype._handleGetBlocks = function _handleGetBlocks(payload) {
|
||||
Peer.prototype._handleVersion = function _handleVersion(version) {
|
||||
var self = this;
|
||||
|
||||
if (this.network.type !== 'regtest') {
|
||||
if (!this.network.selfConnect) {
|
||||
if (version.nonce.cmp(this.pool.localNonce) === 0) {
|
||||
this._error('We connected to ourself. Oops.');
|
||||
this.setMisbehavior(100);
|
||||
@ -1419,7 +1421,7 @@ Peer.prototype._handleGetData = function _handleGetData(items) {
|
||||
return next(err);
|
||||
|
||||
if (!entry) {
|
||||
notfound.push({ type: constants.inv.TX, hash: hash });
|
||||
notfound.push(new InvItem(constants.inv.TX, hash));
|
||||
return next();
|
||||
}
|
||||
|
||||
|
||||
@ -1002,10 +1002,10 @@ Pool.prototype._createPeer = function _createPeer(options) {
|
||||
: null;
|
||||
|
||||
bcoin.debug(
|
||||
'Received reject (%s): msg=%s ccode=%s reason=%s data=%s.',
|
||||
'Received reject (%s): msg=%s code=%s reason=%s data=%s.',
|
||||
peer.hostname,
|
||||
payload.message,
|
||||
payload.ccode,
|
||||
constants.rejectByVal[payload.code] || payload.code,
|
||||
payload.reason,
|
||||
data);
|
||||
|
||||
|
||||
@ -455,6 +455,20 @@ main.minRate = 10000;
|
||||
|
||||
main.maxRate = 50000;
|
||||
|
||||
/**
|
||||
* Whether to allow self-connection.
|
||||
* @const {Boolean}
|
||||
*/
|
||||
|
||||
main.selfConnect = false;
|
||||
|
||||
/**
|
||||
* Whether to request mempool on sync.
|
||||
* @const {Boolean}
|
||||
*/
|
||||
|
||||
main.requestMempool = false;
|
||||
|
||||
/*
|
||||
* Testnet (v3)
|
||||
* https://en.bitcoin.it/wiki/Testnet
|
||||
@ -605,6 +619,10 @@ testnet.minRate = 10000;
|
||||
|
||||
testnet.maxRate = 40000;
|
||||
|
||||
testnet.selfConnect = false;
|
||||
|
||||
testnet.requestMempool = true;
|
||||
|
||||
/*
|
||||
* Regtest
|
||||
*/
|
||||
@ -748,6 +766,10 @@ regtest.minRate = 10000;
|
||||
|
||||
regtest.maxRate = 40000;
|
||||
|
||||
regtest.selfConnect = false;
|
||||
|
||||
regtest.requestMempool = true;
|
||||
|
||||
/*
|
||||
* segnet3
|
||||
*/
|
||||
@ -875,6 +897,10 @@ segnet3.minRate = 10000;
|
||||
|
||||
segnet3.maxRate = 40000;
|
||||
|
||||
segnet3.selfConnect = false;
|
||||
|
||||
segnet3.requestMempool = true;
|
||||
|
||||
/*
|
||||
* segnet4
|
||||
*/
|
||||
@ -1016,3 +1042,7 @@ segnet4.feeRate = 20000;
|
||||
segnet4.minRate = 10000;
|
||||
|
||||
segnet4.maxRate = 40000;
|
||||
|
||||
segnet4.selfConnect = false;
|
||||
|
||||
segnet4.requestMempool = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user