From 72a312ce6bd220c9ed3452d65b88a30f301161e8 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 21 Sep 2023 10:06:27 +0800 Subject: [PATCH] changes based on feedback --- .../forkchoice/ForkChoice.java | 32 +++++++++++-------- .../forkchoice/ForkChoiceTest.java | 8 ++--- 2 files changed, 21 insertions(+), 19 deletions(-) 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