Skip to content

Commit 4428b5a

Browse files
authored
Merge pull request 2140-dev#362 from rustaceanrob/download-policy-5-5
Remove `FilterSyncPolicy`
2 parents d5896b3 + b2c62bd commit 4428b5a

File tree

7 files changed

+4
-121
lines changed

7 files changed

+4
-121
lines changed

src/builder.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
chain::checkpoints::HeaderCheckpoint,
1717
db::traits::{HeaderStore, PeerStore},
1818
};
19-
use crate::{FilterSyncPolicy, LogLevel, PeerStoreSizeConfig, TrustedPeer};
19+
use crate::{LogLevel, PeerStoreSizeConfig, TrustedPeer};
2020

2121
#[cfg(feature = "rusqlite")]
2222
/// The default node returned from the [`NodeBuilder`].
@@ -211,14 +211,6 @@ impl NodeBuilder {
211211
self
212212
}
213213

214-
/// Stop the node from downloading and checking compact block filters until an explicit command by the client is made.
215-
/// This is only useful if the scripts to check for may not be known do to some expensive computation, like in a silent
216-
/// payments context.
217-
pub fn halt_filter_download(mut self) -> Self {
218-
self.config.filter_sync_policy = FilterSyncPolicy::Halt;
219-
self
220-
}
221-
222214
/// Consume the node builder and receive a [`Node`] and [`Client`].
223215
///
224216
/// # Errors

src/client.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,6 @@ impl Requester {
237237
.map_err(|_| ClientError::SendError)
238238
}
239239

240-
/// Explicitly start the block filter syncing process. Note that the node will automatically download and check
241-
/// filters unless the policy is to explicitly halt.
242-
///
243-
/// # Errors
244-
///
245-
/// If the node has stopped running.
246-
pub fn continue_download(&self) -> Result<(), ClientError> {
247-
self.ntx
248-
.send(ClientMessage::ContinueDownload)
249-
.map_err(|_| ClientError::SendError)
250-
}
251-
252240
/// Check if the node is running.
253241
pub fn is_running(&self) -> bool {
254242
self.ntx.send(ClientMessage::NoOp).is_ok()

src/config.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bitcoin::ScriptBuf;
55
use crate::{
66
chain::checkpoints::HeaderCheckpoint,
77
network::{dns::DnsResolver, ConnectionType},
8-
FilterSyncPolicy, LogLevel, PeerStoreSizeConfig, PeerTimeoutConfig, TrustedPeer,
8+
LogLevel, PeerStoreSizeConfig, PeerTimeoutConfig, TrustedPeer,
99
};
1010

1111
const REQUIRED_PEERS: u8 = 1;
@@ -20,7 +20,6 @@ pub(crate) struct NodeConfig {
2020
pub connection_type: ConnectionType,
2121
pub target_peer_size: PeerStoreSizeConfig,
2222
pub peer_timeout_config: PeerTimeoutConfig,
23-
pub filter_sync_policy: FilterSyncPolicy,
2423
pub log_level: LogLevel,
2524
}
2625

@@ -36,7 +35,6 @@ impl Default for NodeConfig {
3635
connection_type: Default::default(),
3736
target_peer_size: PeerStoreSizeConfig::default(),
3837
peer_timeout_config: PeerTimeoutConfig::default(),
39-
filter_sync_policy: Default::default(),
4038
log_level: Default::default(),
4139
}
4240
}

src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,6 @@ pub enum LogLevel {
392392
Warning,
393393
}
394394

