Search in sources :

Example 1 with SchemaDefinitions

use of tech.pegasys.teku.spec.schemas.SchemaDefinitions in project teku by ConsenSys.

the class SszTestExecutor method runTest.

@Override
public void runTest(final TestDefinition testDefinition) throws Exception {
    final Bytes inputData = TestDataUtils.readSszData(testDefinition, "serialized.ssz_snappy");
    final Bytes32 expectedRoot = TestDataUtils.loadYaml(testDefinition, "roots.yaml", Roots.class).getRoot();
    final SchemaDefinitions schemaDefinitions = testDefinition.getSpec().getGenesisSchemaDefinitions();
    final SszSchema<T> sszSchema = sszType.get(schemaDefinitions);
    final T result = sszSchema.sszDeserialize(inputData);
    // Deserialize
    assertThat(result.hashTreeRoot()).isEqualTo(expectedRoot);
    // Serialize
    assertThat(result.sszSerialize()).isEqualTo(inputData);
    // Check TypeDefinition by parsing from YAML version
    final T yamlResult = TestDataUtils.loadYaml(testDefinition, "value.yaml", sszSchema.getJsonTypeDefinition());
    assertThat(yamlResult.hashTreeRoot()).isEqualTo(expectedRoot);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Bytes32(org.apache.tuweni.bytes.Bytes32) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions)

Example 2 with SchemaDefinitions

use of tech.pegasys.teku.spec.schemas.SchemaDefinitions in project teku by ConsenSys.

the class SpecVersion method createPhase0.

static SpecVersion createPhase0(final SpecConfig specConfig) {
    final SchemaDefinitions schemaDefinitions = new SchemaDefinitionsPhase0(specConfig);
    final SpecLogic specLogic = SpecLogicPhase0.create(specConfig, schemaDefinitions);
    return new SpecVersion(SpecMilestone.PHASE0, specConfig, schemaDefinitions, specLogic);
}
Also used : DelegatingSpecLogic(tech.pegasys.teku.spec.logic.DelegatingSpecLogic) SpecLogic(tech.pegasys.teku.spec.logic.SpecLogic) SchemaDefinitionsPhase0(tech.pegasys.teku.spec.schemas.SchemaDefinitionsPhase0) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions)

Example 3 with SchemaDefinitions

use of tech.pegasys.teku.spec.schemas.SchemaDefinitions in project teku by ConsenSys.

the class DataStructureUtil method createAnchorFromState.

public AnchorPoint createAnchorFromState(final BeaconState anchorState) {
    // Create corresponding block
    final SchemaDefinitions schemaDefinitions = spec.atSlot(anchorState.getSlot()).getSchemaDefinitions();
    final BeaconBlock anchorBlock = new BeaconBlock(schemaDefinitions.getBeaconBlockSchema(), anchorState.getSlot(), UInt64.ZERO, anchorState.getLatest_block_header().getParentRoot(), anchorState.hashTreeRoot(), spec.getGenesisSpec().getSchemaDefinitions().getBeaconBlockBodySchema().createEmpty());
    final SignedBeaconBlock signedAnchorBlock = SignedBeaconBlock.create(spec, anchorBlock, BLSSignature.empty());
    final Bytes32 anchorRoot = anchorBlock.hashTreeRoot();
    final UInt64 anchorEpoch = spec.getCurrentEpoch(anchorState);
    final Checkpoint anchorCheckpoint = new Checkpoint(anchorEpoch, anchorRoot);
    return AnchorPoint.create(spec, anchorCheckpoint, signedAnchorBlock, anchorState);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions)

Example 4 with SchemaDefinitions

use of tech.pegasys.teku.spec.schemas.SchemaDefinitions in project teku by ConsenSys.

the class SubnetScorerTest method shouldScoreCandidatePeersOnSubnetsWithFewPeersMoreHighly.

