Skip to content

Commit a611b3b

Browse files
authored
check if block is imported successfully before moving worldstate head (#8447)
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
1 parent 375a700 commit a611b3b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockImporter.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hyperledger.besu.ethereum.core.BlockImporter;
2121
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
2222
import org.hyperledger.besu.ethereum.mainnet.BlockImportResult.BlockImportStatus;
23+
import org.hyperledger.besu.ethereum.trie.pathbased.common.provider.WorldStateQueryParams;
2324

2425
import java.util.List;
2526

@@ -43,14 +44,24 @@ public synchronized BlockImportResult importBlock(
4344

4445
final var result =
4546
blockValidator.validateAndProcessBlock(
46-
context, block, headerValidationMode, ommerValidationMode);
47+
context, block, headerValidationMode, ommerValidationMode, false);
4748

4849
if (result.isSuccessful()) {
4950
result
5051
.getYield()
5152
.ifPresent(
52-
processingOutputs ->
53-
context.getBlockchain().appendBlock(block, processingOutputs.getReceipts()));
53+
processingOutputs -> {
54+
context.getBlockchain().appendBlock(block, processingOutputs.getReceipts());
55+
56+
// move the head worldstate if block processing was successful:
57+
context
58+
.getWorldStateArchive()
59+
.getWorldState(
60+
WorldStateQueryParams.newBuilder()
61+
.withBlockHeader(block.getHeader())
62+
.withShouldWorldStateUpdateHead(true)
63+
.build());
64+
});
5465
}
5566

5667
return new BlockImportResult(result.isSuccessful());

0 commit comments

Comments
 (0)