mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
add logs
This commit is contained in:
parent
a471810a70
commit
866713b600
1 changed files with 33 additions and 7 deletions
|
|
@ -988,11 +988,35 @@ func InspectContract(db ethdb.Database, address common.Address) error {
|
||||||
accountData := ReadAccountSnapshot(db, accountHash)
|
accountData := ReadAccountSnapshot(db, accountHash)
|
||||||
accountSnapshotSize := len(accountSnapshotKey(accountHash)) + len(accountData)
|
accountSnapshotSize := len(accountSnapshotKey(accountHash)) + len(accountData)
|
||||||
|
|
||||||
|
if len(accountData) == 0 {
|
||||||
|
return fmt.Errorf("account snapshot not found for address %s", address)
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
storageStat stat
|
storageStat stat
|
||||||
trieTracker = newDepthTracker()
|
trieTracker = newDepthTracker()
|
||||||
|
storageKeys atomic.Uint64
|
||||||
|
trieKeys atomic.Uint64
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Progress reporter
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(8 * time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
log.Info("Inspecting contract",
|
||||||
|
"storageSlots", storageKeys.Load(),
|
||||||
|
"trieNodes", trieKeys.Load(),
|
||||||
|
"elapsed", common.PrettyDuration(time.Since(start)))
|
||||||
|
case <-done:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
eg, ctx := errgroup.WithContext(context.Background())
|
eg, ctx := errgroup.WithContext(context.Background())
|
||||||
|
|
||||||
// 2. Storage snapshot: iterate all storage slots for this account
|
// 2. Storage snapshot: iterate all storage slots for this account
|
||||||
|
|
@ -1002,6 +1026,7 @@ func InspectContract(db ethdb.Database, address common.Address) error {
|
||||||
|
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
storageStat.add(common.StorageSize(len(it.Key()) + len(it.Value())))
|
storageStat.add(common.StorageSize(len(it.Key()) + len(it.Value())))
|
||||||
|
storageKeys.Add(1)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
@ -1024,6 +1049,7 @@ func InspectContract(db ethdb.Database, address common.Address) error {
|
||||||
}
|
}
|
||||||
trieTracker.add(string(path),
|
trieTracker.add(string(path),
|
||||||
common.StorageSize(len(it.Key())+len(it.Value())))
|
common.StorageSize(len(it.Key())+len(it.Value())))
|
||||||
|
trieKeys.Add(1)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
@ -1035,22 +1061,22 @@ func InspectContract(db ethdb.Database, address common.Address) error {
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := eg.Wait(); err != nil {
|
if err := eg.Wait(); err != nil {
|
||||||
|
close(done)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
close(done)
|
||||||
|
|
||||||
trieCount, trieSize := trieTracker.total()
|
trieCount, trieSize := trieTracker.total()
|
||||||
|
|
||||||
log.Info("Inspection complete", "elapsed", common.PrettyDuration(time.Since(start)))
|
log.Info("Inspection complete",
|
||||||
|
"storageSlots", storageKeys.Load(),
|
||||||
|
"trieNodes", trieCount,
|
||||||
|
"elapsed", common.PrettyDuration(time.Since(start)))
|
||||||
|
|
||||||
// Print results
|
// Print results
|
||||||
fmt.Printf("\n=== Contract Inspection: %s ===\n", address)
|
fmt.Printf("\n=== Contract Inspection: %s ===\n", address)
|
||||||
fmt.Printf("Account hash: %s\n\n", accountHash)
|
fmt.Printf("Account hash: %s\n\n", accountHash)
|
||||||
|
fmt.Printf("Account snapshot: %s\n", common.StorageSize(accountSnapshotSize))
|
||||||
if len(accountData) == 0 {
|
|
||||||
fmt.Println("Account snapshot: not found")
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Account snapshot: %s\n", common.StorageSize(accountSnapshotSize))
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Snapshot storage: %s slots (%s)\n", storageStat.countString(), storageStat.sizeString())
|
fmt.Printf("Snapshot storage: %s slots (%s)\n", storageStat.countString(), storageStat.sizeString())
|
||||||
fmt.Printf("Storage trie: %d nodes (%s)\n", trieCount, common.StorageSize(trieSize))
|
fmt.Printf("Storage trie: %d nodes (%s)\n", trieCount, common.StorageSize(trieSize))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue