From 164982ef5d77fa4fb168f5adf0b4dcbdd095f668 Mon Sep 17 00:00:00 2001 From: Enrico Del Fante Date: Fri, 22 Nov 2024 11:31:48 +0100 Subject: [PATCH] mark locally fetched blobs as validated --- .../BlockBlobSidecarsTrackersPoolImpl.java | 4 ++ ...BlockBlobSidecarsTrackersPoolImplTest.java | 62 ++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java index b63d8894097..507dd6834c5 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java @@ -722,6 +722,10 @@ private synchronized SafeFuture fetchMissingContentFromLocalEL( beaconBlockBodyDeneb, signedBeaconBlockHeader); + blobSidecar.markSignatureAsValidated(); + // assume kzg validation done by local EL + blobSidecar.markKzgAndInclusionProofAsValidated(); + onNewBlobSidecar(blobSidecar, LOCAL_EL); } }); diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImplTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImplTest.java index 2dad121a9eb..317cb65c07a 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImplTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImplTest.java @@ -14,7 +14,9 @@ package tech.pegasys.teku.statetransition.util; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -154,6 +156,19 @@ public void onNewBlock_addTrackerWithBlock() { assertBlobSidecarsTrackersCount(1); } + @Test + public void onNewBlobSidecar_shouldThrowIfNotMarkedKzgAndInclusionProofAsValidated() { + final BlobSidecar blobSidecar = + dataStructureUtil + .createRandomBlobSidecarBuilder() + .signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot)) + .build(); + + assertThrows( + IllegalArgumentException.class, + () -> blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP)); + } + @Test public void onNewBlobSidecar_addTrackerWithBlobSidecarIgnoringDuplicates() { final BlobSidecar blobSidecar = @@ -162,6 +177,8 @@ public void onNewBlobSidecar_addTrackerWithBlobSidecarIgnoringDuplicates() { .signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot)) .build(); + blobSidecar.markKzgAndInclusionProofAsValidated(); + blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP); assertThat( @@ -190,6 +207,8 @@ public void onNewBlobSidecar_shouldIgnoreDuplicates() { .signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot)) .build(); + blobSidecar.markKzgAndInclusionProofAsValidated(); + blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP); blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP); @@ -225,6 +244,10 @@ public void onNewBlobSidecar_shouldMarkForEquivocationAndPublishWhenOriginIsLoca .signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot)) .build(); + blobSidecar1.markKzgAndInclusionProofAsValidated(); + blobSidecar2.markKzgAndInclusionProofAsValidated(); + blobSidecar3.markKzgAndInclusionProofAsValidated(); + when(blobSidecarGossipValidator.markForEquivocation(blobSidecar1)).thenReturn(true); blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar1, RemoteOrigin.LOCAL_EL); @@ -246,6 +269,8 @@ public void onNewBlobSidecar_shouldPublishWhenOriginIsLocalELAndEquivocating() { .signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot)) .build(); + blobSidecar1.markKzgAndInclusionProofAsValidated(); + when(blobSidecarGossipValidator.markForEquivocation(blobSidecar1)).thenReturn(false); blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar1, RemoteOrigin.LOCAL_EL); @@ -265,6 +290,8 @@ public void onNewBlobSidecar_shouldNotPublishWhenOriginIsLocalELIsNotCurrentSlot .signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot)) .build(); + blobSidecar1.markKzgAndInclusionProofAsValidated(); + when(blobSidecarGossipValidator.markForEquivocation(blobSidecar1)).thenReturn(false); blockBlobSidecarsTrackersPool.onSlot(currentSlot.plus(1)); @@ -352,6 +379,8 @@ public void onNewBlobSidecarOnNewBlock_addTrackerWithBothBlockAndBlobSidecar() { final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(currentSlot); final BlobSidecar blobSidecar = dataStructureUtil.randomBlobSidecarsForBlock(block).get(0); + blobSidecar.markKzgAndInclusionProofAsValidated(); + blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP); blockBlobSidecarsTrackersPool.onNewBlock(block, Optional.empty()); @@ -394,6 +423,10 @@ public void twoOnNewBlobSidecar_addTrackerWithBothBlobSidecars() { .index(UInt64.ONE) .build(); + blobSidecar0.markKzgAndInclusionProofAsValidated(); + blobSidecar1.markKzgAndInclusionProofAsValidated(); + blobSidecar1bis.markKzgAndInclusionProofAsValidated(); + blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar0, RemoteOrigin.GOSSIP); blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar1, RemoteOrigin.GOSSIP); blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar1bis, RemoteOrigin.GOSSIP); @@ -447,6 +480,8 @@ public void onCompletedBlockAndBlobSidecars_shouldCreateTrackerIgnoringHistorica final List blobSidecars = dataStructureUtil.randomBlobSidecarsForBlock(block); + blobSidecars.forEach(BlobSidecar::markKzgAndInclusionProofAsValidated); + blockBlobSidecarsTrackersPool.onCompletedBlockAndBlobSidecars(block, blobSidecars); assertThat(asyncRunner.hasDelayedActions()).isFalse(); @@ -714,8 +749,21 @@ void shouldFetchMissingBlobSidecarsFromLocalELFirst() { engineGetBlobsResponse.complete(blobAndProofsFromEL); - verify(tracker).add(missingBlobSidecars.getFirst()); // 0 - verify(tracker).add(missingBlobSidecars.getLast()); // 2 + verify(tracker) + .add( + argThat( + b -> + b.equals(missingBlobSidecars.getFirst()) + && b.isKzgAndInclusionProofValidated() + && b.isSignatureValidated())); // 0 + verify(tracker) + .add( + argThat( + b -> + b.equals(missingBlobSidecars.getLast()) + && b.isKzgAndInclusionProofValidated() + && b.isSignatureValidated())); // 2) + verify(tracker, times(2)).add(any()); assertStats("blob_sidecar", "local_el_fetch", 3); @@ -927,6 +975,8 @@ public void shouldFetchContentWhenBlobSidecarIsNotForCurrentSlot() { .signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(slot)) .build(); + blobSidecar.markKzgAndInclusionProofAsValidated(); + blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP); assertThat(asyncRunner.hasDelayedActions()).isTrue(); @@ -1245,6 +1295,8 @@ void stats_onNewBlobSidecar() { .signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot)) .build(); + blobSidecar.markKzgAndInclusionProofAsValidated(); + // new from gossip blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP); @@ -1270,6 +1322,8 @@ void stats_onNewBlobSidecar() { dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot.increment())) .build(); + blobSidecar2.markKzgAndInclusionProofAsValidated(); + // new from RPC blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar2, RemoteOrigin.RPC); @@ -1285,6 +1339,8 @@ void stats_onNewBlobSidecar() { dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot.increment())) .build(); + blobSidecar3.markKzgAndInclusionProofAsValidated(); + // new from LOCAL_EL blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar3, RemoteOrigin.LOCAL_EL); assertStats("blob_sidecar", "local_el", 1); @@ -1349,6 +1405,8 @@ void stats_onNewBlock() { .signedBeaconBlockHeader(block4.asHeader()) .build(); + blobSidecar4.markKzgAndInclusionProofAsValidated(); + blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar4, RemoteOrigin.RPC); blockBlobSidecarsTrackersPool.onNewBlock(block4, Optional.of(RemoteOrigin.GOSSIP));