Repository navigation
Fork choice changes to align with v1.7.0-alpha.1
#10263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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()); | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
| } | ||
|
|
@@ -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 | ||
| .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); | ||
| } | ||
|
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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unhandled exception when head state exceeds current slotLow Severity When |
||
| }) | ||
| .orElse(true); | ||
| } | ||
|
|
||
| private Optional<List<BlobSidecar>> extractBlobSidecarsFromValidationResults( | ||
|
|
@@ -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; | ||
|
|
@@ -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) { | ||
|
|
||
|
|
@@ -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: | ||
| // | ||
|
|
||
There was a problem hiding this comment.
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_rootnot the logic ofshould_apply_proposer_boostUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
LateBlockReorgLogicclass (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 littlein 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 inLateBlockReorgLogic, maybe this helps understand where all the logic is coming from, not sure...hopefully some of that helps?