diff --git a/.gitignore b/.gitignore index 6dc5000..55f0699 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ Cargo.lock .DS_Store test-crates/jsonrpsee-test/target +.vscode diff --git a/Cargo.toml b/Cargo.toml index 8950e53..20a5076 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,5 @@ members = [ "mocked-crates/futures-timer", ] exclude = [ - "tokio", "test-crates/jsonrpsee-test", ] diff --git a/msim-macros/Cargo.toml b/msim-macros/Cargo.toml index 584be1e..e1d9668 100644 --- a/msim-macros/Cargo.toml +++ b/msim-macros/Cargo.toml @@ -2,10 +2,10 @@ name = "msim-macros" version = "0.1.0" edition = "2021" -authors = ["Runji Wang ", "Mysten Labs "] +authors = ["IOTA Stiftung"] description = "Mysten sim's proc-macro." -homepage = "https://github.com/MystenLabs/mysten-simulator" -repository = "https://github.com/MystenLabs/mysten-simulator" +homepage = "https://www.iota.org/" +repository = "https://github.com/iotaledger/iota-sim" license = "Apache-2.0" categories = ["asynchronous"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/msim-macros/src/lib.rs b/msim-macros/src/lib.rs index 0f45a7f..4500265 100644 --- a/msim-macros/src/lib.rs +++ b/msim-macros/src/lib.rs @@ -1,19 +1,10 @@ //! Macros for use with Madsim -mod request; mod service; use proc_macro::TokenStream; use proc_macro2::{Ident, Span}; use quote::{quote, quote_spanned, ToTokens}; -use syn::DeriveInput; - -#[proc_macro_derive(Request, attributes(rtype))] -pub fn message_derive_rtype(input: TokenStream) -> TokenStream { - let ast: DeriveInput = syn::parse(input).unwrap(); - - request::expand(&ast).into() -} #[proc_macro_attribute] pub fn service(args: TokenStream, input: TokenStream) -> TokenStream { diff --git a/msim-macros/src/request.rs b/msim-macros/src/request.rs deleted file mode 100644 index b83690e..0000000 --- a/msim-macros/src/request.rs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) 2017 Actix Team -// -// 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. - -use proc_macro2::{Span, TokenStream}; -use quote::{quote, ToTokens}; - -pub const MESSAGE_ATTR: &str = "rtype"; - -pub fn expand(ast: &syn::DeriveInput) -> TokenStream { - let item_type = { - match get_attribute_type_multiple(ast, MESSAGE_ATTR) { - Ok(ty) => match ty.len() { - 1 => ty[0].clone(), - _ => { - return syn::Error::new( - Span::call_site(), - format!( - "#[{}(type)] takes 1 parameters, given {}", - MESSAGE_ATTR, - ty.len() - ), - ) - .to_compile_error() - } - }, - Err(err) => return err.to_compile_error(), - } - }; - - let name = &ast.ident; - let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl(); - - let item_type = item_type - .map(ToTokens::into_token_stream) - .unwrap_or_else(|| quote! { () }); - - quote! { - impl #impl_generics ::msim::net::rpc::Request for #name #ty_generics #where_clause { - type Response = #item_type; - const ID: u64 = ::msim::net::rpc::hash_str(concat!(module_path!(), stringify!(#name))); - } - } -} - -fn get_attribute_type_multiple( - ast: &syn::DeriveInput, - name: &str, -) -> syn::Result>> { - let attr = ast - .attrs - .iter() - .find_map(|a| { - let a = a.parse_meta(); - match a { - Ok(meta) => { - if meta.path().is_ident(name) { - Some(meta) - } else { - None - } - } - _ => None, - } - }) - .ok_or_else(|| { - syn::Error::new(Span::call_site(), format!("Expect an attribute `{}`", name)) - })?; - - if let syn::Meta::List(ref list) = attr { - Ok(list - .nested - .iter() - .map(|m| meta_item_to_ty(m).ok()) - .collect()) - } else { - Err(syn::Error::new_spanned( - attr, - format!("The correct syntax is #[{}(type, type, ...)]", name), - )) - } -} - -fn meta_item_to_ty(meta_item: &syn::NestedMeta) -> syn::Result { - match meta_item { - syn::NestedMeta::Meta(syn::Meta::Path(ref path)) => match path.get_ident() { - Some(ident) => syn::parse_str::(&ident.to_string()) - .map_err(|_| syn::Error::new_spanned(ident, "Expect type")), - None => Err(syn::Error::new_spanned(path, "Expect type")), - }, - syn::NestedMeta::Meta(syn::Meta::NameValue(val)) => match val.path.get_ident() { - Some(ident) if ident == "result" => { - if let syn::Lit::Str(ref s) = val.lit { - if let Ok(ty) = syn::parse_str::(&s.value()) { - return Ok(ty); - } - } - Err(syn::Error::new_spanned(&val.lit, "Expect type")) - } - _ => Err(syn::Error::new_spanned( - &val.lit, - r#"Expect `result = "TYPE"`"#, - )), - }, - syn::NestedMeta::Lit(syn::Lit::Str(ref s)) => syn::parse_str::(&s.value()) - .map_err(|_| syn::Error::new_spanned(s, "Expect type")), - - meta => Err(syn::Error::new_spanned(meta, "Expect type")), - } -} diff --git a/msim-tokio/Cargo.toml b/msim-tokio/Cargo.toml index d70cff7..8bf5a5f 100644 --- a/msim-tokio/Cargo.toml +++ b/msim-tokio/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "tokio" -version = "1.36.0" +version = "1.39.2" edition = "2021" -authors = ["Runji Wang ", "Mysten Labs "] +authors = ["IOTA Stiftung"] description = "The `tokio` simulator on msim." -homepage = "https://github.com/MystenLabs/mysten-simulator" -repository = "https://github.com/MystenLabs/mysten-simulator" +homepage = "https://www.iota.org/" +repository = "https://github.com/iotaledger/iota-sim" categories = ["asynchronous", "network-programming", "simulation"] keywords = ["io", "async", "non-blocking", "futures", "simulator"] readme = "README.md" @@ -47,21 +47,18 @@ test-util = ["real_tokio/test-util"] tracing = ["real_tokio/tracing"] bytes = ["real_tokio/bytes"] libc = ["real_tokio/libc"] -memchr = ["real_tokio/memchr"] mio = ["real_tokio/mio"] -num_cpus = ["real_tokio/num_cpus"] signal-hook-registry = ["real_tokio/signal-hook-registry"] socket2 = ["real_tokio/socket2"] -stats = ["real_tokio/stats"] tokio-macros = ["real_tokio/tokio-macros"] [target.'cfg(msim)'.dependencies] -msim = { version = "0.1.0", path = "../msim" } +msim.path = "../msim" [dependencies] tracing = "0.1" -real_tokio = { git = "https://github.com/mystenmark/tokio-madsim-fork.git", rev = "e47aafebf98e9c1734a8848a1876d5946c44bdd1", package = "real_tokio", features = ["full"] } -bytes = { version = "1.1" } -futures = { version = "0.3.0", features = ["async-await"] } -mio = { version = "0.8.1" } +real_tokio = { git = "ssh://git@github.com/iotaledger/tokio-madsim-fork.git", branch = "main", package = "real_tokio", features = ["full"] } +bytes = { version = "1.7" } +futures = { version = "0.3", features = ["async-await"] } +mio = { version = "1.0" } diff --git a/msim-tokio/build.rs b/msim-tokio/build.rs new file mode 100644 index 0000000..1b1f7db --- /dev/null +++ b/msim-tokio/build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo::rustc-check-cfg=cfg(msim)"); +} diff --git a/msim-tokio/src/sim/runtime.rs b/msim-tokio/src/sim/runtime.rs index 8064871..a26b6de 100644 --- a/msim-tokio/src/sim/runtime.rs +++ b/msim-tokio/src/sim/runtime.rs @@ -76,7 +76,10 @@ impl Handle { } } -pub struct EnterGuard<'a>(ms_runtime::EnterGuard, std::marker::PhantomData<&'a Handle>); +pub struct EnterGuard<'a>( + #[expect(unused)] ms_runtime::EnterGuard, + std::marker::PhantomData<&'a Handle>, +); #[derive(Clone, Debug, Hash, Eq, PartialEq)] pub struct Id(u64); diff --git a/msim/Cargo.toml b/msim/Cargo.toml index 7f10c2b..b3dbf33 100644 --- a/msim/Cargo.toml +++ b/msim/Cargo.toml @@ -2,59 +2,53 @@ name = "msim" version = "0.1.0" edition = "2021" -authors = ["Runji Wang ", "Mysten Labs "] +authors = ["IOTA Stiftung"] description = "Deterministic Simulator for distributed systems." readme = "../README.md" -homepage = "https://github.com/MystenLabs/mysten-simulator" -repository = "https://github.com/MystenLabs/mysten-simulator" +homepage = "https://www.iota.org/" +repository = "https://github.com/iotaledger/iota-sim" license = "Apache-2.0" keywords = ["distributed-systems", "async", "deterministic", "simulation"] categories = ["asynchronous", "simulation"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["macros", "rpc"] -rpc = ["bincode"] +default = ["macros"] macros = ["msim-macros", "tokio/macros"] [dependencies] -bincode = { version = "1", optional = true } -bytes = "1" +bytes = "1.7" futures = "0.3" -lazy_static = "1.4" +lazy_static = "1.5" tracing = "0.1" tracing-subscriber = "0.3" -msim-macros = { version = "0.1.0", path = "../msim-macros", optional = true } +msim-macros = { version = "0.1", path = "../msim-macros", optional = true } rand = { version = "0.8", features = ["small_rng"] } -serde = { version = "1", features = ["derive"] } +serde = { version = "1.0", features = ["derive"] } pin-project-lite = "0.2" -tap = "1" +tap = "1.0" [build-dependencies] -cc = { version = "1.0" } +cc = { version = "1.1" } [target.'cfg(msim)'.dependencies] -ahash = "0.7" +ahash = "0.8" downcast-rs = "1.2" libc = "0.2" naive-timer = "0.2" -tokio = { git = "https://github.com/mystenmark/tokio-madsim-fork.git", rev = "e47aafebf98e9c1734a8848a1876d5946c44bdd1", package = "real_tokio", features = ["full"] } -tokio-util = { git = "https://github.com/mystenmark/tokio-madsim-fork.git", rev = "e47aafebf98e9c1734a8848a1876d5946c44bdd1", features = ["full"] } -toml = "0.5" -socket2 = "0.4" +tokio = { git = "ssh://git@github.com/iotaledger/tokio-madsim-fork.git", branch = "main", package = "real_tokio", features = ["full"] } +tokio-util = { git = "ssh://git@github.com/iotaledger/tokio-madsim-fork.git", branch = "main", features = ["full"] } +toml = "0.8" +socket2 = "0.5" erasable = "1.2" # TODO: revert back to the crates-io version after https://github.com/smol-rs/async-task/pull/34 merges async-task = { git = "https://github.com/mystenmark/async-task", rev = "4e45b26e11126b191701b9b2ce5e2346b8d7682f" } [dev-dependencies] -criterion = "0.3" +criterion = "0.5" structopt = "0.3" -tokio = { git = "https://github.com/mystenmark/tokio-madsim-fork.git", rev = "e47aafebf98e9c1734a8848a1876d5946c44bdd1", package = "real_tokio", features = ["full"] } - -[[bench]] -name = "rpc" -harness = false +tokio = { git = "ssh://git@github.com/iotaledger/tokio-madsim-fork.git", branch = "main", package = "real_tokio", features = ["full"] } [package.metadata.docs.rs] # all-features = true diff --git a/msim/benches/rpc.rs b/msim/benches/rpc.rs deleted file mode 100644 index 0fa24df..0000000 --- a/msim/benches/rpc.rs +++ /dev/null @@ -1,56 +0,0 @@ -use std::sync::Arc; - -use criterion::*; -use msim::{net::Endpoint, Request}; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Request)] -#[rtype("()")] -struct Req; - -fn empty_rpc(c: &mut Criterion) { - let rt = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap(); - let addr = rt.block_on(async move { - let net = Arc::new(Endpoint::bind("127.0.0.1:0").await.unwrap()); - net.add_rpc_handler(|_: Req| async move {}); - net.local_addr().unwrap() - }); - - c.bench_function("empty RPC", |b| { - let net = rt.block_on(Endpoint::bind("127.0.0.1:0")).unwrap(); - b.iter(|| rt.block_on(net.call(addr, Req)).unwrap()); - }); -} - -fn rpc_data(c: &mut Criterion) { - let rt = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap(); - let addr = rt.block_on(async move { - let net = Arc::new(Endpoint::bind("127.0.0.1:0").await.unwrap()); - net.add_rpc_handler_with_data(|_: Req, data| async move { - black_box(data); - ((), vec![]) - }); - net.local_addr().unwrap() - }); - - let mut group = c.benchmark_group("RPC with data"); - group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic)); - for size in [16, 256, 4096, 65536, 1048576] { - group.throughput(Throughput::Bytes(size as u64)); - group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { - let data = vec![0u8; size]; - let net = rt.block_on(Endpoint::bind("127.0.0.1:0")).unwrap(); - b.iter(|| rt.block_on(net.call_with_data(addr, Req, &data)).unwrap()); - }); - } - group.finish(); -} - -criterion_group!(benches, empty_rpc, rpc_data); -criterion_main!(benches); diff --git a/msim/build.rs b/msim/build.rs index b6db358..fe3443c 100644 --- a/msim/build.rs +++ b/msim/build.rs @@ -1,4 +1,5 @@ fn main() { + println!("cargo::rustc-check-cfg=cfg(msim)"); #[cfg(target_os = "linux")] { println!("cargo:rerun-if-changed=src/sim/syscall.c"); diff --git a/msim/src/lib.rs b/msim/src/lib.rs index afdc31a..b3d7987 100644 --- a/msim/src/lib.rs +++ b/msim/src/lib.rs @@ -8,10 +8,6 @@ #![cfg_attr(docsrs, feature(doc_cfg))] -#[cfg(all(feature = "rpc", feature = "macros"))] -#[cfg_attr(docsrs, doc(cfg(all(feature = "rpc", feature = "macros"))))] -pub use msim_macros::{service, Request}; - pub use tracing; #[cfg(msim)] diff --git a/msim/src/sim/net/mod.rs b/msim/src/sim/net/mod.rs index f9cfda9..24fd2da 100644 --- a/msim/src/sim/net/mod.rs +++ b/msim/src/sim/net/mod.rs @@ -219,7 +219,7 @@ pub fn get_endpoint_from_socket(fd: libc::c_int) -> io::Result> { } unsafe fn make_sockaddr(sock_addr: *const libc::sockaddr, addr_len: libc::socklen_t) -> SocketAddr { - socket2::SockAddr::init(|storage, len| { + socket2::SockAddr::try_init(|storage, len| { std::ptr::copy_nonoverlapping( sock_addr as *const u8, storage as *mut u8, @@ -544,8 +544,7 @@ define_sys_interceptor!( match (level, name) { // called by anemo::Network::start (via socket2) // skip returning any value here since Sui only uses it to log an error anyway - (libc::SOL_SOCKET, libc::SO_RCVBUF) | - (libc::SOL_SOCKET, libc::SO_SNDBUF) => 0, + (libc::SOL_SOCKET, libc::SO_RCVBUF) | (libc::SOL_SOCKET, libc::SO_SNDBUF) => 0, _ => { warn!("unhandled getsockopt {} {}", level, name); @@ -653,7 +652,7 @@ impl UDPMessage { } unsafe fn msg_hdr_to_socket(msg: &libc::msghdr) -> SocketAddr { - socket2::SockAddr::init(|storage, len| { + socket2::SockAddr::try_init(|storage, len| { std::ptr::copy_nonoverlapping( msg.msg_name as *const u8, storage as *mut u8, diff --git a/msim/src/sim/runtime/mod.rs b/msim/src/sim/runtime/mod.rs index a2d6876..983e060 100644 --- a/msim/src/sim/runtime/mod.rs +++ b/msim/src/sim/runtime/mod.rs @@ -365,7 +365,7 @@ impl Handle { } /// Guard for entering handle -pub struct EnterGuard(context::EnterGuard); +pub struct EnterGuard(#[expect(unused)] context::EnterGuard); /// Builds a node with custom configurations. pub struct NodeBuilder<'a> { @@ -429,7 +429,7 @@ impl<'a> NodeBuilder<'a> { /// Guard for entering a node context. #[must_use] -pub struct NodeEnterGuard(TaskEnterGuard); +pub struct NodeEnterGuard(#[expect(unused)] TaskEnterGuard); /// Handle to a node. #[derive(Clone)] diff --git a/msim/src/sim/task.rs b/msim/src/sim/task.rs index 84d6593..4e76b61 100644 --- a/msim/src/sim/task.rs +++ b/msim/src/sim/task.rs @@ -73,14 +73,14 @@ struct PanicWrapper { restart_after: Option, } -struct PanicHookGuard(Option) + Sync + Send + 'static>>); +struct PanicHookGuard(Option) + Sync + Send + 'static>>); impl PanicHookGuard { fn new() -> Self { Self(Some(std::panic::take_hook())) } - fn call_hook(&self, info: &std::panic::PanicInfo<'_>) { + fn call_hook(&self, info: &std::panic::PanicHookInfo<'_>) { self.0.as_ref().unwrap()(info); } } diff --git a/msim/src/sim/task/join_set.rs b/msim/src/sim/task/join_set.rs index 49ee26b..d528c33 100644 --- a/msim/src/sim/task/join_set.rs +++ b/msim/src/sim/task/join_set.rs @@ -11,8 +11,6 @@ use futures::future::poll_fn; use futures::stream::{FuturesUnordered, Stream}; use crate::runtime::Handle; -#[cfg(tokio_unstable)] -use crate::task::Id; use crate::task::{AbortHandle, JoinError, JoinHandle}; use tokio::task::LocalSet;