Skip to content

Commit

Permalink
mark locally fetched blobs as validated
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Dec 9, 2024
1 parent e16bb37 commit 164982e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,10 @@ private synchronized SafeFuture<Void> fetchMissingContentFromLocalEL(
beaconBlockBodyDeneb,
signedBeaconBlockHeader);

blobSidecar.markSignatureAsValidated();
// assume kzg validation done by local EL
blobSidecar.markKzgAndInclusionProofAsValidated();

onNewBlobSidecar(blobSidecar, LOCAL_EL);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand All @@ -162,6 +177,8 @@ public void onNewBlobSidecar_addTrackerWithBlobSidecarIgnoringDuplicates() {
.signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot))
.build();

blobSidecar.markKzgAndInclusionProofAsValidated();

blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP);

assertThat(
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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));

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -447,6 +480,8 @@ public void onCompletedBlockAndBlobSidecars_shouldCreateTrackerIgnoringHistorica

final List<BlobSidecar> blobSidecars = dataStructureUtil.randomBlobSidecarsForBlock(block);

blobSidecars.forEach(BlobSidecar::markKzgAndInclusionProofAsValidated);

blockBlobSidecarsTrackersPool.onCompletedBlockAndBlobSidecars(block, blobSidecars);

assertThat(asyncRunner.hasDelayedActions()).isFalse();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -927,6 +975,8 @@ public void shouldFetchContentWhenBlobSidecarIsNotForCurrentSlot() {
.signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(slot))
.build();

blobSidecar.markKzgAndInclusionProofAsValidated();

blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP);

assertThat(asyncRunner.hasDelayedActions()).isTrue();
Expand Down Expand Up @@ -1245,6 +1295,8 @@ void stats_onNewBlobSidecar() {
.signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot))
.build();

blobSidecar.markKzgAndInclusionProofAsValidated();

// new from gossip
blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar, RemoteOrigin.GOSSIP);

Expand All @@ -1270,6 +1322,8 @@ void stats_onNewBlobSidecar() {
dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot.increment()))
.build();

blobSidecar2.markKzgAndInclusionProofAsValidated();

// new from RPC
blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar2, RemoteOrigin.RPC);

Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 164982e

Please sign in to comment.