miner: share lock with chain.

This commit is contained in:
Christopher Jeffrey 2017-01-20 15:19:58 -08:00
parent f8c82197a4
commit 170d9a1416
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

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