miner: workers and mining fixes.
This commit is contained in:
parent
5186435f8f
commit
e3a6d7f35e
@ -1921,20 +1921,20 @@ RPC.prototype.getgenerate = function getgenerate(args) {
|
||||
return Promise.resolve(this.mining);
|
||||
};
|
||||
|
||||
RPC.prototype.setgenerate = function setgenerate(args) {
|
||||
RPC.prototype.setgenerate = co(function* setgenerate(args) {
|
||||
if (args.help || args.length < 1 || args.length > 2)
|
||||
return Promise.reject(new RPCError('setgenerate mine ( proclimit )'));
|
||||
throw new RPCError('setgenerate mine ( proclimit )');
|
||||
|
||||
this.mining = toBool(args[0]);
|
||||
this.proclimit = toNumber(args[1], 0);
|
||||
|
||||
if (this.mining)
|
||||
this.miner.start();
|
||||
this.miner.start().catch(utils.nop);
|
||||
else
|
||||
this.miner.stop();
|
||||
yield this.miner.stop();
|
||||
|
||||
return Promise.resolve(this.mining);
|
||||
};
|
||||
return this.mining;
|
||||
});
|
||||
|
||||
RPC.prototype.generate = co(function* generate(args) {
|
||||
var unlock = yield this.locker.lock();
|
||||
@ -2665,17 +2665,17 @@ RPC.prototype.reconsiderblock = function reconsiderblock(args) {
|
||||
};
|
||||
|
||||
RPC.prototype.setmocktime = function setmocktime(args) {
|
||||
var time, delta;
|
||||
var ts, delta;
|
||||
|
||||
if (args.help || args.length !== 1)
|
||||
return Promise.reject(new RPCError('setmocktime timestamp'));
|
||||
|
||||
time = toNumber(args[0]);
|
||||
ts = toNumber(args[0]);
|
||||
|
||||
if (time < 0)
|
||||
if (ts < 0)
|
||||
return Promise.reject(new RPCError('Invalid parameter.'));
|
||||
|
||||
delta = time.now() - time;
|
||||
delta = time.now() - ts;
|
||||
time.offset = -delta;
|
||||
|
||||
return Promise.resolve();
|
||||
|
||||
@ -64,6 +64,14 @@ utils.inherits(Miner, AsyncObject);
|
||||
Miner.prototype._init = function _init() {
|
||||
var self = this;
|
||||
|
||||
this.chain.on('tip', function(tip) {
|
||||
if (!self.attempt)
|
||||
return;
|
||||
|
||||
if (self.attempt.block.prevBlock !== tip.hash)
|
||||
self.attempt.destroy();
|
||||
});
|
||||
|
||||
this.on('block', function(block) {
|
||||
// Emit the block hex as a failsafe (in case we can't send it)
|
||||
self.logger.info('Found block: %d (%s).', block.height, block.rhash);
|
||||
|
||||
@ -871,19 +871,19 @@ if (utils.isBrowser) {
|
||||
}
|
||||
|
||||
exports.set = function set(options) {
|
||||
if (typeof options.useWorkerPool === 'boolean')
|
||||
this.pool.enabled = options.useWorkerPool;
|
||||
if (typeof options.useWorkers === 'boolean')
|
||||
this.pool.enabled = options.useWorkers;
|
||||
|
||||
if (utils.isNumber(options.maxWorkerPool))
|
||||
this.pool.size = options.maxWorkerPool;
|
||||
if (utils.isNumber(options.maxWorkers))
|
||||
this.pool.size = options.maxWorkers;
|
||||
|
||||
if (utils.isNumber(options.workerTimeout))
|
||||
this.pool.timeout = options.workerTimeout;
|
||||
};
|
||||
|
||||
exports.set({
|
||||
useWorkerPool: +process.env.BCOIN_USE_WORKERS === 1,
|
||||
maxWorkerPool: +process.env.BCOIN_MAX_WORKERS,
|
||||
useWorkers: +process.env.BCOIN_USE_WORKERS === 1,
|
||||
maxWorkers: +process.env.BCOIN_MAX_WORKERS,
|
||||
workerTimeout: +process.env.BCOIN_WORKER_TIMEOUT
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user