diff --git a/Cargo.lock b/Cargo.lock index 429c29684f..c1ed1d98ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -245,9 +245,9 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "alloy-chains" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "805f7a974de5804f5c053edc6ca43b20883bdd3a733b3691200ae3a4b454a2db" +checksum = "8158b4878c67837e5413721cc44298e6a2d88d39203175ea025e51892a16ba4c" dependencies = [ "num_enum", "strum", @@ -329,7 +329,7 @@ dependencies = [ "alloy-sol-types", "serde", "serde_json", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "tracing", ] @@ -351,7 +351,7 @@ dependencies = [ "async-trait", "auto_impl", "futures-utils-wasm", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -378,30 +378,35 @@ dependencies = [ "rand", "serde_json", "tempfile", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "tracing", "url", ] [[package]] name = "alloy-primitives" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "411aff151f2a73124ee473708e82ed51b2535f68928b6a1caa8bc1246ae6f7cd" +checksum = "260d3ff3bff0bb84599f032a2f2c6828180b0ea0cd41fdaf44f39cef3ba41861" dependencies = [ "alloy-rlp", "bytes", "cfg-if", "const-hex", "derive_more 1.0.0", + "hashbrown", "hex-literal", + "indexmap", "itoa", "k256", "keccak-asm", + "paste", "proptest", "rand", "ruint", + "rustc-hash 2.0.0", "serde", + "sha3", "tiny-keccak", ] @@ -433,7 +438,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "tokio", "tracing", "url", @@ -477,7 +482,7 @@ dependencies = [ "serde_json", "tokio", "tokio-stream", - "tower 0.5.1", + "tower", "tracing", "url", ] @@ -551,14 +556,14 @@ dependencies = [ "auto_impl", "elliptic-curve", "k256", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "alloy-sol-macro" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0458ccb02a564228fcd76efb8eb5a520521a8347becde37b402afec9a1b83859" +checksum = "68e7f6e8fe5b443f82b3f1e15abfa191128f71569148428e49449d01f6f49e8b" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -570,9 +575,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc65475025fc1e84bf86fc840f04f63fcccdcf3cf12053c99918e4054dfbc69" +checksum = "6b96ce28d2fde09abb6135f410c41fad670a3a770b6776869bd852f1df102e6f" dependencies = [ "alloy-sol-macro-input", "const-hex", @@ -588,9 +593,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed10f0715a0b69fde3236ff3b9ae5f6f7c97db5a387747100070d3016b9266b" +checksum = "906746396a8296537745711630d9185746c0b50c033d5e9d18b0a6eba3d53f90" dependencies = [ "const-hex", "dunce", @@ -603,9 +608,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1eb88e4da0a1b697ed6a9f811fdba223cf4d5c21410804fd1707836af73a462b" +checksum = "d86a533ce22525969661b25dfe296c112d35eb6861f188fd284f8bd4bb3842ae" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -624,9 +629,9 @@ dependencies = [ "futures-utils-wasm", "serde", "serde_json", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "tokio", - "tower 0.5.1", + "tower", "tracing", "url", ] @@ -641,7 +646,7 @@ dependencies = [ "alloy-transport", "reqwest", "serde_json", - "tower 0.5.1", + "tower", "tracing", "url", ] @@ -876,9 +881,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", @@ -966,7 +971,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn 2.0.77", ] @@ -1266,7 +1271,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bb11bd1378bf3731b182997b40cefe00aba6a6cc74042c8318c1b271d3badf7" dependencies = [ "nix 0.27.1", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "tokio", ] @@ -2083,9 +2088,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-channel", @@ -2096,7 +2101,6 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower 0.4.13", "tower-service", "tracing", ] @@ -2145,6 +2149,7 @@ checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown", + "serde", ] [[package]] @@ -2252,6 +2257,15 @@ dependencies = [ "sha2", ] +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + [[package]] name = "keccak-asm" version = "0.1.4" @@ -2300,7 +2314,7 @@ version = "0.0.3" dependencies = [ "cfg-if", "linked_list_allocator", - "thiserror 1.0.63", + "thiserror 1.0.64 (git+https://github.com/quartiq/thiserror?branch=no-std)", ] [[package]] @@ -2348,7 +2362,7 @@ dependencies = [ "serde", "serde_json", "spin", - "thiserror 1.0.63", + "thiserror 1.0.64 (git+https://github.com/quartiq/thiserror?branch=no-std)", "tokio", "tracing", "tracing-subscriber", @@ -2375,7 +2389,7 @@ dependencies = [ "revm", "serde", "serde_json", - "thiserror 1.0.63", + "thiserror 1.0.64 (git+https://github.com/quartiq/thiserror?branch=no-std)", "tracing", ] @@ -2435,7 +2449,7 @@ dependencies = [ "rand", "reqwest", "revm", - "thiserror 1.0.63", + "thiserror 1.0.64 (git+https://github.com/quartiq/thiserror?branch=no-std)", "tokio", "tracing", "tracing-subscriber", @@ -2451,7 +2465,7 @@ dependencies = [ "os_pipe", "rkyv", "serde", - "thiserror 1.0.63", + "thiserror 1.0.64 (git+https://github.com/quartiq/thiserror?branch=no-std)", "tokio", "tracing", ] @@ -2468,7 +2482,7 @@ dependencies = [ "serde", "serde_json", "sha2", - "thiserror 1.0.63", + "thiserror 1.0.64 (git+https://github.com/quartiq/thiserror?branch=no-std)", "tracing", ] @@ -2495,9 +2509,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libloading" @@ -3090,7 +3104,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9" dependencies = [ "memchr", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "ucd-trie", ] @@ -3138,9 +3152,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "plotters" @@ -3195,7 +3209,7 @@ dependencies = [ "smallvec", "symbolic-demangle", "tempfile", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3304,7 +3318,7 @@ dependencies = [ "parking_lot", "procfs", "protobuf", - "thiserror 1.0.64", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3433,6 +3447,7 @@ dependencies = [ "libc", "rand_chacha", "rand_core", + "serde", ] [[package]] @@ -3485,9 +3500,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "355ae415ccd3a04315d3f8246e86d67689ea74d88d915576e1589a351062a13b" dependencies = [ "bitflags 2.6.0", ] @@ -3581,9 +3596,9 @@ dependencies = [ [[package]] name = "revm" -version = "14.0.2" +version = "14.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9f3f55d0414c3d73902d876ba3d55a654f05fe937089fbf5f34b1ced26d78d5" +checksum = "641702b12847f9ed418d552f4fcabe536d867a2c980e96b6e7e25d7b992f929f" dependencies = [ "auto_impl", "cfg-if", @@ -3596,9 +3611,9 @@ dependencies = [ [[package]] name = "revm-interpreter" -version = "10.0.2" +version = "10.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713dbb271acd13afb06dcd460c1dc43da211e7ac9bc73cdf13528f615f55f96b" +checksum = "2e5e14002afae20b5bf1566f22316122f42f57517000e559c55b25bf7a49cba2" dependencies = [ "revm-primitives", "serde", @@ -3606,9 +3621,9 @@ dependencies = [ [[package]] name = "revm-precompile" -version = "11.0.2" +version = "11.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73010c271d53fa7904e9845338e95f3955eb1200a0355e0abfdb89c41aaa9cd" +checksum = "3198c06247e8d4ad0d1312591edf049b0de4ddffa9fecb625c318fd67db8639b" dependencies = [ "aurora-engine-modexp", "blst", @@ -3626,11 +3641,12 @@ dependencies = [ [[package]] name = "revm-primitives" -version = "9.0.2" +version = "10.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7a6bff9dbde3370a5ac9555104117f7e6039b3cc76e8d5d9d01899088beca2a" +checksum = "6f1525851a03aff9a9d6a1d018b414d76252d6802ab54695b27093ecd7e7a101" dependencies = [ - "alloy-eips", + "alloy-eip2930", + "alloy-eip7702", "alloy-primitives", "auto_impl", "bitflags 2.6.0", @@ -3639,7 +3655,6 @@ dependencies = [ "cfg-if", "dyn-clone", "enumn", - "hashbrown", "hex", "serde", ] @@ -3779,6 +3794,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -4062,6 +4083,16 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + [[package]] name = "sha3-asm" version = "0.1.4" @@ -4297,9 +4328,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b95156f8b577cb59dc0b1df15c6f29a10afc5f8a7ac9786b0b5c68c19149278" +checksum = "0ab661c8148c2261222a4d641ad5477fd4bea79406a99056096a0b41b35617a5" dependencies = [ "paste", "proc-macro2", @@ -4364,25 +4395,26 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" -source = "git+https://github.com/quartiq/thiserror?branch=no-std#44737a516b7fd0cc9dabcab07e7b1f927f8f5636" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ - "thiserror-impl 1.0.63", + "thiserror-impl 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "thiserror" version = "1.0.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +source = "git+https://github.com/quartiq/thiserror?branch=no-std#e779e1b70023cee5807f378e147f66387d1ccd4f" dependencies = [ - "thiserror-impl 1.0.64", + "thiserror-impl 1.0.64 (git+https://github.com/quartiq/thiserror?branch=no-std)", ] [[package]] name = "thiserror-impl" -version = "1.0.63" -source = "git+https://github.com/quartiq/thiserror?branch=no-std#44737a516b7fd0cc9dabcab07e7b1f927f8f5636" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -4392,8 +4424,7 @@ dependencies = [ [[package]] name = "thiserror-impl" version = "1.0.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +source = "git+https://github.com/quartiq/thiserror?branch=no-std#e779e1b70023cee5807f378e147f66387d1ccd4f" dependencies = [ "proc-macro2", "quote", @@ -4567,30 +4598,15 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.22.21" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "toml_datetime", "winnow", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", -] - [[package]] name = "tower" version = "0.5.1" @@ -5116,9 +5132,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index e5e9267d2f..39e5bc5590 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,25 @@ default-members = ["bin/host", "bin/client"] # https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html resolver = "2" +[workspace.lints.rust] +missing-debug-implementations = "warn" +missing-docs = "warn" +unreachable-pub = "warn" +unused-must-use = "deny" +rust-2018-idioms = "deny" +unnameable-types = "warn" + +[workspace.lints.rustdoc] +all = "warn" + +[workspace.lints.clippy] +needless-return = "allow" # Temporary fix since this is breaking in nightly clippy +all = { level = "warn", priority = -1 } +missing-const-for-fn = "warn" +use-self = "warn" +option-if-let-else = "warn" +redundant-clone = "warn" + [profile.dev] opt-level = 1 overflow-checks = false diff --git a/bin/host/Cargo.toml b/bin/host/Cargo.toml index 3bbf7fcd29..75431b8aba 100644 --- a/bin/host/Cargo.toml +++ b/bin/host/Cargo.toml @@ -8,6 +8,9 @@ repository.workspace = true homepage.workspace = true publish = false +[lints] +workspace = true + [dependencies] # Workspace kona-mpt.workspace = true diff --git a/bin/host/src/cli/mod.rs b/bin/host/src/cli/mod.rs index 2ed6b378ac..e772ef3fcd 100644 --- a/bin/host/src/cli/mod.rs +++ b/bin/host/src/cli/mod.rs @@ -116,7 +116,7 @@ pub struct HostCli { impl HostCli { /// Returns `true` if the host is running in offline mode. - pub fn is_offline(&self) -> bool { + pub const fn is_offline(&self) -> bool { self.l1_node_address.is_none() && self.l2_node_address.is_none() && self.l1_beacon_address.is_none() @@ -190,7 +190,7 @@ impl HostCli { } /// Styles for the CLI application. -fn cli_styles() -> clap::builder::Styles { +const fn cli_styles() -> clap::builder::Styles { clap::builder::Styles::styled() .usage(Style::new().bold().underline().fg_color(Some(Color::Ansi(AnsiColor::Yellow)))) .header(Style::new().bold().underline().fg_color(Some(Color::Ansi(AnsiColor::Yellow)))) diff --git a/bin/host/src/cli/parser.rs b/bin/host/src/cli/parser.rs index 82293009e6..a83ba55993 100644 --- a/bin/host/src/cli/parser.rs +++ b/bin/host/src/cli/parser.rs @@ -8,6 +8,6 @@ use std::str::FromStr; /// /// # Returns /// * `Result` - Ok if successful, Err otherwise. -pub fn parse_b256(s: &str) -> Result { +pub(crate) fn parse_b256(s: &str) -> Result { B256::from_str(s).map_err(|_| format!("Invalid B256 value: {}", s)) } diff --git a/bin/host/src/fetcher/mod.rs b/bin/host/src/fetcher/mod.rs index 55a674ca0e..7ef9c15628 100644 --- a/bin/host/src/fetcher/mod.rs +++ b/bin/host/src/fetcher/mod.rs @@ -48,7 +48,7 @@ where KV: KeyValueStore + ?Sized, { /// Create a new [Fetcher] with the given [KeyValueStore]. - pub fn new( + pub const fn new( kv_store: Arc>, l1_provider: ReqwestProvider, blob_provider: OnlineBlobProvider, @@ -253,18 +253,16 @@ where let precompile_input = hint_data[20..].to_vec(); let input_hash = keccak256(hint_data.as_ref()); - let result = match precompiles::execute(precompile_address, precompile_input) { - Ok(raw_res) => { - let mut res = Vec::with_capacity(1 + raw_res.len()); - res.push(0x01); // success type byte - res.extend_from_slice(&raw_res); - res - } - Err(_) => { - // failure type byte - vec![0u8; 1] - } - }; + let result = precompiles::execute(precompile_address, precompile_input) + .map_or_else( + |_| vec![0u8; 1], + |raw_res| { + let mut res = Vec::with_capacity(1 + raw_res.len()); + res.push(0x01); + res.extend_from_slice(&raw_res); + res + }, + ); // Acquire a lock on the key-value store and set the preimages. let mut kv_lock = self.kv_store.write().await; diff --git a/bin/host/src/kv/disk.rs b/bin/host/src/kv/disk.rs index 48aa03b1ac..c47e9c7c07 100644 --- a/bin/host/src/kv/disk.rs +++ b/bin/host/src/kv/disk.rs @@ -51,8 +51,8 @@ impl Drop for DiskKeyValueStore { impl TryFrom for MemoryKeyValueStore { type Error = anyhow::Error; - fn try_from(disk_store: DiskKeyValueStore) -> Result { - let mut memory_store = MemoryKeyValueStore::new(); + fn try_from(disk_store: DiskKeyValueStore) -> Result { + let mut memory_store = Self::new(); let mut db_iter = disk_store.db.full_iterator(rocksdb::IteratorMode::Start); while let Some(Ok((key, value))) = db_iter.next() { diff --git a/bin/host/src/kv/local.rs b/bin/host/src/kv/local.rs index 964ce725ce..ed675083e8 100644 --- a/bin/host/src/kv/local.rs +++ b/bin/host/src/kv/local.rs @@ -21,7 +21,7 @@ pub struct LocalKeyValueStore { impl LocalKeyValueStore { /// Create a new [LocalKeyValueStore] with the given [HostCli] config. - pub fn new(cfg: HostCli) -> Self { + pub const fn new(cfg: HostCli) -> Self { Self { cfg } } } diff --git a/bin/host/src/kv/split.rs b/bin/host/src/kv/split.rs index 2ec1f215bc..325c3af213 100644 --- a/bin/host/src/kv/split.rs +++ b/bin/host/src/kv/split.rs @@ -24,7 +24,7 @@ where R: KeyValueStore, { /// Create a new [SplitKeyValueStore] with the given left and right [KeyValueStore]s. - pub fn new(local_store: L, remote_store: R) -> Self { + pub const fn new(local_store: L, remote_store: R) -> Self { Self { local_store, remote_store } } } diff --git a/bin/host/src/lib.rs b/bin/host/src/lib.rs index 88ea04a5f4..8712a52734 100644 --- a/bin/host/src/lib.rs +++ b/bin/host/src/lib.rs @@ -1,6 +1,4 @@ #![doc = include_str!("../README.md")] -#![warn(missing_debug_implementations, missing_docs, rustdoc::all)] -#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] diff --git a/bin/host/src/main.rs b/bin/host/src/main.rs index 648531f6de..d6992589f1 100644 --- a/bin/host/src/main.rs +++ b/bin/host/src/main.rs @@ -1,3 +1,5 @@ +//! Main entrypoint for the host binary. + use anyhow::Result; use clap::Parser; use kona_host::{init_tracing_subscriber, start_server, start_server_and_native_client, HostCli}; diff --git a/bin/host/src/preimage.rs b/bin/host/src/preimage.rs index a9e57f5e19..d184016f25 100644 --- a/bin/host/src/preimage.rs +++ b/bin/host/src/preimage.rs @@ -37,7 +37,7 @@ where KV: KeyValueStore + ?Sized, { /// Create a new [OnlinePreimageFetcher] from the given [Fetcher]. - pub fn new(fetcher: Arc>>) -> Self { + pub const fn new(fetcher: Arc>>) -> Self { Self { inner: fetcher } } } @@ -67,7 +67,7 @@ where KV: KeyValueStore + ?Sized, { /// Create a new [OfflinePreimageFetcher] from the given [KeyValueStore]. - pub fn new(kv_store: Arc>) -> Self { + pub const fn new(kv_store: Arc>) -> Self { Self { inner: kv_store } } } @@ -98,7 +98,7 @@ where KV: KeyValueStore + ?Sized, { /// Create a new [OnlineHintRouter] from the given [Fetcher]. - pub fn new(fetcher: Arc>>) -> Self { + pub const fn new(fetcher: Arc>>) -> Self { Self { inner: fetcher } } } diff --git a/bin/host/src/server.rs b/bin/host/src/server.rs index 847be377d5..2a1e3e0d98 100644 --- a/bin/host/src/server.rs +++ b/bin/host/src/server.rs @@ -45,7 +45,7 @@ where /// Create a new [PreimageServer] with the given [PreimageOracleServer], /// [HintReaderServer], and [KeyValueStore]. Holds onto the file descriptors for the pipes /// that are created, so that the pipes are not closed until the server is dropped. - pub fn new( + pub const fn new( oracle_server: P, hint_reader: H, kv_store: Arc>, diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 50922992e8..c6d85d2c2d 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -8,6 +8,9 @@ license.workspace = true repository.workspace = true homepage.workspace = true +[lints] +workspace = true + [dependencies] thiserror.workspace = true cfg-if.workspace = true diff --git a/crates/common/src/asterisc/io.rs b/crates/common/src/asterisc/io.rs index 116b7ac4e2..433ac67adc 100644 --- a/crates/common/src/asterisc/io.rs +++ b/crates/common/src/asterisc/io.rs @@ -2,7 +2,7 @@ use crate::{asterisc::syscall, errors::IOResult, BasicKernelInterface, FileDescr /// Concrete implementation of the [`KernelIO`] trait for the `riscv64` target architecture. #[derive(Debug)] -pub struct AsteriscIO; +pub(crate) struct AsteriscIO; /// Relevant system call numbers for the `riscv64` target architecture. /// diff --git a/crates/common/src/cannon/io.rs b/crates/common/src/cannon/io.rs index 2a1b9ecb84..3468d0b551 100644 --- a/crates/common/src/cannon/io.rs +++ b/crates/common/src/cannon/io.rs @@ -3,7 +3,7 @@ use crate::{cannon::syscall, errors::IOResult, BasicKernelInterface, FileDescrip /// Concrete implementation of the [BasicKernelInterface] trait for the `MIPS32rel1` target /// architecture. Exposes a safe interface for performing IO operations within the FPVM kernel. #[derive(Debug)] -pub struct CannonIO; +pub(crate) struct CannonIO; /// Relevant system call numbers for the `MIPS32rel1` target architecture. /// diff --git a/crates/common/src/executor.rs b/crates/common/src/executor.rs index 46c4f6c4e5..09616a9537 100644 --- a/crates/common/src/executor.rs +++ b/crates/common/src/executor.rs @@ -16,7 +16,7 @@ pub fn block_on(f: impl Future) -> T { fn noop_clone(_: *const ()) -> RawWaker { noop_raw_waker() } - fn noop(_: *const ()) {} + const fn noop(_: *const ()) {} fn noop_raw_waker() -> RawWaker { let vtable = &RawWakerVTable::new(noop_clone, noop, noop, noop); RawWaker::new(core::ptr::null(), vtable) diff --git a/crates/common/src/io.rs b/crates/common/src/io.rs index e0300b66f3..eb3f6fa74f 100644 --- a/crates/common/src/io.rs +++ b/crates/common/src/io.rs @@ -1,4 +1,4 @@ -//! This module contains the [ClientIO] struct, which is used to perform various IO operations +//! This module contains the `ClientIO` struct, which is used to perform various IO operations //! inside of the FPVM kernel within a `client` program. use crate::{errors::IOResult, BasicKernelInterface, FileDescriptor}; @@ -7,16 +7,16 @@ use cfg_if::cfg_if; cfg_if! { if #[cfg(target_arch = "mips")] { #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `MIPS32rel1` target architecture."] - pub type ClientIO = crate::cannon::io::CannonIO; + pub(crate) type ClientIO = crate::cannon::io::CannonIO; } else if #[cfg(target_arch = "riscv64")] { #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `riscv64` target architecture."] - pub type ClientIO = crate::asterisc::io::AsteriscIO; + pub(crate) type ClientIO = crate::asterisc::io::AsteriscIO; } else if #[cfg(target_os = "zkvm")] { #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `SP1` target architecture."] - pub type ClientIO = crate::zkvm::io::ZkvmIO; + pub(crate) type ClientIO = crate::zkvm::io::ZkvmIO; } else { #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `native` target architecture."] - pub type ClientIO = native_io::NativeIO; + pub(crate) type ClientIO = native_io::NativeIO; } } @@ -56,8 +56,9 @@ pub fn exit(code: usize) -> ! { ClientIO::exit(code) } +/// Native IO Module #[cfg(not(any(target_arch = "mips", target_arch = "riscv64", target_os = "zkvm")))] -mod native_io { +pub(crate) mod native_io { use crate::{ errors::{IOError, IOResult}, io::FileDescriptor, @@ -71,7 +72,7 @@ mod native_io { /// Mock IO implementation for native tests. #[derive(Debug)] - pub struct NativeIO; + pub(crate) struct NativeIO; impl BasicKernelInterface for NativeIO { fn write(fd: FileDescriptor, buf: &[u8]) -> IOResult { diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 958693b548..fde225a3b6 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1,6 +1,4 @@ #![doc = include_str!("../README.md")] -#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] -#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(target_arch = "mips", feature(asm_experimental_arch))] #![cfg_attr(any(target_arch = "mips", target_arch = "riscv64", target_os = "zkvm"), no_std)] diff --git a/crates/common/src/linux.rs b/crates/common/src/linux.rs index be647aafaf..244a1fda95 100644 --- a/crates/common/src/linux.rs +++ b/crates/common/src/linux.rs @@ -5,7 +5,7 @@ use crate::errors::{IOError, IOResult}; /// Converts a return value from a syscall into a [IOResult] type. #[inline(always)] #[allow(unused)] -pub(crate) fn from_ret(value: usize) -> IOResult { +pub(crate) const fn from_ret(value: usize) -> IOResult { if value > -4096isize as usize { // Truncation of the error value is guaranteed to never occur due to // the above check. This is the same check that musl uses: diff --git a/crates/common/src/types.rs b/crates/common/src/types.rs index dc1bd9ac90..f409b1502c 100644 --- a/crates/common/src/types.rs +++ b/crates/common/src/types.rs @@ -38,6 +38,6 @@ impl From for usize { impl From for i32 { fn from(fd: FileDescriptor) -> Self { - usize::from(fd) as i32 + usize::from(fd) as Self } } diff --git a/crates/common/src/zkvm/io.rs b/crates/common/src/zkvm/io.rs index b16228bd2e..977e710f0b 100644 --- a/crates/common/src/zkvm/io.rs +++ b/crates/common/src/zkvm/io.rs @@ -2,7 +2,7 @@ use crate::{errors::IOResult, BasicKernelInterface, FileDescriptor}; /// Concrete implementation of the [`KernelIO`] trait for the `SP1` target architecture. #[derive(Debug)] -pub struct ZkvmIO; +pub(crate) struct ZkvmIO; impl BasicKernelInterface for ZkvmIO { fn write(_fd: FileDescriptor, _buf: &[u8]) -> IOResult { diff --git a/crates/derive/Cargo.toml b/crates/derive/Cargo.toml index 36572e9a19..6c757d6d2d 100644 --- a/crates/derive/Cargo.toml +++ b/crates/derive/Cargo.toml @@ -8,6 +8,9 @@ license.workspace = true repository.workspace = true homepage.workspace = true +[lints] +workspace = true + [dependencies] # Alloy alloy-eips.workspace = true diff --git a/crates/derive/src/attributes/mod.rs b/crates/derive/src/attributes/mod.rs index 173f213ded..e8d901b1e3 100644 --- a/crates/derive/src/attributes/mod.rs +++ b/crates/derive/src/attributes/mod.rs @@ -43,7 +43,7 @@ where L2P: L2ChainProvider + Debug, { /// Create a new [StatefulAttributesBuilder] with the given epoch. - pub fn new(rcfg: Arc, sys_cfg_fetcher: L2P, receipts: L1P) -> Self { + pub const fn new(rcfg: Arc, sys_cfg_fetcher: L2P, receipts: L1P) -> Self { Self { rollup_cfg: rcfg, config_fetcher: sys_cfg_fetcher, receipts_fetcher: receipts } } } diff --git a/crates/derive/src/batch/batch_type.rs b/crates/derive/src/batch/batch_type.rs index 279159c56b..b3797188de 100644 --- a/crates/derive/src/batch/batch_type.rs +++ b/crates/derive/src/batch/batch_type.rs @@ -21,8 +21,8 @@ pub enum BatchType { impl From for BatchType { fn from(val: u8) -> Self { match val { - SINGLE_BATCH_TYPE => BatchType::Single, - SPAN_BATCH_TYPE => BatchType::Span, + SINGLE_BATCH_TYPE => Self::Single, + SPAN_BATCH_TYPE => Self::Span, _ => panic!("Invalid batch type: {val}"), } } @@ -30,15 +30,15 @@ impl From for BatchType { impl From<&[u8]> for BatchType { fn from(buf: &[u8]) -> Self { - BatchType::from(buf[0]) + Self::from(buf[0]) } } impl Encodable for BatchType { fn encode(&self, out: &mut dyn alloy_rlp::BufMut) { let val = match self { - BatchType::Single => SINGLE_BATCH_TYPE, - BatchType::Span => SPAN_BATCH_TYPE, + Self::Single => SINGLE_BATCH_TYPE, + Self::Span => SPAN_BATCH_TYPE, }; val.encode(out); } @@ -47,7 +47,7 @@ impl Encodable for BatchType { impl Decodable for BatchType { fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { let val = u8::decode(buf)?; - Ok(BatchType::from(val)) + Ok(Self::from(val)) } } diff --git a/crates/derive/src/batch/mod.rs b/crates/derive/src/batch/mod.rs index 2aa9d4faaa..86fc9dc675 100644 --- a/crates/derive/src/batch/mod.rs +++ b/crates/derive/src/batch/mod.rs @@ -17,8 +17,9 @@ mod span_batch; pub use span_batch::{ RawSpanBatch, SpanBatch, SpanBatchBits, SpanBatchEip1559TransactionData, SpanBatchEip2930TransactionData, SpanBatchElement, SpanBatchError, - SpanBatchLegacyTransactionData, SpanBatchPayload, SpanBatchPrefix, SpanBatchTransactionData, - SpanBatchTransactions, SpanDecodingError, FJORD_MAX_SPAN_BATCH_BYTES, MAX_SPAN_BATCH_BYTES, + SpanBatchLegacyTransactionData, SpanBatchPayload, SpanBatchPrefix, SpanBatchSignature, + SpanBatchTransactionData, SpanBatchTransactions, SpanDecodingError, FJORD_MAX_SPAN_BATCH_BYTES, + MAX_SPAN_BATCH_BYTES, }; mod single_batch; @@ -92,14 +93,14 @@ impl Batch { BatchType::Single => { let single_batch = SingleBatch::decode(r).map_err(PipelineEncodingError::AlloyRlpError)?; - Ok(Batch::Single(single_batch)) + Ok(Self::Single(single_batch)) } BatchType::Span => { let mut raw_span_batch = RawSpanBatch::decode(r, cfg)?; let span_batch = raw_span_batch .derive(cfg.block_time, cfg.genesis.l2_time, cfg.l2_chain_id) .map_err(PipelineEncodingError::SpanBatchError)?; - Ok(Batch::Span(span_batch)) + Ok(Self::Span(span_batch)) } } } diff --git a/crates/derive/src/batch/single_batch.rs b/crates/derive/src/batch/single_batch.rs index fd3134d6ba..e96f7fc664 100644 --- a/crates/derive/src/batch/single_batch.rs +++ b/crates/derive/src/batch/single_batch.rs @@ -32,7 +32,7 @@ impl SingleBatch { } /// Returns the [BlockNumHash] of the batch. - pub fn epoch(&self) -> BlockNumHash { + pub const fn epoch(&self) -> BlockNumHash { BlockNumHash { number: self.epoch_num, hash: self.epoch_hash } } diff --git a/crates/derive/src/batch/span_batch/bits.rs b/crates/derive/src/batch/span_batch/bits.rs index 4bb0a864df..1932d213eb 100644 --- a/crates/derive/src/batch/span_batch/bits.rs +++ b/crates/derive/src/batch/span_batch/bits.rs @@ -22,7 +22,7 @@ impl AsRef<[u8]> for SpanBatchBits { } impl From for Vec { - fn from(bits: SpanBatchBits) -> Vec { + fn from(bits: SpanBatchBits) -> Self { bits.0 } } @@ -56,7 +56,7 @@ impl SpanBatchBits { b.advance(buffer_len); v }; - let sb_bits = SpanBatchBits(bits); + let sb_bits = Self(bits); if sb_bits.bit_len() > bit_length { return Err(SpanBatchError::BitfieldTooLong); @@ -72,7 +72,7 @@ impl SpanBatchBits { pub fn encode( w: &mut Vec, bit_length: usize, - bits: &SpanBatchBits, + bits: &Self, is_fjord_active: bool, ) -> Result<(), SpanBatchError> { if bits.bit_len() > bit_length { diff --git a/crates/derive/src/batch/span_batch/element.rs b/crates/derive/src/batch/span_batch/element.rs index ce85adb67e..6af125335e 100644 --- a/crates/derive/src/batch/span_batch/element.rs +++ b/crates/derive/src/batch/span_batch/element.rs @@ -19,7 +19,7 @@ pub struct SpanBatchElement { impl From for SpanBatchElement { fn from(batch: SingleBatch) -> Self { - SpanBatchElement { + Self { epoch_num: batch.epoch_num, timestamp: batch.timestamp, transactions: batch.transactions, diff --git a/crates/derive/src/batch/span_batch/mod.rs b/crates/derive/src/batch/span_batch/mod.rs index c4b6a71953..b71312be1e 100644 --- a/crates/derive/src/batch/span_batch/mod.rs +++ b/crates/derive/src/batch/span_batch/mod.rs @@ -46,7 +46,7 @@ mod element; pub use element::SpanBatchElement; mod signature; -pub(crate) use signature::SpanBatchSignature; +pub use signature::SpanBatchSignature; mod tx_data; pub use tx_data::{ diff --git a/crates/derive/src/batch/span_batch/payload.rs b/crates/derive/src/batch/span_batch/payload.rs index 4c746cec79..fc7bd3db2c 100644 --- a/crates/derive/src/batch/span_batch/payload.rs +++ b/crates/derive/src/batch/span_batch/payload.rs @@ -52,7 +52,7 @@ impl SpanBatchPayload { } /// Returns the max span batch size based on the Fjord hardfork. - pub fn max_span_batch_size(&self, is_fjord_active: bool) -> usize { + pub const fn max_span_batch_size(&self, is_fjord_active: bool) -> usize { if is_fjord_active { FJORD_MAX_SPAN_BATCH_BYTES as usize } else { diff --git a/crates/derive/src/batch/span_batch/raw.rs b/crates/derive/src/batch/span_batch/raw.rs index be096cfb19..365f36faf6 100644 --- a/crates/derive/src/batch/span_batch/raw.rs +++ b/crates/derive/src/batch/span_batch/raw.rs @@ -27,7 +27,7 @@ impl TryFrom for RawSpanBatch { let span_start = value.batches.first().ok_or(SpanBatchError::EmptySpanBatch)?; let span_end = value.batches.last().ok_or(SpanBatchError::EmptySpanBatch)?; - Ok(RawSpanBatch { + Ok(Self { prefix: SpanBatchPrefix { rel_timestamp: span_start.timestamp - value.genesis_timestamp, l1_origin_num: span_end.epoch_num, @@ -46,12 +46,12 @@ impl TryFrom for RawSpanBatch { impl RawSpanBatch { /// Returns the batch type - pub fn get_batch_type(&self) -> BatchType { + pub const fn get_batch_type(&self) -> BatchType { BatchType::Span } /// Returns the timestamp for the span batch. - pub fn timestamp(&self) -> u64 { + pub const fn timestamp(&self) -> u64 { self.prefix.rel_timestamp } @@ -63,14 +63,14 @@ impl RawSpanBatch { /// Encodes the [RawSpanBatch] into a writer. pub fn encode(&self, w: &mut Vec, cfg: &RollupConfig) -> Result<(), SpanBatchError> { self.prefix.encode_prefix(w); - let is_fjord_active = RawSpanBatch::is_fjord_active(&self.prefix, cfg); + let is_fjord_active = Self::is_fjord_active(&self.prefix, cfg); self.payload.encode_payload(w, is_fjord_active) } /// Decodes the [RawSpanBatch] from a reader.] pub fn decode(r: &mut &[u8], cfg: &RollupConfig) -> Result { let prefix = SpanBatchPrefix::decode_prefix(r)?; - let is_fjord_active = RawSpanBatch::is_fjord_active(&prefix, cfg); + let is_fjord_active = Self::is_fjord_active(&prefix, cfg); let payload = SpanBatchPayload::decode_payload(r, is_fjord_active)?; Ok(Self { prefix, payload }) } diff --git a/crates/derive/src/batch/span_batch/tx_data/eip1559.rs b/crates/derive/src/batch/span_batch/tx_data/eip1559.rs index 2f01bd9597..0e487a7a44 100644 --- a/crates/derive/src/batch/span_batch/tx_data/eip1559.rs +++ b/crates/derive/src/batch/span_batch/tx_data/eip1559.rs @@ -45,7 +45,7 @@ impl SpanBatchEip1559TransactionData { )?, ), gas_limit: gas as u128, - to: if let Some(to) = to { TxKind::Call(to) } else { TxKind::Create }, + to: to.map_or(TxKind::Create, TxKind::Call), value: self.value, input: self.data.clone().into(), access_list: self.access_list.clone(), diff --git a/crates/derive/src/batch/span_batch/tx_data/eip2930.rs b/crates/derive/src/batch/span_batch/tx_data/eip2930.rs index 94ef4bb6bd..563572175f 100644 --- a/crates/derive/src/batch/span_batch/tx_data/eip2930.rs +++ b/crates/derive/src/batch/span_batch/tx_data/eip2930.rs @@ -38,7 +38,7 @@ impl SpanBatchEip2930TransactionData { })?, ), gas_limit: gas as u128, - to: if let Some(to) = to { TxKind::Call(to) } else { TxKind::Create }, + to: to.map_or(TxKind::Create, TxKind::Call), value: self.value, input: self.data.clone().into(), access_list: self.access_list.clone(), diff --git a/crates/derive/src/batch/span_batch/tx_data/legacy.rs b/crates/derive/src/batch/span_batch/tx_data/legacy.rs index d8b21894d4..625627a3b4 100644 --- a/crates/derive/src/batch/span_batch/tx_data/legacy.rs +++ b/crates/derive/src/batch/span_batch/tx_data/legacy.rs @@ -35,7 +35,7 @@ impl SpanBatchLegacyTransactionData { })?, ), gas_limit: gas as u128, - to: if let Some(to) = to { TxKind::Call(to) } else { TxKind::Create }, + to: to.map_or(TxKind::Create, TxKind::Call), value: self.value, input: self.data.clone().into(), }; diff --git a/crates/derive/src/batch/span_batch/tx_data/wrapper.rs b/crates/derive/src/batch/span_batch/tx_data/wrapper.rs index 2f4a470968..7e273345d4 100644 --- a/crates/derive/src/batch/span_batch/tx_data/wrapper.rs +++ b/crates/derive/src/batch/span_batch/tx_data/wrapper.rs @@ -42,7 +42,7 @@ impl Decodable for SpanBatchTransactionData { fn decode(r: &mut &[u8]) -> Result { if !r.is_empty() && r[0] > 0x7F { // Legacy transaction - return Ok(SpanBatchTransactionData::Legacy(SpanBatchLegacyTransactionData::decode(r)?)); + return Ok(Self::Legacy(SpanBatchLegacyTransactionData::decode(r)?)); } // Non-legacy transaction (EIP-2718 envelope encoding) Self::decode_typed(r) @@ -56,7 +56,7 @@ impl TryFrom<&TxEnvelope> for SpanBatchTransactionData { match tx_envelope { TxEnvelope::Legacy(s) => { let s = s.tx(); - Ok(SpanBatchTransactionData::Legacy(SpanBatchLegacyTransactionData { + Ok(Self::Legacy(SpanBatchLegacyTransactionData { value: s.value, gas_price: U256::from(s.gas_price), data: Bytes::from(s.input().to_vec()), @@ -64,7 +64,7 @@ impl TryFrom<&TxEnvelope> for SpanBatchTransactionData { } TxEnvelope::Eip2930(s) => { let s = s.tx(); - Ok(SpanBatchTransactionData::Eip2930(SpanBatchEip2930TransactionData { + Ok(Self::Eip2930(SpanBatchEip2930TransactionData { value: s.value, gas_price: U256::from(s.gas_price), data: Bytes::from(s.input().to_vec()), @@ -73,7 +73,7 @@ impl TryFrom<&TxEnvelope> for SpanBatchTransactionData { } TxEnvelope::Eip1559(s) => { let s = s.tx(); - Ok(SpanBatchTransactionData::Eip1559(SpanBatchEip1559TransactionData { + Ok(Self::Eip1559(SpanBatchEip1559TransactionData { value: s.value, max_fee_per_gas: U256::from(s.max_fee_per_gas), max_priority_fee_per_gas: U256::from(s.max_priority_fee_per_gas), @@ -88,7 +88,7 @@ impl TryFrom<&TxEnvelope> for SpanBatchTransactionData { impl SpanBatchTransactionData { /// Returns the transaction type of the [SpanBatchTransactionData]. - pub fn tx_type(&self) -> TxType { + pub const fn tx_type(&self) -> TxType { match self { Self::Legacy(_) => TxType::Legacy, Self::Eip2930(_) => TxType::Eip2930, @@ -103,12 +103,12 @@ impl SpanBatchTransactionData { } match b[0].try_into().map_err(|_| alloy_rlp::Error::Custom("Invalid tx type"))? { - TxType::Eip2930 => Ok(SpanBatchTransactionData::Eip2930( - SpanBatchEip2930TransactionData::decode(&mut &b[1..])?, - )), - TxType::Eip1559 => Ok(SpanBatchTransactionData::Eip1559( - SpanBatchEip1559TransactionData::decode(&mut &b[1..])?, - )), + TxType::Eip2930 => { + Ok(Self::Eip2930(SpanBatchEip2930TransactionData::decode(&mut &b[1..])?)) + } + TxType::Eip1559 => { + Ok(Self::Eip1559(SpanBatchEip1559TransactionData::decode(&mut &b[1..])?)) + } _ => Err(alloy_rlp::Error::Custom("Invalid transaction type")), } } diff --git a/crates/derive/src/batch/span_batch/utils.rs b/crates/derive/src/batch/span_batch/utils.rs index 531b4daa1f..a5d98be6e3 100644 --- a/crates/derive/src/batch/span_batch/utils.rs +++ b/crates/derive/src/batch/span_batch/utils.rs @@ -43,7 +43,7 @@ pub(crate) fn read_tx_data(r: &mut &[u8]) -> Result<(Vec, TxType), SpanBatch } /// Converts a `v` value to a y parity bit, from the transaaction type. -pub(crate) fn convert_v_to_y_parity(v: u64, tx_type: TxType) -> Result { +pub(crate) const fn convert_v_to_y_parity(v: u64, tx_type: TxType) -> Result { match tx_type { TxType::Legacy => { if v != 27 && v != 28 { @@ -60,7 +60,7 @@ pub(crate) fn convert_v_to_y_parity(v: u64, tx_type: TxType) -> Result bool { +pub(crate) const fn is_protected_v(tx: &TxEnvelope) -> bool { match tx { TxEnvelope::Legacy(tx) => { let v = tx.signature().v().to_u64(); diff --git a/crates/derive/src/batch/validity.rs b/crates/derive/src/batch/validity.rs index 0e074983a8..bc0d493110 100644 --- a/crates/derive/src/batch/validity.rs +++ b/crates/derive/src/batch/validity.rs @@ -19,7 +19,7 @@ pub enum BatchValidity { impl BatchValidity { /// Returns if the batch is dropped. - pub fn is_drop(&self) -> bool { - matches!(self, BatchValidity::Drop) + pub const fn is_drop(&self) -> bool { + matches!(self, Self::Drop) } } diff --git a/crates/derive/src/errors.rs b/crates/derive/src/errors.rs index 79a72ba5a8..bedda965dc 100644 --- a/crates/derive/src/errors.rs +++ b/crates/derive/src/errors.rs @@ -93,12 +93,12 @@ pub enum PipelineError { impl PipelineError { /// Wrap [self] as a [PipelineErrorKind::Critical]. - pub fn crit(self) -> PipelineErrorKind { + pub const fn crit(self) -> PipelineErrorKind { PipelineErrorKind::Critical(self) } /// Wrap [self] as a [PipelineErrorKind::Temporary]. - pub fn temp(self) -> PipelineErrorKind { + pub const fn temp(self) -> PipelineErrorKind { PipelineErrorKind::Temporary(self) } } diff --git a/crates/derive/src/lib.rs b/crates/derive/src/lib.rs index 0727fcf915..409b124a8e 100644 --- a/crates/derive/src/lib.rs +++ b/crates/derive/src/lib.rs @@ -1,6 +1,4 @@ #![doc = include_str!("../README.md")] -#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] -#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(any(test, feature = "metrics")), no_std)] #![cfg_attr(not(any(test, feature = "test-utils")), warn(unused_crate_dependencies))] diff --git a/crates/derive/src/online/blob_provider.rs b/crates/derive/src/online/blob_provider.rs index f1e2d7dcf3..1fbec0a612 100644 --- a/crates/derive/src/online/blob_provider.rs +++ b/crates/derive/src/online/blob_provider.rs @@ -43,7 +43,11 @@ impl OnlineBlobProvider { /// The `genesis_time` and `slot_interval` arguments are _optional_ and the /// [OnlineBlobProvider] will attempt to load them dynamically at runtime if they are not /// provided. - pub fn new(beacon_client: B, genesis_time: Option, slot_interval: Option) -> Self { + pub const fn new( + beacon_client: B, + genesis_time: Option, + slot_interval: Option, + ) -> Self { Self { beacon_client, genesis_time, slot_interval, _slot_derivation: PhantomData } } @@ -252,7 +256,7 @@ impl { /// Creates a new instance of the [OnlineBlobProviderWithFallback] with the /// specified primary and fallback providers. - pub fn new(primary: OnlineBlobProvider, fallback: Option) -> Self { + pub const fn new(primary: OnlineBlobProvider, fallback: Option) -> Self { Self { primary, fallback, _slot_derivation: PhantomData } } @@ -416,13 +420,13 @@ impl } /// Adds a genesis time to the builder. This is optional. - pub fn with_genesis_time(mut self, genesis_time: u64) -> Self { + pub const fn with_genesis_time(mut self, genesis_time: u64) -> Self { self.genesis_time = Some(genesis_time); self } /// Adds a slot interval to the builder. This is optional. - pub fn with_slot_interval(mut self, slot_interval: u64) -> Self { + pub const fn with_slot_interval(mut self, slot_interval: u64) -> Self { self.slot_interval = Some(slot_interval); self } diff --git a/crates/derive/src/online/mod.rs b/crates/derive/src/online/mod.rs index 58eb9e65a5..8dd3988260 100644 --- a/crates/derive/src/online/mod.rs +++ b/crates/derive/src/online/mod.rs @@ -23,7 +23,7 @@ pub use alloy_providers::{AlloyChainProvider, AlloyL2ChainProvider}; mod blob_provider; pub use blob_provider::{ BlobSidecarProvider, OnlineBlobProvider, OnlineBlobProviderBuilder, - OnlineBlobProviderWithFallback, SimpleSlotDerivation, + OnlineBlobProviderWithFallback, SimpleSlotDerivation, SlotDerivation, }; #[cfg(any(test, feature = "test-utils"))] diff --git a/crates/derive/src/pipeline/builder.rs b/crates/derive/src/pipeline/builder.rs index 2307a8a30a..c9293b6402 100644 --- a/crates/derive/src/pipeline/builder.rs +++ b/crates/derive/src/pipeline/builder.rs @@ -74,7 +74,7 @@ where } /// Sets the origin L1 block for the pipeline. - pub fn origin(mut self, origin: BlockInfo) -> Self { + pub const fn origin(mut self, origin: BlockInfo) -> Self { self.origin = Some(origin); self } @@ -138,6 +138,6 @@ where AttributesQueue::new(rollup_config.clone(), batch_queue, attributes_builder); // Create the pipeline. - DerivationPipeline::new(attributes, rollup_config, l2_chain_provider) + Self::new(attributes, rollup_config, l2_chain_provider) } } diff --git a/crates/derive/src/pipeline/core.rs b/crates/derive/src/pipeline/core.rs index d82b489c17..b05aeab556 100644 --- a/crates/derive/src/pipeline/core.rs +++ b/crates/derive/src/pipeline/core.rs @@ -38,7 +38,11 @@ where P: L2ChainProvider + Send + Sync + Debug, { /// Creates a new instance of the [DerivationPipeline]. - pub fn new(attributes: S, rollup_config: Arc, l2_chain_provider: P) -> Self { + pub const fn new( + attributes: S, + rollup_config: Arc, + l2_chain_provider: P, + ) -> Self { Self { attributes, prepared: VecDeque::new(), rollup_config, l2_chain_provider } } } diff --git a/crates/derive/src/sources/blobs.rs b/crates/derive/src/sources/blobs.rs index 9f28debca7..93b93e0302 100644 --- a/crates/derive/src/sources/blobs.rs +++ b/crates/derive/src/sources/blobs.rs @@ -41,7 +41,7 @@ where B: BlobProvider + Send, { /// Creates a new blob source. - pub fn new( + pub const fn new( chain_provider: F, blob_fetcher: B, batcher_address: Address, diff --git a/crates/derive/src/sources/calldata.rs b/crates/derive/src/sources/calldata.rs index 4fd75f6291..f24c763e47 100644 --- a/crates/derive/src/sources/calldata.rs +++ b/crates/derive/src/sources/calldata.rs @@ -32,7 +32,7 @@ where impl CalldataSource { /// Creates a new calldata source. - pub fn new( + pub const fn new( chain_provider: CP, batch_inbox_address: Address, block_ref: BlockInfo, diff --git a/crates/derive/src/sources/variant.rs b/crates/derive/src/sources/variant.rs index f4c6b9b4d9..d29f4196bd 100644 --- a/crates/derive/src/sources/variant.rs +++ b/crates/derive/src/sources/variant.rs @@ -33,8 +33,8 @@ where async fn next(&mut self) -> PipelineResult { match self { - EthereumDataSourceVariant::Calldata(c) => c.next().await, - EthereumDataSourceVariant::Blob(b) => b.next().await, + Self::Calldata(c) => c.next().await, + Self::Blob(b) => b.next().await, } } } diff --git a/crates/derive/src/stages/batch_stream.rs b/crates/derive/src/stages/batch_stream.rs index 39eea52e8e..419cb5f522 100644 --- a/crates/derive/src/stages/batch_stream.rs +++ b/crates/derive/src/stages/batch_stream.rs @@ -44,7 +44,7 @@ where P: BatchQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug, { /// Create a new [BatchStream] stage. - pub fn new(prev: P, config: Arc) -> Self { + pub const fn new(prev: P, config: Arc) -> Self { Self { prev, span: None, buffer: Vec::new(), config } } @@ -93,10 +93,8 @@ where self.span = Some(b); // Attempt to pull a SingleBatch out of the SpanBatch. - match self.get_single_batch() { - Some(b) => Ok(Batch::Single(b)), - None => Err(PipelineError::NotEnoughData.temp()), - } + self.get_single_batch() + .map_or_else(|| Err(PipelineError::NotEnoughData.temp()), |b| Ok(Batch::Single(b))) } } diff --git a/crates/derive/src/stages/channel_bank.rs b/crates/derive/src/stages/channel_bank.rs index 5f949c6999..a9a5d24bc8 100644 --- a/crates/derive/src/stages/channel_bank.rs +++ b/crates/derive/src/stages/channel_bank.rs @@ -169,10 +169,7 @@ where let channel_data = (0..self.channel_queue.len()).find_map(|i| self.try_read_channel_at_index(i).ok()); - match channel_data { - Some(data) => Ok(Some(data)), - None => Err(PipelineError::Eof.temp()), - } + channel_data.map_or_else(|| Err(PipelineError::Eof.temp()), |data| Ok(Some(data))) } /// Attempts to read the channel at the specified index. If the channel is not ready or timed diff --git a/crates/derive/src/stages/channel_reader.rs b/crates/derive/src/stages/channel_reader.rs index ff14a03ee9..310a8128d5 100644 --- a/crates/derive/src/stages/channel_reader.rs +++ b/crates/derive/src/stages/channel_reader.rs @@ -64,7 +64,7 @@ where /// Create a new [ChannelReader] stage. pub fn new(prev: P, cfg: Arc) -> Self { crate::set!(STAGE_RESETS, 0, &["channel-reader"]); - Self { prev, next_batch: None, cfg: cfg.clone() } + Self { prev, next_batch: None, cfg } } /// Creates the batch reader from available channel data. diff --git a/crates/derive/src/stages/l1_traversal.rs b/crates/derive/src/stages/l1_traversal.rs index 2f0a6fab65..1831d73477 100644 --- a/crates/derive/src/stages/l1_traversal.rs +++ b/crates/derive/src/stages/l1_traversal.rs @@ -63,7 +63,7 @@ impl L1Traversal { } /// Retrieves a reference to the inner data source of the [L1Traversal] stage. - pub fn data_source(&self) -> &F { + pub const fn data_source(&self) -> &F { &self.data_source } } diff --git a/crates/derive/src/stages/test_utils/attributes_queue.rs b/crates/derive/src/stages/test_utils/attributes_queue.rs index a27c6e7cda..bdd3ca3b6b 100644 --- a/crates/derive/src/stages/test_utils/attributes_queue.rs +++ b/crates/derive/src/stages/test_utils/attributes_queue.rs @@ -79,7 +79,7 @@ impl AttributesProvider for MockAttributesProvider { } /// Creates a new [`MockAttributesProvider`] with the given origin and batches. -pub fn new_attributes_provider( +pub const fn new_attributes_provider( origin: Option, batches: Vec>, ) -> MockAttributesProvider { diff --git a/crates/derive/src/stages/test_utils/frame_queue.rs b/crates/derive/src/stages/test_utils/frame_queue.rs index f31f6dd745..5f0b1d307b 100644 --- a/crates/derive/src/stages/test_utils/frame_queue.rs +++ b/crates/derive/src/stages/test_utils/frame_queue.rs @@ -20,7 +20,7 @@ pub struct MockFrameQueueProvider { impl MockFrameQueueProvider { /// Creates a new [MockFrameQueueProvider] with the given data. - pub fn new(data: Vec>) -> Self { + pub const fn new(data: Vec>) -> Self { Self { data } } } diff --git a/crates/derive/src/stages/test_utils/tracing.rs b/crates/derive/src/stages/test_utils/tracing.rs index 6b59e3b747..6a0168fcd5 100644 --- a/crates/derive/src/stages/test_utils/tracing.rs +++ b/crates/derive/src/stages/test_utils/tracing.rs @@ -40,7 +40,7 @@ pub struct CollectingLayer { impl CollectingLayer { /// Creates a new collecting layer with the specified storage. - pub fn new(storage: TraceStorage) -> Self { + pub const fn new(storage: TraceStorage) -> Self { Self { storage } } } diff --git a/crates/derive/src/traits/test_utils.rs b/crates/derive/src/traits/test_utils.rs index b07666bfe8..88d6977456 100644 --- a/crates/derive/src/traits/test_utils.rs +++ b/crates/derive/src/traits/test_utils.rs @@ -56,10 +56,7 @@ impl DataAvailabilityProvider for TestDAP { let results = self .results .iter() - .map(|i| match i { - Ok(r) => Ok(r.clone()), - Err(_) => Err(PipelineError::Eof.temp()), - }) + .map(|i| i.as_ref().map_or_else(|_| Err(PipelineError::Eof.temp()), |r| Ok(r.clone()))) .collect::>>(); Ok(TestIter { open_data_calls: vec![(*block_ref, self.batch_inbox_address)], results }) } @@ -229,7 +226,7 @@ pub struct TestL2ChainProvider { impl TestL2ChainProvider { /// Creates a new [MockBlockFetcher] with the given origin and batches. - pub fn new( + pub const fn new( blocks: Vec, op_blocks: Vec, system_configs: HashMap, diff --git a/crates/executor/Cargo.toml b/crates/executor/Cargo.toml index f1ea6f2cc2..eaadf5be1b 100644 --- a/crates/executor/Cargo.toml +++ b/crates/executor/Cargo.toml @@ -8,6 +8,9 @@ license.workspace = true repository.workspace = true homepage.workspace = true +[lints] +workspace = true + [dependencies] # General thiserror.workspace = true diff --git a/crates/executor/benches/execution.rs b/crates/executor/benches/execution.rs index 140a1c2254..0963133e05 100644 --- a/crates/executor/benches/execution.rs +++ b/crates/executor/benches/execution.rs @@ -1,3 +1,4 @@ +#![allow(missing_docs)] //! Benches for the [StatelessL2BlockExecutor] implementation. use alloy_consensus::{Header, Sealable}; @@ -63,7 +64,7 @@ fn op_mainnet_exec_bench( data_folder: &str, pre_state_header: Header, payload_attrs: OptimismPayloadAttributes, - bencher: &mut Bencher, + bencher: &mut Bencher<'_>, ) { // Make a mock rollup config for OP mainnet, with Ecotone activated at timestamp = 0. let rollup_config = RollupConfig { diff --git a/crates/executor/src/lib.rs b/crates/executor/src/lib.rs index db12ba2f6e..b93dbee925 100644 --- a/crates/executor/src/lib.rs +++ b/crates/executor/src/lib.rs @@ -1,6 +1,4 @@ #![doc = include_str!("../README.md")] -#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] -#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(test), no_std)] diff --git a/crates/executor/src/util.rs b/crates/executor/src/util.rs index 971738fb9c..fd0a785d08 100644 --- a/crates/executor/src/util.rs +++ b/crates/executor/src/util.rs @@ -71,7 +71,7 @@ pub(crate) fn extract_tx_gas_limit(tx: &OpTxEnvelope) -> u128 { } /// Returns whether or not an [OpTxEnvelope] is a system transaction. -pub(crate) fn is_system_transaction(tx: &OpTxEnvelope) -> bool { +pub(crate) const fn is_system_transaction(tx: &OpTxEnvelope) -> bool { match tx { OpTxEnvelope::Deposit(tx) => tx.is_system_transaction, _ => false, diff --git a/crates/mpt/Cargo.toml b/crates/mpt/Cargo.toml index a4f7ff67db..ba11ca7307 100644 --- a/crates/mpt/Cargo.toml +++ b/crates/mpt/Cargo.toml @@ -8,6 +8,9 @@ license.workspace = true repository.workspace = true homepage.workspace = true +[lints] +workspace = true + [dependencies] # General tracing.workspace = true diff --git a/crates/mpt/benches/trie_node.rs b/crates/mpt/benches/trie_node.rs index 922d83d510..d8eaa3fded 100644 --- a/crates/mpt/benches/trie_node.rs +++ b/crates/mpt/benches/trie_node.rs @@ -1,3 +1,4 @@ +#![allow(missing_docs)] //! Contains benchmarks for the [TrieNode]. use alloy_trie::Nibbles; diff --git a/crates/mpt/src/db/mod.rs b/crates/mpt/src/db/mod.rs index 1f39dcc58a..12da988b8e 100644 --- a/crates/mpt/src/db/mod.rs +++ b/crates/mpt/src/db/mod.rs @@ -116,7 +116,7 @@ where } /// Returns a shared reference to the root [TrieNode] of the trie DB. - pub fn root_node_ref(&self) -> &TrieNode { + pub const fn root_node_ref(&self) -> &TrieNode { &self.root_node } @@ -132,7 +132,7 @@ where } /// Returns the mapping of [Address]es to storage roots. - pub fn storage_roots(&self) -> &HashMap { + pub const fn storage_roots(&self) -> &HashMap { &self.storage_roots } @@ -175,7 +175,7 @@ where } /// Returns a reference to the current parent block header of the trie DB. - pub fn parent_block_header(&self) -> &Sealed
{ + pub const fn parent_block_header(&self) -> &Sealed
{ &self.parent_block_header } diff --git a/crates/mpt/src/lib.rs b/crates/mpt/src/lib.rs index fc2830effc..829bd745a3 100644 --- a/crates/mpt/src/lib.rs +++ b/crates/mpt/src/lib.rs @@ -1,6 +1,4 @@ #![doc = include_str!("../README.md")] -#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] -#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(test), no_std)] diff --git a/crates/mpt/src/list_walker.rs b/crates/mpt/src/list_walker.rs index 9aa230b9ce..600d7803f7 100644 --- a/crates/mpt/src/list_walker.rs +++ b/crates/mpt/src/list_walker.rs @@ -31,7 +31,7 @@ where F: TrieProvider, { /// Creates a new [OrderedListWalker], yet to be hydrated. - pub fn new(root: B256) -> Self { + pub const fn new(root: B256) -> Self { Self { root, inner: None, _phantom: PhantomData } } diff --git a/crates/mpt/src/node.rs b/crates/mpt/src/node.rs index d585135def..2662295925 100644 --- a/crates/mpt/src/node.rs +++ b/crates/mpt/src/node.rs @@ -95,15 +95,15 @@ pub enum TrieNode { impl Display for TrieNode { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { - TrieNode::Empty => write!(f, "Empty"), - TrieNode::Blinded { commitment } => write!(f, "Blinded({})", commitment), - TrieNode::Leaf { prefix, value } => { + Self::Empty => write!(f, "Empty"), + Self::Blinded { commitment } => write!(f, "Blinded({})", commitment), + Self::Leaf { prefix, value } => { write!(f, "Leaf({}, {})", hex::encode(prefix.as_ref()), hex::encode(value.as_ref())) } - TrieNode::Extension { prefix, node } => { + Self::Extension { prefix, node } => { write!(f, "Extension({}, {})", hex::encode(prefix.as_ref()), node) } - TrieNode::Branch { .. } => write!(f, "Branch"), + Self::Branch { .. } => write!(f, "Branch"), } } } @@ -116,8 +116,8 @@ impl TrieNode { /// /// ## Returns /// - `Self` - The new blinded [TrieNode]. - pub fn new_blinded(commitment: B256) -> Self { - TrieNode::Blinded { commitment } + pub const fn new_blinded(commitment: B256) -> Self { + Self::Blinded { commitment } } /// Returns the commitment of a [TrieNode::Blinded] node, if `self` is of the @@ -126,9 +126,9 @@ impl TrieNode { /// ## Returns /// - `Some(B256)` - The commitment of the blinded node /// - `None` - `self` is not a [TrieNode::Blinded] node - pub fn blinded_commitment(&self) -> Option { + pub const fn blinded_commitment(&self) -> Option { match self { - TrieNode::Blinded { commitment } => Some(*commitment), + Self::Blinded { commitment } => Some(*commitment), _ => None, } } @@ -137,25 +137,25 @@ impl TrieNode { /// length. Alternatively, if the [TrieNode] is a [TrieNode::Blinded] node already, it /// is left as-is. pub fn blind(&mut self) { - if self.length() >= B256::ZERO.len() && !matches!(self, TrieNode::Blinded { .. }) { + if self.length() >= B256::ZERO.len() && !matches!(self, Self::Blinded { .. }) { let mut rlp_buf = Vec::with_capacity(self.length()); self.encode_in_place(&mut rlp_buf); - *self = TrieNode::Blinded { commitment: keccak256(rlp_buf) } + *self = Self::Blinded { commitment: keccak256(rlp_buf) } } } /// Unblinds the [TrieNode] if it is a [TrieNode::Blinded] node. pub fn unblind(&mut self, fetcher: &F) -> TrieNodeResult<()> { - if let TrieNode::Blinded { commitment } = self { + if let Self::Blinded { commitment } = self { if *commitment == EMPTY_ROOT_HASH { // If the commitment is the empty root hash, the node is empty, and we don't need to // reach out to the fetcher. - *self = TrieNode::Empty; + *self = Self::Empty; } else { let rlp = fetcher .trie_node_preimage(*commitment) .map_err(|e| TrieNodeError::Provider(e.to_string()))?; - *self = TrieNode::decode(&mut rlp.as_ref()).map_err(TrieNodeError::RLPError)?; + *self = Self::decode(&mut rlp.as_ref()).map_err(TrieNodeError::RLPError)?; } } Ok(()) @@ -179,17 +179,17 @@ impl TrieNode { fetcher: &F, ) -> TrieNodeResult> { match self { - TrieNode::Branch { ref mut stack } => { + Self::Branch { ref mut stack } => { let branch_nibble = path[0] as usize; stack .get_mut(branch_nibble) .map(|node| node.open(&path.slice(BRANCH_NODE_NIBBLES..), fetcher)) .unwrap_or(Ok(None)) } - TrieNode::Leaf { prefix, value } => { + Self::Leaf { prefix, value } => { Ok((path.as_slice() == prefix.as_slice()).then_some(value)) } - TrieNode::Extension { prefix, node } => { + Self::Extension { prefix, node } => { if path.slice(..prefix.len()).as_slice() == prefix.as_slice() { // Follow extension branch node.unblind(fetcher)?; @@ -198,11 +198,11 @@ impl TrieNode { Ok(None) } } - TrieNode::Blinded { .. } => { + Self::Blinded { .. } => { self.unblind(fetcher)?; self.open(path, fetcher) } - TrieNode::Empty => Ok(None), + Self::Empty => Ok(None), } } @@ -224,33 +224,33 @@ impl TrieNode { fetcher: &F, ) -> TrieNodeResult<()> { match self { - TrieNode::Empty => { + Self::Empty => { // If the trie node is null, insert the leaf node at the current path. - *self = TrieNode::Leaf { prefix: path.clone(), value }; + *self = Self::Leaf { prefix: path.clone(), value }; Ok(()) } - TrieNode::Leaf { prefix, value: leaf_value } => { + Self::Leaf { prefix, value: leaf_value } => { let shared_extension_nibbles = path.common_prefix_length(prefix); // If all nibbles are shared, update the leaf node with the new value. if path.as_slice() == prefix.as_slice() { - *self = TrieNode::Leaf { prefix: prefix.clone(), value }; + *self = Self::Leaf { prefix: prefix.clone(), value }; return Ok(()); } // Create a branch node stack containing the leaf node and the new value. - let mut stack = vec![TrieNode::Empty; BRANCH_LIST_LENGTH]; + let mut stack = vec![Self::Empty; BRANCH_LIST_LENGTH]; // Insert the shortened extension into the branch stack. let extension_nibble = prefix[shared_extension_nibbles] as usize; - stack[extension_nibble] = TrieNode::Leaf { + stack[extension_nibble] = Self::Leaf { prefix: prefix.slice(shared_extension_nibbles + BRANCH_NODE_NIBBLES..), value: leaf_value.clone(), }; // Insert the new value into the branch stack. let branch_nibble_new = path[shared_extension_nibbles] as usize; - stack[branch_nibble_new] = TrieNode::Leaf { + stack[branch_nibble_new] = Self::Leaf { prefix: path.slice(shared_extension_nibbles + BRANCH_NODE_NIBBLES..), value, }; @@ -258,17 +258,17 @@ impl TrieNode { // Replace the leaf node with the branch if no nibbles are shared, else create an // extension. if shared_extension_nibbles == 0 { - *self = TrieNode::Branch { stack }; + *self = Self::Branch { stack }; } else { let raw_ext_nibbles = path.slice(..shared_extension_nibbles); - *self = TrieNode::Extension { + *self = Self::Extension { prefix: raw_ext_nibbles, - node: Box::new(TrieNode::Branch { stack }), + node: Box::new(Self::Branch { stack }), }; } Ok(()) } - TrieNode::Extension { prefix, node } => { + Self::Extension { prefix, node } => { let shared_extension_nibbles = path.common_prefix_length(prefix); if shared_extension_nibbles == prefix.len() { node.insert(&path.slice(shared_extension_nibbles..), value, fetcher)?; @@ -276,7 +276,7 @@ impl TrieNode { } // Create a branch node stack containing the leaf node and the new value. - let mut stack = vec![TrieNode::Empty; BRANCH_LIST_LENGTH]; + let mut stack = vec![Self::Empty; BRANCH_LIST_LENGTH]; // Insert the shortened extension into the branch stack. let extension_nibble = prefix[shared_extension_nibbles] as usize; @@ -286,12 +286,12 @@ impl TrieNode { // verbatim into the branch. node.as_ref().clone() } else { - TrieNode::Extension { prefix: new_prefix, node: node.clone() } + Self::Extension { prefix: new_prefix, node: node.clone() } }; // Insert the new value into the branch stack. let branch_nibble_new = path[shared_extension_nibbles] as usize; - stack[branch_nibble_new] = TrieNode::Leaf { + stack[branch_nibble_new] = Self::Leaf { prefix: path.slice(shared_extension_nibbles + BRANCH_NODE_NIBBLES..), value, }; @@ -299,22 +299,22 @@ impl TrieNode { // Replace the extension node with the branch if no nibbles are shared, else create // an extension. if shared_extension_nibbles == 0 { - *self = TrieNode::Branch { stack }; + *self = Self::Branch { stack }; } else { let extension = path.slice(..shared_extension_nibbles); - *self = TrieNode::Extension { + *self = Self::Extension { prefix: extension, - node: Box::new(TrieNode::Branch { stack }), + node: Box::new(Self::Branch { stack }), }; } Ok(()) } - TrieNode::Branch { stack } => { + Self::Branch { stack } => { // Follow the branch node to the next node in the path. let branch_nibble = path[0] as usize; stack[branch_nibble].insert(&path.slice(BRANCH_NODE_NIBBLES..), value, fetcher) } - TrieNode::Blinded { .. } => { + Self::Blinded { .. } => { // If a blinded node is approached, reveal the node and continue the insertion // recursion. self.unblind(fetcher)?; @@ -339,21 +339,21 @@ impl TrieNode { hinter: &H, ) -> TrieNodeResult<()> { match self { - TrieNode::Empty => Err(TrieNodeError::KeyNotFound(self.to_string())), - TrieNode::Leaf { prefix, .. } => { + Self::Empty => Err(TrieNodeError::KeyNotFound(self.to_string())), + Self::Leaf { prefix, .. } => { if path == prefix { - *self = TrieNode::Empty; + *self = Self::Empty; Ok(()) } else { Err(TrieNodeError::KeyNotFound(self.to_string())) } } - TrieNode::Extension { prefix, node } => { + Self::Extension { prefix, node } => { let shared_nibbles = path.common_prefix_length(prefix); if shared_nibbles < prefix.len() { return Err(TrieNodeError::KeyNotFound(self.to_string())); } else if shared_nibbles == path.len() { - *self = TrieNode::Empty; + *self = Self::Empty; return Ok(()); } @@ -362,14 +362,14 @@ impl TrieNode { // Simplify extension if possible after the deletion self.collapse_if_possible(fetcher, hinter) } - TrieNode::Branch { stack } => { + Self::Branch { stack } => { let branch_nibble = path[0] as usize; stack[branch_nibble].delete(&path.slice(BRANCH_NODE_NIBBLES..), fetcher, hinter)?; // Simplify the branch if possible after the deletion self.collapse_if_possible(fetcher, hinter) } - TrieNode::Blinded { .. } => { + Self::Blinded { .. } => { self.unblind(fetcher)?; self.delete(path, fetcher, hinter) } @@ -428,38 +428,38 @@ impl TrieNode { hinter: &H, ) -> TrieNodeResult<()> { match self { - TrieNode::Extension { prefix, node } => match node.as_mut() { - TrieNode::Extension { prefix: child_prefix, node: child_node } => { + Self::Extension { prefix, node } => match node.as_mut() { + Self::Extension { prefix: child_prefix, node: child_node } => { // Double extensions are collapsed into a single extension. let new_prefix = Nibbles::from_nibbles_unchecked( [prefix.as_slice(), child_prefix.as_slice()].concat(), ); - *self = TrieNode::Extension { prefix: new_prefix, node: child_node.clone() }; + *self = Self::Extension { prefix: new_prefix, node: child_node.clone() }; } - TrieNode::Leaf { prefix: child_prefix, value: child_value } => { + Self::Leaf { prefix: child_prefix, value: child_value } => { // If the child node is a leaf, convert the extension into a leaf with the full // path. let new_prefix = Nibbles::from_nibbles_unchecked( [prefix.as_slice(), child_prefix.as_slice()].concat(), ); - *self = TrieNode::Leaf { prefix: new_prefix, value: child_value.clone() }; + *self = Self::Leaf { prefix: new_prefix, value: child_value.clone() }; } - TrieNode::Empty => { + Self::Empty => { // If the child node is empty, convert the extension into an empty node. - *self = TrieNode::Empty; + *self = Self::Empty; } - TrieNode::Blinded { .. } => { + Self::Blinded { .. } => { node.unblind(fetcher)?; self.collapse_if_possible(fetcher, hinter)?; } _ => {} }, - TrieNode::Branch { stack } => { + Self::Branch { stack } => { // Count non-empty children let mut non_empty_children = stack .iter_mut() .enumerate() - .filter(|(_, node)| !matches!(node, TrieNode::Empty)) + .filter(|(_, node)| !matches!(node, Self::Empty)) .collect::>(); if non_empty_children.len() == 1 { @@ -467,25 +467,25 @@ impl TrieNode { // If only one non-empty child and no value, convert to extension or leaf match non_empty_node { - TrieNode::Leaf { prefix, value } => { + Self::Leaf { prefix, value } => { let new_prefix = Nibbles::from_nibbles_unchecked( [&[*index as u8], prefix.as_slice()].concat(), ); - *self = TrieNode::Leaf { prefix: new_prefix, value: value.clone() }; + *self = Self::Leaf { prefix: new_prefix, value: value.clone() }; } - TrieNode::Extension { prefix, node } => { + Self::Extension { prefix, node } => { let new_prefix = Nibbles::from_nibbles_unchecked( [&[*index as u8], prefix.as_slice()].concat(), ); - *self = TrieNode::Extension { prefix: new_prefix, node: node.clone() }; + *self = Self::Extension { prefix: new_prefix, node: node.clone() }; } - TrieNode::Branch { .. } => { - *self = TrieNode::Extension { + Self::Branch { .. } => { + *self = Self::Extension { prefix: Nibbles::from_nibbles_unchecked([*index as u8]), node: Box::new(non_empty_node.clone()), }; } - TrieNode::Blinded { commitment } => { + Self::Blinded { commitment } => { // In this special case, we need to send a hint to fetch the preimage of // the blinded node, since it is outside of the paths that have been // traversed so far. @@ -524,9 +524,8 @@ impl TrieNode { match first_nibble { PREFIX_EXTENSION_EVEN | PREFIX_EXTENSION_ODD => { // Extension node - let extension_node_value = - TrieNode::decode(buf).map_err(TrieNodeError::RLPError)?; - Ok(TrieNode::Extension { + let extension_node_value = Self::decode(buf).map_err(TrieNodeError::RLPError)?; + Ok(Self::Extension { prefix: unpack_path_to_nibbles(first, path[1..].as_ref()), node: Box::new(extension_node_value), }) @@ -534,10 +533,7 @@ impl TrieNode { PREFIX_LEAF_EVEN | PREFIX_LEAF_ODD => { // Leaf node let value = Bytes::decode(buf).map_err(TrieNodeError::RLPError)?; - Ok(TrieNode::Leaf { - prefix: unpack_path_to_nibbles(first, path[1..].as_ref()), - value, - }) + Ok(Self::Leaf { prefix: unpack_path_to_nibbles(first, path[1..].as_ref()), value }) } _ => Err(TrieNodeError::InvalidNodeType), } @@ -546,23 +542,23 @@ impl TrieNode { /// Returns the RLP payload length of the [TrieNode]. pub(crate) fn payload_length(&self) -> usize { match self { - TrieNode::Empty => 0, - TrieNode::Blinded { commitment } => commitment.len(), - TrieNode::Leaf { prefix, value } => { + Self::Empty => 0, + Self::Blinded { commitment } => commitment.len(), + Self::Leaf { prefix, value } => { let mut encoded_key_len = prefix.len() / 2 + 1; if encoded_key_len != 1 { encoded_key_len += length_of_length(encoded_key_len); } encoded_key_len + value.length() } - TrieNode::Extension { prefix, node } => { + Self::Extension { prefix, node } => { let mut encoded_key_len = prefix.len() / 2 + 1; if encoded_key_len != 1 { encoded_key_len += length_of_length(encoded_key_len); } encoded_key_len + node.blinded_length() } - TrieNode::Branch { stack } => { + Self::Branch { stack } => { // In branch nodes, if an element is longer than an encoded 32 byte string, it is // blinded. Assuming we have an open trie node, we must re-hash the // elements that are longer than an encoded 32 byte string @@ -583,7 +579,7 @@ impl TrieNode { /// than a [B256]. fn blinded_length(&self) -> usize { let encoded_len = self.length(); - if encoded_len >= B256::ZERO.len() && !matches!(self, TrieNode::Blinded { .. }) { + if encoded_len >= B256::ZERO.len() && !matches!(self, Self::Blinded { .. }) { B256::ZERO.length() } else { encoded_len @@ -656,7 +652,7 @@ impl Decodable for TrieNode { match list_length { BRANCH_LIST_LENGTH => { - let list = Vec::::decode(buf)?; + let list = Vec::::decode(buf)?; Ok(Self::Branch { stack: list }) } LEAF_OR_EXTENSION_LIST_LENGTH => { diff --git a/crates/mpt/src/test_util.rs b/crates/mpt/src/test_util.rs index cb590bcb8f..55d59d0abe 100644 --- a/crates/mpt/src/test_util.rs +++ b/crates/mpt/src/test_util.rs @@ -122,7 +122,7 @@ pub(crate) struct TrieNodeProvider { } impl TrieNodeProvider { - pub(crate) fn new( + pub(crate) const fn new( preimages: BTreeMap, bytecode: BTreeMap, headers: BTreeMap, diff --git a/crates/preimage/Cargo.toml b/crates/preimage/Cargo.toml index ab47a6bc0b..159d500e0c 100644 --- a/crates/preimage/Cargo.toml +++ b/crates/preimage/Cargo.toml @@ -8,6 +8,9 @@ license.workspace = true repository.workspace = true homepage.workspace = true +[lints] +workspace = true + [dependencies] # General thiserror.workspace = true diff --git a/crates/preimage/src/hint.rs b/crates/preimage/src/hint.rs index 208771c4f8..9dcb16061c 100644 --- a/crates/preimage/src/hint.rs +++ b/crates/preimage/src/hint.rs @@ -58,7 +58,7 @@ pub struct HintReader { impl HintReader { /// Create a new [HintReader] from a [PipeHandle]. - pub fn new(pipe_handle: PipeHandle) -> Self { + pub const fn new(pipe_handle: PipeHandle) -> Self { Self { pipe_handle } } } @@ -113,7 +113,7 @@ impl HintReaderServer for HintReader { mod test { use super::*; use crate::test_utils::bidirectional_pipe; - use alloc::{string::ToString, sync::Arc, vec::Vec}; + use alloc::{sync::Arc, vec::Vec}; use kona_common::FileDescriptor; use std::os::unix::io::AsRawFd; use tokio::sync::Mutex; @@ -170,7 +170,7 @@ mod test { let PreimageOracleError::Other(e) = e else { return false; }; - e.to_string().contains("Failed to decode hint payload") + e.contains("Failed to decode hint payload") })); } diff --git a/crates/preimage/src/key.rs b/crates/preimage/src/key.rs index 0c10729ec4..76d9331480 100644 --- a/crates/preimage/src/key.rs +++ b/crates/preimage/src/key.rs @@ -41,12 +41,12 @@ impl TryFrom for PreimageKeyType { fn try_from(value: u8) -> Result { let key_type = match value { - 1 => PreimageKeyType::Local, - 2 => PreimageKeyType::Keccak256, - 3 => PreimageKeyType::GlobalGeneric, - 4 => PreimageKeyType::Sha256, - 5 => PreimageKeyType::Blob, - 6 => PreimageKeyType::Precompile, + 1 => Self::Local, + 2 => Self::Keccak256, + 3 => Self::GlobalGeneric, + 4 => Self::Sha256, + 5 => Self::Blob, + 6 => Self::Precompile, _ => return Err(InvalidPreimageKeyType), }; Ok(key_type) @@ -87,12 +87,12 @@ impl PreimageKey { } /// Returns the [PreimageKeyType] for the [PreimageKey]. - pub fn key_type(&self) -> PreimageKeyType { + pub const fn key_type(&self) -> PreimageKeyType { self.key_type } /// Returns the value of the [PreimageKey] as a [U256]. - pub fn key_value(&self) -> U256 { + pub const fn key_value(&self) -> U256 { U256::from_be_slice(self.data.as_slice()) } } @@ -109,7 +109,7 @@ impl From for [u8; 32] { impl From for B256 { fn from(value: PreimageKey) -> Self { let raw: [u8; 32] = value.into(); - B256::from(raw) + Self::from(raw) } } diff --git a/crates/preimage/src/lib.rs b/crates/preimage/src/lib.rs index 5bf2ac295f..c034f2e946 100644 --- a/crates/preimage/src/lib.rs +++ b/crates/preimage/src/lib.rs @@ -1,6 +1,4 @@ #![doc = include_str!("../README.md")] -#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] -#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(test), no_std)] diff --git a/crates/preimage/src/oracle.rs b/crates/preimage/src/oracle.rs index a569c12c92..4749bcb534 100644 --- a/crates/preimage/src/oracle.rs +++ b/crates/preimage/src/oracle.rs @@ -93,7 +93,7 @@ pub struct OracleServer { impl OracleServer { /// Create a new [OracleServer] from a [PipeHandle]. - pub fn new(pipe_handle: PipeHandle) -> Self { + pub const fn new(pipe_handle: PipeHandle) -> Self { Self { pipe_handle } } } diff --git a/crates/preimage/src/pipe.rs b/crates/preimage/src/pipe.rs index 4a85c0fca1..0af6829df2 100644 --- a/crates/preimage/src/pipe.rs +++ b/crates/preimage/src/pipe.rs @@ -41,12 +41,12 @@ impl PipeHandle { } /// Returns the read handle for the pipe. - pub fn read_handle(&self) -> FileDescriptor { + pub const fn read_handle(&self) -> FileDescriptor { self.read_handle } /// Returns the write handle for the pipe. - pub fn write_handle(&self) -> FileDescriptor { + pub const fn write_handle(&self) -> FileDescriptor { self.write_handle } } diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 840e4e1a3f..6cb526a526 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -8,6 +8,9 @@ license.workspace = true repository.workspace = true homepage.workspace = true +[lints] +workspace = true + [dependencies] # General anyhow.workspace = true diff --git a/crates/primitives/src/blob.rs b/crates/primitives/src/blob.rs index 20c3b4415a..d28db0cd13 100644 --- a/crates/primitives/src/blob.rs +++ b/crates/primitives/src/blob.rs @@ -194,7 +194,7 @@ impl BlobData { } /// Returns if a blob is empty. - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.data.is_none() && self.calldata.is_none() } diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 707372503a..3949704728 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -1,6 +1,4 @@ #![doc = include_str!("../README.md")] -#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] -#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(test), no_std)] diff --git a/crates/primitives/src/sidecar.rs b/crates/primitives/src/sidecar.rs index a48486a239..80682da6b5 100644 --- a/crates/primitives/src/sidecar.rs +++ b/crates/primitives/src/sidecar.rs @@ -200,7 +200,7 @@ pub struct APIGenesisResponse { impl APIGenesisResponse { /// Creates a new API genesis response. - pub fn new(genesis_time: u64) -> Self { + pub const fn new(genesis_time: u64) -> Self { Self { data: ReducedGenesisData { genesis_time } } } } @@ -225,7 +225,7 @@ pub struct APIConfigResponse { impl APIConfigResponse { /// Creates a new API config response. - pub fn new(seconds_per_slot: u64) -> Self { + pub const fn new(seconds_per_slot: u64) -> Self { Self { data: ReducedConfigData { seconds_per_slot } } } }