fix miner.
This commit is contained in:
parent
7b3b0695c3
commit
8e06d737a4
10
bin/node
10
bin/node
@ -22,8 +22,12 @@ node.open(function(err) {
|
|||||||
if (err)
|
if (err)
|
||||||
throw err;
|
throw err;
|
||||||
|
|
||||||
if (node.options.mine)
|
if (node.options.mine) {
|
||||||
|
if (bcoin.protocol.network.type !== 'regtest')
|
||||||
|
node.pool.connect();
|
||||||
node.miner.start();
|
node.miner.start();
|
||||||
else
|
return;
|
||||||
node.startSync();
|
}
|
||||||
|
|
||||||
|
node.startSync();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -99,29 +99,6 @@ Block.prototype.hasWitness = function hasWitness() {
|
|||||||
return false;
|
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) {
|
Block.prototype.hasTX = function hasTX(hash) {
|
||||||
return this.indexOf(hash) !== -1;
|
return this.indexOf(hash) !== -1;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,6 +8,7 @@ var bcoin = require('../bcoin');
|
|||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
|
var network = bcoin.protocol.network;
|
||||||
|
|
||||||
var bn = require('bn.js');
|
var bn = require('bn.js');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
@ -79,7 +80,10 @@ Miner.prototype._init = function _init() {
|
|||||||
this.chain.on('tip', function(tip) {
|
this.chain.on('tip', function(tip) {
|
||||||
if (!self.running)
|
if (!self.running)
|
||||||
return;
|
return;
|
||||||
self.start();
|
self.stop();
|
||||||
|
setTimeout(function() {
|
||||||
|
self.start();
|
||||||
|
}, network.type === 'regtest' ? 100 : 5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on('block', function(block) {
|
this.on('block', function(block) {
|
||||||
@ -182,7 +186,7 @@ Miner.prototype.addTX = function addTX(tx) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Add the tx to our block
|
// Add the tx to our block
|
||||||
this.block.addTX(tx);
|
this.block.txs.push(tx);
|
||||||
|
|
||||||
// Update coinbase value
|
// Update coinbase value
|
||||||
this.updateCoinbase();
|
this.updateCoinbase();
|
||||||
@ -254,12 +258,12 @@ Miner.prototype.createBlock = function createBlock(callback) {
|
|||||||
|
|
||||||
block = bcoin.block(headers);
|
block = bcoin.block(headers);
|
||||||
|
|
||||||
|
block.txs.push(coinbase);
|
||||||
|
|
||||||
block.height = self.chain.height + 1;
|
block.height = self.chain.height + 1;
|
||||||
block.target = utils.fromCompact(target).toBuffer('le', 32);
|
block.target = utils.fromCompact(target).toBuffer('le', 32);
|
||||||
block.extraNonce = new bn(0);
|
block.extraNonce = new bn(0);
|
||||||
|
|
||||||
block.addTX(coinbase);
|
|
||||||
|
|
||||||
if (self.chain.segwitActive) {
|
if (self.chain.segwitActive) {
|
||||||
// Set up the witness nonce and
|
// Set up the witness nonce and
|
||||||
// commitment output for segwit.
|
// commitment output for segwit.
|
||||||
|
|||||||
@ -273,7 +273,7 @@ testnet.height = -1;
|
|||||||
|
|
||||||
regtest = network.regtest = {};
|
regtest = network.regtest = {};
|
||||||
|
|
||||||
regtest.type = 'testnet';
|
regtest.type = 'regtest';
|
||||||
|
|
||||||
regtest.prefixes = {
|
regtest.prefixes = {
|
||||||
privkey: 239,
|
privkey: 239,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user