1
- use alloy:: {
2
- consensus:: {
3
- proofs:: { calculate_transaction_root, calculate_withdrawals_root} ,
4
- Header , TxEnvelope ,
5
- } ,
6
- eips:: eip4895:: Withdrawal ,
7
- primitives:: { Bloom , B64 } ,
8
- rlp:: Decodable ,
9
- } ;
10
- use ethportal_api:: consensus:: {
11
- beacon_block:: {
1
+ use alloy:: { consensus:: TxEnvelope , eips:: eip4895:: Withdrawal } ;
2
+ use ethportal_api:: {
3
+ consensus:: beacon_block:: {
12
4
SignedBeaconBlock , SignedBeaconBlockBellatrix , SignedBeaconBlockCapella ,
13
5
SignedBeaconBlockDeneb , SignedBeaconBlockElectra ,
14
6
} ,
15
- body :: Transactions ,
7
+ types :: execution :: builders :: { block :: decode_transactions , header :: ExecutionHeaderBuilder } ,
16
8
} ;
17
9
use rayon:: iter:: { IntoParallelIterator , ParallelIterator } ;
18
- use revm_primitives:: { b256, B256 , U256 } ;
19
10
20
11
use super :: types:: { ProcessedBlock , TransactionsWithSender } ;
21
12
22
- pub const EMPTY_UNCLE_ROOT_HASH : B256 =
23
- b256 ! ( "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" ) ;
24
-
25
13
pub trait ProcessBeaconBlock {
26
14
fn process_beacon_block ( & self ) -> anyhow:: Result < ProcessedBlock > ;
27
15
}
@@ -42,35 +30,11 @@ impl ProcessBeaconBlock for SignedBeaconBlockBellatrix {
42
30
let payload = & self . message . body . execution_payload ;
43
31
44
32
let transactions = decode_transactions ( & payload. transactions ) ?;
45
- let transactions_root = calculate_transaction_root ( & transactions) ;
33
+ let header = ExecutionHeaderBuilder :: bellatrix ( payload , & transactions) ? ;
46
34
let transactions = process_transactions ( transactions) ?;
47
35
48
- let header = Header {
49
- parent_hash : payload. parent_hash ,
50
- ommers_hash : EMPTY_UNCLE_ROOT_HASH ,
51
- beneficiary : payload. fee_recipient ,
52
- state_root : payload. state_root ,
53
- transactions_root,
54
- receipts_root : payload. receipts_root ,
55
- logs_bloom : Bloom :: from_slice ( payload. logs_bloom . to_vec ( ) . as_slice ( ) ) ,
56
- difficulty : U256 :: ZERO ,
57
- number : payload. block_number ,
58
- gas_limit : payload. gas_limit ,
59
- gas_used : payload. gas_used ,
60
- timestamp : payload. timestamp ,
61
- extra_data : payload. extra_data . to_vec ( ) . into ( ) ,
62
- mix_hash : payload. prev_randao ,
63
- nonce : B64 :: ZERO ,
64
- base_fee_per_gas : Some ( payload. base_fee_per_gas . to ( ) ) ,
65
- withdrawals_root : None ,
66
- blob_gas_used : None ,
67
- excess_blob_gas : None ,
68
- parent_beacon_block_root : None ,
69
- requests_hash : None ,
70
- } ;
71
-
72
36
Ok ( ProcessedBlock {
73
- header : header . clone ( ) ,
37
+ header,
74
38
uncles : None ,
75
39
withdrawals : None ,
76
40
transactions,
@@ -83,39 +47,13 @@ impl ProcessBeaconBlock for SignedBeaconBlockCapella {
83
47
let payload = & self . message . body . execution_payload ;
84
48
85
49
let transactions = decode_transactions ( & payload. transactions ) ?;
86
- let transactions_root = calculate_transaction_root ( & transactions) ;
87
- let transactions = process_transactions ( transactions) ?;
88
-
89
50
let withdrawals: Vec < Withdrawal > =
90
51
payload. withdrawals . iter ( ) . map ( Withdrawal :: from) . collect ( ) ;
91
- let withdrawals_root = calculate_withdrawals_root ( & withdrawals) ;
92
-
93
- let header = Header {
94
- parent_hash : payload. parent_hash ,
95
- ommers_hash : EMPTY_UNCLE_ROOT_HASH ,
96
- beneficiary : payload. fee_recipient ,
97
- state_root : payload. state_root ,
98
- transactions_root,
99
- receipts_root : payload. receipts_root ,
100
- logs_bloom : Bloom :: from_slice ( payload. logs_bloom . to_vec ( ) . as_slice ( ) ) ,
101
- difficulty : U256 :: ZERO ,
102
- number : payload. block_number ,
103
- gas_limit : payload. gas_limit ,
104
- gas_used : payload. gas_used ,
105
- timestamp : payload. timestamp ,
106
- extra_data : payload. extra_data . to_vec ( ) . into ( ) ,
107
- mix_hash : payload. prev_randao ,
108
- nonce : B64 :: ZERO ,
109
- base_fee_per_gas : Some ( payload. base_fee_per_gas . to ( ) ) ,
110
- withdrawals_root : Some ( withdrawals_root) ,
111
- blob_gas_used : None ,
112
- excess_blob_gas : None ,
113
- parent_beacon_block_root : None ,
114
- requests_hash : None ,
115
- } ;
52
+ let header = ExecutionHeaderBuilder :: capella ( payload, & transactions, & withdrawals) ?;
53
+ let transactions = process_transactions ( transactions) ?;
116
54
117
55
Ok ( ProcessedBlock {
118
- header : header . clone ( ) ,
56
+ header,
119
57
uncles : None ,
120
58
withdrawals : Some ( withdrawals) ,
121
59
transactions,
@@ -128,39 +66,18 @@ impl ProcessBeaconBlock for SignedBeaconBlockDeneb {
128
66
let payload = & self . message . body . execution_payload ;
129
67
130
68
let transactions = decode_transactions ( & payload. transactions ) ?;
131
- let transactions_root = calculate_transaction_root ( & transactions) ;
132
- let transactions = process_transactions ( transactions) ?;
133
-
134
69
let withdrawals: Vec < Withdrawal > =
135
70
payload. withdrawals . iter ( ) . map ( Withdrawal :: from) . collect ( ) ;
136
- let withdrawals_root = calculate_withdrawals_root ( & withdrawals) ;
137
-
138
- let header = Header {
139
- parent_hash : payload. parent_hash ,
140
- ommers_hash : EMPTY_UNCLE_ROOT_HASH ,
141
- beneficiary : payload. fee_recipient ,
142
- state_root : payload. state_root ,
143
- transactions_root,
144
- receipts_root : payload. receipts_root ,
145
- logs_bloom : Bloom :: from_slice ( payload. logs_bloom . to_vec ( ) . as_slice ( ) ) ,
146
- difficulty : U256 :: ZERO ,
147
- number : payload. block_number ,
148
- gas_limit : payload. gas_limit ,
149
- gas_used : payload. gas_used ,
150
- timestamp : payload. timestamp ,
151
- extra_data : payload. extra_data . to_vec ( ) . into ( ) ,
152
- mix_hash : payload. prev_randao ,
153
- nonce : B64 :: ZERO ,
154
- base_fee_per_gas : Some ( payload. base_fee_per_gas . to ( ) ) ,
155
- withdrawals_root : Some ( withdrawals_root) ,
156
- blob_gas_used : Some ( payload. blob_gas_used ) ,
157
- excess_blob_gas : Some ( payload. excess_blob_gas ) ,
158
- parent_beacon_block_root : Some ( self . message . parent_root ) ,
159
- requests_hash : None ,
160
- } ;
71
+ let header = ExecutionHeaderBuilder :: deneb (
72
+ payload,
73
+ self . message . parent_root ,
74
+ & transactions,
75
+ & withdrawals,
76
+ ) ?;
77
+ let transactions = process_transactions ( transactions) ?;
161
78
162
79
Ok ( ProcessedBlock {
163
- header : header . clone ( ) ,
80
+ header,
164
81
uncles : None ,
165
82
withdrawals : Some ( withdrawals) ,
166
83
transactions,
@@ -173,36 +90,16 @@ impl ProcessBeaconBlock for SignedBeaconBlockElectra {
173
90
let payload = & self . message . body . execution_payload ;
174
91
175
92
let transactions = decode_transactions ( & payload. transactions ) ?;
176
- let transactions_root = calculate_transaction_root ( & transactions) ;
177
- let transactions = process_transactions ( transactions) ?;
178
-
179
93
let withdrawals: Vec < Withdrawal > =
180
94
payload. withdrawals . iter ( ) . map ( Withdrawal :: from) . collect ( ) ;
181
- let withdrawals_root = calculate_withdrawals_root ( & withdrawals) ;
182
-
183
- let header = Header {
184
- parent_hash : payload. parent_hash ,
185
- ommers_hash : EMPTY_UNCLE_ROOT_HASH ,
186
- beneficiary : payload. fee_recipient ,
187
- state_root : payload. state_root ,
188
- transactions_root,
189
- receipts_root : payload. receipts_root ,
190
- logs_bloom : Bloom :: from_slice ( payload. logs_bloom . to_vec ( ) . as_slice ( ) ) ,
191
- difficulty : U256 :: ZERO ,
192
- number : payload. block_number ,
193
- gas_limit : payload. gas_limit ,
194
- gas_used : payload. gas_used ,
195
- timestamp : payload. timestamp ,
196
- extra_data : payload. extra_data . to_vec ( ) . into ( ) ,
197
- mix_hash : payload. prev_randao ,
198
- nonce : B64 :: ZERO ,
199
- base_fee_per_gas : Some ( payload. base_fee_per_gas . to ( ) ) ,
200
- withdrawals_root : Some ( withdrawals_root) ,
201
- blob_gas_used : Some ( payload. blob_gas_used ) ,
202
- excess_blob_gas : Some ( payload. excess_blob_gas ) ,
203
- parent_beacon_block_root : Some ( self . message . parent_root ) ,
204
- requests_hash : Some ( self . message . body . execution_requests . requests_hash ( ) ) ,
205
- } ;
95
+ let header = ExecutionHeaderBuilder :: electra (
96
+ payload,
97
+ self . message . parent_root ,
98
+ & transactions,
99
+ & withdrawals,
100
+ & self . message . body . execution_requests ,
101
+ ) ?;
102
+ let transactions = process_transactions ( transactions) ?;
206
103
207
104
Ok ( ProcessedBlock {
208
105
header : header. clone ( ) ,
@@ -213,16 +110,6 @@ impl ProcessBeaconBlock for SignedBeaconBlockElectra {
213
110
}
214
111
}
215
112
216
- pub fn decode_transactions ( transactions : & Transactions ) -> anyhow:: Result < Vec < TxEnvelope > > {
217
- transactions
218
- . into_par_iter ( )
219
- . map ( |raw_tx| {
220
- TxEnvelope :: decode ( & mut & * * raw_tx)
221
- . map_err ( |err| anyhow:: anyhow!( "Failed decoding transaction rlp: {err:?}" ) )
222
- } )
223
- . collect :: < anyhow:: Result < Vec < _ > > > ( )
224
- }
225
-
226
113
fn process_transactions (
227
114
transactions : Vec < TxEnvelope > ,
228
115
) -> anyhow:: Result < Vec < TransactionsWithSender > > {
0 commit comments