Skip to main content

alloy_rpc_types_mev/
flashblocks.rs

1use alloy_consensus::Receipt;
2use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256};
3use alloy_rpc_types_eth::Withdrawal;
4use serde::{Deserialize, Serialize};
5use std::collections::BTreeMap;
6
7/// Represents a Flashblock, a real-time block-like structure emitted by the Base L2 chain.
8///
9/// A Flashblock provides a snapshot of a block’s effects before finalization,
10/// allowing faster insight into state transitions, balance changes, and logs.
11/// It includes a diff of the block’s execution and associated metadata.
12///
13/// See: [Base Flashblocks Documentation](https://docs.base.org/chain/flashblocks)
14#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
15pub struct FlashBlock {
16    /// The unique payload ID as assigned by the execution engine for this block.
17    pub payload_id: B64,
18    /// A sequential index that identifies the order of this Flashblock.
19    pub index: u64,
20    /// The execution diff representing state transitions and transactions.
21    pub diff: FlashBlockDiff,
22    /// Additional metadata about the block such as receipts and balances.
23    pub metadata: Metadata,
24}
25
26/// Represents the block-level state and transaction changes from a single Flashblock.
27#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
28pub struct FlashBlockDiff {
29    /// The new state root after execution of the block.
30    pub state_root: B256,
31    /// The root hash of the receipts trie for the block.
32    pub receipts_root: B256,
33    /// Aggregated bloom filter for all logs generated in the block.
34    pub logs_bloom: Bloom,
35    /// Total gas used by all transactions in the block.
36    #[serde(with = "alloy_serde::quantity")]
37    pub gas_used: u64,
38    /// The hash of the block this diff is describing.
39    pub block_hash: B256,
40    /// List of transactions included in the block.
41    pub transactions: Vec<Bytes>,
42    /// Withdrawals included in the block (relevant for post-merge Ethereum withdrawals).
43    pub withdrawals: Vec<Withdrawal>,
44}
45
46/// Provides metadata about the block that may be useful for indexing or analysis.
47#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
48pub struct Metadata {
49    /// The number of the block in the L2 chain.
50    pub block_number: u64,
51    /// A map of addresses to their updated balances after the block execution.
52    /// This represents balance changes due to transactions, rewards, or system transfers.
53    pub new_account_balances: BTreeMap<Address, U256>,
54    /// Execution receipts for all transactions in the block.
55    /// Contains logs, gas usage, and other EVM-level metadata.
56    pub receipts: BTreeMap<B256, Receipt>,
57}
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn flashblock_roundtrip() {
65        let s = r#"{
66            "payload_id": "0x036219efcf320dce",
67            "index": 7,
68            "diff": {
69                "state_root": "0x087bf9d0745c1324b66db31689a388e3e46be9e73810c96f532757db77188267",
70                "receipts_root": "0xc2b07524c59739c4ee2fcec0abf2b5d44e99a526daadef01ae80afdf2ea9387b",
71                "logs_bloom": "0xd8102a8a322101048c40c4042484c0604003c994e980b4804c240710014b00407a444911580f0000110000340c84a0315fd11402173e300a74023050023300000ba0c08000f2042d200082481c0ce800a120108120006801008403960a008030050271980f1392207002240323014f4ed0206820108010412765415a0816000a1240815c282c8713c007421c034f0b2025b001ca1260044c8808000016489047bb1803194907c101001448a408052008900132180112c42204d3920e1088128ce11881060d7b62606801f8162041305080803a09a3f0000480270281820aaa10411188ae10a12224e2841001810792a488052121448549421400604004060902",
72                "gas_used": "0x90b5b8",
73                "block_hash": "0x4a86b5b6648440fdd6fa31575260d769bef2cf77923b06a3cdfa28e13d2554d3",
74                "transactions": [
75                    "0x02f87483014a34827399830f4240830f47bc825a3d94195a15af71f555d52efcf8d627d285fe06ab70dd8701c6bf5263400080c001a02c4375083f2fe20178651df96540e78978c505b5659eed8d819b2da546f96812a0685f339e77d4cb6f568ae6b68b694997eb8ba3dc1b45b166b326f3592dc2a4dd",
76            "0xf9038d8192831252ce8308d8c9947ea0ceb70d5df75a730e6cb3eadec12efdfe80a180b90324e917a962000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000680cca732e7de755ca70cb933dc80103af16cc3303580e5712f1a8927d6461441e99a1e60000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000000200000000000000000000000005b912a180622551b7a8fdc6db6b9d399024dfe9b00000000000000000000000000000000000000000000000000000000000042680000000000000000000000006319df7c227e34b967c1903a08a698a3cc43492b000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d88ddf98fe4d161a66fb836bee4ca469eb0e4a7547e7ef24000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000400000000000000000000000005b912a180622551b7a8fdc6db6b9d399024dfe9b00000000000000000000000000000000000000000000000000236bbe68c897190000000000000000000000000000000000000000000000000000000000000001000000000000000000000000d88ddf98fe4d161a66fb836bee4ca469eb0e4a750000000000000000000000008d09a4502cc8cf1547ad300e066060d043f6982d00000000000000000000000000000000000000000000000000236bbe68c897198302948ba0ffd86c02601379e270a8504769e7d4c5d9a275514c2644782dc345e0ab4ee477a0297a74f13f5316470052b7549c771804b689e4965e6cb34b63f85a9fb75e0a84"
77                ],
78                "withdrawals": []
79            },
80            "metadata": {
81                "block_number": 24907037,
82                "new_account_balances": {
83                    "0x0000f90827f1c53a10cb7a02335b175320002935": "0x0",
84                    "0x000f3df6d732807ef1319fb7b8bb8522d0beac02": "0x0",
85                    "0x07124296362d9e92a7105dc40d7e20e909ccabd6": "0x0",
86                    "0x0d4850679dc9739b00b728c9a40d8599455c8955": "0x38d18a9775de2",
87                    "0x1109cf9d1d48bfa11b9c2923dfacfae4cb495e66": "0x0",
88                    "0x1197766b82eee9c2e57674e53f0d961590e43769": "0x0",
89                    "0x12777af0c14d146336ad0ba75249c4f3dda69b9d": "0x3238cd3b146cd",
90                    "0x13e5fb0b6534bb22cbc59fae339dbbe0dc906871": "0x0",
91                    "0x153c966657dbb740bcf8bc49472aff2eda73c173": "0xb6c902ba9a1f6e",
92                    "0x159e0d14303d752879252a1975b2c935d99c3616": "0xb19e5adad9cfc0",
93                    "0x195a15af71f555d52efcf8d627d285fe06ab70dd": "0x1c6bf52634000",
94                    "0x1ad9bbba2af5893293ca6f8e1b86a3bd36a10ccb": "0x163407e26ed9ff1",
95                    "0x2c55482aecabb7efe86c5a6af608fcdb1b6cb19b": "0x2329f26893fcfe8c",
96                    "0x3148b3a10a4f82d90521f3b45dd0974ae9006ac2": "0x5dc261accac2e",
97                    "0x37287adde7a3d4d05af9cb8811c62e1bade796d0": "0x0",
98                    "0x3a5ee358d54379f5c90b20e5decbdaf9c092351b": "0x9146f5a7fe0bf10a",
99                    "0x3b06913081c7430e08fc9787da2bcdccd4f35b16": "0x0",
100                    "0x3e1553997d345345e2c2a83e695bf867c2def007": "0xb716af35129268f",
101                    "0x3eb4b2c7d235fe915e3a0ef6be73fd458bb891f4": "0x0",
102                    "0x40fc192ebc955650d8708764707fdd9cc884f2b8": "0x0",
103                    "0x412ad14a776c3f20425318daf1562aff520f4005": "0x3aff890bda831e85",
104                    "0x4200000000000000000000000000000000000011": "0x70537c7abe1d7a2844",
105                    "0x4200000000000000000000000000000000000015": "0x0",
106                    "0x4200000000000000000000000000000000000019": "0x18100e2e8feba3c",
107                    "0x420000000000000000000000000000000000001a": "0x12ae17c7ff78394a",
108                    "0x425626c75aa9a793bb932f91dca6eb52e88e15af": "0x113b54ae950a3b",
109                    "0x428a7639af8825f3821c5bcac3d7e097721b3add": "0x1b83df45380f671d",
110                    "0x557bb85fc501616668d39d82aaa9b25027e9e296": "0x237b1b4e10c5ae618",
111                    "0x5b912a180622551b7a8fdc6db6b9d399024dfe9b": "0x352270d78f676e",
112                    "0x5d0677a5d7fb63df06063b88523fd362c93895aa": "0x52b754852a64b",
113                    "0x5e2a5cb3ac8a2d82426d7ec7c169523034434871": "0xf1d6c16c1419ac",
114                    "0x6304fba33e88d77f67483c1d8b0f64859814773b": "0x77b028cfb327ff",
115                    "0x6319df7c227e34b967c1903a08a698a3cc43492b": "0x0",
116                    "0x63d8135af4d393b1db43b649010c8d3ee19fc9fd": "0x0",
117                    "0x677d19965610a92376d6fb43ca7c8db74f2e46db": "0x9ee6271ae62a9f",
118                    "0x682f26c84222b65c457c5e82f3174726279de656": "0x0",
119                    "0x6c3270553c24212c1f1a93a557bdc58472bd1020": "0xdb707af428714",
120                    "0x6defadc8609680d22e85843449b7173314d706c8": "0x3dbbc463e45b2867",
121                    "0x7617cc28ab267cc3bfd2ed05c92dca875e38e67b": "0x0",
122                    "0x7ea0ceb70d5df75a730e6cb3eadec12efdfe80a1": "0x0",
123                    "0x83339e9533c0d2ef0388b39f7601f23495654187": "0x0",
124                    "0x8842699a35d17fcedb9c95641db1062539d53c2d": "0x2de13a4791102b555",
125                    "0x8ee92ce1caf5848d7a54672fc4320e4f92748643": "0x0",
126                    "0x925e69632a5096fa87115f2e990edf621587552a": "0xfdf17306be053b",
127                    "0x986f2315d765f646a4f0cf83bb9dc9f19b6a9115": "0x91faf49a1c5",
128                    "0x98f665d98a046fb81147879ecbe9a6ff68bc276c": "0x0",
129                    "0x9b17032749aa066a2dea40b746aa6aa09cde67d9": "0x0",
130                    "0xa8f7857692260b4ef9483c7f7ec5e767572a3b82": "0x0",
131                    "0xb52dc0e049196064b2e5721effd12401e480ce04": "0xcfec9f5f2e82da",
132                    "0xc075e868e2b27066022c55fb3d0fcabcae440fec": "0x1b7f88a8877375c1",
133                    "0xc53e731a618d2bd97e8dbe89286ca9487598e3cf": "0x54e607f2f464153",
134                    "0xc98deb0a06ced9845cc637a27868dae622017fde": "0x84bd9b50c14d66a",
135                    "0xcdf5c4a793fef4431420f2076005e85e73b8e45a": "0xb3574ae443000",
136                    "0xcee0372632a37ba4d0499d1e2116ecff3a17d3c3": "0xf8655a39eff47c0376",
137                    "0xd434da3bd52ada5a11939898cde02f862bb1de05": "0x4bf223a99b0dc",
138                    "0xd7431e0153794aa23fb72e53482e0b370a9651a2": "0x9bcbe0f95e8374",
139                    "0xdb07b0b4e88d9d5a79a08e91fee20bb41f9989a2": "0x0",
140                    "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001": "0x22bff812f37108",
141                    "0xdf1bfcb92f6be7102fc552af9bb9e63a533764f2": "0x6fa5b1f6e0e75",
142                    "0xe5297e00b55e1333d1b0e548e654152e0df7c42a": "0x0",
143                    "0xe67f852aa8cbad2bcd3bc90fad40bd1b0474817c": "0x2e57531693ba1",
144                    "0xeab3741ee9d5629244842997eb2c0eccebe5f833": "0x3640405ee04fa",
145                    "0xecde025a3de8713be3bda5ad010cb4a96e5f1445": "0x186c39daa8c5c7283",
146                    "0xefc91c5a51e8533282486fa2601dffe0a0b16edb": "0x0"
147                },
148                "receipts": {
149                    "0x2187321da357ac3b0008a9f2fa4f4d879e1fa7d33cc6eccf8f76dcceff63d139": {
150                        "cumulativeGasUsed": "0x8b0e20",
151                        "logs": [],
152                        "status": "0x1"
153                    },
154                    "0x6f1d04fdacaa486d4f921f34af827a62c720600d0bfedcc23efa59c155eda676": {
155                        "cumulativeGasUsed": "0x90b5b8",
156                        "logs": [
157                            {
158                                "address": "0x6319df7c227e34b967c1903a08a698a3cc43492b",
159                                "data": "0x000000000000000000000000000000000000000000000000002386f26fc10000",
160                                "topics": [
161                                    "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
162                                    "0x0000000000000000000000005b912a180622551b7a8fdc6db6b9d399024dfe9b",
163                                    "0x0000000000000000000000007ea0ceb70d5df75a730e6cb3eadec12efdfe80a1"
164                                ]
165                            },
166                            {
167                                "address": "0x7ea0ceb70d5df75a730e6cb3eadec12efdfe80a1",
168                                "data": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000014a34000000000000000000000000000000000000000000000000000000000000426800000000000000000000000000000000000000000000000000000000680cca7300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d88ddf98fe4d161a66fb836bee4ca469eb0e4a7547e7ef24000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000400000000000000000000000005b912a180622551b7a8fdc6db6b9d399024dfe9b00000000000000000000000000000000000000000000000000236bbe68c897190000000000000000000000000000000000000000000000000000000000000001000000000000000000000000d88ddf98fe4d161a66fb836bee4ca469eb0e4a750000000000000000000000008d09a4502cc8cf1547ad300e066060d043f6982d00000000000000000000000000000000000000000000000000236bbe68c89719",
169                                "topics": [
170                                    "0x71069e0637faca19b5cceb36f6ee664347f592a954e37edf597b6c0f37afd59f",
171                                    "0xda8e4f6004c7a74dcf2192cbab7d11d70d8f0c1973d122a91bc3c00cd71cf491"
172                                ]
173                            },
174                            {
175                                "address": "0x7ea0ceb70d5df75a730e6cb3eadec12efdfe80a1",
176                                "data": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000005b912a180622551b7a8fdc6db6b9d399024dfe9b0000000000000000000000000000000000000000000000000000000000014a34000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000680cca73da8e4f6004c7a74dcf2192cbab7d11d70d8f0c1973d122a91bc3c00cd71cf491000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000010000000000000000000000008d09a4502cc8cf1547ad300e066060d043f6982d00000000000000000000000000000000000000000000000000236bbe68c89719000000000000000000000000ae9e2e3acb2914604ca8f13c734388f05c697ef0000000000000000000000000000000000000000000000000000000000000426800000000000000000000000000000000000000000000000000000000000000010000000000000000000000006319df7c227e34b967c1903a08a698a3cc43492b000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014a34000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004268000000000000000000000000ae9e2e3acb2914604ca8f13c734388f05c697ef00000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000014a34000000000000000000000000000000000000000000000000000000000000426800000000000000000000000000000000000000000000000000000000680cca7300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d88ddf98fe4d161a66fb836bee4ca469eb0e4a7547e7ef24000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000400000000000000000000000005b912a180622551b7a8fdc6db6b9d399024dfe9b00000000000000000000000000000000000000000000000000236bbe68c897190000000000000000000000000000000000000000000000000000000000000001000000000000000000000000d88ddf98fe4d161a66fb836bee4ca469eb0e4a750000000000000000000000008d09a4502cc8cf1547ad300e066060d043f6982d00000000000000000000000000000000000000000000000000236bbe68c89719",
177                                "topics": [
178                                    "0xa576d0af275d0c6207ef43ceee8c498a5d7a26b8157a32d3fdf361e64371628c",
179                                    "0xda8e4f6004c7a74dcf2192cbab7d11d70d8f0c1973d122a91bc3c00cd71cf491"
180                                ]
181                            }
182                        ],
183                        "status": "0x1"
184                    }
185                }
186            }
187        }"#;
188
189        let flash_block: FlashBlock =
190            serde_json::from_str(s).expect("Failed to deserialize FlashBlock");
191
192        let serialized = serde_json::to_value(&flash_block).unwrap();
193        let sample_json: serde_json::Value = serde_json::from_str(s).unwrap();
194
195        assert_eq!(sample_json, serialized);
196    }
197}