Skip to content

Commit

Permalink
Merge pull request #151 from gregdhill/chore/tokio-1.0
Browse files Browse the repository at this point in the history
chore: update tokio to v1 and jsonrpc to v18
  • Loading branch information
sander2 authored Jul 22, 2021
2 parents acd041e + 7173ed4 commit da6785d
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 89 deletions.
120 changes: 79 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ thiserror = "1.0"
bitcoincore-rpc = { git = "https://github.com/gregdhill/rust-bitcoincore-rpc", rev = "80ff27b" }
hex = "0.4.2"
async-trait = "0.1.40"
tokio = { version = "0.2.22", features = ["full"] }
tokio = { version = "1.0", features = ["full"] }
backoff = { version = "0.2.1", features = ["tokio"] }
clap = { version = "3.0.0-beta.2", optional = true }
num = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use hyper::Error as HyperError;
use serde_json::Error as SerdeJsonError;
use std::io::ErrorKind as IoErrorKind;
use thiserror::Error;
use tokio::time::Elapsed;
use tokio::time::error::Elapsed;

#[derive(Error, Debug)]
pub enum Error {
Expand Down
16 changes: 8 additions & 8 deletions bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use sp_core::H256;
use std::{future::Future, io::ErrorKind as IoErrorKind, sync::Arc, time::Duration};
use tokio::{
sync::{Mutex, OwnedMutexGuard},
time::{delay_for, timeout},
time::{sleep, timeout},
};

#[macro_use]
Expand Down Expand Up @@ -200,23 +200,23 @@ impl BitcoinCore {
if err.kind() == IoErrorKind::ConnectionRefused =>
{
trace!("could not connect to bitcoin-core");
delay_for(RETRY_DURATION).await;
sleep(RETRY_DURATION).await;
continue;
}
Err(BitcoinError::JsonRpc(JsonRpcError::Rpc(err)))
if BitcoinRpcError::from(err.clone()) == BitcoinRpcError::RpcInWarmup =>
{
// may be loading block index or verifying wallet
trace!("bitcoin-core still in warm up");
delay_for(RETRY_DURATION).await;
sleep(RETRY_DURATION).await;
continue;
}
Err(BitcoinError::JsonRpc(JsonRpcError::Json(err)))
if err.classify() == SerdeJsonCategory::Syntax =>
{
// invalid response, can happen if server is in shutdown
trace!("bitcoin-core gave an invalid response: {}", err);
delay_for(RETRY_DURATION).await;
sleep(RETRY_DURATION).await;
continue;
}
Ok(_) => {
Expand All @@ -241,7 +241,7 @@ impl BitcoinCore {
return Ok(());
}
trace!("bitcoin-core not synced");
delay_for(RETRY_DURATION).await;
sleep(RETRY_DURATION).await;
}
}

Expand Down Expand Up @@ -298,7 +298,7 @@ impl BitcoinCore {
Some(wait) => {
// error occurred, sleep before retrying
log::warn!("{:?} - next retry in {:.3} s", err, wait.as_secs_f64());
tokio::time::delay_for(wait).await;
tokio::time::sleep(wait).await;
}
None => break Err(Error::ConnectionRefused),
}
Expand Down Expand Up @@ -333,15 +333,15 @@ impl BitcoinCoreApi for BitcoinCore {
if info.confirmations >= num_confirmations {
return Ok(self.rpc.get_block(&hash)?);
} else {
delay_for(RETRY_DURATION).await;
sleep(RETRY_DURATION).await;
continue;
}
}
Err(BitcoinError::JsonRpc(JsonRpcError::Rpc(err)))
if BitcoinRpcError::from(err.clone()) == BitcoinRpcError::RpcInvalidParameter =>
{
// block does not exist yet
delay_for(RETRY_DURATION).await;
sleep(RETRY_DURATION).await;
continue;
}
Err(err) => return Err(err.into()),
Expand Down
Loading

0 comments on commit da6785d

Please sign in to comment.