From a9ebeb38714ef77178dcb41ccc45f1afdb98de47 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Thu, 21 Mar 2019 15:10:15 -0700 Subject: [PATCH] blockchain: remove coin cache --- CHANGELOG.md | 3 +++ browser/src/app.js | 1 - docs/configuration.md | 3 --- etc/sample.conf | 1 - lib/blockchain/chain.js | 14 -------------- lib/blockchain/chaindb.js | 24 ------------------------ lib/node/fullnode.js | 1 - 7 files changed, 3 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca941324..8d74049d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,9 @@ - Pool options now has a `--discover` option exposed, and the `--only` node 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 diff --git a/browser/src/app.js b/browser/src/app.js index fd2b9132..89478526 100644 --- a/browser/src/app.js +++ b/browser/src/app.js @@ -61,7 +61,6 @@ const node = new FullNode({ prune: true, network: 'main', memory: false, - coinCache: 30, logConsole: true, workers: true, workerFile: '/worker.js', diff --git a/docs/configuration.md b/docs/configuration.md index 1bf25d1c..85c1b29c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -87,9 +87,6 @@ database and must be passed in consistently. - `prune`: Prune from the last 288 blocks (default: false). - `checkpoints`: Use checkpoints and getheaders for the initial 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) (default: false). - `index-address`: Index transactions and utxos by address (default: false). diff --git a/etc/sample.conf b/etc/sample.conf index 32eb00ef..3dfe2db8 100644 --- a/etc/sample.conf +++ b/etc/sample.conf @@ -37,7 +37,6 @@ log-file: true prune: false checkpoints: true -coin-cache: 0 entry-cache: 5000 index-tx: false index-address: false diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 2c44b11d..5dab1d9f 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -79,9 +79,6 @@ class Chain extends AsyncEmitter { if (this.options.checkpoints) this.logger.info('Checkpoints are enabled.'); - if (this.options.coinCache) - this.logger.info('Coin cache is enabled.'); - if (this.options.bip91) this.logger.warning('BIP91 enabled. Segsignal will be enforced.'); @@ -1535,11 +1532,6 @@ class Chain extends AsyncEmitter { block.getSize(), block.txs.length, 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.forceFlags = false; - this.coinCache = 0; this.entryCache = 5000; this.maxOrphans = 20; this.checkpoints = true; @@ -2786,11 +2777,6 @@ class ChainOptions { this.bip148 = options.bip148; } - if (options.coinCache != null) { - assert((options.coinCache >>> 0) === options.coinCache); - this.coinCache = options.coinCache; - } - if (options.entryCache != null) { assert((options.entryCache >>> 0) === options.entryCache); this.entryCache = options.entryCache; diff --git a/lib/blockchain/chaindb.js b/lib/blockchain/chaindb.js index ec69b134..a361df4b 100644 --- a/lib/blockchain/chaindb.js +++ b/lib/blockchain/chaindb.js @@ -47,7 +47,6 @@ class ChainDB { this.pending = null; this.current = null; - this.coinCache = new LRU(this.options.coinCache, getSize, BufferMap); this.cacheHash = new LRU(this.options.entryCache, null, BufferMap); this.cacheHeight = new LRU(this.options.entryCache); } @@ -118,7 +117,6 @@ class ChainDB { this.current = this.db.batch(); this.pending = this.state.clone(); - this.coinCache.start(); this.cacheHash.start(); this.cacheHeight.start(); @@ -170,7 +168,6 @@ class ChainDB { this.current = null; this.pending = null; - this.coinCache.drop(); this.cacheHash.drop(); this.cacheHeight.drop(); this.stateCache.drop(); @@ -192,7 +189,6 @@ class ChainDB { } catch (e) { this.current = null; this.pending = null; - this.coinCache.drop(); this.cacheHash.drop(); this.cacheHeight.drop(); throw e; @@ -209,7 +205,6 @@ class ChainDB { this.current = null; this.pending = null; - this.coinCache.commit(); this.cacheHash.commit(); this.cacheHeight.commit(); this.stateCache.commit(); @@ -923,22 +918,12 @@ class ChainDB { return null; 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)); if (!raw) return null; - if (state === this.state) - this.coinCache.set(key, raw); - return CoinEntry.fromRaw(raw); } @@ -1722,17 +1707,12 @@ class ChainDB { for (const [index, coin] of coins.outputs) { if (coin.spent) { this.del(layout.c.encode(hash, index)); - if (this.coinCache.capacity > 0) - this.coinCache.unpush(Outpoint.toKey(hash, index)); continue; } const raw = coin.toRaw(); 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 */ -function getSize(value) { - return value.length + 80; -} - function fromU32(num) { const data = Buffer.allocUnsafe(4); data.writeUInt32LE(num, 0, true); diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index b2000434..0e6a8d0e 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -54,7 +54,6 @@ class FullNode extends Node { bip148: this.config.bool('bip148'), prune: this.config.bool('prune'), checkpoints: this.config.bool('checkpoints'), - coinCache: this.config.mb('coin-cache'), entryCache: this.config.uint('entry-cache'), indexTX: this.config.bool('index-tx'), indexAddress: this.config.bool('index-address')