Skip to content

Commit

Permalink
build filters by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidson-Souza committed Dec 27, 2023
1 parent 3a4d9e5 commit b160a7e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion florestad/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub enum Commands {
/// Those filters let you query for chain data after IBD, like wallet rescan,
/// finding an utxo, finding specific tx_ids.
/// Will cause more disk usage
#[arg(long = "cfilters", short = 'c', default_value_t = false)]
#[arg(long = "cfilters", short = 'c', default_value_t = true)]
cfilters: bool,
/// What types of filters we should build. Keep in mind that each filter
/// type you add, will eat up more disk.
Expand All @@ -114,6 +114,7 @@ pub enum Commands {

#[derive(Clone, Debug, ValueEnum)]
pub enum FilterType {
All,
Inputs,
TxId,
SpkPKH,
Expand Down
26 changes: 25 additions & 1 deletion florestad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ fn main() {
cfilters,
cfilter_types,
}) => {
// By default, we build filters for WPKH and TR outputs, as they are the newest.
// We also build the `inputs` filters to find spends
let cfilter_types = match cfilter_types {
Some(cfilters) if !cfilters.is_empty() => cfilters,
_ => {
vec![FilterType::SpkWPKH, FilterType::SpkTR, FilterType::Inputs]
}
};

let ctx = Ctx {
data_dir,
assume_valid,
Expand All @@ -115,7 +124,7 @@ fn main() {
config_file: params.config_file,
network: params.network,
cfilters,
cfilter_types: cfilter_types.unwrap_or_default(),
cfilter_types,
#[cfg(feature = "zmq-server")]
zmq_address: _zmq_address,
};
Expand All @@ -124,9 +133,13 @@ fn main() {

// We may have more commands here, like setup and dump wallet
None => {
let cfilter_types = vec![FilterType::SpkWPKH, FilterType::SpkTR, FilterType::Inputs];

let ctx = Ctx {
config_file: params.config_file,
network: params.network,
cfilters: true,
cfilter_types,
..Default::default()
};
run_with_ctx(ctx);
Expand Down Expand Up @@ -166,6 +179,7 @@ fn run_with_ctx(ctx: Ctx) {
Some(path) => get_config_file(&path),
None => get_config_file(&system_config_file),
};

// Load the watch-only wallet
debug!("Loading wallet");
let mut wallet = load_wallet(&data_dir);
Expand Down Expand Up @@ -216,8 +230,18 @@ fn run_with_ctx(ctx: Ctx) {
let mut filters = FilterBackendBuilder::default()
.key_hash(key)
.use_storage(Box::new(cfilters_db));

for filter_type in ctx.cfilter_types {
filters = match filter_type {
FilterType::All => filters
.index_txids(true)
.index_input(true)
.add_address_type(floresta_compact_filters::OutputTypes::SH)
.add_address_type(floresta_compact_filters::OutputTypes::PKH)
.add_address_type(floresta_compact_filters::OutputTypes::WSH)
.add_address_type(floresta_compact_filters::OutputTypes::WPKH)
.add_address_type(floresta_compact_filters::OutputTypes::TR),

FilterType::TxId => filters.index_txids(true),
FilterType::Inputs => filters.index_input(true),

Expand Down

0 comments on commit b160a7e

Please sign in to comment.