chaindb: switch back to buffer coin cache.
This commit is contained in:
parent
1d5bcc5918
commit
b4221b7589
@ -791,28 +791,24 @@ ChainDB.prototype.getTips = function getTips() {
|
|||||||
|
|
||||||
ChainDB.prototype.getCoin = co(function* getCoin(hash, index) {
|
ChainDB.prototype.getCoin = co(function* getCoin(hash, index) {
|
||||||
var state = this.state;
|
var state = this.state;
|
||||||
var raw, coins;
|
var raw;
|
||||||
|
|
||||||
if (this.options.spv)
|
if (this.options.spv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.coinCache.capacity !== 0) {
|
raw = this.coinCache.get(hash);
|
||||||
coins = yield this.getCoins(hash);
|
|
||||||
|
|
||||||
if (!coins)
|
if (raw)
|
||||||
return;
|
return Coins.parseCoin(raw, hash, index);
|
||||||
|
|
||||||
if (state === this.state)
|
|
||||||
this.coinCache.set(hash, coins);
|
|
||||||
|
|
||||||
return coins.getCoin(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
raw = yield this.db.get(layout.c(hash));
|
raw = yield this.db.get(layout.c(hash));
|
||||||
|
|
||||||
if (!raw)
|
if (!raw)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (state === this.state)
|
||||||
|
this.coinCache.set(hash, raw);
|
||||||
|
|
||||||
return Coins.parseCoin(raw, hash, index);
|
return Coins.parseCoin(raw, hash, index);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -823,24 +819,22 @@ ChainDB.prototype.getCoin = co(function* getCoin(hash, index) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ChainDB.prototype.getCoins = co(function* getCoins(hash) {
|
ChainDB.prototype.getCoins = co(function* getCoins(hash) {
|
||||||
var raw, coins;
|
var raw;
|
||||||
|
|
||||||
if (this.options.spv)
|
if (this.options.spv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
coins = this.coinCache.get(hash);
|
raw = this.coinCache.get(hash);
|
||||||
|
|
||||||
if (coins)
|
if (raw)
|
||||||
return coins;
|
return Coins.fromRaw(raw, hash);
|
||||||
|
|
||||||
raw = yield this.db.get(layout.c(hash));
|
raw = yield this.db.get(layout.c(hash));
|
||||||
|
|
||||||
if (!raw)
|
if (!raw)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
coins = Coins.fromRaw(raw, hash);
|
return Coins.fromRaw(raw, hash);
|
||||||
|
|
||||||
return coins;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1643,7 +1637,7 @@ ChainDB.prototype.removeBlock = co(function* removeBlock(hash) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ChainDB.prototype.saveView = function saveView(view) {
|
ChainDB.prototype.saveView = function saveView(view) {
|
||||||
var i, coins;
|
var i, coins, raw;
|
||||||
|
|
||||||
view = view.toArray();
|
view = view.toArray();
|
||||||
|
|
||||||
@ -1653,8 +1647,9 @@ ChainDB.prototype.saveView = function saveView(view) {
|
|||||||
this.del(layout.c(coins.hash));
|
this.del(layout.c(coins.hash));
|
||||||
this.coinCache.unpush(coins.hash);
|
this.coinCache.unpush(coins.hash);
|
||||||
} else {
|
} else {
|
||||||
this.put(layout.c(coins.hash), coins.toRaw());
|
raw = coins.toRaw();
|
||||||
this.coinCache.push(coins.hash, coins);
|
this.put(layout.c(coins.hash), raw);
|
||||||
|
this.coinCache.push(coins.hash, raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -2226,23 +2221,7 @@ CacheUpdate.prototype.toRaw = function toRaw() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function getSize(value) {
|
function getSize(value) {
|
||||||
var half = 4; // Average half of coins
|
return value.length + 80;
|
||||||
var total = 0;
|
|
||||||
|
|
||||||
total += 128; // coins
|
|
||||||
total += 88; // coins hash
|
|
||||||
total += 32; // coins outputs
|
|
||||||
|
|
||||||
// Average compressed coin size
|
|
||||||
// compressed coin = 112
|
|
||||||
// raw = 80
|
|
||||||
// pubkeyhash buffer = 26
|
|
||||||
total += half * (112 + 80 + 26);
|
|
||||||
|
|
||||||
// Average coin size
|
|
||||||
total += half * 509;
|
|
||||||
|
|
||||||
return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function BlockPair(hash, height) {
|
function BlockPair(hash, height) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user