diff --git a/lib/mining/miner.js b/lib/mining/miner.js index 8d1fb8f8..20e74406 100644 --- a/lib/mining/miner.js +++ b/lib/mining/miner.js @@ -45,6 +45,8 @@ function Miner(options) { this.mempool = this.options.mempool; this.addresses = this.options.addresses; + this.locker = this.chain.locker; + this.running = false; this.stopping = false; this.attempt = null; @@ -239,6 +241,21 @@ Miner.prototype._onStop = function _onStop() { */ Miner.prototype.createBlock = co(function* createBlock(tip, address) { + var unlock = yield this.locker.lock(); + try { + return yield this._createBlock(tip, address); + } finally { + unlock(); + } +}); + +/** + * Create a block "attempt" (without a lock). + * @param {ChainEntry} tip + * @returns {Promise} - Returns {@link MinerBlock}. + */ + +Miner.prototype._createBlock = co(function* createBlock(tip, address) { var version = this.options.version; var ts, locktime, target, attempt;