Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_INTERNAL_SERVER_ERROR;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.json.JsonTestUtil.parseStringMap;
import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.verifyMetadataErrorResponse;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.Resources;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.api.ConfigProvider;
Expand Down Expand Up @@ -64,12 +64,17 @@ void shouldGetCorrectMainnetConfig() throws Exception {
setHandler(new GetSpec(configProvider));
handler.handleRequest(request);

final Map<String, Object> result = (Map<String, Object>) request.getResponseBody();
final Map<String, String> expected =
parseStringMap(
final String json = request.getResponseBodyAsJson(handler);

assertThat(json).contains("BLOB_SCHEDULE");
assertThat(json).isNotEmpty();
final ObjectMapper mapper = new ObjectMapper();
final JsonNode resultNode = mapper.readTree(json).get("data");
final JsonNode referenceNode =
mapper.readTree(
Resources.toString(
Resources.getResource(GetSpecTest.class, "mainnetConfig.json"), UTF_8));

assertThat(result).containsExactlyInAnyOrderEntriesOf(expected);
assertThat(resultNode).isEqualTo(referenceNode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,9 @@
"SAMPLES_PER_SLOT":"8",
"CUSTODY_REQUIREMENT":"4",
"VALIDATOR_CUSTODY_REQUIREMENT":"8",
"BALANCE_PER_ADDITIONAL_CUSTODY_GROUP":"32000000000"
"BALANCE_PER_ADDITIONAL_CUSTODY_GROUP":"32000000000",
"BLOB_SCHEDULE":[
{"EPOCH": "269568", "MAX_BLOBS_PER_BLOCK": "6"},
{"EPOCH": "364032", "MAX_BLOBS_PER_BLOCK": "9"}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tech.pegasys.teku.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
Expand All @@ -33,13 +34,17 @@ public SpecConfigData(final SpecConfig specConfig) {
this.specConfig = specConfig;
}

@SuppressWarnings("unchecked")
public Map<String, Object> getConfigMap() {
final Map<String, Object> configAttributes = new HashMap<>();
specConfig
.getRawConfig()
.forEach(
(name, value) -> {
if (value != null) {
if (value instanceof List<?>) {
LOG.debug("Config field {} is a list", name);
configAttributes.put(name, value);
} else if (value != null) {
configAttributes.put(name, ConfigProvider.formatValue(value));
} else {
LOG.warn("Config field {} was set to null in runtime configuration", name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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 tech.pegasys.teku.infrastructure.unsigned.UInt64;

public record BlobSchedule(UInt64 epoch, int maxBlobsPerBlock) {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.spec.config;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
Expand Down Expand Up @@ -52,6 +53,11 @@ public UInt64 getFieldElementsPerExtBlob() {
return delegate.getFieldElementsPerExtBlob();
}

@Override
public List<BlobSchedule> getBlobSchedule() {
return delegate.getBlobSchedule();
}

@Override
public UInt64 getKzgCommitmentsInclusionProofDepth() {
return delegate.getKzgCommitmentsInclusionProofDepth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.spec.config;

import java.util.List;
import java.util.Optional;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
Expand All @@ -36,6 +37,8 @@ static SpecConfigFulu required(final SpecConfig specConfig) {

UInt64 getFieldElementsPerExtBlob();

List<BlobSchedule> getBlobSchedule();

/** DataColumnSidecar's */
UInt64 getKzgCommitmentsInclusionProofDepth();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.spec.config;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
Expand All @@ -37,6 +38,7 @@ public class SpecConfigFuluImpl extends DelegatingSpecConfigElectra implements S
private final int maxRequestDataColumnSidecars;
private final int maxBlobsPerBlockFulu;
private final UInt64 balancePerAdditionalCustodyGroup;
private final List<BlobSchedule> blobSchedule;

public SpecConfigFuluImpl(
final SpecConfigElectra specConfig,
Expand All @@ -54,7 +56,8 @@ public SpecConfigFuluImpl(
final int minEpochsForDataColumnSidecarsRequests,
final int maxRequestDataColumnSidecars,
final int maxBlobsPerBlockFulu,
final UInt64 balancePerAdditionalCustodyGroup) {
final UInt64 balancePerAdditionalCustodyGroup,
final List<BlobSchedule> blobSchedule) {
super(specConfig);
this.fuluForkVersion = fuluForkVersion;
this.fuluForkEpoch = fuluForkEpoch;
Expand All @@ -71,6 +74,7 @@ public SpecConfigFuluImpl(
this.maxRequestDataColumnSidecars = maxRequestDataColumnSidecars;
this.maxBlobsPerBlockFulu = maxBlobsPerBlockFulu;
this.balancePerAdditionalCustodyGroup = balancePerAdditionalCustodyGroup;
this.blobSchedule = blobSchedule;
}

@Override
Expand All @@ -93,6 +97,11 @@ public UInt64 getFieldElementsPerExtBlob() {
return fieldElementsPerExtBlob;
}

@Override
public List<BlobSchedule> getBlobSchedule() {
return blobSchedule;
}

@Override
public UInt64 getKzgCommitmentsInclusionProofDepth() {
return kzgCommitmentsInclusionProofDepth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import java.lang.reflect.Modifier;
import java.math.BigInteger;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
Expand Down Expand Up @@ -105,9 +107,34 @@ public class SpecConfigReader {
.put(Bytes.class, fromString(Bytes::fromHexString))
.put(Bytes4.class, fromString(Bytes4::fromHexString))
.put(Bytes32.class, fromString(Bytes32::fromHexStringStrict))
.put(List.class, this::blobScheduleFromList)
.put(Eth1Address.class, fromString(Eth1Address::fromHexString))
.build();

@SuppressWarnings("unchecked")
private Object blobScheduleFromList(final Object o) {
final List<BlobSchedule> blobSchedule = new ArrayList<>();
final List<?> schedule = (List<?>) o;
for (Object entry : schedule) {
if (entry instanceof Map) {
final Map<String, String> data = (Map<String, String>) entry;
if (!data.containsKey("EPOCH")
|| !data.containsKey("MAX_BLOBS_PER_BLOCK")
|| data.size() != 2) {
throw new IllegalArgumentException("Map does not look like a blob schedule");
}
blobSchedule.add(
new BlobSchedule(
UInt64.valueOf(data.get("EPOCH")),
Integer.parseInt(data.get("MAX_BLOBS_PER_BLOCK"))));

} else {
throw new IllegalArgumentException("Could not parse entry blob schedule");
}
}
return blobSchedule;
}

final SpecConfigBuilder configBuilder = SpecConfig.builder();

public SpecConfigAndParent<? extends SpecConfig> build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.BlobSchedule;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigAndParent;
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigDenebImpl;

public class DenebBuilder implements ForkConfigBuilder<SpecConfigCapella, SpecConfigDeneb> {

private static final Logger LOG = LogManager.getLogger();
private Bytes4 denebForkVersion;
private UInt64 denebForkEpoch;

Expand Down Expand Up @@ -67,6 +70,14 @@ public SpecConfigAndParent<SpecConfigDeneb> build(
specConfigAndParent);
}

public Optional<BlobSchedule> getBlobSchedule() {
if (denebForkEpoch == null || maxBlobsPerBlock == null) {
LOG.debug("denebForkEpoch = {}, maxBlobsPerBlock = {}", denebForkEpoch, maxBlobsPerBlock);
return Optional.empty();
}
return Optional.of(new BlobSchedule(denebForkEpoch, maxBlobsPerBlock));
}

public DenebBuilder denebForkEpoch(final UInt64 denebForkEpoch) {
checkNotNull(denebForkEpoch);
this.denebForkEpoch = denebForkEpoch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.BlobSchedule;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigAndParent;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.config.SpecConfigElectraImpl;

public class ElectraBuilder implements ForkConfigBuilder<SpecConfigDeneb, SpecConfigElectra> {

private static final Logger LOG = LogManager.getLogger();
private Bytes4 electraForkVersion;
private UInt64 electraForkEpoch;

Expand Down Expand Up @@ -252,6 +256,17 @@ public Map<String, Object> getValidationMap() {
return constants;
}

public Optional<BlobSchedule> getBlobSchedule() {
if (maxBlobsPerBlockElectra == null || electraForkEpoch == null) {
LOG.debug(
"electraForkEpoch = {}, maxBlobsPerBlockElectra = {}",
electraForkEpoch,
maxBlobsPerBlockElectra);
return Optional.empty();
}
return Optional.of(new BlobSchedule(electraForkEpoch, maxBlobsPerBlockElectra));
}

@Override
public void addOverridableItemsToRawConfig(final BiConsumer<String, Object> rawConfig) {
rawConfig.accept("ELECTRA_FORK_EPOCH", electraForkEpoch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.BlobSchedule;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigAndParent;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
Expand All @@ -45,6 +49,7 @@ public class FuluBuilder implements ForkConfigBuilder<SpecConfigElectra, SpecCon
private Integer maxRequestDataColumnSidecars;
private Integer maxBlobsPerBlockFulu;
private UInt64 balancePerAdditionalCustodyGroup;
private List<BlobSchedule> blobSchedule = new ArrayList<>();

FuluBuilder() {}

Expand All @@ -68,7 +73,8 @@ public SpecConfigAndParent<SpecConfigFulu> build(
minEpochsForDataColumnSidecarsRequests,
maxRequestDataColumnSidecars,
maxBlobsPerBlockFulu,
balancePerAdditionalCustodyGroup),
balancePerAdditionalCustodyGroup,
blobSchedule),
specConfigAndParent);
}

Expand Down Expand Up @@ -103,6 +109,11 @@ public FuluBuilder kzgCommitmentsInclusionProofDepth(
return this;
}

public FuluBuilder blobSchedule(final List<BlobSchedule> blobSchedule) {
this.blobSchedule = blobSchedule;
return this;
}

public FuluBuilder numberOfColumns(final Integer numberOfColumns) {
checkNotNull(numberOfColumns);
this.numberOfColumns = numberOfColumns;
Expand Down Expand Up @@ -180,6 +191,22 @@ public void validate() {
validateConstants();
}

public void validateBlobSchedule(
Comment thread
rolfyone marked this conversation as resolved.
final Optional<BlobSchedule> denebSchedule, final Optional<BlobSchedule> electraSchedule) {
denebSchedule.ifPresent(
schedule -> {
if (!blobSchedule.contains(schedule)) {
blobSchedule.add(schedule);
}
});
electraSchedule.ifPresent(
schedule -> {
if (!blobSchedule.contains(schedule)) {
blobSchedule.add(schedule);
}
});
}

@Override
public Map<String, Object> getValidationMap() {
final Map<String, Object> constants = new HashMap<>();
Expand Down
Loading