mempool: fix potential race conditions with coins.
This commit is contained in:
parent
5fb16543f1
commit
b36484c7aa
@ -2268,6 +2268,7 @@ Chain.prototype.getLocks = co(function* getLocks(prev, tx, view, flags) {
|
||||
var disableFlag = constants.sequence.DISABLE_FLAG;
|
||||
var typeFlag = constants.sequence.TYPE_FLAG;
|
||||
var hasFlag = flags & constants.flags.VERIFY_SEQUENCE;
|
||||
var nextHeight = this.height + 1;
|
||||
var minHeight = -1;
|
||||
var minTime = -1;
|
||||
var coinHeight, coinTime;
|
||||
@ -2285,7 +2286,7 @@ Chain.prototype.getLocks = co(function* getLocks(prev, tx, view, flags) {
|
||||
coinHeight = view.getHeight(input);
|
||||
|
||||
if (coinHeight === -1)
|
||||
coinHeight = this.height + 1;
|
||||
coinHeight = nextHeight;
|
||||
|
||||
if ((input.sequence & typeFlag) === 0) {
|
||||
coinHeight += (input.sequence & mask) - 1;
|
||||
|
||||
@ -1500,13 +1500,13 @@ Mempool.prototype.isDoubleSpend = function isDoubleSpend(tx) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Get coin viewpoint.
|
||||
* Get coin viewpoint (no lock).
|
||||
* @param {TX} tx
|
||||
* @param {CoinView} view
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
*/
|
||||
|
||||
Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
||||
Mempool.prototype._getCoinView = co(function* getCoinView(tx) {
|
||||
var view = new CoinView();
|
||||
var prevout = tx.getPrevout();
|
||||
var i, entry, hash, coins;
|
||||
@ -1535,6 +1535,35 @@ Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
||||
return view;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get coin viewpoint (lock).
|
||||
* @param {TX} tx
|
||||
* @param {CoinView} view
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
*/
|
||||
|
||||
Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
||||
var view = yield this.chain.getCoinView(tx);
|
||||
var entries = view.toArray();
|
||||
var i, entry, coins;
|
||||
|
||||
for (i = 0; i < entries.length; i++) {
|
||||
coins = entries[i];
|
||||
|
||||
if (!coins.isEmpty())
|
||||
continue;
|
||||
|
||||
entry = this.getEntry(coins.hash);
|
||||
|
||||
if (!entry)
|
||||
continue;
|
||||
|
||||
view.addTX(entry.tx, -1);
|
||||
}
|
||||
|
||||
return view;
|
||||
});
|
||||
|
||||
/**
|
||||
* Spend coins for transaction.
|
||||
* @param {TX} tx
|
||||
|
||||
Loading…
Reference in New Issue
Block a user