Search in sources :

Example 1 with Eth1EventsChannel

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

the class DepositProcessingController method fetchLatestDepositsOneBlockAtATime.

private synchronized void fetchLatestDepositsOneBlockAtATime() {
    final BigInteger nextBlockNumber;
    synchronized (DepositProcessingController.this) {
        if (isActiveOrAlreadyQueriedLatestCanonicalBlock()) {
            return;
        }
        active = true;
        nextBlockNumber = latestSuccessfullyQueriedBlock.add(BigInteger.ONE);
    }
    depositFetcher.fetchDepositsInRange(nextBlockNumber, nextBlockNumber).thenCompose(__ -> eth1Provider.getGuaranteedEth1Block(UInt64.valueOf(nextBlockNumber))).thenAccept(block -> {
        final BigInteger blockNumber = block.getNumber();
        LOG.trace("Successfully fetched block {} for min genesis checking", blockNumber);
        if (MinimumGenesisTimeBlockFinder.compareBlockTimestampToMinGenesisTime(config, block) >= 0) {
            notifyMinGenesisTimeBlockReached(eth1EventsChannel, block);
            isBlockByBlockModeOn = false;
            LOG.debug("Minimum genesis time block reached, switching back to fetching deposits by range");
        } else {
            LOG.trace("Seconds until min genesis block {}", config.getMinGenesisTime().minus(calculateCandidateGenesisTimestamp(config, block.getTimestamp())));
        }
    }).finish(__ -> onSubscriptionDepositRequestSuccessful(nextBlockNumber), (err) -> onSubscriptionDepositRequestFailed(err, nextBlockNumber));
}
Also used : AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) MinimumGenesisTimeBlockFinder.notifyMinGenesisTimeBlockReached(tech.pegasys.teku.pow.MinimumGenesisTimeBlockFinder.notifyMinGenesisTimeBlockReached) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Throwables(com.google.common.base.Throwables) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) MinimumGenesisTimeBlockFinder.calculateCandidateGenesisTimestamp(tech.pegasys.teku.pow.MinimumGenesisTimeBlockFinder.calculateCandidateGenesisTimestamp) InvalidDepositEventsException(tech.pegasys.teku.ethereum.pow.api.InvalidDepositEventsException) Logger(org.apache.logging.log4j.Logger) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BigInteger(java.math.BigInteger) Constants(tech.pegasys.teku.spec.config.Constants) LogManager(org.apache.logging.log4j.LogManager) Eth1EventsChannel(tech.pegasys.teku.pow.api.Eth1EventsChannel) BigInteger(java.math.BigInteger)

Aggregations

Throwables (com.google.common.base.Throwables)1 BigInteger (java.math.BigInteger)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 InvalidDepositEventsException (tech.pegasys.teku.ethereum.pow.api.InvalidDepositEventsException)1 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 MinimumGenesisTimeBlockFinder.calculateCandidateGenesisTimestamp (tech.pegasys.teku.pow.MinimumGenesisTimeBlockFinder.calculateCandidateGenesisTimestamp)1 MinimumGenesisTimeBlockFinder.notifyMinGenesisTimeBlockReached (tech.pegasys.teku.pow.MinimumGenesisTimeBlockFinder.notifyMinGenesisTimeBlockReached)1 Eth1EventsChannel (tech.pegasys.teku.pow.api.Eth1EventsChannel)1 Constants (tech.pegasys.teku.spec.config.Constants)1 SpecConfig (tech.pegasys.teku.spec.config.SpecConfig)1