@@ -362,6 +362,8 @@ void shouldStartWithStoredDepositsChainReorgedToBeShorter() {
362
362
final BigInteger headBlockNumber = BigInteger .valueOf (60 );
363
363
final BigInteger lastReplayedBlock = BigInteger .valueOf (70 );
364
364
final BigInteger lastReplayedDepositIndex = BigInteger .valueOf (71 );
365
+
366
+ // No deposit tree snapshot loaded, this will be used
365
367
when (eth1DepositStorageChannel .replayDepositEvents ())
366
368
.thenReturn (
367
369
SafeFuture .completedFuture (
@@ -383,31 +385,63 @@ void shouldStartWithStoredDepositsChainReorgedToBeShorter() {
383
385
}
384
386
385
387
@ Test
386
- void shouldStartFromSnapshotFileWhenProvided () {
388
+ void shouldIgnoreSnapshotFileWhenDBSavedVersionProvided () {
387
389
final UInt64 deposits = UInt64 .valueOf (100 );
388
390
final BigInteger lastBlockNumber = BigInteger .valueOf (1000 );
389
391
390
- // DepositTreeSnapshot from file will be used to start from
392
+ // This one will be ignored as DB already has a saved version
391
393
final DepositTreeSnapshot depositTreeSnapshotFromFile =
392
394
dataStructureUtil .randomDepositTreeSnapshot (
393
395
deposits .longValue (), UInt64 .valueOf (lastBlockNumber ));
394
396
when (depositSnapshotFileLoader .loadDepositSnapshot ())
395
397
.thenReturn (LoadDepositSnapshotResult .create (Optional .of (depositTreeSnapshotFromFile )));
396
398
when (depositProcessingController .fetchDepositsInRange (any (), any ())).thenReturn (COMPLETE );
397
399
398
- // This one will be ignored
400
+ // DepositTreeSnapshot from DB will be used to start from
401
+ final UInt64 dbDepositCount = deposits .plus (50 );
402
+ final UInt64 dbBlockHeight = UInt64 .valueOf (lastBlockNumber ).plus (500 );
399
403
final DepositTreeSnapshot depositTreeSnapshotFromDb =
400
- dataStructureUtil .randomDepositTreeSnapshot (
401
- deposits .plus (50 ).longValue (), UInt64 .valueOf (lastBlockNumber ).plus (500 ));
404
+ dataStructureUtil .randomDepositTreeSnapshot (dbDepositCount .longValue (), dbBlockHeight );
402
405
when (depositSnapshotStorageLoader .loadDepositSnapshot ())
403
406
.thenReturn (
404
407
SafeFuture .completedFuture (
405
408
LoadDepositSnapshotResult .create (Optional .of (depositTreeSnapshotFromDb ))));
406
409
407
410
manager .start ();
408
411
notifyHeadBlock (lastBlockNumber , MIN_GENESIS_BLOCK_TIMESTAMP + 1000 );
412
+ verify (depositSnapshotFileLoader , never ()).loadDepositSnapshot ();
409
413
verify (eth1DepositStorageChannel , never ()).replayDepositEvents ();
410
- verify (eth1EventsChannel ).setLatestPublishedDeposit (deposits .decrement ());
414
+ verify (eth1EventsChannel ).setLatestPublishedDeposit (dbDepositCount .decrement ());
415
+ inOrder
416
+ .verify (depositProcessingController )
417
+ .startSubscription (dbBlockHeight .bigIntegerValue ().add (BigInteger .ONE ));
418
+ inOrder .verifyNoMoreInteractions ();
419
+ assertNoUncaughtExceptions ();
420
+ }
421
+
422
+ @ Test
423
+ void shouldTakeSnapshotFileWhenDBSavedVersionNotProvided () {
424
+ final UInt64 depositsCount = UInt64 .valueOf (100 );
425
+ final BigInteger lastBlockNumber = BigInteger .valueOf (1000 );
426
+
427
+ // This one will be used as DB empty
428
+ final DepositTreeSnapshot depositTreeSnapshotFromFile =
429
+ dataStructureUtil .randomDepositTreeSnapshot (
430
+ depositsCount .longValue (), UInt64 .valueOf (lastBlockNumber ));
431
+ when (depositSnapshotFileLoader .loadDepositSnapshot ())
432
+ .thenReturn (LoadDepositSnapshotResult .create (Optional .of (depositTreeSnapshotFromFile )));
433
+ when (depositProcessingController .fetchDepositsInRange (any (), any ())).thenReturn (COMPLETE );
434
+
435
+ // DepositTreeSnapshot from DB empty
436
+ when (depositSnapshotStorageLoader .loadDepositSnapshot ())
437
+ .thenReturn (SafeFuture .completedFuture (LoadDepositSnapshotResult .EMPTY ));
438
+
439
+ manager .start ();
440
+ notifyHeadBlock (lastBlockNumber , MIN_GENESIS_BLOCK_TIMESTAMP + 1000 );
441
+ verify (depositSnapshotStorageLoader ).loadDepositSnapshot ();
442
+ verify (depositSnapshotFileLoader ).loadDepositSnapshot ();
443
+ verify (eth1DepositStorageChannel , never ()).replayDepositEvents ();
444
+ verify (eth1EventsChannel ).setLatestPublishedDeposit (depositsCount .decrement ());
411
445
inOrder
412
446
.verify (depositProcessingController )
413
447
.startSubscription (lastBlockNumber .add (BigInteger .ONE ));
@@ -444,8 +478,8 @@ void shouldStartFromStorageSnapshotWhenProvided() {
444
478
}
445
479
446
480
@ Test
447
- void shouldStartFromBestSnapshotWhenOptionEnabled () {
448
- final Eth1DepositManager manager2 =
481
+ void shouldUseCustomDepositSnapshotPathWhenProvided () {
482
+ final Eth1DepositManager manager =
449
483
new Eth1DepositManager (
450
484
config ,
451
485
eth1Provider ,
@@ -460,34 +494,26 @@ void shouldStartFromBestSnapshotWhenOptionEnabled() {
460
494
Optional .empty (),
461
495
eth1HeadTracker );
462
496
463
- final UInt64 deposits = UInt64 .valueOf (100 );
464
- final BigInteger lastBlockNumberFile = BigInteger .valueOf (1000 );
465
- final BigInteger lastBlockNumberStorage = BigInteger .valueOf (2000 );
497
+ final UInt64 depositsCount = UInt64 .valueOf (100 );
498
+ final BigInteger lastBlockNumber = BigInteger .valueOf (1000 );
466
499
467
- // DepositTreeSnapshot from file will be loaded
500
+ // Custom deposit snapshot path provided, so will be used
468
501
final DepositTreeSnapshot depositTreeSnapshotFromFile =
469
502
dataStructureUtil .randomDepositTreeSnapshot (
470
- deposits .longValue (), UInt64 .valueOf (lastBlockNumberFile ));
503
+ depositsCount .longValue (), UInt64 .valueOf (lastBlockNumber ));
471
504
when (depositSnapshotFileLoader .loadDepositSnapshot ())
472
505
.thenReturn (LoadDepositSnapshotResult .create (Optional .of (depositTreeSnapshotFromFile )));
473
506
when (depositProcessingController .fetchDepositsInRange (any (), any ())).thenReturn (COMPLETE );
474
507
475
- // Storage snapshot will be loaded too and compared to the one from file
476
- final DepositTreeSnapshot depositTreeSnapshotFromDb =
477
- dataStructureUtil .randomDepositTreeSnapshot (
478
- deposits .longValue (), UInt64 .valueOf (lastBlockNumberStorage ));
479
- when (depositSnapshotStorageLoader .loadDepositSnapshot ())
480
- .thenReturn (
481
- SafeFuture .completedFuture (
482
- LoadDepositSnapshotResult .create (Optional .of (depositTreeSnapshotFromDb ))));
483
-
484
- manager2 .start ();
485
- notifyHeadBlock (BigInteger .valueOf (3000 ), MIN_GENESIS_BLOCK_TIMESTAMP + 1000 );
508
+ manager .start ();
509
+ notifyHeadBlock (lastBlockNumber , MIN_GENESIS_BLOCK_TIMESTAMP + 1000 );
510
+ verify (depositSnapshotStorageLoader , never ()).loadDepositSnapshot ();
511
+ verify (depositSnapshotFileLoader ).loadDepositSnapshot ();
486
512
verify (eth1DepositStorageChannel , never ()).replayDepositEvents ();
487
- verify (eth1EventsChannel ).setLatestPublishedDeposit (deposits .decrement ());
513
+ verify (eth1EventsChannel ).setLatestPublishedDeposit (depositsCount .decrement ());
488
514
inOrder
489
515
.verify (depositProcessingController )
490
- .startSubscription (lastBlockNumberStorage .add (BigInteger .ONE ));
516
+ .startSubscription (lastBlockNumber .add (BigInteger .ONE ));
491
517
inOrder .verifyNoMoreInteractions ();
492
518
assertNoUncaughtExceptions ();
493
519
}
0 commit comments