From 820b9f0b237516fa15ef9846990963489f139277 Mon Sep 17 00:00:00 2001 From: Pia Date: Thu, 1 Feb 2024 17:48:53 +0800 Subject: [PATCH 1/4] feat: block header compiler --- Cargo.lock | 14 ++++ Cargo.toml | 2 + crates/common/Cargo.toml | 1 + crates/common/src/block/header.rs | 68 ++++++++++++++++++ crates/common/tests/header.rs | 35 ++++++++++ crates/fetcher/src/example_data.rs | 19 +++++ crates/fetcher/src/lib.rs | 3 +- crates/fetcher/src/memoizer.rs | 80 ++++++++++++++++++++++ crates/types/Cargo.toml | 1 + crates/types/src/compiler/block_sampled.rs | 23 ++++--- crates/types/src/datalake/base.rs | 2 +- crates/types/src/datalake/block_sampled.rs | 11 ++- crates/types/tests/block_sampled.rs | 11 ++- 13 files changed, 258 insertions(+), 12 deletions(-) create mode 100644 crates/common/tests/header.rs create mode 100644 crates/fetcher/src/example_data.rs create mode 100644 crates/fetcher/src/memoizer.rs diff --git a/Cargo.lock b/Cargo.lock index 44199615..d0219484 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,10 +74,22 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d58d9f5da7b40e9bfff0b7e7816700be4019db97d4b6359fe7f94a9e22e42ac" dependencies = [ + "alloy-rlp-derive", "arrayvec", "bytes", ] +[[package]] +name = "alloy-rlp-derive" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a047897373be4bbb0224c1afdabca92648dc57a9c9ef6e7b0be3aff7a859c83" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "alloy-sol-macro" version = "0.6.2" @@ -490,6 +502,7 @@ name = "common" version = "0.1.0" dependencies = [ "alloy-primitives", + "alloy-rlp", "anyhow", ] @@ -1661,6 +1674,7 @@ dependencies = [ "alloy-primitives", "anyhow", "common", + "fetcher", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4460730c..68359367 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,9 @@ members = [ common = { version = "0.1.0", path = "crates/common" } types = { version = "0.1.0", path = "crates/types" } decoder = { version = "0.1.0", path = "crates/decoder" } +fetcher = { version = "0.1.0", path = "crates/fetcher" } tokio = { version = "1", features = ["full"] } alloy-dyn-abi = "0.6.2" alloy-primitives = "0.6.2" +alloy-rlp = { version = "0.3.4", features = ["derive"] } anyhow = "1.0.79" diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 7146d858..187239b2 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -5,4 +5,5 @@ edition = "2021" [dependencies] alloy-primitives = { workspace = true } +alloy-rlp = { workspace = true } anyhow = { workspace = true } diff --git a/crates/common/src/block/header.rs b/crates/common/src/block/header.rs index d069c778..689f3c7d 100644 --- a/crates/common/src/block/header.rs +++ b/crates/common/src/block/header.rs @@ -1,5 +1,8 @@ use std::str::FromStr; +use alloy_primitives::hex::{encode, FromHex}; +use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable}; + #[derive(Debug)] pub enum HeaderField { ParentHash, @@ -18,6 +21,7 @@ pub enum HeaderField { MixHash, Nonce, BaseFeePerGas, + WithdrawalsRoot, } impl HeaderField { @@ -39,6 +43,7 @@ impl HeaderField { 13 => Some(HeaderField::MixHash), 14 => Some(HeaderField::Nonce), 15 => Some(HeaderField::BaseFeePerGas), + 16 => Some(HeaderField::WithdrawalsRoot), _ => None, } } @@ -61,6 +66,7 @@ impl HeaderField { HeaderField::MixHash => Some(13), HeaderField::Nonce => Some(14), HeaderField::BaseFeePerGas => Some(15), + HeaderField::WithdrawalsRoot => Some(16), } } @@ -82,6 +88,7 @@ impl HeaderField { HeaderField::MixHash => "MIX_HASH", HeaderField::Nonce => "NONCE", HeaderField::BaseFeePerGas => "BASE_FEE_PER_GAS", + HeaderField::WithdrawalsRoot => "WITHDRAWALS_ROOT", } } } @@ -107,7 +114,68 @@ impl FromStr for HeaderField { "MIX_HASH" => Ok(HeaderField::MixHash), "NONCE" => Ok(HeaderField::Nonce), "BASE_FEE_PER_GAS" => Ok(HeaderField::BaseFeePerGas), + "WITHDRAWALS_ROOT" => Ok(HeaderField::WithdrawalsRoot), _ => Err(()), } } } + +#[derive(Debug, RlpDecodable, RlpEncodable, PartialEq)] +#[rlp(trailing)] +pub struct BlockHeaderShanghai { + pub parent_hash: String, + pub uncle_hash: String, + pub coinbase: String, + pub state_root: String, + pub transactions_root: String, + pub receipts_root: String, + pub logs_bloom: String, + pub difficulty: u64, + pub number: u64, + pub gas_limit: u64, + pub gas_used: u64, + pub timestamp: u64, + pub extra_data: String, + pub mix_hash: String, + pub nonce: String, + pub base_fee_per_gas: Option, + pub withdrawals_root: Option, +} + +impl BlockHeaderShanghai { + pub fn from_rlp_hexstring(rlp_hexstring: &str) -> Self { + let buffer = Vec::::from_hex(rlp_hexstring).unwrap(); + let rlp_decoded_header = BlockHeaderShanghai::decode(&mut buffer.as_slice()).unwrap(); + rlp_decoded_header + } + + pub fn to_rlp_hexstring(&self) -> String { + let mut buffer = Vec::::new(); + self.encode(&mut buffer); + encode(buffer) + } +} + +pub fn decode_header_field(header_rlp: &str, field: HeaderField) -> String { + let decoded = BlockHeaderShanghai::from_rlp_hexstring(header_rlp); + + match field { + HeaderField::ParentHash => decoded.parent_hash, + HeaderField::OmmerHash => decoded.uncle_hash, + HeaderField::Beneficiary => decoded.coinbase, + HeaderField::StateRoot => decoded.state_root, + HeaderField::TransactionsRoot => decoded.transactions_root, + HeaderField::ReceiptsRoot => decoded.receipts_root, + HeaderField::LogsBloom => decoded.logs_bloom, + HeaderField::Difficulty => decoded.difficulty.to_string(), + HeaderField::Number => decoded.number.to_string(), + HeaderField::GasLimit => decoded.gas_limit.to_string(), + HeaderField::GasUsed => decoded.gas_used.to_string(), + HeaderField::Timestamp => decoded.timestamp.to_string(), + HeaderField::ExtraData => decoded.extra_data, + HeaderField::MixHash => decoded.mix_hash, + HeaderField::Nonce => decoded.nonce, + HeaderField::BaseFeePerGas => decoded.base_fee_per_gas.unwrap_or(0).to_string(), + HeaderField::WithdrawalsRoot => decoded.withdrawals_root.unwrap_or("".to_string()), + } +} diff --git a/crates/common/tests/header.rs b/crates/common/tests/header.rs new file mode 100644 index 00000000..e1328301 --- /dev/null +++ b/crates/common/tests/header.rs @@ -0,0 +1,35 @@ +use common::block::header::BlockHeaderShanghai; + +#[test] +pub fn test_rlp() { + let rlp_hex ="f90475b842307834356164623638346362353435383031396334393632303663313338333839346333363066653936396131303238626134343935356561646661353835636335b842307831646363346465386465633735643761616238356235363762366363643431616433313234353162393438613734313366306131343266643430643439333437aa307862363336613638663833346234643735616639656463356662303133386262343735386564323933b842307831646232333838393233663763373836383062346134366261653732353633373031336437346164373837656335633836316433616465336466383832643831b842307839333538366562356632373831646564333334613261303364313738663431646330366632373164376631666634323965346461366566343264313261373733b842307833363135393037373566656137383537636330343862393332346330336539366632383731393938303363653134343066663165313263356336303038303439b902023078303432303030306132303033303830303030323532303130303561333034303030303839363238303034303231383564633630303134343238303034303038323232313430303031303130313230303435383030326230643838303038303238303034323036383038343038343030343032313038663038313232343632303032343061323034333635313030313039303531633038326130323030383132303432303030303130363034343030393030343430343434343831303030383231303030323830303130363036343063303131343031613830323030303039303333313030303430383234333830343030393430323230313234303830323038323832303430333830313134313035306134613030323038323833323032303530303030663130303538383934303038303030343131303530353132383030323230613230303030303034323237353830303238303839343038303030303230323436303034303033303030303430383030316365303032383234303030303030303261386332343231303030303230303031346133303034303031353032306230343830303032303630383830303030303835303434303234306330363130303031313030323030303030303230303938383030313830303030303838303132386130353034303033323930383163313434303830613034303830303030303480839eb0f68401c9c380836f9a8e8465aa8780b84030783439366336633735366436393665363137343635323034343664366636333732363137343639376136353230343437333734373236393632373537343635b842307863363533653163316365653939303134376634343339373736636333656164366631373565303831393938633333633933646134313635333131326538396365923078303030303030303030303030303030300db842307833396462336639643166653037353665356165663465326630323431616439353765393939653439633938313830396330313834323564303038306636636432".to_string(); + // TODO: we need to figure out with alloy rlp encoding / decoding + //let hex2 = "f9023ca045adb684cb5458019c496206c1383894c360fe969a1028ba44955eadfa585cc5a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b636a68f834b4d75af9edc5fb0138bb4758ed293a01db2388923f7c78680b4a46bae725637013d74ad787ec5c861d3ade3df882d81a093586eb5f2781ded334a2a03d178f41dc06f271d7f1ff429e4da6ef42d12a773a0361590775fea7857cc048b9324c03e96f287199803ce1440ff1e12c5c6008049b901000420000a200308000025201005a30400008962800402185dc600144280040082221400010101200458002b0d88008028004206808408400402108f0812246200240a204365100109051c082a020081204200001060440090044044448100082100028001060640c011401a802000090331000408243804009402201240802082820403801141050a4a00208283202050000f10058894008000411050512800220a200000042275800280894080000202460040030000408001ce00282400000002a8c24210000200014a30040015020b04800020608800000850440240c06100011002000000200988001800000880128a050400329081c144080a040800000480839eb0f68401c9c380836f9a8e8465aa87809f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a0c653e1c1cee990147f4439776cc3ead6f175e081998c33c93da41653112e89ce8800000000000000000da039db3f9d1fe0756e5aef4e2f0241ad957e999e49c981809c018425d0080f6cd2".to_string(); + let header_from_rlp = BlockHeaderShanghai::from_rlp_hexstring(&rlp_hex); + let expected_header = BlockHeaderShanghai { + parent_hash: "0x45adb684cb5458019c496206c1383894c360fe969a1028ba44955eadfa585cc5" + .to_string(), + uncle_hash: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + .to_string(), + coinbase: "0xb636a68f834b4d75af9edc5fb0138bb4758ed293".to_string(), + state_root: "0x1db2388923f7c78680b4a46bae725637013d74ad787ec5c861d3ade3df882d81" + .to_string(), + transactions_root: "0x93586eb5f2781ded334a2a03d178f41dc06f271d7f1ff429e4da6ef42d12a773" + .to_string(), + receipts_root: "0x361590775fea7857cc048b9324c03e96f287199803ce1440ff1e12c5c6008049" + .to_string(), + logs_bloom: "0x0420000a200308000025201005a30400008962800402185dc600144280040082221400010101200458002b0d88008028004206808408400402108f0812246200240a204365100109051c082a020081204200001060440090044044448100082100028001060640c011401a802000090331000408243804009402201240802082820403801141050a4a00208283202050000f10058894008000411050512800220a200000042275800280894080000202460040030000408001ce00282400000002a8c24210000200014a30040015020b04800020608800000850440240c06100011002000000200988001800000880128a050400329081c144080a0408000004".to_string(), + difficulty: 0, + number: 10399990, + gas_limit: 30000000, + gas_used: 7314062, + timestamp: 1705674624, + extra_data: "0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465".to_string(), + mix_hash: "0xc653e1c1cee990147f4439776cc3ead6f175e081998c33c93da41653112e89ce".to_string(), + nonce: "0x0000000000000000".to_string(), + base_fee_per_gas: Some(13), + withdrawals_root: Some("0x39db3f9d1fe0756e5aef4e2f0241ad957e999e49c981809c018425d0080f6cd2".to_string()), + }; + // let header2 = BlockHeaderShanghai::from_rlp_hexstring(&hex2); + assert_eq!(header_from_rlp, expected_header); +} diff --git a/crates/fetcher/src/example_data.rs b/crates/fetcher/src/example_data.rs new file mode 100644 index 00000000..85b33e0c --- /dev/null +++ b/crates/fetcher/src/example_data.rs @@ -0,0 +1,19 @@ +use std::collections::HashMap; + +use crate::memoizer::RlpEncodedValue; + +pub fn get_example_headers() -> HashMap { + let mut headers = HashMap::new(); + headers.insert(10399990, "f90475b842307834356164623638346362353435383031396334393632303663313338333839346333363066653936396131303238626134343935356561646661353835636335b842307831646363346465386465633735643761616238356235363762366363643431616433313234353162393438613734313366306131343266643430643439333437aa307862363336613638663833346234643735616639656463356662303133386262343735386564323933b842307831646232333838393233663763373836383062346134366261653732353633373031336437346164373837656335633836316433616465336466383832643831b842307839333538366562356632373831646564333334613261303364313738663431646330366632373164376631666634323965346461366566343264313261373733b842307833363135393037373566656137383537636330343862393332346330336539366632383731393938303363653134343066663165313263356336303038303439b902023078303432303030306132303033303830303030323532303130303561333034303030303839363238303034303231383564633630303134343238303034303038323232313430303031303130313230303435383030326230643838303038303238303034323036383038343038343030343032313038663038313232343632303032343061323034333635313030313039303531633038326130323030383132303432303030303130363034343030393030343430343434343831303030383231303030323830303130363036343063303131343031613830323030303039303333313030303430383234333830343030393430323230313234303830323038323832303430333830313134313035306134613030323038323833323032303530303030663130303538383934303038303030343131303530353132383030323230613230303030303034323237353830303238303839343038303030303230323436303034303033303030303430383030316365303032383234303030303030303261386332343231303030303230303031346133303034303031353032306230343830303032303630383830303030303835303434303234306330363130303031313030323030303030303230303938383030313830303030303838303132386130353034303033323930383163313434303830613034303830303030303480839eb0f68401c9c380836f9a8e8465aa8780b84030783439366336633735366436393665363137343635323034343664366636333732363137343639376136353230343437333734373236393632373537343635b842307863363533653163316365653939303134376634343339373736636333656164366631373565303831393938633333633933646134313635333131326538396365923078303030303030303030303030303030300db842307833396462336639643166653037353665356165663465326630323431616439353765393939653439633938313830396330313834323564303038306636636432".to_string()); + // headers.insert(10399991, "0xf90237a02ef5bd5264f472d821fb950241aa2bbe83f885fea086b4f58fccb9c9b948adcfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479494750381be1aba0504c666ee1db118f68f0780d4a01fa9a7ad0deb9e4c0762aed5a02a0eb0be12864363eb2f6434ad55454352533ea0e4be7e5ed75566d7ab90c1610d81a8f38f3b56b3c338f211646ae32aebd4e690a0f8973cc47d1dac1a9f71fec14ec19dcde2ad1e6c6b6336e42b1da0322a6c7581b901007432022a09014808001c000b91ab000c408a444206011a6200994018c004101a06d1c003460021145888092814458890000a020092b4e4c0023a3710332c01329252440a050520886880061f020882214f91000e2a64a50a8024444c832446718206009dc60020a0a7e158a104002800080884d0041085084aa83010012ae2c88210a39401140080b04100004b200700902184c3ea95a1c8401532f944820040276e5b884c9b3290120009408b0604a5a401281a41ec508000c2886b280a488a2208d0222800a801080622b00a7602091c2000430481101002800c32400862623110400100400219bc010708a1008080320416001a88804109ce05041097041080839eb0f78401c9c38084012ad0678465aa879899d883010d0a846765746888676f312e32312e36856c696e7578a04d3c8cca805e07a07e9cc74a0b5891629f26bec5ed54b74867ff0f77bcc994b38800000000000000000da002a352293855b89564efc797e98f05368f9d42d0a99be7dadf6d45165eaaf0f0".to_string()); + // headers.insert(10399992, "0xf90236a0000f7814e0558a13469620a059eff4510844d8129d2bd0f814bcbae62adff515a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794455e5aa18469bc6ccef49594645666c587a3a71ba06ef1804556d1e997392ae8ee19e4abf930fed4ecd7199f6f28e5450cae49835da0e96e520730416715728f451bc12e7e348d08c6dc84e42716833dc36b0c6b49c4a0624b8ee1e6e66f17ae42630abeb8fd1cc69c91b3d9bb9c83d6ef2376f8620dc2b9010004000008890100000204208001a10000400210440400004808040410000410420050006000002000180013001440840000020800806040200010051002240210800205004440208000002209402000098200100020042108001004040500002080020000320000800061408000d008090800440004100000482a0010014420008020830401840000800000000f000000000100004210208041051224430000008300008144021000080109e00004042524810800010028200400802a20200000420080060800a00100032010041203081000000200802200000004301010620101100000000010080c000300028804004000000012888000002800002085020080839eb0f88401c9c380836fba078465aa87a499d883010d0a846765746888676f312e32312e36856c696e7578a05cdb41adf931d8a929aaf09f6a825be65513d809e167144bcbec60eabf7922a58800000000000000000ea0a4ad1832a56ef60e6b49323c6ce4221e5524d11aca2c35623b324d094b5541f0".to_string()); + // headers.insert(10399993, "0xf90237a0a4928d67f0c66d5c62a44d2c180badca94ea2aa3bf91f25f97d5a5039d9b812ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479462c8bcec31584187f69295294fbb7620d2e0cd72a01b9b14e361177b5fcde1e8b1cb95b07dccd1bcab35157958e1b5bc4a4b1ad9e3a09897276962157a75b5ddf8b44cd46c1821e36c4fc733ad9706f8f3a14d2778bea066378d7d59d4d3800f512077e63e054274841411de3909a25aeb098bbc342fb1b90100842100082001400010142e0a8ba10100400820420002083004b110100004102286902224048461001800016884042088806078049220420406001318462400301012265a850e008044000a0a800082204481000032c6011110408400cb20682480020002061010d00148408020100801181885c0461406005008001600002040821442040004804050400042038001414402840b423480c8401310f040800000ca000680940030506b0889400104060b96910a0011c04008018600c3140049004208c16220014001000220b0185600080040401006a000100000080210086200ad1048008a1480088c00000020008e02000010009a88015044800240c48cc00480839eb0f98401c9c380836fea688465aa87b09ad983010d09846765746889676f312e32302e3133856c696e7578a0d5c0c49915e6584d0749c52b49716a3fb4b552a0e837253b037498584686036a8800000000000000000ea00ba5704b8908ebfc357a7d939e111750e5e489d7480e8f8f086bf7cc9a256bd4".to_string()); + // headers.insert(10399994, "0xf90236a089a45b58b24fb782ee50cf5b8d116934acaec3e67527713d33cfb114f1736dcfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f36f155486299ecaff2d4f5160ed5114c1f66000a09d2cd16c62f80864a2599183efd95156b58791ebf7464594385daeb202e57dcfa015fb8fd8d2d91227211208562f9bbc905c6cd09be95187ff7f455d5b472e6bcda0899e91c5a0c5082e5275f11d5c7ae263d39b605cd0023e249177572d4088c247b901000621180a20014ac0601c004681a1105c91d844c22600185307110510060c119206908402064021405c0019a804448ba22842c67092a0634103109700522c6432104e442ae40d80d96910025e028c80a146010001b26c818580048684912548608116008886760a9036409ac080920801081884e824100548543a52b4c08e30c582b203840941215030673130435001918401de03ef1d40c8504572706022116003a014ec65283e1003008942880084212e09080201c0408201c1486f6880d8015218d042341a0a50004223b00c570209060060220088431001c0080640026240511c4000080000698901d2b8a840801c2a0154185ec8c04148c800141004021080839eb0fa8401c9c38083fe4eaf8465aa87d499d883010d0a846765746888676f312e32312e36856c696e7578a05625df0bccfd09cb146fc3a90fd7e8befbb1c8476ad0ad7345638c93538f65d78800000000000000000ea06e3d4e738fdb774f4c872d5187168f26df7d71a3086b35692d26c6a3bf7ce734".to_string()); + // headers.insert(10399995, "0xf90236a0c69a0d458b1ea41c72d0a9a43f45cd947e681e7a7c33e1dc3a0fd8abc0f82d0fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794455e5aa18469bc6ccef49594645666c587a3a71ba0094793b132c386d1ca31f83204a5ffa2ccef4edcc3fbffef39153aa52a1f31a0a0dee897271be94192b76eb37c54417c529f095ff1f32f6cbbe4695641855d3feea0456bd3352507c5f327f04f9c63244569af5d17ab5b576693e868a309c32cc54ab901000400000a30014a8000140242012100088000080100028800021000180404000a009000000c100100180041000004008000008004920041000020110002a0403014020042000420084410000b00000008442101082048251000002600010002340402010402000280004100a400001880280884c04014000104002094040820008a16021000000100104610104b0004080001010040108080504120105004000006a00000041010100020894010000010260a000001a040400081004a048040800208902a00000010040230200842000802200000c08000000040001200002200191004200200044822010002a0008204000000105a800004000800000004120080839eb0fb8401c9c38083efc6ff8465aa87e099d883010d0a846765746888676f312e32312e36856c696e7578a0147c52f02f979f18d2b3bb9ef4c149f0c08183dbc6c3f7787f431d0f77e2a20e8800000000000000000fa0adda430f291ebd8b29300dc152eb01614a3e12a54ec2e85fb6f2b0e8862d95a2".to_string()); + // headers.insert(10399996, "0xf90236a036508f57fc618c0eb97f575dea291b029c8fe7dabda8ccadb50f67bc6dc7f6c8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794000095e79eac4d76aab57cb2c1f091d553b36ca0a01d7a5880ff6993159108cda8d8d001fd3c60d21b43901dcb3196b14cfd3d3ebba016b549e2cfe2da964f3ca90c02b85e76263cb7057f9121462cbb7914f8e8a96fa0e840f3d545f932d5bda765791bc958439b382623f7c6dc4db8918b9574e4306fb901000000000800004aa100100002000100084088000000001c400290011800040022028000000000010008002800000420842802800012000100001015001020403412128000600408104110000a8000820044210000004001009008000400000a20000210042700001000420080000408000a0800c0203004000403001000082040a212000000000100104010380000000000010082401400c05041a00040800000028000400020100006009002000000000000008001004080008100222080800002080022000002000002202008d2020906000000048802000040820204002200001200000000004100020030a0000004020000184a080001100800000005028080839eb0fc8401c9c38083b9bf718465aa87ec99d883010d09846765746888676f312e32312e35856c696e7578a032bf691f17cfacbdf561efe601596f5ecda83dd1e3561ab6ef20dbc88d6bfd3a88000000000000000010a0c439b85dd1dc29e603e6dea16ae1608e69ea660122e67f9a138d994dfb849f7b".to_string()); + // headers.insert(10399997, "0xf90227a0ab7d0c58b9c65dfe639c2f211419ae348a5addf750dee4251e333d05b9963e4ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794c6e2459991bfe27cca6d86722f35da23a1e4cb97a0111aba04a60a5c9b12a8ffdb2c25c559a07bff9bcd1fca0def062505ba20c814a07fc3a0fa37591d62f85ef4a6d41c603a28bf406c7b9f9708981641489833358ba02163dad73e78112d9b95112d0586deb63cdd6011b035db341673c997fef149eab901001523000a00114ec00014040ab121000c00880002040018640210011a810c0002969090060404214258002dcd00148080a142c050920663040030170052a4603010120018c40c20994258121fa220a2614f010108a35c201096008604912042780002000586040081024018a04082d882bc088cda401004184e02f314020820808212022083000108104010150380014180013c93e01482e850413150c004022017a01080148110120b408d42800400292411490203f440800dc5026b2180db804388c0020a00ec00090220b50856434806400008b08810100850480244006300251042210a008409a8050080a0008824228014d05e8880410e880c0400e6220080839eb0fd8401c9c38083eb6b288465aa88048a4e65746865726d696e64a0bf9288229d7fcae357296a6625ab4544e09bf51bd06038931bf7c50e443df6f788000000000000000010a05636ee17cad0dcfe4b825748afa13954cd23ab282c1b8a1ea3f3182452bc6a0b".to_string()); + // headers.insert(10399998, "0xf9023ca0453e6e9c59cc79225484522372d91892467b92f93de4b8f959fa103c4d66fd48a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b636a68f834b4d75af9edc5fb0138bb4758ed293a0e18ae94924ff9b4e00d89c68c6b1877ab5fcb42ec624cab0854bad2d25bb864fa0b22db3a12150f67635470138f8310d4ae2b730f25991abde493ca0e313ddac90a06d98daccfe6d2d8864d8695efad9ba54d90007ff01102314412a4048b308eaebb901000600000820234a800834040a0721004880100440c42208494214041a42141022009030450d4011001e0403a0408400880428c000924651008200130092244030310a02420d040220541200ab0020840044118000216c80100400064881010222080200044222008890543084024048000108c4c06030040405002090409820028216520200000500326810100340000040109480001004c010456011450001000288040434201810000089c00003010007100001a080400280a10046248040002208c00240000204000a61200842204806440020c0800001004040024042600001b810004d00001808010000a480801c004040107a860001800100010886022480839eb0fe8401c9c3808353073d8465aa88109f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a01546662902dd3009dc02026e83490ef770422479b77a2956d77447cf04115fd188000000000000000011a02e543617a0f520e23d7c36e89cbcceccead71bfe74bfc01c2038c4c59e252923".to_string()); + // headers.insert(10399999, "0xf90236a0c8d36d24d81f2e36a0f8c1f36f8add24dc8714320a78b17d07b25424e097ffa2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f97e180c050e5ab072211ad2c213eb5aee4df134a019f55a7f1fe370a77267d5c3327474ab2071802f7038a825a79c4bf78544c579a04eb5a4126fc6adc987334d3cb30a0785acf1dc1ca0019b5416288f839184060ea07274312f7366d6e50308a6bf1b2534e9eef27fc1f905125aa7b5f6d7625192deb901000422000d48014a88021400028165080800fc41402a04184203d194180484105242d004620200014018001b20144480808042a040b0f041600a101750122c4238907206004415208c4850221a802a88214e018400326c61088c9c041581060262c006a08c16088098a468408012000c21581804c8049005004e2a5010092a20808e13d31401802120384012114f000000e84124056a15a0e85145e360468200408388809c44203300022189604000042404100000032840a000818822608000008208d0023c012801000622a00c520208170000000080601000c0e42218106ac111340020000020690c000328a2804004020004105aa800510c6840001405029080839eb0ff8401c9c380838ee43e8465aa882899d883010d0a846765746888676f312e32312e36856c696e7578a053b87a12a76bb28a417cbda3acc6b241d7d849717140be043b8c1a2f8cb41ecb88000000000000000010a09c34780aa89b7419c9e7f57494d29e8c557e64d0cf04c3db57092eee73e7af00".to_string()); + // headers.insert(10400000, "0xf9023ca0792521e7510ba898aff41504d3ef2214619b81bcd731c38b2ee010228eebaabfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b64a30399f7f6b0c154c2e7af0a3ec7b0a5b131aa00aa14102830b3bb9ef07b0ed181062ed9ffc671d60b53eedb6d86ad85d3d4f50a0bc85c0c84815c05fd4f6d7139e592064716addb4e1a79e3322d7f08238768969a070806f936670ae9d136239961c487f752467c451ff1709af94e5254128bdaf14b901000460020e880b4a81007400038725009990884202a741984a4211011a84a4111216904c000700010068200ba80906b9c814228215925641400a129780122c44b0b17a080c4605a0a14854103e060898a84605001a3664406c060825c4a12642200084048d062c02853440588031012a00006a94c9281885000622d014080a2086863b821e25042500124490104302010058851485ac1d00c89255327009ea004553a2200a6420b2140a408940820004080670001112c0448004c1c96320a64a0a0288d2f21e240a40080e2bb41b571f081708c0004490e01020c04d034854624011104029004400198800130aa200c27462b214107ac0804104c840152811021480839eb1008401c9c3808386481f8465aa88349f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a00fd71f682d35bd1cb9c06bd2e6c637a79bb5cb25715ef90031c3c4cae99acfad88000000000000000010a0c8b02416e58787efe88ec75d1bae2a4f5ca2adea51b15477700d835bb1923871".to_string()); + headers +} diff --git a/crates/fetcher/src/lib.rs b/crates/fetcher/src/lib.rs index 8b137891..16ed632c 100644 --- a/crates/fetcher/src/lib.rs +++ b/crates/fetcher/src/lib.rs @@ -1 +1,2 @@ - +pub mod example_data; +pub mod memoizer; diff --git a/crates/fetcher/src/memoizer.rs b/crates/fetcher/src/memoizer.rs new file mode 100644 index 00000000..82136b66 --- /dev/null +++ b/crates/fetcher/src/memoizer.rs @@ -0,0 +1,80 @@ +use std::collections::HashMap; + +pub type RlpEncodedValue = String; + +pub struct Memoizer { + pub headers: HashMap, + pub accounts: HashMap>, + pub storages: HashMap>>, +} + +impl Memoizer { + pub fn new() -> Memoizer { + Memoizer { + headers: HashMap::new(), + accounts: HashMap::new(), + storages: HashMap::new(), + } + } + + pub fn pre_filled_memoizer( + headers: HashMap, + accounts: HashMap>, + storages: HashMap>>, + ) -> Memoizer { + Memoizer { + headers, + accounts, + storages, + } + } + + pub fn get_rlp_header(&self, block_number: usize) -> Option { + self.headers.get(&block_number).cloned() + } + + pub fn get_rlp_account(&self, block_number: usize, account: String) -> Option { + self.accounts + .get(&block_number) + .and_then(|accounts| accounts.get(&account).cloned()) + } + + pub fn get_rlp_storage( + &self, + block_number: usize, + account: String, + slot: String, + ) -> Option { + self.storages + .get(&block_number) + .and_then(|storages| storages.get(&account)) + .and_then(|slots| slots.get(&slot).cloned()) + } + + pub fn set_header(&mut self, block_number: usize, header: RlpEncodedValue) { + self.headers.insert(block_number, header); + } + + pub fn set_account(&mut self, block_number: usize, account: String, value: RlpEncodedValue) { + let accounts = self.accounts.entry(block_number).or_default(); + accounts.insert(account, value); + } + + pub fn set_storage( + &mut self, + block_number: usize, + account: String, + slot: String, + value: RlpEncodedValue, + ) { + let storages = self.storages.entry(block_number).or_default(); + let slots = storages.entry(account).or_default(); + slots.insert(slot, value); + } +} + +impl Default for Memoizer { + fn default() -> Memoizer { + Memoizer::new() + } +} diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index f152c992..0e2ad88a 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -8,3 +8,4 @@ alloy-dyn-abi = { workspace = true } alloy-primitives = { workspace = true } common = { workspace = true } anyhow = { workspace = true } +fetcher = { workspace = true } diff --git a/crates/types/src/compiler/block_sampled.rs b/crates/types/src/compiler/block_sampled.rs index 7d5d3f1a..7b6ec82e 100644 --- a/crates/types/src/compiler/block_sampled.rs +++ b/crates/types/src/compiler/block_sampled.rs @@ -1,4 +1,8 @@ +use std::{collections::HashMap, str::FromStr}; + use anyhow::Result; +use common::block::header::{decode_header_field, HeaderField}; +use fetcher::{example_data::get_example_headers, memoizer::Memoizer}; use crate::datalake::base::DataPoint; @@ -9,6 +13,8 @@ pub fn compile_block_sampled_datalake( sampled_property: &str, increment: usize, ) -> Result> { + let header_example = get_example_headers(); + let memoizer = Memoizer::pre_filled_memoizer(header_example, HashMap::new(), HashMap::new()); let property_parts: Vec<&str> = sampled_property.split('.').collect(); let collection = property_parts[0]; @@ -16,18 +22,19 @@ pub fn compile_block_sampled_datalake( match collection { "header" => { - // let property = property_parts[1]; - // Convert property to HeaderField enum variant here + let property = property_parts[1]; + for i in block_range_start..=block_range_end { if i % increment != 0 { continue; } - // let header = memoizer - // .get_header(i)? - // .ok_or(format!("No memoized header for block number: {}", i))?; - // let value = decode_header_field(&header, &HeaderField::YourFieldHere)? - // .ok_or("Decode failed")?; - aggregation_set.push(DataPoint::Int(i)); + let header = memoizer.get_rlp_header(i).unwrap(); + let value = decode_header_field( + &header, + HeaderField::from_str(&property.to_uppercase()).unwrap(), + ); + + aggregation_set.push(DataPoint::Str(value)); } } "account" => { diff --git a/crates/types/src/datalake/base.rs b/crates/types/src/datalake/base.rs index 7ef3ca0e..a9b382a0 100644 --- a/crates/types/src/datalake/base.rs +++ b/crates/types/src/datalake/base.rs @@ -5,7 +5,7 @@ use std::fmt; type DataCompiler = dyn Fn() -> Result>; /// DataPoint is a type that can be used to store data in a Datalake -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub enum DataPoint { Int(usize), Str(String), diff --git a/crates/types/src/datalake/block_sampled.rs b/crates/types/src/datalake/block_sampled.rs index d571cbe7..7b9068d0 100644 --- a/crates/types/src/datalake/block_sampled.rs +++ b/crates/types/src/datalake/block_sampled.rs @@ -13,7 +13,7 @@ use common::{ use crate::compiler::block_sampled::compile_block_sampled_datalake; -use super::base::{DatalakeBase, Derivable}; +use super::base::{DataPoint, DatalakeBase, Derivable}; /// BlockSampledDatalake represents a datalake for a block range #[derive(Debug, Clone, PartialEq)] @@ -82,6 +82,15 @@ impl BlockSampledDatalake { increment, }) } + + pub fn compile(&self) -> Result> { + compile_block_sampled_datalake( + self.block_range_start, + self.block_range_end, + &self.sampled_property, + self.increment, + ) + } } impl Default for BlockSampledDatalake { diff --git a/crates/types/tests/block_sampled.rs b/crates/types/tests/block_sampled.rs index 28aa0bc8..5e241ec1 100644 --- a/crates/types/tests/block_sampled.rs +++ b/crates/types/tests/block_sampled.rs @@ -1,4 +1,4 @@ -use types::datalake::block_sampled::BlockSampledDatalake; +use types::datalake::{base::DataPoint, block_sampled::BlockSampledDatalake}; #[test] fn test_block_datalake_for_header() { @@ -37,3 +37,12 @@ fn test_block_datalake_for_storage() { ); assert_eq!(decoded_datalake, block_datalake); } + +#[test] +fn test_blocksampled_compiler() { + let block_datalake = + BlockSampledDatalake::new(10399990, 10399990, "header.base_fee_per_gas".to_string(), 1); + + let data_points = block_datalake.compile().unwrap(); + assert_eq!(data_points, vec![DataPoint::Str("13".to_string())]); +} From 4867634766ed160efc7f4b3a4d6287b85e1a1059 Mon Sep 17 00:00:00 2001 From: Pia Date: Thu, 1 Feb 2024 23:28:51 +0800 Subject: [PATCH 2/4] feat: block header compiler working! --- Cargo.lock | 1285 +++++++++++++++++++- Cargo.toml | 1 + crates/common/Cargo.toml | 1 + crates/common/src/block/header.rs | 122 +- crates/common/tests/header.rs | 62 +- crates/fetcher/src/example_data.rs | 22 +- crates/types/src/datalake/block_sampled.rs | 10 +- crates/types/tests/block_sampled.rs | 14 +- 8 files changed, 1385 insertions(+), 132 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0219484..ee0a41ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,46 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + +[[package]] +name = "alloy-chains" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "206e825321d0ed5b6e3907e6ddf70c2139cfdc6274e83a1ca2f4784bd0abc0c9" +dependencies = [ + "alloy-rlp", + "num_enum", + "serde", + "strum", +] + [[package]] name = "alloy-dyn-abi" version = "0.6.2" @@ -34,6 +74,16 @@ dependencies = [ "winnow", ] +[[package]] +name = "alloy-genesis" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy#fcbf995278007c19b75e40d4fda7fd477e2d1598" +dependencies = [ + "alloy-primitives", + "alloy-rpc-types", + "serde", +] + [[package]] name = "alloy-json-abi" version = "0.6.2" @@ -57,6 +107,7 @@ dependencies = [ "cfg-if", "const-hex", "derive_more", + "getrandom", "hex-literal", "itoa", "k256", @@ -90,6 +141,44 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "alloy-rpc-engine-types" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy#fcbf995278007c19b75e40d4fda7fd477e2d1598" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "alloy-rpc-types", + "jsonrpsee-types", + "serde", + "thiserror", +] + +[[package]] +name = "alloy-rpc-trace-types" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy#fcbf995278007c19b75e40d4fda7fd477e2d1598" +dependencies = [ + "alloy-primitives", + "alloy-rpc-types", + "serde", + "serde_json", +] + +[[package]] +name = "alloy-rpc-types" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy#fcbf995278007c19b75e40d4fda7fd477e2d1598" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "itertools 0.12.1", + "jsonrpsee-types", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "alloy-sol-macro" version = "0.6.2" @@ -99,7 +188,7 @@ dependencies = [ "const-hex", "dunce", "heck", - "indexmap", + "indexmap 2.2.1", "proc-macro-error", "proc-macro2", "quote", @@ -129,6 +218,37 @@ dependencies = [ "serde", ] +[[package]] +name = "alloy-trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59974c3c7778ebbcd73356a430fd4608aaf0630b1fdb4f5337bfd70f40b66618" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "derive_more", + "hashbrown 0.14.3", + "nybbles", + "serde", + "smallvec", + "tracing", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.11" @@ -183,6 +303,12 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + [[package]] name = "ark-ff" version = "0.3.0" @@ -213,7 +339,7 @@ dependencies = [ "ark-std 0.4.0", "derivative", "digest 0.10.7", - "itertools", + "itertools 0.10.5", "num-bigint", "num-traits", "paste", @@ -313,6 +439,16 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "aurora-engine-modexp" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfacad86e9e138fca0670949eb8ed4ffdf73a55bded8887efe0863cd1a3a6f70" +dependencies = [ + "hex", + "num", +] + [[package]] name = "auto_impl" version = "1.1.2" @@ -351,12 +487,50 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64ct" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" +dependencies = [ + "serde", +] + +[[package]] +name = "bindgen" +version = "0.66.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" +dependencies = [ + "bitflags 2.4.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.48", + "which", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -383,6 +557,9 @@ name = "bitflags" version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +dependencies = [ + "serde", +] [[package]] name = "bitvec" @@ -392,6 +569,7 @@ checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" dependencies = [ "funty", "radium", + "serde", "tap", "wyz", ] @@ -405,6 +583,24 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blst" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c94087b935a822949d3291a9989ad2b2051ea141eda0fd4e478a75f6aa3e604b" +dependencies = [ + "cc", + "glob", + "threadpool", + "zeroize", +] + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + [[package]] name = "byte-slice-cast" version = "1.2.2" @@ -426,21 +622,70 @@ dependencies = [ "serde", ] +[[package]] +name = "c-kzg" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32700dc7904064bb64e857d38a1766607372928e2466ee5f02a869829b3297d7" +dependencies = [ + "bindgen", + "blst", + "cc", + "glob", + "hex", + "libc", + "serde", +] + [[package]] name = "cc" version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ + "jobserver", "libc", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets 0.52.0", +] + +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "4.4.18" @@ -491,6 +736,19 @@ dependencies = [ "types", ] +[[package]] +name = "codecs-derive" +version = "0.1.0-alpha.16" +source = "git+https://github.com/paradigmxyz/reth?rev=01d3df3#01d3df30f78006ad3b3a41fd64fe8b444bb3a4f8" +dependencies = [ + "convert_case 0.6.0", + "parity-scale-codec", + "proc-macro2", + "quote", + "serde", + "syn 2.0.48", +] + [[package]] name = "colorchoice" version = "1.0.0" @@ -504,6 +762,7 @@ dependencies = [ "alloy-primitives", "alloy-rlp", "anyhow", + "reth-primitives", ] [[package]] @@ -531,6 +790,21 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "cpufeatures" version = "0.2.12" @@ -540,6 +814,46 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + [[package]] name = "crunchy" version = "0.2.2" @@ -568,6 +882,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.48", +] + +[[package]] +name = "darling_macro" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.48", +] + [[package]] name = "decoder" version = "0.1.0" @@ -589,6 +938,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + [[package]] name = "derivative" version = "2.2.0" @@ -606,7 +965,7 @@ version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ - "convert_case", + "convert_case 0.4.0", "proc-macro2", "quote", "rustc_version 0.4.0", @@ -679,6 +1038,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "enumn" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -752,6 +1122,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "funty" version = "2.0.0" @@ -786,6 +1165,12 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "group" version = "0.13.0" @@ -797,11 +1182,22 @@ dependencies = [ "subtle", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", + "allocator-api2", + "serde", +] [[package]] name = "heck" @@ -840,16 +1236,64 @@ dependencies = [ ] [[package]] -name = "impl-codec" -version = "0.6.0" +name = "home" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "parity-scale-codec", + "windows-sys 0.52.0", ] [[package]] -name = "impl-trait-for-tuples" +name = "iana-time-zone" +version = "0.1.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-trait-for-tuples" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" @@ -859,6 +1303,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "indexmap" version = "2.2.1" @@ -866,7 +1321,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "433de089bd45971eecf4668ee0ee8f4cec17db4f8bd8f7bc3197a6ce37aa7d9b" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.3", + "serde", ] [[package]] @@ -878,12 +1334,62 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "jobserver" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "jsonrpsee-types" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be0be325642e850ed0bdff426674d2e66b2b7117c9be23a7caef68a2902b7d9" +dependencies = [ + "anyhow", + "beef", + "serde", + "serde_json", + "thiserror", + "tracing", +] + [[package]] name = "k256" version = "0.13.3" @@ -913,6 +1419,15 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" @@ -920,6 +1435,16 @@ version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +[[package]] +name = "libloading" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "libm" version = "0.2.8" @@ -942,12 +1467,24 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + [[package]] name = "memchr" version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -968,6 +1505,51 @@ dependencies = [ "windows-sys 0.48.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 = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.4" @@ -979,6 +1561,21 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-complex" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.45" @@ -989,6 +1586,29 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.17" @@ -1009,6 +1629,40 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "nybbles" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836816c354fb2c09622b54545a6f98416147346b13cc7eba5f92fab6b3042c93" +dependencies = [ + "alloy-rlp", + "const-hex", + "proptest", + "serde", + "smallvec", +] + [[package]] name = "object" version = "0.32.2" @@ -1033,6 +1687,7 @@ dependencies = [ "arrayvec", "bitvec", "byte-slice-cast", + "bytes", "impl-trait-for-tuples", "parity-scale-codec-derive", "serde", @@ -1079,6 +1734,18 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "pest" version = "2.7.6" @@ -1106,12 +1773,34 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "prettyplease" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" +dependencies = [ + "proc-macro2", + "syn 2.0.48", +] + [[package]] name = "primitive-types" version = "0.12.2" @@ -1246,6 +1935,26 @@ dependencies = [ "rand_core", ] +[[package]] +name = "rayon" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -1256,10 +1965,169 @@ dependencies = [ ] [[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "reth-codecs" +version = "0.1.0-alpha.16" +source = "git+https://github.com/paradigmxyz/reth?rev=01d3df3#01d3df30f78006ad3b3a41fd64fe8b444bb3a4f8" +dependencies = [ + "alloy-primitives", + "bytes", + "codecs-derive", +] + +[[package]] +name = "reth-ethereum-forks" +version = "0.1.0-alpha.16" +source = "git+https://github.com/paradigmxyz/reth?rev=01d3df3#01d3df30f78006ad3b3a41fd64fe8b444bb3a4f8" +dependencies = [ + "alloy-chains", + "alloy-primitives", + "alloy-rlp", + "crc", + "serde", + "thiserror", +] + +[[package]] +name = "reth-primitives" +version = "0.1.0-alpha.16" +source = "git+https://github.com/paradigmxyz/reth?rev=01d3df3#01d3df30f78006ad3b3a41fd64fe8b444bb3a4f8" +dependencies = [ + "ahash", + "alloy-chains", + "alloy-genesis", + "alloy-primitives", + "alloy-rlp", + "alloy-trie", + "byteorder", + "bytes", + "c-kzg", + "derive_more", + "itertools 0.11.0", + "modular-bitfield", + "num_enum", + "nybbles", + "once_cell", + "rayon", + "reth-codecs", + "reth-ethereum-forks", + "reth-rpc-types", + "revm", + "revm-primitives", + "secp256k1 0.27.0", + "serde", + "serde_json", + "sha2", + "smallvec", + "strum", + "sucds", + "tempfile", + "thiserror", + "tracing", + "zstd", +] + +[[package]] +name = "reth-rpc-types" +version = "0.1.0-alpha.16" +source = "git+https://github.com/paradigmxyz/reth?rev=01d3df3#01d3df30f78006ad3b3a41fd64fe8b444bb3a4f8" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "alloy-rpc-engine-types", + "alloy-rpc-trace-types", + "alloy-rpc-types", + "bytes", + "itertools 0.12.1", + "jsonrpsee-types", + "secp256k1 0.27.0", + "serde", + "serde_json", + "serde_with", + "thiserror", + "url", +] + +[[package]] +name = "revm" +version = "3.5.0" +source = "git+https://github.com/bluealloy/revm?branch=reth_freeze#2caa13db91db770e7e015a6e52b5feedbb38ee8a" +dependencies = [ + "auto_impl", + "revm-interpreter", + "revm-precompile", +] + +[[package]] +name = "revm-interpreter" +version = "1.3.0" +source = "git+https://github.com/bluealloy/revm?branch=reth_freeze#2caa13db91db770e7e015a6e52b5feedbb38ee8a" +dependencies = [ + "revm-primitives", +] + +[[package]] +name = "revm-precompile" +version = "2.2.0" +source = "git+https://github.com/bluealloy/revm?branch=reth_freeze#2caa13db91db770e7e015a6e52b5feedbb38ee8a" +dependencies = [ + "aurora-engine-modexp", + "c-kzg", + "k256", + "once_cell", + "revm-primitives", + "ripemd", + "secp256k1 0.28.2", + "sha2", + "substrate-bn", +] + +[[package]] +name = "revm-primitives" +version = "1.3.0" +source = "git+https://github.com/bluealloy/revm?branch=reth_freeze#2caa13db91db770e7e015a6e52b5feedbb38ee8a" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "auto_impl", + "bitflags 2.4.2", + "bitvec", + "c-kzg", + "derive_more", + "enumn", + "hashbrown 0.14.3", + "hex", + "once_cell", + "serde", +] [[package]] name = "rfc6979" @@ -1271,6 +2139,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "rlp" version = "0.5.2" @@ -1317,6 +2194,12 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -1354,6 +2237,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "rusty-fork" version = "0.3.0" @@ -1392,6 +2281,43 @@ dependencies = [ "zeroize", ] +[[package]] +name = "secp256k1" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" +dependencies = [ + "rand", + "secp256k1-sys 0.8.1", +] + +[[package]] +name = "secp256k1" +version = "0.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" +dependencies = [ + "secp256k1-sys 0.9.2", +] + +[[package]] +name = "secp256k1-sys" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" +dependencies = [ + "cc", +] + +[[package]] +name = "secp256k1-sys" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" +dependencies = [ + "cc", +] + [[package]] name = "semver" version = "0.11.0" @@ -1447,6 +2373,35 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b0ed1662c5a68664f45b76d18deb0e234aff37207086803165c961eb695e981" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.2.1", + "serde", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "568577ff0ef47b879f736cd66740e022f3672788cdf002a05a4e609ea5a6fb15" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "sha2" version = "0.10.8" @@ -1468,6 +2423,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -1492,6 +2453,10 @@ name = "smallvec" version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +dependencies = [ + "arbitrary", + "serde", +] [[package]] name = "socket2" @@ -1503,6 +2468,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spki" version = "0.7.3" @@ -1525,12 +2496,56 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.48", +] + +[[package]] +name = "substrate-bn" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b5bbfa79abbae15dd642ea8176a21a635ff3c00059961d1ea27ad04e5b441c" +dependencies = [ + "byteorder", + "crunchy", + "lazy_static", + "rand", + "rustc-hex", +] + [[package]] name = "subtle" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "sucds" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64accd20141dfbef67ad83c51d588146cff7810616e1bda35a975be369059533" +dependencies = [ + "anyhow", +] + [[package]] name = "syn" version = "1.0.109" @@ -1604,6 +2619,46 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "time" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe80ced77cbfb4cb91a94bf72b378b4b6791a0d9b7f09d0be747d1bdff4e68bd" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -1613,6 +2668,21 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "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.35.1" @@ -1655,11 +2725,42 @@ version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ - "indexmap", + "indexmap 2.2.1", "toml_datetime", "winnow", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + [[package]] name = "typenum" version = "1.17.0" @@ -1701,12 +2802,44 @@ 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.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "utf8parse" version = "0.2.1" @@ -1740,6 +2873,81 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.48", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -1890,6 +3098,26 @@ dependencies = [ "tap", ] +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "zeroize" version = "1.7.0" @@ -1909,3 +3137,32 @@ dependencies = [ "quote", "syn 2.0.48", ] + +[[package]] +name = "zstd" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "6.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.9+zstd.1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 68359367..eddc6a01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,4 @@ alloy-dyn-abi = "0.6.2" alloy-primitives = "0.6.2" alloy-rlp = { version = "0.3.4", features = ["derive"] } anyhow = "1.0.79" +reth-primitives = { git = "https://github.com/paradigmxyz/reth", package = "reth-primitives", rev = "01d3df3" } diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 187239b2..a41fd801 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" alloy-primitives = { workspace = true } alloy-rlp = { workspace = true } anyhow = { workspace = true } +reth-primitives = { workspace = true } diff --git a/crates/common/src/block/header.rs b/crates/common/src/block/header.rs index 689f3c7d..fbc169ec 100644 --- a/crates/common/src/block/header.rs +++ b/crates/common/src/block/header.rs @@ -1,7 +1,8 @@ use std::str::FromStr; -use alloy_primitives::hex::{encode, FromHex}; -use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable}; +use alloy_primitives::hex; +use alloy_rlp::Decodable; +use reth_primitives::Header; #[derive(Debug)] pub enum HeaderField { @@ -22,6 +23,9 @@ pub enum HeaderField { Nonce, BaseFeePerGas, WithdrawalsRoot, + BlobGasUsed, + ExcessBlobGas, + ParentBeaconBlockRoot, } impl HeaderField { @@ -44,29 +48,35 @@ impl HeaderField { 14 => Some(HeaderField::Nonce), 15 => Some(HeaderField::BaseFeePerGas), 16 => Some(HeaderField::WithdrawalsRoot), + 17 => Some(HeaderField::BlobGasUsed), + 18 => Some(HeaderField::ExcessBlobGas), + 19 => Some(HeaderField::ParentBeaconBlockRoot), _ => None, } } - pub fn to_index(&self) -> Option { + pub fn to_index(&self) -> usize { match self { - HeaderField::ParentHash => Some(0), - HeaderField::OmmerHash => Some(1), - HeaderField::Beneficiary => Some(2), - HeaderField::StateRoot => Some(3), - HeaderField::TransactionsRoot => Some(4), - HeaderField::ReceiptsRoot => Some(5), - HeaderField::LogsBloom => Some(6), - HeaderField::Difficulty => Some(7), - HeaderField::Number => Some(8), - HeaderField::GasLimit => Some(9), - HeaderField::GasUsed => Some(10), - HeaderField::Timestamp => Some(11), - HeaderField::ExtraData => Some(12), - HeaderField::MixHash => Some(13), - HeaderField::Nonce => Some(14), - HeaderField::BaseFeePerGas => Some(15), - HeaderField::WithdrawalsRoot => Some(16), + HeaderField::ParentHash => 0, + HeaderField::OmmerHash => 1, + HeaderField::Beneficiary => 2, + HeaderField::StateRoot => 3, + HeaderField::TransactionsRoot => 4, + HeaderField::ReceiptsRoot => 5, + HeaderField::LogsBloom => 6, + HeaderField::Difficulty => 7, + HeaderField::Number => 8, + HeaderField::GasLimit => 9, + HeaderField::GasUsed => 10, + HeaderField::Timestamp => 11, + HeaderField::ExtraData => 12, + HeaderField::MixHash => 13, + HeaderField::Nonce => 14, + HeaderField::BaseFeePerGas => 15, + HeaderField::WithdrawalsRoot => 16, + HeaderField::BlobGasUsed => 17, + HeaderField::ExcessBlobGas => 18, + HeaderField::ParentBeaconBlockRoot => 19, } } @@ -89,6 +99,9 @@ impl HeaderField { HeaderField::Nonce => "NONCE", HeaderField::BaseFeePerGas => "BASE_FEE_PER_GAS", HeaderField::WithdrawalsRoot => "WITHDRAWALS_ROOT", + HeaderField::BlobGasUsed => "BLOB_GAS_USED", + HeaderField::ExcessBlobGas => "EXCESS_BLOB_GAS", + HeaderField::ParentBeaconBlockRoot => "PARENT_BEACON_BLOCK_ROOT", } } } @@ -115,67 +128,38 @@ impl FromStr for HeaderField { "NONCE" => Ok(HeaderField::Nonce), "BASE_FEE_PER_GAS" => Ok(HeaderField::BaseFeePerGas), "WITHDRAWALS_ROOT" => Ok(HeaderField::WithdrawalsRoot), + "BLOB_GAS_USED" => Ok(HeaderField::BlobGasUsed), + "EXCESS_BLOB_GAS" => Ok(HeaderField::ExcessBlobGas), + "PARENT_BEACON_BLOCK_ROOT" => Ok(HeaderField::ParentBeaconBlockRoot), _ => Err(()), } } } -#[derive(Debug, RlpDecodable, RlpEncodable, PartialEq)] -#[rlp(trailing)] -pub struct BlockHeaderShanghai { - pub parent_hash: String, - pub uncle_hash: String, - pub coinbase: String, - pub state_root: String, - pub transactions_root: String, - pub receipts_root: String, - pub logs_bloom: String, - pub difficulty: u64, - pub number: u64, - pub gas_limit: u64, - pub gas_used: u64, - pub timestamp: u64, - pub extra_data: String, - pub mix_hash: String, - pub nonce: String, - pub base_fee_per_gas: Option, - pub withdrawals_root: Option, -} - -impl BlockHeaderShanghai { - pub fn from_rlp_hexstring(rlp_hexstring: &str) -> Self { - let buffer = Vec::::from_hex(rlp_hexstring).unwrap(); - let rlp_decoded_header = BlockHeaderShanghai::decode(&mut buffer.as_slice()).unwrap(); - rlp_decoded_header - } - - pub fn to_rlp_hexstring(&self) -> String { - let mut buffer = Vec::::new(); - self.encode(&mut buffer); - encode(buffer) - } -} - pub fn decode_header_field(header_rlp: &str, field: HeaderField) -> String { - let decoded = BlockHeaderShanghai::from_rlp_hexstring(header_rlp); + let decoded = +
::decode(&mut hex::decode(header_rlp).unwrap().as_slice()).unwrap(); match field { - HeaderField::ParentHash => decoded.parent_hash, - HeaderField::OmmerHash => decoded.uncle_hash, - HeaderField::Beneficiary => decoded.coinbase, - HeaderField::StateRoot => decoded.state_root, - HeaderField::TransactionsRoot => decoded.transactions_root, - HeaderField::ReceiptsRoot => decoded.receipts_root, - HeaderField::LogsBloom => decoded.logs_bloom, + HeaderField::ParentHash => decoded.parent_hash.to_string(), + HeaderField::OmmerHash => decoded.ommers_hash.to_string(), + HeaderField::Beneficiary => decoded.beneficiary.to_string(), + HeaderField::StateRoot => decoded.state_root.to_string(), + HeaderField::TransactionsRoot => decoded.transactions_root.to_string(), + HeaderField::ReceiptsRoot => decoded.receipts_root.to_string(), + HeaderField::LogsBloom => decoded.logs_bloom.to_string(), HeaderField::Difficulty => decoded.difficulty.to_string(), HeaderField::Number => decoded.number.to_string(), HeaderField::GasLimit => decoded.gas_limit.to_string(), HeaderField::GasUsed => decoded.gas_used.to_string(), HeaderField::Timestamp => decoded.timestamp.to_string(), - HeaderField::ExtraData => decoded.extra_data, - HeaderField::MixHash => decoded.mix_hash, - HeaderField::Nonce => decoded.nonce, - HeaderField::BaseFeePerGas => decoded.base_fee_per_gas.unwrap_or(0).to_string(), - HeaderField::WithdrawalsRoot => decoded.withdrawals_root.unwrap_or("".to_string()), + HeaderField::ExtraData => decoded.extra_data.to_string(), + HeaderField::MixHash => decoded.mix_hash.to_string(), + HeaderField::Nonce => decoded.nonce.to_string(), + HeaderField::BaseFeePerGas => decoded.base_fee_per_gas.unwrap().to_string(), + HeaderField::WithdrawalsRoot => decoded.withdrawals_root.unwrap().to_string(), + HeaderField::BlobGasUsed => decoded.blob_gas_used.unwrap().to_string(), + HeaderField::ExcessBlobGas => decoded.excess_blob_gas.unwrap().to_string(), + HeaderField::ParentBeaconBlockRoot => decoded.parent_beacon_block_root.unwrap().to_string(), } } diff --git a/crates/common/tests/header.rs b/crates/common/tests/header.rs index e1328301..14694fd2 100644 --- a/crates/common/tests/header.rs +++ b/crates/common/tests/header.rs @@ -1,35 +1,39 @@ -use common::block::header::BlockHeaderShanghai; +use std::str::FromStr; + +use alloy_primitives::{hex, Address, Bloom, Bytes, FixedBytes, U256}; +use alloy_rlp::Decodable; +use reth_primitives::Header; #[test] pub fn test_rlp() { - let rlp_hex ="f90475b842307834356164623638346362353435383031396334393632303663313338333839346333363066653936396131303238626134343935356561646661353835636335b842307831646363346465386465633735643761616238356235363762366363643431616433313234353162393438613734313366306131343266643430643439333437aa307862363336613638663833346234643735616639656463356662303133386262343735386564323933b842307831646232333838393233663763373836383062346134366261653732353633373031336437346164373837656335633836316433616465336466383832643831b842307839333538366562356632373831646564333334613261303364313738663431646330366632373164376631666634323965346461366566343264313261373733b842307833363135393037373566656137383537636330343862393332346330336539366632383731393938303363653134343066663165313263356336303038303439b902023078303432303030306132303033303830303030323532303130303561333034303030303839363238303034303231383564633630303134343238303034303038323232313430303031303130313230303435383030326230643838303038303238303034323036383038343038343030343032313038663038313232343632303032343061323034333635313030313039303531633038326130323030383132303432303030303130363034343030393030343430343434343831303030383231303030323830303130363036343063303131343031613830323030303039303333313030303430383234333830343030393430323230313234303830323038323832303430333830313134313035306134613030323038323833323032303530303030663130303538383934303038303030343131303530353132383030323230613230303030303034323237353830303238303839343038303030303230323436303034303033303030303430383030316365303032383234303030303030303261386332343231303030303230303031346133303034303031353032306230343830303032303630383830303030303835303434303234306330363130303031313030323030303030303230303938383030313830303030303838303132386130353034303033323930383163313434303830613034303830303030303480839eb0f68401c9c380836f9a8e8465aa8780b84030783439366336633735366436393665363137343635323034343664366636333732363137343639376136353230343437333734373236393632373537343635b842307863363533653163316365653939303134376634343339373736636333656164366631373565303831393938633333633933646134313635333131326538396365923078303030303030303030303030303030300db842307833396462336639643166653037353665356165663465326630323431616439353765393939653439633938313830396330313834323564303038306636636432".to_string(); - // TODO: we need to figure out with alloy rlp encoding / decoding - //let hex2 = "f9023ca045adb684cb5458019c496206c1383894c360fe969a1028ba44955eadfa585cc5a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b636a68f834b4d75af9edc5fb0138bb4758ed293a01db2388923f7c78680b4a46bae725637013d74ad787ec5c861d3ade3df882d81a093586eb5f2781ded334a2a03d178f41dc06f271d7f1ff429e4da6ef42d12a773a0361590775fea7857cc048b9324c03e96f287199803ce1440ff1e12c5c6008049b901000420000a200308000025201005a30400008962800402185dc600144280040082221400010101200458002b0d88008028004206808408400402108f0812246200240a204365100109051c082a020081204200001060440090044044448100082100028001060640c011401a802000090331000408243804009402201240802082820403801141050a4a00208283202050000f10058894008000411050512800220a200000042275800280894080000202460040030000408001ce00282400000002a8c24210000200014a30040015020b04800020608800000850440240c06100011002000000200988001800000880128a050400329081c144080a040800000480839eb0f68401c9c380836f9a8e8465aa87809f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a0c653e1c1cee990147f4439776cc3ead6f175e081998c33c93da41653112e89ce8800000000000000000da039db3f9d1fe0756e5aef4e2f0241ad957e999e49c981809c018425d0080f6cd2".to_string(); - let header_from_rlp = BlockHeaderShanghai::from_rlp_hexstring(&rlp_hex); - let expected_header = BlockHeaderShanghai { - parent_hash: "0x45adb684cb5458019c496206c1383894c360fe969a1028ba44955eadfa585cc5" - .to_string(), - uncle_hash: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - .to_string(), - coinbase: "0xb636a68f834b4d75af9edc5fb0138bb4758ed293".to_string(), - state_root: "0x1db2388923f7c78680b4a46bae725637013d74ad787ec5c861d3ade3df882d81" - .to_string(), - transactions_root: "0x93586eb5f2781ded334a2a03d178f41dc06f271d7f1ff429e4da6ef42d12a773" - .to_string(), - receipts_root: "0x361590775fea7857cc048b9324c03e96f287199803ce1440ff1e12c5c6008049" - .to_string(), - logs_bloom: "0x0420000a200308000025201005a30400008962800402185dc600144280040082221400010101200458002b0d88008028004206808408400402108f0812246200240a204365100109051c082a020081204200001060440090044044448100082100028001060640c011401a802000090331000408243804009402201240802082820403801141050a4a00208283202050000f10058894008000411050512800220a200000042275800280894080000202460040030000408001ce00282400000002a8c24210000200014a30040015020b04800020608800000850440240c06100011002000000200988001800000880128a050400329081c144080a0408000004".to_string(), - difficulty: 0, - number: 10399990, - gas_limit: 30000000, - gas_used: 7314062, - timestamp: 1705674624, - extra_data: "0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465".to_string(), - mix_hash: "0xc653e1c1cee990147f4439776cc3ead6f175e081998c33c93da41653112e89ce".to_string(), - nonce: "0x0000000000000000".to_string(), + let rlp_hex ="f90266a045adb684cb5458019c496206c1383894c360fe969a1028ba44955eadfa585cc5a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b636a68f834b4d75af9edc5fb0138bb4758ed293a01db2388923f7c78680b4a46bae725637013d74ad787ec5c861d3ade3df882d81a093586eb5f2781ded334a2a03d178f41dc06f271d7f1ff429e4da6ef42d12a773a0361590775fea7857cc048b9324c03e96f287199803ce1440ff1e12c5c6008049b901000420000a200308000025201005a30400008962800402185dc600144280040082221400010101200458002b0d88008028004206808408400402108f0812246200240a204365100109051c082a020081204200001060440090044044448100082100028001060640c011401a802000090331000408243804009402201240802082820403801141050a4a00208283202050000f10058894008000411050512800220a200000042275800280894080000202460040030000408001ce00282400000002a8c24210000200014a30040015020b04800020608800000850440240c06100011002000000200988001800000880128a050400329081c144080a040800000480839eb0f68401c9c380836f9a8e8465aa87809f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a0c653e1c1cee990147f4439776cc3ead6f175e081998c33c93da41653112e89ce8800000000000000000da039db3f9d1fe0756e5aef4e2f0241ad957e999e49c981809c018425d0080f6cd2830400008405320000a0713ce910d12e99ba96492ff2f6411d4e0a3e567ab419e92e60cf5fc4aa74db7a".to_string(); + let rlp = hex::decode(rlp_hex).unwrap(); + let decoded =
::decode(&mut rlp.as_slice()).unwrap(); + let expected_header = Header { + parent_hash:FixedBytes::from_str( "0x45adb684cb5458019c496206c1383894c360fe969a1028ba44955eadfa585cc5").unwrap(), + ommers_hash: FixedBytes::from_str( "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").unwrap(), + beneficiary: Address::from_str("0xb636a68f834b4d75af9edc5fb0138bb4758ed293").unwrap(), + state_root:FixedBytes::from_str( "0x1db2388923f7c78680b4a46bae725637013d74ad787ec5c861d3ade3df882d81" + ).unwrap(), + transactions_root: FixedBytes::from_str("0x93586eb5f2781ded334a2a03d178f41dc06f271d7f1ff429e4da6ef42d12a773" +).unwrap(), + receipts_root: FixedBytes::from_str("0x361590775fea7857cc048b9324c03e96f287199803ce1440ff1e12c5c6008049" +).unwrap(), + logs_bloom:Bloom::from_str("0x0420000a200308000025201005a30400008962800402185dc600144280040082221400010101200458002b0d88008028004206808408400402108f0812246200240a204365100109051c082a020081204200001060440090044044448100082100028001060640c011401a802000090331000408243804009402201240802082820403801141050a4a00208283202050000f10058894008000411050512800220a200000042275800280894080000202460040030000408001ce00282400000002a8c24210000200014a30040015020b04800020608800000850440240c06100011002000000200988001800000880128a050400329081c144080a0408000004").unwrap(), + difficulty: U256::from(0x0), + number: 0x9eb0f6u64, + gas_limit: 0x1c9c380u64, + gas_used: 0x6f9a8eu64, + timestamp: 0x65aa8780u64, + extra_data: Bytes::from_str("0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465").unwrap(), + mix_hash: FixedBytes::from_str("0xc653e1c1cee990147f4439776cc3ead6f175e081998c33c93da41653112e89ce").unwrap(), + nonce:0x0u64, base_fee_per_gas: Some(13), - withdrawals_root: Some("0x39db3f9d1fe0756e5aef4e2f0241ad957e999e49c981809c018425d0080f6cd2".to_string()), + withdrawals_root: Some(FixedBytes::from_str("0x39db3f9d1fe0756e5aef4e2f0241ad957e999e49c981809c018425d0080f6cd2").unwrap()), + blob_gas_used: Some(0x40000u64), + excess_blob_gas: Some(0x5320000u64), + parent_beacon_block_root: Some(FixedBytes::from_str("0x713ce910d12e99ba96492ff2f6411d4e0a3e567ab419e92e60cf5fc4aa74db7a").unwrap()), }; - // let header2 = BlockHeaderShanghai::from_rlp_hexstring(&hex2); - assert_eq!(header_from_rlp, expected_header); + + assert_eq!(decoded, expected_header); } diff --git a/crates/fetcher/src/example_data.rs b/crates/fetcher/src/example_data.rs index 85b33e0c..7287caf7 100644 --- a/crates/fetcher/src/example_data.rs +++ b/crates/fetcher/src/example_data.rs @@ -4,16 +4,16 @@ use crate::memoizer::RlpEncodedValue; pub fn get_example_headers() -> HashMap { let mut headers = HashMap::new(); - headers.insert(10399990, "f90475b842307834356164623638346362353435383031396334393632303663313338333839346333363066653936396131303238626134343935356561646661353835636335b842307831646363346465386465633735643761616238356235363762366363643431616433313234353162393438613734313366306131343266643430643439333437aa307862363336613638663833346234643735616639656463356662303133386262343735386564323933b842307831646232333838393233663763373836383062346134366261653732353633373031336437346164373837656335633836316433616465336466383832643831b842307839333538366562356632373831646564333334613261303364313738663431646330366632373164376631666634323965346461366566343264313261373733b842307833363135393037373566656137383537636330343862393332346330336539366632383731393938303363653134343066663165313263356336303038303439b902023078303432303030306132303033303830303030323532303130303561333034303030303839363238303034303231383564633630303134343238303034303038323232313430303031303130313230303435383030326230643838303038303238303034323036383038343038343030343032313038663038313232343632303032343061323034333635313030313039303531633038326130323030383132303432303030303130363034343030393030343430343434343831303030383231303030323830303130363036343063303131343031613830323030303039303333313030303430383234333830343030393430323230313234303830323038323832303430333830313134313035306134613030323038323833323032303530303030663130303538383934303038303030343131303530353132383030323230613230303030303034323237353830303238303839343038303030303230323436303034303033303030303430383030316365303032383234303030303030303261386332343231303030303230303031346133303034303031353032306230343830303032303630383830303030303835303434303234306330363130303031313030323030303030303230303938383030313830303030303838303132386130353034303033323930383163313434303830613034303830303030303480839eb0f68401c9c380836f9a8e8465aa8780b84030783439366336633735366436393665363137343635323034343664366636333732363137343639376136353230343437333734373236393632373537343635b842307863363533653163316365653939303134376634343339373736636333656164366631373565303831393938633333633933646134313635333131326538396365923078303030303030303030303030303030300db842307833396462336639643166653037353665356165663465326630323431616439353765393939653439633938313830396330313834323564303038306636636432".to_string()); - // headers.insert(10399991, "0xf90237a02ef5bd5264f472d821fb950241aa2bbe83f885fea086b4f58fccb9c9b948adcfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479494750381be1aba0504c666ee1db118f68f0780d4a01fa9a7ad0deb9e4c0762aed5a02a0eb0be12864363eb2f6434ad55454352533ea0e4be7e5ed75566d7ab90c1610d81a8f38f3b56b3c338f211646ae32aebd4e690a0f8973cc47d1dac1a9f71fec14ec19dcde2ad1e6c6b6336e42b1da0322a6c7581b901007432022a09014808001c000b91ab000c408a444206011a6200994018c004101a06d1c003460021145888092814458890000a020092b4e4c0023a3710332c01329252440a050520886880061f020882214f91000e2a64a50a8024444c832446718206009dc60020a0a7e158a104002800080884d0041085084aa83010012ae2c88210a39401140080b04100004b200700902184c3ea95a1c8401532f944820040276e5b884c9b3290120009408b0604a5a401281a41ec508000c2886b280a488a2208d0222800a801080622b00a7602091c2000430481101002800c32400862623110400100400219bc010708a1008080320416001a88804109ce05041097041080839eb0f78401c9c38084012ad0678465aa879899d883010d0a846765746888676f312e32312e36856c696e7578a04d3c8cca805e07a07e9cc74a0b5891629f26bec5ed54b74867ff0f77bcc994b38800000000000000000da002a352293855b89564efc797e98f05368f9d42d0a99be7dadf6d45165eaaf0f0".to_string()); - // headers.insert(10399992, "0xf90236a0000f7814e0558a13469620a059eff4510844d8129d2bd0f814bcbae62adff515a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794455e5aa18469bc6ccef49594645666c587a3a71ba06ef1804556d1e997392ae8ee19e4abf930fed4ecd7199f6f28e5450cae49835da0e96e520730416715728f451bc12e7e348d08c6dc84e42716833dc36b0c6b49c4a0624b8ee1e6e66f17ae42630abeb8fd1cc69c91b3d9bb9c83d6ef2376f8620dc2b9010004000008890100000204208001a10000400210440400004808040410000410420050006000002000180013001440840000020800806040200010051002240210800205004440208000002209402000098200100020042108001004040500002080020000320000800061408000d008090800440004100000482a0010014420008020830401840000800000000f000000000100004210208041051224430000008300008144021000080109e00004042524810800010028200400802a20200000420080060800a00100032010041203081000000200802200000004301010620101100000000010080c000300028804004000000012888000002800002085020080839eb0f88401c9c380836fba078465aa87a499d883010d0a846765746888676f312e32312e36856c696e7578a05cdb41adf931d8a929aaf09f6a825be65513d809e167144bcbec60eabf7922a58800000000000000000ea0a4ad1832a56ef60e6b49323c6ce4221e5524d11aca2c35623b324d094b5541f0".to_string()); - // headers.insert(10399993, "0xf90237a0a4928d67f0c66d5c62a44d2c180badca94ea2aa3bf91f25f97d5a5039d9b812ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479462c8bcec31584187f69295294fbb7620d2e0cd72a01b9b14e361177b5fcde1e8b1cb95b07dccd1bcab35157958e1b5bc4a4b1ad9e3a09897276962157a75b5ddf8b44cd46c1821e36c4fc733ad9706f8f3a14d2778bea066378d7d59d4d3800f512077e63e054274841411de3909a25aeb098bbc342fb1b90100842100082001400010142e0a8ba10100400820420002083004b110100004102286902224048461001800016884042088806078049220420406001318462400301012265a850e008044000a0a800082204481000032c6011110408400cb20682480020002061010d00148408020100801181885c0461406005008001600002040821442040004804050400042038001414402840b423480c8401310f040800000ca000680940030506b0889400104060b96910a0011c04008018600c3140049004208c16220014001000220b0185600080040401006a000100000080210086200ad1048008a1480088c00000020008e02000010009a88015044800240c48cc00480839eb0f98401c9c380836fea688465aa87b09ad983010d09846765746889676f312e32302e3133856c696e7578a0d5c0c49915e6584d0749c52b49716a3fb4b552a0e837253b037498584686036a8800000000000000000ea00ba5704b8908ebfc357a7d939e111750e5e489d7480e8f8f086bf7cc9a256bd4".to_string()); - // headers.insert(10399994, "0xf90236a089a45b58b24fb782ee50cf5b8d116934acaec3e67527713d33cfb114f1736dcfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f36f155486299ecaff2d4f5160ed5114c1f66000a09d2cd16c62f80864a2599183efd95156b58791ebf7464594385daeb202e57dcfa015fb8fd8d2d91227211208562f9bbc905c6cd09be95187ff7f455d5b472e6bcda0899e91c5a0c5082e5275f11d5c7ae263d39b605cd0023e249177572d4088c247b901000621180a20014ac0601c004681a1105c91d844c22600185307110510060c119206908402064021405c0019a804448ba22842c67092a0634103109700522c6432104e442ae40d80d96910025e028c80a146010001b26c818580048684912548608116008886760a9036409ac080920801081884e824100548543a52b4c08e30c582b203840941215030673130435001918401de03ef1d40c8504572706022116003a014ec65283e1003008942880084212e09080201c0408201c1486f6880d8015218d042341a0a50004223b00c570209060060220088431001c0080640026240511c4000080000698901d2b8a840801c2a0154185ec8c04148c800141004021080839eb0fa8401c9c38083fe4eaf8465aa87d499d883010d0a846765746888676f312e32312e36856c696e7578a05625df0bccfd09cb146fc3a90fd7e8befbb1c8476ad0ad7345638c93538f65d78800000000000000000ea06e3d4e738fdb774f4c872d5187168f26df7d71a3086b35692d26c6a3bf7ce734".to_string()); - // headers.insert(10399995, "0xf90236a0c69a0d458b1ea41c72d0a9a43f45cd947e681e7a7c33e1dc3a0fd8abc0f82d0fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794455e5aa18469bc6ccef49594645666c587a3a71ba0094793b132c386d1ca31f83204a5ffa2ccef4edcc3fbffef39153aa52a1f31a0a0dee897271be94192b76eb37c54417c529f095ff1f32f6cbbe4695641855d3feea0456bd3352507c5f327f04f9c63244569af5d17ab5b576693e868a309c32cc54ab901000400000a30014a8000140242012100088000080100028800021000180404000a009000000c100100180041000004008000008004920041000020110002a0403014020042000420084410000b00000008442101082048251000002600010002340402010402000280004100a400001880280884c04014000104002094040820008a16021000000100104610104b0004080001010040108080504120105004000006a00000041010100020894010000010260a000001a040400081004a048040800208902a00000010040230200842000802200000c08000000040001200002200191004200200044822010002a0008204000000105a800004000800000004120080839eb0fb8401c9c38083efc6ff8465aa87e099d883010d0a846765746888676f312e32312e36856c696e7578a0147c52f02f979f18d2b3bb9ef4c149f0c08183dbc6c3f7787f431d0f77e2a20e8800000000000000000fa0adda430f291ebd8b29300dc152eb01614a3e12a54ec2e85fb6f2b0e8862d95a2".to_string()); - // headers.insert(10399996, "0xf90236a036508f57fc618c0eb97f575dea291b029c8fe7dabda8ccadb50f67bc6dc7f6c8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794000095e79eac4d76aab57cb2c1f091d553b36ca0a01d7a5880ff6993159108cda8d8d001fd3c60d21b43901dcb3196b14cfd3d3ebba016b549e2cfe2da964f3ca90c02b85e76263cb7057f9121462cbb7914f8e8a96fa0e840f3d545f932d5bda765791bc958439b382623f7c6dc4db8918b9574e4306fb901000000000800004aa100100002000100084088000000001c400290011800040022028000000000010008002800000420842802800012000100001015001020403412128000600408104110000a8000820044210000004001009008000400000a20000210042700001000420080000408000a0800c0203004000403001000082040a212000000000100104010380000000000010082401400c05041a00040800000028000400020100006009002000000000000008001004080008100222080800002080022000002000002202008d2020906000000048802000040820204002200001200000000004100020030a0000004020000184a080001100800000005028080839eb0fc8401c9c38083b9bf718465aa87ec99d883010d09846765746888676f312e32312e35856c696e7578a032bf691f17cfacbdf561efe601596f5ecda83dd1e3561ab6ef20dbc88d6bfd3a88000000000000000010a0c439b85dd1dc29e603e6dea16ae1608e69ea660122e67f9a138d994dfb849f7b".to_string()); - // headers.insert(10399997, "0xf90227a0ab7d0c58b9c65dfe639c2f211419ae348a5addf750dee4251e333d05b9963e4ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794c6e2459991bfe27cca6d86722f35da23a1e4cb97a0111aba04a60a5c9b12a8ffdb2c25c559a07bff9bcd1fca0def062505ba20c814a07fc3a0fa37591d62f85ef4a6d41c603a28bf406c7b9f9708981641489833358ba02163dad73e78112d9b95112d0586deb63cdd6011b035db341673c997fef149eab901001523000a00114ec00014040ab121000c00880002040018640210011a810c0002969090060404214258002dcd00148080a142c050920663040030170052a4603010120018c40c20994258121fa220a2614f010108a35c201096008604912042780002000586040081024018a04082d882bc088cda401004184e02f314020820808212022083000108104010150380014180013c93e01482e850413150c004022017a01080148110120b408d42800400292411490203f440800dc5026b2180db804388c0020a00ec00090220b50856434806400008b08810100850480244006300251042210a008409a8050080a0008824228014d05e8880410e880c0400e6220080839eb0fd8401c9c38083eb6b288465aa88048a4e65746865726d696e64a0bf9288229d7fcae357296a6625ab4544e09bf51bd06038931bf7c50e443df6f788000000000000000010a05636ee17cad0dcfe4b825748afa13954cd23ab282c1b8a1ea3f3182452bc6a0b".to_string()); - // headers.insert(10399998, "0xf9023ca0453e6e9c59cc79225484522372d91892467b92f93de4b8f959fa103c4d66fd48a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b636a68f834b4d75af9edc5fb0138bb4758ed293a0e18ae94924ff9b4e00d89c68c6b1877ab5fcb42ec624cab0854bad2d25bb864fa0b22db3a12150f67635470138f8310d4ae2b730f25991abde493ca0e313ddac90a06d98daccfe6d2d8864d8695efad9ba54d90007ff01102314412a4048b308eaebb901000600000820234a800834040a0721004880100440c42208494214041a42141022009030450d4011001e0403a0408400880428c000924651008200130092244030310a02420d040220541200ab0020840044118000216c80100400064881010222080200044222008890543084024048000108c4c06030040405002090409820028216520200000500326810100340000040109480001004c010456011450001000288040434201810000089c00003010007100001a080400280a10046248040002208c00240000204000a61200842204806440020c0800001004040024042600001b810004d00001808010000a480801c004040107a860001800100010886022480839eb0fe8401c9c3808353073d8465aa88109f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a01546662902dd3009dc02026e83490ef770422479b77a2956d77447cf04115fd188000000000000000011a02e543617a0f520e23d7c36e89cbcceccead71bfe74bfc01c2038c4c59e252923".to_string()); - // headers.insert(10399999, "0xf90236a0c8d36d24d81f2e36a0f8c1f36f8add24dc8714320a78b17d07b25424e097ffa2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f97e180c050e5ab072211ad2c213eb5aee4df134a019f55a7f1fe370a77267d5c3327474ab2071802f7038a825a79c4bf78544c579a04eb5a4126fc6adc987334d3cb30a0785acf1dc1ca0019b5416288f839184060ea07274312f7366d6e50308a6bf1b2534e9eef27fc1f905125aa7b5f6d7625192deb901000422000d48014a88021400028165080800fc41402a04184203d194180484105242d004620200014018001b20144480808042a040b0f041600a101750122c4238907206004415208c4850221a802a88214e018400326c61088c9c041581060262c006a08c16088098a468408012000c21581804c8049005004e2a5010092a20808e13d31401802120384012114f000000e84124056a15a0e85145e360468200408388809c44203300022189604000042404100000032840a000818822608000008208d0023c012801000622a00c520208170000000080601000c0e42218106ac111340020000020690c000328a2804004020004105aa800510c6840001405029080839eb0ff8401c9c380838ee43e8465aa882899d883010d0a846765746888676f312e32312e36856c696e7578a053b87a12a76bb28a417cbda3acc6b241d7d849717140be043b8c1a2f8cb41ecb88000000000000000010a09c34780aa89b7419c9e7f57494d29e8c557e64d0cf04c3db57092eee73e7af00".to_string()); - // headers.insert(10400000, "0xf9023ca0792521e7510ba898aff41504d3ef2214619b81bcd731c38b2ee010228eebaabfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b64a30399f7f6b0c154c2e7af0a3ec7b0a5b131aa00aa14102830b3bb9ef07b0ed181062ed9ffc671d60b53eedb6d86ad85d3d4f50a0bc85c0c84815c05fd4f6d7139e592064716addb4e1a79e3322d7f08238768969a070806f936670ae9d136239961c487f752467c451ff1709af94e5254128bdaf14b901000460020e880b4a81007400038725009990884202a741984a4211011a84a4111216904c000700010068200ba80906b9c814228215925641400a129780122c44b0b17a080c4605a0a14854103e060898a84605001a3664406c060825c4a12642200084048d062c02853440588031012a00006a94c9281885000622d014080a2086863b821e25042500124490104302010058851485ac1d00c89255327009ea004553a2200a6420b2140a408940820004080670001112c0448004c1c96320a64a0a0288d2f21e240a40080e2bb41b571f081708c0004490e01020c04d034854624011104029004400198800130aa200c27462b214107ac0804104c840152811021480839eb1008401c9c3808386481f8465aa88349f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a00fd71f682d35bd1cb9c06bd2e6c637a79bb5cb25715ef90031c3c4cae99acfad88000000000000000010a0c8b02416e58787efe88ec75d1bae2a4f5ca2adea51b15477700d835bb1923871".to_string()); + headers.insert(10399990, "f90266a045adb684cb5458019c496206c1383894c360fe969a1028ba44955eadfa585cc5a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b636a68f834b4d75af9edc5fb0138bb4758ed293a01db2388923f7c78680b4a46bae725637013d74ad787ec5c861d3ade3df882d81a093586eb5f2781ded334a2a03d178f41dc06f271d7f1ff429e4da6ef42d12a773a0361590775fea7857cc048b9324c03e96f287199803ce1440ff1e12c5c6008049b901000420000a200308000025201005a30400008962800402185dc600144280040082221400010101200458002b0d88008028004206808408400402108f0812246200240a204365100109051c082a020081204200001060440090044044448100082100028001060640c011401a802000090331000408243804009402201240802082820403801141050a4a00208283202050000f10058894008000411050512800220a200000042275800280894080000202460040030000408001ce00282400000002a8c24210000200014a30040015020b04800020608800000850440240c06100011002000000200988001800000880128a050400329081c144080a040800000480839eb0f68401c9c380836f9a8e8465aa87809f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a0c653e1c1cee990147f4439776cc3ead6f175e081998c33c93da41653112e89ce8800000000000000000da039db3f9d1fe0756e5aef4e2f0241ad957e999e49c981809c018425d0080f6cd2830400008405320000a0713ce910d12e99ba96492ff2f6411d4e0a3e567ab419e92e60cf5fc4aa74db7a".to_string()); + headers.insert(10399991, "f90261a02ef5bd5264f472d821fb950241aa2bbe83f885fea086b4f58fccb9c9b948adcfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479494750381be1aba0504c666ee1db118f68f0780d4a01fa9a7ad0deb9e4c0762aed5a02a0eb0be12864363eb2f6434ad55454352533ea0e4be7e5ed75566d7ab90c1610d81a8f38f3b56b3c338f211646ae32aebd4e690a0f8973cc47d1dac1a9f71fec14ec19dcde2ad1e6c6b6336e42b1da0322a6c7581b901007432022a09014808001c000b91ab000c408a444206011a6200994018c004101a06d1c003460021145888092814458890000a020092b4e4c0023a3710332c01329252440a050520886880061f020882214f91000e2a64a50a8024444c832446718206009dc60020a0a7e158a104002800080884d0041085084aa83010012ae2c88210a39401140080b04100004b200700902184c3ea95a1c8401532f944820040276e5b884c9b3290120009408b0604a5a401281a41ec508000c2886b280a488a2208d0222800a801080622b00a7602091c2000430481101002800c32400862623110400100400219bc010708a1008080320416001a88804109ce05041097041080839eb0f78401c9c38084012ad0678465aa879899d883010d0a846765746888676f312e32312e36856c696e7578a04d3c8cca805e07a07e9cc74a0b5891629f26bec5ed54b74867ff0f77bcc994b38800000000000000000da002a352293855b89564efc797e98f05368f9d42d0a99be7dadf6d45165eaaf0f0830600008405300000a0f8dbbd84390d2bf3b34c8f581d42e08dd907764e46972aad56cac48cbb650473".to_string()); + headers.insert(10399992, "f9025da0000f7814e0558a13469620a059eff4510844d8129d2bd0f814bcbae62adff515a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794455e5aa18469bc6ccef49594645666c587a3a71ba06ef1804556d1e997392ae8ee19e4abf930fed4ecd7199f6f28e5450cae49835da0e96e520730416715728f451bc12e7e348d08c6dc84e42716833dc36b0c6b49c4a0624b8ee1e6e66f17ae42630abeb8fd1cc69c91b3d9bb9c83d6ef2376f8620dc2b9010004000008890100000204208001a10000400210440400004808040410000410420050006000002000180013001440840000020800806040200010051002240210800205004440208000002209402000098200100020042108001004040500002080020000320000800061408000d008090800440004100000482a0010014420008020830401840000800000000f000000000100004210208041051224430000008300008144021000080109e00004042524810800010028200400802a20200000420080060800a00100032010041203081000000200802200000004301010620101100000000010080c000300028804004000000012888000002800002085020080839eb0f88401c9c380836fba078465aa87a499d883010d0a846765746888676f312e32312e36856c696e7578a05cdb41adf931d8a929aaf09f6a825be65513d809e167144bcbec60eabf7922a58800000000000000000ea0a4ad1832a56ef60e6b49323c6ce4221e5524d11aca2c35623b324d094b5541f0808405300000a0bb3eb95012cfbeea1e030903f186a1df253e26cc6f0dd5495b677fefabb73c30".to_string()); + headers.insert(10399993, "f90261a0a4928d67f0c66d5c62a44d2c180badca94ea2aa3bf91f25f97d5a5039d9b812ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479462c8bcec31584187f69295294fbb7620d2e0cd72a01b9b14e361177b5fcde1e8b1cb95b07dccd1bcab35157958e1b5bc4a4b1ad9e3a09897276962157a75b5ddf8b44cd46c1821e36c4fc733ad9706f8f3a14d2778bea066378d7d59d4d3800f512077e63e054274841411de3909a25aeb098bbc342fb1b90100842100082001400010142e0a8ba10100400820420002083004b110100004102286902224048461001800016884042088806078049220420406001318462400301012265a850e008044000a0a800082204481000032c6011110408400cb20682480020002061010d00148408020100801181885c0461406005008001600002040821442040004804050400042038001414402840b423480c8401310f040800000ca000680940030506b0889400104060b96910a0011c04008018600c3140049004208c16220014001000220b0185600080040401006a000100000080210086200ad1048008a1480088c00000020008e02000010009a88015044800240c48cc00480839eb0f98401c9c380836fea688465aa87b09ad983010d09846765746889676f312e32302e3133856c696e7578a0d5c0c49915e6584d0749c52b49716a3fb4b552a0e837253b037498584686036a8800000000000000000ea00ba5704b8908ebfc357a7d939e111750e5e489d7480e8f8f086bf7cc9a256bd4830c000084052a0000a072071503b19e199e9dceaffce80a9320b2dfea37d069b37c49224edd32ba5932".to_string()); + headers.insert(10399994, "f90260a089a45b58b24fb782ee50cf5b8d116934acaec3e67527713d33cfb114f1736dcfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f36f155486299ecaff2d4f5160ed5114c1f66000a09d2cd16c62f80864a2599183efd95156b58791ebf7464594385daeb202e57dcfa015fb8fd8d2d91227211208562f9bbc905c6cd09be95187ff7f455d5b472e6bcda0899e91c5a0c5082e5275f11d5c7ae263d39b605cd0023e249177572d4088c247b901000621180a20014ac0601c004681a1105c91d844c22600185307110510060c119206908402064021405c0019a804448ba22842c67092a0634103109700522c6432104e442ae40d80d96910025e028c80a146010001b26c818580048684912548608116008886760a9036409ac080920801081884e824100548543a52b4c08e30c582b203840941215030673130435001918401de03ef1d40c8504572706022116003a014ec65283e1003008942880084212e09080201c0408201c1486f6880d8015218d042341a0a50004223b00c570209060060220088431001c0080640026240511c4000080000698901d2b8a840801c2a0154185ec8c04148c800141004021080839eb0fa8401c9c38083fe4eaf8465aa87d499d883010d0a846765746888676f312e32312e36856c696e7578a05625df0bccfd09cb146fc3a90fd7e8befbb1c8476ad0ad7345638c93538f65d78800000000000000000ea06e3d4e738fdb774f4c872d5187168f26df7d71a3086b35692d26c6a3bf7ce734830600008405300000a05ca81e9c05ea8b4ccd7a21aaf7aacec158f256d601d16e40839c60d98afa7fc0".to_string()); + headers.insert(10399995, "f9025da0c69a0d458b1ea41c72d0a9a43f45cd947e681e7a7c33e1dc3a0fd8abc0f82d0fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794455e5aa18469bc6ccef49594645666c587a3a71ba0094793b132c386d1ca31f83204a5ffa2ccef4edcc3fbffef39153aa52a1f31a0a0dee897271be94192b76eb37c54417c529f095ff1f32f6cbbe4695641855d3feea0456bd3352507c5f327f04f9c63244569af5d17ab5b576693e868a309c32cc54ab901000400000a30014a8000140242012100088000080100028800021000180404000a009000000c100100180041000004008000008004920041000020110002a0403014020042000420084410000b00000008442101082048251000002600010002340402010402000280004100a400001880280884c04014000104002094040820008a16021000000100104610104b0004080001010040108080504120105004000006a00000041010100020894010000010260a000001a040400081004a048040800208902a00000010040230200842000802200000c08000000040001200002200191004200200044822010002a0008204000000105a800004000800000004120080839eb0fb8401c9c38083efc6ff8465aa87e099d883010d0a846765746888676f312e32312e36856c696e7578a0147c52f02f979f18d2b3bb9ef4c149f0c08183dbc6c3f7787f431d0f77e2a20e8800000000000000000fa0adda430f291ebd8b29300dc152eb01614a3e12a54ec2e85fb6f2b0e8862d95a2808405300000a0ac815c7a815300e1c4d8c3a82287d225cb6a2e590dc1f8a3e32a6b2637b312b8".to_string()); + headers.insert(10399996, "f90260a036508f57fc618c0eb97f575dea291b029c8fe7dabda8ccadb50f67bc6dc7f6c8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794000095e79eac4d76aab57cb2c1f091d553b36ca0a01d7a5880ff6993159108cda8d8d001fd3c60d21b43901dcb3196b14cfd3d3ebba016b549e2cfe2da964f3ca90c02b85e76263cb7057f9121462cbb7914f8e8a96fa0e840f3d545f932d5bda765791bc958439b382623f7c6dc4db8918b9574e4306fb901000000000800004aa100100002000100084088000000001c400290011800040022028000000000010008002800000420842802800012000100001015001020403412128000600408104110000a8000820044210000004001009008000400000a20000210042700001000420080000408000a0800c0203004000403001000082040a212000000000100104010380000000000010082401400c05041a00040800000028000400020100006009002000000000000008001004080008100222080800002080022000002000002202008d2020906000000048802000040820204002200001200000000004100020030a0000004020000184a080001100800000005028080839eb0fc8401c9c38083b9bf718465aa87ec99d883010d09846765746888676f312e32312e35856c696e7578a032bf691f17cfacbdf561efe601596f5ecda83dd1e3561ab6ef20dbc88d6bfd3a88000000000000000010a0c439b85dd1dc29e603e6dea16ae1608e69ea660122e67f9a138d994dfb849f7b830c000084052a0000a036b203eace2145f2548866b1800b04bb7fbd0aac31d4f221149f9d0e98d6fd21".to_string()); + headers.insert(10399997, "f90251a0ab7d0c58b9c65dfe639c2f211419ae348a5addf750dee4251e333d05b9963e4ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794c6e2459991bfe27cca6d86722f35da23a1e4cb97a0111aba04a60a5c9b12a8ffdb2c25c559a07bff9bcd1fca0def062505ba20c814a07fc3a0fa37591d62f85ef4a6d41c603a28bf406c7b9f9708981641489833358ba02163dad73e78112d9b95112d0586deb63cdd6011b035db341673c997fef149eab901001523000a00114ec00014040ab121000c00880002040018640210011a810c0002969090060404214258002dcd00148080a142c050920663040030170052a4603010120018c40c20994258121fa220a2614f010108a35c201096008604912042780002000586040081024018a04082d882bc088cda401004184e02f314020820808212022083000108104010150380014180013c93e01482e850413150c004022017a01080148110120b408d42800400292411490203f440800dc5026b2180db804388c0020a00ec00090220b50856434806400008b08810100850480244006300251042210a008409a8050080a0008824228014d05e8880410e880c0400e6220080839eb0fd8401c9c38083eb6b288465aa88048a4e65746865726d696e64a0bf9288229d7fcae357296a6625ab4544e09bf51bd06038931bf7c50e443df6f788000000000000000010a05636ee17cad0dcfe4b825748afa13954cd23ab282c1b8a1ea3f3182452bc6a0b830a00008405300000a055bc73c49ce77e6b083e0aaf908ffa7232de633942a89c2f2155b80b7999a68c".to_string()); + headers.insert(10399998, "f90266a0453e6e9c59cc79225484522372d91892467b92f93de4b8f959fa103c4d66fd48a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b636a68f834b4d75af9edc5fb0138bb4758ed293a0e18ae94924ff9b4e00d89c68c6b1877ab5fcb42ec624cab0854bad2d25bb864fa0b22db3a12150f67635470138f8310d4ae2b730f25991abde493ca0e313ddac90a06d98daccfe6d2d8864d8695efad9ba54d90007ff01102314412a4048b308eaebb901000600000820234a800834040a0721004880100440c42208494214041a42141022009030450d4011001e0403a0408400880428c000924651008200130092244030310a02420d040220541200ab0020840044118000216c80100400064881010222080200044222008890543084024048000108c4c06030040405002090409820028216520200000500326810100340000040109480001004c010456011450001000288040434201810000089c00003010007100001a080400280a10046248040002208c00240000204000a61200842204806440020c0800001004040024042600001b810004d00001808010000a480801c004040107a860001800100010886022480839eb0fe8401c9c3808353073d8465aa88109f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a01546662902dd3009dc02026e83490ef770422479b77a2956d77447cf04115fd188000000000000000011a02e543617a0f520e23d7c36e89cbcceccead71bfe74bfc01c2038c4c59e252923830400008405340000a0cf2322ccda5e2a9bd8dd40c25158ef5b07e2a681ddce97ebe7201793a66d98e8".to_string()); + headers.insert(10399999, "f90260a0c8d36d24d81f2e36a0f8c1f36f8add24dc8714320a78b17d07b25424e097ffa2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f97e180c050e5ab072211ad2c213eb5aee4df134a019f55a7f1fe370a77267d5c3327474ab2071802f7038a825a79c4bf78544c579a04eb5a4126fc6adc987334d3cb30a0785acf1dc1ca0019b5416288f839184060ea07274312f7366d6e50308a6bf1b2534e9eef27fc1f905125aa7b5f6d7625192deb901000422000d48014a88021400028165080800fc41402a04184203d194180484105242d004620200014018001b20144480808042a040b0f041600a101750122c4238907206004415208c4850221a802a88214e018400326c61088c9c041581060262c006a08c16088098a468408012000c21581804c8049005004e2a5010092a20808e13d31401802120384012114f000000e84124056a15a0e85145e360468200408388809c44203300022189604000042404100000032840a000818822608000008208d0023c012801000622a00c520208170000000080601000c0e42218106ac111340020000020690c000328a2804004020004105aa800510c6840001405029080839eb0ff8401c9c380838ee43e8465aa882899d883010d0a846765746888676f312e32312e36856c696e7578a053b87a12a76bb28a417cbda3acc6b241d7d849717140be043b8c1a2f8cb41ecb88000000000000000010a09c34780aa89b7419c9e7f57494d29e8c557e64d0cf04c3db57092eee73e7af00830a00008405320000a0b30e828e1ecadc3c7b194c582d1cc0896eeb2493025282153e4fe0df7419e589".to_string()); + headers.insert(10400000, "f90263a0792521e7510ba898aff41504d3ef2214619b81bcd731c38b2ee010228eebaabfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b64a30399f7f6b0c154c2e7af0a3ec7b0a5b131aa00aa14102830b3bb9ef07b0ed181062ed9ffc671d60b53eedb6d86ad85d3d4f50a0bc85c0c84815c05fd4f6d7139e592064716addb4e1a79e3322d7f08238768969a070806f936670ae9d136239961c487f752467c451ff1709af94e5254128bdaf14b901000460020e880b4a81007400038725009990884202a741984a4211011a84a4111216904c000700010068200ba80906b9c814228215925641400a129780122c44b0b17a080c4605a0a14854103e060898a84605001a3664406c060825c4a12642200084048d062c02853440588031012a00006a94c9281885000622d014080a2086863b821e25042500124490104302010058851485ac1d00c89255327009ea004553a2200a6420b2140a408940820004080670001112c0448004c1c96320a64a0a0288d2f21e240a40080e2bb41b571f081708c0004490e01020c04d034854624011104029004400198800130aa200c27462b214107ac0804104c840152811021480839eb1008401c9c3808386481f8465aa88349f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a00fd71f682d35bd1cb9c06bd2e6c637a79bb5cb25715ef90031c3c4cae99acfad88000000000000000010a0c8b02416e58787efe88ec75d1bae2a4f5ca2adea51b15477700d835bb1923871808405360000a047b14fc563202a2e1c1e14c1f15da41f74ffdefaca5e65a4f138875938074032".to_string()); headers } diff --git a/crates/types/src/datalake/block_sampled.rs b/crates/types/src/datalake/block_sampled.rs index 7b9068d0..39434059 100644 --- a/crates/types/src/datalake/block_sampled.rs +++ b/crates/types/src/datalake/block_sampled.rs @@ -138,14 +138,10 @@ fn serialize_sampled_property(sampled_property: &str) -> Vec { match collection { Collection::Header => { - if let Some(index) = HeaderField::from_str(tokens[1].to_uppercase().as_str()) + let index = HeaderField::from_str(tokens[1].to_uppercase().as_str()) .unwrap() - .to_index() - { - serialized.push(index as u8); - } else { - panic!("Invalid header field"); - } + .to_index(); + serialized.push(index as u8); } Collection::Account | Collection::Storage => { // if !is_address(tokens[1]) { diff --git a/crates/types/tests/block_sampled.rs b/crates/types/tests/block_sampled.rs index 5e241ec1..73ce8943 100644 --- a/crates/types/tests/block_sampled.rs +++ b/crates/types/tests/block_sampled.rs @@ -41,8 +41,18 @@ fn test_block_datalake_for_storage() { #[test] fn test_blocksampled_compiler() { let block_datalake = - BlockSampledDatalake::new(10399990, 10399990, "header.base_fee_per_gas".to_string(), 1); + BlockSampledDatalake::new(10399990, 10399995, "header.base_fee_per_gas".to_string(), 1); let data_points = block_datalake.compile().unwrap(); - assert_eq!(data_points, vec![DataPoint::Str("13".to_string())]); + assert_eq!( + data_points, + vec![ + DataPoint::Str("13".to_string()), + DataPoint::Str("13".to_string()), + DataPoint::Str("14".to_string()), + DataPoint::Str("14".to_string()), + DataPoint::Str("14".to_string()), + DataPoint::Str("15".to_string()), + ] + ); } From 0266e4c043c2766b0af7039564c40a85f452fa46 Mon Sep 17 00:00:00 2001 From: Pia Date: Fri, 2 Feb 2024 02:14:31 +0800 Subject: [PATCH 3/4] feat: account compiler done --- crates/common/src/block/account.rs | 48 +++++++++++++++++ crates/common/tests/account.rs | 60 ++++++++++++++++++++++ crates/common/tests/lib.rs | 3 ++ crates/fetcher/src/example_data.rs | 23 +++++++++ crates/types/src/compiler/block_sampled.rs | 43 ++++++++++------ crates/types/tests/block_sampled.rs | 22 +++++++- 6 files changed, 181 insertions(+), 18 deletions(-) create mode 100644 crates/common/tests/account.rs create mode 100644 crates/common/tests/lib.rs diff --git a/crates/common/src/block/account.rs b/crates/common/src/block/account.rs index 49ee3263..fc086065 100644 --- a/crates/common/src/block/account.rs +++ b/crates/common/src/block/account.rs @@ -1,5 +1,8 @@ use std::str::FromStr; +use alloy_primitives::{hex, FixedBytes, U256}; +use alloy_rlp::{Decodable, Encodable as _, RlpDecodable, RlpEncodable}; + #[derive(Debug)] pub enum AccountField { Nonce, @@ -8,6 +11,41 @@ pub enum AccountField { CodeHash, } +#[derive(Debug, RlpDecodable, RlpEncodable, PartialEq)] +pub struct Account { + pub nonce: u64, + pub balance: U256, + pub storage_root: FixedBytes<32>, + pub code_hash: FixedBytes<32>, +} + +impl Account { + pub fn new( + nonce: u64, + balance: U256, + storage_root: FixedBytes<32>, + code_hash: FixedBytes<32>, + ) -> Self { + Account { + nonce, + balance, + storage_root, + code_hash, + } + } + + pub fn rlp_encode(&self) -> String { + let mut buffer = Vec::::new(); + self.encode(&mut buffer); + hex::encode(buffer) + } + + pub fn rlp_decode(rlp: &str) -> Self { + let decoded = ::decode(&mut hex::decode(rlp).unwrap().as_slice()).unwrap(); + decoded + } +} + impl FromStr for AccountField { type Err = (); @@ -51,3 +89,13 @@ impl AccountField { } } } + +pub fn decode_account_field(account_rlp: &str, field: AccountField) -> String { + let decoded = ::decode(&mut hex::decode(account_rlp).unwrap().as_slice()).unwrap(); + match field { + AccountField::Nonce => decoded.nonce.to_string(), + AccountField::Balance => decoded.balance.to_string(), + AccountField::StorageRoot => decoded.storage_root.to_string(), + AccountField::CodeHash => decoded.code_hash.to_string(), + } +} diff --git a/crates/common/tests/account.rs b/crates/common/tests/account.rs new file mode 100644 index 00000000..de22c7ae --- /dev/null +++ b/crates/common/tests/account.rs @@ -0,0 +1,60 @@ +use std::str::FromStr; + +use alloy_primitives::{FixedBytes, U256}; +use common::block::account::Account; + +#[test] +fn test_get_account_rlp() { + // let account_addr = "0x7b2f05ce9ae365c3dbf30657e2dc6449989e83d6"; + let account = Account::new( + 1, + U256::from(0), + FixedBytes::from_str("0x1c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185") + .unwrap(), + FixedBytes::from_str("0xcd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c") + .unwrap(), + ); + let account_rlp = account.rlp_encode(); + assert_eq!(account_rlp, "f8440180a01c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185a0cd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c"); + let account = Account::new( + 2, + U256::from(0), + FixedBytes::from_str("0x1c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185") + .unwrap(), + FixedBytes::from_str("0xcd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c") + .unwrap(), + ); + let account_rlp = account.rlp_encode(); + assert_eq!(account_rlp, "f8440280a01c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185a0cd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c"); + let account = Account::new( + 2, + U256::from(0x1), + FixedBytes::from_str("0x1c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185") + .unwrap(), + FixedBytes::from_str("0xcd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c") + .unwrap(), + ); + let account_rlp = account.rlp_encode(); + assert_eq!(account_rlp, "f8440201a01c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185a0cd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c"); +} + +#[test] +fn test_decode_account_rlp() { + let account_rlp = "f8440180a01c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185a0cd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c"; + let account = Account::rlp_decode(account_rlp); + assert_eq!( + account, + Account::new( + 1, + U256::from(0), + FixedBytes::from_str( + "0x1c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185" + ) + .unwrap(), + FixedBytes::from_str( + "0xcd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c" + ) + .unwrap() + ) + ); +} diff --git a/crates/common/tests/lib.rs b/crates/common/tests/lib.rs new file mode 100644 index 00000000..ca8aed9a --- /dev/null +++ b/crates/common/tests/lib.rs @@ -0,0 +1,3 @@ +pub mod account; +pub mod header; +pub mod utils; diff --git a/crates/fetcher/src/example_data.rs b/crates/fetcher/src/example_data.rs index 7287caf7..83a645b7 100644 --- a/crates/fetcher/src/example_data.rs +++ b/crates/fetcher/src/example_data.rs @@ -17,3 +17,26 @@ pub fn get_example_headers() -> HashMap { headers.insert(10400000, "f90263a0792521e7510ba898aff41504d3ef2214619b81bcd731c38b2ee010228eebaabfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794b64a30399f7f6b0c154c2e7af0a3ec7b0a5b131aa00aa14102830b3bb9ef07b0ed181062ed9ffc671d60b53eedb6d86ad85d3d4f50a0bc85c0c84815c05fd4f6d7139e592064716addb4e1a79e3322d7f08238768969a070806f936670ae9d136239961c487f752467c451ff1709af94e5254128bdaf14b901000460020e880b4a81007400038725009990884202a741984a4211011a84a4111216904c000700010068200ba80906b9c814228215925641400a129780122c44b0b17a080c4605a0a14854103e060898a84605001a3664406c060825c4a12642200084048d062c02853440588031012a00006a94c9281885000622d014080a2086863b821e25042500124490104302010058851485ac1d00c89255327009ea004553a2200a6420b2140a408940820004080670001112c0448004c1c96320a64a0a0288d2f21e240a40080e2bb41b571f081708c0004490e01020c04d034854624011104029004400198800130aa200c27462b214107ac0804104c840152811021480839eb1008401c9c3808386481f8465aa88349f496c6c756d696e61746520446d6f63726174697a6520447374726962757465a00fd71f682d35bd1cb9c06bd2e6c637a79bb5cb25715ef90031c3c4cae99acfad88000000000000000010a0c8b02416e58787efe88ec75d1bae2a4f5ca2adea51b15477700d835bb1923871808405360000a047b14fc563202a2e1c1e14c1f15da41f74ffdefaca5e65a4f138875938074032".to_string()); headers } + +pub fn get_example_accounts() -> HashMap> { + let mut accounts = HashMap::new(); + let mut account_10399990 = HashMap::new(); + account_10399990.insert( + "0x7b2f05ce9ae365c3dbf30657e2dc6449989e83d6".to_string(), + "f8440180a01c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185a0cd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c".to_string(), + ); + let mut account_10399991 = HashMap::new(); + account_10399991.insert( + "0x7b2f05ce9ae365c3dbf30657e2dc6449989e83d6".to_string(), + "f8440280a01c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185a0cd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c".to_string(), + ); + let mut account_10399992 = HashMap::new(); + account_10399992.insert( + "0x7b2f05ce9ae365c3dbf30657e2dc6449989e83d6".to_string(), + "f8440201a01c35dfde2b62d99d3a74fda76446b60962c4656814bdd7815eb6e5b8be1e7185a0cd4f25236fff0ccac15e82bf4581beb08e95e1b5ba89de6031c75893cd91245c".to_string(), + ); + accounts.insert(10399990, account_10399990); + accounts.insert(10399991, account_10399991); + accounts.insert(10399992, account_10399992); + accounts +} diff --git a/crates/types/src/compiler/block_sampled.rs b/crates/types/src/compiler/block_sampled.rs index 7b6ec82e..b9456ef6 100644 --- a/crates/types/src/compiler/block_sampled.rs +++ b/crates/types/src/compiler/block_sampled.rs @@ -1,8 +1,14 @@ use std::{collections::HashMap, str::FromStr}; use anyhow::Result; -use common::block::header::{decode_header_field, HeaderField}; -use fetcher::{example_data::get_example_headers, memoizer::Memoizer}; +use common::block::{ + account::{decode_account_field, AccountField}, + header::{decode_header_field, HeaderField}, +}; +use fetcher::{ + example_data::{get_example_accounts, get_example_headers}, + memoizer::Memoizer, +}; use crate::datalake::base::DataPoint; @@ -13,8 +19,10 @@ pub fn compile_block_sampled_datalake( sampled_property: &str, increment: usize, ) -> Result> { - let header_example = get_example_headers(); - let memoizer = Memoizer::pre_filled_memoizer(header_example, HashMap::new(), HashMap::new()); + let prefilled_header = get_example_headers(); + let prefilled_account = get_example_accounts(); + let memoizer = + Memoizer::pre_filled_memoizer(prefilled_header, prefilled_account, HashMap::new()); let property_parts: Vec<&str> = sampled_property.split('.').collect(); let collection = property_parts[0]; @@ -39,31 +47,32 @@ pub fn compile_block_sampled_datalake( } "account" => { let account = property_parts[1]; - // let property = property_parts[2]; - // Convert property to AccountField enum variant here + let property = property_parts[2]; + for i in block_range_start..=block_range_end { if i % increment != 0 { continue; } - // let acc = memoizer - // .get_account(i, account)? - // .ok_or(format!("No memoized account for block number: {}", i))?; - // let value = decode_account_field(&acc, &AccountField::YourFieldHere)? - // .ok_or("Decode failed")?; - aggregation_set.push(DataPoint::Str(account.to_string())); + let acc = memoizer.get_rlp_account(i, account.to_string()).unwrap(); + let value = decode_account_field( + &acc, + AccountField::from_str(&property.to_uppercase()).unwrap(), + ); + + aggregation_set.push(DataPoint::Str(value)); } } "storage" => { - // let account = property_parts[1]; + let account = property_parts[1]; let slot = property_parts[2]; for i in block_range_start..=block_range_end { if i % increment != 0 { continue; } - // let value = memoizer - // .get_storage_slot(i, account, slot)? - // .ok_or(format!("No memoized storage slot for block number: {}", i))?; - aggregation_set.push(DataPoint::Str(slot.to_string())); + let value = memoizer + .get_rlp_storage(i, account.to_string(), slot.to_string()) + .unwrap(); + aggregation_set.push(DataPoint::Str(value)); } } _ => todo!(), diff --git a/crates/types/tests/block_sampled.rs b/crates/types/tests/block_sampled.rs index 73ce8943..4d4abeb6 100644 --- a/crates/types/tests/block_sampled.rs +++ b/crates/types/tests/block_sampled.rs @@ -39,7 +39,7 @@ fn test_block_datalake_for_storage() { } #[test] -fn test_blocksampled_compiler() { +fn test_blocksampled_header_compiler() { let block_datalake = BlockSampledDatalake::new(10399990, 10399995, "header.base_fee_per_gas".to_string(), 1); @@ -56,3 +56,23 @@ fn test_blocksampled_compiler() { ] ); } + +#[test] +fn test_blocksampled_account_compiler() { + let block_datalake = BlockSampledDatalake::new( + 10399990, + 10399992, + "account.0x7b2f05ce9ae365c3dbf30657e2dc6449989e83d6.nonce".to_string(), + 1, + ); + + let data_points = block_datalake.compile().unwrap(); + assert_eq!( + data_points, + vec![ + DataPoint::Str("1".to_string()), + DataPoint::Str("2".to_string()), + DataPoint::Str("2".to_string()), + ] + ); +} From aafe10d7140608553fec589eb6bbefdd676bd187 Mon Sep 17 00:00:00 2001 From: Pia Date: Fri, 2 Feb 2024 02:33:26 +0800 Subject: [PATCH 4/4] feat: storage value done --- crates/fetcher/src/example_data.rs | 35 ++++++++++++++++++++++ crates/fetcher/src/memoizer.rs | 8 ++--- crates/types/src/compiler/block_sampled.rs | 13 +++++--- crates/types/tests/block_sampled.rs | 25 ++++++++++++++++ 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/crates/fetcher/src/example_data.rs b/crates/fetcher/src/example_data.rs index 83a645b7..12bcf3ef 100644 --- a/crates/fetcher/src/example_data.rs +++ b/crates/fetcher/src/example_data.rs @@ -40,3 +40,38 @@ pub fn get_example_accounts() -> HashMap accounts.insert(10399992, account_10399992); accounts } + +pub fn get_example_storages() -> HashMap>> { + let mut storages = HashMap::new(); + let mut storage_10399990 = HashMap::new(); + storage_10399990.insert("0x00000000000000adc04c56bf30ac9d3c0aaf14dc".to_string(), { + let mut storage = HashMap::new(); + storage.insert( + "0x0000000000000000000000000000000000000000000000000000000000000000".to_string(), + "0x0000000000000000000000000000000000000000000000000000000000000001".to_string(), + ); + storage + }); + let mut storage_10399991 = HashMap::new(); + storage_10399991.insert("0x00000000000000adc04c56bf30ac9d3c0aaf14dc".to_string(), { + let mut storage = HashMap::new(); + storage.insert( + "0x0000000000000000000000000000000000000000000000000000000000000000".to_string(), + "0x0000000000000000000000000000000000000000000000000000000000000002".to_string(), + ); + storage + }); + let mut storage_10399992 = HashMap::new(); + storage_10399992.insert("0x00000000000000adc04c56bf30ac9d3c0aaf14dc".to_string(), { + let mut storage = HashMap::new(); + storage.insert( + "0x0000000000000000000000000000000000000000000000000000000000000000".to_string(), + "0x0000000000000000000000000000000000000000000000000000000000000001".to_string(), + ); + storage + }); + storages.insert(10399990, storage_10399990); + storages.insert(10399991, storage_10399991); + storages.insert(10399992, storage_10399992); + storages +} diff --git a/crates/fetcher/src/memoizer.rs b/crates/fetcher/src/memoizer.rs index 82136b66..a51dd33e 100644 --- a/crates/fetcher/src/memoizer.rs +++ b/crates/fetcher/src/memoizer.rs @@ -20,7 +20,7 @@ impl Memoizer { pub fn pre_filled_memoizer( headers: HashMap, accounts: HashMap>, - storages: HashMap>>, + storages: HashMap>>, ) -> Memoizer { Memoizer { headers, @@ -39,12 +39,12 @@ impl Memoizer { .and_then(|accounts| accounts.get(&account).cloned()) } - pub fn get_rlp_storage( + pub fn get_storage_value( &self, block_number: usize, account: String, slot: String, - ) -> Option { + ) -> Option { self.storages .get(&block_number) .and_then(|storages| storages.get(&account)) @@ -65,7 +65,7 @@ impl Memoizer { block_number: usize, account: String, slot: String, - value: RlpEncodedValue, + value: String, ) { let storages = self.storages.entry(block_number).or_default(); let slots = storages.entry(account).or_default(); diff --git a/crates/types/src/compiler/block_sampled.rs b/crates/types/src/compiler/block_sampled.rs index b9456ef6..6d9801c4 100644 --- a/crates/types/src/compiler/block_sampled.rs +++ b/crates/types/src/compiler/block_sampled.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, str::FromStr}; +use std::str::FromStr; use anyhow::Result; use common::block::{ @@ -6,7 +6,7 @@ use common::block::{ header::{decode_header_field, HeaderField}, }; use fetcher::{ - example_data::{get_example_accounts, get_example_headers}, + example_data::{get_example_accounts, get_example_headers, get_example_storages}, memoizer::Memoizer, }; @@ -19,10 +19,12 @@ pub fn compile_block_sampled_datalake( sampled_property: &str, increment: usize, ) -> Result> { + // TODO: This is a temporary solution to get the example data later we will add fetcher & memoizer logic let prefilled_header = get_example_headers(); let prefilled_account = get_example_accounts(); + let prefilled_storage = get_example_storages(); let memoizer = - Memoizer::pre_filled_memoizer(prefilled_header, prefilled_account, HashMap::new()); + Memoizer::pre_filled_memoizer(prefilled_header, prefilled_account, prefilled_storage); let property_parts: Vec<&str> = sampled_property.split('.').collect(); let collection = property_parts[0]; @@ -65,13 +67,16 @@ pub fn compile_block_sampled_datalake( "storage" => { let account = property_parts[1]; let slot = property_parts[2]; + for i in block_range_start..=block_range_end { if i % increment != 0 { continue; } + let value = memoizer - .get_rlp_storage(i, account.to_string(), slot.to_string()) + .get_storage_value(i, account.to_string(), slot.to_string()) .unwrap(); + aggregation_set.push(DataPoint::Str(value)); } } diff --git a/crates/types/tests/block_sampled.rs b/crates/types/tests/block_sampled.rs index 4d4abeb6..fdb74cea 100644 --- a/crates/types/tests/block_sampled.rs +++ b/crates/types/tests/block_sampled.rs @@ -76,3 +76,28 @@ fn test_blocksampled_account_compiler() { ] ); } + +#[test] +fn test_blocksampled_storage_compiler() { + let block_datalake = BlockSampledDatalake::new( + 10399990, + 10399992, + "storage.0x00000000000000adc04c56bf30ac9d3c0aaf14dc.0x0000000000000000000000000000000000000000000000000000000000000000".to_string(), + 1, + ); + let data_points = block_datalake.compile().unwrap(); + assert_eq!( + data_points, + vec![ + DataPoint::Str( + "0x0000000000000000000000000000000000000000000000000000000000000001".to_string() + ), + DataPoint::Str( + "0x0000000000000000000000000000000000000000000000000000000000000002".to_string() + ), + DataPoint::Str( + "0x0000000000000000000000000000000000000000000000000000000000000001".to_string() + ), + ] + ); +}