Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ allprojects {
}

def nightly = System.getenv("NIGHTLY") != null
def refTestVersion = nightly ? "nightly" : "v1.6.1"
def refTestVersion = nightly ? "nightly" : "v1.7.0-alpha.1"
def blsRefTestVersion = 'v0.1.2'
def slashingProtectionInterchangeRefTestVersion = 'v5.3.0'
def refTestBaseUrl = 'https://github.com/ethereum/consensus-specs/releases/download'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import static com.google.common.base.Preconditions.checkArgument;
import static tech.pegasys.teku.infrastructure.logging.P2PLogger.P2P_LOG;
import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis;
import static tech.pegasys.teku.statetransition.forkchoice.StateRootCollector.addParentStateRoots;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -67,6 +66,8 @@
import tech.pegasys.teku.spec.executionlayer.PayloadStatus;
import tech.pegasys.teku.spec.logic.common.statetransition.availability.AvailabilityChecker;
import tech.pegasys.teku.spec.logic.common.statetransition.availability.DataAndValidationResult;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.EpochProcessingException;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.SlotProcessingException;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException;
import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult;
import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason;
Expand Down Expand Up @@ -663,8 +664,9 @@ private BlockImportResult importBlockAndState(
blobSidecars,
earliestBlobSidecarsSlot);

final boolean shouldApplyProposerBoost = shouldApplyProposerBoost(block, transaction);
if (shouldApplyProposerBoost) {
final boolean shouldUpdateProposerBoostRoot = shouldUpdateProposerBoostRoot(block, transaction);

if (shouldUpdateProposerBoostRoot) {
transaction.setProposerBoostRoot(block.getRoot());
}

Expand Down Expand Up @@ -694,7 +696,8 @@ private BlockImportResult importBlockAndState(
} else {
result = BlockImportResult.optimisticallySuccessful(block);
}
updateForkChoiceForImportedBlock(block, shouldApplyProposerBoost, result, forkChoiceStrategy);
updateForkChoiceForImportedBlock(
block, shouldUpdateProposerBoostRoot, result, forkChoiceStrategy);
notifyForkChoiceUpdatedAndOptimisticSyncingChanged(Optional.empty());
return result;
}
Expand Down Expand Up @@ -747,20 +750,48 @@ private ExecutionPayloadImportResult importExecutionPayloadAndState(
}

// from consensus-specs/fork-choice:
private boolean shouldApplyProposerBoost(
//
// Add proposer score boost if the block is timely, not conflicting with an existing block, with
// the same the proposer as the canonical chain.
private boolean shouldUpdateProposerBoostRoot(
final SignedBeaconBlock block, final StoreTransaction transaction) {
// get_current_slot(store) == block.slot
if (!spec.getCurrentSlot(transaction).equals(block.getSlot())) {
// is_first_block
if (transaction.getProposerBoostRoot().isPresent()) {
return false;
}
// is_before_attesting_interval
final UInt64 timeIntoSlotMillis =
getMillisIntoSlot(transaction, spec.getSlotDurationMillis(block.getSlot()));
if (!timeIntoSlotMillis.isLessThan(spec.getAttestationDueMillis(block.getSlot()))) {
// is_timely
if (recentChainData.isBlockLate(block.getRoot())) {
return false;
}
// is_first_block
return transaction.getProposerBoostRoot().isEmpty();
// in the edge cases when the chain head is not present or the head state future is not
// immediately available, the proposer boost root will be set to maintain backwards
// compatibility (see: https://github.com/ethereum/consensus-specs/pull/4807/)
return recentChainData

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems to me that this is the logic of update_proposer_boost_root not the logic of should_apply_proposer_boost

@rolfyone rolfyone Jan 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 this doesnt look similar to should_apply_proposer_boost, agree... also if this code does land somewhere we'd want finals etc... i'd have expected to fail the build...
isTimely is tied up in the LateBlockReorgLogic class (isBlockTimely), I think the spec references thing referencing forkChoice is a bit of a lie - not part of this pr, but yeh its going to be fun altering update_proposer_boost_root potentially, we might need to pull some things apart a little

in older specs we had should_override_forkchoice_update (found in 1.6.0), I'm not sure, but it seems like maybe that's what's been broken down to all this... that's the main logic in LateBlockReorgLogic, maybe this helps understand where all the logic is coming from, not sure...

hopefully some of that helps?

.getChainHead()
.map(
chainHead -> {
final SafeFuture<BeaconState> headStateFuture = chainHead.getState();
if (!headStateFuture.isCompletedNormally()) {
return true;
}
BeaconState headState = headStateFuture.join();
final UInt64 currentSlot = spec.getCurrentSlot(transaction);
if (headState.getSlot().isLessThan(currentSlot)) {
try {
headState = spec.processSlots(headState, currentSlot);
} catch (final SlotProcessingException | EpochProcessingException ex) {
throw new RuntimeException(
String.format(
"Can't progress head state from slot %s to slot %s",
headState.getSlot(), currentSlot),
ex);
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}
// Only update if the proposer is the same as on the canonical chain
return block.getProposerIndex().intValue()
== spec.getBeaconProposerIndex(headState, currentSlot);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unhandled exception when head state exceeds current slot

Low Severity

When headState.getSlot() is greater than currentSlot (possible during system clock regression), the code skips slot processing but still calls spec.getBeaconProposerIndex(headState, currentSlot). If these slots span different epochs, this call throws an IllegalArgumentException from the epoch validation check. This exception is not caught by the existing catch block (which only handles SlotProcessingException and EpochProcessingException), causing an unhandled exception that fails the block import. The old implementation would gracefully return false in slot mismatch scenarios.

Fix in Cursor Fix in Web

})
.orElse(true);
}

private Optional<List<BlobSidecar>> extractBlobSidecarsFromValidationResults(
Expand Down Expand Up @@ -812,13 +843,6 @@ private Optional<UInt64> computeEarliestBlobSidecarsSlot(
earliestAvailabilityWindowSlotBeforeBlock.max(earliestAffectedSlot));
}

private UInt64 getMillisIntoSlot(final StoreTransaction transaction, final int millisPerSlot) {
return transaction
.getTimeInMillis()
.minus(secondsToMillis(transaction.getGenesisTime()))
.mod(millisPerSlot);
}

private void onExecutionPayloadResult(
final Bytes32 blockRoot, final PayloadStatus payloadResult) {
final SafeFuture<PayloadValidationResult> transitionValidatedStatus;
Expand Down Expand Up @@ -859,7 +883,7 @@ private void onExecutionPayloadResult(

private void updateForkChoiceForImportedBlock(
final SignedBeaconBlock block,
final boolean shouldApplyProposerBoost,
final boolean shouldUpdateProposerBoostRoot,
final BlockImportResult result,
final ForkChoiceStrategy forkChoiceStrategy) {

Expand All @@ -873,7 +897,7 @@ private void updateForkChoiceForImportedBlock(
}
}

if (!result.isBlockOnCanonicalChain() && shouldApplyProposerBoost) {
if (!result.isBlockOnCanonicalChain() && shouldUpdateProposerBoostRoot) {
// This is likely a reorging block that requires a full processHead to update the head.
// Running processHead here will ensure:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,10 @@ public void setBlockTimelinessIfEmpty(final SignedBeaconBlock block) {
lateBlockReorgLogic.setBlockTimelinessFromArrivalTime(block, store.getTimeInMillis());
}

public boolean isBlockLate(final Bytes32 root) {
return lateBlockReorgLogic.isBlockLate(root);
}

public Optional<UInt64> getCustodyGroupCount() {
return store.getCustodyGroupCount();
}
Expand Down
Loading