11#![ feature( slice_as_array) ]
22
3+ use block_hashes:: BlockHashes ;
34use clap:: Parser ;
45use post_check:: post_check;
56use prestate:: { populate_prestate, DiffTrace , PrestateTrace } ;
@@ -8,6 +9,7 @@ use std::fs::{self, File};
89use std:: io:: BufReader ;
910
1011mod block;
12+ mod block_hashes;
1113mod post_check;
1214mod prestate;
1315mod receipts;
@@ -35,6 +37,10 @@ struct Args {
3537 #[ arg( long) ]
3638 receipts : String ,
3739
40+ /// Path to the block hashes JSON file (optional)
41+ #[ arg( long) ]
42+ block_hashes : Option < String > ,
43+
3844 /// If set, the leaves of the tree are put in random
3945 /// positions to emulate real-world costs
4046 #[ arg( long, action = clap:: ArgAction :: SetTrue ) ]
@@ -51,9 +57,14 @@ fn run<const RANDOMIZED: bool>(
5157 transactions : Vec < Vec < u8 > > ,
5258 receipts : Vec < receipts:: TransactionReceipt > ,
5359 diff_trace : DiffTrace ,
60+ block_hashes : Option < BlockHashes > ,
5461) -> anyhow:: Result < ( ) > {
5562 chain. set_last_block_number ( block_number - 1 ) ;
5663
64+ if let Some ( block_hashes) = block_hashes {
65+ chain. set_block_hashes ( block_hashes. into_array ( block_number) )
66+ }
67+
5768 let prestate_cache = populate_prestate ( & mut chain, ps_trace) ;
5869
5970 let output = chain. run_block ( transactions, Some ( block_context) , None ) ;
@@ -84,6 +95,10 @@ fn main() -> anyhow::Result<()> {
8495 let diff_file = File :: open ( & args. difftrace ) ?;
8596 let diff_reader = BufReader :: new ( diff_file) ;
8697 let diff_trace: DiffTrace = serde_json:: from_reader ( diff_reader) ?;
98+ let block_hashes: Option < BlockHashes > = args. block_hashes . map ( |path| {
99+ let hashes = fs:: read_to_string ( & path) . expect ( "valid block hashes path" ) ;
100+ serde_json:: from_str ( & hashes) . expect ( "valid block hashes JSON" )
101+ } ) ;
87102
88103 let block: block:: Block = serde_json:: from_str ( & block) . expect ( "valid block JSON" ) ;
89104 let block_number = block. result . header . number ;
@@ -130,6 +145,7 @@ fn main() -> anyhow::Result<()> {
130145 transactions,
131146 receipts,
132147 diff_trace,
148+ block_hashes,
133149 )
134150 } else {
135151 let chain = Chain :: empty ( Some ( 1 ) ) ;
@@ -142,6 +158,7 @@ fn main() -> anyhow::Result<()> {
142158 transactions,
143159 receipts,
144160 diff_trace,
161+ block_hashes,
145162 )
146163 }
147164}
0 commit comments