diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java index 966b81d348f..cad84e30407 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncContext; import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BadChainListener; @@ -521,30 +522,42 @@ private boolean setNewHead(final MutableBlockchain blockchain, final BlockHeader LOG, "Forwarding chain head to the block {} saved from a previous newPayload invocation", newHead::toLogString); - forwardWorldStateTo(newHead); - return blockchain.forwardToBlock(newHead); + + if (forwardWorldStateTo(newHead)) { + // move chain head forward: + return blockchain.forwardToBlock(newHead); + } else { + debugLambda( + LOG, + "Failed to move the worldstate forward to hash {}, not moving chain head", + newHead::toLogString); + return false; + } } debugLambda(LOG, "New head {} is a chain reorg, rewind chain head to it", newHead::toLogString); return blockchain.rewindToBlock(newHead.getHash()); } - private void forwardWorldStateTo(final BlockHeader newHead) { - protocolContext - .getWorldStateArchive() - .getMutable(newHead.getStateRoot(), newHead.getHash()) - .ifPresentOrElse( - mutableWorldState -> - debugLambda( - LOG, - "World state for state root hash {} and block hash {} persisted successfully", - mutableWorldState::rootHash, - newHead::getHash), - () -> - LOG.error( - "Could not persist world for root hash {} and block hash {}", - newHead.getStateRoot(), - newHead.getHash())); + private boolean forwardWorldStateTo(final BlockHeader newHead) { + Optional newWorldState = + protocolContext + .getWorldStateArchive() + .getMutable(newHead.getStateRoot(), newHead.getHash()); + + newWorldState.ifPresentOrElse( + mutableWorldState -> + debugLambda( + LOG, + "World state for state root hash {} and block hash {} persisted successfully", + mutableWorldState::rootHash, + newHead::getHash), + () -> + LOG.error( + "Could not persist world for root hash {} and block hash {}", + newHead.getStateRoot(), + newHead.getHash())); + return newWorldState.isPresent(); } @Override diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorage.java index 3d0972e9a1e..46ba2e5f197 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorage.java @@ -39,8 +39,9 @@ import org.apache.tuweni.rlp.RLP; public class BonsaiWorldStateKeyValueStorage implements WorldStateStorage, AutoCloseable { + // 0x776f726c64526f6f74 public static final byte[] WORLD_ROOT_HASH_KEY = "worldRoot".getBytes(StandardCharsets.UTF_8); - + // 0x776f726c64426c6f636b48617368 public static final byte[] WORLD_BLOCK_HASH_KEY = "worldBlockHash".getBytes(StandardCharsets.UTF_8);