Search in sources :

Example 1 with PowBlock

use of tech.pegasys.teku.spec.datastructures.execution.PowBlock in project teku by ConsenSys.

the class BellatrixTransitionHelpersTest method shouldBeValidIfTerminalDifficultyConditionsMet.

@Test
void shouldBeValidIfTerminalDifficultyConditionsMet() {
    final PowBlock powBlock = withPowBlock(payload.getParentHash(), terminalDifficulty.plus(1));
    withPowBlock(powBlock.getParentHash(), terminalDifficulty.subtract(1));
    assertThat(validateMergeBlock()).isCompletedWithValue(PayloadStatus.VALID);
}
Also used : PowBlock(tech.pegasys.teku.spec.datastructures.execution.PowBlock) Test(org.junit.jupiter.api.Test)

Example 2 with PowBlock

use of tech.pegasys.teku.spec.datastructures.execution.PowBlock in project teku by ConsenSys.

the class BellatrixTransitionHelpersTest method withPowBlock.

private PowBlock withPowBlock(final Bytes32 hash, final UInt256 totalDifficulty) {
    final PowBlock powBlock = new PowBlock(hash, dataStructureUtil.randomBytes32(), totalDifficulty);
    when(executionEngine.getPowBlock(powBlock.getBlockHash())).thenReturn(completedFuture(Optional.of(powBlock)));
    return powBlock;
}
Also used : PowBlock(tech.pegasys.teku.spec.datastructures.execution.PowBlock)

Example 3 with PowBlock

use of tech.pegasys.teku.spec.datastructures.execution.PowBlock in project teku by ConsenSys.

the class MergeTransitionBlockValidatorTest method withPowBlockDifficulties.

private void withPowBlockDifficulties(final SignedBlockAndState transitionBlock, final UInt256 terminalBlockDifficulty, final UInt256 ttdBlockParentDifficulty) {
    final Bytes32 terminalBlockParentHash = dataStructureUtil.randomBytes32();
    executionEngine.addPowBlock(new PowBlock(getExecutionPayload(transitionBlock).getParentHash(), terminalBlockParentHash, terminalBlockDifficulty));
    executionEngine.addPowBlock(new PowBlock(terminalBlockParentHash, dataStructureUtil.randomBytes32(), ttdBlockParentDifficulty));
}
Also used : PowBlock(tech.pegasys.teku.spec.datastructures.execution.PowBlock) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 4 with PowBlock

use of tech.pegasys.teku.spec.datastructures.execution.PowBlock in project teku by ConsenSys.

the class TerminalPowBlockMonitorTest method shouldPerformTerminalBlockDetectionByTerminalBlockHash.

