From 4404f120a1cffa09bbc66f670adab61339ee3c9e Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Wed, 16 May 2018 17:22:56 +0300 Subject: [PATCH] Always index the blockchain --- src/bin/indexrs.rs | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/bin/indexrs.rs b/src/bin/indexrs.rs index 4b4ec81..4d08c80 100644 --- a/src/bin/indexrs.rs +++ b/src/bin/indexrs.rs @@ -7,8 +7,7 @@ extern crate simplelog; #[macro_use] extern crate log; -use argparse::{ArgumentParser, StoreFalse, StoreTrue}; -use bitcoin::util::hash::Sha256dHash; +use argparse::{ArgumentParser, StoreTrue}; use indexrs::{daemon, index, query, rpc, store}; use std::fs::OpenOptions; use std::thread; @@ -17,7 +16,6 @@ use std::time::Duration; #[derive(Debug)] struct Config { log_file: String, - enable_indexing: bool, testnet: bool, } @@ -25,17 +23,11 @@ impl Config { pub fn from_args() -> Config { let mut config = Config { log_file: "indexrs.log".to_string(), - enable_indexing: true, testnet: false, }; { let mut parser = ArgumentParser::new(); parser.set_description("Bitcoin indexing server."); - parser.refer(&mut config.enable_indexing).add_option( - &["--disable-indexing"], - StoreFalse, - "Disable indexing server (allow queries on existing DB)", - ); parser.refer(&mut config.testnet).add_option( &["--testnet"], StoreTrue, @@ -73,20 +65,17 @@ impl Config { fn run_server(config: &Config) { let index = index::Index::new(); let daemon = daemon::Daemon::new(config.daemon_addr()); - let mut tip = Sha256dHash::default(); - { - let store = store::Store::open( - config.db_path(), - store::StoreOptions { - // compact manually after the first run has finished successfully - auto_compact: false, - }, - ); - if config.enable_indexing { - tip = index.update(&store, &daemon); - store.compact_if_needed(); - } - } + + let store = store::Store::open( + config.db_path(), + store::StoreOptions { + // compact manually after the first run has finished successfully + auto_compact: false, + }, + ); + let mut tip = index.update(&store, &daemon); + store.compact_if_needed(); + drop(store); let store = store::Store::open(config.db_path(), store::StoreOptions { auto_compact: true }); let query = query::Query::new(&store, &daemon, &index); @@ -101,7 +90,7 @@ fn run_server(config: &Config) { let current_tip = daemon .getbestblockhash() .expect("failed to get latest blockhash"); - if tip == current_tip || !config.enable_indexing { + if tip == current_tip { continue; } tip = index.update(&store, &daemon);