Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
awskii committed Sep 26, 2024
1 parent 539f640 commit 3a79b70
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/commitment-prefix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package main

import (
"bytes"
"errors"
"flag"
"fmt"
Expand Down Expand Up @@ -193,6 +194,13 @@ func extractKVPairFromCompressed(filename string, keysSink chan commitment.Branc
}
val, _ = getter.Next(val[:0])
cpair++
if bytes.Equal(key, []byte("state")) {
str, err := commitment.HexTrieStateToString(val)
if err != nil {
fmt.Printf("[ERR] failed to decode state: %v", err)
}
fmt.Printf("%s: %s\n", key, str)
}

if cpair%100000 == 0 {
fmt.Printf("\r%s pair %d/%d %s/%s", filename, cpair, paris,
Expand Down
42 changes: 42 additions & 0 deletions erigon-lib/commitment/hex_patricia_hashed.go
Original file line number Diff line number Diff line change
Expand Up @@ -2109,3 +2109,45 @@ func (hph *HexPatriciaHashed) hashAndNibblizeKey(key []byte) []byte {
}
return nibblized
}

func HexTrieStateToString(enc []byte) (string, error) {
if len(enc) < 18 {
return "", fmt.Errorf("invlid state length %x (min %d expected)", len(enc), 18)
}
txn := binary.BigEndian.Uint16(enc)
bn := binary.BigEndian.Uint16(enc[8:])
sl := binary.BigEndian.Uint16(enc[16:18])

var s state
sb := new(strings.Builder)
if err := s.Decode(enc[18 : 18+sl]); err != nil {
return "", err
}
fmt.Fprintf(sb, "block: %d txn: %d\n", bn, txn)
fmt.Fprintf(sb, " touchMaps: %v\n", s.TouchMap)
fmt.Fprintf(sb, " afterMaps: %v\n", s.AfterMap)
fmt.Fprintf(sb, " depths: %v\n", s.Depths)

printBoolList := func(sb *strings.Builder, name string, list []bool) {
fmt.Fprintf(sb, " %s: [", name)
for _, v := range list {
if v {
fmt.Fprintf(sb, "1 ")
} else {
fmt.Fprintf(sb, "0 ")
}
}
fmt.Fprintf(sb, "]\n")
}
printBoolList(sb, "branchBefore", s.BranchBefore[:])
fmt.Fprintf(sb, " rootNode: %x [touched=%t, present=%t, checked=%t]\n", s.Root, s.RootTouched, s.RootPresent, s.RootChecked)

root := new(cell)
if err := root.Decode(s.Root); err != nil {
return "", err
}

fmt.Fprintf(sb, "RootHash: %x\n", root.hash)

return sb.String(), nil
}

0 comments on commit 3a79b70

Please sign in to comment.