@@ -2,9 +2,8 @@ use crate::{
2
2
trie:: { hash_builder:: HashBuilderState , StoredSubNode } ,
3
3
Address , BlockNumber , B256 ,
4
4
} ;
5
- use bytes:: { Buf , BufMut } ;
6
- use reth_codecs:: { derive_arbitrary, main_codec, Compact } ;
7
- use serde:: { Deserialize , Serialize } ;
5
+ use bytes:: Buf ;
6
+ use reth_codecs:: { main_codec, Compact } ;
8
7
use std:: {
9
8
fmt:: { Display , Formatter } ,
10
9
ops:: RangeInclusive ,
@@ -258,8 +257,8 @@ impl Display for StageCheckpoint {
258
257
// TODO(alexey): add a merkle checkpoint. Currently it's hard because [`MerkleCheckpoint`]
259
258
// is not a Copy type.
260
259
/// Stage-specific checkpoint metrics.
261
- #[ derive_arbitrary ( compact ) ]
262
- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Serialize , Deserialize ) ]
260
+ #[ main_codec ]
261
+ #[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
263
262
pub enum StageUnitCheckpoint {
264
263
/// Saves the progress of AccountHashing stage.
265
264
Account ( AccountHashingCheckpoint ) ,
@@ -275,42 +274,16 @@ pub enum StageUnitCheckpoint {
275
274
IndexHistory ( IndexHistoryCheckpoint ) ,
276
275
}
277
276
278
- /// Generates:
279
- /// 1. [Compact::to_compact] and [Compact::from_compact] implementations for [StageUnitCheckpoint].
280
- /// 2. [StageCheckpoint] getter and builder methods.
277
+ #[ cfg( test) ]
278
+ impl Default for StageUnitCheckpoint {
279
+ fn default ( ) -> Self {
280
+ Self :: Account ( AccountHashingCheckpoint :: default ( ) )
281
+ }
282
+ }
283
+
284
+ /// Generates [StageCheckpoint] getter and builder methods.
281
285
macro_rules! stage_unit_checkpoints {
282
286
( $( ( $index: expr, $enum_variant: tt, $checkpoint_ty: ty, #[ doc = $fn_get_doc: expr] $fn_get_name: ident, #[ doc = $fn_build_doc: expr] $fn_build_name: ident) ) ,+) => {
283
- impl Compact for StageUnitCheckpoint {
284
- fn to_compact<B >( self , buf: & mut B ) -> usize
285
- where
286
- B : BufMut + AsMut <[ u8 ] >,
287
- {
288
- match self {
289
- $(
290
- StageUnitCheckpoint :: $enum_variant( data) => {
291
- buf. put_u8( $index) ;
292
- 1 + data. to_compact( buf)
293
- }
294
- ) +
295
- }
296
- }
297
-
298
- fn from_compact( buf: & [ u8 ] , _len: usize ) -> ( Self , & [ u8 ] )
299
- where
300
- Self : Sized ,
301
- {
302
- match buf[ 0 ] {
303
- $(
304
- $index => {
305
- let ( data, buf) = <$checkpoint_ty>:: from_compact( & buf[ 1 ..] , buf. len( ) - 1 ) ;
306
- ( Self :: $enum_variant( data) , buf)
307
- }
308
- ) +
309
- _ => unreachable!( "Junk data in database: unknown StageUnitCheckpoint variant" ) ,
310
- }
311
- }
312
- }
313
-
314
287
impl StageCheckpoint {
315
288
$(
316
289
#[ doc = $fn_get_doc]
@@ -416,53 +389,4 @@ mod tests {
416
389
let ( decoded, _) = MerkleCheckpoint :: from_compact ( & buf, encoded) ;
417
390
assert_eq ! ( decoded, checkpoint) ;
418
391
}
419
-
420
- #[ test]
421
- fn stage_unit_checkpoint_roundtrip ( ) {
422
- let mut rng = rand:: thread_rng ( ) ;
423
- let checkpoints = vec ! [
424
- StageUnitCheckpoint :: Account ( AccountHashingCheckpoint {
425
- address: Some ( rng. gen ( ) ) ,
426
- block_range: CheckpointBlockRange { from: rng. gen ( ) , to: rng. gen ( ) } ,
427
- progress: EntitiesCheckpoint {
428
- processed: rng. gen :: <u32 >( ) as u64 ,
429
- total: u32 :: MAX as u64 + rng. gen :: <u64 >( ) ,
430
- } ,
431
- } ) ,
432
- StageUnitCheckpoint :: Storage ( StorageHashingCheckpoint {
433
- address: Some ( rng. gen ( ) ) ,
434
- storage: Some ( rng. gen ( ) ) ,
435
- block_range: CheckpointBlockRange { from: rng. gen ( ) , to: rng. gen ( ) } ,
436
- progress: EntitiesCheckpoint {
437
- processed: rng. gen :: <u32 >( ) as u64 ,
438
- total: u32 :: MAX as u64 + rng. gen :: <u64 >( ) ,
439
- } ,
440
- } ) ,
441
- StageUnitCheckpoint :: Entities ( EntitiesCheckpoint {
442
- processed: rng. gen :: <u32 >( ) as u64 ,
443
- total: u32 :: MAX as u64 + rng. gen :: <u64 >( ) ,
444
- } ) ,
445
- StageUnitCheckpoint :: Execution ( ExecutionCheckpoint {
446
- block_range: CheckpointBlockRange { from: rng. gen ( ) , to: rng. gen ( ) } ,
447
- progress: EntitiesCheckpoint {
448
- processed: rng. gen :: <u32 >( ) as u64 ,
449
- total: u32 :: MAX as u64 + rng. gen :: <u64 >( ) ,
450
- } ,
451
- } ) ,
452
- StageUnitCheckpoint :: Headers ( HeadersCheckpoint {
453
- block_range: CheckpointBlockRange { from: rng. gen ( ) , to: rng. gen ( ) } ,
454
- progress: EntitiesCheckpoint {
455
- processed: rng. gen :: <u32 >( ) as u64 ,
456
- total: u32 :: MAX as u64 + rng. gen :: <u64 >( ) ,
457
- } ,
458
- } ) ,
459
- ] ;
460
-
461
- for checkpoint in checkpoints {
462
- let mut buf = Vec :: new ( ) ;
463
- let encoded = checkpoint. to_compact ( & mut buf) ;
464
- let ( decoded, _) = StageUnitCheckpoint :: from_compact ( & buf, encoded) ;
465
- assert_eq ! ( decoded, checkpoint) ;
466
- }
467
- }
468
392
}
0 commit comments