Skip to content

Commit

Permalink
Rename TimeoutStrategy to SleepStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed May 11, 2023
1 parent 4b49251 commit 5ebce67
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions apps/src/lib/client/eth_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tokio::time::{Duration, Instant};
use web30::client::Web3;

use crate::cli;
use crate::control_flow::timeouts::TimeoutStrategy;
use crate::control_flow::timeouts::SleepStrategy;
use crate::node::ledger::ethereum_oracle::eth_syncing_status;

/// Arguments to [`block_on_eth_sync`].
Expand All @@ -35,7 +35,7 @@ pub async fn block_on_eth_sync(args: BlockOnEthSync<'_>) {
} = args;
tracing::info!("Attempting to synchronize with the Ethereum network");
let client = Web3::new(url, rpc_timeout);
TimeoutStrategy::LinearBackoff { delta: delta_sleep }
SleepStrategy::LinearBackoff { delta: delta_sleep }
.timeout(deadline, || async {
let local_set = LocalSet::new();
let status_fut = local_set
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use crate::client::tendermint_rpc_types::TxResponse;
use crate::client::tx::{
Conversions, PinnedBalanceError, TransactionDelta, TransferDelta,
};
use crate::control_flow::timeouts::TimeoutStrategy;
use crate::control_flow::timeouts::SleepStrategy;
use crate::facade::tendermint::merkle::proof::Proof;
use crate::facade::tendermint_config::net::Address as TendermintAddress;
use crate::facade::tendermint_rpc::error::Error as TError;
Expand All @@ -78,7 +78,7 @@ pub async fn query_tx_status(
deadline: Instant,
) -> Event {
let client = HttpClient::new(address).unwrap();
TimeoutStrategy::LinearBackoff {
SleepStrategy::LinearBackoff {
delta: Duration::from_secs(1),
}
.timeout(deadline, || async {
Expand Down
8 changes: 4 additions & 4 deletions apps/src/lib/control_flow/timeouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio::time::{Duration, Instant};

/// A timeout strategy to
#[derive(Debug, Clone)]
pub enum TimeoutStrategy {
pub enum SleepStrategy {
/// A constant timeout strategy.
Constant(Duration),
/// A linear timeout strategy.
Expand All @@ -18,7 +18,7 @@ pub enum TimeoutStrategy {
},
}

impl TimeoutStrategy {
impl SleepStrategy {
/// Sleep and update the `backoff` timeout, if necessary.
async fn sleep_update(&self, backoff: &mut Duration) {
match self {
Expand All @@ -35,7 +35,7 @@ impl TimeoutStrategy {
/// Execute a fallible task.
///
/// Different retries will result in a sleep operation,
/// with the current [`TimeoutStrategy`].
/// with the current [`SleepStrategy`].
pub async fn run<T, F, G>(&self, mut future_gen: G) -> T
where
G: FnMut() -> F,
Expand All @@ -56,7 +56,7 @@ impl TimeoutStrategy {
/// Run a time constrained task until the given deadline.
///
/// Different retries will result in a sleep operation,
/// with the current [`TimeoutStrategy`].
/// with the current [`SleepStrategy`].
pub async fn timeout<T, F, G>(
&self,
deadline: Instant,
Expand Down
6 changes: 3 additions & 3 deletions apps/src/lib/node/ledger/ethereum_oracle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use self::events::PendingEvent;
#[cfg(test)]
use self::test_tools::mock_web3_client::Web3;
use super::abortable::AbortableSpawner;
use crate::control_flow::timeouts::TimeoutStrategy;
use crate::control_flow::timeouts::SleepStrategy;
use crate::node::ledger::oracle::control::Command;

/// The default amount of time the oracle will wait between processing blocks
Expand Down Expand Up @@ -103,7 +103,7 @@ pub async fn eth_syncing_status(
backoff_duration: Duration,
deadline: Instant,
) -> Result<SyncStatus, Error> {
TimeoutStrategy::Constant(backoff_duration)
SleepStrategy::Constant(backoff_duration)
.timeout(deadline, || async {
ControlFlow::Break(match client.eth_block_number().await {
Ok(height) if height == 0u64.into() => SyncStatus::Syncing,
Expand Down Expand Up @@ -282,7 +282,7 @@ async fn run_oracle_aux(mut oracle: Oracle) {
"Checking Ethereum block for bridge events"
);
let deadline = Instant::now() + oracle.ceiling;
let res = TimeoutStrategy::Constant(oracle.backoff).run(|| async {
let res = SleepStrategy::Constant(oracle.backoff).run(|| async {
tokio::select! {
result = process(&oracle, &config, next_block_to_process.clone()) => {
match result {
Expand Down

0 comments on commit 5ebce67

Please sign in to comment.