Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merge] add merge spec datastructures #4503

Merged
merged 12 commits into from
Oct 26, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import tech.pegasys.teku.api.schema.interfaces.State;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateSchemaAltair;
import tech.pegasys.teku.ssz.SszList;
import tech.pegasys.teku.ssz.collections.SszBitvector;
import tech.pegasys.teku.ssz.primitive.SszByte;
Expand Down Expand Up @@ -125,8 +126,7 @@ protected void applyAdditionalFields(final MutableBeaconState state) {
beaconStateAltair -> {
final tech.pegasys.teku.spec.datastructures.state.SyncCommittee.SyncCommitteeSchema
syncCommitteeSchema =
beaconStateAltair
.getBeaconStateSchemaAltair()
((BeaconStateSchemaAltair) beaconStateAltair.getBeaconStateSchema())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajsutton going down to that path I found this. do you think we should then implement the toVersion<Milestone> pattern in BeaconStateSchema too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it's more likely a required kind of pattern where it just throws an exception if it's the wrong type (with useful detail). Code like this won't be able to handle getting an empty Optional back. But yes that's definitely better than casting.

.getCurrentSyncCommitteeSchema();
final SszList<SszByte> previousEpochParticipation =
beaconStateAltair
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@

public interface BeaconStateAltair extends BeaconState {

default BeaconStateSchemaAltair getBeaconStateSchemaAltair() {
return (BeaconStateSchemaAltair) getSchema();
}

static BeaconStateAltair required(final BeaconState state) {
return state
.toVersionAltair()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class BeaconStateAltairImpl extends AbstractBeaconState<MutableBeaconStateAltair
super(type, backingNode);
}

@Override
public BeaconStateSchemaAltair getBeaconStateSchema() {
return (BeaconStateSchemaAltair) getSchema();
}

@Override
public MutableBeaconStateAltair createWritableCopy() {
return new MutableBeaconStateAltairImpl(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class MutableBeaconStateAltairImpl extends AbstractMutableBeaconState<BeaconStat
super(backingImmutableView, builder);
}

@Override
public BeaconStateSchemaAltair getBeaconStateSchema() {
return (BeaconStateSchemaAltair) getSchema();
}

@Override
protected BeaconStateAltairImpl createImmutableBeaconState(
TreeNode backingNode, IntCache<SszData> viewCache, TransitionCaches transitionCache) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

public interface BeaconStateMerge extends BeaconStateAltair {

default BeaconStateSchemaMerge getBeaconStateSchemaMerge() {
return (BeaconStateSchemaMerge) getSchema();
}

static BeaconStateMerge required(final BeaconState state) {
return state
.toVersionMerge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class BeaconStateMergeImpl extends AbstractBeaconState<MutableBeaconStateMerge>
super(type, backingNode);
}

@Override
public BeaconStateSchemaMerge getBeaconStateSchema() {
return (BeaconStateSchemaMerge) getSchema();
}

@Override
public MutableBeaconStateMerge createWritableCopy() {
return new MutableBeaconStateMergeImpl(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class MutableBeaconStateMergeImpl extends AbstractMutableBeaconState<BeaconState
super(backingImmutableView, builder);
}

@Override
public BeaconStateSchemaMerge getBeaconStateSchema() {
return (BeaconStateSchemaMerge) getSchema();
}

@Override
protected BeaconStateMergeImpl createImmutableBeaconState(
TreeNode backingNode, IntCache<SszData> viewCache, TransitionCaches transitionCache) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

public interface BeaconStatePhase0 extends BeaconState {

default BeaconStateSchemaPhase0 getBeaconStateSchemaPhase0() {
@Override
default BeaconStateSchemaPhase0 getBeaconStateSchema() {
return (BeaconStateSchemaPhase0) getSchema();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class BeaconStatePhase0Impl extends AbstractBeaconState<MutableBeaconStatePhase0
super(type, backingNode);
}

@Override
public BeaconStateSchemaPhase0 getBeaconStateSchema() {
return (BeaconStateSchemaPhase0) getSchema();
}

@Override
public <E1 extends Exception, E2 extends Exception, E3 extends Exception>
BeaconStatePhase0 updatedPhase0(Mutator<MutableBeaconStatePhase0, E1, E2, E3> mutator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public int getPreviousEpochAttestationCapacity(final BeaconState genericState) {
final BeaconStatePhase0 state = BeaconStatePhase0.required(genericState);
final int absoluteMax =
Math.toIntExact(
state.getBeaconStateSchemaPhase0().getPreviousEpochAttestationsSchema().getMaxLength());
state.getBeaconStateSchema().getPreviousEpochAttestationsSchema().getMaxLength());
return absoluteMax - state.getPrevious_epoch_attestations().size();
}
}