fix miner.

This commit is contained in:
Christopher Jeffrey 2016-04-04 00:04:03 -07:00
parent 7b3b0695c3
commit 8e06d737a4
4 changed files with 16 additions and 31 deletions

View File

@ -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();
});

View File

@ -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;
};

View File

@ -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.

View File

@ -273,7 +273,7 @@ testnet.height = -1;
regtest = network.regtest = {};
regtest.type = 'testnet';
regtest.type = 'regtest';
regtest.prefixes = {
privkey: 239,