Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update worldstate state change behavior in case of FCU #5699

Merged
merged 15 commits into from
Aug 18, 2023
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) {
Copy link
Contributor

@gfukushima gfukushima Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rename implies that we could use this method to move the ws "backwards", is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we can do rollback and rollfoward with this code

Optional<MutableWorldState> newWorldState =
protocolContext
.getWorldStateArchive()
Expand Down
Loading