395-
/// Should the node immediately download filters or wait for a command
396-
#[derive(Debug, Default)]
397-
pub enum FilterSyncPolicy {
398-
/// The node will wait for an explicit command to start downloading and checking filters
399-
Halt,
400-
/// Filters are downloaded immediately after CBF headers are synced.
401-
#[default]
402-
Continue,
403-
}
404-
405395
/// The state of the node with respect to connected peers.
406396
#[derive(Debug, Clone, Copy)]
407397
pub enum NodeState {

src/messages.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ pub(crate) enum ClientMessage {
141141
AddScript(ScriptBuf),
142142
/// Starting at the configured anchor checkpoint, look for block inclusions with newly added scripts.
143143
Rescan,
144-
/// If the [`FilterSyncPolicy`] is set to `Halt`, issuing this command will
145-
/// start the filter download and checking process. Otherwise, this command will not have any effect
146-
/// on node operation.
147-
ContinueDownload,
148144
/// Explicitly request a block from the node.
149145
#[cfg(feature = "filter-control")]
150146
GetBlock(BlockRequest),

src/node.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::{
2828
db::traits::{HeaderStore, PeerStore},
2929
error::FetchHeaderError,
3030
network::{peer_map::PeerMap, LastBlockMonitor, PeerId},
31-
FilterSyncPolicy, NodeState, RejectPayload, TxBroadcastPolicy,
31+
NodeState, RejectPayload, TxBroadcastPolicy,
3232
};
3333

3434
use super::{
@@ -60,7 +60,6 @@ pub struct Node<H: HeaderStore, P: PeerStore> {
6060
dialog: Arc<Dialog>,
6161
client_recv: Arc<Mutex<UnboundedReceiver<ClientMessage>>>,
6262
peer_recv: Arc<Mutex<Receiver<PeerThreadMessage>>>,
63-
filter_sync_policy: Arc<RwLock<FilterSyncPolicy>>,
6463
}
6564

6665
impl<H: HeaderStore, P: PeerStore> Node<H, P> {
@@ -80,7 +79,6 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
8079
connection_type,
8180
target_peer_size,
8281
peer_timeout_config,
83-
filter_sync_policy,
8482
log_level,
8583
} = config;
8684
// Set up a communication channel between the node and client
@@ -137,7 +135,6 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
137135
dialog,
138136
client_recv: Arc::new(Mutex::new(crx)),
139137
peer_recv: Arc::new(Mutex::new(mrx)),
140-
filter_sync_policy: Arc::new(RwLock::new(filter_sync_policy)),
141138
},
142139
client,
143140
)
@@ -255,11 +252,6 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
255252
self.broadcast(response).await;
256253
}
257254
},
258-
ClientMessage::ContinueDownload => {
259-
if let Some(response) = self.start_filter_download().await {
260-
self.broadcast(response).await
261-
}
262-
},
263255
#[cfg(feature = "filter-control")]
264256
ClientMessage::GetBlock(hash) => {
265257
let mut state = self.state.write().await;
@@ -477,10 +469,7 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
477469
chain.next_cf_header_message(),
478470
));
479471
} else if !chain.is_filters_synced() {
480-
let filter_download = self.filter_sync_policy.read().await;
481-
if matches!(*filter_download, FilterSyncPolicy::Continue) {
482-
return Some(MainThreadMessage::GetFilters(chain.next_filter_message()));
483-
}
472+
return Some(MainThreadMessage::GetFilters(chain.next_filter_message()));
484473
}
485474
None
486475
}
@@ -732,22 +721,6 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
732721
}
733722
}
734723

735-
// Continue the filter syncing process by explicit command
736-
async fn start_filter_download(&self) -> Option<MainThreadMessage> {
737-
let mut download_policy = self.filter_sync_policy.write().await;
738-
*download_policy = FilterSyncPolicy::Continue;
739-
drop(download_policy);
740-
let current_state = self.state.read().await;
741-
match *current_state {
742-
NodeState::Behind => None,
743-
NodeState::HeadersSynced => None,
744-
_ => {
745-
let mut chain = self.chain.lock().await;
746-
self.next_stateful_message(chain.deref_mut()).await
747-
}
748-
}
749-
}
750-
751724
// When the application starts, fetch any headers we know about from the database.
752725
async fn fetch_headers(&self) -> Result<(), NodeError<H::Error, P::Error>> {
753726
crate::log!(self.dialog, "Attempting to load headers from the database");

tests/core.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -530,60 +530,6 @@ async fn stop_reorg_start_on_orphan() {
530530
rpc.stop().unwrap();
531531
}
532532

533-
#[tokio::test]
534-
#[allow(clippy::collapsible_match)]
535-
async fn halting_download_works() {
536-
let (bitcoind, socket_addr) = start_bitcoind(true).unwrap();
537-
let rpc = &bitcoind.client;
538-
let tempdir = tempfile::TempDir::new().unwrap().into_path();
539-
540-
let miner = rpc.new_address().unwrap();
541-
mine_blocks(rpc, &miner, 10, 1).await;
542-
let best = best_hash(rpc);
543-
let mut scripts = HashSet::new();
544-
let other = rpc.new_address().unwrap();
545-
scripts.insert(other.into());
546-
547-
let host = (IpAddr::V4(*socket_addr.ip()), Some(socket_addr.port()));
548-
let builder = kyoto::builder::NodeBuilder::new(bitcoin::Network::Regtest);
549-
let (node, client) = builder
550-
.add_peers(vec![host.into()])
551-
.add_scripts(scripts)
552-
.data_dir(tempdir)
553-
.halt_filter_download()
554-
.build()
555-
.unwrap();
556-
557-
tokio::task::spawn(async move { node.run().await });
558-
let Client {
559-
requester,
560-
log_rx: _,
561-
info_rx: mut info,
562-
warn_rx: _,
563-
event_rx: mut channel,
564-
} = client;
565-
while let Some(message) = info.recv().await {
566-
if let kyoto::Info::StateChange(node_state) = message {
567-
if let kyoto::NodeState::FilterHeadersSynced = node_state {
568-
println!("Sleeping for one second...");
569-
tokio::time::sleep(Duration::from_secs(1)).await;
570-
requester.continue_download().unwrap();
571-
break;
572-
}
573-
}
574-
}
575-
576-
while let Some(message) = channel.recv().await {
577-
if let kyoto::messages::Event::Synced(update) = message {
578-
println!("Done");
579-
assert_eq!(update.tip().hash, best);
580-
break;
581-
}
582-
}
583-
requester.shutdown().unwrap();
584-
rpc.stop().unwrap();
585-
}
586-
587533
#[tokio::test]
588534
async fn signet_syncs() {
589535
let tempdir = tempfile::TempDir::new().unwrap().into_path();

0 commit comments

Comments
 (0)