From b9339ca8473374e6f1585548f26f9b6f0f72028e Mon Sep 17 00:00:00 2001 From: jsvisa Date: Wed, 22 Oct 2025 12:15:39 +0800 Subject: [PATCH] core/state: add debug if accounts mismatch --- core/state/state_sizer_test.go | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/core/state/state_sizer_test.go b/core/state/state_sizer_test.go index cab0c38163..e14319f2ba 100644 --- a/core/state/state_sizer_test.go +++ b/core/state/state_sizer_test.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/triedb" "github.com/ethereum/go-ethereum/triedb/pathdb" "github.com/holiman/uint256" @@ -119,6 +120,57 @@ func TestSizeTracker(t *testing.T) { } baseline := baselineResult.stat + // DEBUG: Check if baseline found all expected accounts + if baseline.Accounts != 52 { + t.Logf("WARNING: Baseline found %d accounts instead of expected 52", baseline.Accounts) + + // Collect all expected account addresses + expectedAddrs := make(map[common.Address]bool) + expectedAddrs[addr1] = true + expectedAddrs[addr2] = true + expectedAddrs[addr3] = true + for i := 1; i < 50; i++ { + testAddr := common.BigToAddress(uint256.NewInt(uint64(i + 100)).ToBig()) + expectedAddrs[testAddr] = true + } + + // Scan what's actually in the snapshot + actualAddrs := make(map[common.Address]bool) + iter := db.NewIterator(rawdb.SnapshotAccountPrefix, nil) + for iter.Next() { + // Key is: prefix + account hash + if len(iter.Key()) < len(rawdb.SnapshotAccountPrefix)+common.HashLength { + continue + } + accHash := common.BytesToHash(iter.Key()[len(rawdb.SnapshotAccountPrefix):]) + + // Find which address this hash corresponds to + for addr := range expectedAddrs { + if crypto.Keccak256Hash(addr.Bytes()) == accHash { + actualAddrs[addr] = true + break + } + } + } + iter.Release() + + t.Logf("Serial scan found %d accounts in snapshot", len(actualAddrs)) + + // Find missing accounts + for addr := range expectedAddrs { + if !actualAddrs[addr] { + t.Logf("MISSING ACCOUNT: %s (hash: %s)", addr.Hex(), crypto.Keccak256Hash(addr.Bytes()).Hex()) + } + } + + // Find unexpected accounts + for addr := range actualAddrs { + if !expectedAddrs[addr] { + t.Logf("UNEXPECTED ACCOUNT: %s (hash: %s)", addr.Hex(), crypto.Keccak256Hash(addr.Bytes()).Hex()) + } + } + } + // Now start the tracker and notify it of updates that happen AFTER the baseline tracker, err := NewSizeTracker(db, tdb) if err != nil {