Skip to content

Commit

Permalink
Remove tokio dependency from tendermint-machine
Browse files Browse the repository at this point in the history
Indirects it via a minimal wrapper which can be trivially patched.
  • Loading branch information
kayabaNerve committed Sep 5, 2024
1 parent efc7d70 commit ac7b98d
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/common-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
GITHUB_CI=true RUST_BACKTRACE=1 cargo test --all-features \
-p std-shims \
-p zalloc \
-p patchable-async-sleep \
-p serai-db \
-p serai-env \
-p simple-request
8 changes: 8 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [

"common/std-shims",
"common/zalloc",
"common/patchable-async-sleep",
"common/db",
"common/env",
"common/request",
Expand Down
19 changes: 19 additions & 0 deletions common/patchable-async-sleep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "patchable-async-sleep"
version = "0.1.0"
description = "An async sleep function, patchable to the preferred runtime"
license = "MIT"
repository = "https://github.com/serai-dex/serai/tree/develop/common/patchable-async-sleep"
authors = ["Luke Parker <[email protected]>"]
keywords = ["async", "sleep", "tokio", "smol", "async-std"]
edition = "2021"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints]
workspace = true

[dependencies]
tokio = { version = "1", default-features = false, features = [ "time"] }
21 changes: 21 additions & 0 deletions common/patchable-async-sleep/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Luke Parker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions common/patchable-async-sleep/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Patchable Async Sleep

An async sleep function, patchable to the preferred runtime.

This crate is `tokio`-backed. Applications which don't want to use `tokio`
should patch this crate to one which works witht heir preferred runtime. The
point of it is to have a minimal API surface to trivially facilitate such work.
10 changes: 10 additions & 0 deletions common/patchable-async-sleep/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![deny(missing_docs)]

use core::time::Duration;

/// Sleep for the specified duration.
pub fn sleep(duration: Duration) -> impl core::future::Future<Output = ()> {
tokio::time::sleep(duration)
}
2 changes: 1 addition & 1 deletion coordinator/tributary/tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ parity-scale-codec = { version = "3", default-features = false, features = ["std

futures-util = { version = "0.3", default-features = false, features = ["std", "async-await-macro", "sink", "channel"] }
futures-channel = { version = "0.3", default-features = false, features = ["std", "sink"] }
tokio = { version = "1", default-features = false, features = ["time"] }
patchable-async-sleep = { version = "0.1", path = "../../../common/patchable-async-sleep", default-features = false }

serai-db = { path = "../../../common/db", version = "0.1", default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion coordinator/tributary/tendermint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use futures_util::{
FutureExt, StreamExt, SinkExt,
future::{self, Fuse},
};
use tokio::time::sleep;
use patchable_async_sleep::sleep;

use serai_db::{Get, DbTxn, Db};

Expand Down
2 changes: 1 addition & 1 deletion coordinator/tributary/tendermint/src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use futures_util::{FutureExt, future};
use tokio::time::sleep;
use patchable_async_sleep::sleep;

use crate::{
time::CanonicalInstant,
Expand Down

0 comments on commit ac7b98d

Please sign in to comment.