use of tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig in project teku by ConsenSys.
the class BlockImporterTest method importBlock_weakSubjectivityFailure_wrongAncestor.
@Test
public void importBlock_weakSubjectivityFailure_wrongAncestor() throws Exception {
final UInt64 wsEpoch = UInt64.valueOf(10);
final UInt64 wsEpochSlot = this.spec.computeStartSlotAtEpoch(wsEpoch);
final SignedBeaconBlock wsBlock = localChain.createBlockAtSlot(wsEpochSlot);
final SignedBeaconBlock otherBlock = otherChain.createBlockAtSlot(wsEpochSlot.plus(1));
final Spec spec = TestSpecFactory.createMinimalPhase0();
final Checkpoint wsCheckpoint = new Checkpoint(wsEpoch, wsBlock.getRoot());
final WeakSubjectivityConfig wsConfig = WeakSubjectivityConfig.builder().specProvider(spec).weakSubjectivityCheckpoint(wsCheckpoint).build();
final WeakSubjectivityValidator weakSubjectivityValidator = WeakSubjectivityValidator.lenient(wsConfig);
final BlockImporter blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, weakSubjectivityValidator, ExecutionEngineChannel.NOOP);
final BlockImportResult result = blockImporter.importBlock(otherBlock).get();
assertImportFailed(result, FailureReason.FAILED_WEAK_SUBJECTIVITY_CHECKS);
}
use of tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig in project teku by ConsenSys.
the class BlockImporterTest method importBlock_weakSubjectivityChecksPass.
@Test
public void importBlock_weakSubjectivityChecksPass() throws Exception {
final UInt64 wsEpoch = UInt64.valueOf(10);
final UInt64 wsEpochSlot = this.spec.computeStartSlotAtEpoch(wsEpoch);
final SignedBeaconBlock wsBlock = localChain.createBlockAtSlot(wsEpochSlot);
final SignedBeaconBlock nextBlock = localChain.createAndImportBlockAtSlot(wsEpochSlot.plus(1));
localChain.setSlot(wsEpochSlot.plus(1));
final Spec spec = TestSpecFactory.createMinimalPhase0();
final Checkpoint wsCheckpoint = new Checkpoint(wsEpoch, wsBlock.getRoot());
final WeakSubjectivityConfig wsConfig = WeakSubjectivityConfig.builder().specProvider(spec).weakSubjectivityCheckpoint(wsCheckpoint).build();
final WeakSubjectivityValidator weakSubjectivityValidator = WeakSubjectivityValidator.lenient(wsConfig);
final BlockImporter blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, weakSubjectivityValidator, ExecutionEngineChannel.NOOP);
// Import wsBlock
final BlockImportResult result = blockImporter.importBlock(wsBlock).get();
assertSuccessfulResult(result);
// Import next valid block
final BlockImportResult result2 = blockImporter.importBlock(nextBlock).get();
assertSuccessfulResult(result2);
}
use of tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig in project teku by ConsenSys.
the class WeakSubjectivityValidatorTest method isBlockValid_withWSCheckpoint_blockAtCheckpointEpochBoundary_matches.
@Test
public void isBlockValid_withWSCheckpoint_blockAtCheckpointEpochBoundary_matches() {
final UInt64 wsCheckpointEpoch = UInt64.valueOf(100);
final UInt64 wsCheckpointSlot = spec.computeStartSlotAtEpoch(wsCheckpointEpoch);
final Checkpoint wsCheckpoint = new Checkpoint(wsCheckpointEpoch, Bytes32.fromHexStringLenient("0x0100"));
final WeakSubjectivityConfig config = configBuilder().weakSubjectivityCheckpoint(wsCheckpoint).build();
final WeakSubjectivityValidator validator = new WeakSubjectivityValidator(config, calculator, policy);
final SignedBeaconBlock block = mockBlock(wsCheckpointSlot, wsCheckpoint.getRoot(), Bytes32.fromHexString("0x01"));
assertThat(validator.isBlockValid(block, forkChoiceStrategy)).isTrue();
}
use of tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig in project teku by ConsenSys.
the class WeakSubjectivityValidatorTest method isBlockValid_withWSCheckpoint_blockPriorToCheckpoint.
@Test
public void isBlockValid_withWSCheckpoint_blockPriorToCheckpoint() {
final Checkpoint wsCheckpoint = new Checkpoint(UInt64.valueOf(100), Bytes32.fromHexStringLenient("0x01"));
final WeakSubjectivityConfig config = configBuilder().weakSubjectivityCheckpoint(wsCheckpoint).build();
final WeakSubjectivityValidator validator = new WeakSubjectivityValidator(config, calculator, policy);
final SignedBeaconBlock block = mockBlock(10, Bytes32.fromHexString("0x02"), Bytes32.fromHexString("0x01"));
assertThat(validator.isBlockValid(block, forkChoiceStrategy)).isTrue();
}
use of tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig in project teku by ConsenSys.
the class WeakSubjectivityValidatorTest method validateLatestFinalizedCheckpoint_withWSCheckpoint_shouldRunChecksWhenFinalizedAtCheckpoint_shouldFailMultipleChecks.
@Test
public void validateLatestFinalizedCheckpoint_withWSCheckpoint_shouldRunChecksWhenFinalizedAtCheckpoint_shouldFailMultipleChecks() {
final Checkpoint wsCheckpoint = new Checkpoint(UInt64.valueOf(100), Bytes32.fromHexStringLenient("0x01"));
final WeakSubjectivityConfig config = configBuilder().weakSubjectivityCheckpoint(wsCheckpoint).build();
final WeakSubjectivityValidator validator = new WeakSubjectivityValidator(config, calculator, policy);
// Checkpoint is at the ws epoch, but has a different root
when(checkpointState.getEpoch()).thenReturn(wsCheckpoint.getEpoch());
when(checkpointState.getRoot()).thenReturn(Bytes32.fromHexStringLenient("0x02"));
when(checkpointState.getBlockSlot()).thenReturn(wsCheckpoint.getEpochStartSlot(spec));
when(calculator.isWithinWeakSubjectivityPeriod(checkpointState, currentSlot)).thenReturn(false);
when(calculator.computeWeakSubjectivityPeriod(checkpointState)).thenReturn(mockWsPeriod);
validator.validateLatestFinalizedCheckpoint(checkpointState, currentSlot);
verify(policy).onChainInconsistentWithWeakSubjectivityCheckpoint(wsCheckpoint, checkpointState.getRoot(), checkpointState.getBlockSlot());
verify(policy).onFinalizedCheckpointOutsideOfWeakSubjectivityPeriod(spec.computeEpochAtSlot(currentSlot), checkpointState, mockWsPeriod);
verifyNoMoreInteractions(policy);
}
Aggregations