From eeeff1f7951362ce7745bf932165d605a7424efc Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 6 Mar 2017 18:03:56 -0800 Subject: [PATCH] chain: skip all preliminary verification when using checkpoints. --- lib/blockchain/chain.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 49fe3e2f..6b44757f 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -231,9 +231,26 @@ Chain.prototype.verify = co(function* verify(block, prev, flags) { assert(typeof flags === 'number'); + // Extra sanity check. if (block.prevBlock !== prev.hash) throw new VerifyError(block, 'invalid', 'bad-prevblk', 0); + // Skip everything when using checkpoints. + // We can do this safely because every + // block in between each checkpoint was + // validated outside in the header chain. + if (prev.isHistorical()) { + if (this.options.spv) + return new DeploymentState(); + + // 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. if (flags & common.flags.VERIFY_BODY) { if (!block.verifyBody(ret)) {