From ff856fd6c278c0ffcc19ec8cdfd3b2a75e23f791 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 10 Jul 2017 18:16:41 -0700 Subject: [PATCH] chain: post-verify transactions due to potential of rejected promises. --- lib/blockchain/chain.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 696c19ea..d0fe2a65 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -547,7 +547,6 @@ Chain.prototype.verifyInputs = async function verifyInputs(block, prev, state) { let jobs = []; let sigops = 0; let reward = 0; - let valid; if (this.options.spv) return view; @@ -615,15 +614,13 @@ Chain.prototype.verifyInputs = async function verifyInputs(block, prev, state) { 'bad-cb-amount', 100); } - - // Push onto verification queue. - jobs.push(tx.verifyAsync(view, state.flags, this.workers)); } // Add new coins. view.addTX(tx, height); } + // Skip script verification. if (historical) return view; @@ -637,10 +634,14 @@ Chain.prototype.verifyInputs = async function verifyInputs(block, prev, state) { 100); } - // Verify all txs in parallel. - valid = await co.every(jobs); + // Push onto verification queue. + for (let i = 1; i < block.txs.length; i++) { + let tx = block.txs[i]; + jobs.push(tx.verifyAsync(view, state.flags, this.workers)); + } - if (!valid) { + // Verify all txs in parallel. + if (!(await co.every(jobs))) { throw new VerifyError(block, 'invalid', 'mandatory-script-verify-flag-failed',