Skip to content

Commit

Permalink
fix: add conversion trait
Browse files Browse the repository at this point in the history
  • Loading branch information
nakul1010 committed Aug 3, 2023
1 parent ae8ece5 commit 8830613
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
21 changes: 12 additions & 9 deletions vault/src/connection_manger.rs → vault/src/connection_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use crate::{
Error,
};
use async_trait::async_trait;
use backoff::{Error as BackoffError, ExponentialBackoff};
use backoff::Error as BackoffError;
use bitcoin::{cli::BitcoinOpts as BitcoinConfig, BitcoinCoreApi, Error as BitcoinError};
use futures::{future::Either, Future, FutureExt};
use governor::{Quota, RateLimiter};
Expand Down Expand Up @@ -135,15 +135,18 @@ impl<Config: Clone + Send + 'static, F: Fn()> ConnectionManager<Config, F> {
self.db_path.clone(),
);

let backoff = ExponentialBackoff::default();

backoff::future::retry(backoff, || async {
match service.start().await {
Ok(()) => Ok(()),
Err(err) => Err(err),
match service.start().await {
Err(err @ backoff::Error::Permanent(_)) => {
tracing::warn!("Disconnected: {}", err);
return Err(err.into());
}
})
.await?;
Err(err) => {
tracing::warn!("Disconnected: {}", err);
}
_ => {
tracing::warn!("Disconnected");
}
};

// propagate shutdown signal from main tasks
let _ = shutdown_tx.send(());
Expand Down
9 changes: 9 additions & 0 deletions vault/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ pub enum Error {
#[error("System I/O error: {0}")]
IoError(#[from] IoError),
}

impl From<backoff::Error<Error>> for Error {
fn from(err: backoff::Error<Error>) -> Self {
match err {
backoff::Error::Permanent(err) => err,
backoff::Error::Transient(err) => err,
}
}
}
7 changes: 3 additions & 4 deletions vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![feature(array_zip)]

mod cancellation;
mod cli;
mod connection_manager;
pub mod delay;
mod error;
mod execution;
Expand All @@ -12,17 +14,14 @@ pub mod process;
mod redeem;
pub mod relay;
mod replace;
// pub mod services;
mod cli;
mod connection_manger;
mod system;
mod trace;
mod types;

pub mod service {
pub use crate::{
cancellation::{CancellationScheduler, IssueCanceller, ReplaceCanceller},
connection_manger::{
connection_manager::{
init_subscriber, spawn_cancelable, wait_or_shutdown, warp, warp::Filter, ConnectionManager,
DynBitcoinCoreApi, MonitoringConfig, Service, ServiceConfig, ShutdownSender,
},
Expand Down
5 changes: 2 additions & 3 deletions vault/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ impl VaultService {
}

async fn run_service(&self) -> Result<(), BackoffError<Error>> {
//ToDo: remove service error put all errors in error
self.validate_bitcoin_network()
.await
.map_err(|err| BackoffError::Permanent(err))?;
Expand All @@ -609,7 +608,7 @@ impl VaultService {
.btc_parachain
.get_bitcoin_confirmations()
.await
.map_err(|err| BackoffError::Transient::<Error>(err.into()))?,
.map_err(|err| Error::RuntimeError(err))?,
};
tracing::info!("Using {} bitcoin confirmations", num_confirmations);

Expand Down Expand Up @@ -692,7 +691,7 @@ impl VaultService {
Arc::new(Box::new(
OrderedVaultsDelay::new(self.btc_parachain.clone())
.await
.map_err(|err| BackoffError::Transient::<Error>(err.into()))?,
.map_err(|err| Error::RuntimeError(err))?,
))
};

Expand Down

0 comments on commit 8830613

Please sign in to comment.