Skip to content
Closed
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
4 changes: 1 addition & 3 deletions src/chain/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,7 @@ impl<H: HeaderStore> Chain<H> {

#[cfg(not(feature = "filter-control"))]
if !self.block_queue.contains(&filter_message.block_hash)
&& filter
.contains_any(self.scripts.iter())
.map_err(CFilterSyncError::Filter)?
&& filter.contains_any(self.scripts.iter())
{
// Add to the block queue
self.block_queue.add(filter_message.block_hash);
Expand Down
20 changes: 0 additions & 20 deletions src/filters/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub enum CFilterSyncError {
UnrequestedStophash,
UnknownFilterHash,
MisalignedFilterHash,
Filter(FilterError),
}

impl core::fmt::Display for CFilterSyncError {
Expand All @@ -65,27 +64,8 @@ impl core::fmt::Display for CFilterSyncError {
f,
"the filter hash from our header chain and this filter hash do not match."
),
CFilterSyncError::Filter(_) => write!(
f,
"the filter experienced an IO error checking for Script inclusions."
),
}
}
}

impl_sourceless_error!(CFilterSyncError);

#[derive(Debug)]
pub enum FilterError {
IORead,
}

impl core::fmt::Display for FilterError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FilterError::IORead => write!(f, "unable to read from the filter contents buffer."),
}
}
}

impl_sourceless_error!(FilterError);
9 changes: 2 additions & 7 deletions src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ pub(crate) mod filter_chain;
use bitcoin::hashes::{sha256d, Hash};
use bitcoin::{bip158::BlockFilter, BlockHash, FilterHash, ScriptBuf};

use error::FilterError;

#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct Filter {
filter_hash: FilterHash,
Expand Down Expand Up @@ -40,12 +38,9 @@ impl Filter {
&self.block_hash
}

pub fn contains_any<'a>(
&'a mut self,
scripts: impl Iterator<Item = &'a ScriptBuf>,
) -> Result<bool, FilterError> {
pub fn contains_any<'a>(&'a mut self, scripts: impl Iterator<Item = &'a ScriptBuf>) -> bool {
self.block_filter
.match_any(&self.block_hash, scripts.map(|script| script.to_bytes()))
.map_err(|_| FilterError::IORead)
.expect("&[u8] reader is infalliable")
}
}
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ impl IndexedFilter {

/// Does the filter contain a positive match for any of the provided scripts
pub fn contains_any<'a>(&'a mut self, scripts: impl Iterator<Item = &'a ScriptBuf>) -> bool {
self.filter
.contains_any(scripts)
.expect("vec reader is infallible")
self.filter.contains_any(scripts)
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
},
db::traits::{HeaderStore, PeerStore},
error::FetchHeaderError,
filters::{cfheader_chain::AppendAttempt, error::CFilterSyncError},
filters::cfheader_chain::AppendAttempt,
network::{peer_map::PeerMap, LastBlockMonitor, PeerId, PeerTimeoutConfig},
FilterSyncPolicy, NodeState, RejectPayload, TxBroadcastPolicy,
};
Expand Down Expand Up @@ -624,14 +624,9 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
self.dialog.send_warning(Warning::UnexpectedSyncError {
warning: format!("Compact filter syncing encountered an error: {}", e),
});
match e {
CFilterSyncError::Filter(_) => Some(MainThreadMessage::Disconnect),
_ => {
let mut lock = self.peer_map.lock().await;
lock.ban(peer_id).await;
Some(MainThreadMessage::Disconnect)
}
}
let mut lock = self.peer_map.lock().await;
lock.ban(peer_id).await;
Some(MainThreadMessage::Disconnect)
}
}
}
Expand Down