Skip to content

Commit

Permalink
fixup:
Browse files Browse the repository at this point in the history
* Don't run supposedly useless plugin task
* Join webserver task on shutdown
* Wait for offer if not ready yet
  • Loading branch information
elsirion committed Jul 4, 2022
1 parent 2aaf4c5 commit 667ef48
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
21 changes: 21 additions & 0 deletions client/client-lib/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl<'a> dyn FederationApi + 'a {
}
}
}

pub async fn await_output_outcome<T: TryIntoOutcome + Send>(
&self,
outpoint: OutPoint,
Expand All @@ -75,6 +76,26 @@ impl<'a> dyn FederationApi + 'a {
.await
.map_err(|_| ApiError::Timeout)?
}

pub async fn await_offer(
&self,
payment_hash: Sha256Hash,
timeout: Duration,
) -> Result<IncomingContractOffer> {
let poll = || async {
let interval = Duration::from_millis(100);
loop {
match self.fetch_offer(payment_hash).await {
Ok(t) => return Ok(t),
Err(e) if e.is_retryable() => minimint_api::task::sleep(interval).await,
Err(e) => return Err(e),
}
}
};
minimint_api::task::timeout(timeout, poll())
.await
.map_err(|_| ApiError::Timeout)?
}
}

#[derive(Debug, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion client/client-lib/src/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use minimint_core::modules::ln::{
ContractAccount, ContractInput, ContractOrOfferOutput, ContractOutput,
};
use rand::{CryptoRng, RngCore};
use std::time::Duration;
use thiserror::Error;

pub struct LnClient<'c> {
Expand Down Expand Up @@ -152,7 +153,7 @@ impl<'c> LnClient<'c> {
pub async fn get_offer(&self, payment_hash: Sha256Hash) -> Result<IncomingContractOffer> {
self.context
.api
.fetch_offer(payment_hash)
.await_offer(payment_hash, Duration::from_secs(10))
.await
.map_err(LnClientError::ApiError)
}
Expand Down
1 change: 0 additions & 1 deletion ln-gateway/src/bin/ln_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ async fn main() -> Result<(), Error> {
.await?
{
let mut gateway = initialize_gateway(&plugin, sender, receiver).await;
tokio::spawn(async move { plugin.join().await });
gateway.run().await.expect("gateway failed to run");
Ok(())
} else {
Expand Down
3 changes: 1 addition & 2 deletions ln-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ impl LnGateway {
impl Drop for LnGateway {
fn drop(&mut self) {
self.webserver.abort();
// FIXME: this panics ...
// assert!(futures::executor::block_on(&mut self.webserver).is_err());
let _ = futures::executor::block_on(&mut self.webserver);
}
}

Expand Down

0 comments on commit 667ef48

Please sign in to comment.