diff --git a/bin/node b/bin/node index 3d1b677b..8d0ac655 100755 --- a/bin/node +++ b/bin/node @@ -38,6 +38,7 @@ node.open(function(err) { if (node.network.type === 'regtest') { node.miner.start(); + node.startSync(); return; } diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 9b420ab1..35f7530a 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -95,7 +95,6 @@ function Peer(pool, options) { this.hashContinue = null; this.spvFilter = null; this.relay = true; - this.localNonce = utils.nonce(); this.feeRate = -1; this.addrFilter = new bcoin.bloom.rolling(5000, 0.001); this.invFilter = new bcoin.bloom.rolling(50000, 0.000001); @@ -252,7 +251,7 @@ Peer.prototype._init = function init() { this.write(this.framer.version({ height: this.chain.height, relay: this.options.relay, - nonce: this.localNonce + nonce: this.pool.localNonce })); }; @@ -975,10 +974,12 @@ Peer.prototype._handleVersion = function handleVersion(payload) { var version = payload.version; var services = payload.services; - if (payload.nonce.cmp(this.localNonce) === 0) { - this._error('We connected to ourself. Oops.'); - this.setMisbehavior(100); - return; + if (this.network.type !== 'regtest') { + if (payload.nonce.cmp(this.pool.localNonce) === 0) { + this._error('We connected to ourself. Oops.'); + this.setMisbehavior(100); + return; + } } if (version < constants.MIN_VERSION) { @@ -1128,6 +1129,11 @@ Peer.prototype._handleGetData = function handleGetData(items) { return next(); } + if (tx.isCoinbase()) { + notfound.push({ type: constants.inv.TX, hash: hash }); + return next(); + } + data = witness ? self.framer.witnessTX(tx) : self.framer.tx(tx); @@ -1345,9 +1351,12 @@ Peer.prototype._handleGetAddr = function handleGetAddr() { break; } + if (items.length === 0) + return; + bcoin.debug( 'Sending %d addrs to peer (%s)', - addrs.length, + items.length, this.hostname); return this.write(this.framer.addr(items)); diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index aabf71c2..0750bbd4 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -138,6 +138,8 @@ function Pool(options) { ? bcoin.bloom.fromRate(10000, 0.01, constants.bloom.NONE) : null; + this.localNonce = utils.nonce(); + this.peers = { // Peers that are loading blocks themselves regular: [], @@ -2328,7 +2330,7 @@ BroadcastItem.prototype.finish = function finish(err) { BroadcastItem.prototype.send = function send(peer, witness) { var self = this; - var i, data; + var data; if (!this.msg) { this.ack(peer); @@ -2336,6 +2338,11 @@ BroadcastItem.prototype.send = function send(peer, witness) { } if (this.type === constants.inv.TX) { + if (this.msg.isCoinbase()) { + peer.write(peer.framer.notFound([this])); + return true; + } + data = witness ? peer.framer.witnessTX(this.msg) : peer.framer.tx(this.msg); @@ -2345,7 +2352,7 @@ BroadcastItem.prototype.send = function send(peer, witness) { : peer.framer.block(this.msg); } - peer.write(value); + peer.write(data); this.ack(peer); @@ -2359,6 +2366,7 @@ BroadcastItem.prototype.send = function send(peer, witness) { BroadcastItem.prototype.ack = function ack(peer) { var self = this; + var i; setTimeout(function() { self.emit('ack', peer); @@ -2395,7 +2403,7 @@ BroadcastItem.prototype.reject = function reject(peer) { BroadcastItem.prototype.inspect = function inspect() { return ''; }; diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index a7f56969..65f520ba 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -2255,7 +2255,8 @@ Script.createCommitment = function createCommitment(hash) { p.writeHash(hash); return new Script([ opcodes.OP_RETURN, - p.render() + p.render(), + new Buffer('mined by bcoin', 'ascii') ]); }; diff --git a/lib/bcoin/workers.js b/lib/bcoin/workers.js index c3785201..a0be3cdc 100644 --- a/lib/bcoin/workers.js +++ b/lib/bcoin/workers.js @@ -314,6 +314,10 @@ function Worker(pool, id) { self.emit('error', err); }); + this.child.stdout.on('data', function(data) { + self.emit('data', data); + }); + this.child.stderr.setEncoding('utf8'); this.child.stderr.on('data', function(data) { bcoin.debug(data.trim()); @@ -573,6 +577,9 @@ Master.prototype.debug = function debug() { */ Master.prototype.error = function error(err) { + if (!err) + return; + this.debug(err.message); };