chain: earlier sanity checks.
This commit is contained in:
parent
1ca3738699
commit
22830cf6f3
@ -347,12 +347,26 @@ class Chain extends AsyncEmitter {
|
||||
if (this.options.spv)
|
||||
return this.state;
|
||||
|
||||
// Check merkle root.
|
||||
if (flags & common.flags.VERIFY_BODY) {
|
||||
assert(typeof block.createMerkleRoot === 'function');
|
||||
|
||||
const root = block.createMerkleRoot('hex');
|
||||
|
||||
if (!root || block.merkleRoot !== root) {
|
||||
throw new VerifyError(block,
|
||||
'invalid',
|
||||
'bad-txnmrklroot',
|
||||
100);
|
||||
}
|
||||
|
||||
flags &= ~common.flags.VERIFY_BODY;
|
||||
}
|
||||
|
||||
// Once segwit is active, we will still
|
||||
// need to check for block mutability.
|
||||
if (!block.hasWitness() && !block.getCommitmentHash())
|
||||
return new DeploymentState();
|
||||
|
||||
flags &= ~common.flags.VERIFY_BODY;
|
||||
}
|
||||
|
||||
// Non-contextual checks.
|
||||
|
||||
@ -416,17 +416,6 @@ class Block extends AbstractBlock {
|
||||
*/
|
||||
|
||||
checkBody() {
|
||||
// Check merkle root.
|
||||
const root = this.createMerkleRoot('hex');
|
||||
|
||||
// If the merkle is mutated,
|
||||
// we have duplicate txs.
|
||||
if (!root)
|
||||
return [false, 'bad-txns-duplicate', 100];
|
||||
|
||||
if (this.merkleRoot !== root)
|
||||
return [false, 'bad-txnmrklroot', 100];
|
||||
|
||||
// Check base size.
|
||||
if (this.txs.length === 0
|
||||
|| this.txs.length > consensus.MAX_BLOCK_SIZE
|
||||
@ -438,6 +427,17 @@ class Block extends AbstractBlock {
|
||||
if (this.txs.length === 0 || !this.txs[0].isCoinbase())
|
||||
return [false, 'bad-cb-missing', 100];
|
||||
|
||||
// Check merkle root.
|
||||
const root = this.createMerkleRoot('hex');
|
||||
|
||||
// If the merkle is mutated,
|
||||
// we have duplicate txs.
|
||||
if (!root)
|
||||
return [false, 'bad-txns-duplicate', 100];
|
||||
|
||||
if (this.merkleRoot !== root)
|
||||
return [false, 'bad-txnmrklroot', 100];
|
||||
|
||||
// Test all transactions.
|
||||
const scale = consensus.WITNESS_SCALE_FACTOR;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user