From b55e22487cb7b2e8df23618fe66c3b6505225855 Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Thu, 15 Jan 2026 18:58:09 +0000 Subject: [PATCH 1/2] Adjust example for P2TR --- example/bitcoin.rs | 21 ++++++++++++--------- src/lib.rs | 3 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/example/bitcoin.rs b/example/bitcoin.rs index b98439ed..49a0d287 100644 --- a/example/bitcoin.rs +++ b/example/bitcoin.rs @@ -3,8 +3,8 @@ use bip157::builder::Builder; use bip157::chain::{BlockHeaderChanges, ChainState}; -use bip157::{lookup_host, Client, Event, HeaderCheckpoint, Network, ScriptBuf}; -use std::collections::HashSet; +use bip157::{Client, Event, FilterType, HeaderCheckpoint, Network}; +use std::net::{IpAddr, Ipv4Addr}; use tokio::time::Instant; const NETWORK: Network = Network::Bitcoin; @@ -15,23 +15,20 @@ async fn main() { let subscriber = tracing_subscriber::FmtSubscriber::new(); tracing::subscriber::set_global_default(subscriber).unwrap(); let now = Instant::now(); - // Add Bitcoin scripts to scan the blockchain for - let address = ScriptBuf::new_op_return(b"Kyoto light client"); - let mut addresses = HashSet::new(); - addresses.insert(address); - let seeds = lookup_host("seed.bitcoin.sipa.be").await; + // let seeds = lookup_host("seed.bitcoin.sipa.be").await; // Create a new node builder let builder = Builder::new(NETWORK); // Add node preferences and build the node/client let (node, client) = builder // The number of connections we would like to maintain - .required_peers(2) + .required_peers(1) // Only scan for taproot scripts .chain_state(ChainState::Checkpoint( HeaderCheckpoint::taproot_activation(), )) + .filter_type(FilterType::Taproot) // Add some initial peers - .add_peers(seeds.into_iter().map(From::from)) + .add_peer(IpAddr::V4(Ipv4Addr::new(65, 109, 109, 117))) // Create the node and client .build(); // Run the node on a separate task @@ -45,6 +42,7 @@ async fn main() { mut warn_rx, mut event_rx, } = client; + let mut total_bytes = 0; // Continually listen for events until the node is synced to its peers. loop { tokio::select! { @@ -60,8 +58,13 @@ async fn main() { tracing::info!("Total sync time: {sync_time} seconds"); let avg_fee_rate = requester.average_fee_rate(update.tip().hash).await.unwrap(); tracing::info!("Last block average fee rate: {:#}", avg_fee_rate); + tracing::info!("Total bytes downloaded {}", total_bytes); break; }, + Event::IndexedFilter(filter) => { + let byte_vec = filter.into_contents(); + total_bytes += byte_vec.len(); + }, Event::ChainUpdate(BlockHeaderChanges::Connected(header)) => { tracing::info!("New best tip {}", header.height); }, diff --git a/src/lib.rs b/src/lib.rs index 2e670f15..3db70170 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,12 +117,15 @@ pub enum FilterType { #[default] /// A golomb coded compact sketch based on siphash. Contains all spendable script types. Basic, + /// GCS filter only containing P2TR outputs. + Taproot, } impl From for u8 { fn from(value: FilterType) -> Self { match value { FilterType::Basic => 0x00, + FilterType::Taproot => 0x01, } } } From b61511e537cf7dcfb6c9edfad76003038dcaf37c Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Fri, 16 Jan 2026 14:13:24 +0000 Subject: [PATCH 2/2] Use one month of data --- example/bitcoin.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/example/bitcoin.rs b/example/bitcoin.rs index 49a0d287..5688fec5 100644 --- a/example/bitcoin.rs +++ b/example/bitcoin.rs @@ -23,9 +23,12 @@ async fn main() { // The number of connections we would like to maintain .required_peers(1) // Only scan for taproot scripts - .chain_state(ChainState::Checkpoint( - HeaderCheckpoint::taproot_activation(), - )) + .chain_state(ChainState::Checkpoint(HeaderCheckpoint { + height: 927516, + hash: "00000000000000000001849ec8caa64852aa2299002629269ee90424c765c617" + .parse() + .unwrap(), + })) .filter_type(FilterType::Taproot) // Add some initial peers .add_peer(IpAddr::V4(Ipv4Addr::new(65, 109, 109, 117)))