diff --git a/etc/sample.conf b/etc/sample.conf index f9c79f2d..93c325fa 100644 --- a/etc/sample.conf +++ b/etc/sample.conf @@ -91,6 +91,7 @@ known-peers: ./known-peers coinbase-flags: mined by bcoin # payout-address: 1111111111111111111114oLvT2,1111111111111111111114oLvT2 +preverify: false max-block-weight: 4000000 reserved-block-weight: 4000 reserved-block-sigops: 400 diff --git a/lib/mining/miner.js b/lib/mining/miner.js index 2d2ba162..214e390a 100644 --- a/lib/mining/miner.js +++ b/lib/mining/miner.js @@ -322,6 +322,23 @@ Miner.prototype._createBlock = co(function* createBlock(tip, address) { Amount.btc(attempt.fees), attempt.items.length + 1); + if (this.options.preverify) { + try { + yield this.chain._verifyBlock(attempt.block); + } catch (e) { + if (e.type === 'VerifyError') { + this.logger.warning('Miner created invalid block!'); + this.logger.error(e); + throw new Error('BUG: Miner created invalid block.'); + } + throw e; + } + + this.logger.debug( + 'Preverified block %d successfully!', + attempt.height); + } + return attempt; }); @@ -512,6 +529,7 @@ function MinerOptions(options) { this.version = -1; this.addresses = []; this.coinbaseFlags = new Buffer('mined by bcoin', 'ascii'); + this.preverify = false; this.minWeight = policy.MIN_BLOCK_WEIGHT; this.maxWeight = policy.MAX_BLOCK_WEIGHT; @@ -581,6 +599,11 @@ MinerOptions.prototype.fromOptions = function fromOptions(options) { this.coinbaseFlags = flags; } + if (options.preverify != null) { + assert(typeof options.preverify === 'boolean'); + this.preverify = options.preverify; + } + if (options.minWeight != null) { assert(util.isNumber(options.minWeight)); this.minWeight = options.minWeight; diff --git a/lib/node/config.js b/lib/node/config.js index ae099111..98bcf031 100644 --- a/lib/node/config.js +++ b/lib/node/config.js @@ -283,6 +283,7 @@ config.toOptions = function toOptions(data) { // Miner options.payoutAddress = list(data.payoutaddress); options.coinbaseFlags = str(data.coinbaseflags); + options.preverify = bool(data.preverify); options.maxBlockWeight = num(data.maxblockweight); options.reservedBlockWeight = num(data.reservedblockweight); options.reservedBlockSigops = num(data.reservedblocksigops); diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index 72fb997e..b6b58418 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -121,6 +121,7 @@ function FullNode(options) { fees: this.fees, address: this.options.payoutAddress, coinbaseFlags: this.options.coinbaseFlags, + preverify: this.options.preverify, maxWeight: this.options.maxBlockWeight, reservedWeight: this.options.reservedBlockWeight, reservedSigops: this.options.reservedBlockSigops