diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 19cfea93..aa546681 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -2687,8 +2687,6 @@ class ChainOptions { this.bip91 = false; this.bip148 = false; this.prune = false; - this.indexTX = false; - this.indexAddress = false; this.forceFlags = false; this.entryCache = 5000; @@ -2766,16 +2764,6 @@ class ChainOptions { this.compression = options.compression; } - if (options.indexTX != null) { - assert(typeof options.indexTX === 'boolean'); - this.indexTX = options.indexTX; - } - - if (options.indexAddress != null) { - assert(typeof options.indexAddress === 'boolean'); - this.indexAddress = options.indexAddress; - } - if (options.prune != null) { assert(typeof options.prune === 'boolean'); this.prune = options.prune; diff --git a/lib/blockchain/chaindb.js b/lib/blockchain/chaindb.js index 184afbf1..24dc6846 100644 --- a/lib/blockchain/chaindb.js +++ b/lib/blockchain/chaindb.js @@ -571,12 +571,6 @@ class ChainDB { if (!options.prune && flags.prune) throw new Error('Cannot retroactively unprune.'); - if (options.prune && options.indexTX && !flags.indexTX) - throw new Error('Cannot retroactively enable TX indexing.'); - - if (options.prune && options.indexAddress && !flags.indexAddress) - throw new Error('Cannot retroactively enable address indexing.'); - if (needsSave) { await this.logger.info('Rewriting chain flags.'); await this.saveFlags(); @@ -1801,8 +1795,6 @@ class ChainFlags { this.bip91 = false; this.bip148 = false; this.prune = false; - this.indexTX = false; - this.indexAddress = false; if (options) this.fromOptions(options); @@ -1831,16 +1823,6 @@ class ChainFlags { this.prune = options.prune; } - if (options.indexTX != null) { - assert(typeof options.indexTX === 'boolean'); - this.indexTX = options.indexTX; - } - - if (options.indexAddress != null) { - assert(typeof options.indexAddress === 'boolean'); - this.indexAddress = options.indexAddress; - } - return this; } @@ -1862,12 +1844,6 @@ class ChainFlags { if (this.prune) flags |= 1 << 2; - if (this.indexTX) - flags |= 1 << 3; - - if (this.indexAddress) - flags |= 1 << 4; - if (this.bip91) flags |= 1 << 5; @@ -1891,8 +1867,6 @@ class ChainFlags { this.spv = (flags & 1) !== 0; this.witness = (flags & 2) !== 0; this.prune = (flags & 4) !== 0; - this.indexTX = (flags & 8) !== 0; - this.indexAddress = (flags & 16) !== 0; this.bip91 = (flags & 32) !== 0; this.bip148 = (flags & 64) !== 0; diff --git a/lib/indexer/indexer.js b/lib/indexer/indexer.js index 5a6b51f4..11187771 100644 --- a/lib/indexer/indexer.js +++ b/lib/indexer/indexer.js @@ -612,6 +612,7 @@ class IndexOptions { 'Indexer requires a blockstore.'); assert(options.chain && typeof options.chain === 'object', 'Indexer requires chain.'); + assert(!options.prune, 'Can not index while pruned.'); this.blocks = options.blocks; this.chain = options.chain; diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index 0a3612fc..2b77a7c0 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -164,6 +164,7 @@ class FullNode extends Node { logger: this.logger, blocks: this.blocks, chain: this.chain, + prune: this.config.bool('prune'), memory: this.config.bool('memory'), prefix: this.config.filter('index').str('prefix') || this.config.prefix }); @@ -175,6 +176,7 @@ class FullNode extends Node { logger: this.logger, blocks: this.blocks, chain: this.chain, + prune: this.config.bool('prune'), memory: this.config.bool('memory'), prefix: this.config.filter('index').str('prefix') || this.config.prefix, maxTxs: this.config.uint('max-txs') diff --git a/test/indexer-test.js b/test/indexer-test.js index 699c4813..61b9acb5 100644 --- a/test/indexer-test.js +++ b/test/indexer-test.js @@ -17,6 +17,7 @@ const TXIndexer = require('../lib/indexer/txindexer'); const AddrIndexer = require('../lib/indexer/addrindexer'); const BlockStore = require('../lib/blockstore/level'); const FullNode = require('../lib/node/fullnode'); +const SPVNode = require('../lib/node/spvnode'); const Network = require('../lib/protocol/network'); const network = Network.get('regtest'); const {NodeClient, WalletClient} = require('bclient'); @@ -639,6 +640,45 @@ describe('Indexer', function() { await node.close(); } }); + + it('will not index if pruned', async () => { + let err = null; + + try { + new FullNode({ + prefix: prefix, + network: 'regtest', + apiKey: 'foo', + memory: false, + prune: true, + indexTX: true, + indexAddress: true, + port: ports.p2p, + httpPort: ports.node + }); + } catch (e) { + err = e; + } + + assert(err); + assert.equal(err.message, 'Can not index while pruned.'); + }); + + it('will not index if spv', async () => { + const node = new SPVNode({ + prefix: prefix, + network: 'regtest', + apiKey: 'foo', + memory: false, + indexTX: true, + indexAddress: true, + port: ports.p2p, + httpPort: ports.node + }); + + assert.equal(node.txindex, undefined); + assert.equal(node.addrindex, undefined); + }); }); });