mempool: remove confidence.
This commit is contained in:
parent
21f4f45205
commit
01535c55d7
@ -163,13 +163,9 @@ Mempool.prototype._addBlock = function addBlock(block) {
|
|||||||
var entries = [];
|
var entries = [];
|
||||||
var i, entry, tx, hash;
|
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];
|
tx = block.txs[i];
|
||||||
hash = tx.hash('hex');
|
hash = tx.hash('hex');
|
||||||
|
|
||||||
if (tx.isCoinbase())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
entry = this.getEntry(hash);
|
entry = this.getEntry(hash);
|
||||||
|
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
@ -218,13 +214,10 @@ Mempool.prototype.removeBlock = co(function* removeBlock(block) {
|
|||||||
Mempool.prototype._removeBlock = function removeBlock(block) {
|
Mempool.prototype._removeBlock = function removeBlock(block) {
|
||||||
var i, entry, tx, hash;
|
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];
|
tx = block.txs[i];
|
||||||
hash = tx.hash('hex');
|
hash = tx.hash('hex');
|
||||||
|
|
||||||
if (tx.isCoinbase())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (this.hasTX(hash))
|
if (this.hasTX(hash))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -752,9 +745,9 @@ Mempool.prototype._addUnchecked = co(function* addUnchecked(entry) {
|
|||||||
yield this._addTX(tx);
|
yield this._addTX(tx);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.type === 'VerifyError') {
|
if (err.type === 'VerifyError') {
|
||||||
this.logger.debug('Could not resolve orphan %s: %s.',
|
this.logger.debug(
|
||||||
tx.txid(),
|
'Could not resolve orphan %s: %s.',
|
||||||
err.message);
|
tx.txid(), err.message);
|
||||||
|
|
||||||
if (!tx.hasWitness() && !err.malleated)
|
if (!tx.hasWitness() && !err.malleated)
|
||||||
this.rejects.add(tx.hash());
|
this.rejects.add(tx.hash());
|
||||||
@ -795,9 +788,8 @@ Mempool.prototype.removeUnchecked = function removeUnchecked(entry, limit) {
|
|||||||
|
|
||||||
this.untrackEntry(entry);
|
this.untrackEntry(entry);
|
||||||
|
|
||||||
if (this.fees) {
|
if (this.fees)
|
||||||
this.fees.removeTX(hash);
|
this.fees.removeTX(hash);
|
||||||
}
|
|
||||||
|
|
||||||
this.emit('remove entry', entry);
|
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);
|
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.
|
* Map a transaction to the mempool.
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
@ -506,16 +506,6 @@ FullNode.prototype.fillHistory = function fillHistory(tx) {
|
|||||||
return this.mempool.fillAllHistory(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
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -897,44 +897,6 @@ exports.thresholdStates = {
|
|||||||
FAILED: 4
|
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.
|
* The name of our currency.
|
||||||
* @const {String}
|
* @const {String}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user