@Test
void shouldScoreCandidatePeersOnSubnetsWithFewPeersMoreHighly() {
    final MockNodeId node1 = new MockNodeId(0);
    final MockNodeId node2 = new MockNodeId(1);
    final MockNodeId node3 = new MockNodeId(2);
    final SubnetScorer scorer = SubnetScorer.create(PeerSubnetSubscriptions.builder(() -> schemaDefinitions).attestationSubnetSubscriptions(b -> b.addRelevantSubnet(1).addRelevantSubnet(2).addRelevantSubnet(3).addRelevantSubnet(5).addSubscriber(1, node2).addSubscriber(3, node3)).syncCommitteeSubnetSubscriptions(b -> b.addRelevantSubnet(1).addRelevantSubnet(2).addSubscriber(1, node1).addSubscriber(1, node2).addSubscriber(1, node3)).build());
    assertCandidatePeerScores(scorer, entry(candidateWithSubnets(List.of(1, 3), List.of(1)), 562), entry(candidateWithSubnets(List.of(1), List.of(1)), 312), entry(candidateWithSubnets(List.of(2), List.of(1)), 1062), entry(candidateWithSubnets(List.of(3), List.of(1)), 312), entry(candidateWithSubnets(emptyList(), emptyList()), 0), entry(candidateWithSubnets(List.of(5), emptyList()), 1000), entry(candidateWithSubnets(List.of(4), emptyList()), 0), entry(candidateWithSubnets(emptyList(), List.of(2)), 1000), entry(candidateWithSubnets(emptyList(), List.of(3)), 0));
}
Also used : MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) PeerScorer(tech.pegasys.teku.networking.eth2.peers.PeerScorer) Collections.emptyList(java.util.Collections.emptyList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions) MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) Assertions.entry(org.assertj.core.api.Assertions.entry) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) Stream(java.util.stream.Stream) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) Spec(tech.pegasys.teku.spec.Spec) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) Test(org.junit.jupiter.api.Test)

Example 5 with SchemaDefinitions

use of tech.pegasys.teku.spec.schemas.SchemaDefinitions in project teku by ConsenSys.

the class AggregationDuty method createSignedAggregateAndProof.

private SafeFuture<ProductionResult<SignedAggregateAndProof>> createSignedAggregateAndProof(final CommitteeAggregator aggregator, final Attestation aggregate) {
    final SchemaDefinitions schemaDefinitions = spec.atSlot(aggregate.getData().getSlot()).getSchemaDefinitions();
    final AggregateAndProof aggregateAndProof = schemaDefinitions.getAggregateAndProofSchema().create(aggregator.validatorIndex, aggregate, aggregator.proof);
    return forkProvider.getForkInfo(slot).thenCompose(forkInfo -> aggregator.validator.getSigner().signAggregateAndProof(aggregateAndProof, forkInfo).thenApply(signature -> ProductionResult.success(aggregator.validator.getPublicKey(), aggregateAndProof.getAggregate().getData().getBeacon_block_root(), schemaDefinitions.getSignedAggregateAndProofSchema().create(aggregateAndProof, signature))));
}
Also used : ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) BLSSignature(tech.pegasys.teku.bls.BLSSignature) AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) Duty(tech.pegasys.teku.validator.client.duties.Duty) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions) MoreObjects(com.google.common.base.MoreObjects) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) ConcurrentMap(java.util.concurrent.ConcurrentMap) Logger(org.apache.logging.log4j.Logger) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) ForkProvider(tech.pegasys.teku.validator.client.ForkProvider) ProductionResult(tech.pegasys.teku.validator.client.duties.ProductionResult) Optional(java.util.Optional) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) LogManager(org.apache.logging.log4j.LogManager) DutyResult(tech.pegasys.teku.validator.client.duties.DutyResult) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Validator(tech.pegasys.teku.validator.client.Validator) AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions)

Aggregations

SchemaDefinitions (tech.pegasys.teku.spec.schemas.SchemaDefinitions)9 Spec (tech.pegasys.teku.spec.Spec)5 List (java.util.List)4 Stream (java.util.stream.Stream)4 Bytes (org.apache.tuweni.bytes.Bytes)4 Collections.emptyList (java.util.Collections.emptyList)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 Test (org.junit.jupiter.api.Test)3 TestSpecFactory (tech.pegasys.teku.spec.TestSpecFactory)3 Function (java.util.function.Function)2 Pair (org.apache.commons.lang3.tuple.Pair)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.entry (org.assertj.core.api.Assertions.entry)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1