From c8f2e74e6faafcfc6ff2428580b738dde7f66bc2 Mon Sep 17 00:00:00 2001 From: Simon Dudley Date: Fri, 10 Jan 2025 16:54:31 +1000 Subject: [PATCH] Log calculated world state contents upon state root mismatch Signed-off-by: Simon Dudley --- .../vm/GeneralStateReferenceTestTools.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java index 7166c13a5b6..a4de20225c2 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Optional; +import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.BlobGas; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -42,8 +43,12 @@ import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.testutil.JsonTestParameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class GeneralStateReferenceTestTools { + private static final Logger LOG = LoggerFactory.getLogger(GeneralStateReferenceTestTools.class); + private static final List SPECS_PRIOR_TO_DELETING_EMPTY_ACCOUNTS = Arrays.asList("Frontier", "Homestead", "EIP150"); @@ -179,11 +184,27 @@ public static void executeTest(final GeneralStateTestCaseEipSpec spec) { worldStateUpdater.deleteAccount(coinbase.getAddress()); } worldStateUpdater.commit(); - worldState.processExtraStateStorageFormatValidation(blockHeader); +// worldState.processExtraStateStorageFormatValidation(blockHeader); worldState.persist(blockHeader); // Check the world state root hash. final Hash expectedRootHash = spec.getExpectedRootHash(); + if (!worldState.rootHash().equals(expectedRootHash)) { + worldState.streamAccounts(Bytes32.ZERO, Integer.MAX_VALUE) + .forEach( + account -> { + LOG.error("ADDRESS: {}", account.getAddress()); + LOG.error("nonce: {}", account.getNonce()); + LOG.error("balance: {}", account.getBalance()); + LOG.error("code: {}", account.getCode()); + account.storageEntriesFrom(Bytes32.ZERO, Integer.MAX_VALUE) + .forEach( + (key, value) -> { + LOG.error("storage: {} -> {}", key, value); + }); + LOG.error("--------------------------"); + }); + } assertThat(worldState.rootHash()) .withFailMessage( "Unexpected world state root hash; expected state: %s, computed state: %s",