Skip to content

Commit

Permalink
Do tracking at beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Nov 28, 2024
1 parent 590f37b commit fcb7b9f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
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 @@ -73,6 +73,10 @@ public SafeFuture<SendSignedBlockResult> sendSignedBlock(
final SignedBlockContainer blockContainer,
final BroadcastValidationLevel broadcastValidationLevel,
final BlockPublishingPerformance blockPublishingPerformance) {
// always track the block as produced even in case of publishing failures (e.g.
// relay API timeouts during unblinding), because we later do comparison against the chain data
// anyway
performanceTracker.saveProducedBlock(blockContainer.getSignedBlock().getSlotAndBlockRoot());
return blockFactory
.unblindSignedBlockIfBlinded(blockContainer.getSignedBlock(), blockPublishingPerformance)
.thenCompose(
Expand All @@ -84,13 +88,7 @@ public SafeFuture<SendSignedBlockResult> sendSignedBlock(
Suppliers.memoize(() -> blockFactory.createBlobSidecars(blockContainer)),
broadcastValidationLevel,
blockPublishingPerformance))
.thenCompose(result -> calculateResult(blockContainer, result, blockPublishingPerformance))
.alwaysRun(
() ->
// always track the block as produced even in case of publishing failures (e.g.
// relay API timeouts during unblinding), because we later do comparison against the
// chain data anyway
performanceTracker.saveProducedBlock(blockContainer.getSignedBlock()));
.thenCompose(result -> calculateResult(blockContainer, result, blockPublishingPerformance));
}

private SafeFuture<BlockImportAndBroadcastValidationResults>
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 @@ -263,7 +263,8 @@ public void sendSignedBlock_shouldTrackBlockAsProducedEvenIfExceptionOccurs() {
BroadcastValidationLevel.NOT_REQUIRED,
BlockPublishingPerformance.NOOP);

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

private SafeFuture<BlockImportAndBroadcastValidationResults> prepareBlockImportResult(
Expand Down

0 comments on commit fcb7b9f

Please sign in to comment.