-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Attestation and AttnetsENR schemas to registry (#8692)
* migrate Attestation and AttnetsENR schemas to registry * allow `addMilestoneMapping` with same `milestone` and `untilMilestone`
- Loading branch information
Showing
8 changed files
with
124 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AttestationSchemaProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.spec.schemas.registry; | ||
|
||
import static tech.pegasys.teku.spec.SpecMilestone.DENEB; | ||
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA; | ||
import static tech.pegasys.teku.spec.SpecMilestone.PHASE0; | ||
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTESTATION_SCHEMA; | ||
|
||
import java.util.Set; | ||
import tech.pegasys.teku.spec.SpecMilestone; | ||
import tech.pegasys.teku.spec.config.SpecConfig; | ||
import tech.pegasys.teku.spec.datastructures.operations.Attestation; | ||
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema; | ||
import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttestationElectraSchema; | ||
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema; | ||
|
||
public class AttestationSchemaProvider | ||
extends AbstractSchemaProvider<AttestationSchema<Attestation>> { | ||
|
||
public AttestationSchemaProvider() { | ||
super(ATTESTATION_SCHEMA); | ||
addMilestoneMapping(PHASE0, DENEB); | ||
addMilestoneMapping(ELECTRA, SpecMilestone.getHighestMilestone()); | ||
} | ||
|
||
@Override | ||
protected AttestationSchema<Attestation> createSchema( | ||
final SchemaRegistry registry, | ||
final SpecMilestone effectiveMilestone, | ||
final SpecConfig specConfig) { | ||
return switch (effectiveMilestone) { | ||
case PHASE0 -> | ||
new AttestationPhase0Schema(specConfig.getMaxValidatorsPerCommittee()) | ||
.castTypeToAttestationSchema(); | ||
case ELECTRA -> | ||
new AttestationElectraSchema( | ||
(long) specConfig.getMaxValidatorsPerCommittee() | ||
* specConfig.getMaxCommitteesPerSlot(), | ||
specConfig.getMaxCommitteesPerSlot()) | ||
.castTypeToAttestationSchema(); | ||
default -> | ||
throw new IllegalArgumentException( | ||
"It is not supposed to create a specific version for " + effectiveMilestone); | ||
}; | ||
} | ||
|
||
@Override | ||
public Set<SpecMilestone> getSupportedMilestones() { | ||
return ALL_MILESTONES; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../src/main/java/tech/pegasys/teku/spec/schemas/registry/AttnetsENRFieldSchemaProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.spec.schemas.registry; | ||
|
||
import static tech.pegasys.teku.spec.SpecMilestone.PHASE0; | ||
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTNETS_ENR_FIELD_SCHEMA; | ||
|
||
import java.util.Set; | ||
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector; | ||
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema; | ||
import tech.pegasys.teku.spec.SpecMilestone; | ||
import tech.pegasys.teku.spec.config.SpecConfig; | ||
|
||
public class AttnetsENRFieldSchemaProvider | ||
extends AbstractSchemaProvider<SszBitvectorSchema<SszBitvector>> { | ||
public AttnetsENRFieldSchemaProvider() { | ||
super(ATTNETS_ENR_FIELD_SCHEMA); | ||
addMilestoneMapping(PHASE0, SpecMilestone.getHighestMilestone()); | ||
} | ||
|
||
@Override | ||
protected SszBitvectorSchema<SszBitvector> createSchema( | ||
final SchemaRegistry registry, | ||
final SpecMilestone effectiveMilestone, | ||
final SpecConfig specConfig) { | ||
return SszBitvectorSchema.create(specConfig.getAttestationSubnetCount()); | ||
} | ||
|
||
@Override | ||
public Set<SpecMilestone> getSupportedMilestones() { | ||
return ALL_MILESTONES; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters