Skip to content

Commit

Permalink
Add Fulu
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Nov 21, 2024
1 parent ad7a043 commit 9c4a9c4
Show file tree
Hide file tree
Showing 32 changed files with 696 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public BeaconBlock getBlindedBlock(
block.getParentRoot(),
block.getStateRoot(),
getBlindedBlockBodyDeneb(block.getBody()));
case ELECTRA ->
case ELECTRA, FULU ->
new BlindedBlockElectra(
block.getSlot(),
block.getProposerIndex(),
Expand Down Expand Up @@ -147,7 +147,7 @@ public BeaconBlock getBeaconBlock(
block.getParentRoot(),
block.getStateRoot(),
getBeaconBlockBodyDeneb(block.getBody()));
case ELECTRA ->
case ELECTRA, FULU ->
new BeaconBlockElectra(
block.getSlot(),
block.getProposerIndex(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static Version fromMilestone(final SpecMilestone milestone) {
case CAPELLA -> capella;
case DENEB -> deneb;
case ELECTRA -> electra;
// TODO: when it's compatible with Dora switch to fulu
case FULU -> electra;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void shouldConvertToInternalObject(final SpecContext ctx) {
case BELLATRIX -> new BeaconStateBellatrix(beaconStateInternal);
case CAPELLA -> new BeaconStateCapella(beaconStateInternal);
case DENEB -> new BeaconStateDeneb(beaconStateInternal);
case ELECTRA -> new BeaconStateElectra(beaconStateInternal);
case ELECTRA, FULU -> new BeaconStateElectra(beaconStateInternal);
};

assertThat(beaconState.asInternalBeaconState(spec)).isEqualTo(beaconStateInternal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public MilestoneBasedEngineJsonRpcMethodsResolver(
case DENEB:
methodsByMilestone.put(milestone, denebSupportedMethods());
break;
case ELECTRA:
case ELECTRA, FULU:
methodsByMilestone.put(milestone, electraSupportedMethods());
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static tech.pegasys.teku.spec.SpecMilestone.CAPELLA;
import static tech.pegasys.teku.spec.SpecMilestone.DENEB;
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA;
import static tech.pegasys.teku.spec.SpecMilestone.FULU;
import static tech.pegasys.teku.spec.SpecMilestone.PHASE0;
import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH;

Expand All @@ -29,6 +30,7 @@
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.config.SpecConfigFulu;
import tech.pegasys.teku.spec.config.SpecConfigLoader;
import tech.pegasys.teku.spec.config.builder.SpecConfigBuilder;

Expand Down Expand Up @@ -63,9 +65,13 @@ public static Spec create(final SpecConfig config) {
.toVersionElectra()
.map(SpecConfigElectra::getElectraForkEpoch)
.orElse(FAR_FUTURE_EPOCH);
final UInt64 fuluForkEpoch =
config.toVersionFulu().map(SpecConfigFulu::getFuluForkEpoch).orElse(FAR_FUTURE_EPOCH);
final SpecMilestone highestMilestoneSupported;

if (!electraForkEpoch.equals(FAR_FUTURE_EPOCH)) {
if (!fuluForkEpoch.equals(FAR_FUTURE_EPOCH)) {
highestMilestoneSupported = FULU;
} else if (!electraForkEpoch.equals(FAR_FUTURE_EPOCH)) {
highestMilestoneSupported = ELECTRA;
} else if (!denebForkEpoch.equals(FAR_FUTURE_EPOCH)) {
highestMilestoneSupported = DENEB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.config.SpecConfigFulu;

public enum SpecMilestone {
PHASE0,
ALTAIR,
BELLATRIX,
CAPELLA,
DENEB,
ELECTRA;
ELECTRA,
FULU;

/**
* Returns true if this milestone is at or after the supplied milestone ({@code other})
Expand Down Expand Up @@ -121,6 +123,7 @@ static Optional<Bytes4> getForkVersion(
case CAPELLA -> specConfig.toVersionCapella().map(SpecConfigCapella::getCapellaForkVersion);
case DENEB -> specConfig.toVersionDeneb().map(SpecConfigDeneb::getDenebForkVersion);
case ELECTRA -> specConfig.toVersionElectra().map(SpecConfigElectra::getElectraForkVersion);
case FULU -> specConfig.toVersionFulu().map(SpecConfigFulu::getFuluForkVersion);
};
}

Expand All @@ -136,6 +139,7 @@ static Optional<UInt64> getForkEpoch(final SpecConfig specConfig, final SpecMile
case CAPELLA -> specConfig.toVersionCapella().map(SpecConfigCapella::getCapellaForkEpoch);
case DENEB -> specConfig.toVersionDeneb().map(SpecConfigDeneb::getDenebForkEpoch);
case ELECTRA -> specConfig.toVersionElectra().map(SpecConfigElectra::getElectraForkEpoch);
case FULU -> specConfig.toVersionFulu().map(SpecConfigFulu::getFuluForkEpoch);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.config.SpecConfigFulu;
import tech.pegasys.teku.spec.logic.DelegatingSpecLogic;
import tech.pegasys.teku.spec.logic.SpecLogic;
import tech.pegasys.teku.spec.logic.versions.altair.SpecLogicAltair;
import tech.pegasys.teku.spec.logic.versions.bellatrix.SpecLogicBellatrix;
import tech.pegasys.teku.spec.logic.versions.capella.SpecLogicCapella;
import tech.pegasys.teku.spec.logic.versions.deneb.SpecLogicDeneb;
import tech.pegasys.teku.spec.logic.versions.electra.SpecLogicElectra;
import tech.pegasys.teku.spec.logic.versions.fulu.SpecLogicFulu;
import tech.pegasys.teku.spec.logic.versions.phase0.SpecLogicPhase0;
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair;
Expand Down Expand Up @@ -86,6 +88,10 @@ public static Optional<SpecVersion> create(
specConfig
.toVersionElectra()
.map(specConfigElectra -> createElectra(specConfigElectra, schemaRegistryBuilder));
case FULU ->
specConfig
.toVersionFulu()
.map(specConfigFulu -> createFulu(specConfigFulu, schemaRegistryBuilder));
};
}

Expand Down Expand Up @@ -155,6 +161,21 @@ static SpecVersion createElectra(
return new SpecVersion(SpecMilestone.ELECTRA, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createFulu(
final SpecConfigFulu specConfig, final SchemaRegistryBuilder schemaRegistryBuilder) {
final SchemaRegistry schemaRegistry =
schemaRegistryBuilder.build(SpecMilestone.FULU, specConfig);
final SchemaDefinitionsElectra schemaDefinitions =
new SchemaDefinitionsElectra(
schemaRegistry,
specConfig
.getOptionalEip7594Config()
.map(__ -> new SchemaDefinitionsEip7594(schemaRegistry)));
final SpecLogicFulu specLogic =
SpecLogicFulu.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.FULU, specConfig, schemaDefinitions, specLogic);
}

public SpecMilestone getMilestone() {
return milestone;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.config;

import java.util.Objects;
import java.util.Optional;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public class DelegatingSpecConfigFulu extends DelegatingSpecConfigElectra
implements SpecConfigFulu {
private final SpecConfigFulu specConfigFulu;

public DelegatingSpecConfigFulu(final SpecConfigFulu specConfig) {
super(specConfig);
this.specConfigFulu = SpecConfigFulu.required(specConfig);
}

@Override
public Optional<SpecConfigFulu> toVersionFulu() {
return Optional.of(this);
}

@Override
public Bytes4 getFuluForkVersion() {
return specConfigFulu.getFuluForkVersion();
}

@Override
public UInt64 getFuluForkEpoch() {
return specConfigFulu.getFuluForkEpoch();
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final DelegatingSpecConfigFulu that = (DelegatingSpecConfigFulu) o;
return Objects.equals(specConfigFulu, that.specConfigFulu);
}

@Override
public int hashCode() {
return Objects.hash(specConfigFulu);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,8 @@ default Optional<SpecConfigDeneb> toVersionDeneb() {
default Optional<SpecConfigElectra> toVersionElectra() {
return Optional.empty();
}

default Optional<SpecConfigFulu> toVersionFulu() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.config;

import java.util.Optional;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public interface SpecConfigFulu extends SpecConfigElectra {

static SpecConfigFulu required(final SpecConfig specConfig) {
return specConfig
.toVersionFulu()
.orElseThrow(
() ->
new IllegalArgumentException(
"Expected Fulu spec config but got: " + specConfig.getClass().getSimpleName()));
}

Bytes4 getFuluForkVersion();

UInt64 getFuluForkEpoch();

@Override
Optional<SpecConfigFulu> toVersionFulu();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.config;

import java.util.Objects;
import java.util.Optional;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public class SpecConfigFuluImpl extends DelegatingSpecConfigElectra implements SpecConfigFulu {

private final Bytes4 fuluForkVersion;
private final UInt64 fuluForkEpoch;

public SpecConfigFuluImpl(
final SpecConfigElectra specConfig,
final Bytes4 fuluForkVersion,
final UInt64 fuluForkEpoch) {
super(specConfig);
this.fuluForkVersion = fuluForkVersion;
this.fuluForkEpoch = fuluForkEpoch;
}

@Override
public Bytes4 getFuluForkVersion() {
return fuluForkVersion;
}

@Override
public UInt64 getFuluForkEpoch() {
return fuluForkEpoch;
}

@Override
public Optional<SpecConfigFulu> toVersionFulu() {
return Optional.of(this);
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final SpecConfigFuluImpl that = (SpecConfigFuluImpl) o;
return Objects.equals(specConfig, that.specConfig)
&& Objects.equals(fuluForkVersion, that.fuluForkVersion)
&& Objects.equals(fuluForkEpoch, that.fuluForkEpoch);
}

@Override
public int hashCode() {
return Objects.hash(specConfig, fuluForkVersion, fuluForkEpoch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import tech.pegasys.teku.spec.config.builder.DenebBuilder;
import tech.pegasys.teku.spec.config.builder.Eip7594Builder;
import tech.pegasys.teku.spec.config.builder.ElectraBuilder;
import tech.pegasys.teku.spec.config.builder.FuluBuilder;
import tech.pegasys.teku.spec.config.builder.SpecConfigBuilder;

public class SpecConfigReader {
Expand Down Expand Up @@ -218,6 +219,16 @@ public void loadFromMap(
unprocessedConfig.remove(constantKey);
});

// Process Fulu config
streamConfigSetters(FuluBuilder.class)
.forEach(
setter -> {
final String constantKey = camelToSnakeCase(setter.getName());
final Object rawValue = unprocessedConfig.get(constantKey);
invokeSetter(setter, configBuilder::fuluBuilder, constantKey, rawValue);
unprocessedConfig.remove(constantKey);
});

// Check any constants that have been configured and then ignore
final Set<String> configuredConstants =
Sets.intersection(CONSTANT_KEYS, unprocessedConfig.keySet());
Expand Down
Loading

0 comments on commit 9c4a9c4

Please sign in to comment.