From 085872d5038f9a8b8c70a9a958c55d9eb25d0c67 Mon Sep 17 00:00:00 2001 From: Daniel Savu Date: Thu, 29 Oct 2020 02:45:37 +0200 Subject: [PATCH] Add index-unspendables CLI flag (#28) --- README.md | 1 + doc/schema.md | 2 +- src/config.rs | 7 +++++++ src/new_index/mempool.rs | 4 +++- src/new_index/schema.rs | 4 +++- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 71a1dd57..5cf685ff 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ In addition to electrs's original configuration options, a few new options are a - `--lightmode` - enable light mode (see above) - `--cors ` - origins allowed to make cross-site request (optional, defaults to none). - `--address-search` - enables the by-prefix address search index. +- `--index-unspendables` - enables indexing of provably unspendable outputs. - `--utxos-limit ` - maximum number of utxos to return per address. - `--electrum-txs-limit ` - maximum number of txs to return per address in the electrum server (does not apply for the http api). - `--electrum-banner ` - welcome banner text for electrum server. diff --git a/doc/schema.md b/doc/schema.md index 851c6754..4875cb4d 100644 --- a/doc/schema.md +++ b/doc/schema.md @@ -43,7 +43,7 @@ When the indexer is synced up to the tip of the chain, the hash of the tip is sa ### `history` -Each funding output (except for provably unspendable ones) results in the following new rows (`H` is for history, `F` is for funding): +Each funding output (except for provably unspendable ones when `--index-unspendables` is not enabled) results in the following new rows (`H` is for history, `F` is for funding): * `"H{funding-scripthash}{funding-height}F{funding-txid:vout}{value}" → ""` * `"a{funding-address-str}" → ""` (for prefix address search, only saved when `--address-search` is enabled) diff --git a/src/config.rs b/src/config.rs index 48adaf05..189ac557 100644 --- a/src/config.rs +++ b/src/config.rs @@ -31,6 +31,7 @@ pub struct Config { pub jsonrpc_import: bool, pub light_mode: bool, pub address_search: bool, + pub index_unspendables: bool, pub cors: Option, pub precache_scripts: Option, pub utxos_limit: usize, @@ -148,6 +149,11 @@ impl Config { .long("address-search") .help("Enable prefix address search") ) + .arg( + Arg::with_name("index_unspendables") + .long("index-unspendables") + .help("Enable indexing of provably unspendable outputs") + ) .arg( Arg::with_name("cors") .long("cors") @@ -362,6 +368,7 @@ impl Config { jsonrpc_import: m.is_present("jsonrpc_import"), light_mode: m.is_present("light_mode"), address_search: m.is_present("address_search"), + index_unspendables: m.is_present("index_unspendables"), cors: m.value_of("cors").map(|s| s.to_string()), precache_scripts: m.value_of("precache_scripts").map(|s| s.to_string()), diff --git a/src/new_index/mempool.rs b/src/new_index/mempool.rs index 16a771ce..cf67790b 100644 --- a/src/new_index/mempool.rs +++ b/src/new_index/mempool.rs @@ -378,12 +378,14 @@ impl Mempool { ) }); + let config = &self.config; + // An iterator over (ScriptHash, TxHistoryInfo) let funding = tx .output .iter() .enumerate() - .filter(|(_, txo)| is_spendable(txo)) + .filter(|(_, txo)| is_spendable(txo) || config.index_unspendables) .map(|(index, txo)| { ( compute_script_hash(&txo.script_pubkey), diff --git a/src/new_index/schema.rs b/src/new_index/schema.rs index facc9f36..bb85bda0 100644 --- a/src/new_index/schema.rs +++ b/src/new_index/schema.rs @@ -169,6 +169,7 @@ pub struct Indexer { struct IndexerConfig { light_mode: bool, address_search: bool, + index_unspendables: bool, network: Network, #[cfg(feature = "liquid")] parent_network: Network, @@ -179,6 +180,7 @@ impl From<&Config> for IndexerConfig { IndexerConfig { light_mode: config.light_mode, address_search: config.address_search, + index_unspendables: config.index_unspendables, network: config.network_type, #[cfg(feature = "liquid")] parent_network: config.parent_network, @@ -1072,7 +1074,7 @@ fn index_transaction( // S{funding-txid:vout}{spending-txid:vin} → "" let txid = full_hash(&tx.txid()[..]); for (txo_index, txo) in tx.output.iter().enumerate() { - if is_spendable(txo) { + if is_spendable(txo) || iconfig.index_unspendables { let history = TxHistoryRow::new( &txo.script_pubkey, confirmed_height,