Support post merge forks at genesis for hive tests (#5019)

Signed-off-by: Jason Frame <jason.frame@consensys.net>
pull/5074/head
Jason Frame 2 years ago committed by GitHub
parent d7afa411e9
commit b2d378e174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java
  2. 7
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeContext.java
  3. 17
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/PostMergeContext.java
  4. 5
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionContext.java
  5. 10
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionUtils.java
  6. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java
  7. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java
  8. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/Blockchain.java

@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.controller;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.consensus.merge.MergeContext;
import org.hyperledger.besu.consensus.merge.MergeProtocolSchedule;
import org.hyperledger.besu.consensus.merge.PostMergeContext;
@ -186,19 +187,24 @@ public class MergeBesuControllerBuilder extends BesuControllerBuilder {
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule) {
OptionalLong terminalBlockNumber = configOptionsSupplier.get().getTerminalBlockNumber();
Optional<Hash> terminalBlockHash = configOptionsSupplier.get().getTerminalBlockHash();
final GenesisConfigOptions genesisConfigOptions = configOptionsSupplier.get();
final OptionalLong terminalBlockNumber = genesisConfigOptions.getTerminalBlockNumber();
final Optional<Hash> terminalBlockHash = genesisConfigOptions.getTerminalBlockHash();
final boolean isPostMergeAtGenesis =
genesisConfigOptions.getTerminalTotalDifficulty().isPresent()
&& genesisConfigOptions.getTerminalTotalDifficulty().get().isZero()
&& blockchain.getGenesisBlockHeader().getDifficulty().isZero();
final MergeContext mergeContext =
PostMergeContext.get()
.setSyncState(syncState.get())
.setTerminalTotalDifficulty(
configOptionsSupplier
.get()
genesisConfigOptions
.getTerminalTotalDifficulty()
.map(Difficulty::of)
.orElse(Difficulty.ZERO))
.setCheckpointPostMergeSync(syncConfig.isCheckpointPostMergeEnabled());
.setCheckpointPostMergeSync(syncConfig.isCheckpointPostMergeEnabled())
.setPostMergeAtGenesis(isPostMergeAtGenesis);
blockchain
.getFinalized()

@ -192,4 +192,11 @@ public interface MergeContext extends ConsensusContext {
* @return the boolean
*/
boolean isCheckpointPostMergeSync();
/**
* Is configured for a post-merge from genesis.
*
* @return the boolean
*/
boolean isPostMergeAtGenesis();
}

@ -70,6 +70,7 @@ public class PostMergeContext implements MergeContext {
private final AtomicReference<Optional<BlockHeader>> terminalPoWBlock =
new AtomicReference<>(Optional.empty());
private boolean isCheckpointPostMergeSync;
private boolean isPostMergeAtGenesis;
// TODO: cleanup - isChainPruningEnabled will not be required after
// https://github.com/hyperledger/besu/pull/4703 is merged.
@ -329,4 +330,20 @@ public class PostMergeContext implements MergeContext {
public boolean isCheckpointPostMergeSync() {
return this.isCheckpointPostMergeSync;
}
@Override
public boolean isPostMergeAtGenesis() {
return this.isPostMergeAtGenesis;
}
/**
* Sets whether it is post merge at genesis
*
* @param isPostMergeAtGenesis the is post merge at genesis state
* @return the post merge context
*/
public PostMergeContext setPostMergeAtGenesis(final boolean isPostMergeAtGenesis) {
this.isPostMergeAtGenesis = isPostMergeAtGenesis;
return this;
}
}

@ -154,4 +154,9 @@ public class TransitionContext implements MergeContext {
public boolean isCheckpointPostMergeSync() {
return false;
}
@Override
public boolean isPostMergeAtGenesis() {
return postMergeContext.isPostMergeAtGenesis();
}
}

@ -116,6 +116,13 @@ public class TransitionUtils<SwitchingObject> {
// if we cannot find difficulty or are merge-at-genesis
.orElse(Difficulty.ZERO);
final MergeContext consensusContext = context.getConsensusContext(MergeContext.class);
// Genesis is configured for post-merge we will never have a terminal pow block
if (consensusContext.isPostMergeAtGenesis()) {
return false;
}
if (currentChainTotalDifficulty.isZero()) {
warnLambda(
LOG,
@ -123,8 +130,7 @@ public class TransitionUtils<SwitchingObject> {
header::toLogString,
header::getParentHash);
}
Difficulty configuredTotalTerminalDifficulty =
context.getConsensusContext(MergeContext.class).getTerminalTotalDifficulty();
Difficulty configuredTotalTerminalDifficulty = consensusContext.getTerminalTotalDifficulty();
if (currentChainTotalDifficulty
.add(headerDifficulty)

@ -121,6 +121,7 @@ public abstract class AbstractEngineForkchoiceUpdated extends ExecutionEngineJso
// TODO: post-merge cleanup, this should be unnecessary after merge
if (requireTerminalPoWBlockValidation()
&& !mergeContext.get().isCheckpointPostMergeSync()
&& !mergeContext.get().isPostMergeAtGenesis()
&& !mergeCoordinator.latestValidAncestorDescendsFromTerminal(newHead)
&& !mergeContext.get().isChainPruningEnabled()) {
logForkchoiceUpdatedCall(INVALID, forkChoice);

@ -213,6 +213,7 @@ public abstract class AbstractEngineNewPayload extends ExecutionEngineJsonRpcMet
// TODO: post-merge cleanup
if (requireTerminalPoWBlockValidation()
&& !mergeContext.get().isCheckpointPostMergeSync()
&& !mergeContext.get().isPostMergeAtGenesis()
&& !mergeCoordinator.latestValidAncestorDescendsFromTerminal(newBlockHeader)
&& !mergeContext.get().isChainPruningEnabled()) {
mergeCoordinator.addBadBlock(block, Optional.empty());

@ -94,6 +94,11 @@ public interface Blockchain {
.orElseThrow(() -> new IllegalStateException("Missing genesis block."));
}
default BlockHeader getGenesisBlockHeader() {
return getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER)
.orElseThrow(() -> new IllegalStateException("Missing genesis block header."));
}
default Optional<Block> getBlockByHash(final Hash blockHash) {
return getBlockHeader(blockHash)
.flatMap(header -> getBlockBody(blockHash).map(body -> new Block(header, body)));

Loading…
Cancel
Save