Skip to content

Commit

Permalink
Have processor's Network::new sleep until booted, not panic
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Nov 8, 2023
1 parent bc07e14 commit a688350
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
8 changes: 7 additions & 1 deletion processor/src/networks/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,13 @@ impl Eq for Bitcoin {}

impl Bitcoin {
pub async fn new(url: String) -> Bitcoin {
Bitcoin { rpc: Rpc::new(url).await.expect("couldn't create a Bitcoin RPC") }
let mut res = Rpc::new(url.clone()).await;
while let Err(e) = res {
log::error!("couldn't connect to Bitcoin node: {e:?}");
tokio::time::sleep(Duration::from_secs(5)).await;
res = Rpc::new(url.clone()).await;
}
Bitcoin { rpc: res.unwrap() }
}

#[cfg(test)]
Expand Down
8 changes: 7 additions & 1 deletion processor/src/networks/monero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ fn map_rpc_err(err: RpcError) -> NetworkError {

impl Monero {
pub async fn new(url: String) -> Monero {
Monero { rpc: HttpRpc::new(url).await.unwrap() }
let mut res = HttpRpc::new(url.clone()).await;
while let Err(e) = res {
log::error!("couldn't connect to Monero node: {e:?}");
tokio::time::sleep(Duration::from_secs(5)).await;
res = HttpRpc::new(url.clone()).await;
}
Monero { rpc: res.unwrap() }
}

fn view_pair(spend: EdwardsPoint) -> ViewPair {
Expand Down
19 changes: 2 additions & 17 deletions processor/src/tests/literal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ mod bitcoin {

async fn bitcoin(ops: &DockerOperations) -> Bitcoin {
let handle = ops.handle("serai-dev-bitcoin").host_port(8332).unwrap();
let url = format!("http://serai:seraidex@{}:{}", handle.0, handle.1);
for _ in 0 .. 20 {
if bitcoin_serai::rpc::Rpc::new(url.clone()).await.is_ok() {
break;
}
tokio::time::sleep(core::time::Duration::from_secs(1)).await;
}
let bitcoin = Bitcoin::new(url).await;
let bitcoin = Bitcoin::new(format!("http://serai:seraidex@{}:{}", handle.0, handle.1)).await;
bitcoin.fresh_chain().await;
bitcoin
}
Expand Down Expand Up @@ -114,15 +107,7 @@ mod monero {

async fn monero(ops: &DockerOperations) -> Monero {
let handle = ops.handle("serai-dev-monero").host_port(18081).unwrap();
let url = format!("http://serai:seraidex@{}:{}", handle.0, handle.1);
for _ in 0 .. 60 {
if monero_serai::rpc::HttpRpc::new(url.clone()).await.is_ok() {
break;
}
tokio::time::sleep(core::time::Duration::from_secs(1)).await;
}

let monero = Monero::new(url).await;
let monero = Monero::new(format!("http://serai:seraidex@{}:{}", handle.0, handle.1)).await;
while monero.get_latest_block_number().await.unwrap() < 150 {
monero.mine_block().await;
}
Expand Down

0 comments on commit a688350

Please sign in to comment.