block/tx: sigops cost/size/weight.
This commit is contained in:
parent
f9a1e18437
commit
33a8e1e511
@ -653,9 +653,9 @@ Chain.prototype.verifyInputs = co(function* verifyInputs(block, prev, state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count sigops (legacy + scripthash? + witness?)
|
// Count sigops (legacy + scripthash? + witness?)
|
||||||
sigops += tx.getSigopsWeight(view, state.flags);
|
sigops += tx.getSigopsCost(view, state.flags);
|
||||||
|
|
||||||
if (sigops > constants.block.MAX_SIGOPS_WEIGHT) {
|
if (sigops > constants.block.MAX_SIGOPS_COST) {
|
||||||
throw new VerifyError(block,
|
throw new VerifyError(block,
|
||||||
'invalid',
|
'invalid',
|
||||||
'bad-blk-sigops',
|
'bad-blk-sigops',
|
||||||
|
|||||||
@ -1548,6 +1548,7 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) {
|
|||||||
var vbrules = [];
|
var vbrules = [];
|
||||||
var attempt = yield this._getAttempt(false);
|
var attempt = yield this._getAttempt(false);
|
||||||
var block = attempt.block;
|
var block = attempt.block;
|
||||||
|
var scale = attempt.witness ? 1 : constants.WITNESS_SCALE_FACTOR;
|
||||||
var i, j, entry, tx, deps, input, dep, output, raw, rwhash;
|
var i, j, entry, tx, deps, input, dep, output, raw, rwhash;
|
||||||
var template, name, deployment, state;
|
var template, name, deployment, state;
|
||||||
|
|
||||||
@ -1576,7 +1577,7 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) {
|
|||||||
hash: tx.rwhash(),
|
hash: tx.rwhash(),
|
||||||
depends: deps,
|
depends: deps,
|
||||||
fee: entry.fee,
|
fee: entry.fee,
|
||||||
sigops: entry.sigops,
|
sigops: entry.sigops / scale | 0,
|
||||||
weight: tx.getWeight()
|
weight: tx.getWeight()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1629,10 +1630,8 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) {
|
|||||||
maxtime: this.network.now() + 2 * 60 * 60,
|
maxtime: this.network.now() + 2 * 60 * 60,
|
||||||
mutable: mutable,
|
mutable: mutable,
|
||||||
noncerange: '00000000ffffffff',
|
noncerange: '00000000ffffffff',
|
||||||
sigoplimit: attempt.witness
|
sigoplimit: constants.block.MAX_SIGOPS_COST / scale | 0,
|
||||||
? constants.block.MAX_SIGOPS_WEIGHT
|
sizelimit: constants.block.MAX_RAW_SIZE,
|
||||||
: constants.block.MAX_SIGOPS,
|
|
||||||
sizelimit: constants.block.MAX_SIZE,
|
|
||||||
weightlimit: constants.block.MAX_WEIGHT,
|
weightlimit: constants.block.MAX_WEIGHT,
|
||||||
curtime: block.ts,
|
curtime: block.ts,
|
||||||
bits: util.hex32(block.bits),
|
bits: util.hex32(block.bits),
|
||||||
@ -1661,7 +1660,7 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) {
|
|||||||
hash: rwhash,
|
hash: rwhash,
|
||||||
depends: [],
|
depends: [],
|
||||||
fee: 0,
|
fee: 0,
|
||||||
sigops: tx.getSigopsWeight(),
|
sigops: tx.getSigopsCost() / scale | 0,
|
||||||
weight: tx.getWeight()
|
weight: tx.getWeight()
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -552,6 +552,8 @@ HTTPServer.prototype._init = function _init() {
|
|||||||
req.body.method = 'getworklp';
|
req.body.method = 'getworklp';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.info(req.body);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json = yield this.rpc.execute(req.body);
|
json = yield this.rpc.execute(req.body);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -902,7 +902,7 @@ Mempool.prototype.verify = co(function* verify(entry, view) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Annoying process known as sigops counting.
|
// Annoying process known as sigops counting.
|
||||||
if (tx.getSigopsWeight(view, flags) > constants.tx.MAX_SIGOPS_WEIGHT) {
|
if (tx.getSigopsCost(view, flags) > constants.tx.MAX_SIGOPS_COST) {
|
||||||
throw new VerifyError(tx,
|
throw new VerifyError(tx,
|
||||||
'nonstandard',
|
'nonstandard',
|
||||||
'bad-txns-too-many-sigops',
|
'bad-txns-too-many-sigops',
|
||||||
|
|||||||
@ -84,7 +84,7 @@ MempoolEntry.fromOptions = function fromOptions(options) {
|
|||||||
MempoolEntry.prototype.fromTX = function fromTX(tx, view, height) {
|
MempoolEntry.prototype.fromTX = function fromTX(tx, view, height) {
|
||||||
var priority = tx.getPriority(view, height);
|
var priority = tx.getPriority(view, height);
|
||||||
var value = tx.getChainValue(view, height);
|
var value = tx.getChainValue(view, height);
|
||||||
var sigops = tx.getSigopsWeight(view);
|
var sigops = tx.getSigopsCost(view);
|
||||||
var dependencies = false;
|
var dependencies = false;
|
||||||
var size = tx.getVirtualSize();
|
var size = tx.getVirtualSize();
|
||||||
var fee = tx.getFee(view);
|
var fee = tx.getFee(view);
|
||||||
|
|||||||
@ -54,7 +54,7 @@ function Miner(options) {
|
|||||||
|
|
||||||
this.minWeight = 0;
|
this.minWeight = 0;
|
||||||
this.maxWeight = 750000 * constants.WITNESS_SCALE_FACTOR;
|
this.maxWeight = 750000 * constants.WITNESS_SCALE_FACTOR;
|
||||||
this.maxSigops = constants.block.MAX_SIGOPS_WEIGHT;
|
this.maxSigops = constants.block.MAX_SIGOPS_COST;
|
||||||
this.priorityWeight = 50000 * constants.WITNESS_SCALE_FACTOR;
|
this.priorityWeight = 50000 * constants.WITNESS_SCALE_FACTOR;
|
||||||
this.minPriority = constants.tx.FREE_THRESHOLD;
|
this.minPriority = constants.tx.FREE_THRESHOLD;
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ Miner.prototype._initOptions = function _initOptions(options) {
|
|||||||
|
|
||||||
if (options.maxSigops != null) {
|
if (options.maxSigops != null) {
|
||||||
assert(util.isNumber(options.maxSigops));
|
assert(util.isNumber(options.maxSigops));
|
||||||
assert(options.maxSigops <= constants.block.MAX_SIGOPS_WEIGHT);
|
assert(options.maxSigops <= constants.block.MAX_SIGOPS_COST);
|
||||||
this.maxSigops = options.maxSigops;
|
this.maxSigops = options.maxSigops;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,7 +462,7 @@ Miner.prototype.build = function build(attempt) {
|
|||||||
sigops += item.sigops;
|
sigops += item.sigops;
|
||||||
|
|
||||||
// If we had a view we could do:
|
// If we had a view we could do:
|
||||||
// sigops += tx.getSigopsWeight(view, attempt.flags);
|
// sigops += tx.getSigopsCost(view, attempt.flags);
|
||||||
|
|
||||||
if (sigops > this.maxSigops)
|
if (sigops > this.maxSigops)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -190,7 +190,7 @@ MinerBlock.prototype._init = function _init() {
|
|||||||
this.weight += 8 * scale;
|
this.weight += 8 * scale;
|
||||||
|
|
||||||
// Initialize sigops weight.
|
// Initialize sigops weight.
|
||||||
this.sigops = cb.getSigopsWeight(null, this.flags);
|
this.sigops = cb.getSigopsCost(null, this.flags);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -288,7 +288,7 @@ MinerBlock.prototype.addTX = function addTX(tx, view) {
|
|||||||
if (this.weight + weight > constants.block.MAX_WEIGHT)
|
if (this.weight + weight > constants.block.MAX_WEIGHT)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (this.sigops + sigops > constants.block.MAX_SIGOPS_WEIGHT)
|
if (this.sigops + sigops > constants.block.MAX_SIGOPS_COST)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!this.witness && tx.hasWitness())
|
if (!this.witness && tx.hasWitness())
|
||||||
@ -522,7 +522,7 @@ BlockEntry.fromTX = function fromTX(tx, view, attempt) {
|
|||||||
entry.rate = tx.getRate(view);
|
entry.rate = tx.getRate(view);
|
||||||
entry.priority = tx.getPriority(view, attempt.height);
|
entry.priority = tx.getPriority(view, attempt.height);
|
||||||
entry.free = false;
|
entry.free = false;
|
||||||
entry.sigops = tx.getSigopsWeight(view, attempt.flags);
|
entry.sigops = tx.getSigopsCost(view, attempt.flags);
|
||||||
return entry;
|
return entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -484,7 +484,7 @@ Block.prototype._verify = function _verify(ret) {
|
|||||||
|
|
||||||
// Count legacy sigops (do not count scripthash or witness).
|
// Count legacy sigops (do not count scripthash or witness).
|
||||||
sigops += tx.getLegacySigops();
|
sigops += tx.getLegacySigops();
|
||||||
if (sigops * scale > constants.block.MAX_SIGOPS_WEIGHT) {
|
if (sigops * scale > constants.block.MAX_SIGOPS_COST) {
|
||||||
ret.reason = 'bad-blk-sigops';
|
ret.reason = 'bad-blk-sigops';
|
||||||
ret.score = 100;
|
ret.score = 100;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -1177,7 +1177,7 @@ TX.prototype.getScripthashSigops = function getScripthashSigops(view) {
|
|||||||
* @returns {Number} sigop weight
|
* @returns {Number} sigop weight
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TX.prototype.getSigopsWeight = function getSigopsWeight(view, flags) {
|
TX.prototype.getSigopsCost = function getSigopsCost(view, flags) {
|
||||||
var weight = this.getLegacySigops() * constants.WITNESS_SCALE_FACTOR;
|
var weight = this.getLegacySigops() * constants.WITNESS_SCALE_FACTOR;
|
||||||
var i, input, coin;
|
var i, input, coin;
|
||||||
|
|
||||||
@ -1220,7 +1220,7 @@ TX.prototype.getSigops = function getSigops(view, flags) {
|
|||||||
if (flags == null)
|
if (flags == null)
|
||||||
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
||||||
|
|
||||||
return (this.getSigopsWeight(view, flags) + scale - 1) / scale | 0;
|
return (this.getSigopsCost(view, flags) + scale - 1) / scale | 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -385,9 +385,10 @@ exports.WITNESS_SCALE_FACTOR = 4;
|
|||||||
|
|
||||||
exports.block = {
|
exports.block = {
|
||||||
MAX_SIZE: 1000000,
|
MAX_SIZE: 1000000,
|
||||||
|
MAX_RAW_SIZE: 4000000,
|
||||||
MAX_WEIGHT: 4000000,
|
MAX_WEIGHT: 4000000,
|
||||||
MAX_SIGOPS: 1000000 / 50,
|
MAX_SIGOPS: 1000000 / 50,
|
||||||
MAX_SIGOPS_WEIGHT: 80000,
|
MAX_SIGOPS_COST: 80000,
|
||||||
MEDIAN_TIMESPAN: 11,
|
MEDIAN_TIMESPAN: 11,
|
||||||
BIP16_TIME: 1333238400,
|
BIP16_TIME: 1333238400,
|
||||||
SIGHASH_LIMIT: 1300000000
|
SIGHASH_LIMIT: 1300000000
|
||||||
@ -421,7 +422,7 @@ exports.tx = {
|
|||||||
BARE_MULTISIG: true,
|
BARE_MULTISIG: true,
|
||||||
FREE_THRESHOLD: exports.COIN * 144 / 250,
|
FREE_THRESHOLD: exports.COIN * 144 / 250,
|
||||||
MAX_SIGOPS: exports.block.MAX_SIGOPS / 5,
|
MAX_SIGOPS: exports.block.MAX_SIGOPS / 5,
|
||||||
MAX_SIGOPS_WEIGHT: exports.block.MAX_SIGOPS_WEIGHT / 5,
|
MAX_SIGOPS_COST: exports.block.MAX_SIGOPS_COST / 5,
|
||||||
BYTES_PER_SIGOP: 20,
|
BYTES_PER_SIGOP: 20,
|
||||||
COINBASE_MATURITY: 100
|
COINBASE_MATURITY: 100
|
||||||
};
|
};
|
||||||
|
|||||||
@ -180,7 +180,7 @@ describe('Block', function() {
|
|||||||
assert(tx.checkInputs(view, height));
|
assert(tx.checkInputs(view, height));
|
||||||
assert(tx.verify(view, flags));
|
assert(tx.verify(view, flags));
|
||||||
assert(!tx.hasWitness());
|
assert(!tx.hasWitness());
|
||||||
sigops += tx.getSigopsWeight(view, flags);
|
sigops += tx.getSigopsCost(view, flags);
|
||||||
view.addTX(tx, height);
|
view.addTX(tx, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user