From 01535c55d7b76e2b0afc5028762035999ab7c9e9 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 5 Dec 2016 11:35:33 -0800 Subject: [PATCH] mempool: remove confidence. --- lib/mempool/mempool.js | 58 ++++----------------------------------- lib/node/fullnode.js | 10 ------- lib/protocol/constants.js | 38 ------------------------- 3 files changed, 6 insertions(+), 100 deletions(-) diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index 0c390345..1575a308 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -163,13 +163,9 @@ Mempool.prototype._addBlock = function addBlock(block) { var entries = []; var i, entry, tx, hash; - for (i = block.txs.length - 1; i >= 0; i--) { + for (i = block.txs.length - 1; i >= 1; i--) { tx = block.txs[i]; hash = tx.hash('hex'); - - if (tx.isCoinbase()) - continue; - entry = this.getEntry(hash); if (!entry) { @@ -218,13 +214,10 @@ Mempool.prototype.removeBlock = co(function* removeBlock(block) { Mempool.prototype._removeBlock = function removeBlock(block) { var i, entry, tx, hash; - for (i = 0; i < block.txs.length; i++) { + for (i = 1; i < block.txs.length; i++) { tx = block.txs[i]; hash = tx.hash('hex'); - if (tx.isCoinbase()) - continue; - if (this.hasTX(hash)) continue; @@ -752,9 +745,9 @@ Mempool.prototype._addUnchecked = co(function* addUnchecked(entry) { yield this._addTX(tx); } catch (err) { if (err.type === 'VerifyError') { - this.logger.debug('Could not resolve orphan %s: %s.', - tx.txid(), - err.message); + this.logger.debug( + 'Could not resolve orphan %s: %s.', + tx.txid(), err.message); if (!tx.hasWitness() && !err.malleated) this.rejects.add(tx.hash()); @@ -795,9 +788,8 @@ Mempool.prototype.removeUnchecked = function removeUnchecked(entry, limit) { this.untrackEntry(entry); - if (this.fees) { + if (this.fees) this.fees.removeTX(hash); - } this.emit('remove entry', entry); }; @@ -1598,44 +1590,6 @@ Mempool.prototype.verifyLocks = function verifyLocks(tx, flags) { return this.chain.verifyLocks(this.chain.tip, tx, flags); }; -/** - * Calculate bitcoinj-style confidence. - * @see http://bit.ly/1OVQwlO - * @param {TX|Hash} hash - * @returns {Promise} - Returns Number. - */ - -Mempool.prototype.getConfidence = co(function* getConfidence(hash) { - var tx, result; - - if (hash instanceof TX) { - tx = hash; - hash = hash.hash('hex'); - } else { - tx = this.getTX(hash); - } - - if (this.hasTX(hash)) - return constants.confidence.PENDING; - - if (tx && this.isDoubleSpend(tx)) - return constants.confidence.INCONFLICT; - - if (tx && tx.block) { - result = yield this.chain.db.isMainChain(tx.block); - if (result) - return constants.confidence.BUILDING; - return constants.confidence.DEAD; - } - - result = yield this.chain.db.hasCoins(hash); - - if (result) - return constants.confidence.BUILDING; - - return constants.confidence.UNKNOWN; -}); - /** * Map a transaction to the mempool. * @private diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index 1d2eade9..40d22afe 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -506,16 +506,6 @@ FullNode.prototype.fillHistory = function fillHistory(tx) { return this.mempool.fillAllHistory(tx); }; -/** - * Return bitcoinj-style confidence for a transaction. - * @param {Hash|TX} tx - * @returns {Promise} - Returns {@link Confidence}. - */ - -FullNode.prototype.getConfidence = function getConfidence(tx) { - return this.mempool.getConfidence(tx); -}; - /* * Expose */ diff --git a/lib/protocol/constants.js b/lib/protocol/constants.js index 40e924b2..a334a0b6 100644 --- a/lib/protocol/constants.js +++ b/lib/protocol/constants.js @@ -897,44 +897,6 @@ exports.thresholdStates = { FAILED: 4 }; -/** - * Bitcoinj-style confidence calculation - * @enum {Number} - * @default - */ - -exports.confidence = { - /** - * Transaction is in the main chain. - */ - - BUILDING: 1, - - /** - * Transaction is valid and in the mempool. - */ - - PENDING: 2, - - /** - * Transaction is on a side chain. - */ - - DEAD: 4, - - /** - * Transaction is double-spent. - */ - - INCONFLICT: 5, - - /** - * Transaction is not in the mempool or chain. - */ - - UNKNOWN: 0 -}; - /** * The name of our currency. * @const {String}