From 5dce1427bab20cd3ab7cd7608ec177475d98d0ff Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 25 Jan 2016 15:40:53 -0800 Subject: [PATCH] raw blocks. pool fixes. --- lib/bcoin/block.js | 4 +++- lib/bcoin/pool.js | 10 +++++++++- lib/bcoin/protocol/parser.js | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 92ef571d..3427b503 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -98,7 +98,7 @@ Block.prototype.hash = function hash(enc) { Block.prototype.abbr = function abbr() { if (this.network && this._raw) - return this._raw.slice(); + return this._raw.slice(0, 80); var res = new Array(80); utils.write32(res, this.version, 0); @@ -123,6 +123,8 @@ Block.verify = function verify(data, subtype) { }; Block.prototype.render = function render() { + if (this.network && this._raw && this._raw.length > 80) + return this._raw; return bcoin.protocol.framer.block(this, this.subtype); }; diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 386e245f..24db968a 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -333,6 +333,14 @@ Pool.prototype._addLoader = function _addLoader() { if (this.peers.load != null) return; + if (!this.options.headers && !this.options.multiplePeers) { + this.request = { + map: {}, + active: 0, + queue: [] + }; + } + peer = this._createPeer(750 * Math.random(), true); peer.once('socket', function() { @@ -1609,7 +1617,7 @@ Pool.prototype.usableSeed = function usableSeed(priority, connecting) { // If we have no block peers, always return // an address. if (!priority) { - if (all.length === 1) + if (all.length === 1 || connecting) return all[Math.random() * (all.length - 1) | 0]; } diff --git a/lib/bcoin/protocol/parser.js b/lib/bcoin/protocol/parser.js index c736a9a6..a8767d5b 100644 --- a/lib/bcoin/protocol/parser.js +++ b/lib/bcoin/protocol/parser.js @@ -353,7 +353,7 @@ Parser.prototype.parseBlock = function parseBlock(p) { nonce: utils.readU32(p, 76), totalTX: totalTX, txs: txs, - _raw: p.slice(0, 80), + _raw: p, _size: p.length }; };