fixes.
This commit is contained in:
parent
5dc7030ac4
commit
86efd59261
@ -154,21 +154,24 @@ Chain.prototype._init = function _init() {
|
|||||||
if (err)
|
if (err)
|
||||||
return self.emit('error', err);
|
return self.emit('error', err);
|
||||||
|
|
||||||
self.isSegwitActive(function(err) {
|
self.db.getTip(function(err, tip) {
|
||||||
if (err)
|
if (err)
|
||||||
return self.emit('error', err);
|
return self.emit('error', err);
|
||||||
|
|
||||||
self.db.getTip(function(err, tip) {
|
assert(tip);
|
||||||
|
|
||||||
|
self.tip = tip;
|
||||||
|
self.height = tip.height;
|
||||||
|
|
||||||
|
if (self.bestHeight === -1)
|
||||||
|
network.height = tip.height;
|
||||||
|
|
||||||
|
self.isSegwitActive(function(err, result) {
|
||||||
if (err)
|
if (err)
|
||||||
return self.emit('error', err);
|
return self.emit('error', err);
|
||||||
|
|
||||||
assert(tip);
|
if (result)
|
||||||
|
utils.debug('Segwit is active.');
|
||||||
self.tip = tip;
|
|
||||||
self.height = tip.height;
|
|
||||||
|
|
||||||
if (self.bestHeight === -1)
|
|
||||||
network.height = tip.height;
|
|
||||||
|
|
||||||
self.loaded = true;
|
self.loaded = true;
|
||||||
self.emit('open');
|
self.emit('open');
|
||||||
@ -1906,6 +1909,7 @@ Chain.prototype.computeBlockVersion = function computeBlockVersion(prev, callbac
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.isSegwitActive = function isSegwitActive(callback) {
|
Chain.prototype.isSegwitActive = function isSegwitActive(callback) {
|
||||||
|
var self = this;
|
||||||
var tip = this.tip;
|
var tip = this.tip;
|
||||||
var unlock;
|
var unlock;
|
||||||
|
|
||||||
@ -1915,7 +1919,7 @@ Chain.prototype.isSegwitActive = function isSegwitActive(callback) {
|
|||||||
if (!tip)
|
if (!tip)
|
||||||
return utils.asyncify(callback)(null, false);
|
return utils.asyncify(callback)(null, false);
|
||||||
|
|
||||||
if (!(network.segwitHeight !== -1 && height >= network.segwitHeight))
|
if (!(network.segwitHeight !== -1 && tip.height >= network.segwitHeight))
|
||||||
return utils.asyncify(callback)(null, false);
|
return utils.asyncify(callback)(null, false);
|
||||||
|
|
||||||
unlock = this._lock(isSegwitActive, [callback]);
|
unlock = this._lock(isSegwitActive, [callback]);
|
||||||
|
|||||||
@ -22,12 +22,12 @@ var network = bcoin.protocol.network;
|
|||||||
function Coin(tx, index) {
|
function Coin(tx, index) {
|
||||||
var options;
|
var options;
|
||||||
|
|
||||||
if (!(this instanceof Coin))
|
|
||||||
return new Coin(tx, index);
|
|
||||||
|
|
||||||
if (tx instanceof Coin)
|
if (tx instanceof Coin)
|
||||||
return tx;
|
return tx;
|
||||||
|
|
||||||
|
if (!(this instanceof Coin))
|
||||||
|
return new Coin(tx, index);
|
||||||
|
|
||||||
if (tx instanceof bcoin.tx) {
|
if (tx instanceof bcoin.tx) {
|
||||||
this.version = tx.version;
|
this.version = tx.version;
|
||||||
this.height = tx.height;
|
this.height = tx.height;
|
||||||
@ -117,7 +117,7 @@ Coin.prototype.toJSON = function toJSON() {
|
|||||||
version: this.version,
|
version: this.version,
|
||||||
height: this.height,
|
height: this.height,
|
||||||
value: utils.btc(this.value),
|
value: utils.btc(this.value),
|
||||||
script: utils.toHex(bcoin.protocol.framer(this.script)),
|
script: utils.toHex(bcoin.protocol.framer.script(this.script)),
|
||||||
coinbase: this.coinbase,
|
coinbase: this.coinbase,
|
||||||
hash: this.hash ? utils.revHex(this.hash) : null,
|
hash: this.hash ? utils.revHex(this.hash) : null,
|
||||||
index: this.index
|
index: this.index
|
||||||
|
|||||||
@ -360,6 +360,7 @@ Mempool.prototype.addTX = function addTX(tx, peer, callback, force) {
|
|||||||
'mempool full',
|
'mempool full',
|
||||||
0));
|
0));
|
||||||
}
|
}
|
||||||
|
utils.debug('Added orphan %s to mempool.', tx.rhash);
|
||||||
return self.storeOrphan(tx, callback);
|
return self.storeOrphan(tx, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,6 +413,7 @@ Mempool.prototype.addUnchecked = function addUnchecked(tx, peer, callback) {
|
|||||||
self.addUnchecked(tx, peer, function(err) {
|
self.addUnchecked(tx, peer, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
self.emit('error', err);
|
self.emit('error', err);
|
||||||
|
utils.debug('Resolved orphan %s in mempool.', tx.rhash);
|
||||||
next();
|
next();
|
||||||
}, true);
|
}, true);
|
||||||
}, callback);
|
}, callback);
|
||||||
@ -872,9 +874,9 @@ Mempool.prototype.getLocks = function getLocks(tx, flags, entry, callback) {
|
|||||||
if (input.sequence & disableFlag)
|
if (input.sequence & disableFlag)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
coinHeight = coin.height === -1
|
coinHeight = input.coin.height === -1
|
||||||
? self.chain.tip + 1
|
? self.chain.tip + 1
|
||||||
: coin.height;
|
: input.coin.height;
|
||||||
|
|
||||||
if ((input.sequence & typeFlag) === 0) {
|
if ((input.sequence & typeFlag) === 0) {
|
||||||
coinHeight += (input.sequence & mask) - 1;
|
coinHeight += (input.sequence & mask) - 1;
|
||||||
@ -921,7 +923,7 @@ Mempool.prototype.evalLocks = function evalLocks(entry, minHeight, minTime, call
|
|||||||
|
|
||||||
return callback(null, true);
|
return callback(null, true);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
Mempool.prototype.checkLocks = function checkLocks(tx, flags, entry, callback) {
|
Mempool.prototype.checkLocks = function checkLocks(tx, flags, entry, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -931,7 +933,7 @@ Mempool.prototype.checkLocks = function checkLocks(tx, flags, entry, callback) {
|
|||||||
|
|
||||||
self.evalLocks(entry, minHeight, minTime, callback);
|
self.evalLocks(entry, minHeight, minTime, callback);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
Mempool.prototype.checkMempoolLocks = function checkMempoolLocks(tx, flags, callback) {
|
Mempool.prototype.checkMempoolLocks = function checkMempoolLocks(tx, flags, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -950,7 +952,7 @@ Mempool.prototype.checkMempoolLocks = function checkMempoolLocks(tx, flags, call
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.checkLocks(tx, flags, index, callback);
|
this.checkLocks(tx, flags, index, callback);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VerifyError
|
* VerifyError
|
||||||
|
|||||||
@ -42,6 +42,8 @@ function Peer(pool, options) {
|
|||||||
this.ack = false;
|
this.ack = false;
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
this.ts = this.options.ts || 0;
|
this.ts = this.options.ts || 0;
|
||||||
|
this.sendHeaders = false;
|
||||||
|
this.haveWitness = false;
|
||||||
|
|
||||||
this.challenge = null;
|
this.challenge = null;
|
||||||
this.lastPong = 0;
|
this.lastPong = 0;
|
||||||
@ -147,6 +149,11 @@ Peer.prototype._init = function init() {
|
|||||||
this.challenge = utils.nonce();
|
this.challenge = utils.nonce();
|
||||||
|
|
||||||
this._ping.timer = setInterval(function() {
|
this._ping.timer = setInterval(function() {
|
||||||
|
if (self.options.witness && !self.haveWitness) {
|
||||||
|
self._error('Peer does not support segregated witness.');
|
||||||
|
self.setMisbehavior(100);
|
||||||
|
return;
|
||||||
|
}
|
||||||
self._write(self.framer.ping({
|
self._write(self.framer.ping({
|
||||||
nonce: self.challenge
|
nonce: self.challenge
|
||||||
}));
|
}));
|
||||||
@ -163,12 +170,20 @@ Peer.prototype._init = function init() {
|
|||||||
self.emit('ack');
|
self.emit('ack');
|
||||||
self.ts = utils.now();
|
self.ts = utils.now();
|
||||||
|
|
||||||
self._write(self.framer.packet('getaddr', new Buffer([])));
|
self._write(self.framer.packet('getaddr'));
|
||||||
|
|
||||||
if (self.pool.options.headers) {
|
if (self.options.headers) {
|
||||||
if (self.version && self.version.version > 70012)
|
if (self.version && self.version.version > 70012)
|
||||||
self._write(self.framer.packet('sendheaders', new Buffer([])));
|
self._write(self.framer.packet('sendheaders'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self.options.witness) {
|
||||||
|
if (self.version && self.version.version >= 70012)
|
||||||
|
self._write(self.framer.packet('havewitness'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.pool.chain.isFull())
|
||||||
|
self.getMempool();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send hello
|
// Send hello
|
||||||
@ -454,6 +469,16 @@ Peer.prototype._onPacket = function onPacket(packet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmd === 'sendheaders') {
|
||||||
|
this.sendHeaders = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd === 'havewitness') {
|
||||||
|
this.haveWitness = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this._res(cmd, payload))
|
if (this._res(cmd, payload))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -469,14 +494,14 @@ Peer.prototype._emitMerkle = function _emitMerkle(payload) {
|
|||||||
Peer.prototype._handleVersion = function handleVersion(payload) {
|
Peer.prototype._handleVersion = function handleVersion(payload) {
|
||||||
if (payload.version < constants.minVersion) {
|
if (payload.version < constants.minVersion) {
|
||||||
this._error('Peer doesn\'t support required protocol version.');
|
this._error('Peer doesn\'t support required protocol version.');
|
||||||
this.pool.setMisbehavior(this, 100);
|
this.setMisbehavior(100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.headers) {
|
if (this.options.headers) {
|
||||||
if (payload.version < 31800) {
|
if (payload.version < 31800) {
|
||||||
this._error('Peer doesn\'t support getheaders.');
|
this._error('Peer doesn\'t support getheaders.');
|
||||||
this.pool.setMisbehavior(this, 100);
|
this.setMisbehavior(100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -484,7 +509,7 @@ Peer.prototype._handleVersion = function handleVersion(payload) {
|
|||||||
if (this.options.network) {
|
if (this.options.network) {
|
||||||
if (!payload.network) {
|
if (!payload.network) {
|
||||||
this._error('Peer does not support network services.');
|
this._error('Peer does not support network services.');
|
||||||
this.pool.setMisbehavior(this, 100);
|
this.setMisbehavior(100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -492,19 +517,22 @@ Peer.prototype._handleVersion = function handleVersion(payload) {
|
|||||||
if (this.options.spv) {
|
if (this.options.spv) {
|
||||||
if (!payload.bloom && payload.version < 70011) {
|
if (!payload.bloom && payload.version < 70011) {
|
||||||
this._error('Peer does not support bip37.');
|
this._error('Peer does not support bip37.');
|
||||||
this.pool.setMisbehavior(this, 100);
|
this.setMisbehavior(100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.witness) {
|
if (this.options.witness) {
|
||||||
if (!payload.witness) {
|
if (!payload.witness) {
|
||||||
this._error('Peer does not support segregated witness.');
|
// this._error('Peer does not support segregated witness service.');
|
||||||
this.pool.setMisbehavior(this, 100);
|
// this.setMisbehavior(100);
|
||||||
return;
|
// return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (payload.witness)
|
||||||
|
this.haveWitness = true;
|
||||||
|
|
||||||
// ACK
|
// ACK
|
||||||
this._write(this.framer.verack());
|
this._write(this.framer.verack());
|
||||||
this.version = payload;
|
this.version = payload;
|
||||||
@ -734,8 +762,8 @@ Peer.prototype.isMisbehaving = function isMisbehaving() {
|
|||||||
return this.pool.isMisbehaving(this.host);
|
return this.pool.isMisbehaving(this.host);
|
||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype.setMisbehavior = function setMisbehavior(dos) {
|
Peer.prototype.setMisbehavior = function setMisbehavior(score) {
|
||||||
return this.pool.setMisbehavior(this, dos);
|
return this.pool.setMisbehavior(this, score);
|
||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype.sendReject = function sendReject(obj, code, reason, score) {
|
Peer.prototype.sendReject = function sendReject(obj, code, reason, score) {
|
||||||
|
|||||||
@ -7,10 +7,9 @@
|
|||||||
var bn = require('bn.js');
|
var bn = require('bn.js');
|
||||||
|
|
||||||
exports.minVersion = 70001;
|
exports.minVersion = 70001;
|
||||||
exports.version = 70002;
|
exports.version = 70012;
|
||||||
// exports.maxMessage = 2 * 1024 * 1024; // main
|
// exports.maxMessage = 2 * 1024 * 1024; // main
|
||||||
exports.maxMessage = 4 * 1000 * 1000; // segwit
|
exports.maxMessage = 4 * 1000 * 1000; // segwit
|
||||||
exports.bcoinServices = 0;
|
|
||||||
|
|
||||||
exports.services = {
|
exports.services = {
|
||||||
network: (1 << 0),
|
network: (1 << 0),
|
||||||
@ -19,6 +18,9 @@ exports.services = {
|
|||||||
witness: (1 << 3)
|
witness: (1 << 3)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.localServices = exports.services.network
|
||||||
|
| exports.services.witness;
|
||||||
|
|
||||||
exports.inv = {
|
exports.inv = {
|
||||||
error: 0,
|
error: 0,
|
||||||
tx: 1,
|
tx: 1,
|
||||||
|
|||||||
@ -10,6 +10,7 @@ var constants = require('./constants');
|
|||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var BufferWriter = require('../writer');
|
var BufferWriter = require('../writer');
|
||||||
|
var DUMMY = new Buffer([]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Framer
|
* Framer
|
||||||
@ -53,8 +54,14 @@ Framer.prototype.header = function header(cmd, payload) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Framer.prototype.packet = function packet(cmd, payload) {
|
Framer.prototype.packet = function packet(cmd, payload) {
|
||||||
var h = this.header(cmd, payload);
|
var header;
|
||||||
return Buffer.concat([h, payload]);
|
|
||||||
|
if (!payload)
|
||||||
|
payload = DUMMY;
|
||||||
|
|
||||||
|
header = this.header(cmd, payload);
|
||||||
|
|
||||||
|
return Buffer.concat([header, payload]);
|
||||||
};
|
};
|
||||||
|
|
||||||
Framer.prototype.version = function version(options) {
|
Framer.prototype.version = function version(options) {
|
||||||
@ -205,10 +212,10 @@ Framer.version = function version(options, writer) {
|
|||||||
options.local = {};
|
options.local = {};
|
||||||
|
|
||||||
if (options.local.services == null)
|
if (options.local.services == null)
|
||||||
options.local.services = constants.bcoinServices;
|
options.local.services = constants.localServices;
|
||||||
|
|
||||||
p.write32(constants.version);
|
p.write32(constants.version);
|
||||||
p.writeU64(constants.bcoinServices);
|
p.writeU64(constants.localServices);
|
||||||
p.write64(utils.now());
|
p.write64(utils.now());
|
||||||
Framer.address(options.remote, false, p);
|
Framer.address(options.remote, false, p);
|
||||||
Framer.address(options.local, false, p);
|
Framer.address(options.local, false, p);
|
||||||
|
|||||||
@ -153,6 +153,9 @@ Parser.prototype.parsePayload = function parsePayload(cmd, p) {
|
|||||||
if (cmd === 'alert')
|
if (cmd === 'alert')
|
||||||
return Parser.parseAlert(p);
|
return Parser.parseAlert(p);
|
||||||
|
|
||||||
|
if (cmd === 'utxo')
|
||||||
|
return Parser.parseUTXO(p);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -436,7 +439,7 @@ Parser.parseOutput = function parseOutput(p) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Parser.parseUTXO = function parseUTXO(p) {
|
Parser.parseUTXO = function parseUTXO(p) {
|
||||||
var version, height, value, script, hash, index, coinbase;
|
var version, height, value, script;
|
||||||
|
|
||||||
p = new BufferReader(p);
|
p = new BufferReader(p);
|
||||||
p.start();
|
p.start();
|
||||||
|
|||||||
@ -2234,7 +2234,7 @@ Script.format = function format(code) {
|
|||||||
|
|
||||||
assert(typeof chunk === 'number');
|
assert(typeof chunk === 'number');
|
||||||
|
|
||||||
if (constants.opcodeByVal[chunk])
|
if (constants.opcodesByVal[chunk])
|
||||||
return constants.opcodesByVal[chunk];
|
return constants.opcodesByVal[chunk];
|
||||||
|
|
||||||
chunk = chunk.toString(16);
|
chunk = chunk.toString(16);
|
||||||
|
|||||||
@ -852,7 +852,7 @@ TX.prototype.isStandardInputs = function isStandardInputs(flags) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((flags & constants.flags.VERIFY_WITNESS)
|
if ((flags & constants.flags.VERIFY_WITNESS)
|
||||||
&& input.coin.isWitnessProgram()) {
|
&& input.coin.script.isWitnessProgram()) {
|
||||||
hadWitness = true;
|
hadWitness = true;
|
||||||
|
|
||||||
// Input script must be empty.
|
// Input script must be empty.
|
||||||
@ -1266,8 +1266,7 @@ TX._fromExtended = function _fromExtended(buf, saveCoins) {
|
|||||||
coin = bcoin.protocol.parser.parseCoin(coin, false);
|
coin = bcoin.protocol.parser.parseCoin(coin, false);
|
||||||
coin.hash = tx.inputs[i].prevout.hash;
|
coin.hash = tx.inputs[i].prevout.hash;
|
||||||
coin.index = tx.inputs[i].prevout.index;
|
coin.index = tx.inputs[i].prevout.index;
|
||||||
coin.coinbase = false;
|
tx.inputs[i].coin = coin;
|
||||||
tx.inputs[i].coin = new bcoin.coin(coin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user