Skip to content

Commit

Permalink
Log calculated world state contents upon state root mismatch
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Dudley <[email protected]>
  • Loading branch information
siladu committed Jan 10, 2025
1 parent 2aadbfc commit c8f2e74
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> SPECS_PRIOR_TO_DELETING_EMPTY_ACCOUNTS =
Arrays.asList("Frontier", "Homestead", "EIP150");

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c8f2e74

Please sign in to comment.