Remove tokio dependency from tendermint-machine

Indirects it via a minimal wrapper which can be trivially patched.
This commit is contained in:
Luke Parker 2024-09-05 16:30:27 -04:00
parent efc7d70ab1
commit ac7b98daac
No known key found for this signature in database
10 changed files with 70 additions and 3 deletions

View file

@ -27,6 +27,7 @@ jobs:
GITHUB_CI=true RUST_BACKTRACE=1 cargo test --all-features \ GITHUB_CI=true RUST_BACKTRACE=1 cargo test --all-features \
-p std-shims \ -p std-shims \
-p zalloc \ -p zalloc \
-p patchable-async-sleep \
-p serai-db \ -p serai-db \
-p serai-env \ -p serai-env \
-p simple-request -p simple-request

8
Cargo.lock generated
View file

@ -5720,6 +5720,13 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "patchable-async-sleep"
version = "0.1.0"
dependencies = [
"tokio",
]
[[package]] [[package]]
name = "pbkdf2" name = "pbkdf2"
version = "0.11.0" version = "0.11.0"
@ -9843,6 +9850,7 @@ dependencies = [
"hex", "hex",
"log", "log",
"parity-scale-codec", "parity-scale-codec",
"patchable-async-sleep",
"serai-db", "serai-db",
"thiserror", "thiserror",
"tokio", "tokio",

View file

@ -18,6 +18,7 @@ members = [
"common/std-shims", "common/std-shims",
"common/zalloc", "common/zalloc",
"common/patchable-async-sleep",
"common/db", "common/db",
"common/env", "common/env",
"common/request", "common/request",

View file

@ -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 <lukeparker5132@gmail.com>"]
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"] }

View file

@ -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.

View file

@ -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.

View file

@ -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)
}

View file

@ -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-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"] } 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 } serai-db = { path = "../../../common/db", version = "0.1", default-features = false }

View file

@ -13,7 +13,7 @@ use futures_util::{
FutureExt, StreamExt, SinkExt, FutureExt, StreamExt, SinkExt,
future::{self, Fuse}, future::{self, Fuse},
}; };
use tokio::time::sleep; use patchable_async_sleep::sleep;
use serai_db::{Get, DbTxn, Db}; use serai_db::{Get, DbTxn, Db};

View file

@ -5,7 +5,7 @@ use std::{
}; };
use futures_util::{FutureExt, future}; use futures_util::{FutureExt, future};
use tokio::time::sleep; use patchable_async_sleep::sleep;
use crate::{ use crate::{
time::CanonicalInstant, time::CanonicalInstant,