Skip to content

Commit

Permalink
apply new blobSidecar gossip rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Oct 18, 2023
1 parent 5cf83e2 commit 677272c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ public SafeFuture<InternalValidationResult> validate(final SignedBlobSidecar sig
tech.pegasys.teku.networking.eth2.gossip.BlobSidecarGossipManager.TopicSubnetIdAwareOperationProcessor
*/

/*
[REJECT] The sidecar's index is consistent with `MAX_BLOBS_PER_BLOCK` -- i.e. `sidecar.index < MAX_BLOBS_PER_BLOCK`
*/
final Optional<Integer> maxBlobsPerBlockAtSlot =
spec.getMaxBlobsPerBlock(blobSidecar.getSlot());
if (maxBlobsPerBlockAtSlot.isEmpty()) {
return completedFuture(reject("BlobSidecar's slot is pre deneb"));
}
if (blobSidecar.getIndex().isGreaterThanOrEqualTo(maxBlobsPerBlockAtSlot.get())) {
return completedFuture(reject("BlobSidecar index is greater than MAX_BLOBS_PER_BLOCK"));
}

/*
[REJECT] The sidecar's block's parent (defined by sidecar.block_parent_root) passes validation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.async.SafeFutureAssert;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.TestSpecContext;
import tech.pegasys.teku.spec.TestSpecInvocationContextProvider.SpecContext;
Expand Down Expand Up @@ -101,6 +102,36 @@ void shouldAccept() {
.isCompletedWithValueMatching(InternalValidationResult::isAccept);
}

@TestTemplate
void shouldRejectWhenIndexIsTooBig(final SpecContext specContext) {

signedBlobSidecar =
specContext
.getDataStructureUtil()
.createRandomBlobSidecarBuilder()
.slot(slot)
.index(UInt64.valueOf(specContext.getSpec().getMaxBlobsPerBlock().orElseThrow()))
.proposerIndex(proposerIndex)
.blockRoot(blockRoot)
.blockParentRoot(blockParentRoot)
.buildSigned();

SafeFutureAssert.assertThatSafeFuture(blobSidecarValidator.validate(signedBlobSidecar))
.isCompletedWithValueMatching(InternalValidationResult::isReject);
}

@TestTemplate
void shouldRejectWhenSlotIsNotDeneb() {
final Spec mockedSpec = mock(Spec.class);
when(mockedSpec.getMaxBlobsPerBlock(slot)).thenReturn(Optional.empty());

blobSidecarValidator =
BlobSidecarValidator.create(mockedSpec, invalidBlocks, gossipValidationHelper);

SafeFutureAssert.assertThatSafeFuture(blobSidecarValidator.validate(signedBlobSidecar))
.isCompletedWithValueMatching(InternalValidationResult::isReject);
}

@TestTemplate
void shouldRejectWhenParentBlockInvalid() {
invalidBlocks.put(blockParentRoot, BlockImportResult.FAILED_INVALID_ANCESTRY);
Expand Down

0 comments on commit 677272c

Please sign in to comment.