Search in sources :

Example 1 with ZERO

use of tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO in project teku by ConsenSys.

the class TekuNode method checkValidatorLiveness.

public void checkValidatorLiveness(final int epoch, final int totalValidatorCount, ValidatorLivenessExpectation... args) throws IOException {
    final List<UInt64> validators = new ArrayList<>();
    for (UInt64 i = UInt64.ZERO; i.isLessThan(totalValidatorCount); i = i.increment()) {
        validators.add(i);
    }
    final Map<UInt64, Boolean> data = getValidatorLivenessAtEpoch(UInt64.valueOf(epoch), validators);
    for (ValidatorLivenessExpectation expectation : args) {
        expectation.verify(data);
    }
}
Also used : ArrayList(java.util.ArrayList) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Example 2 with ZERO

use of tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO in project teku by ConsenSys.

the class BatchDataRequesterTest method shouldScheduleAdditionalBatchWhenThereIsOnlyOneBlockRemainingToFetch.

@Test
void shouldScheduleAdditionalBatchWhenThereIsOnlyOneBlockRemainingToFetch() {
    final UInt64 firstBatchStart = targetChain.getChainHead().getSlot().minus(BATCH_SIZE);
    final Batch batch = batchFactory.createBatch(targetChain, firstBatchStart, BATCH_SIZE);
    batchChain.add(batch);
    fillQueue(ZERO);
    final List<Batch> batches = batchChain.stream().collect(toList());
    assertThat(batches).hasSize(2);
    final long targetSlot = targetChain.getChainHead().getSlot().longValue();
    assertThatBatch(batches.get(0)).hasRange(firstBatchStart.intValue(), targetSlot - 1);
    assertThatBatch(batches.get(1)).hasRange(targetSlot, targetSlot);
}
Also used : BatchAssert.assertThatBatch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.BatchAssert.assertThatBatch) Batch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.Batch) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 3 with ZERO

use of tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO in project teku by ConsenSys.

the class ValidatorApiHandlerTest method sendAggregateAndProofs_shouldProcessMixOfValidAndInvalidAggregates.

@Test
void sendAggregateAndProofs_shouldProcessMixOfValidAndInvalidAggregates() {
    final SignedAggregateAndProof invalidAggregate = dataStructureUtil.randomSignedAggregateAndProof();
    final SignedAggregateAndProof validAggregate = dataStructureUtil.randomSignedAggregateAndProof();
    when(attestationManager.onAttestation(ValidateableAttestation.aggregateFromValidator(spec, invalidAggregate))).thenReturn(completedFuture(AttestationProcessingResult.invalid("Bad juju")));
    when(attestationManager.onAttestation(ValidateableAttestation.aggregateFromValidator(spec, validAggregate))).thenReturn(completedFuture(SUCCESSFUL));
    final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendAggregateAndProofs(List.of(invalidAggregate, validAggregate));
    assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(ZERO, "Bad juju")));
    // Should send both to the attestation manager.
    verify(attestationManager).onAttestation(argThat(validatableAttestation -> validatableAttestation.getSignedAggregateAndProof().equals(validAggregate)));
    verify(attestationManager).onAttestation(argThat(validatableAttestation -> validatableAttestation.getSignedAggregateAndProof().equals(invalidAggregate)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) SyncCommitteeSubscriptionManager(tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) AggregatingAttestationPool(tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool) SUCCESSFUL(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult.SUCCESSFUL) ONE(tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE) SafeFutureAssert.assertThatSafeFuture(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) BlockImportChannel(tech.pegasys.teku.statetransition.block.BlockImportChannel) AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Map(java.util.Map) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) Bytes32(org.apache.tuweni.bytes.Bytes32) ChainDataProvider(tech.pegasys.teku.api.ChainDataProvider) SendSignedBlockResult(tech.pegasys.teku.validator.api.SendSignedBlockResult) DefaultPerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.DefaultPerformanceTracker) BLSSignature(tech.pegasys.teku.bls.BLSSignature) DOES_NOT_DESCEND_FROM_LATEST_FINALIZED(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason.DOES_NOT_DESCEND_FROM_LATEST_FINALIZED) Collections.emptyList(java.util.Collections.emptyList) ValidationResultCode(tech.pegasys.teku.statetransition.validation.ValidationResultCode) Test(org.junit.jupiter.api.Test) List(java.util.List) SyncCommitteeContributionPool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) Mockito.inOrder(org.mockito.Mockito.inOrder) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) ForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier) Optional(java.util.Optional) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BlockGossipChannel(tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) SyncCommitteeSubnetSubscription(tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription) NodeSyncingException(tech.pegasys.teku.validator.api.NodeSyncingException) ForkChoiceTrigger(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) AttestationTopicSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber) SafeFuture.completedFuture(tech.pegasys.teku.infrastructure.async.SafeFuture.completedFuture) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) SyncCommitteeMessagePool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ZERO(tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Validator(tech.pegasys.teku.spec.datastructures.state.Validator) CommitteeSubscriptionRequest(tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest) InOrder(org.mockito.InOrder) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) AttestationManager(tech.pegasys.teku.statetransition.attestation.AttestationManager) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Mockito.when(org.mockito.Mockito.when) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) IntList(it.unimi.dsi.fastutil.ints.IntList) SyncState(tech.pegasys.teku.beacon.sync.events.SyncState) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) SyncStateProvider(tech.pegasys.teku.beacon.sync.events.SyncStateProvider) IntSet(it.unimi.dsi.fastutil.ints.IntSet) CheckpointState(tech.pegasys.teku.spec.datastructures.state.CheckpointState) Comparator(java.util.Comparator) SszMutableList(tech.pegasys.teku.infrastructure.ssz.SszMutableList) SpecConfigAltair(tech.pegasys.teku.spec.config.SpecConfigAltair) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) IntList(it.unimi.dsi.fastutil.ints.IntList) SszMutableList(tech.pegasys.teku.infrastructure.ssz.SszMutableList) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Test(org.junit.jupiter.api.Test)

