Skip to content

Commit

Permalink
publish despite already seen in gossip rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Oct 3, 2024
1 parent 6ffea1e commit 00cd375
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,8 @@ public synchronized void onNewBlobSidecar(
}

private void publishBlobSidecar(final BlobSidecar blobSidecar) {
if (gossipValidatorSupplier.get().markAsSeen(blobSidecar)) {
blobSidecarGossipPublisher.accept(blobSidecar);
}
gossipValidatorSupplier.get().markForEquivocation(blobSidecar);
blobSidecarGossipPublisher.accept(blobSidecar);
}

private void countBlobSidecar(final RemoteOrigin origin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public SafeFuture<InternalValidationResult> validate(final BlobSidecar blobSidec
* [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index, blob_sidecar.index)
* with valid header signature, sidecar inclusion proof, and kzg proof.
*/
if (!markAsSeen(blockHeader, blobSidecar.getIndex())) {
if (!markForEquivocation(blockHeader, blobSidecar.getIndex())) {
return ignore(
"BlobSidecar is not the first valid for its slot and index. It will be dropped.");
}
Expand All @@ -273,14 +273,14 @@ public SafeFuture<InternalValidationResult> validate(final BlobSidecar blobSidec
});
}

private boolean markAsSeen(final BeaconBlockHeader blockHeader, final UInt64 index) {
private boolean markForEquivocation(final BeaconBlockHeader blockHeader, final UInt64 index) {
return receivedValidBlobSidecarInfoSet.add(
new SlotProposerIndexAndBlobIndex(
blockHeader.getSlot(), blockHeader.getProposerIndex(), index));
}

public boolean markAsSeen(final BlobSidecar blobSidecar) {
return markAsSeen(
public boolean markForEquivocation(final BlobSidecar blobSidecar) {
return markForEquivocation(
blobSidecar.getSignedBeaconBlockHeader().getMessage(), blobSidecar.getIndex());
}

Expand Down Expand Up @@ -317,7 +317,7 @@ private SafeFuture<InternalValidationResult> validateBlobSidecarWithKnownValidHe
* [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index, blob_sidecar.index)
* with valid header signature, sidecar inclusion proof, and kzg proof.
*/
if (!markAsSeen(blockHeader, blobSidecar.getIndex())) {
if (!markForEquivocation(blockHeader, blobSidecar.getIndex())) {
return SafeFuture.completedFuture(
ignore("BlobSidecar is not the first valid for its slot and index. It will be dropped."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void onNewBlobSidecar_shouldIgnoreDuplicates() {
}

@Test
public void onNewBlobSidecar_shouldMarkAsSeenAndPublishWhenOriginIsLocalEL() {
public void onNewBlobSidecar_shouldMarkForEquivocationAndPublishWhenOriginIsLocalEL() {
final BlobSidecar blobSidecar1 =
dataStructureUtil
.createRandomBlobSidecarBuilder()
Expand All @@ -225,7 +225,7 @@ public void onNewBlobSidecar_shouldMarkAsSeenAndPublishWhenOriginIsLocalEL() {
.signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot))
.build();

when(blobSidecarGossipValidator.markAsSeen(blobSidecar1)).thenReturn(true);
when(blobSidecarGossipValidator.markForEquivocation(blobSidecar1)).thenReturn(true);

blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar1, RemoteOrigin.LOCAL_EL);
blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar2, RemoteOrigin.GOSSIP);
Expand All @@ -234,12 +234,12 @@ public void onNewBlobSidecar_shouldMarkAsSeenAndPublishWhenOriginIsLocalEL() {
assertBlobSidecarsCount(3);
assertBlobSidecarsTrackersCount(3);

verify(blobSidecarGossipValidator).markAsSeen(blobSidecar1);
verify(blobSidecarGossipValidator).markForEquivocation(blobSidecar1);
verify(blobSidecarPublisher, times(1)).accept(blobSidecar1);
}

@Test
public void onNewBlobSidecar_shouldNotPublishWhenOriginIsLocalELButAlreadySeen() {
public void onNewBlobSidecar_shouldPublishEvenWhenOriginIsLocalELButEquivocating() {
final BlobSidecar blobSidecar1 =
dataStructureUtil
.createRandomBlobSidecarBuilder()
Expand All @@ -256,7 +256,7 @@ public void onNewBlobSidecar_shouldNotPublishWhenOriginIsLocalELButAlreadySeen()
.signedBeaconBlockHeader(dataStructureUtil.randomSignedBeaconBlockHeader(currentSlot))
.build();

when(blobSidecarGossipValidator.markAsSeen(blobSidecar1)).thenReturn(false);
when(blobSidecarGossipValidator.markForEquivocation(blobSidecar1)).thenReturn(false);

blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar1, RemoteOrigin.LOCAL_EL);
blockBlobSidecarsTrackersPool.onNewBlobSidecar(blobSidecar2, RemoteOrigin.GOSSIP);
Expand All @@ -265,8 +265,8 @@ public void onNewBlobSidecar_shouldNotPublishWhenOriginIsLocalELButAlreadySeen()
assertBlobSidecarsCount(3);
assertBlobSidecarsTrackersCount(3);

verify(blobSidecarGossipValidator).markAsSeen(blobSidecar1);
verify(blobSidecarPublisher, never()).accept(blobSidecar1);
verify(blobSidecarGossipValidator).markForEquivocation(blobSidecar1);
verify(blobSidecarPublisher, times(1)).accept(blobSidecar1);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ void shouldTrackValidInfoSet() {
}

@TestTemplate
void shouldMarkAsSeen() {
assertThat(blobSidecarValidator.markAsSeen(blobSidecar)).isTrue();
void shouldMarkForEquivocation() {
assertThat(blobSidecarValidator.markForEquivocation(blobSidecar)).isTrue();

assertThat(blobSidecarValidator.markAsSeen(blobSidecar)).isFalse();
assertThat(blobSidecarValidator.markForEquivocation(blobSidecar)).isFalse();

SafeFutureAssert.assertThatSafeFuture(blobSidecarValidator.validate(blobSidecar))
.isCompletedWithValueMatching(InternalValidationResult::isIgnore);
Expand Down

0 comments on commit 00cd375

Please sign in to comment.