@@ -20,8 +20,10 @@ import (
20
20
"bytes"
21
21
"errors"
22
22
"fmt"
23
+ "maps"
23
24
"os"
24
25
"path/filepath"
26
+ "slices"
25
27
"strings"
26
28
"time"
27
29
@@ -360,24 +362,27 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
360
362
logged = time .Now ()
361
363
362
364
// Key-value store statistics
363
- headers stat
364
- bodies stat
365
- receipts stat
366
- tds stat
367
- numHashPairings stat
368
- hashNumPairings stat
369
- legacyTries stat
370
- stateLookups stat
371
- accountTries stat
372
- storageTries stat
373
- codes stat
374
- txLookups stat
375
- accountSnaps stat
376
- storageSnaps stat
377
- preimages stat
378
- filterMaps stat
379
- beaconHeaders stat
380
- cliqueSnaps stat
365
+ headers stat
366
+ bodies stat
367
+ receipts stat
368
+ tds stat
369
+ numHashPairings stat
370
+ hashNumPairings stat
371
+ legacyTries stat
372
+ stateLookups stat
373
+ accountTries stat
374
+ storageTries stat
375
+ codes stat
376
+ txLookups stat
377
+ accountSnaps stat
378
+ storageSnaps stat
379
+ preimages stat
380
+ beaconHeaders stat
381
+ cliqueSnaps stat
382
+ bloomBits stat
383
+ filterMapRows stat
384
+ filterMapLastBlock stat
385
+ filterMapBlockLV stat
381
386
382
387
// Verkle statistics
383
388
verkleTries stat
@@ -393,6 +398,11 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
393
398
394
399
// Totals
395
400
total common.StorageSize
401
+
402
+ // This map tracks example keys for unaccounted data.
403
+ // For each unique two-byte prefix, the first unaccounted key encountered
404
+ // by the iterator will be stored.
405
+ unaccountedKeys = make (map [[2 ]byte ][]byte )
396
406
)
397
407
// Inspect key-value database first.
398
408
for it .Next () {
@@ -436,19 +446,33 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
436
446
metadata .Add (size )
437
447
case bytes .HasPrefix (key , genesisPrefix ) && len (key ) == (len (genesisPrefix )+ common .HashLength ):
438
448
metadata .Add (size )
439
- case bytes .HasPrefix (key , []byte (filterMapsPrefix )):
440
- filterMaps .Add (size )
441
449
case bytes .HasPrefix (key , skeletonHeaderPrefix ) && len (key ) == (len (skeletonHeaderPrefix )+ 8 ):
442
450
beaconHeaders .Add (size )
443
451
case bytes .HasPrefix (key , CliqueSnapshotPrefix ) && len (key ) == 7 + common .HashLength :
444
452
cliqueSnaps .Add (size )
445
- case bytes .HasPrefix (key , ChtTablePrefix ) ||
446
- bytes .HasPrefix (key , ChtIndexTablePrefix ) ||
447
- bytes .HasPrefix (key , ChtPrefix ): // Canonical hash trie
453
+
454
+ // new log index
455
+ case bytes .HasPrefix (key , filterMapRowPrefix ) && len (key ) <= len (filterMapRowPrefix )+ 9 :
456
+ filterMapRows .Add (size )
457
+ case bytes .HasPrefix (key , filterMapLastBlockPrefix ) && len (key ) == len (filterMapLastBlockPrefix )+ 4 :
458
+ filterMapLastBlock .Add (size )
459
+ case bytes .HasPrefix (key , filterMapBlockLVPrefix ) && len (key ) == len (filterMapBlockLVPrefix )+ 8 :
460
+ filterMapBlockLV .Add (size )
461
+
462
+ // old log index (deprecated)
463
+ case bytes .HasPrefix (key , bloomBitsPrefix ) && len (key ) == (len (bloomBitsPrefix )+ 10 + common .HashLength ):
464
+ bloomBits .Add (size )
465
+ case bytes .HasPrefix (key , bloomBitsMetaPrefix ) && len (key ) < len (bloomBitsMetaPrefix )+ 8 :
466
+ bloomBits .Add (size )
467
+
468
+ // LES indexes (deprecated)
469
+ case bytes .HasPrefix (key , chtTablePrefix ) ||
470
+ bytes .HasPrefix (key , chtIndexTablePrefix ) ||
471
+ bytes .HasPrefix (key , chtPrefix ): // Canonical hash trie
448
472
chtTrieNodes .Add (size )
449
- case bytes .HasPrefix (key , BloomTrieTablePrefix ) ||
450
- bytes .HasPrefix (key , BloomTrieIndexPrefix ) ||
451
- bytes .HasPrefix (key , BloomTriePrefix ): // Bloomtrie sub
473
+ case bytes .HasPrefix (key , bloomTrieTablePrefix ) ||
474
+ bytes .HasPrefix (key , bloomTrieIndexPrefix ) ||
475
+ bytes .HasPrefix (key , bloomTriePrefix ): // Bloomtrie sub
452
476
bloomTrieNodes .Add (size )
453
477
454
478
// Verkle trie data is detected, determine the sub-category
@@ -468,24 +492,19 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
468
492
default :
469
493
unaccounted .Add (size )
470
494
}
495
+
496
+ // Metadata keys
497
+ case slices .ContainsFunc (knownMetadataKeys , func (x []byte ) bool { return bytes .Equal (x , key ) }):
498
+ metadata .Add (size )
499
+
471
500
default :
472
- var accounted bool
473
- for _ , meta := range [][]byte {
474
- databaseVersionKey , headHeaderKey , headBlockKey , headFastBlockKey , headFinalizedBlockKey ,
475
- lastPivotKey , fastTrieProgressKey , snapshotDisabledKey , SnapshotRootKey , snapshotJournalKey ,
476
- snapshotGeneratorKey , snapshotRecoveryKey , txIndexTailKey , fastTxLookupLimitKey ,
477
- uncleanShutdownKey , badBlockKey , transitionStatusKey , skeletonSyncStatusKey ,
478
- persistentStateIDKey , trieJournalKey , snapshotSyncStatusKey , snapSyncStatusFlagKey ,
479
- } {
480
- if bytes .Equal (key , meta ) {
481
- metadata .Add (size )
482
- accounted = true
483
- break
501
+ unaccounted .Add (size )
502
+ if len (key ) >= 2 {
503
+ prefix := [2 ]byte (key [:2 ])
504
+ if _ , ok := unaccountedKeys [prefix ]; ! ok {
505
+ unaccountedKeys [prefix ] = bytes .Clone (key )
484
506
}
485
507
}
486
- if ! accounted {
487
- unaccounted .Add (size )
488
- }
489
508
}
490
509
count ++
491
510
if count % 1000 == 0 && time .Since (logged ) > 8 * time .Second {
@@ -502,7 +521,10 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
502
521
{"Key-Value store" , "Block number->hash" , numHashPairings .Size (), numHashPairings .Count ()},
503
522
{"Key-Value store" , "Block hash->number" , hashNumPairings .Size (), hashNumPairings .Count ()},
504
523
{"Key-Value store" , "Transaction index" , txLookups .Size (), txLookups .Count ()},
505
- {"Key-Value store" , "Log search index" , filterMaps .Size (), filterMaps .Count ()},
524
+ {"Key-Value store" , "Log index filter-map rows" , filterMapRows .Size (), filterMapRows .Count ()},
525
+ {"Key-Value store" , "Log index last-block-of-map" , filterMapLastBlock .Size (), filterMapLastBlock .Count ()},
526
+ {"Key-Value store" , "Log index block-lv" , filterMapBlockLV .Size (), filterMapBlockLV .Count ()},
527
+ {"Key-Value store" , "Log bloombits (deprecated)" , bloomBits .Size (), bloomBits .Count ()},
506
528
{"Key-Value store" , "Contract codes" , codes .Size (), codes .Count ()},
507
529
{"Key-Value store" , "Hash trie nodes" , legacyTries .Size (), legacyTries .Count ()},
508
530
{"Key-Value store" , "Path trie state lookups" , stateLookups .Size (), stateLookups .Count ()},
@@ -543,10 +565,23 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
543
565
544
566
if unaccounted .size > 0 {
545
567
log .Error ("Database contains unaccounted data" , "size" , unaccounted .size , "count" , unaccounted .count )
568
+ for _ , e := range slices .SortedFunc (maps .Values (unaccountedKeys ), bytes .Compare ) {
569
+ log .Error (fmt .Sprintf (" example key: %x" , e ))
570
+ }
546
571
}
547
572
return nil
548
573
}
549
574
575
+ // This is the list of known 'metadata' keys stored in the databasse.
576
+ var knownMetadataKeys = [][]byte {
577
+ databaseVersionKey , headHeaderKey , headBlockKey , headFastBlockKey , headFinalizedBlockKey ,
578
+ lastPivotKey , fastTrieProgressKey , snapshotDisabledKey , SnapshotRootKey , snapshotJournalKey ,
579
+ snapshotGeneratorKey , snapshotRecoveryKey , txIndexTailKey , fastTxLookupLimitKey ,
580
+ uncleanShutdownKey , badBlockKey , transitionStatusKey , skeletonSyncStatusKey ,
581
+ persistentStateIDKey , trieJournalKey , snapshotSyncStatusKey , snapSyncStatusFlagKey ,
582
+ filterMapsRangeKey ,
583
+ }
584
+
550
585
// printChainMetadata prints out chain metadata to stderr.
551
586
func printChainMetadata (db ethdb.KeyValueStore ) {
552
587
fmt .Fprintf (os .Stderr , "Chain metadata\n " )
@@ -566,6 +601,7 @@ func ReadChainMetadata(db ethdb.KeyValueStore) [][]string {
566
601
}
567
602
return fmt .Sprintf ("%d (%#x)" , * val , * val )
568
603
}
604
+
569
605
data := [][]string {
570
606
{"databaseVersion" , pp (ReadDatabaseVersion (db ))},
571
607
{"headBlockHash" , fmt .Sprintf ("%v" , ReadHeadBlockHash (db ))},
@@ -582,5 +618,8 @@ func ReadChainMetadata(db ethdb.KeyValueStore) [][]string {
582
618
if b := ReadSkeletonSyncStatus (db ); b != nil {
583
619
data = append (data , []string {"SkeletonSyncStatus" , string (b )})
584
620
}
621
+ if fmr , ok , _ := ReadFilterMapsRange (db ); ok {
622
+ data = append (data , []string {"filterMapsRange" , fmt .Sprintf ("%+v" , fmr )})
623
+ }
585
624
return data
586
625
}
0 commit comments