use of tech.pegasys.teku.api.schema.BeaconState in project teku by ConsenSys.
the class TekuNode method waitForAttestationBeingGossiped.
public void waitForAttestationBeingGossiped(int validatorSeparationIndex, int totalValidatorCount) {
List<UInt64> node1Validators = IntStream.range(0, validatorSeparationIndex).mapToObj(UInt64::valueOf).collect(toList());
List<UInt64> node2Validators = IntStream.range(validatorSeparationIndex, totalValidatorCount).mapToObj(UInt64::valueOf).collect(toList());
waitFor(() -> {
final Optional<SignedBlock> maybeBlock = fetchHeadBlock();
final Optional<BeaconState> maybeState = fetchHeadState();
assertThat(maybeBlock).isPresent();
assertThat(maybeState).isPresent();
SignedBeaconBlock block = (SignedBeaconBlock) maybeBlock.get();
BeaconState state = maybeState.get();
// Check that the fetched block and state are in sync
assertThat(state.latest_block_header.parent_root).isEqualTo(block.getMessage().parent_root);
tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState internalBeaconState = state.asInternalBeaconState(spec);
UInt64 proposerIndex = block.getMessage().proposer_index;
Set<UInt64> attesterIndicesInAttestations = block.getMessage().getBody().attestations.stream().map(a -> spec.getAttestingIndices(internalBeaconState, a.asInternalAttestation(spec).getData(), a.asInternalAttestation(spec).getAggregationBits())).flatMap(Collection::stream).map(UInt64::valueOf).collect(toSet());
if (node1Validators.contains(proposerIndex)) {
assertThat(attesterIndicesInAttestations.stream().anyMatch(node2Validators::contains)).isTrue();
} else if (node2Validators.contains(proposerIndex)) {
assertThat(attesterIndicesInAttestations.stream().anyMatch(node1Validators::contains)).isTrue();
} else {
throw new IllegalStateException("Proposer index greater than total validator count");
}
}, 2, MINUTES);
}
use of tech.pegasys.teku.api.schema.BeaconState in project teku by ConsenSys.
the class TekuNode method waitForValidators.
public void waitForValidators(int numberOfValidators) {
waitFor(() -> {
Optional<BeaconState> maybeState = fetchHeadState();
assertThat(maybeState).isPresent();
BeaconState state = maybeState.get();
assertThat(state.asInternalBeaconState(spec).getValidators().size()).isEqualTo(numberOfValidators);
});
}
use of tech.pegasys.teku.api.schema.BeaconState in project teku by ConsenSys.
the class JsonProviderTest method beaconStateJsonTest.
@Test
void beaconStateJsonTest() throws JsonProcessingException {
tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState stateInternal = dataStructureUtil.randomBeaconState(UInt64.valueOf(16));
BeaconState state = new BeaconStatePhase0(stateInternal);
String jsonState = jsonProvider.objectToJSON(state);
assertTrue(jsonState.length() > 0);
}
use of tech.pegasys.teku.api.schema.BeaconState in project teku by ConsenSys.
the class GetStateResponseV2Deserializer method deserialize.
@Override
public GetStateResponseV2 deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
JsonNode node = jp.getCodec().readTree(jp);
final Version version = Version.valueOf(node.findValue("version").asText().toLowerCase(Locale.ROOT));
final JsonNode executionOptimisticNode = node.findValue("execution_optimistic");
final Boolean executionOptimistic = executionOptimisticNode != null ? executionOptimisticNode.asBoolean() : null;
final BeaconState state;
switch(version) {
case altair:
state = mapper.treeToValue(node.findValue("data"), BeaconStateAltair.class);
break;
case phase0:
state = mapper.treeToValue(node.findValue("data"), BeaconStatePhase0.class);
break;
default:
throw new IOException("Milestone was not able to be decoded");
}
return new GetStateResponseV2(version, executionOptimistic, state);
}
Aggregations