miner: share lock with chain.
This commit is contained in:
parent
f8c82197a4
commit
170d9a1416
@ -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;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user