use of tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0 in project teku by ConsenSys.
the class ValidatorStatusFactoryPhase0 method processParticipation.
@Override
protected void processParticipation(final List<ValidatorStatus> statuses, final BeaconState genericState, final UInt64 previousEpoch, final UInt64 currentEpoch) {
final BeaconStatePhase0 state = BeaconStatePhase0.required(genericState);
Stream.concat(state.getPrevious_epoch_attestations().stream(), state.getCurrent_epoch_attestations().stream()).forEach(attestation -> {
final AttestationData data = attestation.getData();
final AttestationUpdates updates = new AttestationUpdates();
final Checkpoint target = data.getTarget();
if (target.getEpoch().equals(currentEpoch)) {
updates.currentEpochSourceAttester = true;
updates.currentEpochTargetAttester = matchesEpochStartBlock(state, currentEpoch, target.getRoot());
} else if (target.getEpoch().equals(previousEpoch)) {
updates.previousEpochSourceAttester = true;
updates.inclusionInfo = Optional.of(new InclusionInfo(attestation.getInclusion_delay(), attestation.getProposer_index()));
if (matchesEpochStartBlock(state, previousEpoch, target.getRoot())) {
updates.previousEpochTargetAttester = true;
updates.previousEpochHeadAttester = beaconStateAccessors.getBlockRootAtSlot(state, data.getSlot()).equals(data.getBeacon_block_root());
}
}
// Apply flags to attestingIndices
attestationUtil.streamAttestingIndices(state, data, attestation.getAggregation_bits()).mapToObj(statuses::get).forEach(updates::apply);
});
}
use of tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0 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.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0 in project teku by ConsenSys.
the class ForkUpgradeTestExecutor method processAltairUpgrade.
private void processAltairUpgrade(final TestDefinition testDefinition) {
final SpecVersion spec = testDefinition.getSpec().getGenesisSpec();
final BeaconStateSchema<BeaconStatePhase0, MutableBeaconStatePhase0> phase0Schema = BeaconStateSchemaPhase0.create(spec.getConfig());
final BeaconState preState = TestDataUtils.loadSsz(testDefinition, "pre.ssz_snappy", phase0Schema);
final BeaconState postState = TestDataUtils.loadStateFromSsz(testDefinition, "post.ssz_snappy");
final StateUpgrade<?> stateUpgrade = testDefinition.getSpec().getGenesisSpec().getStateUpgrade().orElseThrow();
final BeaconState updated = stateUpgrade.upgrade(preState);
assertThatSszData(updated).isEqualByGettersTo(postState);
}
use of tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0 in project teku by ConsenSys.
the class BeaconStateTest method shouldConvertToInternalObject.
@TestTemplate
public void shouldConvertToInternalObject(SpecContext ctx) {
final tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState beaconStateInternal = ctx.getDataStructureUtil().randomBeaconState();
final Spec spec = ctx.getSpec();
final BeaconState beaconState;
switch(spec.getGenesisSpec().getMilestone()) {
case PHASE0:
beaconState = new BeaconStatePhase0(beaconStateInternal);
break;
case ALTAIR:
beaconState = new BeaconStateAltair(beaconStateInternal);
break;
case BELLATRIX:
beaconState = new BeaconStateBellatrix(beaconStateInternal);
break;
default:
throw new IllegalStateException("Unsupported milestone");
}
assertThat(beaconState.asInternalBeaconState(spec)).isEqualTo(beaconStateInternal);
}
use of tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0 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