From 57fe11206ea9bb84a1aba89c2eaaec0b5b83a8b1 Mon Sep 17 00:00:00 2001 From: sadiq1971 Date: Wed, 14 May 2025 18:54:01 +0600 Subject: [PATCH 01/22] feat: added reth dependency to create db table --- Cargo.lock | 864 +++++++++++++++--- crates/supervisor/core/Cargo.toml | 6 + crates/supervisor/core/src/lib.rs | 2 + crates/supervisor/core/src/state/log/mod.rs | 1 + crates/supervisor/core/src/state/log/table.rs | 89 ++ crates/supervisor/core/src/state/mod.rs | 2 + crates/supervisor/core/src/types/log.rs | 16 + crates/supervisor/core/src/types/message.rs | 18 + 8 files changed, 867 insertions(+), 131 deletions(-) create mode 100644 crates/supervisor/core/src/state/log/mod.rs create mode 100644 crates/supervisor/core/src/state/log/table.rs create mode 100644 crates/supervisor/core/src/types/log.rs create mode 100644 crates/supervisor/core/src/types/message.rs diff --git a/Cargo.lock b/Cargo.lock index 7d1b4dfecb..bfdf1b2ac4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,6 +116,29 @@ dependencies = [ "strum 0.27.1", ] +[[package]] +name = "alloy-consensus" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2179ba839ac532f50279f5da2a6c5047f791f03f6f808b4dfab11327b97902f" +dependencies = [ + "alloy-eips 0.14.0", + "alloy-primitives", + "alloy-rlp", + "alloy-serde 0.14.0", + "alloy-trie", + "auto_impl", + "c-kzg", + "derive_more", + "either", + "k256", + "once_cell", + "rand 0.8.5", + "serde", + "serde_with", + "thiserror 2.0.12", +] + [[package]] name = "alloy-consensus" version = "0.15.11" @@ -141,13 +164,27 @@ dependencies = [ "thiserror 2.0.12", ] +[[package]] +name = "alloy-consensus-any" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aec6f67bdc62aa277e0ec13c1b1fb396c8a62b65c8e9bd8c1d3583cc6d1a8dd3" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-eips 0.14.0", + "alloy-primitives", + "alloy-rlp", + "alloy-serde 0.14.0", + "serde", +] + [[package]] name = "alloy-consensus-any" version = "0.15.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dda014fb5591b8d8d24cab30f52690117d238e52254c6fb40658e91ea2ccd6c3" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-rlp", @@ -242,25 +279,57 @@ dependencies = [ "sha2 0.10.9", ] +[[package]] +name = "alloy-evm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caabd28657614cecc14d77fde0a630c5c177bfe432ce4ad99db0ad41d9219856" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-eips 0.14.0", + "alloy-hardforks", + "alloy-primitives", + "alloy-sol-types", + "auto_impl", + "derive_more", + "op-alloy-consensus 0.14.1", + "op-revm 3.0.2", + "revm 22.0.1", + "thiserror 2.0.12", +] + [[package]] name = "alloy-evm" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7263f5a79a16743b33237017097886d7bd62d4d32eebe64f22e0a7c7ba70f4" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-hardforks", "alloy-primitives", "alloy-sol-types", "auto_impl", "derive_more", - "op-alloy-consensus", - "op-revm", - "revm", + "op-alloy-consensus 0.15.7", + "op-revm 4.0.2", + "revm 23.1.0", "thiserror 2.0.12", ] +[[package]] +name = "alloy-genesis" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dfec8348d97bd624901c6a4b22bb4c24df8a3128fc3d5e42d24f7b79dfa8588" +dependencies = [ + "alloy-eips 0.14.0", + "alloy-primitives", + "alloy-serde 0.14.0", + "alloy-trie", + "serde", +] + [[package]] name = "alloy-hardforks" version = "0.2.0" @@ -306,14 +375,14 @@ version = "0.15.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879afc0f4a528908c8fe6935b2ab0bc07f77221a989186f71583f7592831689e" dependencies = [ - "alloy-consensus", - "alloy-consensus-any", + "alloy-consensus 0.15.11", + "alloy-consensus-any 0.15.11", "alloy-eips 0.15.11", "alloy-json-rpc", - "alloy-network-primitives", + "alloy-network-primitives 0.15.11", "alloy-primitives", "alloy-rpc-types-any", - "alloy-rpc-types-eth", + "alloy-rpc-types-eth 0.15.11", "alloy-serde 0.15.11", "alloy-signer", "alloy-sol-types", @@ -326,13 +395,26 @@ dependencies = [ "thiserror 2.0.12", ] +[[package]] +name = "alloy-network-primitives" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "498f2ee2eef38a6db0fc810c7bf7daebdf5f2fa8d04adb8bd53e54e91ddbdea3" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-eips 0.14.0", + "alloy-primitives", + "alloy-serde 0.14.0", + "serde", +] + [[package]] name = "alloy-network-primitives" version = "0.15.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec185bac9d32df79c1132558a450d48f6db0bfb5adef417dbb1a0258153f879b" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-serde 0.15.11", @@ -345,15 +427,15 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2379a87a3018a563a0524002caed789ac832a8ae8ff0270189559dccf8e49ae9" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", - "alloy-evm", + "alloy-evm 0.7.2", "alloy-op-hardforks", "alloy-primitives", "auto_impl", - "op-alloy-consensus", - "op-revm", - "revm", + "op-alloy-consensus 0.15.7", + "op-revm 4.0.2", + "revm 23.1.0", ] [[package]] @@ -404,16 +486,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2d918534afe9cc050eabd8309c107dafd161aa77357782eca4f218bef08a660" dependencies = [ "alloy-chains", - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-json-rpc", "alloy-network", - "alloy-network-primitives", + "alloy-network-primitives 0.15.11", "alloy-primitives", "alloy-pubsub", "alloy-rpc-client", "alloy-rpc-types-engine", - "alloy-rpc-types-eth", + "alloy-rpc-types-eth 0.15.11", "alloy-signer", "alloy-sol-types", "alloy-transport", @@ -519,7 +601,7 @@ checksum = "4aa10e26554ad7f79a539a6a8851573aedec5289f1f03244aad0bdbc324bfe5c" dependencies = [ "alloy-primitives", "alloy-rpc-types-debug", - "alloy-rpc-types-eth", + "alloy-rpc-types-eth 0.15.11", "alloy-serde 0.15.11", "serde", ] @@ -530,8 +612,8 @@ version = "0.15.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5a8f1efd77116915dad61092f9ef9295accd0b0b251062390d9c4e81599344" dependencies = [ - "alloy-consensus-any", - "alloy-rpc-types-eth", + "alloy-consensus-any 0.15.11", + "alloy-rpc-types-eth 0.15.11", "alloy-serde 0.15.11", ] @@ -565,7 +647,7 @@ version = "0.15.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "246c225f878dbcb8ad405949a30c403b3bb43bdf974f7f0331b276f835790a5e" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-rlp", @@ -579,16 +661,36 @@ dependencies = [ "strum 0.27.1", ] +[[package]] +name = "alloy-rpc-types-eth" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2a9f64e0f69cfb6029e2a044519a1bdd44ce9fc334d5315a7b9837f7a6748e5" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-consensus-any 0.14.0", + "alloy-eips 0.14.0", + "alloy-network-primitives 0.14.0", + "alloy-primitives", + "alloy-rlp", + "alloy-serde 0.14.0", + "alloy-sol-types", + "itertools 0.13.0", + "serde", + "serde_json", + "thiserror 2.0.12", +] + [[package]] name = "alloy-rpc-types-eth" version = "0.15.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc1323310d87f9d950fb3ff58d943fdf832f5e10e6f902f405c0eaa954ffbaf1" dependencies = [ - "alloy-consensus", - "alloy-consensus-any", + "alloy-consensus 0.15.11", + "alloy-consensus-any 0.15.11", "alloy-eips 0.15.11", - "alloy-network-primitives", + "alloy-network-primitives 0.15.11", "alloy-primitives", "alloy-rlp", "alloy-serde 0.15.11", @@ -1517,6 +1619,9 @@ name = "bitflags" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +dependencies = [ + "serde", +] [[package]] name = "bitvec" @@ -1526,6 +1631,7 @@ checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" dependencies = [ "funty", "radium", + "serde", "tap", "wyz", ] @@ -2099,6 +2205,12 @@ dependencies = [ "itertools 0.10.5", ] +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + [[package]] name = "crossbeam-channel" version = "0.5.15" @@ -2686,6 +2798,17 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "enumn" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "equator" version = "0.4.2" @@ -4322,9 +4445,9 @@ dependencies = [ name = "kona-client" version = "1.0.1" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", - "alloy-evm", + "alloy-evm 0.7.2", "alloy-op-evm", "alloy-primitives", "alloy-rlp", @@ -4345,10 +4468,10 @@ dependencies = [ "kona-std-fpvm", "kona-std-fpvm-proc", "lru 0.14.0", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-types-engine", - "op-revm", - "revm", + "op-revm 4.0.2", + "revm 23.1.0", "serde", "serde_json", "sha2 0.10.9", @@ -4363,7 +4486,7 @@ name = "kona-comp" version = "0.3.0" dependencies = [ "alloc-no-stdlib", - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-rlp", @@ -4377,7 +4500,7 @@ dependencies = [ "kona-genesis", "kona-protocol", "miniz_oxide", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "proptest", "rand 0.9.1", "serde", @@ -4393,7 +4516,7 @@ dependencies = [ name = "kona-derive" version = "0.3.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-rlp", @@ -4404,7 +4527,7 @@ dependencies = [ "kona-hardforks", "kona-protocol", "kona-registry", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-types-engine", "proptest", "serde", @@ -4420,8 +4543,8 @@ dependencies = [ name = "kona-driver" version = "0.3.0" dependencies = [ - "alloy-consensus", - "alloy-evm", + "alloy-consensus 0.15.11", + "alloy-evm 0.7.2", "alloy-primitives", "alloy-rlp", "async-trait", @@ -4429,7 +4552,7 @@ dependencies = [ "kona-executor", "kona-genesis", "kona-protocol", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-types-engine", "spin 0.10.0", "thiserror 2.0.12", @@ -4440,15 +4563,15 @@ dependencies = [ name = "kona-engine" version = "0.1.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-network", - "alloy-network-primitives", + "alloy-network-primitives 0.15.11", "alloy-primitives", "alloy-provider", "alloy-rpc-client", "alloy-rpc-types-engine", - "alloy-rpc-types-eth", + "alloy-rpc-types-eth 0.15.11", "alloy-transport", "alloy-transport-http", "arbitrary", @@ -4461,7 +4584,7 @@ dependencies = [ "kona-registry", "metrics", "metrics-exporter-prometheus", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-network", "op-alloy-provider", "op-alloy-rpc-types", @@ -4482,9 +4605,9 @@ dependencies = [ name = "kona-executor" version = "0.3.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", - "alloy-evm", + "alloy-evm 0.7.2", "alloy-op-evm", "alloy-op-hardforks", "alloy-primitives", @@ -4500,11 +4623,11 @@ dependencies = [ "kona-mpt", "kona-protocol", "kona-registry", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-types-engine", - "op-revm", + "op-revm 4.0.2", "rand 0.9.1", - "revm", + "revm 23.1.0", "rocksdb", "rstest", "serde", @@ -4519,7 +4642,7 @@ dependencies = [ name = "kona-genesis" version = "0.3.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-hardforks", "alloy-op-hardforks", @@ -4528,7 +4651,7 @@ dependencies = [ "arbitrary", "derive_more", "kona-serde", - "op-revm", + "op-revm 4.0.2", "rand 0.9.1", "serde", "serde_json", @@ -4544,16 +4667,16 @@ dependencies = [ "alloy-eips 0.15.11", "alloy-primitives", "kona-protocol", - "op-alloy-consensus", - "op-revm", - "revm", + "op-alloy-consensus 0.15.7", + "op-revm 4.0.2", + "revm 23.1.0", ] [[package]] name = "kona-host" version = "1.0.1" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-op-evm", "alloy-primitives", @@ -4587,7 +4710,7 @@ dependencies = [ "op-alloy-rpc-types-engine", "proptest", "reqwest", - "revm", + "revm 23.1.0", "rocksdb", "serde", "serde_json", @@ -4601,7 +4724,7 @@ dependencies = [ name = "kona-interop" version = "0.3.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-rlp", @@ -4612,7 +4735,7 @@ dependencies = [ "kona-genesis", "kona-protocol", "kona-registry", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "rand 0.9.1", "serde", "serde_json", @@ -4629,7 +4752,7 @@ version = "0.1.0" name = "kona-mpt" version = "0.2.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-primitives", "alloy-provider", "alloy-rlp", @@ -4694,7 +4817,7 @@ dependencies = [ "alloy-provider", "alloy-rpc-client", "alloy-rpc-types-engine", - "alloy-rpc-types-eth", + "alloy-rpc-types-eth 0.15.11", "alloy-transport", "alloy-transport-http", "async-trait", @@ -4726,7 +4849,7 @@ dependencies = [ name = "kona-p2p" version = "0.1.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-rlp", @@ -4745,7 +4868,7 @@ dependencies = [ "libp2p-identity", "metrics", "multihash", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-types-engine", "openssl", "rand 0.9.1", @@ -4779,9 +4902,9 @@ dependencies = [ name = "kona-proof" version = "0.3.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", - "alloy-evm", + "alloy-evm 0.7.2", "alloy-op-evm", "alloy-primitives", "alloy-rlp", @@ -4800,9 +4923,9 @@ dependencies = [ "kona-registry", "lazy_static", "lru 0.14.0", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-types-engine", - "op-revm", + "op-revm 4.0.2", "rand 0.9.1", "rayon", "rstest", @@ -4818,9 +4941,9 @@ dependencies = [ name = "kona-proof-interop" version = "0.2.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", - "alloy-evm", + "alloy-evm 0.7.2", "alloy-op-evm", "alloy-primitives", "alloy-rlp", @@ -4835,11 +4958,11 @@ dependencies = [ "kona-proof", "kona-protocol", "kona-registry", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-types-engine", - "op-revm", + "op-revm 4.0.2", "rand 0.9.1", - "revm", + "revm 23.1.0", "serde", "serde_json", "spin 0.10.0", @@ -4852,12 +4975,12 @@ name = "kona-protocol" version = "0.3.0" dependencies = [ "alloc-no-stdlib", - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-rlp", "alloy-rpc-types-engine", - "alloy-rpc-types-eth", + "alloy-rpc-types-eth 0.15.11", "alloy-serde 0.15.11", "alloy-sol-types", "arbitrary", @@ -4867,7 +4990,7 @@ dependencies = [ "kona-genesis", "kona-protocol", "miniz_oxide", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-types", "op-alloy-rpc-types-engine", "proptest", @@ -4887,7 +5010,7 @@ dependencies = [ name = "kona-providers-alloy" version = "0.2.0" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-provider", @@ -4903,7 +5026,7 @@ dependencies = [ "kona-genesis", "kona-protocol", "lru 0.14.0", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-network", "reqwest", "serde", @@ -4945,7 +5068,7 @@ dependencies = [ "kona-p2p", "kona-protocol", "metrics", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-jsonrpsee", "op-alloy-rpc-types-engine", "serde", @@ -5030,11 +5153,14 @@ version = "0.1.0" dependencies = [ "alloy-eips 0.15.11", "alloy-primitives", + "alloy-rlp", "async-trait", "jsonrpsee 0.25.1", "kona-interop", "kona-supervisor-rpc", "metrics", + "reth-db-api", + "serde", "thiserror 2.0.12", "tracing", ] @@ -5745,6 +5871,27 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "modular-bitfield" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a53d79ba8304ac1c4f9eb3b9d281f21f7be9d4626f72ce7df4ad8fbde4f38a74" +dependencies = [ + "modular-bitfield-impl", + "static_assertions", +] + +[[package]] +name = "modular-bitfield-impl" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a7d5f7076603ebc68de2dc6a650ec331a062a13abaa346975be747bbfa4b789" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "moka" version = "0.12.10" @@ -6120,6 +6267,10 @@ name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +dependencies = [ + "critical-section", + "portable-atomic", +] [[package]] name = "oorandom" @@ -6127,13 +6278,29 @@ version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" +[[package]] +name = "op-alloy-consensus" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f400404e37862bb974fbc3ad2d8ca2a2df286b718e762446496d04267ee912" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-eips 0.14.0", + "alloy-primitives", + "alloy-rlp", + "alloy-serde 0.14.0", + "derive_more", + "serde", + "thiserror 2.0.12", +] + [[package]] name = "op-alloy-consensus" version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c33ec121a10f7348ee360b8af71caf4623d7e61942c046cdbe4360e4b640316a" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-rlp", @@ -6150,12 +6317,12 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1402f67836bb833948037ca6128e0bc7a5261f47d50c4a4b38470c2ecabf6362" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-network", "alloy-primitives", - "alloy-rpc-types-eth", + "alloy-rpc-types-eth 0.15.11", "alloy-signer", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "op-alloy-rpc-types", ] @@ -6190,15 +6357,15 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "084a0a5dc3d5af1e161ca5a602b9efac872c7d416120be24d7f33e299973a204" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", - "alloy-network-primitives", + "alloy-network-primitives 0.15.11", "alloy-primitives", - "alloy-rpc-types-eth", + "alloy-rpc-types-eth 0.15.11", "alloy-serde 0.15.11", "arbitrary", "derive_more", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "serde", "serde_json", ] @@ -6209,7 +6376,7 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d840947bd5ce24a8db8a29eb7b0eaf8c2280a56eefe968c44a5aa79afe6af51" dependencies = [ - "alloy-consensus", + "alloy-consensus 0.15.11", "alloy-eips 0.15.11", "alloy-primitives", "alloy-rlp", @@ -6217,12 +6384,24 @@ dependencies = [ "alloy-serde 0.15.11", "derive_more", "ethereum_ssz", - "op-alloy-consensus", + "op-alloy-consensus 0.15.7", "serde", "snap", "thiserror 2.0.12", ] +[[package]] +name = "op-revm" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8646cb935063087579f44da58fe1dea329c280c3b35898d6fd01a928de91f" +dependencies = [ + "auto_impl", + "once_cell", + "revm 22.0.1", + "serde", +] + [[package]] name = "op-revm" version = "4.0.2" @@ -6231,7 +6410,7 @@ checksum = "e2d9ddee86c9927dd88cd3037008f98c04016b013cd7c2822015b134e8d9b465" dependencies = [ "auto_impl", "once_cell", - "revm", + "revm 23.1.0", "serde", ] @@ -6345,6 +6524,7 @@ dependencies = [ "arrayvec", "bitvec", "byte-slice-cast", + "bytes", "const_format", "impl-trait-for-tuples", "parity-scale-codec-derive", @@ -6444,6 +6624,7 @@ checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" dependencies = [ "phf_macros", "phf_shared", + "serde", ] [[package]] @@ -7195,23 +7376,255 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95325155c684b1c89f7765e30bc1c42e4a6da51ca513615660cb8a62ef9a88e3" +[[package]] +name = "reth-codecs" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-eips 0.14.0", + "alloy-genesis", + "alloy-primitives", + "alloy-trie", + "bytes", + "modular-bitfield", + "op-alloy-consensus 0.14.1", + "reth-codecs-derive", + "reth-zstd-compressors", + "serde", +] + +[[package]] +name = "reth-codecs-derive" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "reth-db-api" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-genesis", + "alloy-primitives", + "bytes", + "derive_more", + "metrics", + "modular-bitfield", + "parity-scale-codec", + "reth-codecs", + "reth-db-models", + "reth-ethereum-primitives", + "reth-primitives-traits", + "reth-prune-types", + "reth-stages-types", + "reth-storage-errors", + "reth-trie-common", + "roaring", + "serde", +] + +[[package]] +name = "reth-db-models" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-eips 0.14.0", + "alloy-primitives", + "bytes", + "modular-bitfield", + "reth-codecs", + "reth-primitives-traits", + "serde", +] + +[[package]] +name = "reth-ethereum-primitives" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-eips 0.14.0", + "alloy-evm 0.5.0", + "alloy-primitives", + "alloy-rlp", + "alloy-rpc-types-eth 0.14.0", + "derive_more", + "modular-bitfield", + "rand 0.8.5", + "reth-codecs", + "reth-primitives-traits", + "reth-zstd-compressors", + "revm-context 3.0.1", + "secp256k1 0.30.0", + "serde", + "serde_with", +] + +[[package]] +name = "reth-primitives-traits" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-eips 0.14.0", + "alloy-genesis", + "alloy-primitives", + "alloy-rlp", + "alloy-trie", + "auto_impl", + "byteorder", + "bytes", + "derive_more", + "k256", + "modular-bitfield", + "once_cell", + "op-alloy-consensus 0.14.1", + "reth-codecs", + "revm-bytecode 3.0.0", + "revm-primitives 18.0.0", + "revm-state 3.0.0", + "secp256k1 0.30.0", + "serde", + "serde_with", + "thiserror 2.0.12", +] + +[[package]] +name = "reth-prune-types" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-primitives", + "derive_more", + "modular-bitfield", + "reth-codecs", + "serde", + "thiserror 2.0.12", +] + +[[package]] +name = "reth-stages-types" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-primitives", + "bytes", + "modular-bitfield", + "reth-codecs", + "reth-trie-common", + "serde", +] + +[[package]] +name = "reth-static-file-types" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-primitives", + "derive_more", + "serde", + "strum 0.27.1", +] + +[[package]] +name = "reth-storage-errors" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-eips 0.14.0", + "alloy-primitives", + "alloy-rlp", + "derive_more", + "reth-primitives-traits", + "reth-prune-types", + "reth-static-file-types", + "revm-database-interface 3.0.0", + "thiserror 2.0.12", +] + +[[package]] +name = "reth-trie-common" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-consensus 0.14.0", + "alloy-primitives", + "alloy-rlp", + "alloy-rpc-types-eth 0.14.0", + "alloy-trie", + "bytes", + "derive_more", + "itertools 0.14.0", + "nybbles", + "reth-codecs", + "reth-primitives-traits", + "revm-database 3.0.0", + "serde", +] + +[[package]] +name = "reth-zstd-compressors" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "zstd", +] + +[[package]] +name = "revm" +version = "22.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5378e95ffe5c8377002dafeb6f7d370a55517cef7d6d6c16fc552253af3b123" +dependencies = [ + "revm-bytecode 3.0.0", + "revm-context 3.0.1", + "revm-context-interface 3.0.0", + "revm-database 3.0.0", + "revm-database-interface 3.0.0", + "revm-handler 3.0.1", + "revm-inspector 3.0.1", + "revm-interpreter 18.0.0", + "revm-precompile 19.0.0", + "revm-primitives 18.0.0", + "revm-state 3.0.0", +] + [[package]] name = "revm" version = "23.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df1eb83c8652836bc0422f9a144522179134d8befcc7ab595c1ada60dac39e51" dependencies = [ - "revm-bytecode", - "revm-context", - "revm-context-interface", - "revm-database", - "revm-database-interface", - "revm-handler", - "revm-inspector", - "revm-interpreter", - "revm-precompile", - "revm-primitives", - "revm-state", + "revm-bytecode 4.0.0", + "revm-context 4.1.0", + "revm-context-interface 4.1.0", + "revm-database 4.0.0", + "revm-database-interface 4.0.0", + "revm-handler 4.1.0", + "revm-inspector 4.1.0", + "revm-interpreter 19.1.0", + "revm-precompile 20.1.0", + "revm-primitives 19.0.0", + "revm-state 4.0.0", +] + +[[package]] +name = "revm-bytecode" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e63e138d520c5c5bc25ecc82506e9e4e6e85a811809fc5251c594378dccabfc6" +dependencies = [ + "bitvec", + "phf", + "revm-primitives 18.0.0", + "serde", ] [[package]] @@ -7223,7 +7636,23 @@ dependencies = [ "bitvec", "once_cell", "phf", - "revm-primitives", + "revm-primitives 19.0.0", + "serde", +] + +[[package]] +name = "revm-context" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9765628dfea4f3686aa8f2a72471c52801e6b38b601939ac16965f49bac66580" +dependencies = [ + "cfg-if", + "derive-where", + "revm-bytecode 3.0.0", + "revm-context-interface 3.0.0", + "revm-database-interface 3.0.0", + "revm-primitives 18.0.0", + "revm-state 3.0.0", "serde", ] @@ -7235,11 +7664,26 @@ checksum = "bcd6faa992a1a10b84723326d6117203764c040d3519fd1ba34950d049389eb7" dependencies = [ "cfg-if", "derive-where", - "revm-bytecode", - "revm-context-interface", - "revm-database-interface", - "revm-primitives", - "revm-state", + "revm-bytecode 4.0.0", + "revm-context-interface 4.1.0", + "revm-database-interface 4.0.0", + "revm-primitives 19.0.0", + "revm-state 4.0.0", + "serde", +] + +[[package]] +name = "revm-context-interface" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d74335aa1f14222cc4d3be1f62a029cc7dc03819cc8d080ff17b7e1d76375f" +dependencies = [ + "alloy-eip2930", + "alloy-eip7702", + "auto_impl", + "revm-database-interface 3.0.0", + "revm-primitives 18.0.0", + "revm-state 3.0.0", "serde", ] @@ -7253,9 +7697,23 @@ dependencies = [ "alloy-eip7702", "auto_impl", "either", - "revm-database-interface", - "revm-primitives", - "revm-state", + "revm-database-interface 4.0.0", + "revm-primitives 19.0.0", + "revm-state 4.0.0", + "serde", +] + +[[package]] +name = "revm-database" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e5c80c5a2fd605f2119ee32a63fb3be941fb6a81ced8cdb3397abca28317224" +dependencies = [ + "alloy-eips 0.14.0", + "revm-bytecode 3.0.0", + "revm-database-interface 3.0.0", + "revm-primitives 18.0.0", + "revm-state 3.0.0", "serde", ] @@ -7266,10 +7724,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a16e1a58d5614bef333402ae8682d0ea7ba4f4b0563b3a58a6c0ad9d392db4f6" dependencies = [ "alloy-eips 0.14.0", - "revm-bytecode", - "revm-database-interface", - "revm-primitives", - "revm-state", + "revm-bytecode 4.0.0", + "revm-database-interface 4.0.0", + "revm-primitives 19.0.0", + "revm-state 4.0.0", + "serde", +] + +[[package]] +name = "revm-database-interface" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0e4dfbc734b1ea67b5e8f8b3c7dc4283e2210d978cdaf6c7a45e97be5ea53b3" +dependencies = [ + "auto_impl", + "revm-primitives 18.0.0", + "revm-state 3.0.0", "serde", ] @@ -7280,8 +7750,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6839eb2e1667d3acd9cba59f77299fae8802c229fae50bc6f0435ed4c4ef398e" dependencies = [ "auto_impl", - "revm-primitives", - "revm-state", + "revm-primitives 19.0.0", + "revm-state 4.0.0", + "serde", +] + +[[package]] +name = "revm-handler" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8676379521c7bf179c31b685c5126ce7800eab5844122aef3231b97026d41a10" +dependencies = [ + "auto_impl", + "revm-bytecode 3.0.0", + "revm-context 3.0.1", + "revm-context-interface 3.0.0", + "revm-database-interface 3.0.0", + "revm-interpreter 18.0.0", + "revm-precompile 19.0.0", + "revm-primitives 18.0.0", + "revm-state 3.0.0", "serde", ] @@ -7292,15 +7780,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "511e50a8c7f14e97681ec96266ee53bf8316c0dea1d4a6633ff6f37c5c0fe9d0" dependencies = [ "auto_impl", - "revm-bytecode", - "revm-context", - "revm-context-interface", - "revm-database-interface", - "revm-interpreter", - "revm-precompile", - "revm-primitives", - "revm-state", + "revm-bytecode 4.0.0", + "revm-context 4.1.0", + "revm-context-interface 4.1.0", + "revm-database-interface 4.0.0", + "revm-interpreter 19.1.0", + "revm-precompile 20.1.0", + "revm-primitives 19.0.0", + "revm-state 4.0.0", + "serde", +] + +[[package]] +name = "revm-inspector" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfed4ecf999a3f6ae776ae2d160478c5dca986a8c2d02168e04066b1e34c789e" +dependencies = [ + "auto_impl", + "revm-context 3.0.1", + "revm-database-interface 3.0.0", + "revm-handler 3.0.1", + "revm-interpreter 18.0.0", + "revm-primitives 18.0.0", + "revm-state 3.0.0", "serde", + "serde_json", ] [[package]] @@ -7310,28 +7815,64 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9f6c88fcf481f8e315bfd87377aa0ae83e1159dd381430122cbf431474ce39c" dependencies = [ "auto_impl", - "revm-context", - "revm-database-interface", - "revm-handler", - "revm-interpreter", - "revm-primitives", - "revm-state", + "revm-context 4.1.0", + "revm-database-interface 4.0.0", + "revm-handler 4.1.0", + "revm-interpreter 19.1.0", + "revm-primitives 19.0.0", + "revm-state 4.0.0", "serde", "serde_json", ] +[[package]] +name = "revm-interpreter" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feb20260342003cfb791536e678ef5bbea1bfd1f8178b170e8885ff821985473" +dependencies = [ + "revm-bytecode 3.0.0", + "revm-context-interface 3.0.0", + "revm-primitives 18.0.0", + "serde", +] + [[package]] name = "revm-interpreter" version = "19.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0b7d75106333808bc97df3cd6a1864ced4ffec9be28fd3e459733813f3c300e" dependencies = [ - "revm-bytecode", - "revm-context-interface", - "revm-primitives", + "revm-bytecode 4.0.0", + "revm-context-interface 4.1.0", + "revm-primitives 19.0.0", "serde", ] +[[package]] +name = "revm-precompile" +version = "19.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418e95eba68c9806c74f3e36cd5d2259170b61e90ac608b17ff8c435038ddace" +dependencies = [ + "ark-bls12-381", + "ark-bn254", + "ark-ec", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "aurora-engine-modexp", + "c-kzg", + "cfg-if", + "k256", + "libsecp256k1", + "once_cell", + "p256", + "revm-primitives 18.0.0", + "ripemd", + "secp256k1 0.30.0", + "sha2 0.10.9", +] + [[package]] name = "revm-precompile" version = "20.1.0" @@ -7351,12 +7892,23 @@ dependencies = [ "libsecp256k1", "once_cell", "p256", - "revm-primitives", + "revm-primitives 19.0.0", "ripemd", "secp256k1 0.30.0", "sha2 0.10.9", ] +[[package]] +name = "revm-primitives" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc2283ff87358ec7501956c5dd8724a6c2be959c619c4861395ae5e0054575f" +dependencies = [ + "alloy-primitives", + "enumn", + "serde", +] + [[package]] name = "revm-primitives" version = "19.0.0" @@ -7368,6 +7920,18 @@ dependencies = [ "serde", ] +[[package]] +name = "revm-state" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09dd121f6e66d75ab111fb51b4712f129511569bc3e41e6067ae760861418bd8" +dependencies = [ + "bitflags 2.9.0", + "revm-bytecode 3.0.0", + "revm-primitives 18.0.0", + "serde", +] + [[package]] name = "revm-state" version = "4.0.0" @@ -7375,8 +7939,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ac26c71bf0fe5a9cd9fe6adaa13487afedbf8c2ee6e228132eae074cb3c2b58" dependencies = [ "bitflags 2.9.0", - "revm-bytecode", - "revm-primitives", + "revm-bytecode 4.0.0", + "revm-primitives 19.0.0", "serde", ] @@ -7462,6 +8026,16 @@ dependencies = [ "rustc-hex", ] +[[package]] +name = "roaring" +version = "0.10.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e8d2cfa184d94d0726d650a9f4a1be7f9b76ac9fdb954219878dc00c1c1e7b" +dependencies = [ + "bytemuck", + "byteorder", +] + [[package]] name = "rocksdb" version = "0.23.0" @@ -10030,3 +10604,31 @@ dependencies = [ "quote", "syn 2.0.101", ] + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.15+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb81183ddd97d0c74cedf1d50d85c8d08c1b8b68ee863bdee9e706eedba1a237" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/crates/supervisor/core/Cargo.toml b/crates/supervisor/core/Cargo.toml index 15474f8a6c..cbf886b38b 100644 --- a/crates/supervisor/core/Cargo.toml +++ b/crates/supervisor/core/Cargo.toml @@ -20,15 +20,21 @@ kona-supervisor-rpc = { workspace = true, features = ["jsonrpsee"] } # Alloy alloy-eips.workspace = true alloy-primitives = { workspace = true, features = ["map", "rlp", "serde"] } +alloy-rlp = { workspace = true, features = ["arrayvec"] } # Misc jsonrpsee = { workspace = true, features = [ "server" ] } async-trait.workspace = true tracing = { workspace = true } thiserror.workspace = true +reth-db-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } + + + # `metrics` feature metrics = { workspace = true } +serde = { version = "1.0.219", features = ["derive"] } [lints] workspace = true diff --git a/crates/supervisor/core/src/lib.rs b/crates/supervisor/core/src/lib.rs index d6023d6e39..f5162e6ebc 100644 --- a/crates/supervisor/core/src/lib.rs +++ b/crates/supervisor/core/src/lib.rs @@ -5,4 +5,6 @@ mod supervisor; pub use supervisor::{Supervisor, SupervisorError, SupervisorService}; mod rpc; +mod state; + pub use rpc::SupervisorRpc; diff --git a/crates/supervisor/core/src/state/log/mod.rs b/crates/supervisor/core/src/state/log/mod.rs new file mode 100644 index 0000000000..1a1404c9ad --- /dev/null +++ b/crates/supervisor/core/src/state/log/mod.rs @@ -0,0 +1 @@ +mod table; \ No newline at end of file diff --git a/crates/supervisor/core/src/state/log/table.rs b/crates/supervisor/core/src/state/log/table.rs new file mode 100644 index 0000000000..ed0cd24f6b --- /dev/null +++ b/crates/supervisor/core/src/state/log/table.rs @@ -0,0 +1,89 @@ +use alloy_primitives::B256; +use alloy_rlp:: {RlpDecodable, RlpEncodable}; +use serde::{Deserialize, Serialize}; +use std::convert::TryInto; +use reth_db_api::DatabaseError; +use reth_db_api::{Tables}; +use reth_db_api::table::{Encode, Decode}; +use kona_interop::ExecutingMessage; + + +#[derive(Ord, PartialOrd, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] +pub struct LogKey { + pub chain_id: u64, + pub block_number: u64, + pub log_index: u32, +} + +impl Encode for LogKey { + type Encoded = [u8; 20]; + + fn encode(self) -> Self::Encoded { + let mut buf = [0u8; 20]; + buf[..8].copy_from_slice(&self.chain_id.to_be_bytes()); + buf[8..16].copy_from_slice(&self.block_number.to_be_bytes()); + buf[16..20].copy_from_slice(&self.log_index.to_be_bytes()); + buf + } +} + +impl Decode for LogKey { + fn decode(value: &[u8]) -> Result { + if value.len() != 20 { + return Err(DatabaseError::Decode); + } + + let chain_id = u64::from_be_bytes(value[0..8].try_into().unwrap()); + let block_number = u64::from_be_bytes(value[8..16].try_into().unwrap()); + let log_index = u32::from_be_bytes(value[16..20].try_into().unwrap()); + + Ok(LogKey { + chain_id, + block_number, + log_index, + }) + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] +#[rlp(trailing)] +pub struct LogValue { + pub hash: B256, + pub executing_message: Option, +} + +#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] +pub struct ExecutingMessageValue { + hash: B256, + timestamp: u64, +} + +// #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] +// pub struct BlockRef { +// pub hash: B256, +// pub number: u64, +// pub parent_hash: B256, +// pub time: u64, +// } +// +// +// use reth_db::table::{Table, TableInfo}; +// use serde::{Deserialize, Serialize}; +// +// pub struct LogsTable; +// impl Table for LogsTable { +// type Key = LogKey; +// type Value = LogValue; +// fn table_info() -> TableInfo { +// TableInfo { name: "Logs" } +// } +// } +// +// pub struct BlockRefTable; +// impl Table for BlockRefTable { +// type Key = (u64, u64); // (chain_id, block_number) +// type Value = BlockRef; +// fn table_info() -> TableInfo { +// TableInfo { name: "BlockRef" } +// } +// } diff --git a/crates/supervisor/core/src/state/mod.rs b/crates/supervisor/core/src/state/mod.rs index 695a56c9a5..205ab47ad5 100644 --- a/crates/supervisor/core/src/state/mod.rs +++ b/crates/supervisor/core/src/state/mod.rs @@ -1,2 +1,4 @@ //! This module is responsible for managing and persisting the state of the supervisor. // TODO: Implement state management logic for the supervisor. + +mod log; \ No newline at end of file diff --git a/crates/supervisor/core/src/types/log.rs b/crates/supervisor/core/src/types/log.rs new file mode 100644 index 0000000000..f1ccb7eb8d --- /dev/null +++ b/crates/supervisor/core/src/types/log.rs @@ -0,0 +1,16 @@ +/// A reference entry representing a log observed in an L2 receipt. +/// +/// This struct does **not** store the actual log content. Instead: +/// - `hash` is the hash of the log (as computed by [`log_to_log_hash`]), +/// which uniquely identifies the log entry and can be used for lookups or comparisons. +/// - `executing_message` is present if the log represents an `ExecutingMessage` emitted +/// by the `CrossL2Inbox` contract. +/// +/// This is the unit persisted by the log indexer into the database for later validation. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct LogEntry { + /// The hash of the log, derived from the log address and payload. + pub hash: B256, + /// The parsed message, if the log matches an `ExecutingMessage` event. + pub executing_message: Option, +} diff --git a/crates/supervisor/core/src/types/message.rs b/crates/supervisor/core/src/types/message.rs new file mode 100644 index 0000000000..81fd02a894 --- /dev/null +++ b/crates/supervisor/core/src/types/message.rs @@ -0,0 +1,18 @@ +use alloy_primitives::B256; + +/// A parsed executing message extracted from a log emitted by the +/// `CrossL2Inbox` contract on an L2 chain. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ExecutingMessage { + /// The chain ID where the message was observed. + pub chain_id: u64, + /// The block number that contained the log. + pub block_number: u64, + /// The log index within the block. + pub log_index: u16, + /// The timestamp of the block. + pub timestamp: u64, + /// A unique hash identifying the log (based on payload + origin). + pub hash: B256, +} + From f4a1fd6a0c2744c016f9957d9379fc2693922c70 Mon Sep 17 00:00:00 2001 From: sadiq1971 Date: Thu, 15 May 2025 03:07:59 +0600 Subject: [PATCH 02/22] added storage crate for supervisor --- crates/supervisor/core/Cargo.toml | 1 - crates/supervisor/core/src/state/log/mod.rs | 1 - crates/supervisor/core/src/state/log/table.rs | 89 ---------- crates/supervisor/core/src/state/mod.rs | 2 - crates/supervisor/core/src/types/log.rs | 16 -- crates/supervisor/core/src/types/message.rs | 18 -- crates/supervisor/storage/Cargo.toml | 49 ++++++ crates/supervisor/storage/src/lib.rs | 2 + crates/supervisor/storage/src/log/mod.rs | 5 + .../supervisor/storage/src/log/models/log.rs | 104 +++++++++++ .../supervisor/storage/src/log/models/mod.rs | 2 + crates/supervisor/storage/src/log/storage.rs | 161 ++++++++++++++++++ crates/supervisor/storage/src/log/table.rs | 14 ++ 13 files changed, 337 insertions(+), 127 deletions(-) delete mode 100644 crates/supervisor/core/src/state/log/mod.rs delete mode 100644 crates/supervisor/core/src/state/log/table.rs delete mode 100644 crates/supervisor/core/src/types/log.rs delete mode 100644 crates/supervisor/core/src/types/message.rs create mode 100644 crates/supervisor/storage/Cargo.toml create mode 100644 crates/supervisor/storage/src/lib.rs create mode 100644 crates/supervisor/storage/src/log/mod.rs create mode 100644 crates/supervisor/storage/src/log/models/log.rs create mode 100644 crates/supervisor/storage/src/log/models/mod.rs create mode 100644 crates/supervisor/storage/src/log/storage.rs create mode 100644 crates/supervisor/storage/src/log/table.rs diff --git a/crates/supervisor/core/Cargo.toml b/crates/supervisor/core/Cargo.toml index cbf886b38b..85bee122c3 100644 --- a/crates/supervisor/core/Cargo.toml +++ b/crates/supervisor/core/Cargo.toml @@ -27,7 +27,6 @@ jsonrpsee = { workspace = true, features = [ "server" ] } async-trait.workspace = true tracing = { workspace = true } thiserror.workspace = true -reth-db-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } diff --git a/crates/supervisor/core/src/state/log/mod.rs b/crates/supervisor/core/src/state/log/mod.rs deleted file mode 100644 index 1a1404c9ad..0000000000 --- a/crates/supervisor/core/src/state/log/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod table; \ No newline at end of file diff --git a/crates/supervisor/core/src/state/log/table.rs b/crates/supervisor/core/src/state/log/table.rs deleted file mode 100644 index ed0cd24f6b..0000000000 --- a/crates/supervisor/core/src/state/log/table.rs +++ /dev/null @@ -1,89 +0,0 @@ -use alloy_primitives::B256; -use alloy_rlp:: {RlpDecodable, RlpEncodable}; -use serde::{Deserialize, Serialize}; -use std::convert::TryInto; -use reth_db_api::DatabaseError; -use reth_db_api::{Tables}; -use reth_db_api::table::{Encode, Decode}; -use kona_interop::ExecutingMessage; - - -#[derive(Ord, PartialOrd, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] -pub struct LogKey { - pub chain_id: u64, - pub block_number: u64, - pub log_index: u32, -} - -impl Encode for LogKey { - type Encoded = [u8; 20]; - - fn encode(self) -> Self::Encoded { - let mut buf = [0u8; 20]; - buf[..8].copy_from_slice(&self.chain_id.to_be_bytes()); - buf[8..16].copy_from_slice(&self.block_number.to_be_bytes()); - buf[16..20].copy_from_slice(&self.log_index.to_be_bytes()); - buf - } -} - -impl Decode for LogKey { - fn decode(value: &[u8]) -> Result { - if value.len() != 20 { - return Err(DatabaseError::Decode); - } - - let chain_id = u64::from_be_bytes(value[0..8].try_into().unwrap()); - let block_number = u64::from_be_bytes(value[8..16].try_into().unwrap()); - let log_index = u32::from_be_bytes(value[16..20].try_into().unwrap()); - - Ok(LogKey { - chain_id, - block_number, - log_index, - }) - } -} - -#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] -#[rlp(trailing)] -pub struct LogValue { - pub hash: B256, - pub executing_message: Option, -} - -#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] -pub struct ExecutingMessageValue { - hash: B256, - timestamp: u64, -} - -// #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] -// pub struct BlockRef { -// pub hash: B256, -// pub number: u64, -// pub parent_hash: B256, -// pub time: u64, -// } -// -// -// use reth_db::table::{Table, TableInfo}; -// use serde::{Deserialize, Serialize}; -// -// pub struct LogsTable; -// impl Table for LogsTable { -// type Key = LogKey; -// type Value = LogValue; -// fn table_info() -> TableInfo { -// TableInfo { name: "Logs" } -// } -// } -// -// pub struct BlockRefTable; -// impl Table for BlockRefTable { -// type Key = (u64, u64); // (chain_id, block_number) -// type Value = BlockRef; -// fn table_info() -> TableInfo { -// TableInfo { name: "BlockRef" } -// } -// } diff --git a/crates/supervisor/core/src/state/mod.rs b/crates/supervisor/core/src/state/mod.rs index 205ab47ad5..695a56c9a5 100644 --- a/crates/supervisor/core/src/state/mod.rs +++ b/crates/supervisor/core/src/state/mod.rs @@ -1,4 +1,2 @@ //! This module is responsible for managing and persisting the state of the supervisor. // TODO: Implement state management logic for the supervisor. - -mod log; \ No newline at end of file diff --git a/crates/supervisor/core/src/types/log.rs b/crates/supervisor/core/src/types/log.rs deleted file mode 100644 index f1ccb7eb8d..0000000000 --- a/crates/supervisor/core/src/types/log.rs +++ /dev/null @@ -1,16 +0,0 @@ -/// A reference entry representing a log observed in an L2 receipt. -/// -/// This struct does **not** store the actual log content. Instead: -/// - `hash` is the hash of the log (as computed by [`log_to_log_hash`]), -/// which uniquely identifies the log entry and can be used for lookups or comparisons. -/// - `executing_message` is present if the log represents an `ExecutingMessage` emitted -/// by the `CrossL2Inbox` contract. -/// -/// This is the unit persisted by the log indexer into the database for later validation. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct LogEntry { - /// The hash of the log, derived from the log address and payload. - pub hash: B256, - /// The parsed message, if the log matches an `ExecutingMessage` event. - pub executing_message: Option, -} diff --git a/crates/supervisor/core/src/types/message.rs b/crates/supervisor/core/src/types/message.rs deleted file mode 100644 index 81fd02a894..0000000000 --- a/crates/supervisor/core/src/types/message.rs +++ /dev/null @@ -1,18 +0,0 @@ -use alloy_primitives::B256; - -/// A parsed executing message extracted from a log emitted by the -/// `CrossL2Inbox` contract on an L2 chain. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct ExecutingMessage { - /// The chain ID where the message was observed. - pub chain_id: u64, - /// The block number that contained the log. - pub block_number: u64, - /// The log index within the block. - pub log_index: u16, - /// The timestamp of the block. - pub timestamp: u64, - /// A unique hash identifying the log (based on payload + origin). - pub hash: B256, -} - diff --git a/crates/supervisor/storage/Cargo.toml b/crates/supervisor/storage/Cargo.toml new file mode 100644 index 0000000000..c1793f03e5 --- /dev/null +++ b/crates/supervisor/storage/Cargo.toml @@ -0,0 +1,49 @@ +[package] +name = "kona-supervisor-storage" +version = "0.1.0" + +edition.workspace = true +license.workspace = true +rust-version.workspace = true +authors.workspace = true +homepage.workspace = true +repository.workspace = true +keywords.workspace = true +categories.workspace = true +exclude.workspace = true + +[dependencies] +# Workspace +kona-interop.workspace = true +kona-supervisor-rpc = { workspace = true, features = ["jsonrpsee"] } + +# Alloy +alloy-eips.workspace = true +alloy-primitives = { workspace = true, features = ["map", "rlp", "serde"] } +alloy-rlp = { workspace = true, features = ["arrayvec"] } + +# Misc +jsonrpsee = { workspace = true, features = [ "server" ] } +async-trait.workspace = true +tracing = { workspace = true } +thiserror.workspace = true +eyre = "0.6" + +#reth +reth-db-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } +reth-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } +reth-codecs = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } + + + +# `metrics` feature +metrics = { workspace = true } +serde = { version = "1.0.219", features = ["derive"] } + +bincode = "1.3.3" +tempfile = "3.20.0" +rand = "0.9.1" + +[lints] +workspace = true + diff --git a/crates/supervisor/storage/src/lib.rs b/crates/supervisor/storage/src/lib.rs new file mode 100644 index 0000000000..24117ad83e --- /dev/null +++ b/crates/supervisor/storage/src/lib.rs @@ -0,0 +1,2 @@ +mod log; +pub use log::LogStorage; \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/mod.rs b/crates/supervisor/storage/src/log/mod.rs new file mode 100644 index 0000000000..bda464f8f3 --- /dev/null +++ b/crates/supervisor/storage/src/log/mod.rs @@ -0,0 +1,5 @@ +mod storage; +mod models; +mod table; + +pub use storage::*; \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/models/log.rs b/crates/supervisor/storage/src/log/models/log.rs new file mode 100644 index 0000000000..0671128ba7 --- /dev/null +++ b/crates/supervisor/storage/src/log/models/log.rs @@ -0,0 +1,104 @@ +use alloy_primitives::B256; +use serde::{Deserialize, Serialize}; +use std::convert::TryInto; +use alloy_rlp::{bytes}; +use reth_db_api::{DatabaseError}; +use reth_db_api::table::{Encode, Decode, Compress, Decompress, TableInfo}; +use reth_db::table::{Table}; +use bytes::BufMut; +use reth_codecs::Compact; + +#[derive(Ord, PartialOrd, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] +pub struct LogKey { + pub chain_id: u64, + pub block_number: u64, + pub log_index: u32, +} + +impl Encode for LogKey { + type Encoded = [u8; 20]; + + fn encode(self) -> Self::Encoded { + let mut buf = [0u8; 20]; + buf[..8].copy_from_slice(&self.chain_id.to_be_bytes()); + buf[8..16].copy_from_slice(&self.block_number.to_be_bytes()); + buf[16..20].copy_from_slice(&self.log_index.to_be_bytes()); + buf + } +} + +impl Decode for LogKey { + fn decode(value: &[u8]) -> Result { + if value.len() != 20 { + return Err(DatabaseError::Decode); + } + + let chain_id = u64::from_be_bytes(value[0..8].try_into().unwrap()); + let block_number = u64::from_be_bytes(value[8..16].try_into().unwrap()); + let log_index = u32::from_be_bytes(value[16..20].try_into().unwrap()); + + Ok(LogKey { + chain_id, + block_number, + log_index, + }) + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] +pub struct LogValue { + pub hash: B256, + pub executing_message_hash: B256, + pub timestamp: u64, +} + +// TODO: check if we can use derive +impl Compress for LogValue { + type Compressed = Vec; + + fn compress_to_buf>(&self, buf: &mut B) { + let _ = Compact::to_compact(self, buf); + } +} + +// TODO: check if we can use derive +impl Decompress for LogValue { + fn decompress(value: &[u8]) -> Result { + let (obj, _) = Compact::from_compact(value, value.len()); + Ok(obj) + } +} + +// TODO: use derive +impl Compact for LogValue { + fn to_compact>(&self, out: &mut B) -> usize { + let encoded = bincode::serialize(self).expect("bincode never fails"); + out.put_slice(&encoded); + encoded.len() + } + + fn from_compact(bytes: &[u8], _len: usize) -> (Self, &[u8]) { + let value: Self = bincode::deserialize(bytes).expect("bincode deserialize failed"); + (value, &[]) + } +} + + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] +pub struct LogEntries; +impl Table for LogEntries { + const NAME: &'static str = "log_entries"; + const DUPSORT: bool = false; + + type Key = LogKey; + type Value = LogValue; +} + +impl TableInfo for LogEntries { + fn name(&self) -> &'static str { + LogEntries::NAME + } + fn is_dupsort(&self) -> bool { + LogEntries::DUPSORT + } +} \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/models/mod.rs b/crates/supervisor/storage/src/log/models/mod.rs new file mode 100644 index 0000000000..469c58435c --- /dev/null +++ b/crates/supervisor/storage/src/log/models/mod.rs @@ -0,0 +1,2 @@ +mod log; +pub use log::*; \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/storage.rs b/crates/supervisor/storage/src/log/storage.rs new file mode 100644 index 0000000000..aae26abd82 --- /dev/null +++ b/crates/supervisor/storage/src/log/storage.rs @@ -0,0 +1,161 @@ +use std::path::Path; +use reth_db::{DatabaseError}; +use reth_db::database::{Database}; +use reth_db::transaction::{DbTx, DbTxMut}; +use reth_db::cursor::{DbCursorRO, DbCursorRW}; +use reth_db::mdbx::{init_db_for, DatabaseArguments, DatabaseEnv}; +use crate::log::models::{LogEntries, LogKey, LogValue}; +use crate::log::table::LogStorageTables; + +/// Minimal LogStorage with open/insert/get capabilities. +pub struct LogStorage { + db: DatabaseEnv, +} + +impl LogStorage { + /// Open or create the database at the given path. + pub fn init>(path: P, args: DatabaseArguments) -> eyre::Result { + let db = init_db_for::<_,LogStorageTables>(path, args)?; + Ok(Self { db }) + } + + /// Insert a log entry. + pub fn insert_log(&self, key: LogKey, value: LogValue) -> Result { + let mut tx = self.db.tx_mut()?; + tx.put::(key, value)?; + tx.commit() + } + + /// Retrieve a log entry by key. + pub fn get_log(&self, key: LogKey) -> Result, DatabaseError> { + let tx = self.db.tx()?; + tx.get::(key) + } + /// Insert multiple logs for a single block in a single transaction. + pub fn insert_logs( + &self, + chain_id: u64, + block_number: u64, + logs: impl IntoIterator + ) -> Result { + let mut tx = self.db.tx_mut()?; + + for (log_index, log_value) in logs { + let key = LogKey { + chain_id, + block_number, + log_index, + }; + tx.put::(key, log_value)?; + } + + tx.commit() + } + + /// Get all logs in a block (sorted by log_index). + pub fn get_logs_in_block( + &self, + chain_id: u64, + block_number: u64, + ) -> Result, reth_db_api::DatabaseError> { + let tx = self.db.tx()?; + + let start_key = LogKey { + chain_id, + block_number, + log_index: 0, + }; + let end_key = LogKey { + chain_id, + block_number, + log_index: u32::MAX, + }; + + let mut cursor = tx.cursor_read::()?; + let mut walker = cursor.walk_range(start_key..=end_key)?; + + let mut logs = Vec::new(); + for row in walker { + let (_, value) = row?; + logs.push(value); + } + + Ok(logs) + } +} + + +#[cfg(test)] +mod tests { + use super::*; + use tempfile::tempdir; + use alloy_primitives::{hex, B256}; + use rand::Rng; + + fn random_b256() -> B256 { + let mut bytes = [0u8; 32]; + rand::rng().fill(&mut bytes); + B256::from(bytes) + } + + #[test] + fn test_insert_and_get_log() { + let tmp_dir = tempdir().expect("failed to create temp dir"); + let db_args = DatabaseArguments::default(); + let storage = LogStorage::init(tmp_dir.path(), db_args).expect("db init failed"); + + let key = LogKey { + chain_id: 1, + block_number: 100000000, + log_index: 0, + }; + + let value = LogValue { + hash: B256::from([0xAB; 32]), + executing_message_hash: B256::from([0xAB; 32]), + timestamp: 1000000000, + }; + + storage.insert_log(key.clone(), value.clone()).expect("insert failed"); + + let loaded = storage.get_log(key.clone()).expect("get failed"); + + assert_eq!(loaded, Some(value)); + } + + #[test] + fn test_insert_and_get_logs_multiple_chains_blocks() { + let tmp_dir = tempdir().expect("failed to create temp dir"); + let db_args = DatabaseArguments::default(); + let storage = LogStorage::init(tmp_dir.path(), db_args).expect("db init failed"); + + let test_data = vec![ + (1, 100), // chain 1, block 100 + (1, 101), // chain 1, block 101 + (2, 200), // chain 2, block 200 + ]; + + let mut expected_map = std::collections::HashMap::new(); + + for (chain_id, block_number) in &test_data { + let logs: Vec<(u32, LogValue)> = (0..3).map(|i| { + (i, LogValue { + hash: random_b256(), + executing_message_hash: random_b256(), + timestamp: 10000000 + i as u64, + }) + }).collect(); + + storage.insert_logs(*chain_id, *block_number, logs.clone()).expect("batch insert failed"); + expected_map.insert((*chain_id, *block_number), logs); + } + + // Validate each set of inserted logs + for (chain_id, block_number) in &test_data { + let fetched_logs = storage.get_logs_in_block(*chain_id, *block_number).expect("fetch failed"); + let expected_logs = expected_map.get(&(*chain_id, *block_number)).unwrap(); + let expected_values: Vec = expected_logs.iter().map(|(_, val)| val.clone()).collect(); + assert_eq!(fetched_logs, expected_values, "Mismatch for chain {chain_id}, block {block_number}"); + } + } +} \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/table.rs b/crates/supervisor/storage/src/log/table.rs new file mode 100644 index 0000000000..9fe41d20bb --- /dev/null +++ b/crates/supervisor/storage/src/log/table.rs @@ -0,0 +1,14 @@ +use reth_db_api::table::TableInfo; +use reth_db_api::TableSet; +use crate::log::models::LogEntries; + +#[derive(Debug, Clone, Copy)] +pub struct LogStorageTables; + +impl TableSet for LogStorageTables { + fn tables() -> Box>> { + Box::new(vec![ + Box::new(LogEntries) as Box, + ].into_iter()) + } +} \ No newline at end of file From 4d5028015b16ea86b78c5e0b9bfcc13261cb3df3 Mon Sep 17 00:00:00 2001 From: sadiq1971 Date: Thu, 15 May 2025 03:13:28 +0600 Subject: [PATCH 03/22] removed unused imports --- Cargo.lock | 311 +++++++++++++++++++++++---- crates/supervisor/core/Cargo.toml | 5 - crates/supervisor/core/src/lib.rs | 2 - crates/supervisor/storage/Cargo.toml | 20 +- 4 files changed, 277 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bfdf1b2ac4..53c56c7040 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1557,6 +1557,15 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "230c5f1ca6a325a32553f8640d31ac9b49f2411e901e427570154868b46da4f7" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bindgen" version = "0.69.5" @@ -1577,6 +1586,24 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "bindgen" +version = "0.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" +dependencies = [ + "bitflags 2.9.0", + "cexpr", + "clang-sys", + "itertools 0.10.5", + "proc-macro2", + "quote", + "regex", + "rustc-hash 1.1.0", + "shlex", + "syn 2.0.101", +] + [[package]] name = "bit-set" version = "0.8.0" @@ -1825,9 +1852,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.22" +version = "1.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32db95edf998450acc7881c932f94cd9b05c87b4b2599e8bab064753da4acfd1" +checksum = "c736e259eea577f443d5c86c304f9f4ae0295c43f3ba05c21f1d66b5f06001af" dependencies = [ "jobserver", "libc", @@ -1893,8 +1920,10 @@ checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "wasm-bindgen", "windows-link", ] @@ -3659,7 +3688,7 @@ dependencies = [ "js-sys", "log", "wasm-bindgen", - "windows-core 0.61.0", + "windows-core 0.58.0", ] [[package]] @@ -5153,14 +5182,11 @@ version = "0.1.0" dependencies = [ "alloy-eips 0.15.11", "alloy-primitives", - "alloy-rlp", "async-trait", "jsonrpsee 0.25.1", "kona-interop", "kona-supervisor-rpc", "metrics", - "reth-db-api", - "serde", "thiserror 2.0.12", "tracing", ] @@ -5186,6 +5212,22 @@ dependencies = [ "tracing", ] +[[package]] +name = "kona-supervisor-storage" +version = "0.1.0" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "bincode", + "eyre", + "rand 0.9.1", + "reth-codecs", + "reth-db", + "reth-db-api", + "serde", + "tempfile", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -5607,7 +5649,7 @@ version = "0.17.1+9.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b7869a512ae9982f4d46ba482c2a304f1efd80c6412a3d4bf57bb79a619679f" dependencies = [ - "bindgen", + "bindgen 0.69.5", "bzip2-sys", "cc", "libc", @@ -5757,6 +5799,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" +[[package]] +name = "lz4_flex" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75761162ae2b0e580d7e7c390558127e5f01b4194debd6221fd8c207fc80e3f5" + [[package]] name = "macro-string" version = "0.1.4" @@ -5802,6 +5850,18 @@ dependencies = [ "portable-atomic", ] +[[package]] +name = "metrics-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3dbdd96ed57d565ec744cba02862d707acf373c5772d152abae6ec5c4e24f6c" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn 2.0.101", +] + [[package]] name = "metrics-exporter-prometheus" version = "0.17.0" @@ -6099,6 +6159,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -6504,6 +6573,16 @@ dependencies = [ "sha2 0.10.9", ] +[[package]] +name = "page_size" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "papergrid" version = "0.15.0" @@ -7405,6 +7484,30 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "reth-db" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "alloy-primitives", + "derive_more", + "eyre", + "metrics", + "page_size", + "reth-db-api", + "reth-fs-util", + "reth-libmdbx", + "reth-metrics", + "reth-nippy-jar", + "reth-static-file-types", + "reth-storage-errors", + "reth-tracing", + "rustc-hash 2.1.1", + "strum 0.27.1", + "sysinfo", + "thiserror 2.0.12", +] + [[package]] name = "reth-db-api" version = "1.3.12" @@ -7467,6 +7570,68 @@ dependencies = [ "serde_with", ] +[[package]] +name = "reth-fs-util" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "serde", + "serde_json", + "thiserror 2.0.12", +] + +[[package]] +name = "reth-libmdbx" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "bitflags 2.9.0", + "byteorder", + "dashmap", + "derive_more", + "indexmap 2.9.0", + "parking_lot", + "reth-mdbx-sys", + "smallvec", + "thiserror 2.0.12", + "tracing", +] + +[[package]] +name = "reth-mdbx-sys" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "bindgen 0.70.1", + "cc", +] + +[[package]] +name = "reth-metrics" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "metrics", + "metrics-derive", +] + +[[package]] +name = "reth-nippy-jar" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "anyhow", + "bincode", + "derive_more", + "lz4_flex", + "memmap2", + "reth-fs-util", + "serde", + "thiserror 2.0.12", + "tracing", + "zstd", +] + [[package]] name = "reth-primitives-traits" version = "1.3.12" @@ -7549,6 +7714,21 @@ dependencies = [ "thiserror 2.0.12", ] +[[package]] +name = "reth-tracing" +version = "1.3.12" +source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" +dependencies = [ + "clap", + "eyre", + "rolling-file", + "tracing", + "tracing-appender", + "tracing-journald", + "tracing-logfmt", + "tracing-subscriber 0.3.19", +] + [[package]] name = "reth-trie-common" version = "1.3.12" @@ -8046,6 +8226,15 @@ dependencies = [ "librocksdb-sys", ] +[[package]] +name = "rolling-file" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8395b4f860856b740f20a296ea2cd4d823e81a2658cf05ef61be22916026a906" +dependencies = [ + "chrono", +] + [[package]] name = "route-recognizer" version = "0.3.1" @@ -8991,6 +9180,19 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "sysinfo" +version = "0.33.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fc858248ea01b66f19d8e8a6d55f41deaf91e9d495246fd01368d99935c6c01" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "windows 0.57.0", +] + [[package]] name = "system-configuration" version = "0.6.1" @@ -9439,6 +9641,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "tracing-journald" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0b4143302cf1022dac868d521e36e8b27691f72c84b3311750d5188ebba657" +dependencies = [ + "libc", + "tracing-core", + "tracing-subscriber 0.3.19", +] + [[package]] name = "tracing-log" version = "0.2.0" @@ -9450,6 +9663,28 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-logfmt" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1f47d22deb79c3f59fcf2a1f00f60cbdc05462bf17d1cd356c1fefa3f444bd" +dependencies = [ + "time", + "tracing", + "tracing-core", + "tracing-subscriber 0.3.19", +] + +[[package]] +name = "tracing-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1" +dependencies = [ + "serde", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.2.25" @@ -9470,12 +9705,14 @@ dependencies = [ "once_cell", "regex", "serde", + "serde_json", "sharded-slab", "smallvec", "thread_local", "tracing", "tracing-core", "tracing-log", + "tracing-serde", ] [[package]] @@ -9901,6 +10138,16 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows" version = "0.58.0" @@ -9923,35 +10170,34 @@ dependencies = [ [[package]] name = "windows-core" -version = "0.58.0" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" dependencies = [ - "windows-implement 0.58.0", - "windows-interface 0.58.0", - "windows-result 0.2.0", - "windows-strings 0.1.0", + "windows-implement 0.57.0", + "windows-interface 0.57.0", + "windows-result 0.1.2", "windows-targets 0.52.6", ] [[package]] name = "windows-core" -version = "0.61.0" +version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" dependencies = [ - "windows-implement 0.60.0", - "windows-interface 0.59.1", - "windows-link", - "windows-result 0.3.2", - "windows-strings 0.4.0", + "windows-implement 0.58.0", + "windows-interface 0.58.0", + "windows-result 0.2.0", + "windows-strings 0.1.0", + "windows-targets 0.52.6", ] [[package]] name = "windows-implement" -version = "0.58.0" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" dependencies = [ "proc-macro2", "quote", @@ -9960,9 +10206,9 @@ dependencies = [ [[package]] name = "windows-implement" -version = "0.60.0" +version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" dependencies = [ "proc-macro2", "quote", @@ -9971,9 +10217,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.58.0" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" dependencies = [ "proc-macro2", "quote", @@ -9982,9 +10228,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.59.1" +version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" dependencies = [ "proc-macro2", "quote", @@ -10054,15 +10300,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-strings" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" -dependencies = [ - "windows-link", -] - [[package]] name = "windows-sys" version = "0.45.0" diff --git a/crates/supervisor/core/Cargo.toml b/crates/supervisor/core/Cargo.toml index 85bee122c3..15474f8a6c 100644 --- a/crates/supervisor/core/Cargo.toml +++ b/crates/supervisor/core/Cargo.toml @@ -20,7 +20,6 @@ kona-supervisor-rpc = { workspace = true, features = ["jsonrpsee"] } # Alloy alloy-eips.workspace = true alloy-primitives = { workspace = true, features = ["map", "rlp", "serde"] } -alloy-rlp = { workspace = true, features = ["arrayvec"] } # Misc jsonrpsee = { workspace = true, features = [ "server" ] } @@ -28,12 +27,8 @@ async-trait.workspace = true tracing = { workspace = true } thiserror.workspace = true - - - # `metrics` feature metrics = { workspace = true } -serde = { version = "1.0.219", features = ["derive"] } [lints] workspace = true diff --git a/crates/supervisor/core/src/lib.rs b/crates/supervisor/core/src/lib.rs index f5162e6ebc..d6023d6e39 100644 --- a/crates/supervisor/core/src/lib.rs +++ b/crates/supervisor/core/src/lib.rs @@ -5,6 +5,4 @@ mod supervisor; pub use supervisor::{Supervisor, SupervisorError, SupervisorService}; mod rpc; -mod state; - pub use rpc::SupervisorRpc; diff --git a/crates/supervisor/storage/Cargo.toml b/crates/supervisor/storage/Cargo.toml index c1793f03e5..71121235bf 100644 --- a/crates/supervisor/storage/Cargo.toml +++ b/crates/supervisor/storage/Cargo.toml @@ -13,37 +13,23 @@ categories.workspace = true exclude.workspace = true [dependencies] -# Workspace -kona-interop.workspace = true -kona-supervisor-rpc = { workspace = true, features = ["jsonrpsee"] } - # Alloy -alloy-eips.workspace = true alloy-primitives = { workspace = true, features = ["map", "rlp", "serde"] } alloy-rlp = { workspace = true, features = ["arrayvec"] } # Misc -jsonrpsee = { workspace = true, features = [ "server" ] } -async-trait.workspace = true -tracing = { workspace = true } -thiserror.workspace = true eyre = "0.6" +bincode = "1.3.3" +tempfile = "3.20.0" +rand = "0.9.1" #reth reth-db-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } reth-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } reth-codecs = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } - - -# `metrics` feature -metrics = { workspace = true } serde = { version = "1.0.219", features = ["derive"] } -bincode = "1.3.3" -tempfile = "3.20.0" -rand = "0.9.1" - [lints] workspace = true From ff3a19d633a8c031a87c7ed67cdf4cc059b7a9ab Mon Sep 17 00:00:00 2001 From: sadiq1971 Date: Fri, 16 May 2025 00:16:23 +0600 Subject: [PATCH 04/22] defined schema for log storage --- .gitignore | 3 + Cargo.lock | 149 +++++++++++++++- crates/supervisor/storage/Cargo.toml | 3 + crates/supervisor/storage/src/lib.rs | 24 ++- crates/supervisor/storage/src/log/mod.rs | 5 - .../supervisor/storage/src/log/models/log.rs | 104 ----------- .../supervisor/storage/src/log/models/mod.rs | 2 - crates/supervisor/storage/src/log/storage.rs | 161 ------------------ crates/supervisor/storage/src/log/table.rs | 14 -- crates/supervisor/storage/src/models/block.rs | 55 ++++++ crates/supervisor/storage/src/models/log.rs | 66 +++++++ crates/supervisor/storage/src/models/mod.rs | 115 +++++++++++++ 12 files changed, 409 insertions(+), 292 deletions(-) delete mode 100644 crates/supervisor/storage/src/log/mod.rs delete mode 100644 crates/supervisor/storage/src/log/models/log.rs delete mode 100644 crates/supervisor/storage/src/log/models/mod.rs delete mode 100644 crates/supervisor/storage/src/log/storage.rs delete mode 100644 crates/supervisor/storage/src/log/table.rs create mode 100644 crates/supervisor/storage/src/models/block.rs create mode 100644 crates/supervisor/storage/src/models/log.rs create mode 100644 crates/supervisor/storage/src/models/mod.rs diff --git a/.gitignore b/.gitignore index 640d3a55db..8a7961fd51 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ data/ # Prestate artifacts prestate-artifacts-* + +# IDE specific +.idea diff --git a/Cargo.lock b/Cargo.lock index 53c56c7040..f23c8d9984 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -675,7 +675,7 @@ dependencies = [ "alloy-rlp", "alloy-serde 0.14.0", "alloy-sol-types", - "itertools 0.13.0", + "itertools 0.14.0", "serde", "serde_json", "thiserror 2.0.12", @@ -1566,6 +1566,26 @@ dependencies = [ "serde", ] +[[package]] +name = "bincode" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740" +dependencies = [ + "bincode_derive", + "serde", + "unty", +] + +[[package]] +name = "bincode_derive" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09" +dependencies = [ + "virtue", +] + [[package]] name = "bindgen" version = "0.69.5" @@ -1595,7 +1615,7 @@ dependencies = [ "bitflags 2.9.0", "cexpr", "clang-sys", - "itertools 0.10.5", + "itertools 0.13.0", "proc-macro2", "quote", "regex", @@ -1829,6 +1849,38 @@ dependencies = [ "serde", ] +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba" +dependencies = [ + "camino", + "cargo-platform", + "semver 1.0.26", + "serde", + "serde_json", + "thiserror 2.0.12", +] + [[package]] name = "cassowary" version = "0.3.0" @@ -5218,14 +5270,17 @@ version = "0.1.0" dependencies = [ "alloy-primitives", "alloy-rlp", - "bincode", + "bincode 1.3.3", + "bytes", "eyre", + "modular-bitfield", "rand 0.9.1", "reth-codecs", "reth-db", "reth-db-api", "serde", "tempfile", + "test-fuzz", ] [[package]] @@ -6905,6 +6960,16 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "prettyplease" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "664ec5419c51e34154eec046ebcba56312d5a2fc3b09a06da188e1ad21afadf6" +dependencies = [ + "proc-macro2", + "syn 2.0.101", +] + [[package]] name = "primeorder" version = "0.13.6" @@ -7621,7 +7686,7 @@ version = "1.3.12" source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" dependencies = [ "anyhow", - "bincode", + "bincode 1.3.3", "derive_more", "lz4_flex", "memmap2", @@ -8666,6 +8731,9 @@ name = "semver" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +dependencies = [ + "serde", +] [[package]] name = "semver-parser" @@ -8697,6 +8765,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_combinators" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de5fb30ae2918667d3cee99ef4b112f1f7ca0a6c58fa349d7d9e76035c72f8b" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.219" @@ -9263,6 +9340,58 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "test-fuzz" +version = "7.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae2f06b1ae65cbf4dc1f4975279cee7dbf70fcca269bdbdd8aabd20a79e6785c" +dependencies = [ + "serde", + "serde_combinators", + "test-fuzz-internal", + "test-fuzz-macro", + "test-fuzz-runtime", +] + +[[package]] +name = "test-fuzz-internal" +version = "7.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac6a1dc2074c20c6410ac75687be17808a22abfd449e28301a95d72974b91768" +dependencies = [ + "bincode 2.0.1", + "cargo_metadata", + "serde", +] + +[[package]] +name = "test-fuzz-macro" +version = "7.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190423aabaca6cec8392cf45e471777e036d424a14d979db8033f25cc417f1ad" +dependencies = [ + "darling", + "heck", + "itertools 0.14.0", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "test-fuzz-runtime" +version = "7.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05723662ca81651b49dd87b50cae65a0a38523aa1c0cb6b049a8c4f5c2c7836" +dependencies = [ + "hex", + "num-traits", + "serde", + "sha1", + "test-fuzz-internal", +] + [[package]] name = "testing_table" version = "0.3.0" @@ -9851,6 +9980,12 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "unty" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" + [[package]] name = "url" version = "2.5.4" @@ -9907,6 +10042,12 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "virtue" +version = "0.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1" + [[package]] name = "wait-timeout" version = "0.2.1" diff --git a/crates/supervisor/storage/Cargo.toml b/crates/supervisor/storage/Cargo.toml index 71121235bf..133a10ff1d 100644 --- a/crates/supervisor/storage/Cargo.toml +++ b/crates/supervisor/storage/Cargo.toml @@ -29,6 +29,9 @@ reth-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } reth-codecs = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } serde = { version = "1.0.219", features = ["derive"] } +bytes = "1.10.1" +modular-bitfield = "0.11.2" +test-fuzz = "7.2.0" [lints] workspace = true diff --git a/crates/supervisor/storage/src/lib.rs b/crates/supervisor/storage/src/lib.rs index 24117ad83e..2395a7e38b 100644 --- a/crates/supervisor/storage/src/lib.rs +++ b/crates/supervisor/storage/src/lib.rs @@ -1,2 +1,22 @@ -mod log; -pub use log::LogStorage; \ No newline at end of file +//! Persistent storage for the Supervisor. +//! +//! This crate provides structured, append-only storage for the Supervisor, +//! exposing high-level APIs to write and query logs, block metadata, and +//! other execution states. +//! +//! The storage system is built on top of [`reth-db`], using MDBX, +//! and defines schemas for supervisor-specific data like: +//! - L2 log entries +//! - Block ancestry metadata +//! - Source and Derived Blocks +//! - Chain heads for safety levels: **SAFE**, **UNSAFE**, and **CROSS-SAFE** +//! +//! +//! ## Capabilities +//! +//! - Append logs emitted by L2 execution +//! - Look up logs by block number and index +//! - Rewind logs during reorgs +//! - Track sealed blocks and ancestry metadata + +pub mod models; \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/mod.rs b/crates/supervisor/storage/src/log/mod.rs deleted file mode 100644 index bda464f8f3..0000000000 --- a/crates/supervisor/storage/src/log/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod storage; -mod models; -mod table; - -pub use storage::*; \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/models/log.rs b/crates/supervisor/storage/src/log/models/log.rs deleted file mode 100644 index 0671128ba7..0000000000 --- a/crates/supervisor/storage/src/log/models/log.rs +++ /dev/null @@ -1,104 +0,0 @@ -use alloy_primitives::B256; -use serde::{Deserialize, Serialize}; -use std::convert::TryInto; -use alloy_rlp::{bytes}; -use reth_db_api::{DatabaseError}; -use reth_db_api::table::{Encode, Decode, Compress, Decompress, TableInfo}; -use reth_db::table::{Table}; -use bytes::BufMut; -use reth_codecs::Compact; - -#[derive(Ord, PartialOrd, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] -pub struct LogKey { - pub chain_id: u64, - pub block_number: u64, - pub log_index: u32, -} - -impl Encode for LogKey { - type Encoded = [u8; 20]; - - fn encode(self) -> Self::Encoded { - let mut buf = [0u8; 20]; - buf[..8].copy_from_slice(&self.chain_id.to_be_bytes()); - buf[8..16].copy_from_slice(&self.block_number.to_be_bytes()); - buf[16..20].copy_from_slice(&self.log_index.to_be_bytes()); - buf - } -} - -impl Decode for LogKey { - fn decode(value: &[u8]) -> Result { - if value.len() != 20 { - return Err(DatabaseError::Decode); - } - - let chain_id = u64::from_be_bytes(value[0..8].try_into().unwrap()); - let block_number = u64::from_be_bytes(value[8..16].try_into().unwrap()); - let log_index = u32::from_be_bytes(value[16..20].try_into().unwrap()); - - Ok(LogKey { - chain_id, - block_number, - log_index, - }) - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] -pub struct LogValue { - pub hash: B256, - pub executing_message_hash: B256, - pub timestamp: u64, -} - -// TODO: check if we can use derive -impl Compress for LogValue { - type Compressed = Vec; - - fn compress_to_buf>(&self, buf: &mut B) { - let _ = Compact::to_compact(self, buf); - } -} - -// TODO: check if we can use derive -impl Decompress for LogValue { - fn decompress(value: &[u8]) -> Result { - let (obj, _) = Compact::from_compact(value, value.len()); - Ok(obj) - } -} - -// TODO: use derive -impl Compact for LogValue { - fn to_compact>(&self, out: &mut B) -> usize { - let encoded = bincode::serialize(self).expect("bincode never fails"); - out.put_slice(&encoded); - encoded.len() - } - - fn from_compact(bytes: &[u8], _len: usize) -> (Self, &[u8]) { - let value: Self = bincode::deserialize(bytes).expect("bincode deserialize failed"); - (value, &[]) - } -} - - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] -pub struct LogEntries; -impl Table for LogEntries { - const NAME: &'static str = "log_entries"; - const DUPSORT: bool = false; - - type Key = LogKey; - type Value = LogValue; -} - -impl TableInfo for LogEntries { - fn name(&self) -> &'static str { - LogEntries::NAME - } - fn is_dupsort(&self) -> bool { - LogEntries::DUPSORT - } -} \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/models/mod.rs b/crates/supervisor/storage/src/log/models/mod.rs deleted file mode 100644 index 469c58435c..0000000000 --- a/crates/supervisor/storage/src/log/models/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod log; -pub use log::*; \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/storage.rs b/crates/supervisor/storage/src/log/storage.rs deleted file mode 100644 index aae26abd82..0000000000 --- a/crates/supervisor/storage/src/log/storage.rs +++ /dev/null @@ -1,161 +0,0 @@ -use std::path::Path; -use reth_db::{DatabaseError}; -use reth_db::database::{Database}; -use reth_db::transaction::{DbTx, DbTxMut}; -use reth_db::cursor::{DbCursorRO, DbCursorRW}; -use reth_db::mdbx::{init_db_for, DatabaseArguments, DatabaseEnv}; -use crate::log::models::{LogEntries, LogKey, LogValue}; -use crate::log::table::LogStorageTables; - -/// Minimal LogStorage with open/insert/get capabilities. -pub struct LogStorage { - db: DatabaseEnv, -} - -impl LogStorage { - /// Open or create the database at the given path. - pub fn init>(path: P, args: DatabaseArguments) -> eyre::Result { - let db = init_db_for::<_,LogStorageTables>(path, args)?; - Ok(Self { db }) - } - - /// Insert a log entry. - pub fn insert_log(&self, key: LogKey, value: LogValue) -> Result { - let mut tx = self.db.tx_mut()?; - tx.put::(key, value)?; - tx.commit() - } - - /// Retrieve a log entry by key. - pub fn get_log(&self, key: LogKey) -> Result, DatabaseError> { - let tx = self.db.tx()?; - tx.get::(key) - } - /// Insert multiple logs for a single block in a single transaction. - pub fn insert_logs( - &self, - chain_id: u64, - block_number: u64, - logs: impl IntoIterator - ) -> Result { - let mut tx = self.db.tx_mut()?; - - for (log_index, log_value) in logs { - let key = LogKey { - chain_id, - block_number, - log_index, - }; - tx.put::(key, log_value)?; - } - - tx.commit() - } - - /// Get all logs in a block (sorted by log_index). - pub fn get_logs_in_block( - &self, - chain_id: u64, - block_number: u64, - ) -> Result, reth_db_api::DatabaseError> { - let tx = self.db.tx()?; - - let start_key = LogKey { - chain_id, - block_number, - log_index: 0, - }; - let end_key = LogKey { - chain_id, - block_number, - log_index: u32::MAX, - }; - - let mut cursor = tx.cursor_read::()?; - let mut walker = cursor.walk_range(start_key..=end_key)?; - - let mut logs = Vec::new(); - for row in walker { - let (_, value) = row?; - logs.push(value); - } - - Ok(logs) - } -} - - -#[cfg(test)] -mod tests { - use super::*; - use tempfile::tempdir; - use alloy_primitives::{hex, B256}; - use rand::Rng; - - fn random_b256() -> B256 { - let mut bytes = [0u8; 32]; - rand::rng().fill(&mut bytes); - B256::from(bytes) - } - - #[test] - fn test_insert_and_get_log() { - let tmp_dir = tempdir().expect("failed to create temp dir"); - let db_args = DatabaseArguments::default(); - let storage = LogStorage::init(tmp_dir.path(), db_args).expect("db init failed"); - - let key = LogKey { - chain_id: 1, - block_number: 100000000, - log_index: 0, - }; - - let value = LogValue { - hash: B256::from([0xAB; 32]), - executing_message_hash: B256::from([0xAB; 32]), - timestamp: 1000000000, - }; - - storage.insert_log(key.clone(), value.clone()).expect("insert failed"); - - let loaded = storage.get_log(key.clone()).expect("get failed"); - - assert_eq!(loaded, Some(value)); - } - - #[test] - fn test_insert_and_get_logs_multiple_chains_blocks() { - let tmp_dir = tempdir().expect("failed to create temp dir"); - let db_args = DatabaseArguments::default(); - let storage = LogStorage::init(tmp_dir.path(), db_args).expect("db init failed"); - - let test_data = vec![ - (1, 100), // chain 1, block 100 - (1, 101), // chain 1, block 101 - (2, 200), // chain 2, block 200 - ]; - - let mut expected_map = std::collections::HashMap::new(); - - for (chain_id, block_number) in &test_data { - let logs: Vec<(u32, LogValue)> = (0..3).map(|i| { - (i, LogValue { - hash: random_b256(), - executing_message_hash: random_b256(), - timestamp: 10000000 + i as u64, - }) - }).collect(); - - storage.insert_logs(*chain_id, *block_number, logs.clone()).expect("batch insert failed"); - expected_map.insert((*chain_id, *block_number), logs); - } - - // Validate each set of inserted logs - for (chain_id, block_number) in &test_data { - let fetched_logs = storage.get_logs_in_block(*chain_id, *block_number).expect("fetch failed"); - let expected_logs = expected_map.get(&(*chain_id, *block_number)).unwrap(); - let expected_values: Vec = expected_logs.iter().map(|(_, val)| val.clone()).collect(); - assert_eq!(fetched_logs, expected_values, "Mismatch for chain {chain_id}, block {block_number}"); - } - } -} \ No newline at end of file diff --git a/crates/supervisor/storage/src/log/table.rs b/crates/supervisor/storage/src/log/table.rs deleted file mode 100644 index 9fe41d20bb..0000000000 --- a/crates/supervisor/storage/src/log/table.rs +++ /dev/null @@ -1,14 +0,0 @@ -use reth_db_api::table::TableInfo; -use reth_db_api::TableSet; -use crate::log::models::LogEntries; - -#[derive(Debug, Clone, Copy)] -pub struct LogStorageTables; - -impl TableSet for LogStorageTables { - fn tables() -> Box>> { - Box::new(vec![ - Box::new(LogEntries) as Box, - ].into_iter()) - } -} \ No newline at end of file diff --git a/crates/supervisor/storage/src/models/block.rs b/crates/supervisor/storage/src/models/block.rs new file mode 100644 index 0000000000..2b1b5f001e --- /dev/null +++ b/crates/supervisor/storage/src/models/block.rs @@ -0,0 +1,55 @@ +//! Models for storing block metadata in the database. +//! +//! This module defines the data structure and schema used for tracking +//! individual blocks by block number. The stored metadata includes block hash, +//! parent hash, and block timestamp. +//! +//! Unlike logs, each block is uniquely identified by its number and does not +//! require dup-sorting. + +use alloy_primitives::B256; +use serde::{Deserialize, Serialize}; +use reth_codecs::Compact; +use reth_db::table::Table; + +/// Metadata reference for a single block. +/// +/// This struct captures minimal but essential block header information required +/// to track canonical block lineage and verify ancestry. It is stored as the value +/// in the [`BlockHeaders`] table. +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] +pub struct BlockHeader { + /// The hash of the block itself. + pub hash: B256, + + /// The hash of the parent block (previous block in the chain). + pub parent_hash: B256, + + /// The timestamp of the block (seconds since Unix epoch). + pub time: u64, +} + +/// A table for storing block metadata by block number. +/// +/// This is a standard table (not dup-sorted) where: +/// - **Key**: `u64` — block number +/// - **Value**: [`BlockHeader`] — block metadata +/// +/// This layout allows efficient retrieval of block header info +/// for ancestry checks and parent lookups. +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Hash)] +pub struct BlockHeaders; + +impl Table for BlockHeaders { + /// Table name used internally by the backend database. + const NAME: &'static str = "block_headers"; + + /// Indicates that this is a single-entry table (not dup-sorted). + const DUPSORT: bool = false; + + /// Primary key: block number. + type Key = u64; + + /// Stored value: block metadata. + type Value = BlockHeader; +} diff --git a/crates/supervisor/storage/src/models/log.rs b/crates/supervisor/storage/src/models/log.rs new file mode 100644 index 0000000000..de4994dcfb --- /dev/null +++ b/crates/supervisor/storage/src/models/log.rs @@ -0,0 +1,66 @@ +//! Models for storing blockchain logs in the database. +//! +//! This module defines the data structure and table mapping for logs emitted during +//! transaction execution. Each log is uniquely identified by its block number and +//! index within the block. +//! +//! The table is dup-sorted, allowing efficient grouping of multiple logs per block. +//! It supports fast appends, retrieval, and range queries ordered by log index. + +use alloy_primitives::B256; +use serde::{Deserialize, Serialize}; +use reth_codecs::Compact; +use reth_db_api::table::DupSort; +use reth_db::table::Table; + +/// Metadata associated with a single emitted log. +/// +/// This is the value stored in the `LogEntries` dup-sorted table. Each entry includes: +/// - `hash`: The keccak256 hash of the log event. +/// - `executing_message_hash`: Optional hash representing a message that executes this log +/// (used in cross-chain execution contexts). +/// - `timestamp`: Optional timestamp at when the executing message was created. +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] +pub struct LogEntry { + /// The keccak256 hash of the emitted log event. + pub hash: B256, + /// Optional cross-domain execution message hash. + pub executing_message_hash: Option, + /// Optional timestamp of the log (usually block timestamp). + pub timestamp: Option, +} + +/// A dup-sorted table that stores all logs emitted in a given block, sorted by their index. +/// +/// ## Table Schema: +/// - **Key**: `u64` — Block number. +/// - **SubKey**: `u32` — Log index within the block. +/// - **Value**: [`LogEntry`] — Structured metadata about the log. +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Hash)] +pub struct LogEntries; + +/// Implements the [`Table`] trait for [`LogEntries`] to define its physical storage layout. +/// +/// This declares the primary key type (`u64`) and the value type [`LogEntry`], +/// and marks the table as dup-sorted so it supports multiple values per key. +impl Table for LogEntries { + /// Internal name used in the database backend (e.g., MDBX). + const NAME: &'static str = "log_entries"; + + /// Indicates that this table is dup-sorted (multiple values per primary key). + const DUPSORT: bool = true; + + /// Primary key: block number. + type Key = u64; + + /// Value stored for each log. + type Value = LogEntry; +} + +/// Implements the [`DupSort`] trait for [`LogEntries`] to support ordered sub-keys. +/// +/// This defines the secondary key (`u32`) used to sort logs by index within each block. +impl DupSort for LogEntries { + /// SubKey: log index within the block. + type SubKey = u32; +} \ No newline at end of file diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs new file mode 100644 index 0000000000..2a72ef27b0 --- /dev/null +++ b/crates/supervisor/storage/src/models/mod.rs @@ -0,0 +1,115 @@ +//! Database table schemas used by the Supervisor. +//! +//! This module defines the value types, keys, and table layouts for all data +//! persisted by the `supervisor` component of the node. +//! +//! The tables are registered using [`TableInfo`] and grouped into a [`TableSet`] +//! for database initialization via Reth's storage-api. +//! +//! ## Macros Provided +//! - [`impl_compression_for_compact!`] — Enables compression support for types that derive [`Compact`] +//! - [`impl_table_info!`] — Implements `TableInfo` for one or more tables. +//! - [`impl_table_set!`] — Defines a set of tables that can be initialized together. + +mod log; +pub use log::{LogEntry, LogEntries}; +mod block; +pub use block::{BlockHeader, BlockHeaders}; + +use reth_db::table::Table; +use reth_codecs::Compact; +use reth_db_api::table::{Compress, Decompress}; + +/// Implements [`Compress`] and [`Decompress`] traits for types that implement [`Compact`]. +/// +/// This macro defines how to serialize and deserialize a type into a compressed +/// byte format using Reth's compact codec system. +/// +/// # Example +/// ```ignore +/// impl_compression_for_compact!(BlockHeader, LogEntry); +/// ``` +macro_rules! impl_compression_for_compact { + ($($name:ident$(<$($generic:ident),*>)?),+) => { + $( + impl$(<$($generic: core::fmt::Debug + Send + Sync + Compact),*>)? Compress for $name$(<$($generic),*>)? { + type Compressed = Vec; + + fn compress_to_buf>(&self, buf: &mut B) { + let _ = Compact::to_compact(self, buf); + } + } + + impl$(<$($generic: core::fmt::Debug + Send + Sync + Compact),*>)? Decompress for $name$(<$($generic),*>)? { + fn decompress(value: &[u8]) -> Result<$name$(<$($generic),*>)?, reth_db_api::DatabaseError> { + let (obj, _) = Compact::from_compact(value, value.len()); + Ok(obj) + } + } + )+ + }; +} + +/// Implements [`TableInfo`] for one or more table types that implement [`Table`] or [`DupSort`]. +/// +/// This allows the table to be registered and introspected by the Reth database schema system. +/// +/// # Example +/// ```ignore +/// impl_table_info!(BlockHeaders, LogEntries); +/// ``` +macro_rules! impl_table_info { + ($($table:ty),+ $(,)?) => { + $( + impl reth_db_api::table::TableInfo for $table { + fn name(&self) -> &'static str { + <$table>::NAME + } + + fn is_dupsort(&self) -> bool { + <$table>::DUPSORT + } + } + )+ + }; +} + +/// Declares a struct representing a collection of tables and implements [`TableSet`] for it. +/// +/// The resulting struct can be passed to Reth's `init_db_for::<_, YourTableSet>()` +/// to initialize only the specified tables. +/// +/// # Example +/// ```ignore +/// impl_table_set!(LogStorageTables, BlockHeaders, LogEntries); +/// ``` +#[macro_export] +macro_rules! impl_table_set { + ( + $(#[$outer:meta])* + $set_name:ident, $($table:ty),+ $(,)? + ) => { + #[allow(dead_code)] + $(#[$outer])* + pub(crate) struct $set_name; + + impl reth_db_api::TableSet for $set_name { + fn tables() -> Box>> { + Box::new(vec![ + $( + Box::new(<$table>::default()) as Box + ),* + ].into_iter()) + } + } + }; +} + +// Implement compression logic for all value types stored in tables +impl_compression_for_compact!(BlockHeader, LogEntry); + +// Enable reflection for each table (name + dupsort metadata) +impl_table_info!(BlockHeaders, LogEntries); + +// Define and register the full table set used by log storage +impl_table_set!(LogStorageTables, BlockHeaders, LogEntries); From 15312c7e48f51ee56f4b06b15f09bbddf39aebce Mon Sep 17 00:00:00 2001 From: sadiq1971 Date: Fri, 16 May 2025 00:37:53 +0600 Subject: [PATCH 05/22] added space --- crates/supervisor/storage/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/supervisor/storage/Cargo.toml b/crates/supervisor/storage/Cargo.toml index 29a292f857..a94041e274 100644 --- a/crates/supervisor/storage/Cargo.toml +++ b/crates/supervisor/storage/Cargo.toml @@ -19,7 +19,7 @@ alloy-primitives = { workspace = true, features = ["map", "rlp", "serde"] } # Misc serde = { version = "1.0.219", features = ["derive"] } bytes = "1.10.1" -modular-bitfield = "0.11.2"# lastest is not compatible with reth +modular-bitfield = "0.11.2" # lastest is not compatible with reth test-fuzz = "7.2.0" #reth From 49d13497372f1678000a31ef9de731c08b8300d8 Mon Sep 17 00:00:00 2001 From: sadiq1971 Date: Fri, 16 May 2025 01:25:54 +0600 Subject: [PATCH 06/22] lint fixed --- crates/supervisor/storage/src/lib.rs | 2 +- crates/supervisor/storage/src/models/block.rs | 2 +- crates/supervisor/storage/src/models/log.rs | 10 ++--- crates/supervisor/storage/src/models/mod.rs | 41 +++++++++---------- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/crates/supervisor/storage/src/lib.rs b/crates/supervisor/storage/src/lib.rs index 2395a7e38b..323e38dbaa 100644 --- a/crates/supervisor/storage/src/lib.rs +++ b/crates/supervisor/storage/src/lib.rs @@ -19,4 +19,4 @@ //! - Rewind logs during reorgs //! - Track sealed blocks and ancestry metadata -pub mod models; \ No newline at end of file +pub mod models; diff --git a/crates/supervisor/storage/src/models/block.rs b/crates/supervisor/storage/src/models/block.rs index 2b1b5f001e..37cef8ff2a 100644 --- a/crates/supervisor/storage/src/models/block.rs +++ b/crates/supervisor/storage/src/models/block.rs @@ -8,9 +8,9 @@ //! require dup-sorting. use alloy_primitives::B256; -use serde::{Deserialize, Serialize}; use reth_codecs::Compact; use reth_db::table::Table; +use serde::{Deserialize, Serialize}; /// Metadata reference for a single block. /// diff --git a/crates/supervisor/storage/src/models/log.rs b/crates/supervisor/storage/src/models/log.rs index de4994dcfb..2b0bf2bdf0 100644 --- a/crates/supervisor/storage/src/models/log.rs +++ b/crates/supervisor/storage/src/models/log.rs @@ -8,17 +8,17 @@ //! It supports fast appends, retrieval, and range queries ordered by log index. use alloy_primitives::B256; -use serde::{Deserialize, Serialize}; use reth_codecs::Compact; -use reth_db_api::table::DupSort; use reth_db::table::Table; +use reth_db_api::table::DupSort; +use serde::{Deserialize, Serialize}; /// Metadata associated with a single emitted log. /// /// This is the value stored in the `LogEntries` dup-sorted table. Each entry includes: /// - `hash`: The keccak256 hash of the log event. -/// - `executing_message_hash`: Optional hash representing a message that executes this log -/// (used in cross-chain execution contexts). +/// - `executing_message_hash`: Optional hash representing a message that executes this log (used in +/// cross-chain execution contexts). /// - `timestamp`: Optional timestamp at when the executing message was created. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] pub struct LogEntry { @@ -63,4 +63,4 @@ impl Table for LogEntries { impl DupSort for LogEntries { /// SubKey: log index within the block. type SubKey = u32; -} \ No newline at end of file +} diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index 2a72ef27b0..e86343645d 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -3,24 +3,16 @@ //! This module defines the value types, keys, and table layouts for all data //! persisted by the `supervisor` component of the node. //! -//! The tables are registered using [`TableInfo`] and grouped into a [`TableSet`] -//! for database initialization via Reth's storage-api. -//! -//! ## Macros Provided -//! - [`impl_compression_for_compact!`] — Enables compression support for types that derive [`Compact`] -//! - [`impl_table_info!`] — Implements `TableInfo` for one or more tables. -//! - [`impl_table_set!`] — Defines a set of tables that can be initialized together. +//! The tables are registered using [`reth_db_api::table::TableInfo`] and grouped into a +//! [`reth_db_api::TableSet`] for database initialization via Reth's storage-api. mod log; -pub use log::{LogEntry, LogEntries}; +pub use log::{LogEntries, LogEntry}; mod block; pub use block::{BlockHeader, BlockHeaders}; -use reth_db::table::Table; -use reth_codecs::Compact; -use reth_db_api::table::{Compress, Decompress}; - -/// Implements [`Compress`] and [`Decompress`] traits for types that implement [`Compact`]. +/// Implements [`reth_db_api::table::Compress`] and [`reth_db_api::table::Decompress`] traits for +/// types that implement [`reth_codecs::Compact`]. /// /// This macro defines how to serialize and deserialize a type into a compressed /// byte format using Reth's compact codec system. @@ -32,17 +24,17 @@ use reth_db_api::table::{Compress, Decompress}; macro_rules! impl_compression_for_compact { ($($name:ident$(<$($generic:ident),*>)?),+) => { $( - impl$(<$($generic: core::fmt::Debug + Send + Sync + Compact),*>)? Compress for $name$(<$($generic),*>)? { + impl$(<$($generic: core::fmt::Debug + Send + Sync + Compact),*>)? reth_db_api::table::Compress for $name$(<$($generic),*>)? { type Compressed = Vec; fn compress_to_buf>(&self, buf: &mut B) { - let _ = Compact::to_compact(self, buf); + let _ = reth_codecs::Compact::to_compact(self, buf); } } - impl$(<$($generic: core::fmt::Debug + Send + Sync + Compact),*>)? Decompress for $name$(<$($generic),*>)? { + impl$(<$($generic: core::fmt::Debug + Send + Sync + Compact),*>)? reth_db_api::table::Decompress for $name$(<$($generic),*>)? { fn decompress(value: &[u8]) -> Result<$name$(<$($generic),*>)?, reth_db_api::DatabaseError> { - let (obj, _) = Compact::from_compact(value, value.len()); + let (obj, _) = reth_codecs::Compact::from_compact(value, value.len()); Ok(obj) } } @@ -50,7 +42,8 @@ macro_rules! impl_compression_for_compact { }; } -/// Implements [`TableInfo`] for one or more table types that implement [`Table`] or [`DupSort`]. +/// Implements [`reth_db_api::table::TableInfo`] for one or more table types that implement +/// [`reth_db_api::table::Table`] or [`reth_db_api::table::DupSort`]. /// /// This allows the table to be registered and introspected by the Reth database schema system. /// @@ -61,20 +54,24 @@ macro_rules! impl_compression_for_compact { macro_rules! impl_table_info { ($($table:ty),+ $(,)?) => { $( - impl reth_db_api::table::TableInfo for $table { + impl reth_db_api::table::TableInfo for $table + where + $table: reth_db_api::table::Table, + { fn name(&self) -> &'static str { - <$table>::NAME + <$table as reth_db_api::table::Table>::NAME } fn is_dupsort(&self) -> bool { - <$table>::DUPSORT + <$table as reth_db_api::table::Table>::DUPSORT } } )+ }; } -/// Declares a struct representing a collection of tables and implements [`TableSet`] for it. +/// Declares a struct representing a collection of tables and implements [`reth_db_api::TableSet`] +/// for it. /// /// The resulting struct can be passed to Reth's `init_db_for::<_, YourTableSet>()` /// to initialize only the specified tables. From b2f29adfdd33da6d345870109afc10d561620aad Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Fri, 16 May 2025 17:29:46 +0530 Subject: [PATCH 07/22] refactoring --- Cargo.toml | 8 ++ crates/supervisor/storage/Cargo.toml | 15 ++- crates/supervisor/storage/src/models/block.rs | 26 ----- crates/supervisor/storage/src/models/log.rs | 37 -------- crates/supervisor/storage/src/models/mod.rs | 94 ++++++------------- 5 files changed, 45 insertions(+), 135 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ab89c891df..8f6f9ce2bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -147,6 +147,11 @@ op-revm = { version = "4.0.2", default-features = false } alloy-evm = { version = "0.8.0", default-features = false, features = ["op"] } alloy-op-evm = { version = "0.8.0", default-features = false } +# Reth (pinned to v1.3.12 for kona-supervisor-storage) +reth-db-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } +reth-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } +reth-codecs = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } + # General url = "2.5.4" lru = "0.14.0" @@ -162,11 +167,14 @@ ratatui = "0.29.0" futures = "0.3.31" reqwest = "0.12.15" tempfile = "3.19.1" +bytes = "1.10.1" +test-fuzz = "7.2.0" arbitrary = "1.4.1" multihash = "0.19.3" crossterm = "0.29.0" color-eyre = "0.6.3" jsonrpsee = "0.25.1" +modular-bitfield = "0.11.2" tokio-util = "0.7.15" vergen-git2 = "1.0.0" parking_lot = "0.12.3" diff --git a/crates/supervisor/storage/Cargo.toml b/crates/supervisor/storage/Cargo.toml index a94041e274..e0b3145382 100644 --- a/crates/supervisor/storage/Cargo.toml +++ b/crates/supervisor/storage/Cargo.toml @@ -17,16 +17,15 @@ exclude.workspace = true alloy-primitives = { workspace = true, features = ["map", "rlp", "serde"] } # Misc -serde = { version = "1.0.219", features = ["derive"] } -bytes = "1.10.1" -modular-bitfield = "0.11.2" # lastest is not compatible with reth -test-fuzz = "7.2.0" +serde = { workspace = true, features = ["derive"] } +bytes = { workspace = true } +modular-bitfield = { workspace = true } +test-fuzz = { workspace = true } #reth -reth-db-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } -reth-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } -reth-codecs = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.12" } +reth-db-api = { workspace = true } +reth-db = { workspace = true } +reth-codecs = { workspace = true } [lints] workspace = true - diff --git a/crates/supervisor/storage/src/models/block.rs b/crates/supervisor/storage/src/models/block.rs index 37cef8ff2a..0b783dbb14 100644 --- a/crates/supervisor/storage/src/models/block.rs +++ b/crates/supervisor/storage/src/models/block.rs @@ -9,7 +9,6 @@ use alloy_primitives::B256; use reth_codecs::Compact; -use reth_db::table::Table; use serde::{Deserialize, Serialize}; /// Metadata reference for a single block. @@ -28,28 +27,3 @@ pub struct BlockHeader { /// The timestamp of the block (seconds since Unix epoch). pub time: u64, } - -/// A table for storing block metadata by block number. -/// -/// This is a standard table (not dup-sorted) where: -/// - **Key**: `u64` — block number -/// - **Value**: [`BlockHeader`] — block metadata -/// -/// This layout allows efficient retrieval of block header info -/// for ancestry checks and parent lookups. -#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Hash)] -pub struct BlockHeaders; - -impl Table for BlockHeaders { - /// Table name used internally by the backend database. - const NAME: &'static str = "block_headers"; - - /// Indicates that this is a single-entry table (not dup-sorted). - const DUPSORT: bool = false; - - /// Primary key: block number. - type Key = u64; - - /// Stored value: block metadata. - type Value = BlockHeader; -} diff --git a/crates/supervisor/storage/src/models/log.rs b/crates/supervisor/storage/src/models/log.rs index 2b0bf2bdf0..30ddbfce34 100644 --- a/crates/supervisor/storage/src/models/log.rs +++ b/crates/supervisor/storage/src/models/log.rs @@ -9,8 +9,6 @@ use alloy_primitives::B256; use reth_codecs::Compact; -use reth_db::table::Table; -use reth_db_api::table::DupSort; use serde::{Deserialize, Serialize}; /// Metadata associated with a single emitted log. @@ -29,38 +27,3 @@ pub struct LogEntry { /// Optional timestamp of the log (usually block timestamp). pub timestamp: Option, } - -/// A dup-sorted table that stores all logs emitted in a given block, sorted by their index. -/// -/// ## Table Schema: -/// - **Key**: `u64` — Block number. -/// - **SubKey**: `u32` — Log index within the block. -/// - **Value**: [`LogEntry`] — Structured metadata about the log. -#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Hash)] -pub struct LogEntries; - -/// Implements the [`Table`] trait for [`LogEntries`] to define its physical storage layout. -/// -/// This declares the primary key type (`u64`) and the value type [`LogEntry`], -/// and marks the table as dup-sorted so it supports multiple values per key. -impl Table for LogEntries { - /// Internal name used in the database backend (e.g., MDBX). - const NAME: &'static str = "log_entries"; - - /// Indicates that this table is dup-sorted (multiple values per primary key). - const DUPSORT: bool = true; - - /// Primary key: block number. - type Key = u64; - - /// Value stored for each log. - type Value = LogEntry; -} - -/// Implements the [`DupSort`] trait for [`LogEntries`] to support ordered sub-keys. -/// -/// This defines the secondary key (`u32`) used to sort logs by index within each block. -impl DupSort for LogEntries { - /// SubKey: log index within the block. - type SubKey = u32; -} diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index e86343645d..6cfae8abe4 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -6,10 +6,17 @@ //! The tables are registered using [`reth_db_api::table::TableInfo`] and grouped into a //! [`reth_db_api::TableSet`] for database initialization via Reth's storage-api. +use reth_db_api::{ + TableSet, TableType, TableViewer, + table::{DupSort, TableInfo}, + tables, +}; +use std::fmt; + mod log; -pub use log::{LogEntries, LogEntry}; +pub use log::LogEntry; mod block; -pub use block::{BlockHeader, BlockHeaders}; +pub use block::BlockHeader; /// Implements [`reth_db_api::table::Compress`] and [`reth_db_api::table::Decompress`] traits for /// types that implement [`reth_codecs::Compact`]. @@ -42,71 +49,30 @@ macro_rules! impl_compression_for_compact { }; } -/// Implements [`reth_db_api::table::TableInfo`] for one or more table types that implement -/// [`reth_db_api::table::Table`] or [`reth_db_api::table::DupSort`]. -/// -/// This allows the table to be registered and introspected by the Reth database schema system. -/// -/// # Example -/// ```ignore -/// impl_table_info!(BlockHeaders, LogEntries); -/// ``` -macro_rules! impl_table_info { - ($($table:ty),+ $(,)?) => { - $( - impl reth_db_api::table::TableInfo for $table - where - $table: reth_db_api::table::Table, - { - fn name(&self) -> &'static str { - <$table as reth_db_api::table::Table>::NAME - } - - fn is_dupsort(&self) -> bool { - <$table as reth_db_api::table::Table>::DUPSORT - } - } - )+ - }; -} - -/// Declares a struct representing a collection of tables and implements [`reth_db_api::TableSet`] -/// for it. -/// -/// The resulting struct can be passed to Reth's `init_db_for::<_, YourTableSet>()` -/// to initialize only the specified tables. -/// -/// # Example -/// ```ignore -/// impl_table_set!(LogStorageTables, BlockHeaders, LogEntries); -/// ``` -#[macro_export] -macro_rules! impl_table_set { - ( - $(#[$outer:meta])* - $set_name:ident, $($table:ty),+ $(,)? - ) => { - #[allow(dead_code)] - $(#[$outer])* - pub(crate) struct $set_name; - - impl reth_db_api::TableSet for $set_name { - fn tables() -> Box>> { - Box::new(vec![ - $( - Box::new(<$table>::default()) as Box - ),* - ].into_iter()) - } - } - }; -} - // Implement compression logic for all value types stored in tables impl_compression_for_compact!(BlockHeader, LogEntry); // Enable reflection for each table (name + dupsort metadata) -impl_table_info!(BlockHeaders, LogEntries); +// impl_table_info!(BlockHeaders, LogEntries); // Define and register the full table set used by log storage -impl_table_set!(LogStorageTables, BlockHeaders, LogEntries); +// impl_table_set!(LogStorageTables, BlockHeaders, LogEntries); + +tables! { + /// A dup-sorted table that stores all logs emitted in a given block, sorted by their index. + /// Keyed by block number, with log index as the subkey for DupSort. + table LogEntries { + type Key = u64; // Primary key: u64 (block_number) + type Value = LogEntry; // Value: The log metadata + type SubKey = u32; // SubKey for DupSort: u32 (log_index) + } + + /// A table for storing block metadata by block number. + /// This is a standard table (not dup-sorted) where: + /// - Key: `u64` — block number + /// - Value: [`BlockHeader`] — block metadata + table BlockHeaders { + type Key = u64; + type Value = BlockHeader; + } +} From eb3ef5e725451191c7d250836acc42f9bc646a43 Mon Sep 17 00:00:00 2001 From: sadiq1971 Date: Fri, 16 May 2025 18:21:59 +0600 Subject: [PATCH 08/22] added executing message to log entry --- crates/supervisor/storage/src/models/block.rs | 5 +-- crates/supervisor/storage/src/models/log.rs | 31 ++++++++++++++----- crates/supervisor/storage/src/models/mod.rs | 2 +- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/crates/supervisor/storage/src/models/block.rs b/crates/supervisor/storage/src/models/block.rs index 0b783dbb14..5813c8ad39 100644 --- a/crates/supervisor/storage/src/models/block.rs +++ b/crates/supervisor/storage/src/models/block.rs @@ -14,16 +14,13 @@ use serde::{Deserialize, Serialize}; /// Metadata reference for a single block. /// /// This struct captures minimal but essential block header information required -/// to track canonical block lineage and verify ancestry. It is stored as the value -/// in the [`BlockHeaders`] table. +/// to track canonical block lineage and verify ancestry. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] pub struct BlockHeader { /// The hash of the block itself. pub hash: B256, - /// The hash of the parent block (previous block in the chain). pub parent_hash: B256, - /// The timestamp of the block (seconds since Unix epoch). pub time: u64, } diff --git a/crates/supervisor/storage/src/models/log.rs b/crates/supervisor/storage/src/models/log.rs index 30ddbfce34..09059430c0 100644 --- a/crates/supervisor/storage/src/models/log.rs +++ b/crates/supervisor/storage/src/models/log.rs @@ -15,15 +15,32 @@ use serde::{Deserialize, Serialize}; /// /// This is the value stored in the `LogEntries` dup-sorted table. Each entry includes: /// - `hash`: The keccak256 hash of the log event. -/// - `executing_message_hash`: Optional hash representing a message that executes this log (used in -/// cross-chain execution contexts). -/// - `timestamp`: Optional timestamp at when the executing message was created. +/// - `executing_message` - An optional field that may contain a cross-domain execution message, #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] pub struct LogEntry { /// The keccak256 hash of the emitted log event. pub hash: B256, - /// Optional cross-domain execution message hash. - pub executing_message_hash: Option, - /// Optional timestamp of the log (usually block timestamp). - pub timestamp: Option, + /// Optional cross-domain execution message. + executing_message: Option, +} + +/// Represents an entry of an executing message, containing metadata +/// about the message's origin and context within the blockchain. +/// - `chain_id` (`u64`): The unique identifier of the blockchain where the message originated. +/// - `block_number` (`u64`): The block number in the blockchain where the message originated. +/// - `log_index` (`u64`): The index of the log entry within the block where the message was logged. +/// - `timestamp` (`u64`): The timestamp associated with the block where the message was recorded. +/// - `hash` (`B256`): The unique hash identifier of the message. +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] +pub struct ExecutingMessageEntry { + /// ID of the chain where the message was emitted. + chain_id: u64, + /// Block number in the source chain. + block_number: u64, + /// Log index within the block. + log_index: u64, + /// Timestamp of the block. + timestamp: u64, + /// Hash of the message. + hash: B256, } diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index 6cfae8abe4..8a827577df 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -14,7 +14,7 @@ use reth_db_api::{ use std::fmt; mod log; -pub use log::LogEntry; +pub use log::{ExecutingMessageEntry, LogEntry}; mod block; pub use block::BlockHeader; From 433d36e89a887533e3a7fb8ab0c833c3c406328e Mon Sep 17 00:00:00 2001 From: sadiq1971 Date: Fri, 16 May 2025 18:59:32 +0600 Subject: [PATCH 09/22] doc fixed --- crates/supervisor/storage/src/models/block.rs | 3 ++- crates/supervisor/storage/src/models/log.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/supervisor/storage/src/models/block.rs b/crates/supervisor/storage/src/models/block.rs index 5813c8ad39..1035caef84 100644 --- a/crates/supervisor/storage/src/models/block.rs +++ b/crates/supervisor/storage/src/models/block.rs @@ -14,7 +14,8 @@ use serde::{Deserialize, Serialize}; /// Metadata reference for a single block. /// /// This struct captures minimal but essential block header information required -/// to track canonical block lineage and verify ancestry. +/// to track canonical block lineage and verify ancestry. It is stored as the value +/// in the [`crate::models::BlockHeaders`] table. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] pub struct BlockHeader { /// The hash of the block itself. diff --git a/crates/supervisor/storage/src/models/log.rs b/crates/supervisor/storage/src/models/log.rs index 09059430c0..1582be0924 100644 --- a/crates/supervisor/storage/src/models/log.rs +++ b/crates/supervisor/storage/src/models/log.rs @@ -13,9 +13,10 @@ use serde::{Deserialize, Serialize}; /// Metadata associated with a single emitted log. /// -/// This is the value stored in the `LogEntries` dup-sorted table. Each entry includes: +/// This is the value stored in the [`crate::models::LogEntries`] dup-sorted table. Each entry +/// includes: /// - `hash`: The keccak256 hash of the log event. -/// - `executing_message` - An optional field that may contain a cross-domain execution message, +/// - `executing_message` - An optional field that may contain a cross-domain execution message. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] pub struct LogEntry { /// The keccak256 hash of the emitted log event. From 19afcbb783f477fa94ac7a43e6a6fea67211e962 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Fri, 16 May 2025 19:05:35 +0530 Subject: [PATCH 10/22] minor fixes --- Cargo.lock | 305 +------------------- crates/supervisor/storage/Cargo.toml | 1 - crates/supervisor/storage/src/models/mod.rs | 6 - 3 files changed, 4 insertions(+), 308 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0612fdb58..d25c84e943 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1567,15 +1567,6 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "230c5f1ca6a325a32553f8640d31ac9b49f2411e901e427570154868b46da4f7" -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - [[package]] name = "bincode" version = "2.0.1" @@ -1616,24 +1607,6 @@ dependencies = [ "syn 2.0.101", ] -[[package]] -name = "bindgen" -version = "0.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" -dependencies = [ - "bitflags 2.9.0", - "cexpr", - "clang-sys", - "itertools 0.13.0", - "proc-macro2", - "quote", - "regex", - "rustc-hash 1.1.0", - "shlex", - "syn 2.0.101", -] - [[package]] name = "bit-set" version = "0.8.0" @@ -1967,10 +1940,8 @@ checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "android-tzdata", "iana-time-zone", - "js-sys", "num-traits", "serde", - "wasm-bindgen", "windows-link", ] @@ -2963,16 +2934,6 @@ dependencies = [ "url", ] -[[package]] -name = "eyre" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" -dependencies = [ - "indenter", - "once_cell", -] - [[package]] name = "fastrand" version = "2.3.0" @@ -3885,12 +3846,6 @@ dependencies = [ "syn 2.0.101", ] -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - [[package]] name = "indexmap" version = "1.9.3" @@ -5076,7 +5031,6 @@ dependencies = [ "bytes", "modular-bitfield", "reth-codecs", - "reth-db", "reth-db-api", "serde", "test-fuzz", @@ -5515,7 +5469,7 @@ version = "0.17.1+9.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b7869a512ae9982f4d46ba482c2a304f1efd80c6412a3d4bf57bb79a619679f" dependencies = [ - "bindgen 0.69.5", + "bindgen", "bzip2-sys", "cc", "libc", @@ -5660,12 +5614,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" -[[package]] -name = "lz4_flex" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75761162ae2b0e580d7e7c390558127e5f01b4194debd6221fd8c207fc80e3f5" - [[package]] name = "macro-string" version = "0.1.4" @@ -5711,18 +5659,6 @@ dependencies = [ "portable-atomic", ] -[[package]] -name = "metrics-derive" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3dbdd96ed57d565ec744cba02862d707acf373c5772d152abae6ec5c4e24f6c" -dependencies = [ - "proc-macro2", - "quote", - "regex", - "syn 2.0.101", -] - [[package]] name = "metrics-exporter-prometheus" version = "0.17.0" @@ -6019,15 +5955,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "ntapi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" -dependencies = [ - "winapi", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -6437,16 +6364,6 @@ dependencies = [ "sha2 0.10.9", ] -[[package]] -name = "page_size" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "papergrid" version = "0.15.0" @@ -7337,30 +7254,6 @@ dependencies = [ "syn 2.0.101", ] -[[package]] -name = "reth-db" -version = "1.3.12" -source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" -dependencies = [ - "alloy-primitives", - "derive_more", - "eyre", - "metrics", - "page_size", - "reth-db-api", - "reth-fs-util", - "reth-libmdbx", - "reth-metrics", - "reth-nippy-jar", - "reth-static-file-types", - "reth-storage-errors", - "reth-tracing", - "rustc-hash 2.1.1", - "strum", - "sysinfo", - "thiserror 2.0.12", -] - [[package]] name = "reth-db-api" version = "1.3.12" @@ -7423,68 +7316,6 @@ dependencies = [ "serde_with", ] -[[package]] -name = "reth-fs-util" -version = "1.3.12" -source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" -dependencies = [ - "serde", - "serde_json", - "thiserror 2.0.12", -] - -[[package]] -name = "reth-libmdbx" -version = "1.3.12" -source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" -dependencies = [ - "bitflags 2.9.0", - "byteorder", - "dashmap", - "derive_more", - "indexmap 2.9.0", - "parking_lot", - "reth-mdbx-sys", - "smallvec", - "thiserror 2.0.12", - "tracing", -] - -[[package]] -name = "reth-mdbx-sys" -version = "1.3.12" -source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" -dependencies = [ - "bindgen 0.70.1", - "cc", -] - -[[package]] -name = "reth-metrics" -version = "1.3.12" -source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" -dependencies = [ - "metrics", - "metrics-derive", -] - -[[package]] -name = "reth-nippy-jar" -version = "1.3.12" -source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" -dependencies = [ - "anyhow", - "bincode 1.3.3", - "derive_more", - "lz4_flex", - "memmap2", - "reth-fs-util", - "serde", - "thiserror 2.0.12", - "tracing", - "zstd", -] - [[package]] name = "reth-primitives-traits" version = "1.3.12" @@ -7567,21 +7398,6 @@ dependencies = [ "thiserror 2.0.12", ] -[[package]] -name = "reth-tracing" -version = "1.3.12" -source = "git+https://github.com/paradigmxyz/reth?tag=v1.3.12#6f8e7258f4733279080e4bd8345ce50538a40d6e" -dependencies = [ - "clap", - "eyre", - "rolling-file", - "tracing", - "tracing-appender", - "tracing-journald", - "tracing-logfmt", - "tracing-subscriber 0.3.19", -] - [[package]] name = "reth-trie-common" version = "1.3.12" @@ -8079,15 +7895,6 @@ dependencies = [ "librocksdb-sys", ] -[[package]] -name = "rolling-file" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8395b4f860856b740f20a296ea2cd4d823e81a2658cf05ef61be22916026a906" -dependencies = [ - "chrono", -] - [[package]] name = "route-recognizer" version = "0.3.1" @@ -9002,19 +8809,6 @@ dependencies = [ "syn 2.0.101", ] -[[package]] -name = "sysinfo" -version = "0.33.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc858248ea01b66f19d8e8a6d55f41deaf91e9d495246fd01368d99935c6c01" -dependencies = [ - "core-foundation-sys", - "libc", - "memchr", - "ntapi", - "windows 0.57.0", -] - [[package]] name = "system-configuration" version = "0.6.1" @@ -9104,7 +8898,7 @@ version = "7.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac6a1dc2074c20c6410ac75687be17808a22abfd449e28301a95d72974b91768" dependencies = [ - "bincode 2.0.1", + "bincode", "cargo_metadata", "serde", ] @@ -9447,18 +9241,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "tracing-appender" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" -dependencies = [ - "crossbeam-channel", - "thiserror 1.0.69", - "time", - "tracing-subscriber 0.3.19", -] - [[package]] name = "tracing-attributes" version = "0.1.28" @@ -9492,17 +9274,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tracing-journald" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0b4143302cf1022dac868d521e36e8b27691f72c84b3311750d5188ebba657" -dependencies = [ - "libc", - "tracing-core", - "tracing-subscriber 0.3.19", -] - [[package]] name = "tracing-log" version = "0.2.0" @@ -9514,28 +9285,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "tracing-logfmt" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b1f47d22deb79c3f59fcf2a1f00f60cbdc05462bf17d1cd356c1fefa3f444bd" -dependencies = [ - "time", - "tracing", - "tracing-core", - "tracing-subscriber 0.3.19", -] - -[[package]] -name = "tracing-serde" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1" -dependencies = [ - "serde", - "tracing-core", -] - [[package]] name = "tracing-subscriber" version = "0.2.25" @@ -9556,14 +9305,12 @@ dependencies = [ "once_cell", "regex", "serde", - "serde_json", "sharded-slab", "smallvec", "thread_local", "tracing", "tracing-core", "tracing-log", - "tracing-serde", ] [[package]] @@ -10025,16 +9772,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" -dependencies = [ - "windows-core 0.57.0", - "windows-targets 0.52.6", -] - [[package]] name = "windows" version = "0.61.1" @@ -10067,26 +9804,14 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-core" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" -dependencies = [ - "windows-implement 0.57.0", - "windows-interface 0.57.0", - "windows-result 0.1.2", - "windows-targets 0.52.6", -] - [[package]] name = "windows-core" version = "0.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" dependencies = [ - "windows-implement 0.60.0", - "windows-interface 0.59.1", + "windows-implement", + "windows-interface", "windows-link", "windows-result 0.3.2", "windows-strings 0.4.0", @@ -10102,17 +9827,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-implement" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.101", -] - [[package]] name = "windows-implement" version = "0.60.0" @@ -10124,17 +9838,6 @@ dependencies = [ "syn 2.0.101", ] -[[package]] -name = "windows-interface" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.101", -] - [[package]] name = "windows-interface" version = "0.59.1" diff --git a/crates/supervisor/storage/Cargo.toml b/crates/supervisor/storage/Cargo.toml index e0b3145382..4dd44e24e9 100644 --- a/crates/supervisor/storage/Cargo.toml +++ b/crates/supervisor/storage/Cargo.toml @@ -24,7 +24,6 @@ test-fuzz = { workspace = true } #reth reth-db-api = { workspace = true } -reth-db = { workspace = true } reth-codecs = { workspace = true } [lints] diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index 8a827577df..9ef9b49c55 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -52,12 +52,6 @@ macro_rules! impl_compression_for_compact { // Implement compression logic for all value types stored in tables impl_compression_for_compact!(BlockHeader, LogEntry); -// Enable reflection for each table (name + dupsort metadata) -// impl_table_info!(BlockHeaders, LogEntries); - -// Define and register the full table set used by log storage -// impl_table_set!(LogStorageTables, BlockHeaders, LogEntries); - tables! { /// A dup-sorted table that stores all logs emitted in a given block, sorted by their index. /// Keyed by block number, with log index as the subkey for DupSort. From 2de12ec79e6b15a0521c72562d5041ca205c732c Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Fri, 16 May 2025 21:15:34 +0530 Subject: [PATCH 11/22] test cases added --- crates/supervisor/storage/Cargo.toml | 6 +- crates/supervisor/storage/src/models/log.rs | 12 ++-- crates/supervisor/storage/src/models/mod.rs | 63 +++++++++++++++++++++ 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/crates/supervisor/storage/Cargo.toml b/crates/supervisor/storage/Cargo.toml index 4dd44e24e9..7063aaf20d 100644 --- a/crates/supervisor/storage/Cargo.toml +++ b/crates/supervisor/storage/Cargo.toml @@ -14,17 +14,19 @@ exclude.workspace = true [dependencies] # Alloy -alloy-primitives = { workspace = true, features = ["map", "rlp", "serde"] } +alloy-primitives = { workspace = true, features = ["map", "rlp", "serde", "rand"] } # Misc serde = { workspace = true, features = ["derive"] } bytes = { workspace = true } modular-bitfield = { workspace = true } -test-fuzz = { workspace = true } #reth reth-db-api = { workspace = true } reth-codecs = { workspace = true } +[dev-dependencies] +test-fuzz = { workspace = true } + [lints] workspace = true diff --git a/crates/supervisor/storage/src/models/log.rs b/crates/supervisor/storage/src/models/log.rs index 1582be0924..a1cb5f7f41 100644 --- a/crates/supervisor/storage/src/models/log.rs +++ b/crates/supervisor/storage/src/models/log.rs @@ -22,7 +22,7 @@ pub struct LogEntry { /// The keccak256 hash of the emitted log event. pub hash: B256, /// Optional cross-domain execution message. - executing_message: Option, + pub executing_message: Option, } /// Represents an entry of an executing message, containing metadata @@ -35,13 +35,13 @@ pub struct LogEntry { #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] pub struct ExecutingMessageEntry { /// ID of the chain where the message was emitted. - chain_id: u64, + pub chain_id: u64, /// Block number in the source chain. - block_number: u64, + pub block_number: u64, /// Log index within the block. - log_index: u64, + pub log_index: u64, /// Timestamp of the block. - timestamp: u64, + pub timestamp: u64, /// Hash of the message. - hash: B256, + pub hash: B256, } diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index 9ef9b49c55..2edc87fc66 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -70,3 +70,66 @@ tables! { type Value = BlockHeader; } } + +#[cfg(test)] +mod tests { + use super::*; // Imports BlockHeader, LogEntry, ExecutingMessageEntry, etc. + use alloy_primitives::B256; + use reth_db_api::table::{Compress, Decompress}; + + // Helper to create somewhat unique B256 values for testing. + fn test_b256(val: u8) -> B256 { + let mut val_bytes = [0u8; 32]; + val_bytes[0] = val; // Place the u8 into the first byte of the array + let b256_from_val = B256::from(val_bytes); + B256::random() ^ b256_from_val + } + + #[test] + fn test_block_header_compression_decompression() { + let original = BlockHeader { + hash: test_b256(1), + parent_hash: test_b256(2), + time: 1234567890, + }; + + let mut compressed_buf = Vec::new(); + original.compress_to_buf(&mut compressed_buf); + + // Ensure some data was written + assert!(!compressed_buf.is_empty()); + + let decompressed = BlockHeader::decompress(&compressed_buf).unwrap(); + assert_eq!(original, decompressed); + } + + #[test] + fn test_log_entry_compression_decompression_with_message() { + let original = LogEntry { + hash: test_b256(3), + executing_message: Some(ExecutingMessageEntry { + chain_id: 1, + block_number: 100, + log_index: 2, + timestamp: 12345, + hash: test_b256(4), + }), + }; + + let mut compressed_buf = Vec::new(); + original.compress_to_buf(&mut compressed_buf); + assert!(!compressed_buf.is_empty()); + let decompressed = LogEntry::decompress(&compressed_buf).unwrap(); + assert_eq!(original, decompressed); + } + + #[test] + fn test_log_entry_compression_decompression_without_message() { + let original = LogEntry { hash: test_b256(5), executing_message: None }; + let mut compressed_buf = Vec::new(); + original.compress_to_buf(&mut compressed_buf); + assert!(!compressed_buf.is_empty()); + let decompressed = LogEntry::decompress(&compressed_buf).unwrap(); + assert_eq!(original, decompressed); + } +} From 01cc5f6374e6e62ff481a4185958ad4442f419d1 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Fri, 16 May 2025 21:26:05 +0530 Subject: [PATCH 12/22] lintfix --- crates/supervisor/storage/src/models/mod.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index 2edc87fc66..d017ba4ecf 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -87,11 +87,8 @@ mod tests { #[test] fn test_block_header_compression_decompression() { - let original = BlockHeader { - hash: test_b256(1), - parent_hash: test_b256(2), - time: 1234567890, - }; + let original = + BlockHeader { hash: test_b256(1), parent_hash: test_b256(2), time: 1234567890 }; let mut compressed_buf = Vec::new(); original.compress_to_buf(&mut compressed_buf); From f17f9aa855e5bdbc9d962ad0f89f004a3b5d9ad7 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Mon, 19 May 2025 17:37:07 +0530 Subject: [PATCH 13/22] block schema updated and test cases added --- crates/supervisor/storage/src/models/block.rs | 33 ++++++++++ crates/supervisor/storage/src/models/log.rs | 60 +++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/crates/supervisor/storage/src/models/block.rs b/crates/supervisor/storage/src/models/block.rs index 1035caef84..22d8c086db 100644 --- a/crates/supervisor/storage/src/models/block.rs +++ b/crates/supervisor/storage/src/models/block.rs @@ -18,6 +18,8 @@ use serde::{Deserialize, Serialize}; /// in the [`crate::models::BlockHeaders`] table. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] pub struct BlockHeader { + /// The height of the block. + pub number: u64, /// The hash of the block itself. pub hash: B256, /// The hash of the parent block (previous block in the chain). @@ -25,3 +27,34 @@ pub struct BlockHeader { /// The timestamp of the block (seconds since Unix epoch). pub time: u64, } + +#[cfg(test)] +mod tests { + use super::*; + use alloy_primitives::B256; + + fn test_b256(val: u8) -> B256 { + let mut val_bytes = [0u8; 32]; + val_bytes[0] = val; + let b256_from_val = B256::from(val_bytes); + B256::random() ^ b256_from_val + } + + #[test] + fn test_block_header_compact_roundtrip() { + let original_header = BlockHeader { + number: 42, + hash: test_b256(10), + parent_hash: test_b256(11), + time: 1678886400, + }; + + let mut buffer = Vec::new(); + let bytes_written = original_header.to_compact(&mut buffer); + assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); + + let (deserialized_header, remaining_buf) = BlockHeader::from_compact(&buffer, bytes_written); + assert_eq!(original_header, deserialized_header, "Original and deserialized header should be equal"); + assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); + } +} diff --git a/crates/supervisor/storage/src/models/log.rs b/crates/supervisor/storage/src/models/log.rs index a1cb5f7f41..ad178b68b3 100644 --- a/crates/supervisor/storage/src/models/log.rs +++ b/crates/supervisor/storage/src/models/log.rs @@ -45,3 +45,63 @@ pub struct ExecutingMessageEntry { /// Hash of the message. pub hash: B256, } + +#[cfg(test)] +mod tests { + use super::*; // Imports LogEntry, ExecutingMessageEntry + use alloy_primitives::B256; + use reth_codecs::Compact; // For the Compact trait methods + + // Helper to create somewhat unique B256 values for testing. + // Assumes the "rand" feature for alloy-primitives is enabled for tests. + fn test_b256(val: u8) -> B256 { + let mut val_bytes = [0u8; 32]; + val_bytes[0] = val; + let b256_from_val = B256::from(val_bytes); + B256::random() ^ b256_from_val + } + + #[test] + fn test_log_entry_compact_roundtrip_with_message() { + let original_log_entry = LogEntry { + hash: test_b256(1), + executing_message: Some(ExecutingMessageEntry { + chain_id: 10, + block_number: 1001, + log_index: 5, + timestamp: 1234567890, + hash: test_b256(2), + }), + }; + + let mut buffer = Vec::new(); + let bytes_written = original_log_entry.to_compact(&mut buffer); + + assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); + assert!(!buffer.is_empty(), "Buffer should not be empty after compression"); + + let (deserialized_log_entry, remaining_buf) = LogEntry::from_compact(&buffer, bytes_written); + + assert_eq!(original_log_entry, deserialized_log_entry, "Original and deserialized log entries should be equal"); + assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); + } + + #[test] + fn test_log_entry_compact_roundtrip_without_message() { + let original_log_entry = LogEntry { + hash: test_b256(3), + executing_message: None, + }; + + let mut buffer = Vec::new(); + let bytes_written = original_log_entry.to_compact(&mut buffer); + + assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); + assert!(!buffer.is_empty(), "Buffer should not be empty after compression"); + + let (deserialized_log_entry, remaining_buf) = LogEntry::from_compact(&buffer, bytes_written); + + assert_eq!(original_log_entry, deserialized_log_entry, "Original and deserialized log entries should be equal"); + assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); + } +} From 5483329bb40c984852917c8043642fa5e3bc5884 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Mon, 19 May 2025 17:38:54 +0530 Subject: [PATCH 14/22] lintfix --- crates/supervisor/storage/src/models/block.rs | 8 +++++-- crates/supervisor/storage/src/models/log.rs | 21 ++++++++++++------- crates/supervisor/storage/src/models/mod.rs | 8 +++++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/crates/supervisor/storage/src/models/block.rs b/crates/supervisor/storage/src/models/block.rs index 22d8c086db..01257c69c5 100644 --- a/crates/supervisor/storage/src/models/block.rs +++ b/crates/supervisor/storage/src/models/block.rs @@ -53,8 +53,12 @@ mod tests { let bytes_written = original_header.to_compact(&mut buffer); assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); - let (deserialized_header, remaining_buf) = BlockHeader::from_compact(&buffer, bytes_written); - assert_eq!(original_header, deserialized_header, "Original and deserialized header should be equal"); + let (deserialized_header, remaining_buf) = + BlockHeader::from_compact(&buffer, bytes_written); + assert_eq!( + original_header, deserialized_header, + "Original and deserialized header should be equal" + ); assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); } } diff --git a/crates/supervisor/storage/src/models/log.rs b/crates/supervisor/storage/src/models/log.rs index ad178b68b3..b846eeb8db 100644 --- a/crates/supervisor/storage/src/models/log.rs +++ b/crates/supervisor/storage/src/models/log.rs @@ -80,18 +80,19 @@ mod tests { assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); assert!(!buffer.is_empty(), "Buffer should not be empty after compression"); - let (deserialized_log_entry, remaining_buf) = LogEntry::from_compact(&buffer, bytes_written); + let (deserialized_log_entry, remaining_buf) = + LogEntry::from_compact(&buffer, bytes_written); - assert_eq!(original_log_entry, deserialized_log_entry, "Original and deserialized log entries should be equal"); + assert_eq!( + original_log_entry, deserialized_log_entry, + "Original and deserialized log entries should be equal" + ); assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); } #[test] fn test_log_entry_compact_roundtrip_without_message() { - let original_log_entry = LogEntry { - hash: test_b256(3), - executing_message: None, - }; + let original_log_entry = LogEntry { hash: test_b256(3), executing_message: None }; let mut buffer = Vec::new(); let bytes_written = original_log_entry.to_compact(&mut buffer); @@ -99,9 +100,13 @@ mod tests { assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); assert!(!buffer.is_empty(), "Buffer should not be empty after compression"); - let (deserialized_log_entry, remaining_buf) = LogEntry::from_compact(&buffer, bytes_written); + let (deserialized_log_entry, remaining_buf) = + LogEntry::from_compact(&buffer, bytes_written); - assert_eq!(original_log_entry, deserialized_log_entry, "Original and deserialized log entries should be equal"); + assert_eq!( + original_log_entry, deserialized_log_entry, + "Original and deserialized log entries should be equal" + ); assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); } } diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index d017ba4ecf..99614c2c49 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -87,8 +87,12 @@ mod tests { #[test] fn test_block_header_compression_decompression() { - let original = - BlockHeader { hash: test_b256(1), parent_hash: test_b256(2), time: 1234567890 }; + let original = BlockHeader { + number: 1, + hash: test_b256(1), + parent_hash: test_b256(2), + time: 1234567890, + }; let mut compressed_buf = Vec::new(); original.compress_to_buf(&mut compressed_buf); From 2177686de86ab46e1fe86f35852c517adf583106 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Mon, 19 May 2025 17:47:37 +0530 Subject: [PATCH 15/22] feat: derivation table schema added --- .../storage/src/models/derivation.rs | 82 +++++++++++++++++++ crates/supervisor/storage/src/models/mod.rs | 10 ++- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 crates/supervisor/storage/src/models/derivation.rs diff --git a/crates/supervisor/storage/src/models/derivation.rs b/crates/supervisor/storage/src/models/derivation.rs new file mode 100644 index 0000000000..fe660061b3 --- /dev/null +++ b/crates/supervisor/storage/src/models/derivation.rs @@ -0,0 +1,82 @@ +//! Models for storing blockchain derivation in the database. +//! +//! This module defines the data structure and schema used for tracking +//! how blocks are derived from source. This is particularly relevant +//! in rollup contexts, such as linking an L2 block to its originating L1 block. + +use super::BlockHeader; +use reth_codecs::Compact; +use serde::{Deserialize, Serialize}; + +/// Represents a pair of block where one block (derived) is derived from another (source). +/// +/// This structure is used to track the lineage of blocks where L2 blocks are derived from L1 +/// blocks. It stores the header information for both the source and the derived block. It is stored +/// as value in the [`crate::models::DerivedBlocks`] table. +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] +pub struct DerivedBlockPair { + /// The block that was derived from the `source` block. + pub derived: BlockHeader, + /// The source block from which the `derived` block was created. + pub source: BlockHeader, +} + +// Manually implement Compact for DerivedBlockPair +impl Compact for DerivedBlockPair { + fn to_compact>(&self, buf: &mut B) -> usize { + let mut bytes_written = 0; + // Encode the 'derived' BlockHeader first + bytes_written += self.derived.to_compact(buf); + // Then encode the 'source' BlockHeader + bytes_written += self.source.to_compact(buf); + bytes_written + } + + // The `len` parameter here is the length of the buffer `buf` that pertains to this specific + // DerivedBlockPair. Since BlockHeader::from_compact returns the remaining buffer, we don't + // strictly need `len` if BlockHeader consumes exactly what it needs and returns the rest. + fn from_compact(buf: &[u8], _len: usize) -> (Self, &[u8]) { + let (derived, remaining_buf) = BlockHeader::from_compact(buf, buf.len()); + let (source, final_remaining_buf) = + BlockHeader::from_compact(remaining_buf, remaining_buf.len()); + (Self { derived, source }, final_remaining_buf) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::models::BlockHeader; + use alloy_primitives::B256; + use reth_codecs::Compact; + + fn test_b256(val: u8) -> B256 { + let mut val_bytes = [0u8; 32]; + val_bytes[0] = val; + let b256_from_val = B256::from(val_bytes); + B256::random() ^ b256_from_val + } + + #[test] + fn test_derived_block_pair_compact_roundtrip() { + let source_header = + BlockHeader { number: 100, hash: test_b256(1), parent_hash: test_b256(2), time: 1000 }; + let derived_header = + BlockHeader { number: 200, hash: test_b256(3), parent_hash: test_b256(4), time: 1010 }; + + let original_pair = DerivedBlockPair { source: source_header, derived: derived_header }; + + let mut buffer = Vec::new(); + let bytes_written = original_pair.to_compact(&mut buffer); + + assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); + let (deserialized_pair, remaining_buf) = + DerivedBlockPair::from_compact(&buffer, bytes_written); + + assert_eq!( + original_pair, deserialized_pair, + "Original and deserialized pairs should be equal" + ); + assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); + } +} diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index 99614c2c49..d289d71c81 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -18,6 +18,9 @@ pub use log::{ExecutingMessageEntry, LogEntry}; mod block; pub use block::BlockHeader; +mod derivation; +pub use derivation::DerivedBlockPair; + /// Implements [`reth_db_api::table::Compress`] and [`reth_db_api::table::Decompress`] traits for /// types that implement [`reth_codecs::Compact`]. /// @@ -50,7 +53,7 @@ macro_rules! impl_compression_for_compact { } // Implement compression logic for all value types stored in tables -impl_compression_for_compact!(BlockHeader, LogEntry); +impl_compression_for_compact!(BlockHeader, LogEntry, DerivedBlockPair); tables! { /// A dup-sorted table that stores all logs emitted in a given block, sorted by their index. @@ -69,6 +72,11 @@ tables! { type Key = u64; type Value = BlockHeader; } + + table DerivedBlocks { + type Key = u64; + type Value = DerivedBlockPair; + } } #[cfg(test)] From e4b321008412b36eaf52bcdc0a6652b1a0f5a724 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Mon, 19 May 2025 19:46:47 +0530 Subject: [PATCH 16/22] table added for source to derived block --- .../supervisor/storage/src/models/common.rs | 111 ++++++++++++++++++ crates/supervisor/storage/src/models/mod.rs | 77 +++++++++++- 2 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 crates/supervisor/storage/src/models/common.rs diff --git a/crates/supervisor/storage/src/models/common.rs b/crates/supervisor/storage/src/models/common.rs new file mode 100644 index 0000000000..2598aa2dc9 --- /dev/null +++ b/crates/supervisor/storage/src/models/common.rs @@ -0,0 +1,111 @@ +//! Common model types used across various storage tables. + +use alloy_primitives::bytes; +use reth_codecs::Compact; +use serde::{Deserialize, Serialize}; +use std::ops::{Deref, DerefMut}; + +/// A newtype wrapper for `Vec` to represent a list of numbers. +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] +pub struct U64List(pub Vec); + +// Implement Compact for the newtype by delegating to the inner Vec. +impl Compact for U64List { + fn to_compact>(&self, buf: &mut B) -> usize { + self.0.to_compact(buf) + } + + fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) { + let (vec_u64, remainder) = Vec::::from_compact(buf, len); + (U64List(vec_u64), remainder) + } +} + +impl Deref for U64List { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for U64List { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +#[cfg(test)] +mod tests { + use super::*; + use reth_codecs::Compact; + + #[test] + fn test_u64list_compact_empty() { + let original_list = U64List(Vec::new()); + + let mut buffer = Vec::new(); + let bytes_written = original_list.to_compact(&mut buffer); + + assert_eq!( + bytes_written, + buffer.len(), + "Bytes written should match buffer length for empty list" + ); + let (deserialized_list, remaining_buf) = U64List::from_compact(&buffer, bytes_written); + + assert_eq!( + original_list, deserialized_list, + "Original and deserialized empty lists should be equal" + ); + assert!( + remaining_buf.is_empty(), + "Remaining buffer should be empty after deserialization of empty list" + ); + } + + #[test] + fn test_u64list_compact_with_data() { + let original_list = U64List(vec![10, 20, 30, 40, 50]); + + let mut buffer = Vec::new(); + let bytes_written = original_list.to_compact(&mut buffer); + + assert_eq!( + bytes_written, + buffer.len(), + "Bytes written should match buffer length for list with data" + ); + let (deserialized_list, remaining_buf) = U64List::from_compact(&buffer, bytes_written); + + assert_eq!( + original_list, deserialized_list, + "Original and deserialized lists with data should be equal" + ); + assert!( + remaining_buf.is_empty(), + "Remaining buffer should be empty after deserialization of list with data" + ); + } + + #[test] + fn test_u64list_deref() { + let list = U64List(vec![1, 2, 3]); + assert_eq!(list.len(), 3); + assert_eq!(list[0], 1); + assert!(!list.is_empty()); + } + + #[test] + fn test_u64list_deref_mut() { + let mut list = U64List(vec![1, 2, 3]); + list.push(4); + assert_eq!(list.0, vec![1, 2, 3, 4]); + + list.sort(); + assert_eq!(list.0, vec![1, 2, 3, 4]); + + list.clear(); + assert!(list.is_empty()); + } +} diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index d289d71c81..5f908c18a7 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -15,12 +15,16 @@ use std::fmt; mod log; pub use log::{ExecutingMessageEntry, LogEntry}; + mod block; pub use block::BlockHeader; mod derivation; pub use derivation::DerivedBlockPair; +mod common; +pub use common::U64List; + /// Implements [`reth_db_api::table::Compress`] and [`reth_db_api::table::Decompress`] traits for /// types that implement [`reth_codecs::Compact`]. /// @@ -53,7 +57,7 @@ macro_rules! impl_compression_for_compact { } // Implement compression logic for all value types stored in tables -impl_compression_for_compact!(BlockHeader, LogEntry, DerivedBlockPair); +impl_compression_for_compact!(BlockHeader, LogEntry, DerivedBlockPair, U64List); tables! { /// A dup-sorted table that stores all logs emitted in a given block, sorted by their index. @@ -73,10 +77,21 @@ tables! { type Value = BlockHeader; } + /// A table mapping a derived block number to its corresponding source and derived block headers. + /// - Key: `u64` — derived block number + /// - Value: [`DerivedBlockPair`] — pair of source and derived block headers table DerivedBlocks { type Key = u64; type Value = DerivedBlockPair; } + + /// A table mapping a source block number to a list of its derived block numbers. + /// - Key: `u64` — source block number + /// - Value: [`U64List`] — list of derived block numbers + table SourceToDerivedBlockNumbers { + type Key = u64; + type Value = U64List; + } } #[cfg(test)] @@ -141,4 +156,64 @@ mod tests { let decompressed = LogEntry::decompress(&compressed_buf).unwrap(); assert_eq!(original, decompressed); } + + #[test] + fn test_derived_block_pair_compression_decompression() { + let source_header = + BlockHeader { number: 100, hash: test_b256(6), parent_hash: test_b256(7), time: 1000 }; + let derived_header = BlockHeader { + number: 200, + hash: test_b256(8), + parent_hash: test_b256(8), // Link to source + time: 1010, + }; + + let original_pair = DerivedBlockPair { source: source_header, derived: derived_header }; + + let mut compressed_buf = Vec::new(); + original_pair.compress_to_buf(&mut compressed_buf); + + assert!(!compressed_buf.is_empty(), "Buffer should not be empty after compression"); + + let decompressed_pair = DerivedBlockPair::decompress(&compressed_buf).unwrap(); + assert_eq!( + original_pair, decompressed_pair, + "Original and deserialized pairs should be equal" + ); + } + + #[test] + fn test_u64list_compression_decompression_empty() { + let original_list = U64List(Vec::new()); + + let mut compressed_buf = Vec::new(); + original_list.compress_to_buf(&mut compressed_buf); + + // For an empty list, the compact representation might also be empty or very small. + // The primary check is that deserialization works and results in an empty list. + let decompressed_list = U64List::decompress(&compressed_buf).unwrap(); + assert_eq!( + original_list, decompressed_list, + "Original and deserialized empty U64List should be equal" + ); + } + + #[test] + fn test_u64list_compression_decompression_with_data() { + let original_list = U64List(vec![10, 20, 30, 40, 50]); + + let mut compressed_buf = Vec::new(); + original_list.compress_to_buf(&mut compressed_buf); + + assert!( + !compressed_buf.is_empty(), + "Buffer should not be empty after compression of U64List with data" + ); + + let decompressed_list = U64List::decompress(&compressed_buf).unwrap(); + assert_eq!( + original_list, decompressed_list, + "Original and deserialized U64List with data should be equal" + ); + } } From c092a1a33e6c800c2cd7ca813401331fee8d0059 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Mon, 19 May 2025 19:49:32 +0530 Subject: [PATCH 17/22] minor fixes --- crates/supervisor/storage/src/models/common.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/supervisor/storage/src/models/common.rs b/crates/supervisor/storage/src/models/common.rs index 2598aa2dc9..5dd190eb8c 100644 --- a/crates/supervisor/storage/src/models/common.rs +++ b/crates/supervisor/storage/src/models/common.rs @@ -5,11 +5,10 @@ use reth_codecs::Compact; use serde::{Deserialize, Serialize}; use std::ops::{Deref, DerefMut}; -/// A newtype wrapper for `Vec` to represent a list of numbers. +/// Wrapper for `Vec` to represent a list of numbers. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct U64List(pub Vec); -// Implement Compact for the newtype by delegating to the inner Vec. impl Compact for U64List { fn to_compact>(&self, buf: &mut B) -> usize { self.0.to_compact(buf) From 5c816d8d356eb94d773554501d4fc9e608c3c890 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Mon, 19 May 2025 19:57:21 +0530 Subject: [PATCH 18/22] blockHeader -> blockRef --- crates/supervisor/storage/src/models/block.rs | 22 +++++++++---------- crates/supervisor/storage/src/models/mod.rs | 20 ++++++++--------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/supervisor/storage/src/models/block.rs b/crates/supervisor/storage/src/models/block.rs index 01257c69c5..a507ae665a 100644 --- a/crates/supervisor/storage/src/models/block.rs +++ b/crates/supervisor/storage/src/models/block.rs @@ -13,11 +13,11 @@ use serde::{Deserialize, Serialize}; /// Metadata reference for a single block. /// -/// This struct captures minimal but essential block header information required -/// to track canonical block lineage and verify ancestry. It is stored as the value -/// in the [`crate::models::BlockHeaders`] table. +/// This struct captures essential block information required to track canonical +/// block lineage and verify ancestry. It is stored as the value +/// in the [`crate::models::BlockRefs`] table. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] -pub struct BlockHeader { +pub struct BlockRef { /// The height of the block. pub number: u64, /// The hash of the block itself. @@ -41,8 +41,8 @@ mod tests { } #[test] - fn test_block_header_compact_roundtrip() { - let original_header = BlockHeader { + fn test_block_ref_compact_roundtrip() { + let original_ref = BlockRef { number: 42, hash: test_b256(10), parent_hash: test_b256(11), @@ -50,14 +50,14 @@ mod tests { }; let mut buffer = Vec::new(); - let bytes_written = original_header.to_compact(&mut buffer); + let bytes_written = original_ref.to_compact(&mut buffer); assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); - let (deserialized_header, remaining_buf) = - BlockHeader::from_compact(&buffer, bytes_written); + let (deserialized_ref, remaining_buf) = + BlockRef::from_compact(&buffer, bytes_written); assert_eq!( - original_header, deserialized_header, - "Original and deserialized header should be equal" + original_ref, deserialized_ref, + "Original and deserialized ref should be equal" ); assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); } diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index 99614c2c49..cfac1a707f 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -16,7 +16,7 @@ use std::fmt; mod log; pub use log::{ExecutingMessageEntry, LogEntry}; mod block; -pub use block::BlockHeader; +pub use block::BlockRef; /// Implements [`reth_db_api::table::Compress`] and [`reth_db_api::table::Decompress`] traits for /// types that implement [`reth_codecs::Compact`]. @@ -26,7 +26,7 @@ pub use block::BlockHeader; /// /// # Example /// ```ignore -/// impl_compression_for_compact!(BlockHeader, LogEntry); +/// impl_compression_for_compact!(BlockRef, LogEntry); /// ``` macro_rules! impl_compression_for_compact { ($($name:ident$(<$($generic:ident),*>)?),+) => { @@ -50,7 +50,7 @@ macro_rules! impl_compression_for_compact { } // Implement compression logic for all value types stored in tables -impl_compression_for_compact!(BlockHeader, LogEntry); +impl_compression_for_compact!(BlockRef, LogEntry); tables! { /// A dup-sorted table that stores all logs emitted in a given block, sorted by their index. @@ -64,16 +64,16 @@ tables! { /// A table for storing block metadata by block number. /// This is a standard table (not dup-sorted) where: /// - Key: `u64` — block number - /// - Value: [`BlockHeader`] — block metadata - table BlockHeaders { + /// - Value: [`BlockRef`] — block metadata + table BlockRefs { type Key = u64; - type Value = BlockHeader; + type Value = BlockRef; } } #[cfg(test)] mod tests { - use super::*; // Imports BlockHeader, LogEntry, ExecutingMessageEntry, etc. + use super::*; use alloy_primitives::B256; use reth_db_api::table::{Compress, Decompress}; @@ -86,8 +86,8 @@ mod tests { } #[test] - fn test_block_header_compression_decompression() { - let original = BlockHeader { + fn test_block_ref_compression_decompression() { + let original = BlockRef { number: 1, hash: test_b256(1), parent_hash: test_b256(2), @@ -100,7 +100,7 @@ mod tests { // Ensure some data was written assert!(!compressed_buf.is_empty()); - let decompressed = BlockHeader::decompress(&compressed_buf).unwrap(); + let decompressed = BlockRef::decompress(&compressed_buf).unwrap(); assert_eq!(original, decompressed); } From 249558fa06a43d53254b85ed80e8815bfc4d552a Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Mon, 19 May 2025 19:58:14 +0530 Subject: [PATCH 19/22] lintfix --- crates/supervisor/storage/src/models/block.rs | 10 +++------- crates/supervisor/storage/src/models/mod.rs | 8 ++------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/crates/supervisor/storage/src/models/block.rs b/crates/supervisor/storage/src/models/block.rs index a507ae665a..4c34afc3af 100644 --- a/crates/supervisor/storage/src/models/block.rs +++ b/crates/supervisor/storage/src/models/block.rs @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize}; /// Metadata reference for a single block. /// -/// This struct captures essential block information required to track canonical +/// This struct captures essential block information required to track canonical /// block lineage and verify ancestry. It is stored as the value /// in the [`crate::models::BlockRefs`] table. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] @@ -53,12 +53,8 @@ mod tests { let bytes_written = original_ref.to_compact(&mut buffer); assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); - let (deserialized_ref, remaining_buf) = - BlockRef::from_compact(&buffer, bytes_written); - assert_eq!( - original_ref, deserialized_ref, - "Original and deserialized ref should be equal" - ); + let (deserialized_ref, remaining_buf) = BlockRef::from_compact(&buffer, bytes_written); + assert_eq!(original_ref, deserialized_ref, "Original and deserialized ref should be equal"); assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); } } diff --git a/crates/supervisor/storage/src/models/mod.rs b/crates/supervisor/storage/src/models/mod.rs index cfac1a707f..3cb206fd54 100644 --- a/crates/supervisor/storage/src/models/mod.rs +++ b/crates/supervisor/storage/src/models/mod.rs @@ -87,12 +87,8 @@ mod tests { #[test] fn test_block_ref_compression_decompression() { - let original = BlockRef { - number: 1, - hash: test_b256(1), - parent_hash: test_b256(2), - time: 1234567890, - }; + let original = + BlockRef { number: 1, hash: test_b256(1), parent_hash: test_b256(2), time: 1234567890 }; let mut compressed_buf = Vec::new(); original.compress_to_buf(&mut compressed_buf); From 644f0205aa63efe440b51845e8e1dfe274baec03 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Mon, 19 May 2025 20:13:20 +0530 Subject: [PATCH 20/22] deny setting updated --- deny.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deny.toml b/deny.toml index f0ad6b08a8..97f35d40c2 100644 --- a/deny.toml +++ b/deny.toml @@ -62,7 +62,7 @@ skip-tree = [] unknown-registry = "deny" unknown-git = "deny" allow-registry = ["https://github.com/rust-lang/crates.io-index"] -allow-git = [] +allow-git = ["https://github.com/paradigmxyz/reth"] [sources.allow-org] github = [] From 2ec942c8aa27be5d1b22b1731bbc0898970dc081 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Mon, 19 May 2025 21:40:32 +0530 Subject: [PATCH 21/22] testcase fixes --- crates/supervisor/storage/src/models/common.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/crates/supervisor/storage/src/models/common.rs b/crates/supervisor/storage/src/models/common.rs index 5dd190eb8c..d15da6b6c5 100644 --- a/crates/supervisor/storage/src/models/common.rs +++ b/crates/supervisor/storage/src/models/common.rs @@ -1,25 +1,13 @@ //! Common model types used across various storage tables. -use alloy_primitives::bytes; use reth_codecs::Compact; use serde::{Deserialize, Serialize}; use std::ops::{Deref, DerefMut}; /// Wrapper for `Vec` to represent a list of numbers. -#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] pub struct U64List(pub Vec); -impl Compact for U64List { - fn to_compact>(&self, buf: &mut B) -> usize { - self.0.to_compact(buf) - } - - fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) { - let (vec_u64, remainder) = Vec::::from_compact(buf, len); - (U64List(vec_u64), remainder) - } -} - impl Deref for U64List { type Target = Vec; From 4b3057e2b8586d5009e810f55d6b54375335a28c Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Tue, 20 May 2025 17:24:06 +0530 Subject: [PATCH 22/22] rust doc fixes --- Cargo.lock | 1 + crates/supervisor/storage/Cargo.toml | 1 + .../supervisor/storage/src/models/common.rs | 21 +++++-------------- .../storage/src/models/derivation.rs | 17 ++++++--------- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36fed6e994..4551134092 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5038,6 +5038,7 @@ version = "0.1.0" dependencies = [ "alloy-primitives", "bytes", + "derive_more", "modular-bitfield", "reth-codecs", "reth-db-api", diff --git a/crates/supervisor/storage/Cargo.toml b/crates/supervisor/storage/Cargo.toml index 7063aaf20d..4a830348b5 100644 --- a/crates/supervisor/storage/Cargo.toml +++ b/crates/supervisor/storage/Cargo.toml @@ -18,6 +18,7 @@ alloy-primitives = { workspace = true, features = ["map", "rlp", "serde", "rand" # Misc serde = { workspace = true, features = ["derive"] } +derive_more.workspace = true bytes = { workspace = true } modular-bitfield = { workspace = true } diff --git a/crates/supervisor/storage/src/models/common.rs b/crates/supervisor/storage/src/models/common.rs index d15da6b6c5..968dac51f6 100644 --- a/crates/supervisor/storage/src/models/common.rs +++ b/crates/supervisor/storage/src/models/common.rs @@ -1,27 +1,16 @@ //! Common model types used across various storage tables. +use derive_more::{Deref, DerefMut}; use reth_codecs::Compact; use serde::{Deserialize, Serialize}; -use std::ops::{Deref, DerefMut}; /// Wrapper for `Vec` to represent a list of numbers. -#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact)] +// todo: add support for Vec<64> in table +#[derive( + Deref, DerefMut, Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact, +)] pub struct U64List(pub Vec); -impl Deref for U64List { - type Target = Vec; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for U64List { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/supervisor/storage/src/models/derivation.rs b/crates/supervisor/storage/src/models/derivation.rs index a02e93474d..d53e0edb8e 100644 --- a/crates/supervisor/storage/src/models/derivation.rs +++ b/crates/supervisor/storage/src/models/derivation.rs @@ -8,33 +8,28 @@ use super::BlockRef; use reth_codecs::Compact; use serde::{Deserialize, Serialize}; -/// Represents a pair of block where one block (derived) is derived from another (source). +/// Represents a pair of blocks where one block [`derived`](`Self::derived`) is derived +/// from another [`source`](`Self::source`). /// /// This structure is used to track the lineage of blocks where L2 blocks are derived from L1 -/// blocks. It stores the block reference information for both the source and the derived. -/// It is stored as value in the [`crate::models::DerivedBlocks`] table. +/// blocks. It stores the [`BlockRef`] information for both the source and the derived blocks. +/// It is stored as value in the [`DerivedBlocks`](`crate::models::DerivedBlocks`) table. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct DerivedBlockPair { - /// The block that was derived from the `source` block. + /// The block that was derived from the [`source`](`Self::source`) block. pub derived: BlockRef, - /// The source block from which the `derived` block was created. + /// The source block from which the [`derived`](`Self::derived`) block was created. pub source: BlockRef, } -// Manually implement Compact for DerivedBlockPair impl Compact for DerivedBlockPair { fn to_compact>(&self, buf: &mut B) -> usize { let mut bytes_written = 0; - // Encode the 'derived' BlockRef first bytes_written += self.derived.to_compact(buf); - // Then encode the 'source' BlockRef bytes_written += self.source.to_compact(buf); bytes_written } - // The `len` parameter here is the length of the buffer `buf` that pertains to this specific - // DerivedBlockPair. Since BlockRef::from_compact returns the remaining buffer, we don't - // strictly need `len` if BlockRef consumes exactly what it needs and returns the rest. fn from_compact(buf: &[u8], _len: usize) -> (Self, &[u8]) { let (derived, remaining_buf) = BlockRef::from_compact(buf, buf.len()); let (source, final_remaining_buf) =