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