fix sigops counting.
This commit is contained in:
parent
ff467afaff
commit
4b672d6337
@ -412,8 +412,10 @@ Chain.prototype._removeBlock = function _removeBlock(tip, callback) {
|
||||
if (self.mempool)
|
||||
self.mempool.removeBlock(block);
|
||||
|
||||
self.emit('remove block', block.hash('hex'));
|
||||
|
||||
block.txs.forEach(function(tx) {
|
||||
self.emit('remove', tx.hash('hex'), block.hash('hex'));
|
||||
self.emit('remove tx', tx.hash('hex'));
|
||||
});
|
||||
|
||||
return callback();
|
||||
@ -473,7 +475,7 @@ Chain.prototype._verify = function _verify(block, prev) {
|
||||
}
|
||||
|
||||
// Ensure the miner's target is equal to what we expect
|
||||
if (block.bits !== block.chain.getTarget(prev, block)) {
|
||||
if (block.bits !== this.getTarget(prev, block)) {
|
||||
utils.debug('Block is using wrong target: %s', block.rhash);
|
||||
return false;
|
||||
}
|
||||
@ -561,17 +563,6 @@ Chain.prototype._verify = function _verify(block, prev) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for tx sigops limits
|
||||
// Bitcoind does not check for this when accepting
|
||||
// a block even though it probably should.
|
||||
// if (tx.getSigops(true) > constants.script.maxTxSigops) {
|
||||
// // Block 71036 abused checksig to
|
||||
// // include a huge number of sigops.
|
||||
// utils.debug('Block TX has too many sigops: %s', block.rhash);
|
||||
// if (!(network.type === 'main' && height === 71036))
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// Check for block sigops limits
|
||||
// Start counting P2SH sigops once block
|
||||
// timestamps reach March 31st, 2012.
|
||||
|
||||
@ -1615,12 +1615,15 @@ script.getUnknownData = function getUnknownData(s) {
|
||||
};
|
||||
|
||||
script.getInputKeys = function getInputKeys(s, prev) {
|
||||
if (prev) {
|
||||
if (script.isScripthash(prev))
|
||||
return script.getOutputKeys(script.getRedeem(s));
|
||||
return script.getOutputKeys(prev);
|
||||
}
|
||||
|
||||
if (script.isScripthashInput(s))
|
||||
return script.getOutputKeys(script.getRedeem(s));
|
||||
|
||||
if (prev)
|
||||
return script.getOutputKeys(prev);
|
||||
|
||||
if (script.isPubkeyhashInput(s))
|
||||
return [s[1]];
|
||||
|
||||
@ -1638,12 +1641,15 @@ script.getOutputKeys = function getOutputKeys(s) {
|
||||
};
|
||||
|
||||
script.getInputKeyHashes = function getInputKeyHashes(s, prev) {
|
||||
if (prev) {
|
||||
if (script.isScripthash(prev))
|
||||
return script.getOutputKeyHashes(script.getRedeem(s));
|
||||
return script.getOuputKeyHashes(prev);
|
||||
}
|
||||
|
||||
if (script.isScripthashInput(s))
|
||||
return script.getOutputKeyHashes(script.getRedeem(s));
|
||||
|
||||
if (prev)
|
||||
return script.getOuputKeyHashes(prev);
|
||||
|
||||
if (script.isPubkeyhashInput(s))
|
||||
return [bcoin.address.hash160(s[1])];
|
||||
|
||||
@ -1715,12 +1721,15 @@ script.getOutputAddress = function getOutputAddress(s) {
|
||||
};
|
||||
|
||||
script.getInputMN = function getInputMN(s, prev) {
|
||||
if (prev) {
|
||||
if (script.isScripthash(prev))
|
||||
return script.getOutputMN(script.getRedeem(s));
|
||||
return script.getOuputMN(prev);
|
||||
}
|
||||
|
||||
if (script.isScripthashInput(s))
|
||||
return script.getOutputMN(script.getRedeem(s));
|
||||
|
||||
if (prev)
|
||||
return script.getOuputMN(prev);
|
||||
|
||||
return { m: 1, n: 1 };
|
||||
};
|
||||
|
||||
@ -1747,7 +1756,7 @@ script.isPubkey = function isPubkey(s, key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return s[0];
|
||||
return true;
|
||||
};
|
||||
|
||||
script.isPubkeyhash = function isPubkeyhash(s, hash) {
|
||||
@ -1770,7 +1779,7 @@ script.isPubkeyhash = function isPubkeyhash(s, hash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return s[2];
|
||||
return true;
|
||||
};
|
||||
|
||||
script.isMultisig = function isMultisig(s, keys) {
|
||||
@ -1836,11 +1845,7 @@ script.isMultisig = function isMultisig(s, keys) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
keys: s.slice(1, n + 1),
|
||||
m: m,
|
||||
n: n
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
script.isScripthash = function isScripthash(s, hash) {
|
||||
@ -1861,7 +1866,7 @@ script.isScripthash = function isScripthash(s, hash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return s[1];
|
||||
return true;
|
||||
};
|
||||
|
||||
script.isNulldata = function isNulldata(s) {
|
||||
@ -1875,7 +1880,7 @@ script.isNulldata = function isNulldata(s) {
|
||||
if (!res)
|
||||
return false;
|
||||
|
||||
return s[1];
|
||||
return true;
|
||||
};
|
||||
|
||||
script.getInputType = function getInputType(s, prev) {
|
||||
@ -1906,7 +1911,7 @@ script.isPubkeyInput = function isPubkeyInput(s, key, tx, i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return s[0];
|
||||
return true;
|
||||
};
|
||||
|
||||
script.isPubkeyhashInput = function isPubkeyhashInput(s, key) {
|
||||
@ -1924,7 +1929,7 @@ script.isPubkeyhashInput = function isPubkeyhashInput(s, key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return s[1];
|
||||
return true;
|
||||
};
|
||||
|
||||
script.isMultisigInput = function isMultisigInput(s, keys, tx, i) {
|
||||
@ -1970,10 +1975,7 @@ script.isMultisigInput = function isMultisigInput(s, keys, tx, i) {
|
||||
// recovered.push(key);
|
||||
// }
|
||||
|
||||
return {
|
||||
signatures: s.slice(1),
|
||||
m: s.length - 1
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
script.isScripthashInput = function isScripthashInput(s, data, strict) {
|
||||
@ -2011,12 +2013,12 @@ script.isScripthashInput = function isScripthashInput(s, data, strict) {
|
||||
// Check data against last array in case
|
||||
// a raw redeem script was passed in.
|
||||
if (data && utils.isEqual(data, raw))
|
||||
return raw;
|
||||
return true;
|
||||
|
||||
// Return here if we do not want to check
|
||||
// against standard transaction types.
|
||||
if (!strict)
|
||||
return raw;
|
||||
return true;
|
||||
|
||||
// P2SH redeem scripts can be nonstandard: make
|
||||
// it easier for other functions to parse this.
|
||||
@ -2039,7 +2041,7 @@ script.isScripthashInput = function isScripthashInput(s, data, strict) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return raw;
|
||||
return true;
|
||||
};
|
||||
|
||||
script.getCoinbaseData = function getCoinbaseData(s) {
|
||||
@ -2391,9 +2393,14 @@ script.getSigops = function getSigops(s, accurate) {
|
||||
return n;
|
||||
};
|
||||
|
||||
script.getScripthashSigops = function getScripthashSigops(s) {
|
||||
if (!script.isScripthashInput(s))
|
||||
return 0;
|
||||
script.getScripthashSigops = function getScripthashSigops(s, prev) {
|
||||
if (prev) {
|
||||
if (!script.isScripthash(prev))
|
||||
return 0;
|
||||
} else {
|
||||
if (!script.isScripthashInput(s))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!script.isPushOnly(s))
|
||||
return 0;
|
||||
|
||||
@ -1523,9 +1523,12 @@ TX.prototype.isFinal = function isFinal(height, ts) {
|
||||
TX.prototype.getSigops = function getSigops(scriptHash, accurate) {
|
||||
var n = 0;
|
||||
this.inputs.forEach(function(input) {
|
||||
var prev;
|
||||
n += bcoin.script.getSigops(input.script, accurate);
|
||||
if (scriptHash && !this.isCoinbase())
|
||||
n += bcoin.script.getScripthashSigops(input.script);
|
||||
if (scriptHash && !this.isCoinbase()) {
|
||||
prev = input.output ? input.output.script : null;
|
||||
n += bcoin.script.getScripthashSigops(input.script, prev);
|
||||
}
|
||||
}, this);
|
||||
this.outputs.forEach(function(output) {
|
||||
n += bcoin.script.getSigops(output.script, accurate);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user