diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 76cb41f0..73c863a5 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -627,6 +627,9 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac utils.debug('Block is using spent inputs: %s (tx: %s, output: %s)', block.rhash, tx.rhash, input.prevout.rhash + '/' + input.prevout.index); + throw new Error('Spent inputs: ' + + utils._inspect(input, false) + + JSON.stringify(input, null, 2)); return callback(null, false); } @@ -634,6 +637,15 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac if (!tx.verify(j, true, flags)) { utils.debug('Block has invalid inputs: %s (%s/%d)', block.rhash, tx.rhash, j); + utils.debug('Signature Hash: %s', utils.toHex(tx.signatureHash(j, input.output.script, 'all'))); + utils.debug(input); + utils.debug('raw: %s', utils.toHex(input.output.script._raw || [])); + utils.debug('encoded: %s', utils.toHex(bcoin.script.encode(input.output.script))); + throw new Error('Bad inputs: ' + + utils._inspect(input, false) + + JSON.stringify(input, null, 2) + + '\n' + + utils.toHex(tx.signatureHash(j, input.output.script, 'all'))); return callback(null, false); } } @@ -1005,6 +1017,7 @@ Chain.prototype.add = function add(initial, peer, callback) { self.orphan.bmap = {}; self.orphan.count = 0; self.orphan.size = 0; + utils.debug('Warning: 20mb of orphans cleared!'); } if (code !== Chain.codes.okay) { diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 8935359e..a3b763ab 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -709,9 +709,6 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) { if (err) return done(err); - if (added) - self.emit('pool block', block, peer); - // Resolve orphan chain. self.peers.load.loadBlocks( self.chain.getLocator(), @@ -744,10 +741,8 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) { if (err) return done(err); - if (added) { - self.emit('pool block', block, peer); + if (added) return done(null, true); - } return done(null, false); }); @@ -765,11 +760,6 @@ Pool.prototype._addIndex = function _addIndex(block, peer, callback) { self.emit('chain-progress', self.chain.fillPercent(), peer); - // if (peer._requesting && peer._requesting.hash === block.hash('hex')) { - // delete peer._requesting; - // self._nextBlock(peer); - // } - if (added > 0 && peer._requesting) delete peer._requesting; @@ -1563,10 +1553,10 @@ Pool.prototype._request = function _request(peer, type, hash, options, cb) { // Block should be not in chain, or be requested // Do not use with headers-first - if (!options.force && (type === 'block' || type === 'filtered')) { - if (this.chain.has(hash)) - return; - } + // if (!options.force && (type === 'block' || type === 'filtered')) { + // if (this.chain.has(hash)) + // return; + // } item = new LoadRequest(this, peer, type, hash, cb); @@ -1629,7 +1619,7 @@ Pool.prototype._nextBlock = function _nextBlock(peer) { utils.debug( 'Requesting block %s (%d/%d) from %s with getdata (height %d)', - utils.revHex(item[0].hash), + utils.revHex(item[item.length - 1].hash), peer._blockQueue.length, this.request.active, peer.host,