mempool: remove confidence.

This commit is contained in:
Christopher Jeffrey 2016-12-05 11:35:33 -08:00
parent 21f4f45205
commit 01535c55d7
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 6 additions and 100 deletions

View File

@ -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

View File

@ -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
*/

View File

@ -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}