Skip to content

Commit

Permalink
Track produced block when builder doesn't reveal the payload (Consens…
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov authored Nov 28, 2024
1 parent 557e083 commit 2494e4b
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ public void setup(final SpecContext specContext) {
blockGossipChannel,
blockBlobSidecarsTrackersPool,
blobSidecarGossipChannel,
performanceTracker,
dutyMetrics,
P2PConfig.DEFAULT_GOSSIP_BLOBS_AFTER_BLOCK_ENABLED));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ public SafeFuture<Optional<BlockContainerAndMetaData>> createUnsignedBlockIntern
requestedBuilderBoostFactor,
blockSlotState,
blockProductionPerformance))
.thenPeek(
maybeBlock ->
maybeBlock.ifPresent(
block ->
performanceTracker.saveProducedBlock(
block.blockContainer().getBlock().getSlotAndBlockRoot())))
.alwaysRun(blockProductionPerformance::complete);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ public void saveProducedAttestation(final Attestation attestation) {
}

@Override
public void saveProducedBlock(final SignedBeaconBlock block) {
final UInt64 epoch = spec.computeEpochAtSlot(block.getSlot());
public void saveProducedBlock(final SlotAndBlockRoot slotAndBlockRoot) {
final UInt64 epoch = spec.computeEpochAtSlot(slotAndBlockRoot.getSlot());
final Set<SlotAndBlockRoot> blocksInEpoch =
producedBlocksByEpoch.computeIfAbsent(epoch, __ -> concurrentSet());
blocksInEpoch.add(block.getSlotAndBlockRoot());
blocksInEpoch.add(slotAndBlockRoot);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import it.unimi.dsi.fastutil.ints.IntSet;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage;

Expand All @@ -28,7 +28,7 @@ public void start(final UInt64 nodeStartSlot) {}
public void saveProducedAttestation(final Attestation attestation) {}

@Override
public void saveProducedBlock(final SignedBeaconBlock block) {}
public void saveProducedBlock(final SlotAndBlockRoot slotAndBlockRoot) {}

@Override
public void reportBlockProductionAttempt(final UInt64 epoch) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import it.unimi.dsi.fastutil.ints.IntSet;
import tech.pegasys.teku.ethereum.events.SlotEventsChannel;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage;

Expand All @@ -26,7 +26,7 @@ public interface PerformanceTracker extends SlotEventsChannel {

void saveProducedAttestation(Attestation attestation);

void saveProducedBlock(SignedBeaconBlock block);
void saveProducedBlock(SlotAndBlockRoot slotAndBlockRoot);

void reportBlockProductionAttempt(UInt64 epoch);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import tech.pegasys.teku.validator.api.SendSignedBlockResult;
import tech.pegasys.teku.validator.coordinator.BlockFactory;
import tech.pegasys.teku.validator.coordinator.DutyMetrics;
import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker;

public abstract class AbstractBlockPublisher implements BlockPublisher {
private static final Logger LOG = LogManager.getLogger();
Expand All @@ -48,22 +47,19 @@ public abstract class AbstractBlockPublisher implements BlockPublisher {
protected final BlockFactory blockFactory;
protected final BlockImportChannel blockImportChannel;
protected final BlockGossipChannel blockGossipChannel;
protected final PerformanceTracker performanceTracker;
protected final DutyMetrics dutyMetrics;

public AbstractBlockPublisher(
final AsyncRunner asyncRunner,
final BlockFactory blockFactory,
final BlockGossipChannel blockGossipChannel,
final BlockImportChannel blockImportChannel,
final PerformanceTracker performanceTracker,
final DutyMetrics dutyMetrics,
final boolean gossipBlobsAfterBlock) {
this.asyncRunner = asyncRunner;
this.blockFactory = blockFactory;
this.blockImportChannel = blockImportChannel;
this.blockGossipChannel = blockGossipChannel;
this.performanceTracker = performanceTracker;
this.dutyMetrics = dutyMetrics;
this.gossipBlobsAfterBlock = gossipBlobsAfterBlock;
}
Expand All @@ -75,7 +71,6 @@ public SafeFuture<SendSignedBlockResult> sendSignedBlock(
final BlockPublishingPerformance blockPublishingPerformance) {
return blockFactory
.unblindSignedBlockIfBlinded(blockContainer.getSignedBlock(), blockPublishingPerformance)
.thenPeek(performanceTracker::saveProducedBlock)
.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 @@ -24,7 +24,6 @@
import tech.pegasys.teku.statetransition.block.BlockImportChannel;
import tech.pegasys.teku.validator.coordinator.BlockFactory;
import tech.pegasys.teku.validator.coordinator.DutyMetrics;
import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker;

public class BlockPublisherDeneb extends BlockPublisherPhase0 {

Expand All @@ -38,15 +37,13 @@ public BlockPublisherDeneb(
final BlockGossipChannel blockGossipChannel,
final BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool,
final BlobSidecarGossipChannel blobSidecarGossipChannel,
final PerformanceTracker performanceTracker,
final DutyMetrics dutyMetrics,
final boolean gossipBlobsAfterBlock) {
super(
asyncRunner,
blockFactory,
blockGossipChannel,
blockImportChannel,
performanceTracker,
dutyMetrics,
gossipBlobsAfterBlock);
this.blockBlobSidecarsTrackersPool = blockBlobSidecarsTrackersPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import tech.pegasys.teku.statetransition.block.BlockImportChannel.BlockImportAndBroadcastValidationResults;
import tech.pegasys.teku.validator.coordinator.BlockFactory;
import tech.pegasys.teku.validator.coordinator.DutyMetrics;
import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker;

public class BlockPublisherPhase0 extends AbstractBlockPublisher {

Expand All @@ -34,15 +33,13 @@ public BlockPublisherPhase0(
final BlockFactory blockFactory,
final BlockGossipChannel blockGossipChannel,
final BlockImportChannel blockImportChannel,
final PerformanceTracker performanceTracker,
final DutyMetrics dutyMetrics,
final boolean gossipBlobsAfterBlock) {
super(
asyncRunner,
blockFactory,
blockGossipChannel,
blockImportChannel,
performanceTracker,
dutyMetrics,
gossipBlobsAfterBlock);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import tech.pegasys.teku.validator.api.SendSignedBlockResult;
import tech.pegasys.teku.validator.coordinator.BlockFactory;
import tech.pegasys.teku.validator.coordinator.DutyMetrics;
import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker;

public class MilestoneBasedBlockPublisher implements BlockPublisher {

Expand All @@ -47,7 +46,6 @@ public MilestoneBasedBlockPublisher(
final BlockGossipChannel blockGossipChannel,
final BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool,
final BlobSidecarGossipChannel blobSidecarGossipChannel,
final PerformanceTracker performanceTracker,
final DutyMetrics dutyMetrics,
final boolean gossipBlobsAfterBlock) {
this.spec = spec;
Expand All @@ -57,7 +55,6 @@ public MilestoneBasedBlockPublisher(
blockFactory,
blockGossipChannel,
blockImportChannel,
performanceTracker,
dutyMetrics,
gossipBlobsAfterBlock);

Expand All @@ -72,7 +69,6 @@ public MilestoneBasedBlockPublisher(
blockGossipChannel,
blockBlobSidecarsTrackersPool,
blobSidecarGossipChannel,
performanceTracker,
dutyMetrics,
gossipBlobsAfterBlock));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ public void createUnsignedBlock_shouldCreateBlock() {
Optional.empty(),
Optional.of(ONE),
BlockProductionPerformance.NOOP);

verify(performanceTracker).reportBlockProductionAttempt(spec.computeEpochAtSlot(newSlot));
verify(performanceTracker)
.saveProducedBlock(
blockContainerAndMetaData.blockContainer().getBlock().getSlotAndBlockRoot());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ void shouldDisplayPerfectBlockInclusion() {
chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(10));
performanceTracker.reportBlockProductionAttempt(spec.computeEpochAtSlot(UInt64.valueOf(1)));
performanceTracker.reportBlockProductionAttempt(spec.computeEpochAtSlot(UInt64.valueOf(2)));
performanceTracker.saveProducedBlock(chainUpdater.chainBuilder.getBlockAtSlot(1));
performanceTracker.saveProducedBlock(chainUpdater.chainBuilder.getBlockAtSlot(2));
performanceTracker.saveProducedBlock(
chainUpdater.chainBuilder.getBlockAtSlot(1).getSlotAndBlockRoot());
performanceTracker.saveProducedBlock(
chainUpdater.chainBuilder.getBlockAtSlot(2).getSlotAndBlockRoot());
performanceTracker.onSlot(spec.computeStartSlotAtEpoch(UInt64.ONE));
BlockPerformance expectedBlockPerformance = new BlockPerformance(UInt64.ZERO, 2, 2, 2);
verify(log).performance(expectedBlockPerformance.toString());
Expand All @@ -103,7 +105,7 @@ void shouldDisplayBlockInclusionWhenProducedBlockIsChainHead() {
final SignedBlockAndState bestBlock = chainUpdater.advanceChainUntil(2);
chainUpdater.updateBestBlock(bestBlock);
performanceTracker.reportBlockProductionAttempt(spec.computeEpochAtSlot(bestBlock.getSlot()));
performanceTracker.saveProducedBlock(bestBlock.getBlock());
performanceTracker.saveProducedBlock(bestBlock.getBlock().getSlotAndBlockRoot());
performanceTracker.onSlot(lastSlot);
BlockPerformance expectedBlockPerformance = new BlockPerformance(UInt64.ZERO, 1, 1, 1);
verify(log).performance(expectedBlockPerformance.toString());
Expand All @@ -115,9 +117,12 @@ void shouldDisplayOneMissedBlock() {
performanceTracker.reportBlockProductionAttempt(spec.computeEpochAtSlot(UInt64.valueOf(1)));
performanceTracker.reportBlockProductionAttempt(spec.computeEpochAtSlot(UInt64.valueOf(2)));
performanceTracker.reportBlockProductionAttempt(spec.computeEpochAtSlot(UInt64.valueOf(3)));
performanceTracker.saveProducedBlock(chainUpdater.chainBuilder.getBlockAtSlot(1));
performanceTracker.saveProducedBlock(chainUpdater.chainBuilder.getBlockAtSlot(2));
performanceTracker.saveProducedBlock(dataStructureUtil.randomSignedBeaconBlock(3));
performanceTracker.saveProducedBlock(
chainUpdater.chainBuilder.getBlockAtSlot(1).getSlotAndBlockRoot());
performanceTracker.saveProducedBlock(
chainUpdater.chainBuilder.getBlockAtSlot(2).getSlotAndBlockRoot());
performanceTracker.saveProducedBlock(
dataStructureUtil.randomSignedBeaconBlock(3).getSlotAndBlockRoot());
performanceTracker.onSlot(spec.computeStartSlotAtEpoch(UInt64.ONE));
BlockPerformance expectedBlockPerformance = new BlockPerformance(UInt64.ZERO, 3, 2, 3);
verify(log).performance(expectedBlockPerformance.toString());
Expand Down Expand Up @@ -258,8 +263,10 @@ void shouldClearOldSentObjects() {
chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(10));
performanceTracker.reportBlockProductionAttempt(spec.computeEpochAtSlot(UInt64.valueOf(1)));
performanceTracker.reportBlockProductionAttempt(spec.computeEpochAtSlot(UInt64.valueOf(2)));
performanceTracker.saveProducedBlock(chainUpdater.chainBuilder.getBlockAtSlot(1));
performanceTracker.saveProducedBlock(chainUpdater.chainBuilder.getBlockAtSlot(2));
performanceTracker.saveProducedBlock(
chainUpdater.chainBuilder.getBlockAtSlot(1).getSlotAndBlockRoot());
performanceTracker.saveProducedBlock(
chainUpdater.chainBuilder.getBlockAtSlot(2).getSlotAndBlockRoot());
performanceTracker.saveProducedAttestation(
spec.getGenesisSchemaDefinitions()
.getAttestationSchema()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import tech.pegasys.teku.validator.api.SendSignedBlockResult;
import tech.pegasys.teku.validator.coordinator.BlockFactory;
import tech.pegasys.teku.validator.coordinator.DutyMetrics;
import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker;

public class AbstractBlockPublisherTest {
private final StubAsyncRunner asyncRunner = new StubAsyncRunner();
Expand All @@ -54,7 +53,6 @@ public class AbstractBlockPublisherTest {
private final BlockFactory blockFactory = mock(BlockFactory.class);
private final BlockGossipChannel blockGossipChannel = mock(BlockGossipChannel.class);
private final BlockImportChannel blockImportChannel = mock(BlockImportChannel.class);
private final PerformanceTracker performanceTracker = mock(PerformanceTracker.class);
private final DutyMetrics dutyMetrics = mock(DutyMetrics.class);

private final AbstractBlockPublisher blockPublisher =
Expand All @@ -64,7 +62,6 @@ public class AbstractBlockPublisherTest {
blockFactory,
blockGossipChannel,
blockImportChannel,
performanceTracker,
dutyMetrics,
false));

Expand Down Expand Up @@ -195,7 +192,6 @@ public void sendSignedBlock_shouldPublishBlobsAfterBlockWhenOptionIsEnabled() {
blockFactory,
blockGossipChannel,
blockImportChannel,
performanceTracker,
dutyMetrics,
true));

Expand Down Expand Up @@ -273,15 +269,13 @@ public BlockPublisherTest(
final BlockFactory blockFactory,
final BlockGossipChannel blockGossipChannel,
final BlockImportChannel blockImportChannel,
final PerformanceTracker performanceTracker,
final DutyMetrics dutyMetrics,
final boolean gossipBlobsAfterBlock) {
super(
asyncRunner,
blockFactory,
blockGossipChannel,
blockImportChannel,
performanceTracker,
dutyMetrics,
gossipBlobsAfterBlock);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import tech.pegasys.teku.statetransition.block.BlockImportChannel;
import tech.pegasys.teku.validator.coordinator.BlockFactory;
import tech.pegasys.teku.validator.coordinator.DutyMetrics;
import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker;

class BlockPublisherDenebTest {
private final BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool =
Expand All @@ -47,7 +46,6 @@ class BlockPublisherDenebTest {
mock(BlockGossipChannel.class),
blockBlobSidecarsTrackersPool,
blobSidecarGossipChannel,
mock(PerformanceTracker.class),
mock(DutyMetrics.class),
true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import tech.pegasys.teku.statetransition.block.BlockImportChannel;
import tech.pegasys.teku.validator.coordinator.BlockFactory;
import tech.pegasys.teku.validator.coordinator.DutyMetrics;
import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker;

class BlockPublisherPhase0Test {
private final BlockGossipChannel blockGossipChannel = mock(BlockGossipChannel.class);
Expand All @@ -41,7 +40,6 @@ class BlockPublisherPhase0Test {
mock(BlockFactory.class),
blockGossipChannel,
blockImportChannel,
mock(PerformanceTracker.class),
mock(DutyMetrics.class),
false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,6 @@ public void initValidatorApiHandler() {
blockGossipChannel,
blockBlobSidecarsTrackersPool,
blobSidecarGossipChannel,
performanceTracker,
dutyMetrics,
beaconConfig.p2pConfig().isGossipBlobsAfterBlockEnabled());

Expand Down

0 comments on commit 2494e4b

Please sign in to comment.