Skip to content

Commit

Permalink
Update worldstate state change behavior in case of FCU (hyperledger#5699
Browse files Browse the repository at this point in the history
)

Update the worldstate in the same way as the blockchain in order to avoid having inconsistencies between the two and later trigger a big rollforward

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Co-authored-by: Ameziane H <ameziane.hamlat@consensys.net>
  • Loading branch information
2 people authored and garyschulte committed Aug 28, 2023
1 parent fb63b59 commit 5357f75
Showing 1 changed file with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,33 +607,30 @@ private boolean setNewHead(final MutableBlockchain blockchain, final BlockHeader
return true;
}

if (newHead.getParentHash().equals(blockchain.getChainHeadHash())) {
LOG.atDebug()
.setMessage(
"Forwarding chain head to the block {} saved from a previous newPayload invocation")
.addArgument(newHead::toLogString)
.log();

if (forwardWorldStateTo(newHead)) {
// move chain head forward:
if (moveWorldStateTo(newHead)) {
if (newHead.getParentHash().equals(blockchain.getChainHeadHash())) {
LOG.atDebug()
.setMessage(
"Forwarding chain head to the block {} saved from a previous newPayload invocation")
.addArgument(newHead::toLogString)
.log();
return blockchain.forwardToBlock(newHead);
} else {
LOG.atDebug()
.setMessage("Failed to move the worldstate forward to hash {}, not moving chain head")
.setMessage("New head {} is a chain reorg, rewind chain head to it")
.addArgument(newHead::toLogString)
.log();
return false;
return blockchain.rewindToBlock(newHead.getHash());
}
}

LOG.atDebug()
.setMessage("New head {} is a chain reorg, rewind chain head to it")
.setMessage("Failed to move the worldstate forward to hash {}, not moving chain head")
.addArgument(newHead::toLogString)
.log();
return blockchain.rewindToBlock(newHead.getHash());
return false;
}

private boolean forwardWorldStateTo(final BlockHeader newHead) {
private boolean moveWorldStateTo(final BlockHeader newHead) {
Optional<MutableWorldState> newWorldState =
protocolContext
.getWorldStateArchive()
Expand Down

0 comments on commit 5357f75

Please sign in to comment.