diff --git a/.env b/.env index 26ba24e..04e50f5 100644 --- a/.env +++ b/.env @@ -12,8 +12,8 @@ ESCROW_NPUB=npub1hcsc4r3xc9ygnefp4eqyan9r46tjvd3w0dxk2hgydc9k6m5xd3jq2hkjqp # Mint URL MINT_URL=http://0.0.0.0:3338 -#MINT_URL=https://mint.minibits.cash/Bitcoin +# MINT_URL=https://mint.minibits.cash/Bitcoin # Nostr relays (comma separated) NOSTR_RELAYS="ws://localhost:4736" -# NOSTR_RELAYS="wss://relay.damus.io, wss://relay.primal.net, wss://relay.nostr.band, wss://ftp.halifax.rwth-aachen.de/nostr, wss://nostr.mom, wss://relay.nostrplebs.com" \ No newline at end of file +# NOSTR_RELAYS="wss://relay.damus.io, wss://relay.primal.net, wss://relay.nostr.band, wss://ftp.halifax.rwth-aachen.de/nostr, wss://nostr.mom, wss://relay.nostrplebs.com" diff --git a/coordinator/src/escrow_coordinator/mod.rs b/coordinator/src/escrow_coordinator/mod.rs index 036fe23..d149752 100644 --- a/coordinator/src/escrow_coordinator/mod.rs +++ b/coordinator/src/escrow_coordinator/mod.rs @@ -1,5 +1,4 @@ use super::*; -use anyhow::anyhow; use cashu_escrow_common::model::TradeContract; use cdk::nuts::SecretKey as CDKSecretKey; use hashes::hex::DisplayHex; @@ -81,15 +80,13 @@ impl EscrowCoordinator { } } } else if RelayPoolNotification::Shutdown == notification { - break Err(anyhow!( - "Got shutdown notification, breaking coordinator loop!" - )); + error!("Got shutdown notification, restarting nostr client!"); + self.reconnect_nostr_client().await?; } } Err(RecvError::Closed) => { - break Err(anyhow!( - "Got closed error from channel, breaking coordinator loop!" - )) + error!("Got closed error from channel, restarting nostr client..."); + self.reconnect_nostr_client().await?; } Err(RecvError::Lagged(count)) => { warn!("Lost {} events, resuming after that...", count); @@ -136,4 +133,13 @@ impl EscrowCoordinator { let trade_hash: [u8; 32] = hasher.finalize().into(); Ok((trade_hash, contract)) } + + async fn reconnect_nostr_client(&self) -> anyhow::Result<()> { + self.nostr_client.client.disconnect().await?; + warn!("Reconnecting nostr client in 60 seconds..."); + tokio::time::sleep(std::time::Duration::from_secs(60)).await; + self.nostr_client.client.connect().await; + info!("Nostr client reconnected sucessfully!"); + Ok(()) + } } diff --git a/coordinator/src/main.rs b/coordinator/src/main.rs index fe782ef..8b84543 100644 --- a/coordinator/src/main.rs +++ b/coordinator/src/main.rs @@ -18,11 +18,11 @@ async fn main() -> anyhow::Result<()> { .init(); let keys = Keys::from_str(&env::var("ESCROW_NSEC")?)?; - let relays = env::var("NOSTR_RELAYS")? + let relays: Vec = env::var("NOSTR_RELAYS")? .split(',') .map(String::from) .collect(); - let nostr_client = NostrClient::new(keys, relays).await?; + let nostr_client = NostrClient::new(keys.clone(), relays.clone()).await?; info!( "Coordinator npub: {}", nostr_client.public_key().to_bech32()?