Search in sources :

Example 1 with ReplayDepositsResult

use of tech.pegasys.teku.storage.api.schema.ReplayDepositsResult in project teku by ConsenSys.

the class DepositStorageTest method shouldFailIfStoredDepositsEventIsMissingDeposits.

@ParameterizedTest(name = "{0}")
@ArgumentsSource(StorageSystemArgumentsProvider.class)
public void shouldFailIfStoredDepositsEventIsMissingDeposits(final String storageType, final StorageSystemArgumentsProvider.StorageSystemSupplier storageSystemSupplier) {
    setup(storageSystemSupplier);
    final DepositsFromBlockEvent invalidEvent = new UnsafeDepositsFromBlockEvent(block_99.getBlockNumber(), block_99.getBlockHash(), block_99.getBlockTimestamp(), List.of(dataStructureUtil.randomDepositEvent(UInt64.valueOf(0)), // Deposit at index 1 is skipped
    dataStructureUtil.randomDepositEvent(UInt64.valueOf(2))));
    database.addDepositsFromBlockEvent(invalidEvent);
    SafeFuture<ReplayDepositsResult> future = depositStorage.replayDepositEvents();
    assertThat(future).isCompletedExceptionally();
    assertThatThrownBy(future::get).hasCauseInstanceOf(InvalidDepositEventsException.class);
}
Also used : ReplayDepositsResult(tech.pegasys.teku.storage.api.schema.ReplayDepositsResult) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 2 with ReplayDepositsResult

use of tech.pegasys.teku.storage.api.schema.ReplayDepositsResult in project teku by ConsenSys.

the class DepositStorageTest method shouldSendGenesisBeforeFirstDeposit.

@ParameterizedTest(name = "{0}")
@ArgumentsSource(StorageSystemArgumentsProvider.class)
public void shouldSendGenesisBeforeFirstDeposit(final String storageType, final StorageSystemArgumentsProvider.StorageSystemSupplier storageSystemSupplier) throws ExecutionException, InterruptedException {
    setup(storageSystemSupplier);
    final DepositsFromBlockEvent postGenesisDeposits = dataStructureUtil.randomDepositsFromBlockEvent(101L, 0, 21);
    database.addMinGenesisTimeBlock(genesis_100);
    database.addDepositsFromBlockEvent(postGenesisDeposits);
    SafeFuture<ReplayDepositsResult> future = depositStorage.replayDepositEvents();
    assertThat(future).isCompleted();
    assertThat(eventsChannel.getOrderedList()).containsExactly(genesis_100, postGenesisDeposits);
    assertThat(eventsChannel.getGenesis()).isEqualToComparingFieldByField(genesis_100);
    assertThat(future.get().getLastProcessedBlockNumber()).isEqualTo(postGenesisDeposits.getBlockNumber().bigIntegerValue());
    assertThat(future.get().getLastProcessedDepositIndex()).hasValue(postGenesisDeposits.getLastDepositIndex().bigIntegerValue());
    assertThat(future.get().isPastMinGenesisBlock()).isTrue();
}
Also used : ReplayDepositsResult(tech.pegasys.teku.storage.api.schema.ReplayDepositsResult) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 3 with ReplayDepositsResult

use of tech.pegasys.teku.storage.api.schema.ReplayDepositsResult in project teku by ConsenSys.

the class DepositStorage method replayDeposits.

private ReplayDepositsResult replayDeposits() {
    final DepositSequencer depositSequencer = new DepositSequencer(eth1EventsChannel, database.getMinGenesisTimeBlock());
    try (Stream<DepositsFromBlockEvent> eventStream = database.streamDepositsFromBlocks()) {
        eventStream.forEach(depositSequencer::depositEvent);
    }
    ReplayDepositsResult result = depositSequencer.depositsComplete();
    lastReplayedBlock = Optional.of(result.getLastProcessedBlockNumber());
    return result;
}
Also used : ReplayDepositsResult(tech.pegasys.teku.storage.api.schema.ReplayDepositsResult) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent)

Aggregations

DepositsFromBlockEvent (tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent)3 ReplayDepositsResult (tech.pegasys.teku.storage.api.schema.ReplayDepositsResult)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)2