Search in sources :

Example 1 with WeakSubjectivityConfig

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);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityValidator(tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Spec(tech.pegasys.teku.spec.Spec) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Test(org.junit.jupiter.api.Test)

Example 2 with WeakSubjectivityConfig

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);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityValidator(tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Spec(tech.pegasys.teku.spec.Spec) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Test(org.junit.jupiter.api.Test)

Example 3 with WeakSubjectivityConfig

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();
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Test(org.junit.jupiter.api.Test)

Example 4 with WeakSubjectivityConfig

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();
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Test(org.junit.jupiter.api.Test)

Example 5 with WeakSubjectivityConfig

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);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) Test(org.junit.jupiter.api.Test)

Aggregations

WeakSubjectivityConfig (tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig)28 Test (org.junit.jupiter.api.Test)26 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)23 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)14 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)10 DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)4 CombinedChainDataClient (tech.pegasys.teku.storage.client.CombinedChainDataClient)4 WeakSubjectivityState (tech.pegasys.teku.storage.events.WeakSubjectivityState)3 Spec (tech.pegasys.teku.spec.Spec)2 BlockImportResult (tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)2 WeakSubjectivityValidator (tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 WeakSubjectivityUpdate (tech.pegasys.teku.storage.events.WeakSubjectivityUpdate)1