Address dump utility (#1856)

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
This commit is contained in:
ledgerwatch 2021-05-01 21:04:02 +01:00 committed by GitHub
parent 08f6299257
commit 4303465e96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1213,6 +1213,45 @@ func testGetProof(chaindata string, address common.Address, rewind int, regen bo
return nil return nil
} }
func dumpAddresses(chaindata string) error {
db := ethdb.MustOpen(chaindata)
defer db.Close()
f, err := os.Create("addresses")
if err != nil {
return err
}
defer f.Close()
w := bufio.NewWriter(f)
defer w.Flush()
stAccounts := 0
stStorage := 0
if err := db.RwKV().View(context.Background(), func(tx ethdb.Tx) error {
c, err := tx.Cursor(dbutils.PlainStateBucket)
if err != nil {
return err
}
k, _, e := c.First()
for ; k != nil && e == nil; k, _, e = c.Next() {
if len(k) > 28 {
stStorage++
} else {
stAccounts++
if _, err1 := w.Write(k[:20]); err1 != nil {
return err1
}
}
if (stStorage+stAccounts)%100000 == 0 {
fmt.Printf("State records: %d\n", stStorage+stAccounts)
}
}
return e
}); err != nil {
return err
}
fmt.Printf("stAccounts = %d, stStorage = %d\n", stAccounts, stStorage)
return nil
}
func changeSetStats(chaindata string, block1, block2 uint64) error { func changeSetStats(chaindata string, block1, block2 uint64) error {
db := ethdb.MustOpen(chaindata) db := ethdb.MustOpen(chaindata)
defer db.Close() defer db.Close()
@ -1920,6 +1959,9 @@ func main() {
case "snapSizes": case "snapSizes":
err = snapSizes(*chaindata) err = snapSizes(*chaindata)
case "dumpAddresses":
err = dumpAddresses(*chaindata)
} }
if err != nil { if err != nil {