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