Skip to content

Commit 357237c

Browse files
committed
update mischelpers with new parameters
1 parent fbfb8a2 commit 357237c

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static tech.pegasys.teku.infrastructure.time.TimeUtilities.millisToSeconds;
1818
import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis;
1919
import static tech.pegasys.teku.spec.SpecMilestone.DENEB;
20+
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA;
2021

2122
import com.fasterxml.jackson.databind.ObjectMapper;
2223
import com.google.common.base.Preconditions;
@@ -48,9 +49,11 @@
4849
import tech.pegasys.teku.spec.cache.IndexedAttestationCache;
4950
import tech.pegasys.teku.spec.config.NetworkingSpecConfig;
5051
import tech.pegasys.teku.spec.config.NetworkingSpecConfigDeneb;
52+
import tech.pegasys.teku.spec.config.NetworkingSpecConfigElectra;
5153
import tech.pegasys.teku.spec.config.SpecConfig;
5254
import tech.pegasys.teku.spec.config.SpecConfigAltair;
5355
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
56+
import tech.pegasys.teku.spec.config.SpecConfigElectra;
5457
import tech.pegasys.teku.spec.constants.Domain;
5558
import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation;
5659
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
@@ -220,6 +223,16 @@ public Optional<NetworkingSpecConfigDeneb> getNetworkingConfigDeneb() {
220223
.map(specConfig -> (NetworkingSpecConfigDeneb) specConfig.getNetworkingConfig());
221224
}
222225

226+
/**
227+
* Networking config with Electra constants. Use {@link SpecConfigElectra#required(SpecConfig)}
228+
* when you are sure that Electra is available, otherwise use this method
229+
*/
230+
public Optional<NetworkingSpecConfigElectra> getNetworkingConfigElectra() {
231+
return Optional.ofNullable(forMilestone(ELECTRA))
232+
.map(SpecVersion::getConfig)
233+
.map(specConfig -> (NetworkingSpecConfigElectra) specConfig.getNetworkingConfig());
234+
}
235+
223236
public SchemaDefinitions getGenesisSchemaDefinitions() {
224237
return getGenesisSpec().getSchemaDefinitions();
225238
}
@@ -945,9 +958,9 @@ public Optional<Integer> getMaxBlobsPerBlock(final UInt64 slot) {
945958
}
946959

947960
public UInt64 computeSubnetForBlobSidecar(final BlobSidecar blobSidecar) {
948-
final SpecConfig config = atSlot(blobSidecar.getSlot()).getConfig();
949-
final SpecConfigDeneb specConfigDeneb = SpecConfigDeneb.required(config);
950-
return blobSidecar.getIndex().mod(specConfigDeneb.getBlobSidecarSubnetCount());
961+
return blobSidecar
962+
.getIndex()
963+
.mod(atSlot(blobSidecar.getSlot()).miscHelpers().getBlobSidecarSubnetCount());
951964
}
952965

953966
public Optional<UInt64> computeFirstSlotWithBlobSupport() {

ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import tech.pegasys.teku.spec.constants.NetworkConstants;
4141
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar;
4242
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
43+
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
4344
import tech.pegasys.teku.spec.datastructures.state.ForkData;
4445
import tech.pegasys.teku.spec.datastructures.state.SigningData;
4546
import tech.pegasys.teku.spec.datastructures.state.Validator;
@@ -387,6 +388,22 @@ public UInt64 getMaxRequestBlocks() {
387388
return UInt64.valueOf(specConfig.getNetworkingConfig().getMaxRequestBlocks());
388389
}
389390

391+
public int getMaxRequestBlobSidecars() {
392+
throw new UnsupportedOperationException("No Blob Sidecars before Deneb");
393+
}
394+
395+
public int getMaxBlobsPerBlock() {
396+
throw new UnsupportedOperationException("No Blob Sidecars before Deneb");
397+
}
398+
399+
public int getBlobSidecarSubnetCount() {
400+
throw new UnsupportedOperationException("No Blob Sidecars before Deneb");
401+
}
402+
403+
public int getBlobKzgCommitmentsCount(final SignedBeaconBlock signedBeaconBlock) {
404+
throw new UnsupportedOperationException("No Blob KZG Commitments before Deneb");
405+
}
406+
390407
public UInt64 getMaxEffectiveBalance(final Validator validator) {
391408
return specConfig.getMaxEffectiveBalance();
392409
}

ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDeneb.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,22 @@ public Optional<MiscHelpersDeneb> toVersionDeneb() {
211211
return Optional.of(this);
212212
}
213213

214+
@Override
215+
public int getMaxRequestBlobSidecars() {
216+
return SpecConfigDeneb.required(specConfig).getMaxRequestBlobSidecars();
217+
}
218+
219+
@Override
220+
public int getMaxBlobsPerBlock() {
221+
return SpecConfigDeneb.required(specConfig).getMaxBlobsPerBlock();
222+
}
223+
224+
@Override
225+
public int getBlobSidecarSubnetCount() {
226+
return SpecConfigDeneb.required(specConfig).getBlobSidecarSubnetCount();
227+
}
228+
229+
@Override
214230
public int getBlobKzgCommitmentsCount(final SignedBeaconBlock signedBeaconBlock) {
215231
return signedBeaconBlock
216232
.getMessage()

ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/MiscHelpersElectra.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,19 @@ public boolean isFormerDepositMechanismDisabled(final BeaconState state) {
8585
.getEth1DepositIndex()
8686
.equals(BeaconStateElectra.required(state).getDepositRequestsStartIndex());
8787
}
88+
89+
@Override
90+
public int getMaxRequestBlobSidecars() {
91+
return SpecConfigElectra.required(specConfig).getMaxRequestBlobSidecarsElectra();
92+
}
93+
94+
@Override
95+
public int getMaxBlobsPerBlock() {
96+
return SpecConfigElectra.required(specConfig).getMaxBlobsPerBlockElectra();
97+
}
98+
99+
@Override
100+
public int getBlobSidecarSubnetCount() {
101+
return SpecConfigElectra.required(specConfig).getBlobSidecarSubnetCountElectra();
102+
}
88103
}

0 commit comments

Comments
 (0)