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
5 changes: 5 additions & 0 deletions src/taker/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,11 @@ impl Taker {
pub fn is_offerbook_syncing(&self) -> bool {
self.offer_sync_handle.is_syncing()
}

/// Run offer sync now.
pub fn run_offer_sync_now(&self) {
self.offer_sync_handle.run_sync_now()
}
}

impl Role for Taker {
Expand Down
5 changes: 5 additions & 0 deletions src/taker/api2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,11 @@ impl Taker {
pub fn is_offerbook_syncing(&self) -> bool {
self.offer_sync_handle.is_syncing()
}

/// Run offer sync now.
pub fn run_offer_sync_now(&self) {
self.offer_sync_handle.run_sync_now()
}
}

impl Role for Taker {
Expand Down
18 changes: 17 additions & 1 deletion src/taker/offers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,15 @@ pub struct OfferSyncService {
socks_port: u16,
rpc_backend: BitcoinRpc,
is_syncing: Arc<AtomicBool>,
run_now: Arc<AtomicBool>,
}

/// OfferSync handle, use for shutting down OfferSyncService
pub struct OfferSyncHandle {
shutdown: Arc<AtomicBool>,
join: Option<JoinHandle<()>>,
is_syncing: Arc<AtomicBool>,
run_now: Arc<AtomicBool>,
}

impl OfferSyncHandle {
Expand All @@ -325,6 +327,11 @@ impl OfferSyncHandle {
pub fn is_syncing(&self) -> bool {
self.is_syncing.load(Ordering::SeqCst)
}

/// Runs manual sync, rather than waiting for routine to trigger it.
pub fn run_sync_now(&self) {
self.run_now.store(true, Ordering::Relaxed);
}
}

impl OfferSyncService {
Expand All @@ -341,6 +348,7 @@ impl OfferSyncService {
socks_port,
rpc_backend,
is_syncing: Arc::new(AtomicBool::new(false)),
run_now: Arc::new(AtomicBool::new(false)),
}
}

Expand Down Expand Up @@ -397,6 +405,7 @@ impl OfferSyncService {
let shutdown = Arc::new(AtomicBool::new(false));
let shutdown_flag = shutdown.clone();
let is_syncing = self.is_syncing.clone();
let run_now = self.run_now.clone();
self.is_syncing.store(true, Ordering::SeqCst);

let join = std::thread::Builder::new()
Expand All @@ -414,10 +423,16 @@ impl OfferSyncService {
log::debug!("Running offerbook sync completed");
self.is_syncing.store(false, Ordering::SeqCst);
let mut slept = Duration::ZERO;
while slept < OFFER_SYNC_INTERVAL && !shutdown_flag.load(Ordering::Relaxed) {
while slept < OFFER_SYNC_INTERVAL
&& !self.run_now.load(Ordering::Relaxed)
&& !shutdown_flag.load(Ordering::Relaxed)
{
std::thread::sleep(Duration::from_secs(1));
slept += Duration::from_secs(1);
}
if self.run_now.swap(false, Ordering::Relaxed) {
log::info!("Manual offerbook syncing initiated");
}
}

log::debug!("Offer sync service stopped");
Expand All @@ -428,6 +443,7 @@ impl OfferSyncService {
shutdown,
join: Some(join),
is_syncing,
run_now,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/watch_tower/rpc_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl BitcoinRpc {
}
}
None => {
log::warn!("Invalid fidelity {txid}:{vout} via {relay_url}");
log::debug!("Invalid fidelity {txid}:{vout} via {relay_url}");
}
}
}
Expand Down