Skip to content

Commit

Permalink
Add unit test which checks SYNC_BLOB_SIDECARS_SIZE against all milest…
Browse files Browse the repository at this point in the history
…ones config
  • Loading branch information
StefanBratanov committed Feb 27, 2023
1 parent 9a9d03d commit 1df0182
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public static List<SpecMilestone> 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<SpecMilestone> getAllFutureMilestones(SpecMilestone milestone) {
final List<SpecMilestone> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -271,4 +273,20 @@ public void shouldSendToPeerRequestedBlobSidecars() {

verify(callback).completeSuccessfully();
}

@Test
public void verifySyncBlobSidecarsSizeIsNotLargerThanMaxRequestSizeForShardingMilestones() {
final List<SpecMilestone> 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();
});
}
}

0 comments on commit 1df0182

Please sign in to comment.