diff --git a/Cargo.lock b/Cargo.lock index b327baf..76b34b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,15 +17,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" -[[package]] -name = "aead" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" -dependencies = [ - "generic-array", -] - [[package]] name = "aead" version = "0.5.2" @@ -36,19 +27,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "aes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" -dependencies = [ - "cfg-if", - "cipher 0.3.0", - "cpufeatures", - "ctr 0.8.0", - "opaque-debug", -] - [[package]] name = "aes" version = "0.8.4" @@ -56,35 +34,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", - "cipher 0.4.4", + "cipher", "cpufeatures", ] -[[package]] -name = "aes-gcm" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc3be92e19a7ef47457b8e6f90707e12b6ac5d20c6f3866584fa3be0787d839f" -dependencies = [ - "aead 0.4.3", - "aes 0.7.5", - "cipher 0.3.0", - "ctr 0.7.0", - "ghash 0.4.4", - "subtle", -] - [[package]] name = "aes-gcm" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" dependencies = [ - "aead 0.5.2", - "aes 0.8.4", - "cipher 0.4.4", - "ctr 0.9.2", - "ghash 0.5.1", + "aead", + "aes", + "cipher", + "ctr", + "ghash", "subtle", ] @@ -157,9 +121,9 @@ dependencies = [ [[package]] name = "alloy-chains" -version = "0.1.38" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "156bfc5dcd52ef9a5f33381701fa03310317e14c65093a9430d3e3557b08dcd3" +checksum = "742b81ecb16cc5e9c029d55257cc8d9d5f9409f6384b65d996e583ad62a8c831" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -1832,7 +1796,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" dependencies = [ "cfg-if", - "cipher 0.4.4", + "cipher", "cpufeatures", ] @@ -1842,9 +1806,9 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" dependencies = [ - "aead 0.5.2", + "aead", "chacha20", - "cipher 0.4.4", + "cipher", "poly1305", "zeroize", ] @@ -1864,15 +1828,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "cipher" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" -dependencies = [ - "generic-array", -] - [[package]] name = "cipher" version = "0.4.4" @@ -2234,31 +2189,13 @@ dependencies = [ "subtle", ] -[[package]] -name = "ctr" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a232f92a03f37dd7d7dd2adc67166c77e9cd88de5b019b9a9eecfaeaf7bfd481" -dependencies = [ - "cipher 0.3.0", -] - -[[package]] -name = "ctr" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" -dependencies = [ - "cipher 0.3.0", -] - [[package]] name = "ctr" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" dependencies = [ - "cipher 0.4.4", + "cipher", ] [[package]] @@ -2392,6 +2329,17 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "delay_map" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df941644b671f05f59433e481ba0d31ac10e3667de725236a4c0d587c496fba1" +dependencies = [ + "futures", + "tokio", + "tokio-util", +] + [[package]] name = "der" version = "0.7.9" @@ -2541,64 +2489,65 @@ dependencies = [ [[package]] name = "discv5" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cafb8ed8d460b7d1c8d4c970270d45ecb5e283179a3945143196624c55cda6ac" +checksum = "f569b8c367554666c8652305621e8bae3634a2ff5c6378081d5bd8c399c99f23" dependencies = [ - "aes 0.7.5", - "aes-gcm 0.9.2", + "aes", + "aes-gcm", "alloy-rlp", "arrayvec", - "delay_map", + "ctr", + "delay_map 0.3.0", "enr", "fnv", "futures", - "hashlink", + "hashlink 0.8.4", "hex", "hkdf", "lazy_static", + "libp2p-identity", "lru", "more-asserts", + "multiaddr", "parking_lot 0.11.2", "rand", "smallvec", "socket2 0.4.10", "tokio", "tracing", - "uint", + "uint 0.9.5", "zeroize", ] [[package]] name = "discv5" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f569b8c367554666c8652305621e8bae3634a2ff5c6378081d5bd8c399c99f23" +checksum = "23e6b70634e26c909d1edbb3142b3eaf3b89da0e52f284f00ca7c80d9901ad9e" dependencies = [ - "aes 0.8.4", - "aes-gcm 0.10.3", + "aes", + "aes-gcm", "alloy-rlp", "arrayvec", - "ctr 0.9.2", - "delay_map", + "ctr", + "delay_map 0.4.0", "enr", "fnv", "futures", - "hashlink", + "hashlink 0.9.1", "hex", "hkdf", "lazy_static", - "libp2p-identity", "lru", "more-asserts", - "multiaddr", - "parking_lot 0.11.2", + "parking_lot 0.12.3", "rand", "smallvec", - "socket2 0.4.10", + "socket2 0.5.7", "tokio", "tracing", - "uint", + "uint 0.10.0", "zeroize", ] @@ -3149,16 +3098,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "ghash" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" -dependencies = [ - "opaque-debug", - "polyval 0.5.3", -] - [[package]] name = "ghash" version = "0.5.1" @@ -3166,7 +3105,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" dependencies = [ "opaque-debug", - "polyval 0.6.2", + "polyval", ] [[package]] @@ -3319,6 +3258,15 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "hashlink" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +dependencies = [ + "hashbrown 0.14.5", +] + [[package]] name = "hdrhistogram" version = "7.5.4" @@ -4375,7 +4323,7 @@ dependencies = [ [[package]] name = "kona-derive" version = "0.0.3" -source = "git+https://github.com/anton-rs/kona?branch=main#a83f0cfbd3704343b74c288a6a7ff889aaf9e098" +source = "git+https://github.com/anton-rs/kona?branch=main#6b6a8816690831ba97462c9e4585a3d61a30af88" dependencies = [ "alloc-no-stdlib", "alloy-consensus", @@ -4401,7 +4349,7 @@ dependencies = [ [[package]] name = "kona-primitives" version = "0.0.2" -source = "git+https://github.com/anton-rs/kona?branch=main#a83f0cfbd3704343b74c288a6a7ff889aaf9e098" +source = "git+https://github.com/anton-rs/kona?branch=main#6b6a8816690831ba97462c9e4585a3d61a30af88" dependencies = [ "alloy-eips", "alloy-primitives", @@ -4417,7 +4365,7 @@ dependencies = [ [[package]] name = "kona-providers" version = "0.0.1" -source = "git+https://github.com/anton-rs/kona?branch=main#a83f0cfbd3704343b74c288a6a7ff889aaf9e098" +source = "git+https://github.com/anton-rs/kona?branch=main#6b6a8816690831ba97462c9e4585a3d61a30af88" dependencies = [ "alloy-consensus", "alloy-primitives", @@ -4430,7 +4378,7 @@ dependencies = [ [[package]] name = "kona-providers-alloy" version = "0.0.1" -source = "git+https://github.com/anton-rs/kona?branch=main#a83f0cfbd3704343b74c288a6a7ff889aaf9e098" +source = "git+https://github.com/anton-rs/kona?branch=main#6b6a8816690831ba97462c9e4585a3d61a30af88" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4458,7 +4406,7 @@ dependencies = [ "alloy-rlp", "async-trait", "eyre", - "hashbrown 0.14.5", + "hashbrown 0.15.0", "kona-derive", "kona-primitives", "kona-providers", @@ -4522,9 +4470,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.159" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libloading" @@ -5630,7 +5578,7 @@ dependencies = [ [[package]] name = "op-alloy-consensus" version = "0.4.0" -source = "git+https://github.com/alloy-rs/op-alloy?branch=main#20eb16233c00087827f70d6b4a42afb79dc39da9" +source = "git+https://github.com/alloy-rs/op-alloy?branch=main#9fd8a65e9b8c535f09fdde6f3997cc94637bd292" dependencies = [ "alloy-consensus", "alloy-eips", @@ -5659,7 +5607,7 @@ dependencies = [ [[package]] name = "op-alloy-genesis" version = "0.4.0" -source = "git+https://github.com/alloy-rs/op-alloy?branch=main#20eb16233c00087827f70d6b4a42afb79dc39da9" +source = "git+https://github.com/alloy-rs/op-alloy?branch=main#9fd8a65e9b8c535f09fdde6f3997cc94637bd292" dependencies = [ "alloy-consensus", "alloy-eips", @@ -5689,7 +5637,7 @@ dependencies = [ [[package]] name = "op-alloy-protocol" version = "0.4.0" -source = "git+https://github.com/alloy-rs/op-alloy?branch=main#20eb16233c00087827f70d6b4a42afb79dc39da9" +source = "git+https://github.com/alloy-rs/op-alloy?branch=main#9fd8a65e9b8c535f09fdde6f3997cc94637bd292" dependencies = [ "alloy-consensus", "alloy-eips", @@ -5705,7 +5653,7 @@ dependencies = [ [[package]] name = "op-alloy-rpc-jsonrpsee" version = "0.4.0" -source = "git+https://github.com/alloy-rs/op-alloy?branch=main#20eb16233c00087827f70d6b4a42afb79dc39da9" +source = "git+https://github.com/alloy-rs/op-alloy?branch=main#9fd8a65e9b8c535f09fdde6f3997cc94637bd292" dependencies = [ "alloy-eips", "alloy-primitives", @@ -5716,7 +5664,7 @@ dependencies = [ [[package]] name = "op-alloy-rpc-types" version = "0.4.0" -source = "git+https://github.com/alloy-rs/op-alloy?branch=main#20eb16233c00087827f70d6b4a42afb79dc39da9" +source = "git+https://github.com/alloy-rs/op-alloy?branch=main#9fd8a65e9b8c535f09fdde6f3997cc94637bd292" dependencies = [ "alloy-consensus", "alloy-eips", @@ -5746,7 +5694,7 @@ dependencies = [ [[package]] name = "op-alloy-rpc-types-engine" version = "0.4.0" -source = "git+https://github.com/alloy-rs/op-alloy?branch=main#20eb16233c00087827f70d6b4a42afb79dc39da9" +source = "git+https://github.com/alloy-rs/op-alloy?branch=main#9fd8a65e9b8c535f09fdde6f3997cc94637bd292" dependencies = [ "alloy-primitives", "alloy-rpc-types-engine", @@ -5766,7 +5714,7 @@ dependencies = [ "alloy-rlp", "arbitrary", "arbtest", - "discv5 0.6.0", + "discv5 0.8.0", "eyre", "futures", "lazy_static", @@ -5780,6 +5728,24 @@ dependencies = [ "unsigned-varint 0.8.0", ] +[[package]] +name = "op-rpc" +version = "0.0.0" +dependencies = [ + "alloy", + "alloy-eips", + "async-trait", + "jsonrpsee", + "jsonrpsee-types", + "op-alloy-rpc-jsonrpsee", + "op-alloy-rpc-types", + "reqwest", + "reth-rpc-eth-types", + "serde_json", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing", +] + [[package]] name = "op-rs" version = "0.1.0" @@ -5800,9 +5766,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.67" +version = "0.10.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b8cefcf97f41316955f9294cd61f639bdcfa9f2f230faac6cb896aa8ab64704" +checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" dependencies = [ "bitflags 2.6.0", "cfg-if", @@ -6117,19 +6083,7 @@ checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" dependencies = [ "cpufeatures", "opaque-debug", - "universal-hash 0.5.1", -] - -[[package]] -name = "polyval" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" -dependencies = [ - "cfg-if", - "cpufeatures", - "opaque-debug", - "universal-hash 0.4.0", + "universal-hash", ] [[package]] @@ -6141,7 +6095,7 @@ dependencies = [ "cfg-if", "cpufeatures", "opaque-debug", - "universal-hash 0.5.1", + "universal-hash", ] [[package]] @@ -6193,7 +6147,7 @@ checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", "impl-codec", - "uint", + "uint 0.9.5", ] [[package]] @@ -6689,6 +6643,7 @@ dependencies = [ "pin-project-lite", "quinn", "rustls", + "rustls-native-certs 0.8.0", "rustls-pemfile", "rustls-pki-types", "serde", @@ -7347,14 +7302,14 @@ name = "reth-ecies" version = "1.0.8" source = "git+https://github.com/paradigmxyz/reth?rev=a846cbd#a846cbdcee94d00ed1b022708f19e8ed20ffbb29" dependencies = [ - "aes 0.8.4", + "aes", "alloy-primitives", "alloy-rlp", "block-padding", "byteorder", - "cipher 0.4.4", + "cipher", "concat-kdf", - "ctr 0.9.2", + "ctr", "digest 0.10.7", "futures", "generic-array", @@ -9214,7 +9169,7 @@ dependencies = [ "clap", "eyre", "futures", - "hashbrown 0.14.5", + "hashbrown 0.15.0", "kona-derive", "kona-providers", "kona-providers-alloy", @@ -9671,9 +9626,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.129" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "6dbcf9b78a125ee667ae19388837dd12294b858d101fdd393cb9d5501ef09eb2" dependencies = [ "indexmap 2.6.0", "itoa", @@ -9933,7 +9888,7 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "850948bee068e713b8ab860fe1adc4d109676ab4c3b621fd8147f06b261f2f85" dependencies = [ - "aes-gcm 0.10.3", + "aes-gcm", "blake2", "chacha20poly1305", "curve25519-dalek", @@ -10073,7 +10028,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "superchain" version = "0.7.1" -source = "git+https://github.com/anton-rs/superchain?branch=main#5a2e3e4ebb0eaf473f4aee95d3d4211657dcd40c" +source = "git+https://github.com/anton-rs/superchain?branch=main#ade4cfcad120327b4a14e0ae90dedc4c55fba716" dependencies = [ "alloy-primitives", "lazy_static", @@ -10819,6 +10774,18 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "uint" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909988d098b2f738727b161a106cfc7cab00c539c2687a8836f8e565976fb53e" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unarray" version = "0.1.4" @@ -10884,16 +10851,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" -[[package]] -name = "universal-hash" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" -dependencies = [ - "generic-array", - "subtle", -] - [[package]] name = "universal-hash" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 3e6be73..c7d504e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,7 @@ alloy = { version = "0.4.2", features = [ ] } alloy-primitives = { version = "0.8", features = ["serde"] } alloy-rlp = "0.3" +alloy-eips = { version = "0.4", default-features = false } # Op-Alloy op-alloy-consensus = { version = "0.4.0", default-features = false } @@ -76,7 +77,11 @@ tokio = { version = "1.21", default-features = false } # Serialization serde_json = "1" -ethereum_ssz = "0.7.1" +ethereum_ssz = "0.8.0" + +# RPC +jsonrpsee = { version = "0.24", features = ["jsonrpsee-core", "client-core", "server-core", "macros"] } +jsonrpsee-types = "0.24" # Reth reth = { git = "https://github.com/paradigmxyz/reth", rev = "a846cbd" } @@ -93,10 +98,12 @@ reth-provider = { git = "https://github.com/paradigmxyz/reth", rev = "a846cbd" } reth-revm = { git = "https://github.com/paradigmxyz/reth", rev = "a846cbd" } reth-evm = { git = "https://github.com/paradigmxyz/reth", rev = "a846cbd" } reth-tracing = { git = "https://github.com/paradigmxyz/reth", rev = "a846cbd" } +reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth", rev = "a846cbd" } +reth-rpc-eth-types = { git = "https://github.com/paradigmxyz/reth", rev = "a846cbd" } # Networking snap = "1.1.1" -discv5 = "0.6.0" +discv5 = "0.8.0" openssl = { version = "0.10.66", features = ["vendored"] } libp2p-identity = { version = "0.2.9", features = [ "secp256k1" ] } libp2p = { version = "0.54.0", features = ["macros", "tokio", "tcp", "noise", "gossipsub", "ping", "yamux"] } @@ -106,17 +113,18 @@ arbtest = "0.3" arbitrary = { version = "1", features = ["derive"] } # Misc -reqwest = "0.12.7" -tracing = "0.1.0" +tracing = "0.1.40" +thiserror = "1.0" tracing-subscriber = "0.3.18" eyre = "0.6.12" clap = { version = "4.5.4", features = ["derive", "env"] } lazy_static = "1.5.0" futures = "0.3.30" -async-trait = "0.1.81" -hashbrown = "0.14.5" +async-trait = "0.1.83" +hashbrown = "0.15.0" parking_lot = "0.12.3" unsigned-varint = "0.8.0" +reqwest = { version = "0.12", features = ["rustls-tls-native-roots"] } rand = { version = "0.8.5", features = ["small_rng", "alloc", "getrandom"], default-features = false } url = "2.5.2" diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml new file mode 100644 index 0000000..3e1918d --- /dev/null +++ b/crates/rpc/Cargo.toml @@ -0,0 +1,43 @@ +[package] +name = "op-rpc" +description = "Consensus RPC for Rollup Nodes" +version = "0.0.0" +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +keywords.workspace = true +categories.workspace = true + +[dependencies] +# op-alloy +op-alloy-rpc-types.workspace = true +op-alloy-rpc-jsonrpsee.workspace = true + +# Alloy +alloy-eips.workspace = true + +# Misc +tracing.workspace = true +jsonrpsee.workspace = true +async-trait.workspace = true + +# `reth` feature flag dependencies +alloy = { workspace = true, optional = true } +reqwest = { workspace = true, optional = true } +thiserror = { workspace = true, optional = true } +serde_json = { workspace = true, optional = true } +jsonrpsee-types = { workspace = true, optional = true } +reth-rpc-eth-types = { workspace = true, optional = true } + +[features] +default = ["reth"] +reth = [ + "dep:alloy", + "dep:reqwest", + "dep:serde_json", + "dep:thiserror", + "dep:jsonrpsee-types", + "dep:reth-rpc-eth-types", +] diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs new file mode 100644 index 0000000..4b2beac --- /dev/null +++ b/crates/rpc/src/lib.rs @@ -0,0 +1,10 @@ +//! Consensus RPC for Rollup Nodes + +#![doc(issue_tracker_base_url = "https://github.com/paradigmxyz/op-rs/issues/")] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] + +pub mod rollup; + +#[cfg(feature = "reth")] +pub mod sequencer; diff --git a/crates/rpc/src/rollup.rs b/crates/rpc/src/rollup.rs new file mode 100644 index 0000000..3a09aa7 --- /dev/null +++ b/crates/rpc/src/rollup.rs @@ -0,0 +1,48 @@ +//! Contains the RPC Definition + +use alloy_eips::BlockNumberOrTag; +use async_trait::async_trait; +use jsonrpsee::core::RpcResult; +use op_alloy_rpc_jsonrpsee::traits::RollupNodeServer; +use op_alloy_rpc_types::{ + config::RollupConfig, output::OutputResponse, safe_head::SafeHeadResponse, sync::SyncStatus, +}; +use tracing::trace; + +/// An implementation of the [`RollupNodeServer`] trait. +#[derive(Debug, Clone)] +pub struct RollupNodeRpc { + /// The version of the node. + version: String, +} + +#[async_trait] +impl RollupNodeServer for RollupNodeRpc { + async fn op_output_at_block( + &self, + block_number: BlockNumberOrTag, + ) -> RpcResult { + trace!("op_output_at_block: {:?}", block_number); + unimplemented!() + } + + async fn op_safe_head_at_l1_block( + &self, + block_number: BlockNumberOrTag, + ) -> RpcResult { + trace!("op_safe_head_at_l1_block: {:?}", block_number); + unimplemented!() + } + + async fn op_sync_status(&self) -> RpcResult { + unimplemented!() + } + + async fn op_rollup_config(&self) -> RpcResult { + unimplemented!() + } + + async fn op_version(&self) -> RpcResult { + Ok(self.version.clone()) + } +} diff --git a/crates/rpc/src/sequencer.rs b/crates/rpc/src/sequencer.rs new file mode 100644 index 0000000..c4e2e12 --- /dev/null +++ b/crates/rpc/src/sequencer.rs @@ -0,0 +1,114 @@ +//! Optimism reth RPC Extension used to forward raw transactions to the sequencer. + +use std::sync::{atomic::AtomicUsize, Arc}; + +use jsonrpsee_types::error::{ErrorObject, INTERNAL_ERROR_CODE}; +use reqwest::Client; +use reth_rpc_eth_types::error::EthApiError; +use reth_rpc_types::ToRpcError; + +/// Error type when interacting with the Sequencer +#[derive(Debug, thiserror::Error)] +pub enum SequencerRpcError { + /// Wrapper around an [`reqwest::Error`]. + #[error(transparent)] + HttpError(#[from] reqwest::Error), + /// Thrown when serializing transaction to forward to sequencer + #[error("invalid sequencer transaction")] + InvalidSequencerTransaction, +} + +impl ToRpcError for SequencerRpcError { + fn to_rpc_error(&self) -> ErrorObject<'static> { + ErrorObject::owned(INTERNAL_ERROR_CODE, self.to_string(), None::) + } +} + +impl From for EthApiError { + fn from(err: SequencerRpcError) -> Self { + Self::other(err) + } +} + +/// A client to interact with a Sequencer +#[derive(Debug, Clone)] +pub struct SequencerClient { + inner: Arc, +} + +impl SequencerClient { + /// Creates a new [`SequencerClient`]. + pub fn new(sequencer_endpoint: impl Into) -> Self { + let client = Client::builder().use_rustls_tls().build().unwrap(); + Self::with_client(sequencer_endpoint, client) + } + + /// Creates a new [`SequencerClient`]. + pub fn with_client(sequencer_endpoint: impl Into, http_client: Client) -> Self { + let inner = SequencerClientInner { + sequencer_endpoint: sequencer_endpoint.into(), + http_client, + id: AtomicUsize::new(0), + }; + Self { inner: Arc::new(inner) } + } + + /// Returns the network of the client + pub fn endpoint(&self) -> &str { + &self.inner.sequencer_endpoint + } + + /// Returns the client + pub fn http_client(&self) -> &Client { + &self.inner.http_client + } + + /// Returns the next id for the request + fn next_request_id(&self) -> usize { + self.inner.id.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + } + + /// Forwards a transaction to the sequencer endpoint. + pub async fn forward_raw_transaction(&self, tx: &[u8]) -> Result<(), SequencerRpcError> { + let body = serde_json::to_string(&serde_json::json!({ + "jsonrpc": "2.0", + "method": "eth_sendRawTransaction", + "params": [format!("0x{}", alloy::primitives::hex::encode(tx))], + "id": self.next_request_id() + })) + .map_err(|_| { + tracing::warn!( + target = "rpc::eth", + "Failed to serialize transaction for forwarding to sequencer" + ); + SequencerRpcError::InvalidSequencerTransaction + })?; + + self.http_client() + .post(self.endpoint()) + .header(reqwest::header::CONTENT_TYPE, "application/json") + .body(body) + .send() + .await + .inspect_err(|err| { + tracing::warn!( + target = "rpc::eth", + %err, + "Failed to forward transaction to sequencer", + ); + }) + .map_err(SequencerRpcError::HttpError)?; + + Ok(()) + } +} + +#[derive(Debug, Default)] +struct SequencerClientInner { + /// The endpoint of the sequencer + sequencer_endpoint: String, + /// The HTTP client + http_client: Client, + /// Keeps track of unique request ids + id: AtomicUsize, +}