diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoice.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoice.java index 2dbc83a37db..8039f5344b7 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoice.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoice.java @@ -543,7 +543,7 @@ private BlockImportResult importBlockAndState( blobSidecars, earliestBlobSidecarsSlot); - if (applyProposerBoost(block, transaction)) { + if (shouldApplyProposerBoost(block, transaction)) { transaction.setProposerBoostRoot(block.getRoot()); } @@ -578,21 +578,25 @@ private BlockImportResult importBlockAndState( return result; } - private boolean applyProposerBoost( + // from consensus-specs/fork-choice: + // get_current_slot(store) == block.slot and is_before_attesting_interval and is_first_block + private boolean shouldApplyProposerBoost( final SignedBeaconBlock block, final StoreTransaction transaction) { - if (spec.getCurrentSlot(transaction).equals(block.getSlot())) { - final UInt64 millisPerSlot = spec.getMillisPerSlot(block.getSlot()); - final UInt64 timeIntoSlotMillis = getMillisIntoSlot(transaction, millisPerSlot); - - if (isBeforeAttestingInterval(millisPerSlot, timeIntoSlotMillis)) { - if (forkChoiceProposerBoostUniquenessEnabled) { - // is_first_block - return recentChainData.getStore().getProposerBoostRoot().isEmpty(); - } - return true; - } + if (!spec.getCurrentSlot(transaction).equals(block.getSlot())) { + return false; + } + + final UInt64 millisPerSlot = spec.getMillisPerSlot(block.getSlot()); + final UInt64 timeIntoSlotMillis = getMillisIntoSlot(transaction, millisPerSlot); + if (!isBeforeAttestingInterval(millisPerSlot, timeIntoSlotMillis)) { + return false; } - return false; + + if (forkChoiceProposerBoostUniquenessEnabled) { + return transaction.getProposerBoostRoot().isEmpty(); + } + + return true; } /** diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java index 9e6cf578640..52ff4045690 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java @@ -1094,11 +1094,9 @@ private SignedBlockAndState generateMergeBlock() { ZERO); executionLayer.addPowBlock(terminalBlock); executionLayer.addPowBlock(terminalParentBlock); - final SignedBlockAndState epoch4Block = - chainBuilder.generateBlockAtSlot( - storageSystem.chainUpdater().getHeadSlot().plus(1), - BlockOptions.create().setTerminalBlockHash(terminalBlockHash)); - return epoch4Block; + return chainBuilder.generateBlockAtSlot( + storageSystem.chainUpdater().getHeadSlot().plus(1), + BlockOptions.create().setTerminalBlockHash(terminalBlockHash)); } @Test