From 53fb6dc8d521bd04b22139c0e7455d4a62885c05 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 19 Apr 2016 03:05:42 -0700 Subject: [PATCH] some consensus stuff. --- lib/bcoin/block.js | 34 ++++++++++++++++++++++++---------- lib/bcoin/chain.js | 2 +- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index ab22162b..67c5cc27 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -326,8 +326,8 @@ Block.prototype.__defineGetter__('commitmentHash', function() { */ Block.prototype._verify = function _verify(ret) { - var uniq = {}; - var i, tx, hash; + var sigops = 0; + var i, tx, merkle; if (!ret) ret = {}; @@ -361,18 +361,32 @@ Block.prototype._verify = function _verify(ret) { return false; } - // Check for duplicate txids - hash = tx.hash('hex'); - if (uniq[hash]) { - ret.reason = 'bad-txns-duplicate'; - ret.score = 100; + // Sanity checks + if (!tx.isSane(ret)) return false; - } - uniq[hash] = true; + + // Count legacy sigops (do not count scripthash or witness) + // sigops += tx._getSigops(); + // if (sigops > constants.block.MAX_SIGOPS) { + // return callback(new VerifyError(block, + // 'invalid', + // 'bad-blk-sigops', + // 100)); + // } } // Check merkle root - if (this.merkleRoot !== this.getMerkleRoot('hex')) { + merkle = this.getMerkleRoot('hex'); + + // If the merkle is mutated, + // we have duplicate txs. + if (!merkle) { + ret.reason = 'bad-txns-duplicate'; + ret.score = 100; + return false; + } + + if (this.merkleRoot !== merkle) { ret.reason = 'bad-txnmrkleroot'; ret.score = 100; return false; diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 32f515a8..57d435c4 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -822,7 +822,7 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac // Check for block sigops limits // Start counting P2SH sigops once block // timestamps reach March 31st, 2012. - if (block.ts >= constants.block.BIP16_TIME) + if (flags & constants.flags.VERIFY_P2SH) sigops += tx.getSigops(true); else sigops += tx.getSigops();