mempool: share lock with chain.
This commit is contained in:
parent
3fb2150dc4
commit
f8c82197a4
@ -74,7 +74,7 @@ function Mempool(options) {
|
|||||||
this.chain = this.options.chain;
|
this.chain = this.options.chain;
|
||||||
this.fees = this.options.fees;
|
this.fees = this.options.fees;
|
||||||
|
|
||||||
this.locker = new Lock(true);
|
this.locker = this.chain.locker;
|
||||||
|
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
this.totalOrphans = 0;
|
this.totalOrphans = 0;
|
||||||
@ -1479,46 +1479,6 @@ Mempool.prototype.isDoubleSpend = function isDoubleSpend(tx) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Get coin viewpoint (no lock).
|
|
||||||
* @param {TX} tx
|
|
||||||
* @param {CoinView} view
|
|
||||||
* @returns {Promise} - Returns {@link CoinView}.
|
|
||||||
*/
|
|
||||||
|
|
||||||
Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
|
||||||
var state = this.chain.state;
|
|
||||||
var view = new CoinView();
|
|
||||||
var prevout = tx.getPrevout();
|
|
||||||
var i, entry, hash, coins;
|
|
||||||
|
|
||||||
for (i = 0; i < prevout.length; i++) {
|
|
||||||
hash = prevout[i];
|
|
||||||
entry = this.getEntry(hash);
|
|
||||||
|
|
||||||
if (entry) {
|
|
||||||
view.addTX(entry.tx, -1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
coins = yield this.chain.db.getCoins(hash);
|
|
||||||
|
|
||||||
if (!coins) {
|
|
||||||
coins = new Coins();
|
|
||||||
coins.hash = hash;
|
|
||||||
view.add(coins);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
view.add(coins);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state !== this.chain.state)
|
|
||||||
throw new Error('Chain state changed while getting coins.');
|
|
||||||
|
|
||||||
return view;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get coin viewpoint (lock).
|
* Get coin viewpoint (lock).
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
@ -1526,8 +1486,7 @@ Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
|||||||
* @returns {Promise} - Returns {@link CoinView}.
|
* @returns {Promise} - Returns {@link CoinView}.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Mempool.prototype._getCoinView = co(function* getCoinView(tx) {
|
Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
||||||
var state = this.chain.state;
|
|
||||||
var view = yield this.chain.db.getCoinView(tx);
|
var view = yield this.chain.db.getCoinView(tx);
|
||||||
var items = view.toArray();
|
var items = view.toArray();
|
||||||
var i, coins, entry;
|
var i, coins, entry;
|
||||||
@ -1546,9 +1505,6 @@ Mempool.prototype._getCoinView = co(function* getCoinView(tx) {
|
|||||||
view.addTX(entry.tx, -1);
|
view.addTX(entry.tx, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state !== this.chain.state)
|
|
||||||
throw new Error('Chain state changed while getting coins.');
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user