From 5c5b60fe512f8c023e6a0eae07f6bed4e7eafbde Mon Sep 17 00:00:00 2001 From: refcell Date: Wed, 19 Jun 2024 11:11:55 -0400 Subject: [PATCH] feat(fjord): fjord parameter changes --- Cargo.lock | 455 ++++++------------ crates/derive/src/lib.rs | 3 +- crates/derive/src/params.rs | 13 + crates/derive/src/types/batch/mod.rs | 4 +- crates/derive/src/types/batch/single_batch.rs | 5 +- .../src/types/batch/span_batch/batch.rs | 6 +- .../derive/src/types/batch/span_batch/bits.rs | 35 +- .../derive/src/types/batch/span_batch/mod.rs | 7 - .../src/types/batch/span_batch/payload.rs | 180 +++++-- .../src/types/batch/span_batch/prefix.rs | 20 +- .../derive/src/types/batch/span_batch/raw.rs | 25 +- .../types/batch/span_batch/transactions.rs | 82 +++- crates/derive/src/types/mod.rs | 1 - 13 files changed, 453 insertions(+), 383 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ded12ee8..ad2136975 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,10 +40,10 @@ name = "alloy-consensus" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=cb95183#cb95183d477024b57b27336035d10403e8ba55b8" dependencies = [ - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-eips 0.1.0", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-serde 0.1.0", "c-kzg", "serde", "sha2", @@ -51,13 +51,13 @@ dependencies = [ [[package]] name = "alloy-consensus" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#060de7871a76e99863917e62717c97423c37cadf" +version = "0.1.2" +source = "git+https://github.com/alloy-rs/alloy#68639726d659555a9693f3c1656e8efd0e2a5fdf" dependencies = [ - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy)", + "alloy-eips 0.1.2", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.1.0 (git+https://github.com/alloy-rs/alloy)", + "alloy-serde 0.1.2", "serde", ] @@ -68,7 +68,7 @@ source = "git+https://github.com/alloy-rs/alloy?rev=cb95183#cb95183d477024b57b27 dependencies = [ "alloy-primitives", "alloy-rlp", - "alloy-serde 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-serde 0.1.0", "c-kzg", "once_cell", "serde", @@ -76,12 +76,12 @@ dependencies = [ [[package]] name = "alloy-eips" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#060de7871a76e99863917e62717c97423c37cadf" +version = "0.1.2" +source = "git+https://github.com/alloy-rs/alloy#68639726d659555a9693f3c1656e8efd0e2a5fdf" dependencies = [ "alloy-primitives", "alloy-rlp", - "alloy-serde 0.1.0 (git+https://github.com/alloy-rs/alloy)", + "alloy-serde 0.1.2", "c-kzg", "serde", "sha2", @@ -93,7 +93,7 @@ version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=cb95183#cb95183d477024b57b27336035d10403e8ba55b8" dependencies = [ "alloy-primitives", - "alloy-serde 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-serde 0.1.0", "serde", ] @@ -114,8 +114,8 @@ name = "alloy-network" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=cb95183#cb95183d477024b57b27336035d10403e8ba55b8" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", + "alloy-eips 0.1.0", "alloy-json-rpc", "alloy-primitives", "alloy-rpc-types", @@ -167,7 +167,7 @@ name = "alloy-provider" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=cb95183#cb95183d477024b57b27336035d10403e8ba55b8" dependencies = [ - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-eips 0.1.0", "alloy-json-rpc", "alloy-network", "alloy-primitives", @@ -237,12 +237,12 @@ name = "alloy-rpc-types" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=cb95183#cb95183d477024b57b27336035d10403e8ba55b8" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", + "alloy-eips 0.1.0", "alloy-genesis", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-serde 0.1.0", "alloy-sol-types", "itertools 0.12.1", "serde", @@ -257,7 +257,7 @@ source = "git+https://github.com/alloy-rs/alloy?rev=cb95183#cb95183d477024b57b27 dependencies = [ "alloy-primitives", "alloy-rpc-types", - "alloy-serde 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-serde 0.1.0", "serde", "serde_json", ] @@ -274,8 +274,8 @@ dependencies = [ [[package]] name = "alloy-serde" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#060de7871a76e99863917e62717c97423c37cadf" +version = "0.1.2" +source = "git+https://github.com/alloy-rs/alloy#68639726d659555a9693f3c1656e8efd0e2a5fdf" dependencies = [ "alloy-primitives", "serde", @@ -1003,17 +1003,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "displaydoc" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - [[package]] name = "dunce" version = "1.0.4" @@ -1418,9 +1407,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.3" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0e7a4dd27b9476dc40cb050d3632d3bba3a70ddbff012285f7f8559a1e7e545" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "hyper" @@ -1442,6 +1431,23 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-rustls" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + [[package]] name = "hyper-tls" version = "0.6.0" @@ -1478,134 +1484,14 @@ dependencies = [ "tracing", ] -[[package]] -name = "icu_collections" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" -dependencies = [ - "displaydoc", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_locid" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" -dependencies = [ - "displaydoc", - "litemap", - "tinystr", - "writeable", - "zerovec", -] - -[[package]] -name = "icu_locid_transform" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_locid_transform_data", - "icu_provider", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_locid_transform_data" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" - -[[package]] -name = "icu_normalizer" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" -dependencies = [ - "displaydoc", - "icu_collections", - "icu_normalizer_data", - "icu_properties", - "icu_provider", - "smallvec", - "utf16_iter", - "utf8_iter", - "write16", - "zerovec", -] - -[[package]] -name = "icu_normalizer_data" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" - -[[package]] -name = "icu_properties" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f8ac670d7422d7f76b32e17a5db556510825b29ec9154f235977c9caba61036" -dependencies = [ - "displaydoc", - "icu_collections", - "icu_locid_transform", - "icu_properties_data", - "icu_provider", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_properties_data" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" - -[[package]] -name = "icu_provider" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_provider_macros", - "stable_deref_trait", - "tinystr", - "writeable", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_provider_macros" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - [[package]] name = "idna" -version = "1.0.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4716a3a0933a1d01c2f72450e89596eb51dd34ef3c211ccd875acdf1f8fe47ed" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "icu_normalizer", - "icu_properties", - "smallvec", - "utf8_iter", + "unicode-bidi", + "unicode-normalization", ] [[package]] @@ -1710,8 +1596,8 @@ dependencies = [ name = "kona-client" version = "0.1.0" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", + "alloy-eips 0.1.0", "alloy-primitives", "alloy-rlp", "anyhow", @@ -1759,8 +1645,8 @@ dependencies = [ name = "kona-derive" version = "0.0.1" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", + "alloy-eips 0.1.0", "alloy-node-bindings", "alloy-primitives", "alloy-provider", @@ -1795,8 +1681,8 @@ dependencies = [ name = "kona-executor" version = "0.0.1" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", + "alloy-eips 0.1.0", "alloy-primitives", "alloy-rlp", "anyhow", @@ -1813,8 +1699,8 @@ dependencies = [ name = "kona-host" version = "0.1.0" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", + "alloy-eips 0.1.0", "alloy-primitives", "alloy-provider", "alloy-rlp", @@ -1843,7 +1729,7 @@ dependencies = [ name = "kona-mpt" version = "0.0.1" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", "alloy-primitives", "alloy-provider", "alloy-rlp", @@ -1863,7 +1749,7 @@ dependencies = [ name = "kona-plasma" version = "0.0.1" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", "alloy-primitives", "alloy-provider", "alloy-transport-http", @@ -1898,8 +1784,8 @@ dependencies = [ name = "kona-primitives" version = "0.0.1" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", + "alloy-eips 0.1.0", "alloy-primitives", "alloy-rlp", "alloy-sol-types", @@ -1946,12 +1832,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "litemap" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" - [[package]] name = "lock_api" version = "0.4.12" @@ -2001,9 +1881,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] @@ -2169,13 +2049,13 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "op-alloy-consensus" version = "0.1.0" -source = "git+https://github.com/alloy-rs/op-alloy?branch=refcell/re-exports#d581e8a58b57ed008d0fa4368dac324f9a71b304" +source = "git+https://github.com/alloy-rs/op-alloy?branch=refcell/re-exports#01e94e6d4a13ba8a5ee58fbeca1e830edea4730a" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy)", - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy)", + "alloy-consensus 0.1.2", + "alloy-eips 0.1.2", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.1.0 (git+https://github.com/alloy-rs/alloy)", + "alloy-serde 0.1.2", "serde", ] @@ -2526,9 +2406,9 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "reqwest" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" dependencies = [ "base64", "bytes", @@ -2540,6 +2420,7 @@ dependencies = [ "http-body", "http-body-util", "hyper", + "hyper-rustls", "hyper-tls", "hyper-util", "ipnet", @@ -2637,6 +2518,21 @@ dependencies = [ "subtle", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "ripemd" version = "0.1.3" @@ -2729,6 +2625,19 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.23.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + [[package]] name = "rustls-pemfile" version = "2.1.2" @@ -2745,6 +2654,17 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" +[[package]] +name = "rustls-webpki" +version = "0.102.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rusty-fork" version = "0.3.0" @@ -3033,12 +2953,6 @@ dependencies = [ "der", ] -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - [[package]] name = "static_assertions" version = "1.1.0" @@ -3073,10 +2987,10 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "superchain-primitives" version = "0.1.0" -source = "git+https://github.com/ethereum-optimism/superchain-registry?branch=main#645bb0a309970f3cc03ef6ff84670fc35917772a" +source = "git+https://github.com/ethereum-optimism/superchain-registry?branch=main#3fb9d9b4c72183373447571e932ea01f6fef46e9" dependencies = [ - "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", - "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", + "alloy-consensus 0.1.0", + "alloy-eips 0.1.0", "alloy-genesis", "alloy-primitives", "alloy-sol-types", @@ -3122,20 +3036,9 @@ dependencies = [ [[package]] name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - -[[package]] -name = "synstructure" -version = "0.13.1" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" [[package]] name = "system-configuration" @@ -3225,15 +3128,20 @@ dependencies = [ ] [[package]] -name = "tinystr" -version = "0.7.6" +name = "tinyvec" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ - "displaydoc", - "zerovec", + "tinyvec_macros", ] +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.38.0" @@ -3274,6 +3182,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.15" @@ -3456,41 +3375,50 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + [[package]] name = "unsigned-varint" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" -version = "2.5.1" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c25da092f0a868cdf09e8674cd3b7ef3a7d92a24253e663a2fb85e2496de56" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", "percent-encoding", ] -[[package]] -name = "utf16_iter" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" - -[[package]] -name = "utf8_iter" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" - [[package]] name = "utf8parse" version = "0.2.2" @@ -3795,18 +3723,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "write16" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" - -[[package]] -name = "writeable" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" - [[package]] name = "wyz" version = "0.5.1" @@ -3816,30 +3732,6 @@ dependencies = [ "tap", ] -[[package]] -name = "yoke" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" -dependencies = [ - "serde", - "stable_deref_trait", - "yoke-derive", - "zerofrom", -] - -[[package]] -name = "yoke-derive" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", - "synstructure", -] - [[package]] name = "zerocopy" version = "0.7.34" @@ -3860,27 +3752,6 @@ dependencies = [ "syn 2.0.66", ] -[[package]] -name = "zerofrom" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" -dependencies = [ - "zerofrom-derive", -] - -[[package]] -name = "zerofrom-derive" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", - "synstructure", -] - [[package]] name = "zeroize" version = "1.8.1" @@ -3900,25 +3771,3 @@ dependencies = [ "quote", "syn 2.0.66", ] - -[[package]] -name = "zerovec" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2cc8827d6c0994478a15c53f374f46fbd41bea663d809b14744bc42e6b109c" -dependencies = [ - "yoke", - "zerofrom", - "zerovec-derive", -] - -[[package]] -name = "zerovec-derive" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97cf56601ee5052b4417d90c8755c6683473c926039908196cf35d99f893ebe7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] diff --git a/crates/derive/src/lib.rs b/crates/derive/src/lib.rs index 5817f5575..2f7a66e5d 100644 --- a/crates/derive/src/lib.rs +++ b/crates/derive/src/lib.rs @@ -9,7 +9,8 @@ extern crate alloc; mod params; pub use params::{ ChannelID, CHANNEL_ID_LENGTH, CONFIG_UPDATE_EVENT_VERSION_0, CONFIG_UPDATE_TOPIC, - DERIVATION_VERSION_0, FRAME_OVERHEAD, MAX_CHANNEL_BANK_SIZE, MAX_FRAME_LEN, + DERIVATION_VERSION_0, FJORD_MAX_CHANNEL_BANK_SIZE, FJORD_MAX_RLP_BYTES_PER_CHANNEL, + FJORD_MAX_SPAN_BATCH_BYTES, FRAME_OVERHEAD, MAX_CHANNEL_BANK_SIZE, MAX_FRAME_LEN, MAX_RLP_BYTES_PER_CHANNEL, MAX_SPAN_BATCH_BYTES, SEQUENCER_FEE_VAULT_ADDRESS, }; diff --git a/crates/derive/src/params.rs b/crates/derive/src/params.rs index 26fef6304..94c1b7fca 100644 --- a/crates/derive/src/params.rs +++ b/crates/derive/src/params.rs @@ -17,13 +17,26 @@ pub const DERIVATION_VERSION_0: u8 = 0; /// MaxRLPBytesPerChannel because single batch cannot be larger than channel size. pub const MAX_SPAN_BATCH_BYTES: u64 = MAX_RLP_BYTES_PER_CHANNEL; +/// [FJORD_MAX_SPAN_BATCH_BYTES] is the maximum amount of bytes that will be needed +/// to decode every span batch field after the Fjord Hardfork. +/// This value cannot be larger than MaxRLPBytesPerChannel because single batch +/// cannot be larger than channel size. +pub const FJORD_MAX_SPAN_BATCH_BYTES: u64 = FJORD_MAX_RLP_BYTES_PER_CHANNEL; + /// [MAX_RLP_BYTES_PER_CHANNEL] is the maximum amount of bytes that will be read from /// a channel. This limit is set when decoding the RLP. pub const MAX_RLP_BYTES_PER_CHANNEL: u64 = 10_000_000; +/// [FJORD_MAX_RLP_BYTES_PER_CHANNEL] is the maximum amount of bytes that will be read from +/// a channel when the Fjord Hardfork is activated. This limit is set when decoding the RLP. +pub const FJORD_MAX_RLP_BYTES_PER_CHANNEL: u64 = 100_000_000; + /// The maximum size of a channel bank. pub const MAX_CHANNEL_BANK_SIZE: usize = 100_000_000; +/// The maximum size of a channel bank after the Fjord Hardfork. +pub const FJORD_MAX_CHANNEL_BANK_SIZE: usize = 1_000_000_000; + /// [CHANNEL_ID_LENGTH] is the length of the channel ID. pub const CHANNEL_ID_LENGTH: usize = 16; diff --git a/crates/derive/src/types/batch/mod.rs b/crates/derive/src/types/batch/mod.rs index ad7aeddd0..68243d756 100644 --- a/crates/derive/src/types/batch/mod.rs +++ b/crates/derive/src/types/batch/mod.rs @@ -19,7 +19,7 @@ pub use span_batch::{ RawSpanBatch, SpanBatch, SpanBatchBits, SpanBatchEip1559TransactionData, SpanBatchEip2930TransactionData, SpanBatchElement, SpanBatchError, SpanBatchLegacyTransactionData, SpanBatchPayload, SpanBatchPrefix, SpanBatchTransactionData, - SpanBatchTransactions, SpanDecodingError, MAX_SPAN_BATCH_SIZE, + SpanBatchTransactions, SpanDecodingError, }; mod single_batch; @@ -95,7 +95,7 @@ impl Batch { } BatchType::Span => { let mut raw_span_batch = - RawSpanBatch::decode(r).map_err(DecodeError::SpanBatchError)?; + RawSpanBatch::decode(r, cfg).map_err(DecodeError::SpanBatchError)?; let span_batch = raw_span_batch .derive(cfg.block_time, cfg.genesis.l2_time, cfg.l2_chain_id) .map_err(DecodeError::SpanBatchError)?; diff --git a/crates/derive/src/types/batch/single_batch.rs b/crates/derive/src/types/batch/single_batch.rs index eb427e3de..454d37354 100644 --- a/crates/derive/src/types/batch/single_batch.rs +++ b/crates/derive/src/types/batch/single_batch.rs @@ -113,10 +113,11 @@ impl SingleBatch { } // Check if we ran out of sequencer time drift - let max = if let Some(max) = batch_origin.timestamp.checked_add(cfg.max_sequencer_drift) { + let max_drift = cfg.max_sequencer_drift(batch_origin.timestamp); + let max = if let Some(max) = batch_origin.timestamp.checked_add(max_drift) { max } else { - warn!("dropped batch, timestamp exceeds configured max sequencer drift, origin timestamp: {}, max drift: {}", batch_origin.timestamp, cfg.max_sequencer_drift); + warn!("dropped batch, timestamp exceeds configured max sequencer drift, origin timestamp: {}, max drift: {}", batch_origin.timestamp, max_drift); return BatchValidity::Drop; }; diff --git a/crates/derive/src/types/batch/span_batch/batch.rs b/crates/derive/src/types/batch/span_batch/batch.rs index e5efd1c04..5bebadc6c 100644 --- a/crates/derive/src/types/batch/span_batch/batch.rs +++ b/crates/derive/src/types/batch/span_batch/batch.rs @@ -221,8 +221,10 @@ impl SpanBatch { ); return BatchValidity::Drop; } + // Check if we ran out of sequencer time drift - if block_timestamp > l1_origin.timestamp + cfg.max_sequencer_drift { + let max_drift = cfg.max_sequencer_drift(l1_origin.timestamp); + if block_timestamp > l1_origin.timestamp + max_drift { if batch.transactions.is_empty() { // If the sequencer is co-operating by producing an empty batch, // then allow the batch if it was the right thing to do to maintain the L2 time @@ -248,7 +250,7 @@ impl SpanBatch { // allowed to include anything past this point without moving to the next epoch. warn!( "batch exceeded sequencer time drift, sequencer must adopt new L1 origin to include transactions again, max_time: {}", - l1_origin.timestamp + cfg.max_sequencer_drift + l1_origin.timestamp + max_drift ); return BatchValidity::Drop; } diff --git a/crates/derive/src/types/batch/span_batch/bits.rs b/crates/derive/src/types/batch/span_batch/bits.rs index 32cf8fe3d..11ef326f5 100644 --- a/crates/derive/src/types/batch/span_batch/bits.rs +++ b/crates/derive/src/types/batch/span_batch/bits.rs @@ -1,6 +1,9 @@ //! Module for working with span batch bits. -use crate::types::{SpanBatchError, MAX_SPAN_BATCH_SIZE}; +use crate::{ + params::{FJORD_MAX_SPAN_BATCH_BYTES, MAX_SPAN_BATCH_BYTES}, + types::SpanBatchError, +}; use alloc::{vec, vec::Vec}; use alloy_rlp::Buf; use anyhow::Result; @@ -31,10 +34,19 @@ impl From for Vec { impl SpanBatchBits { /// Decodes a standard span-batch bitlist from a reader. /// The bitlist is encoded as big-endian integer, left-padded with zeroes to a multiple of 8 - /// bits. The encoded bitlist cannot be longer than [MAX_SPAN_BATCH_SIZE]. - pub fn decode(b: &mut &[u8], bit_length: usize) -> Result { + /// bits. The encoded bitlist cannot be longer than [MAX_SPAN_BATCH_BYTES]. + pub fn decode( + b: &mut &[u8], + bit_length: usize, + is_fjord_active: bool, + ) -> Result { let buffer_len = bit_length / 8 + if bit_length % 8 != 0 { 1 } else { 0 }; - if buffer_len > MAX_SPAN_BATCH_SIZE { + let max_bytes = if is_fjord_active { + FJORD_MAX_SPAN_BATCH_BYTES as usize + } else { + MAX_SPAN_BATCH_BYTES as usize + }; + if buffer_len > max_bytes { return Err(SpanBatchError::TooBigSpanBatchSize); } @@ -59,11 +71,13 @@ impl SpanBatchBits { /// Encodes a standard span-batch bitlist. /// The bitlist is encoded as big-endian integer, left-padded with zeroes to a multiple of 8 - /// bits. The encoded bitlist cannot be longer than [MAX_SPAN_BATCH_SIZE]. + /// bits. The encoded bitlist cannot be longer than [MAX_SPAN_BATCH_BYTES] or + /// [FJORD_MAX_SPAN_BATCH_BYTES] if fjord is active. pub fn encode( w: &mut Vec, bit_length: usize, bits: &SpanBatchBits, + is_fjord_active: bool, ) -> Result<(), SpanBatchError> { if bits.bit_len() > bit_length { return Err(SpanBatchError::BitfieldTooLong); @@ -72,7 +86,12 @@ impl SpanBatchBits { // Round up, ensure enough bytes when number of bits is not a multiple of 8. // Alternative of (L+7)/8 is not overflow-safe. let buf_len = bit_length / 8 + if bit_length % 8 != 0 { 1 } else { 0 }; - if buf_len > MAX_SPAN_BATCH_SIZE { + let max_bytes = if is_fjord_active { + FJORD_MAX_SPAN_BATCH_BYTES as usize + } else { + MAX_SPAN_BATCH_BYTES as usize + }; + if buf_len > max_bytes { return Err(SpanBatchError::TooBigSpanBatchSize); } let mut buf = vec![0; buf_len]; @@ -174,9 +193,9 @@ mod test { #[test] fn test_encode_decode_roundtrip_span_bitlist(vec in vec(any::(), 0..5096)) { let bits = SpanBatchBits(vec); - assert_eq!(SpanBatchBits::decode(&mut bits.as_ref(), bits.0.len() * 8).unwrap(), bits); + assert_eq!(SpanBatchBits::decode(&mut bits.as_ref(), bits.0.len() * 8, false).unwrap(), bits); let mut encoded = Vec::new(); - SpanBatchBits::encode(&mut encoded, bits.0.len() * 8, &bits).unwrap(); + SpanBatchBits::encode(&mut encoded, bits.0.len() * 8, &bits, false).unwrap(); assert_eq!(encoded, bits.0); } diff --git a/crates/derive/src/types/batch/span_batch/mod.rs b/crates/derive/src/types/batch/span_batch/mod.rs index c26605848..726417280 100644 --- a/crates/derive/src/types/batch/span_batch/mod.rs +++ b/crates/derive/src/types/batch/span_batch/mod.rs @@ -10,13 +10,6 @@ //! txs = contract_creation_bits ++ y_parity_bits ++ tx_sigs ++ tx_tos ++ tx_datas ++ tx_nonces ++ tx_gases ++ protected_bits //! ``` -use crate::MAX_RLP_BYTES_PER_CHANNEL; - -/// The maximum amount of bytes that will be needed to decode every span -/// batch field. This value cannot be larger than [MAX_RLP_BYTES_PER_CHANNEL] -/// because single batch cannot be larger than channel size. -pub const MAX_SPAN_BATCH_SIZE: usize = MAX_RLP_BYTES_PER_CHANNEL as usize; - mod batch; pub use batch::SpanBatch; diff --git a/crates/derive/src/types/batch/span_batch/payload.rs b/crates/derive/src/types/batch/span_batch/payload.rs index e0eb57e7b..8ed0dd405 100644 --- a/crates/derive/src/types/batch/span_batch/payload.rs +++ b/crates/derive/src/types/batch/span_batch/payload.rs @@ -1,7 +1,8 @@ //! Raw Span Batch Payload -use crate::types::{ - SpanBatchBits, SpanBatchError, SpanBatchTransactions, SpanDecodingError, MAX_SPAN_BATCH_SIZE, +use crate::{ + params::{FJORD_MAX_SPAN_BATCH_BYTES, MAX_SPAN_BATCH_BYTES}, + types::{SpanBatchBits, SpanBatchError, SpanBatchTransactions, SpanDecodingError}, }; use alloc::vec::Vec; @@ -21,36 +22,58 @@ pub struct SpanBatchPayload { impl SpanBatchPayload { /// Decodes a [SpanBatchPayload] from a reader. - pub fn decode_payload(r: &mut &[u8]) -> Result { + pub fn decode_payload(r: &mut &[u8], is_fjord_active: bool) -> Result { let mut payload = Self::default(); - payload.decode_block_count(r)?; - payload.decode_origin_bits(r)?; - payload.decode_block_tx_counts(r)?; - payload.decode_txs(r)?; + payload.decode_block_count(r, is_fjord_active)?; + payload.decode_origin_bits(r, is_fjord_active)?; + payload.decode_block_tx_counts(r, is_fjord_active)?; + payload.decode_txs(r, is_fjord_active)?; Ok(payload) } /// Encodes a [SpanBatchPayload] into a writer. - pub fn encode_payload(&self, w: &mut Vec) -> Result<(), SpanBatchError> { + pub fn encode_payload( + &self, + w: &mut Vec, + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { self.encode_block_count(w); - self.encode_origin_bits(w)?; + self.encode_origin_bits(w, is_fjord_active)?; self.encode_block_tx_counts(w); - self.encode_txs(w) + self.encode_txs(w, is_fjord_active) } /// Decodes the origin bits from a reader. - pub fn decode_origin_bits(&mut self, r: &mut &[u8]) -> Result<(), SpanBatchError> { - self.origin_bits = SpanBatchBits::decode(r, self.block_count as usize)?; + pub fn decode_origin_bits( + &mut self, + r: &mut &[u8], + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { + self.origin_bits = SpanBatchBits::decode(r, self.block_count as usize, is_fjord_active)?; Ok(()) } + /// Returns the max span batch size based on the Fjord hardfork. + pub fn max_span_batch_size(&self, is_fjord_active: bool) -> usize { + if is_fjord_active { + FJORD_MAX_SPAN_BATCH_BYTES as usize + } else { + MAX_SPAN_BATCH_BYTES as usize + } + } + /// Decode a block count from a reader. - pub fn decode_block_count(&mut self, r: &mut &[u8]) -> Result<(), SpanBatchError> { + pub fn decode_block_count( + &mut self, + r: &mut &[u8], + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { let (block_count, remaining) = unsigned_varint::decode::u64(r) .map_err(|_| SpanBatchError::Decoding(SpanDecodingError::BlockCount))?; // The number of transactions in a single L2 block cannot be greater than - // [MAX_SPAN_BATCH_SIZE]. - if block_count as usize > MAX_SPAN_BATCH_SIZE { + // [MAX_SPAN_BATCH_BYTES] or [FJORD_MAX_SPAN_BATCH_BYTES] if Fjord is active. + let max_span_batch_size = self.max_span_batch_size(is_fjord_active); + if block_count as usize > max_span_batch_size { return Err(SpanBatchError::TooBigSpanBatchSize); } if block_count == 0 { @@ -62,7 +85,11 @@ impl SpanBatchPayload { } /// Decode block transaction counts from a reader. - pub fn decode_block_tx_counts(&mut self, r: &mut &[u8]) -> Result<(), SpanBatchError> { + pub fn decode_block_tx_counts( + &mut self, + r: &mut &[u8], + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { // Initially allocate the vec with the block count, to reduce re-allocations in the first // few blocks. let mut block_tx_counts = Vec::with_capacity(self.block_count as usize); @@ -72,9 +99,10 @@ impl SpanBatchPayload { .map_err(|_| SpanBatchError::Decoding(SpanDecodingError::BlockTxCounts))?; // The number of transactions in a single L2 block cannot be greater than - // [MAX_SPAN_BATCH_SIZE]. Every transaction will take at least a single - // byte. - if block_tx_count as usize > MAX_SPAN_BATCH_SIZE { + // [MAX_SPAN_BATCH_BYTES] or [FJORD_MAX_SPAN_BATCH_BYTES] if Fjord is active. + // Every transaction will take at least a single byte. + let max_span_batch_size = self.max_span_batch_size(is_fjord_active); + if block_tx_count as usize > max_span_batch_size { return Err(SpanBatchError::TooBigSpanBatchSize); } block_tx_counts.push(block_tx_count); @@ -85,7 +113,11 @@ impl SpanBatchPayload { } /// Decode transactions from a reader. - pub fn decode_txs(&mut self, r: &mut &[u8]) -> Result<(), SpanBatchError> { + pub fn decode_txs( + &mut self, + r: &mut &[u8], + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { if self.block_tx_counts.is_empty() { return Err(SpanBatchError::EmptySpanBatch); } @@ -96,18 +128,23 @@ impl SpanBatchPayload { })?; // The total number of transactions in a span batch cannot be greater than - // [MAX_SPAN_BATCH_SIZE]. - if total_block_tx_count as usize > MAX_SPAN_BATCH_SIZE { + // [MAX_SPAN_BATCH_BYTES] or [FJORD_MAX_SPAN_BATCH_BYTES] if Fjord is active. + let max_span_batch_size = self.max_span_batch_size(is_fjord_active); + if total_block_tx_count as usize > max_span_batch_size { return Err(SpanBatchError::TooBigSpanBatchSize); } self.txs.total_block_tx_count = total_block_tx_count; - self.txs.decode(r)?; + self.txs.decode(r, is_fjord_active)?; Ok(()) } /// Encode the origin bits into a writer. - pub fn encode_origin_bits(&self, w: &mut Vec) -> Result<(), SpanBatchError> { - SpanBatchBits::encode(w, self.block_count as usize, &self.origin_bits) + pub fn encode_origin_bits( + &self, + w: &mut Vec, + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { + SpanBatchBits::encode(w, self.block_count as usize, &self.origin_bits, is_fjord_active) } /// Encode the block count into a writer. @@ -126,7 +163,96 @@ impl SpanBatchPayload { } /// Encode the transactions into a writer. - pub fn encode_txs(&self, w: &mut Vec) -> Result<(), SpanBatchError> { - self.txs.encode(w) + pub fn encode_txs(&self, w: &mut Vec, is_fjord_active: bool) -> Result<(), SpanBatchError> { + self.txs.encode(w, is_fjord_active) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use alloc::vec; + + #[test] + fn test_decode_origin_bits() { + let block_count = 10; + let encoded = vec![2; block_count / 8 + 1]; + let mut payload = + SpanBatchPayload { block_count: block_count as u64, ..Default::default() }; + payload.decode_origin_bits(&mut encoded.as_slice(), false).unwrap(); + assert_eq!(payload.origin_bits, SpanBatchBits(vec![2; block_count / 8 + 1])); + } + + #[test] + fn test_zero_block_count() { + let mut u64_varint_buf = [0; 10]; + let mut encoded = unsigned_varint::encode::u64(0, &mut u64_varint_buf); + let mut payload = SpanBatchPayload::default(); + let err = payload.decode_block_count(&mut encoded, false).unwrap_err(); + assert_eq!(err, SpanBatchError::EmptySpanBatch); + } + + #[test] + fn test_decode_block_count_pre_fjord() { + let block_count = MAX_SPAN_BATCH_BYTES; + let mut u64_varint_buf = [0; 10]; + let mut encoded = unsigned_varint::encode::u64(block_count, &mut u64_varint_buf); + let mut payload = SpanBatchPayload::default(); + payload.decode_block_count(&mut encoded, false).unwrap(); + assert_eq!(payload.block_count, block_count); + } + + #[test] + fn test_decode_block_count_pre_fjord_errors() { + let block_count = MAX_SPAN_BATCH_BYTES + 1; + let mut u64_varint_buf = [0; 10]; + let mut encoded = unsigned_varint::encode::u64(block_count, &mut u64_varint_buf); + let mut payload = SpanBatchPayload::default(); + let err = payload.decode_block_count(&mut encoded, false).unwrap_err(); + assert_eq!(err, SpanBatchError::TooBigSpanBatchSize); + } + + #[test] + fn test_decode_block_count_post_fjord() { + let block_count = FJORD_MAX_SPAN_BATCH_BYTES; + let mut u64_varint_buf = [0; 10]; + let mut encoded = unsigned_varint::encode::u64(block_count, &mut u64_varint_buf); + let mut payload = SpanBatchPayload::default(); + payload.decode_block_count(&mut encoded, true).unwrap(); + assert_eq!(payload.block_count, block_count); + } + + #[test] + fn test_decode_block_count_post_fjord_errors() { + let block_count = FJORD_MAX_SPAN_BATCH_BYTES + 1; + let mut u64_varint_buf = [0; 10]; + let mut encoded = unsigned_varint::encode::u64(block_count, &mut u64_varint_buf); + let mut payload = SpanBatchPayload::default(); + let err = payload.decode_block_count(&mut encoded, true).unwrap_err(); + assert_eq!(err, SpanBatchError::TooBigSpanBatchSize); + } + + #[test] + fn test_decode_block_tx_counts() { + let block_count = 2; + let mut u64_varint_buf = [0; 10]; + let mut encoded = unsigned_varint::encode::u64(block_count, &mut u64_varint_buf); + let mut payload = SpanBatchPayload::default(); + payload.decode_block_count(&mut encoded, false).unwrap(); + let mut r: Vec = Vec::new(); + for _ in 0..2 { + let mut buf = [0u8; 10]; + let encoded = unsigned_varint::encode::u64(2, &mut buf); + r.append(&mut encoded.to_vec()); + } + payload.decode_block_tx_counts(&mut r.as_slice(), false).unwrap(); + assert_eq!(payload.block_tx_counts, vec![2, 2]); + } + + #[test] + fn test_max_span_batch_size() { + let payload = SpanBatchPayload::default(); + assert_eq!(payload.max_span_batch_size(false), MAX_SPAN_BATCH_BYTES as usize); + assert_eq!(payload.max_span_batch_size(true), FJORD_MAX_SPAN_BATCH_BYTES as usize); } } diff --git a/crates/derive/src/types/batch/span_batch/prefix.rs b/crates/derive/src/types/batch/span_batch/prefix.rs index 350082edc..b37fa8ca9 100644 --- a/crates/derive/src/types/batch/span_batch/prefix.rs +++ b/crates/derive/src/types/batch/span_batch/prefix.rs @@ -1,6 +1,6 @@ //! Raw Span Batch Prefix -use crate::types::{SpanBatchError, SpanDecodingError}; +use crate::types::{RollupConfig, SpanBatchError, SpanDecodingError}; use alloc::vec::Vec; use alloy_primitives::FixedBytes; @@ -28,6 +28,11 @@ impl SpanBatchPrefix { Ok(prefix) } + /// Returns if the Fjord hardfork is active based on the relative timestamp of the span batch. + pub fn is_fjord_active(&self, cfg: &RollupConfig) -> bool { + cfg.is_fjord_active(self.rel_timestamp + cfg.genesis.l2_time) + } + /// Decodes the relative timestamp from a reader. pub fn decode_rel_timestamp(&mut self, r: &mut &[u8]) -> Result<(), SpanBatchError> { let (rel_timestamp, remaining) = unsigned_varint::decode::u64(r) @@ -76,10 +81,21 @@ impl SpanBatchPrefix { #[cfg(test)] mod test { - use super::SpanBatchPrefix; + use super::*; use alloc::vec::Vec; use alloy_primitives::address; + #[test] + fn test_is_fjord_active() { + let mut cfg = RollupConfig::default(); + let prefix = SpanBatchPrefix { rel_timestamp: 10, ..Default::default() }; + assert!(!prefix.is_fjord_active(&cfg)); + cfg.fjord_time = Some(11); + assert!(!prefix.is_fjord_active(&cfg)); + cfg.fjord_time = Some(9); + assert!(prefix.is_fjord_active(&cfg)); + } + #[test] fn test_span_batch_prefix_encoding_roundtrip() { let expected = SpanBatchPrefix { diff --git a/crates/derive/src/types/batch/span_batch/raw.rs b/crates/derive/src/types/batch/span_batch/raw.rs index 40decbb8f..997c6065f 100644 --- a/crates/derive/src/types/batch/span_batch/raw.rs +++ b/crates/derive/src/types/batch/span_batch/raw.rs @@ -1,7 +1,7 @@ //! Raw Span Batch use crate::types::{ - BatchType, RawTransaction, SpanBatchElement, SpanBatchPayload, SpanBatchPrefix, + BatchType, RawTransaction, RollupConfig, SpanBatchElement, SpanBatchPayload, SpanBatchPrefix, SpanDecodingError, }; use alloc::{vec, vec::Vec}; @@ -57,16 +57,23 @@ impl RawSpanBatch { self.prefix.rel_timestamp } + fn is_fjord_active(prefix: &SpanBatchPrefix, cfg: &RollupConfig) -> bool { + let timestamp = cfg.genesis.l2_time + prefix.rel_timestamp; + cfg.is_fjord_active(timestamp) + } + /// Encodes the [RawSpanBatch] into a writer. - pub fn encode(&self, w: &mut Vec) -> Result<(), SpanBatchError> { + pub fn encode(&self, w: &mut Vec, cfg: &RollupConfig) -> Result<(), SpanBatchError> { self.prefix.encode_prefix(w); - self.payload.encode_payload(w) + let is_fjord_active = RawSpanBatch::is_fjord_active(&self.prefix, cfg); + self.payload.encode_payload(w, is_fjord_active) } /// Decodes the [RawSpanBatch] from a reader.] - pub fn decode(r: &mut &[u8]) -> Result { + pub fn decode(r: &mut &[u8], cfg: &RollupConfig) -> Result { let prefix = SpanBatchPrefix::decode_prefix(r)?; - let payload = SpanBatchPayload::decode_payload(r)?; + let is_fjord_active = RawSpanBatch::is_fjord_active(&prefix, cfg); + let payload = SpanBatchPayload::decode_payload(r, is_fjord_active)?; Ok(Self { prefix, payload }) } @@ -133,7 +140,7 @@ impl RawSpanBatch { #[cfg(test)] mod test { extern crate std; - use super::{RawSpanBatch, SpanBatch, SpanBatchElement}; + use super::{RawSpanBatch, RollupConfig, SpanBatch, SpanBatchElement}; use alloc::{vec, vec::Vec}; use alloy_primitives::FixedBytes; @@ -173,11 +180,13 @@ mod test { fn test_decode_encode_raw_span_batch() { // Load in the raw span batch from the `op-node` derivation pipeline implementation. let raw_span_batch_hex = include_bytes!("../../../../testdata/raw_batch.hex"); - let mut raw_span_batch = RawSpanBatch::decode(&mut raw_span_batch_hex.as_slice()).unwrap(); + let cfg = RollupConfig::default(); + let mut raw_span_batch = + RawSpanBatch::decode(&mut raw_span_batch_hex.as_slice(), &cfg).unwrap(); raw_span_batch.payload.txs.recover_v(981).unwrap(); let mut encoding_buf = Vec::new(); - raw_span_batch.encode(&mut encoding_buf).unwrap(); + raw_span_batch.encode(&mut encoding_buf, &cfg).unwrap(); assert_eq!(encoding_buf, raw_span_batch_hex); } } diff --git a/crates/derive/src/types/batch/span_batch/transactions.rs b/crates/derive/src/types/batch/span_batch/transactions.rs index abb73e7c6..7dbe5b1c2 100644 --- a/crates/derive/src/types/batch/span_batch/transactions.rs +++ b/crates/derive/src/types/batch/span_batch/transactions.rs @@ -41,46 +41,73 @@ pub struct SpanBatchTransactions { impl SpanBatchTransactions { /// Encodes the [SpanBatchTransactions] into a writer. - pub fn encode(&self, w: &mut Vec) -> Result<(), SpanBatchError> { - self.encode_contract_creation_bits(w)?; - self.encode_y_parity_bits(w)?; + pub fn encode(&self, w: &mut Vec, is_fjord_active: bool) -> Result<(), SpanBatchError> { + self.encode_contract_creation_bits(w, is_fjord_active)?; + self.encode_y_parity_bits(w, is_fjord_active)?; self.encode_tx_sigs_rs(w)?; self.encode_tx_tos(w)?; self.encode_tx_datas(w)?; self.encode_tx_nonces(w)?; self.encode_tx_gases(w)?; - self.encode_protected_bits(w)?; + self.encode_protected_bits(w, is_fjord_active)?; Ok(()) } /// Decodes the [SpanBatchTransactions] from a reader. - pub fn decode(&mut self, r: &mut &[u8]) -> Result<(), SpanBatchError> { - self.decode_contract_creation_bits(r)?; - self.decode_y_parity_bits(r)?; + pub fn decode(&mut self, r: &mut &[u8], is_fjord_active: bool) -> Result<(), SpanBatchError> { + self.decode_contract_creation_bits(r, is_fjord_active)?; + self.decode_y_parity_bits(r, is_fjord_active)?; self.decode_tx_sigs_rs(r)?; self.decode_tx_tos(r)?; self.decode_tx_datas(r)?; self.decode_tx_nonces(r)?; self.decode_tx_gases(r)?; - self.decode_protected_bits(r)?; + self.decode_protected_bits(r, is_fjord_active)?; Ok(()) } /// Encode the contract creation bits into a writer. - pub fn encode_contract_creation_bits(&self, w: &mut Vec) -> Result<(), SpanBatchError> { - SpanBatchBits::encode(w, self.total_block_tx_count as usize, &self.contract_creation_bits)?; + pub fn encode_contract_creation_bits( + &self, + w: &mut Vec, + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { + SpanBatchBits::encode( + w, + self.total_block_tx_count as usize, + &self.contract_creation_bits, + is_fjord_active, + )?; Ok(()) } /// Encode the protected bits into a writer. - pub fn encode_protected_bits(&self, w: &mut Vec) -> Result<(), SpanBatchError> { - SpanBatchBits::encode(w, self.legacy_tx_count as usize, &self.protected_bits)?; + pub fn encode_protected_bits( + &self, + w: &mut Vec, + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { + SpanBatchBits::encode( + w, + self.legacy_tx_count as usize, + &self.protected_bits, + is_fjord_active, + )?; Ok(()) } /// Encode the y parity bits into a writer. - pub fn encode_y_parity_bits(&self, w: &mut Vec) -> Result<(), SpanBatchError> { - SpanBatchBits::encode(w, self.total_block_tx_count as usize, &self.y_parity_bits)?; + pub fn encode_y_parity_bits( + &self, + w: &mut Vec, + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { + SpanBatchBits::encode( + w, + self.total_block_tx_count as usize, + &self.y_parity_bits, + is_fjord_active, + )?; Ok(()) } @@ -130,20 +157,35 @@ impl SpanBatchTransactions { } /// Decode the contract creation bits from a reader. - pub fn decode_contract_creation_bits(&mut self, r: &mut &[u8]) -> Result<(), SpanBatchError> { - self.contract_creation_bits = SpanBatchBits::decode(r, self.total_block_tx_count as usize)?; + pub fn decode_contract_creation_bits( + &mut self, + r: &mut &[u8], + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { + self.contract_creation_bits = + SpanBatchBits::decode(r, self.total_block_tx_count as usize, is_fjord_active)?; Ok(()) } /// Decode the protected bits from a reader. - pub fn decode_protected_bits(&mut self, r: &mut &[u8]) -> Result<(), SpanBatchError> { - self.protected_bits = SpanBatchBits::decode(r, self.legacy_tx_count as usize)?; + pub fn decode_protected_bits( + &mut self, + r: &mut &[u8], + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { + self.protected_bits = + SpanBatchBits::decode(r, self.legacy_tx_count as usize, is_fjord_active)?; Ok(()) } /// Decode the y parity bits from a reader. - pub fn decode_y_parity_bits(&mut self, r: &mut &[u8]) -> Result<(), SpanBatchError> { - self.y_parity_bits = SpanBatchBits::decode(r, self.total_block_tx_count as usize)?; + pub fn decode_y_parity_bits( + &mut self, + r: &mut &[u8], + is_fjord_active: bool, + ) -> Result<(), SpanBatchError> { + self.y_parity_bits = + SpanBatchBits::decode(r, self.total_block_tx_count as usize, is_fjord_active)?; Ok(()) } diff --git a/crates/derive/src/types/mod.rs b/crates/derive/src/types/mod.rs index 64f2385fc..6aa8b8f78 100644 --- a/crates/derive/src/types/mod.rs +++ b/crates/derive/src/types/mod.rs @@ -15,7 +15,6 @@ pub use batch::{ SpanBatchBits, SpanBatchEip1559TransactionData, SpanBatchEip2930TransactionData, SpanBatchElement, SpanBatchError, SpanBatchLegacyTransactionData, SpanBatchPayload, SpanBatchPrefix, SpanBatchTransactionData, SpanBatchTransactions, SpanDecodingError, - MAX_SPAN_BATCH_SIZE, }; /// Re-export eip4844 primitives.