Search in sources :

Example 1 with BeaconStatePhase0

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);
    });
}
Also used : AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) BeaconStatePhase0(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0) InclusionInfo(tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.InclusionInfo)

Example 2 with BeaconStatePhase0

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);
}
Also used : BeaconStatePhase0(tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0) BeaconState(tech.pegasys.teku.api.schema.BeaconState) Test(org.junit.jupiter.api.Test)

Example 3 with BeaconStatePhase0

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);
}
Also used : MutableBeaconStatePhase0(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.MutableBeaconStatePhase0) SpecVersion(tech.pegasys.teku.spec.SpecVersion) MutableBeaconStatePhase0(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.MutableBeaconStatePhase0) BeaconStatePhase0(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 4 with BeaconStatePhase0

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);
}
Also used : BeaconStateBellatrix(tech.pegasys.teku.api.schema.bellatrix.BeaconStateBellatrix) BeaconStatePhase0(tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0) Spec(tech.pegasys.teku.spec.Spec) BeaconStateAltair(tech.pegasys.teku.api.schema.altair.BeaconStateAltair) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 5 with BeaconStatePhase0

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);
}
Also used : GetStateResponseV2(tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2) Version(tech.pegasys.teku.api.schema.Version) JsonNode(com.fasterxml.jackson.databind.JsonNode) BeaconStatePhase0(tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0) IOException(java.io.IOException) BeaconStateAltair(tech.pegasys.teku.api.schema.altair.BeaconStateAltair) BeaconState(tech.pegasys.teku.api.schema.BeaconState)

Aggregations

BeaconStatePhase0 (tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0)4 BeaconStatePhase0 (tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0)3 Test (org.junit.jupiter.api.Test)2 BeaconState (tech.pegasys.teku.api.schema.BeaconState)2 BeaconStateAltair (tech.pegasys.teku.api.schema.altair.BeaconStateAltair)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 TestTemplate (org.junit.jupiter.api.TestTemplate)1 GetStateResponseV2 (tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2)1 Version (tech.pegasys.teku.api.schema.Version)1 BeaconStateBellatrix (tech.pegasys.teku.api.schema.bellatrix.BeaconStateBellatrix)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 Spec (tech.pegasys.teku.spec.Spec)1 SpecVersion (tech.pegasys.teku.spec.SpecVersion)1 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)1 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)1 Validator (tech.pegasys.teku.spec.datastructures.state.Validator)1 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)1 MutableBeaconStatePhase0 (tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.MutableBeaconStatePhase0)1 InclusionInfo (tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.InclusionInfo)1