miner: add "preverify" option.

This commit is contained in:
Christopher Jeffrey 2017-03-07 20:00:33 -08:00
parent 871225bbe4
commit d0628e990d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 26 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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