@@ -20,15 +20,14 @@ use crate::{
20
20
oracle:: HeaderOracle ,
21
21
} ;
22
22
23
- #[ derive( Debug , Default , Clone ) ]
23
+ #[ derive( Debug , Clone ) ]
24
24
pub enum HistoricalSummariesProvider {
25
25
/// The historical summaries are provided by the header oracle.
26
26
HeaderOracle ( Arc < RwLock < HeaderOracle > > ) ,
27
27
/// The historical summaries are provided by passed historical summaries.
28
28
HistoricalSummaries ( HistoricalSummaries ) ,
29
29
/// We don't have historical summaries, for example the E2HS bridge doesn't use a provider and
30
30
/// hence can't get HistoricalSummaries. HistoricalSummary proof validation will fail.
31
- #[ default]
32
31
None ,
33
32
}
34
33
@@ -64,9 +63,7 @@ impl HistoricalSummariesProvider {
64
63
65
64
/// HeaderValidator is responsible for validating pre-merge and post-merge headers with their
66
65
/// respective proofs.
67
- ///
68
- /// Default can only be used for validating pre-capella headers.
69
- #[ derive( Debug , Clone , Default ) ]
66
+ #[ derive( Debug , Clone ) ]
70
67
pub struct HeaderValidator {
71
68
/// Pre-merge accumulator used to validate pre-merge headers.
72
69
pub pre_merge_acc : PreMergeAccumulator ,
@@ -78,16 +75,21 @@ pub struct HeaderValidator {
78
75
79
76
impl HeaderValidator {
80
77
pub fn new ( historical_summaries_provider : HistoricalSummariesProvider ) -> Self {
81
- let pre_merge_acc = PreMergeAccumulator :: default ( ) ;
82
- let historical_roots_acc = HistoricalRootsAccumulator :: default ( ) ;
83
-
84
78
Self {
85
- pre_merge_acc,
86
- historical_roots_acc,
79
+ pre_merge_acc : PreMergeAccumulator :: default ( ) ,
80
+ historical_roots_acc : HistoricalRootsAccumulator :: default ( ) ,
87
81
historical_summaries_provider,
88
82
}
89
83
}
90
84
85
+ pub fn new_without_historical_summaries ( ) -> Self {
86
+ Self {
87
+ pre_merge_acc : PreMergeAccumulator :: default ( ) ,
88
+ historical_roots_acc : HistoricalRootsAccumulator :: default ( ) ,
89
+ historical_summaries_provider : HistoricalSummariesProvider :: None ,
90
+ }
91
+ }
92
+
91
93
pub async fn validate_header_with_proof (
92
94
& self ,
93
95
header_with_proof : & HeaderWithProof ,
@@ -152,7 +154,7 @@ impl HeaderValidator {
152
154
) ) ;
153
155
}
154
156
155
- // Verify the chain of proofs for post-merge/pre- capella block header
157
+ // Verify the chain of proofs for post-capella block header
156
158
Self :: verify_beacon_block_proof (
157
159
header_hash,
158
160
& proof. execution_block_proof ,
@@ -347,7 +349,7 @@ mod test {
347
349
header,
348
350
proof : BlockHeaderProof :: HistoricalHashes ( trin_proof) ,
349
351
} ;
350
- HeaderValidator :: default ( )
352
+ HeaderValidator :: new_without_historical_summaries ( )
351
353
. validate_header_with_proof ( & header_with_proof)
352
354
. await
353
355
. unwrap ( ) ;
@@ -372,7 +374,7 @@ mod test {
372
374
header,
373
375
proof : BlockHeaderProof :: HistoricalHashes ( proof) ,
374
376
} ;
375
- HeaderValidator :: default ( )
377
+ HeaderValidator :: new_without_historical_summaries ( )
376
378
. validate_header_with_proof ( & header_with_proof)
377
379
. await
378
380
. unwrap ( ) ;
@@ -401,7 +403,7 @@ mod test {
401
403
header,
402
404
proof : BlockHeaderProof :: HistoricalHashes ( proof) ,
403
405
} ;
404
- assert ! ( HeaderValidator :: default ( )
406
+ assert ! ( HeaderValidator :: new_without_historical_summaries ( )
405
407
. validate_header_with_proof( & header_with_proof)
406
408
. await
407
409
. unwrap_err( )
@@ -418,7 +420,7 @@ mod test {
418
420
header : future_header,
419
421
proof : BlockHeaderProof :: HistoricalHashes ( Default :: default ( ) ) ,
420
422
} ;
421
- HeaderValidator :: default ( )
423
+ HeaderValidator :: new_without_historical_summaries ( )
422
424
. validate_header_with_proof ( & future_hwp)
423
425
. await
424
426
. unwrap ( ) ;
@@ -441,7 +443,7 @@ mod test {
441
443
let historical_roots_block_proof: BlockProofHistoricalRoots =
442
444
serde_yaml:: from_value ( value) . unwrap ( ) ;
443
445
444
- let header_validator = HeaderValidator :: default ( ) ;
446
+ let header_validator = HeaderValidator :: new_without_historical_summaries ( ) ;
445
447
header_validator
446
448
. verify_historical_roots ( block_number, header_hash, & historical_roots_block_proof)
447
449
. unwrap ( ) ;
@@ -552,7 +554,9 @@ mod test {
552
554
#[ tokio:: test]
553
555
async fn header_oracle_bootstraps_with_default_pre_merge_acc ( ) {
554
556
assert_eq ! (
555
- HeaderValidator :: default ( ) . pre_merge_acc. tree_hash_root( ) ,
557
+ HeaderValidator :: new_without_historical_summaries( )
558
+ . pre_merge_acc
559
+ . tree_hash_root( ) ,
556
560
B256 :: from_str( DEFAULT_PRE_MERGE_ACC_HASH ) . unwrap( ) ,
557
561
) ;
558
562
}
0 commit comments