Search in sources :

Example 1 with Block

use of org.web3j.protocol.core.methods.response.EthBlock.Block in project teku by ConsenSys.

the class BlockBasedEth1HeadTrackerTest method block.

private Block block(final long blockNumber) {
    final Block block = new Block();
    block.setNumber("0x" + Long.toHexString(blockNumber));
    return block;
}
Also used : Block(org.web3j.protocol.core.methods.response.EthBlock.Block)

Example 2 with Block

use of org.web3j.protocol.core.methods.response.EthBlock.Block in project teku by ConsenSys.

the class Eth1DepositManagerTest method notifyHeadBlock.

private void notifyHeadBlock(final BigInteger blockNumber, final long timestamp) {
    final Block latestBlock = block(blockNumber, timestamp);
    when(eth1Provider.getGuaranteedEth1Block(UInt64.valueOf(blockNumber))).thenReturn(SafeFuture.completedFuture(latestBlock));
    final ArgumentCaptor<HeadUpdatedSubscriber> captor = ArgumentCaptor.forClass(HeadUpdatedSubscriber.class);
    verify(eth1HeadTracker, atLeastOnce()).subscribe(captor.capture());
    captor.getValue().onHeadUpdated(UInt64.valueOf(blockNumber));
}
Also used : Block(org.web3j.protocol.core.methods.response.EthBlock.Block) HeadUpdatedSubscriber(tech.pegasys.teku.pow.Eth1HeadTracker.HeadUpdatedSubscriber)

Example 3 with Block

use of org.web3j.protocol.core.methods.response.EthBlock.Block in project teku by ConsenSys.

the class Eth1DepositManagerTest method block.

private Block block(final BigInteger number, final long timestamp) {
    final Block block = mock(Block.class);
    when(block.getNumber()).thenReturn(number);
    when(block.getTimestamp()).thenReturn(BigInteger.valueOf(timestamp));
    when(block.getHash()).thenReturn(Bytes32.ZERO.toHexString());
    return block;
}
Also used : Block(org.web3j.protocol.core.methods.response.EthBlock.Block)

Example 4 with Block

use of org.web3j.protocol.core.methods.response.EthBlock.Block in project teku by ConsenSys.

the class BlockBasedEth1HeadTracker method onLatestBlockHead.

private void onLatestBlockHead(final Block headBlock) {
    final UInt64 headBlockNumber = UInt64.valueOf(headBlock.getNumber());
    if (headBlockNumber.compareTo(config.getEth1FollowDistance()) < 0) {
        LOG.debug("Not processing Eth1 blocks because chain has not reached minimum follow distance");
        return;
    }
    final UInt64 newHeadAtFollowDistance = headBlockNumber.minus(config.getEth1FollowDistance());
    if (headAtFollowDistance.map(current -> current.compareTo(newHeadAtFollowDistance) < 0).orElse(true)) {
        if (reachedHead.compareAndSet(false, true)) {
            reachedHead.set(true);
        }
        headAtFollowDistance = Optional.of(newHeadAtFollowDistance);
        LOG.debug("ETH1 block at follow distance updated to {}", newHeadAtFollowDistance);
        subscribers.deliver(HeadUpdatedSubscriber::onHeadUpdated, newHeadAtFollowDistance);
    }
}
Also used : AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) Logger(org.apache.logging.log4j.Logger) Block(org.web3j.protocol.core.methods.response.EthBlock.Block) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Duration(java.time.Duration) Optional(java.util.Optional) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) LogManager(org.apache.logging.log4j.LogManager) Subscribers(tech.pegasys.teku.infrastructure.subscribers.Subscribers) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Example 5 with Block

use of org.web3j.protocol.core.methods.response.EthBlock.Block in project teku by ConsenSys.

the class Eth1BlockFetcherTest method block.

private Block block(final int blockNumber, final UInt64 blockTimestamp, final Bytes32 blockHash) {
    final Block block = new Block();
    block.setNumber("0x" + Integer.toHexString(blockNumber));
    block.setTimestamp("0x" + Long.toHexString(blockTimestamp.longValue()));
    block.setHash(blockHash.toHexString());
    return block;
}
Also used : Block(org.web3j.protocol.core.methods.response.EthBlock.Block)

Aggregations

Block (org.web3j.protocol.core.methods.response.EthBlock.Block)26 EthBlock (org.web3j.protocol.core.methods.response.EthBlock)12 Test (org.junit.jupiter.api.Test)11 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)7 Optional (java.util.Optional)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 BigInteger (java.math.BigInteger)1 Duration (java.time.Duration)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 ExoContainer (org.exoplatform.container.ExoContainer)1 ExoContainerContext (org.exoplatform.container.ExoContainerContext)1 RequestLifeCycle (org.exoplatform.container.component.RequestLifeCycle)1 org.exoplatform.services.listener (org.exoplatform.services.listener)1 ExoLogger (org.exoplatform.services.log.ExoLogger)1