Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use bitcoin::Network;
use super::{client::Client, node::Node};
use crate::chain::ChainState;
use crate::network::ConnectionType;
use crate::Config;
use crate::TrustedPeer;
use crate::{Config, FilterType};

const MIN_PEERS: u8 = 1;
const MAX_PEERS: u8 = 15;
Expand Down Expand Up @@ -132,6 +132,12 @@ impl Builder {
self
}

/// Request a specific compact sketch type.
pub fn filter_type(mut self, filter_type: FilterType) -> Self {
self.config.filter_type = filter_type;
self
}

/// Consume the node builder and receive a [`Node`] and [`Client`].
pub fn build(mut self) -> (Node, Client) {
Node::new(self.network, core::mem::take(&mut self.config))
Expand Down
12 changes: 8 additions & 4 deletions src/chain/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ use super::{
CFHeaderBatch, CFHeaderChanges, ChainState, Filter, FilterCheck, FilterHeaderRequest,
FilterRequest, FilterRequestState, HeaderValidationExt, HeightMonitor, PeerId,
};
use crate::IndexedFilter;
use crate::{chain::BlockHeaderChanges, messages::Event, Dialog, Info, Progress};
use crate::{FilterType, IndexedFilter};

const FILTER_BASIC: u8 = 0x00;
const CF_HEADER_BATCH_SIZE: u32 = 1_999;
const FILTER_BATCH_SIZE: u32 = 999;

Expand All @@ -28,6 +27,7 @@ pub(crate) struct Chain {
network: Network,
heights: Arc<Mutex<HeightMonitor>>,
dialog: Arc<Dialog>,
filter_type: FilterType,
}

impl Chain {
Expand All @@ -37,6 +37,7 @@ impl Chain {
dialog: Arc<Dialog>,
height_monitor: Arc<Mutex<HeightMonitor>>,
quorum_required: u8,
filter_type: FilterType,
) -> Self {
let header_chain = match chain_state {
ChainState::Snapshot(headers) => {
Expand All @@ -60,6 +61,7 @@ impl Chain {
network,
heights: height_monitor,
dialog,
filter_type,
}
}

Expand Down Expand Up @@ -295,7 +297,7 @@ impl Chain {
stop_hash,
});
GetCFHeaders {
filter_type: FILTER_BASIC,
filter_type: self.filter_type.into(),
start_height: last_unchecked_cfheader,
stop_hash,
}
Expand Down Expand Up @@ -372,7 +374,7 @@ impl Chain {
start_height: last_unchecked_filter,
});
GetCFilters {
filter_type: FILTER_BASIC,
filter_type: self.filter_type.into(),
start_height: last_unchecked_filter,
stop_hash,
}
Expand Down Expand Up @@ -437,6 +439,7 @@ mod tests {
use tokio::sync::Mutex;

use crate::chain::ChainState;
use crate::FilterType;
use crate::{
chain::checkpoints::HeaderCheckpoint,
messages::{Event, Info, Warning},
Expand All @@ -459,6 +462,7 @@ mod tests {
Arc::new(Dialog::new(info_tx, warn_tx, event_tx)),
height_monitor,
peers,
FilterType::Basic,
)
}

Expand Down
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ impl IndexedBlock {
}
}

/// The type of filter to make a request for.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum FilterType {
#[default]
/// A golomb coded compact sketch based on siphash. Contains all spendable script types.
Basic,
}

impl From<FilterType> for u8 {
fn from(value: FilterType) -> Self {
match value {
FilterType::Basic => 0x00,
}
}
}

/// A compact block filter with associated height.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IndexedFilter {
Expand Down Expand Up @@ -334,6 +351,7 @@ struct Config {
chain_state: Option<ChainState>,
connection_type: ConnectionType,
peer_timeout_config: PeerTimeoutConfig,
filter_type: FilterType,
}

impl Default for Config {
Expand All @@ -345,6 +363,7 @@ impl Default for Config {
chain_state: Default::default(),
connection_type: Default::default(),
peer_timeout_config: PeerTimeoutConfig::default(),
filter_type: FilterType::default(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl Node {
chain_state,
connection_type,
peer_timeout_config,
filter_type,
} = config;
// Set up a communication channel between the node and client
let (info_tx, info_rx) = mpsc::channel::<Info>(32);
Expand Down Expand Up @@ -107,6 +108,7 @@ impl Node {
Arc::clone(&dialog),
height_monitor,
required_peers,
filter_type,
);
(
Self {
Expand Down