From 8e06d737a4c02e9ee5914b2ddce1511535c8864c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 4 Apr 2016 00:04:03 -0700 Subject: [PATCH] fix miner. --- bin/node | 10 +++++++--- lib/bcoin/block.js | 23 ----------------------- lib/bcoin/miner.js | 12 ++++++++---- lib/bcoin/protocol/network.js | 2 +- 4 files changed, 16 insertions(+), 31 deletions(-) diff --git a/bin/node b/bin/node index 2200d37c..f3ce7c3f 100755 --- a/bin/node +++ b/bin/node @@ -22,8 +22,12 @@ node.open(function(err) { if (err) throw err; - if (node.options.mine) + if (node.options.mine) { + if (bcoin.protocol.network.type !== 'regtest') + node.pool.connect(); node.miner.start(); - else - node.startSync(); + return; + } + + node.startSync(); }); diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index ca23aea2..8e82aa34 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -99,29 +99,6 @@ Block.prototype.hasWitness = function hasWitness() { return false; }; -Block.prototype.addTX = function addTX(tx) { - var hash = tx.hash('hex'); - var index; - - if (this.indexOf(hash) !== -1) - return; - - index = this.txs.push(tx) - 1; - - tx.setBlock(this, index); -}; - -Block.prototype.removeTX = function removeTX(hash) { - var index = this.indexOf(hash); - var tx; - - if (index === -1) - return; - - tx = this.txs.splice(index, 1)[0]; - tx.unsetBlock(); -}; - Block.prototype.hasTX = function hasTX(hash) { return this.indexOf(hash) !== -1; }; diff --git a/lib/bcoin/miner.js b/lib/bcoin/miner.js index 8e1fbdd5..a2b99f3b 100644 --- a/lib/bcoin/miner.js +++ b/lib/bcoin/miner.js @@ -8,6 +8,7 @@ var bcoin = require('../bcoin'); var utils = require('./utils'); var assert = utils.assert; var constants = bcoin.protocol.constants; +var network = bcoin.protocol.network; var bn = require('bn.js'); var EventEmitter = require('events').EventEmitter; @@ -79,7 +80,10 @@ Miner.prototype._init = function _init() { this.chain.on('tip', function(tip) { if (!self.running) return; - self.start(); + self.stop(); + setTimeout(function() { + self.start(); + }, network.type === 'regtest' ? 100 : 5000); }); this.on('block', function(block) { @@ -182,7 +186,7 @@ Miner.prototype.addTX = function addTX(tx) { return false; // Add the tx to our block - this.block.addTX(tx); + this.block.txs.push(tx); // Update coinbase value this.updateCoinbase(); @@ -254,12 +258,12 @@ Miner.prototype.createBlock = function createBlock(callback) { block = bcoin.block(headers); + block.txs.push(coinbase); + block.height = self.chain.height + 1; block.target = utils.fromCompact(target).toBuffer('le', 32); block.extraNonce = new bn(0); - block.addTX(coinbase); - if (self.chain.segwitActive) { // Set up the witness nonce and // commitment output for segwit. diff --git a/lib/bcoin/protocol/network.js b/lib/bcoin/protocol/network.js index ef1f9b0c..f6bb99c2 100644 --- a/lib/bcoin/protocol/network.js +++ b/lib/bcoin/protocol/network.js @@ -273,7 +273,7 @@ testnet.height = -1; regtest = network.regtest = {}; -regtest.type = 'testnet'; +regtest.type = 'regtest'; regtest.prefixes = { privkey: 239,