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();
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations