Search in sources :

Example 1 with MinGenesisTimeBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent in project teku by ConsenSys.

the class Eth1DepositManagerTest method shouldStartWithStoredDepositsAndHeadAfterMinGenesisTime.

@Test
void shouldStartWithStoredDepositsAndHeadAfterMinGenesisTime() {
    final BigInteger headBlockNumber = BigInteger.valueOf(100);
    final BigInteger minGenesisBlockNumber = BigInteger.valueOf(60);
    final BigInteger lastReplayedBlock = BigInteger.valueOf(10);
    final BigInteger lastReplayedDepositIndex = BigInteger.valueOf(11);
    when(eth1DepositStorageChannel.replayDepositEvents()).thenReturn(SafeFuture.completedFuture(ReplayDepositsResult.create(lastReplayedBlock, lastReplayedDepositIndex, false)));
    withMinGenesisBlock(headBlockNumber, minGenesisBlockNumber);
    when(depositProcessingController.fetchDepositsInRange(any(), any())).thenReturn(COMPLETE);
    manager.start();
    notifyHeadBlock(headBlockNumber, MIN_GENESIS_BLOCK_TIMESTAMP + 1000);
    verify(eth1EventsChannel).setLatestPublishedDeposit(UInt64.valueOf(lastReplayedDepositIndex));
    inOrder.verify(eth1DepositStorageChannel).replayDepositEvents();
    // Find min genesis block
    inOrder.verify(minimumGenesisTimeBlockFinder).findMinGenesisTimeBlockInHistory(headBlockNumber, asyncRunner);
    // Process blocks from after the last stored block to min genesis
    inOrder.verify(depositProcessingController).fetchDepositsInRange(lastReplayedBlock.add(BigInteger.ONE), minGenesisBlockNumber);
    // Send min genesis event
    inOrder.verify(eth1EventsChannel).onMinGenesisTimeBlock(new MinGenesisTimeBlockEvent(UInt64.valueOf(MIN_GENESIS_BLOCK_TIMESTAMP), UInt64.valueOf(minGenesisBlockNumber), Bytes32.ZERO));
    // Then start the subscription to process any blocks after min genesis
    // Adding one to ensure we don't process the min genesis block a second time
    inOrder.verify(depositProcessingController).startSubscription(minGenesisBlockNumber.add(BigInteger.ONE));
    inOrder.verifyNoMoreInteractions();
    assertNoUncaughtExceptions();
}
Also used : MinGenesisTimeBlockEvent(tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 2 with MinGenesisTimeBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent in project teku by ConsenSys.

the class MinimumGenesisTimeBlockFinder method notifyMinGenesisTimeBlockReached.

static void notifyMinGenesisTimeBlockReached(Eth1EventsChannel eth1EventsChannel, EthBlock.Block block) {
    MinGenesisTimeBlockEvent event = new MinGenesisTimeBlockEvent(UInt64.valueOf(block.getTimestamp()), UInt64.valueOf(block.getNumber()), Bytes32.fromHexString(block.getHash()));
    eth1EventsChannel.onMinGenesisTimeBlock(event);
    LOG.debug("Notifying BeaconChainService of MinGenesisTimeBlock: {}", event);
}
Also used : MinGenesisTimeBlockEvent(tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent)

Example 3 with MinGenesisTimeBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent in project teku by ConsenSys.

the class AbstractKvStoreDatabaseTest method shouldThrowIfTransactionModifiedAfterDatabaseIsClosed_updateEth1Dao.

@Test
public void shouldThrowIfTransactionModifiedAfterDatabaseIsClosed_updateEth1Dao() throws Exception {
    database.storeInitialAnchor(genesisAnchor);
    final DataStructureUtil dataStructureUtil = new DataStructureUtil();
    try (final KvStoreEth1Dao.Eth1Updater updater = ((KvStoreDatabase) database).eth1Dao.eth1Updater()) {
        final MinGenesisTimeBlockEvent genesisTimeBlockEvent = dataStructureUtil.randomMinGenesisTimeBlockEvent(1);
        database.close();
        assertThatThrownBy(() -> updater.addMinGenesisTimeBlock(genesisTimeBlockEvent)).isInstanceOf(ShuttingDownException.class);
    }
}
Also used : KvStoreEth1Dao(tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreEth1Dao) MinGenesisTimeBlockEvent(tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) AbstractStorageBackedDatabaseTest(tech.pegasys.teku.storage.server.AbstractStorageBackedDatabaseTest) Test(org.junit.jupiter.api.Test)

Example 4 with MinGenesisTimeBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent in project teku by ConsenSys.

the class AbstractDatabaseTest method shouldRecordAndRetrieveGenesisInformation.

@Test
public void shouldRecordAndRetrieveGenesisInformation() {
    final DataStructureUtil util = new DataStructureUtil(spec);
    final MinGenesisTimeBlockEvent event = new MinGenesisTimeBlockEvent(util.randomUInt64(), util.randomUInt64(), util.randomBytes32());
    database.addMinGenesisTimeBlock(event);
    final Optional<MinGenesisTimeBlockEvent> fetch = database.getMinGenesisTimeBlock();
    assertThat(fetch.isPresent()).isTrue();
    assertThat(fetch.get()).isEqualToComparingFieldByField(event);
}
Also used : MinGenesisTimeBlockEvent(tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Example 5 with MinGenesisTimeBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent in project teku by ConsenSys.

the class MinGenesisTimeBlockEventSerializerTest method shouldSurviveSerialization.

@Test
void shouldSurviveSerialization() {
    final MinGenesisTimeBlockEvent original = new MinGenesisTimeBlockEvent(dataStructureUtil.randomUInt64(), dataStructureUtil.randomUInt64(), dataStructureUtil.randomBytes32());
    final byte[] serialized = serializer.serialize(original);
    final MinGenesisTimeBlockEvent deserialized = serializer.deserialize(serialized);
    assertThat(deserialized).isEqualToComparingFieldByField(original);
}
Also used : MinGenesisTimeBlockEvent(tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent) Test(org.junit.jupiter.api.Test)

Aggregations

MinGenesisTimeBlockEvent (tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent)7 Test (org.junit.jupiter.api.Test)5 BigInteger (java.math.BigInteger)2 DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 AbstractStorageBackedDatabaseTest (tech.pegasys.teku.storage.server.AbstractStorageBackedDatabaseTest)1 KvStoreEth1Dao (tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreEth1Dao)1