Skip to content

Commit

Permalink
Track produced block when builder doesn't reveal the payload
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Nov 27, 2024
1 parent d5528fa commit 1da043b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import com.google.common.base.Suppliers;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tech.pegasys.teku.ethereum.performance.trackers.BlockPublishingPerformance;
import tech.pegasys.teku.infrastructure.async.AsyncRunner;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.exceptions.ExceptionUtil;
import tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
Expand Down Expand Up @@ -75,7 +77,18 @@ public SafeFuture<SendSignedBlockResult> sendSignedBlock(
final BlockPublishingPerformance blockPublishingPerformance) {
return blockFactory
.unblindSignedBlockIfBlinded(blockContainer.getSignedBlock(), blockPublishingPerformance)
.thenPeek(performanceTracker::saveProducedBlock)
.whenComplete(
(block, ex) -> {
if (ex != null) {
// in case of relay API timeouts when unblinding, we still want to assume the block
// as produced, since the relay could have published it
if (ExceptionUtil.hasCause(ex, TimeoutException.class)) {
performanceTracker.saveProducedBlock(blockContainer.getSignedBlock());
}
} else {
performanceTracker.saveProducedBlock(block);
}
})
.thenCompose(
// creating blob sidecars after unblinding the block to ensure in the blinded flow we
// will have the cached builder payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture;

import java.util.List;
import java.util.concurrent.TimeoutException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.ethereum.performance.trackers.BlockPublishingPerformance;
Expand Down Expand Up @@ -252,6 +253,19 @@ public void sendSignedBlock_shouldReturnNotImportedWhenBlockImportFails() {
verify(blockPublisher).importBlobSidecars(blobSidecars, BlockPublishingPerformance.NOOP);
}

@Test
public void sendSignedBlock_shouldTrackBlockAsProducedIfUnblindingTimeouts() {
when(blockFactory.unblindSignedBlockIfBlinded(signedBlock, BlockPublishingPerformance.NOOP))
.thenReturn(SafeFuture.failedFuture(new TimeoutException()));

blockPublisher.sendSignedBlock(
signedBlockContents,
BroadcastValidationLevel.NOT_REQUIRED,
BlockPublishingPerformance.NOOP);

verify(performanceTracker).saveProducedBlock(signedBlockContents.getSignedBlock());
}

private SafeFuture<BlockImportAndBroadcastValidationResults> prepareBlockImportResult(
final BlockImportResult blockImportResult) {
return SafeFuture.completedFuture(
Expand Down

0 comments on commit 1da043b

Please sign in to comment.