From 2c2249ab922d7912b945e0dd81cbed36fb1129a3 Mon Sep 17 00:00:00 2001 From: Enrico Del Fante Date: Wed, 10 Apr 2024 12:54:10 +0200 Subject: [PATCH] Cleanup on block performance (#8184) --- .../java/tech/pegasys/teku/spec/Spec.java | 51 +++++++++---------- .../beaconchain/BeaconChainController.java | 3 +- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java index ee2add97ad5..2638f8b21f7 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java @@ -292,10 +292,10 @@ public int getSyncCommitteeSize(final UInt64 slot) { // Genesis public BeaconState initializeBeaconStateFromEth1( - Bytes32 eth1BlockHash, - UInt64 eth1Timestamp, - List deposits, - Optional payloadHeader) { + final Bytes32 eth1BlockHash, + final UInt64 eth1Timestamp, + final List deposits, + final Optional payloadHeader) { final GenesisGenerator genesisGenerator = createGenesisGenerator(); genesisGenerator.updateCandidateState(eth1BlockHash, eth1Timestamp, deposits); payloadHeader.ifPresent(genesisGenerator::updateExecutionPayloadHeader); @@ -415,7 +415,7 @@ public UInt64 getPreviousEpoch(final BeaconState state) { return atState(state).beaconStateAccessors().getPreviousEpoch(state); } - public Bytes32 getSeed(BeaconState state, UInt64 epoch, Bytes4 domainType) + public Bytes32 getSeed(final BeaconState state, final UInt64 epoch, final Bytes4 domainType) throws IllegalArgumentException { return atState(state).beaconStateAccessors().getSeed(state, epoch, domainType); } @@ -429,38 +429,35 @@ public UInt64 computeEpochAtSlot(final UInt64 slot) { } public UInt64 computeTimeAtSlot(final BeaconState state, final UInt64 slot) { - return computeTimeAtSlot(state.getGenesisTime(), slot); + return atSlot(slot).miscHelpers().computeTimeAtSlot(state.getGenesisTime(), slot); } - public UInt64 computeTimeAtSlot(final UInt64 genesisTime, final UInt64 slot) { - return atSlot(slot).miscHelpers().computeTimeAtSlot(genesisTime, slot); - } - - public Bytes computeSigningRoot(BeaconBlock block, Bytes32 domain) { + public Bytes computeSigningRoot(final BeaconBlock block, final Bytes32 domain) { return atBlock(block).miscHelpers().computeSigningRoot(block, domain); } - public Bytes computeSigningRoot(BeaconBlockHeader blockHeader, Bytes32 domain) { + public Bytes computeSigningRoot(final BeaconBlockHeader blockHeader, final Bytes32 domain) { return atSlot(blockHeader.getSlot()).miscHelpers().computeSigningRoot(blockHeader, domain); } - public Bytes computeSigningRoot(AggregateAndProof proof, Bytes32 domain) { + public Bytes computeSigningRoot(final AggregateAndProof proof, final Bytes32 domain) { return atSlot(proof.getAggregate().getData().getSlot()) .miscHelpers() .computeSigningRoot(proof, domain); } - public Bytes computeSigningRoot(UInt64 slot, Bytes32 domain) { + public Bytes computeSigningRoot(final UInt64 slot, final Bytes32 domain) { return atSlot(slot).miscHelpers().computeSigningRoot(slot, domain); } - public Bytes computeBuilderApplicationSigningRoot(UInt64 slot, Merkleizable object) { + public Bytes computeBuilderApplicationSigningRoot(final UInt64 slot, final Merkleizable object) { final MiscHelpers miscHelpers = atSlot(slot).miscHelpers(); return miscHelpers.computeSigningRoot( object, miscHelpers.computeDomain(Domain.APPLICATION_BUILDER)); } - public Bytes4 computeForkDigest(Bytes4 currentVersion, Bytes32 genesisValidatorsRoot) { + public Bytes4 computeForkDigest( + final Bytes4 currentVersion, final Bytes32 genesisValidatorsRoot) { return atForkVersion(currentVersion) .miscHelpers() .computeForkDigest(currentVersion, genesisValidatorsRoot); @@ -564,7 +561,7 @@ public UInt64 getCurrentSlotForMillis(UInt64 currentTimeMillis, UInt64 genesisTi .getCurrentSlotForMillis(currentTimeMillis, genesisTimeMillis); } - public UInt64 getCurrentSlot(ReadOnlyStore store) { + public UInt64 getCurrentSlot(final ReadOnlyStore store) { return atTime(store.getGenesisTime(), store.getTimeSeconds()) .getForkChoiceUtil() .getCurrentSlot(store); @@ -574,36 +571,38 @@ public UInt64 getCurrentEpoch(final ReadOnlyStore store) { return computeEpochAtSlot(getCurrentSlot(store)); } - public UInt64 getSlotStartTime(UInt64 slotNumber, UInt64 genesisTime) { + public UInt64 getSlotStartTime(final UInt64 slotNumber, final UInt64 genesisTime) { return atSlot(slotNumber).getForkChoiceUtil().getSlotStartTime(slotNumber, genesisTime); } - public UInt64 getSlotStartTimeMillis(UInt64 slotNumber, UInt64 genesisTimeMillis) { + public UInt64 getSlotStartTimeMillis(final UInt64 slotNumber, final UInt64 genesisTimeMillis) { return atSlot(slotNumber) .getForkChoiceUtil() .getSlotStartTimeMillis(slotNumber, genesisTimeMillis); } public Optional getAncestor( - ReadOnlyForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 slot) { + final ReadOnlyForkChoiceStrategy forkChoiceStrategy, final Bytes32 root, final UInt64 slot) { return forGetAncestor(forkChoiceStrategy, root, slot) .getForkChoiceUtil() .getAncestor(forkChoiceStrategy, root, slot); } public NavigableMap getAncestors( - ReadOnlyForkChoiceStrategy forkChoiceStrategy, - Bytes32 root, - UInt64 startSlot, - UInt64 step, - UInt64 count) { + final ReadOnlyForkChoiceStrategy forkChoiceStrategy, + final Bytes32 root, + final UInt64 startSlot, + final UInt64 step, + final UInt64 count) { return forGetAncestor(forkChoiceStrategy, root, startSlot) .getForkChoiceUtil() .getAncestors(forkChoiceStrategy, root, startSlot, step, count); } public NavigableMap getAncestorsOnFork( - ReadOnlyForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 startSlot) { + final ReadOnlyForkChoiceStrategy forkChoiceStrategy, + final Bytes32 root, + final UInt64 startSlot) { return forGetAncestor(forkChoiceStrategy, root, startSlot) .getForkChoiceUtil() .getAncestorsOnFork(forkChoiceStrategy, root, startSlot); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index 243b0e28801..3ae8b310fb9 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -929,8 +929,7 @@ public void initValidatorApiHandler() { final BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory = new BlockProductionAndPublishingPerformanceFactory( timeProvider, - (slot) -> - secondsToMillis(spec.computeTimeAtSlot(recentChainData.getGenesisTime(), slot)), + (slot) -> secondsToMillis(recentChainData.computeTimeAtSlot(slot)), beaconConfig.getMetricsConfig().isBlockProductionAndPublishingPerformanceEnabled(), beaconConfig.getMetricsConfig().getBlockProductionPerformanceWarningThreshold(), beaconConfig.getMetricsConfig().getBlockPublishingPerformanceWarningThreshold());