Example 4 with ZERO

use of tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO in project teku by ConsenSys.

the class Eth1DataCache method onEth1Block.

public void onEth1Block(final Bytes32 blockHash, final UInt64 blockTimestamp) {
    final Map.Entry<UInt64, Eth1Data> previousBlock = eth1ChainCache.floorEntry(blockTimestamp);
    final Eth1Data data;
    if (previousBlock == null) {
        data = new Eth1Data(Eth1Data.EMPTY_DEPOSIT_ROOT, UInt64.ZERO, blockHash);
    } else {
        data = previousBlock.getValue().withBlockHash(blockHash);
    }
    eth1ChainCache.put(blockTimestamp, data);
    prune(blockTimestamp);
}
Also used : UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Eth1Data(tech.pegasys.teku.spec.datastructures.blocks.Eth1Data) HashMap(java.util.HashMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Map(java.util.Map)

Example 5 with ZERO

use of tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO in project teku by ConsenSys.

the class Eth1DataCacheTest method shouldPruneOldBlocksWhenNewerOnesReceived.

@Test
void shouldPruneOldBlocksWhenNewerOnesReceived() {
    final UInt64 olderBlockTimestamp = ZERO;
    final UInt64 oldBlockTimestamp = olderBlockTimestamp.plus(ONE);
    final UInt64 newBlockTimestamp = oldBlockTimestamp.plus(CACHE_DURATION).plus(ONE);
    final UInt64 newerBlockTimestamp = newBlockTimestamp.plus(CACHE_DURATION);
    eth1DataCache.onBlockWithDeposit(olderBlockTimestamp, createEth1Data(STATE_DEPOSIT_COUNT));
    eth1DataCache.onBlockWithDeposit(oldBlockTimestamp, createEth1Data(STATE_DEPOSIT_COUNT));
    assertThat(getCacheSize()).isEqualTo(2);
    // Push both old blocks out of the cache period
    eth1DataCache.onBlockWithDeposit(newBlockTimestamp, createEth1Data(STATE_DEPOSIT_COUNT));
    // But only the oldest block gets pruned because we need at least one event prior to the cache
    // period so empty blocks right at the start of the period can lookup the
    assertThat(getCacheSize()).isEqualTo(2);
    // Third block is close enough to the second that they are both kept.
    // newBlockTimestamp is now exactly at the start of the cache period so we can remove oldBlock
    eth1DataCache.onBlockWithDeposit(newerBlockTimestamp, createEth1Data(STATE_DEPOSIT_COUNT));
    assertThat(getCacheSize()).isEqualTo(2);
}
Also used : UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Aggregations

UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)136 Test (org.junit.jupiter.api.Test)85 Bytes32 (org.apache.tuweni.bytes.Bytes32)26 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)25 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)19 Optional (java.util.Optional)16 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)14 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)13 BLSSignature (tech.pegasys.teku.bls.BLSSignature)11 Spec (tech.pegasys.teku.spec.Spec)11 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)11 List (java.util.List)10 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)10 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)9 ArrayList (java.util.ArrayList)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 TestSpecFactory (tech.pegasys.teku.spec.TestSpecFactory)7 Validator (tech.pegasys.teku.spec.datastructures.state.Validator)7 PayloadAttributes (tech.pegasys.teku.spec.executionengine.PayloadAttributes)7