@Test
void shouldPerformTerminalBlockDetectionByTerminalBlockHash() {
    setUpTerminalBlockHashConfig();
    terminalPowBlockMonitor.start();
    // NOT YET BELLATRIX FORK - should not notify
    goToSlot(UInt64.ONE);
    assertThat(terminalPowBlockMonitor.isRunning()).isTrue();
    assertThat(asyncRunner.hasDelayedActions()).isTrue();
    asyncRunner.executeQueuedActions();
    // we call exchangeTransitionConfiguration even before bellatrix activates
    verify(executionEngine, times(1)).exchangeTransitionConfiguration(localTransitionConfiguration);
    verify(executionEngine, times(0)).getPowBlock(any());
    verify(forkChoiceNotifier, times(0)).onTerminalBlockReached(any());
    // AT BELLATRIX FORK, Terminal Bloch Epoch not reached - should not notify
    goToSlot(BELLATRIX_FORK_EPOCH.times(spec.getGenesisSpecConfig().getSlotsPerEpoch()));
    asyncRunner.executeQueuedActions();
    verify(executionEngine, times(0)).getPowBlock(any());
    verify(forkChoiceNotifier, times(0)).onTerminalBlockReached(any());
    // AT Terminal Bloch Epoch, Terminal Block Hash not found - should not notify
    goToSlot(TERMINAL_BLOCK_EPOCH.times(spec.getGenesisSpecConfig().getSlotsPerEpoch()));
    when(executionEngine.getPowBlock(TERMINAL_BLOCK_HASH)).thenReturn(completedFuture(Optional.empty()));
    asyncRunner.executeQueuedActions();
    verify(executionEngine, times(1)).getPowBlock(TERMINAL_BLOCK_HASH);
    verify(forkChoiceNotifier, times(0)).onTerminalBlockReached(any());
    // AT Terminal Bloch Epoch, Terminal Block Hash found - should notify
    when(executionEngine.getPowBlock(TERMINAL_BLOCK_HASH)).thenReturn(completedFuture(Optional.of(new PowBlock(TERMINAL_BLOCK_HASH, dataStructureUtil.randomBytes32(), UInt256.ONE))));
    asyncRunner.executeQueuedActions();
    verify(eventLogger).terminalPowBlockDetected(TERMINAL_BLOCK_HASH);
    verify(executionEngine, times(2)).getPowBlock(TERMINAL_BLOCK_HASH);
    verify(forkChoiceNotifier, times(1)).onTerminalBlockReached(TERMINAL_BLOCK_HASH);
    // MERGE Completed - should stop
    doMerge(TERMINAL_BLOCK_HASH);
    asyncRunner.executeQueuedActions();
    assertThat(terminalPowBlockMonitor.isRunning()).isFalse();
    // final check
    verify(executionEngine, atLeastOnce()).exchangeTransitionConfiguration(localTransitionConfiguration);
    verifyNoMoreInteractions(executionEngine);
    verifyNoMoreInteractions(eventLogger);
}
Also used : PowBlock(tech.pegasys.teku.spec.datastructures.execution.PowBlock) Test(org.junit.jupiter.api.Test)

Example 5 with PowBlock

use of tech.pegasys.teku.spec.datastructures.execution.PowBlock in project teku by ConsenSys.

the class ForkChoiceTestExecutor method parsePowBlock.

private PowBlock parsePowBlock(final Bytes data) {
    return SSZ.decode(data, reader -> {
        final Bytes32 blockHash = Bytes32.wrap(reader.readFixedBytes(Bytes32.SIZE));
        final Bytes32 parentHash = Bytes32.wrap(reader.readFixedBytes(Bytes32.SIZE));
        final UInt256 totalDifficulty = UInt256.valueOf(reader.readFixedBytes(Bytes32.SIZE).toUnsignedBigInteger(ByteOrder.LITTLE_ENDIAN));
        // Read difficulty even though we don't use it.
        reader.readFixedBytes(Bytes32.SIZE);
        return new PowBlock(blockHash, parentHash, totalDifficulty);
    });
}
Also used : PowBlock(tech.pegasys.teku.spec.datastructures.execution.PowBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) UInt256(org.apache.tuweni.units.bigints.UInt256)

Aggregations

PowBlock (tech.pegasys.teku.spec.datastructures.execution.PowBlock)11 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 Test (org.junit.jupiter.api.Test)5 UInt256 (org.apache.tuweni.units.bigints.UInt256)3 Duration (java.time.Duration)1 Optional (java.util.Optional)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)1 Cancellable (tech.pegasys.teku.infrastructure.async.Cancellable)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 TekuPair (tech.pegasys.teku.infrastructure.collections.TekuPair)1 EventLogger (tech.pegasys.teku.infrastructure.logging.EventLogger)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 Spec (tech.pegasys.teku.spec.Spec)1 SpecMilestone (tech.pegasys.teku.spec.SpecMilestone)1 SpecVersion (tech.pegasys.teku.spec.SpecVersion)1 SpecConfig (tech.pegasys.teku.spec.config.SpecConfig)1 SpecConfigBellatrix (tech.pegasys.teku.spec.config.SpecConfigBellatrix)1 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)1