blockchain: remove coin cache
This commit is contained in:
parent
2b2e53d83d
commit
a9ebeb3871
@ -44,6 +44,9 @@
|
|||||||
|
|
||||||
- Pool options now has a `--discover` option exposed, and the `--only` node
|
- Pool options now has a `--discover` option exposed, and the `--only` node
|
||||||
option will disable discovery of new nodes.
|
option will disable discovery of new nodes.
|
||||||
|
- The option for `coin-cache` has been removed, this setting was causing
|
||||||
|
issues during the sync with out-of-memory errors and was making performance
|
||||||
|
worse instead of better.
|
||||||
|
|
||||||
### Script changes
|
### Script changes
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,6 @@ const node = new FullNode({
|
|||||||
prune: true,
|
prune: true,
|
||||||
network: 'main',
|
network: 'main',
|
||||||
memory: false,
|
memory: false,
|
||||||
coinCache: 30,
|
|
||||||
logConsole: true,
|
logConsole: true,
|
||||||
workers: true,
|
workers: true,
|
||||||
workerFile: '/worker.js',
|
workerFile: '/worker.js',
|
||||||
|
|||||||
@ -87,9 +87,6 @@ database and must be passed in consistently.
|
|||||||
- `prune`: Prune from the last 288 blocks (default: false).
|
- `prune`: Prune from the last 288 blocks (default: false).
|
||||||
- `checkpoints`: Use checkpoints and getheaders for the initial
|
- `checkpoints`: Use checkpoints and getheaders for the initial
|
||||||
sync (default: true).
|
sync (default: true).
|
||||||
- `coin-cache`: The size (in MB) of the in-memory UTXO cache. By default,
|
|
||||||
there is no UTXO cache enabled. To get a good number of cache hits per
|
|
||||||
block, the coin cache has to be fairly large (60-100mb recommended at least).
|
|
||||||
- `index-tx`: Index transactions (enables transaction endpoints in REST api)
|
- `index-tx`: Index transactions (enables transaction endpoints in REST api)
|
||||||
(default: false).
|
(default: false).
|
||||||
- `index-address`: Index transactions and utxos by address (default: false).
|
- `index-address`: Index transactions and utxos by address (default: false).
|
||||||
|
|||||||
@ -37,7 +37,6 @@ log-file: true
|
|||||||
|
|
||||||
prune: false
|
prune: false
|
||||||
checkpoints: true
|
checkpoints: true
|
||||||
coin-cache: 0
|
|
||||||
entry-cache: 5000
|
entry-cache: 5000
|
||||||
index-tx: false
|
index-tx: false
|
||||||
index-address: false
|
index-address: false
|
||||||
|
|||||||
@ -79,9 +79,6 @@ class Chain extends AsyncEmitter {
|
|||||||
if (this.options.checkpoints)
|
if (this.options.checkpoints)
|
||||||
this.logger.info('Checkpoints are enabled.');
|
this.logger.info('Checkpoints are enabled.');
|
||||||
|
|
||||||
if (this.options.coinCache)
|
|
||||||
this.logger.info('Coin cache is enabled.');
|
|
||||||
|
|
||||||
if (this.options.bip91)
|
if (this.options.bip91)
|
||||||
this.logger.warning('BIP91 enabled. Segsignal will be enforced.');
|
this.logger.warning('BIP91 enabled. Segsignal will be enforced.');
|
||||||
|
|
||||||
@ -1535,11 +1532,6 @@ class Chain extends AsyncEmitter {
|
|||||||
block.getSize(),
|
block.getSize(),
|
||||||
block.txs.length,
|
block.txs.length,
|
||||||
elapsed);
|
elapsed);
|
||||||
|
|
||||||
if (this.db.coinCache.capacity > 0) {
|
|
||||||
this.logger.debug('Coin Cache: size=%dmb, items=%d.',
|
|
||||||
this.db.coinCache.size / (1 << 20), this.db.coinCache.items);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2687,7 +2679,6 @@ class ChainOptions {
|
|||||||
this.indexAddress = false;
|
this.indexAddress = false;
|
||||||
this.forceFlags = false;
|
this.forceFlags = false;
|
||||||
|
|
||||||
this.coinCache = 0;
|
|
||||||
this.entryCache = 5000;
|
this.entryCache = 5000;
|
||||||
this.maxOrphans = 20;
|
this.maxOrphans = 20;
|
||||||
this.checkpoints = true;
|
this.checkpoints = true;
|
||||||
@ -2786,11 +2777,6 @@ class ChainOptions {
|
|||||||
this.bip148 = options.bip148;
|
this.bip148 = options.bip148;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.coinCache != null) {
|
|
||||||
assert((options.coinCache >>> 0) === options.coinCache);
|
|
||||||
this.coinCache = options.coinCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.entryCache != null) {
|
if (options.entryCache != null) {
|
||||||
assert((options.entryCache >>> 0) === options.entryCache);
|
assert((options.entryCache >>> 0) === options.entryCache);
|
||||||
this.entryCache = options.entryCache;
|
this.entryCache = options.entryCache;
|
||||||
|
|||||||
@ -47,7 +47,6 @@ class ChainDB {
|
|||||||
this.pending = null;
|
this.pending = null;
|
||||||
this.current = null;
|
this.current = null;
|
||||||
|
|
||||||
this.coinCache = new LRU(this.options.coinCache, getSize, BufferMap);
|
|
||||||
this.cacheHash = new LRU(this.options.entryCache, null, BufferMap);
|
this.cacheHash = new LRU(this.options.entryCache, null, BufferMap);
|
||||||
this.cacheHeight = new LRU(this.options.entryCache);
|
this.cacheHeight = new LRU(this.options.entryCache);
|
||||||
}
|
}
|
||||||
@ -118,7 +117,6 @@ class ChainDB {
|
|||||||
this.current = this.db.batch();
|
this.current = this.db.batch();
|
||||||
this.pending = this.state.clone();
|
this.pending = this.state.clone();
|
||||||
|
|
||||||
this.coinCache.start();
|
|
||||||
this.cacheHash.start();
|
this.cacheHash.start();
|
||||||
this.cacheHeight.start();
|
this.cacheHeight.start();
|
||||||
|
|
||||||
@ -170,7 +168,6 @@ class ChainDB {
|
|||||||
this.current = null;
|
this.current = null;
|
||||||
this.pending = null;
|
this.pending = null;
|
||||||
|
|
||||||
this.coinCache.drop();
|
|
||||||
this.cacheHash.drop();
|
this.cacheHash.drop();
|
||||||
this.cacheHeight.drop();
|
this.cacheHeight.drop();
|
||||||
this.stateCache.drop();
|
this.stateCache.drop();
|
||||||
@ -192,7 +189,6 @@ class ChainDB {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.current = null;
|
this.current = null;
|
||||||
this.pending = null;
|
this.pending = null;
|
||||||
this.coinCache.drop();
|
|
||||||
this.cacheHash.drop();
|
this.cacheHash.drop();
|
||||||
this.cacheHeight.drop();
|
this.cacheHeight.drop();
|
||||||
throw e;
|
throw e;
|
||||||
@ -209,7 +205,6 @@ class ChainDB {
|
|||||||
this.current = null;
|
this.current = null;
|
||||||
this.pending = null;
|
this.pending = null;
|
||||||
|
|
||||||
this.coinCache.commit();
|
|
||||||
this.cacheHash.commit();
|
this.cacheHash.commit();
|
||||||
this.cacheHeight.commit();
|
this.cacheHeight.commit();
|
||||||
this.stateCache.commit();
|
this.stateCache.commit();
|
||||||
@ -923,22 +918,12 @@ class ChainDB {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
const {hash, index} = prevout;
|
const {hash, index} = prevout;
|
||||||
const key = prevout.toKey();
|
|
||||||
const state = this.state;
|
|
||||||
|
|
||||||
const cache = this.coinCache.get(key);
|
|
||||||
|
|
||||||
if (cache)
|
|
||||||
return CoinEntry.fromRaw(cache);
|
|
||||||
|
|
||||||
const raw = await this.db.get(layout.c.encode(hash, index));
|
const raw = await this.db.get(layout.c.encode(hash, index));
|
||||||
|
|
||||||
if (!raw)
|
if (!raw)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (state === this.state)
|
|
||||||
this.coinCache.set(key, raw);
|
|
||||||
|
|
||||||
return CoinEntry.fromRaw(raw);
|
return CoinEntry.fromRaw(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1722,17 +1707,12 @@ class ChainDB {
|
|||||||
for (const [index, coin] of coins.outputs) {
|
for (const [index, coin] of coins.outputs) {
|
||||||
if (coin.spent) {
|
if (coin.spent) {
|
||||||
this.del(layout.c.encode(hash, index));
|
this.del(layout.c.encode(hash, index));
|
||||||
if (this.coinCache.capacity > 0)
|
|
||||||
this.coinCache.unpush(Outpoint.toKey(hash, index));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const raw = coin.toRaw();
|
const raw = coin.toRaw();
|
||||||
|
|
||||||
this.put(layout.c.encode(hash, index), raw);
|
this.put(layout.c.encode(hash, index), raw);
|
||||||
|
|
||||||
if (this.coinCache.capacity > 0)
|
|
||||||
this.coinCache.push(Outpoint.toKey(hash, index), raw);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2281,10 +2261,6 @@ class CacheUpdate {
|
|||||||
* Helpers
|
* Helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getSize(value) {
|
|
||||||
return value.length + 80;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fromU32(num) {
|
function fromU32(num) {
|
||||||
const data = Buffer.allocUnsafe(4);
|
const data = Buffer.allocUnsafe(4);
|
||||||
data.writeUInt32LE(num, 0, true);
|
data.writeUInt32LE(num, 0, true);
|
||||||
|
|||||||
@ -54,7 +54,6 @@ class FullNode extends Node {
|
|||||||
bip148: this.config.bool('bip148'),
|
bip148: this.config.bool('bip148'),
|
||||||
prune: this.config.bool('prune'),
|
prune: this.config.bool('prune'),
|
||||||
checkpoints: this.config.bool('checkpoints'),
|
checkpoints: this.config.bool('checkpoints'),
|
||||||
coinCache: this.config.mb('coin-cache'),
|
|
||||||
entryCache: this.config.uint('entry-cache'),
|
entryCache: this.config.uint('entry-cache'),
|
||||||
indexTX: this.config.bool('index-tx'),
|
indexTX: this.config.bool('index-tx'),
|
||||||
indexAddress: this.config.bool('index-address')
|
indexAddress: this.config.bool('index-address')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user