diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecMilestone.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecMilestone.java index d4192df3ddd..14414848004 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecMilestone.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecMilestone.java @@ -51,6 +51,16 @@ public static List getAllPriorMilestones(SpecMilestone milestone) return allMilestones.subList(0, milestoneIndex); } + /** + * @param milestone The milestone being inspected + * @return An ordered list of all milestones succeeding the supplied milestone + */ + public static List getAllFutureMilestones(SpecMilestone milestone) { + final List allMilestones = Arrays.asList(SpecMilestone.values()); + final int milestoneIndex = allMilestones.indexOf(milestone); + return allMilestones.subList(milestoneIndex + 1, SpecMilestone.values().length); + } + /** * @param milestone The milestone being inspected * @return An ordered list of all milestones up to and included the specified milestone diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/Constants.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/Constants.java index abf8bfa63dc..8dac1d5aff1 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/Constants.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/Constants.java @@ -70,6 +70,7 @@ public class Constants { public static final UInt64 MAX_BLOCK_BY_RANGE_REQUEST_SIZE = UInt64.valueOf(200); public static final UInt64 SYNC_BATCH_SIZE = UInt64.valueOf(50); public static final UInt64 SYNC_BLOBS_SIDECARS_SIZE = UInt64.valueOf(50); + public static final UInt64 SYNC_BLOB_SIDECARS_SIZE = UInt64.valueOf(50); public static final int MAX_BLOCKS_PER_MINUTE = 500; public static final int MAX_BLOBS_SIDECARS_PER_MINUTE = 500; diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootMessageHandlerTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootMessageHandlerTest.java index 99b5360c160..2376e7464e7 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootMessageHandlerTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootMessageHandlerTest.java @@ -27,6 +27,7 @@ import static tech.pegasys.teku.networking.eth2.rpc.core.RpcResponseStatus.RESOURCE_UNAVAILABLE; import static tech.pegasys.teku.spec.config.Constants.MAX_CHUNK_SIZE_BELLATRIX; import static tech.pegasys.teku.spec.config.Constants.MAX_REQUEST_BLOB_SIDECARS; +import static tech.pegasys.teku.spec.config.Constants.SYNC_BLOB_SIDECARS_SIZE; import java.util.List; import java.util.Optional; @@ -45,6 +46,7 @@ import tech.pegasys.teku.networking.eth2.rpc.core.RpcException; import tech.pegasys.teku.networking.eth2.rpc.core.encodings.RpcEncoding; import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.TestSpecFactory; import tech.pegasys.teku.spec.config.SpecConfigDeneb; import tech.pegasys.teku.spec.datastructures.execution.versions.deneb.BlobSidecar; @@ -271,4 +273,20 @@ public void shouldSendToPeerRequestedBlobSidecars() { verify(callback).completeSuccessfully(); } + + @Test + public void verifySyncBlobSidecarsSizeIsNotLargerThanMaxRequestSizeForShardingMilestones() { + final List shardingMilestones = + SpecMilestone.getAllFutureMilestones(SpecMilestone.CAPELLA); + + shardingMilestones.forEach( + milestone -> { + final Spec spec = TestSpecFactory.createMainnet(milestone); + final int maxBlobsPerBlock = + SpecConfigDeneb.required(spec.forMilestone(milestone).getConfig()) + .getMaxBlobsPerBlock(); + final UInt64 maxRequestSize = MAX_REQUEST_BLOB_SIDECARS.times(maxBlobsPerBlock); + assertThat(SYNC_BLOB_SIDECARS_SIZE.isLessThanOrEqualTo(maxRequestSize)).isTrue(); + }); + } }