Skip to content

Commit

Permalink
focil spec config
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Dec 20, 2024
1 parent 4dbdd08 commit e9a0a08
Show file tree
Hide file tree
Showing 18 changed files with 725 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tech.pegasys.teku.spec.config.SpecConfigBellatrix;
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigEip7805;
import tech.pegasys.teku.spec.config.SpecConfigElectra;

public enum SpecMilestone {
Expand All @@ -35,7 +36,8 @@ public enum SpecMilestone {
BELLATRIX,
CAPELLA,
DENEB,
ELECTRA;
ELECTRA,
EIP7805;

/**
* Returns true if this milestone is at or after the supplied milestone ({@code other})
Expand Down Expand Up @@ -131,6 +133,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 EIP7805 -> specConfig.toVersionEip7805().map(SpecConfigEip7805::getEip7805ForkVersion);
};
}

Expand All @@ -146,6 +149,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 EIP7805 -> specConfig.toVersionEip7805().map(SpecConfigEip7805::getEip7805ForkEpoch);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@
import tech.pegasys.teku.spec.config.SpecConfigBellatrix;
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigEip7805;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
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.eip7805.SpecLogicEip7805;
import tech.pegasys.teku.spec.logic.versions.electra.SpecLogicElectra;
import tech.pegasys.teku.spec.logic.versions.phase0.SpecLogicPhase0;
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsCapella;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip7805;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsPhase0;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;
Expand Down Expand Up @@ -85,6 +88,10 @@ public static Optional<SpecVersion> create(
specConfig
.toVersionElectra()
.map(specConfigElectra -> createElectra(specConfigElectra, schemaRegistryBuilder));
case EIP7805 ->
specConfig
.toVersionEip7805()
.map(specConfigEip7732 -> createEip7805(specConfigEip7732, schemaRegistryBuilder));
};
}

Expand Down Expand Up @@ -149,6 +156,16 @@ static SpecVersion createElectra(
return new SpecVersion(SpecMilestone.ELECTRA, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createEip7805(
final SpecConfigEip7805 specConfig, final SchemaRegistryBuilder schemaRegistryBuilder) {
final SchemaRegistry schemaRegistry =
schemaRegistryBuilder.build(SpecMilestone.EIP7805, specConfig);
final SchemaDefinitionsEip7805 schemaDefinitions = new SchemaDefinitionsEip7805(schemaRegistry);
final SpecLogicEip7805 specLogic =
SpecLogicEip7805.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.EIP7805, specConfig, schemaDefinitions, specLogic);
}

public SpecMilestone getMilestone() {
return milestone;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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 class DelegatingSpecConfigElectra extends DelegatingSpecConfigDeneb
implements SpecConfigElectra {
private final SpecConfigElectra specConfigElectra;

public DelegatingSpecConfigElectra(final SpecConfigElectra specConfig) {
super(specConfig);
this.specConfigElectra = SpecConfigElectra.required(specConfig);
}

@Override
public Bytes4 getElectraForkVersion() {
return specConfigElectra.getElectraForkVersion();
}

@Override
public UInt64 getElectraForkEpoch() {
return specConfigElectra.getElectraForkEpoch();
}

@Override
public UInt64 getMinPerEpochChurnLimitElectra() {
return specConfigElectra.getMinPerEpochChurnLimitElectra();
}

@Override
public UInt64 getMinActivationBalance() {
return specConfigElectra.getMinActivationBalance();
}

@Override
public UInt64 getMaxEffectiveBalanceElectra() {
return specConfigElectra.getMaxEffectiveBalanceElectra();
}

@Override
public int getPendingDepositsLimit() {
return specConfigElectra.getPendingDepositsLimit();
}

@Override
public int getPendingPartialWithdrawalsLimit() {
return specConfigElectra.getPendingPartialWithdrawalsLimit();
}

@Override
public int getPendingConsolidationsLimit() {
return specConfigElectra.getPendingConsolidationsLimit();
}

@Override
public int getMinSlashingPenaltyQuotientElectra() {
return specConfigElectra.getMinSlashingPenaltyQuotientElectra();
}

@Override
public int getWhistleblowerRewardQuotientElectra() {
return specConfigElectra.getWhistleblowerRewardQuotientElectra();
}

@Override
public int getMaxAttesterSlashingsElectra() {
return specConfigElectra.getMaxAttesterSlashingsElectra();
}

@Override
public int getMaxAttestationsElectra() {
return specConfigElectra.getMaxAttestationsElectra();
}

@Override
public int getMaxConsolidationRequestsPerPayload() {
return specConfigElectra.getMaxConsolidationRequestsPerPayload();
}

@Override
public int getMaxDepositRequestsPerPayload() {
return specConfigElectra.getMaxDepositRequestsPerPayload();
}

@Override
public int getMaxWithdrawalRequestsPerPayload() {
return specConfigElectra.getMaxWithdrawalRequestsPerPayload();
}

@Override
public int getMaxPendingPartialsPerWithdrawalsSweep() {
return specConfigElectra.getMaxPendingPartialsPerWithdrawalsSweep();
}

@Override
public int getMaxPendingDepositsPerEpoch() {
return specConfigElectra.getMaxPendingDepositsPerEpoch();
}

@Override
public Optional<SpecConfigElectra> toVersionElectra() {
return Optional.of(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,9 @@ default Optional<SpecConfigElectra> toVersionElectra() {
return Optional.empty();
}

default Optional<SpecConfigEip7805> toVersionEip7805() {
return Optional.empty();
}

SpecMilestone getMilestone();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 SpecConfigEip7805 extends SpecConfigElectra {

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

Bytes4 getEip7805ForkVersion();

UInt64 getEip7805ForkEpoch();

int getIlCommitteeSize();

int getMaxTransactionPerInclusionList();

@Override
Optional<SpecConfigEip7805> toVersionEip7805();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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;
import tech.pegasys.teku.spec.SpecMilestone;

public class SpecConfigEip7805Impl extends DelegatingSpecConfigElectra
implements SpecConfigEip7805 {

private final Bytes4 eip7805ForkVersion;
private final UInt64 eip7805ForkEpoch;
private final int ilCommitteeSize;
private final int maxTransactionPerInclusionList;

public SpecConfigEip7805Impl(
final SpecConfigElectra specConfig,
final Bytes4 eip7805ForkVersion,
final UInt64 eip7805ForkEpoch,
final int ilCommitteeSize,
final int maxTransactionPerInclusionList) {
super(specConfig);
this.eip7805ForkVersion = eip7805ForkVersion;
this.eip7805ForkEpoch = eip7805ForkEpoch;
this.ilCommitteeSize = ilCommitteeSize;
this.maxTransactionPerInclusionList = maxTransactionPerInclusionList;
}

@Override
public Bytes4 getEip7805ForkVersion() {
return eip7805ForkVersion;
}

@Override
public UInt64 getEip7805ForkEpoch() {
return eip7805ForkEpoch;
}

@Override
public int getIlCommitteeSize() {
return ilCommitteeSize;
}

@Override
public int getMaxTransactionPerInclusionList() {
return maxTransactionPerInclusionList;
}

@Override
public Optional<SpecConfigEip7805> toVersionEip7805() {
return Optional.of(this);
}

@Override
public SpecMilestone getMilestone() {
return SpecMilestone.EIP7805;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final SpecConfigEip7805Impl that = (SpecConfigEip7805Impl) o;
return Objects.equals(specConfig, that.specConfig)
&& Objects.equals(eip7805ForkVersion, that.eip7805ForkVersion)
&& Objects.equals(eip7805ForkEpoch, that.eip7805ForkEpoch)
&& ilCommitteeSize == that.ilCommitteeSize
&& maxTransactionPerInclusionList == that.maxTransactionPerInclusionList;
}

@Override
public int hashCode() {
return Objects.hash(
specConfig,
eip7805ForkVersion,
eip7805ForkEpoch,
ilCommitteeSize,
maxTransactionPerInclusionList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import tech.pegasys.teku.spec.config.builder.BellatrixBuilder;
import tech.pegasys.teku.spec.config.builder.CapellaBuilder;
import tech.pegasys.teku.spec.config.builder.DenebBuilder;
import tech.pegasys.teku.spec.config.builder.Eip7805Builder;
import tech.pegasys.teku.spec.config.builder.ElectraBuilder;
import tech.pegasys.teku.spec.config.builder.SpecConfigBuilder;

Expand Down Expand Up @@ -208,6 +209,16 @@ public void loadFromMap(
unprocessedConfig.remove(constantKey);
});

// Process eip7805 config
streamConfigSetters(Eip7805Builder.class)
.forEach(
setter -> {
final String constantKey = camelToSnakeCase(setter.getName());
final Object rawValue = unprocessedConfig.get(constantKey);
invokeSetter(setter, configBuilder::eip7805Builder, 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 e9a0a08

Please sign in to comment.