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

8767 update mischelpers #8821

Merged
merged 2 commits into from
Nov 6, 2024
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
19 changes: 16 additions & 3 deletions ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static tech.pegasys.teku.infrastructure.time.TimeUtilities.millisToSeconds;
import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis;
import static tech.pegasys.teku.spec.SpecMilestone.DENEB;
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -48,9 +49,11 @@
import tech.pegasys.teku.spec.cache.IndexedAttestationCache;
import tech.pegasys.teku.spec.config.NetworkingSpecConfig;
import tech.pegasys.teku.spec.config.NetworkingSpecConfigDeneb;
import tech.pegasys.teku.spec.config.NetworkingSpecConfigElectra;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigAltair;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.constants.Domain;
import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
Expand Down Expand Up @@ -220,6 +223,16 @@ public Optional<NetworkingSpecConfigDeneb> getNetworkingConfigDeneb() {
.map(specConfig -> (NetworkingSpecConfigDeneb) specConfig.getNetworkingConfig());
}

/**
* Networking config with Electra constants. Use {@link SpecConfigElectra#required(SpecConfig)}
* when you are sure that Electra is available, otherwise use this method
*/
public Optional<NetworkingSpecConfigElectra> getNetworkingConfigElectra() {
return Optional.ofNullable(forMilestone(ELECTRA))
.map(SpecVersion::getConfig)
.map(specConfig -> (NetworkingSpecConfigElectra) specConfig.getNetworkingConfig());
}

public SchemaDefinitions getGenesisSchemaDefinitions() {
return getGenesisSpec().getSchemaDefinitions();
}
Expand Down Expand Up @@ -945,9 +958,9 @@ public Optional<Integer> getMaxBlobsPerBlock(final UInt64 slot) {
}

public UInt64 computeSubnetForBlobSidecar(final BlobSidecar blobSidecar) {
final SpecConfig config = atSlot(blobSidecar.getSlot()).getConfig();
final SpecConfigDeneb specConfigDeneb = SpecConfigDeneb.required(config);
return blobSidecar.getIndex().mod(specConfigDeneb.getBlobSidecarSubnetCount());
return blobSidecar
.getIndex()
.mod(atSlot(blobSidecar.getSlot()).miscHelpers().getBlobSidecarSubnetCount());
}

public Optional<UInt64> computeFirstSlotWithBlobSupport() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import tech.pegasys.teku.spec.constants.NetworkConstants;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.state.ForkData;
import tech.pegasys.teku.spec.datastructures.state.SigningData;
import tech.pegasys.teku.spec.datastructures.state.Validator;
Expand Down Expand Up @@ -387,6 +388,22 @@ public UInt64 getMaxRequestBlocks() {
return UInt64.valueOf(specConfig.getNetworkingConfig().getMaxRequestBlocks());
}

public int getMaxRequestBlobSidecars() {
throw new UnsupportedOperationException("No Blob Sidecars before Deneb");
}

public int getMaxBlobsPerBlock() {
throw new UnsupportedOperationException("No Blob Sidecars before Deneb");
}

public int getBlobSidecarSubnetCount() {
throw new UnsupportedOperationException("No Blob Sidecars before Deneb");
}

public int getBlobKzgCommitmentsCount(final SignedBeaconBlock signedBeaconBlock) {
throw new UnsupportedOperationException("No Blob KZG Commitments before Deneb");
}

public UInt64 getMaxEffectiveBalance(final Validator validator) {
return specConfig.getMaxEffectiveBalance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ public Optional<MiscHelpersDeneb> toVersionDeneb() {
return Optional.of(this);
}

@Override
public int getMaxRequestBlobSidecars() {
return SpecConfigDeneb.required(specConfig).getMaxRequestBlobSidecars();
}

@Override
public int getMaxBlobsPerBlock() {
return SpecConfigDeneb.required(specConfig).getMaxBlobsPerBlock();
}

@Override
public int getBlobSidecarSubnetCount() {
return SpecConfigDeneb.required(specConfig).getBlobSidecarSubnetCount();
}

@Override
public int getBlobKzgCommitmentsCount(final SignedBeaconBlock signedBeaconBlock) {
return signedBeaconBlock
.getMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,19 @@ public boolean isFormerDepositMechanismDisabled(final BeaconState state) {
.getEth1DepositIndex()
.equals(BeaconStateElectra.required(state).getDepositRequestsStartIndex());
}

@Override
public int getMaxRequestBlobSidecars() {
return SpecConfigElectra.required(specConfig).getMaxRequestBlobSidecarsElectra();
}

@Override
public int getMaxBlobsPerBlock() {
return SpecConfigElectra.required(specConfig).getMaxBlobsPerBlockElectra();
}

@Override
public int getBlobSidecarSubnetCount() {
return SpecConfigElectra.required(specConfig).getBlobSidecarSubnetCountElectra();
}
}