Skip to content

Commit

Permalink
Revert "refactor: rename fields in hex patricia trie (#11296)"
Browse files Browse the repository at this point in the history
This reverts commit 62ed361.
  • Loading branch information
awskii committed Jul 26, 2024
1 parent 55ea23d commit e6a10a9
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 247 deletions.
24 changes: 12 additions & 12 deletions erigon-lib/commitment/bin_patricia_hashed.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ func (cell *BinaryCell) unwrapToHexCell() (cl *Cell) {
cl.Balance = *cell.Balance.Clone()
cl.Nonce = cell.Nonce
cl.StorageLen = cell.StorageLen
cl.accountPlainKeyLen = cell.apl
cl.storagePlainKeyLen = cell.spl
cl.HashLen = cell.hl
cl.apl = cell.apl
cl.spl = cell.spl
cl.hl = cell.hl

copy(cl.accountPlainKey[:], cell.apk[:])
copy(cl.storagePlainKey[:], cell.spk[:])
copy(cl.hash[:], cell.h[:])
copy(cl.apk[:], cell.apk[:])
copy(cl.spk[:], cell.spk[:])
copy(cl.h[:], cell.h[:])

if cell.extLen > 0 {
compactedExt := binToCompact(cell.extension[:cell.extLen])
Expand Down Expand Up @@ -1674,12 +1674,12 @@ func wrapAccountStorageFn(fn func([]byte, *Cell) error) func(pk []byte, bc *Bina
bc.Balance = *cl.Balance.Clone()
bc.Nonce = cl.Nonce
bc.StorageLen = cl.StorageLen
bc.apl = cl.accountPlainKeyLen
bc.spl = cl.storagePlainKeyLen
bc.hl = cl.HashLen
copy(bc.apk[:], cl.accountPlainKey[:])
copy(bc.spk[:], cl.storagePlainKey[:])
copy(bc.h[:], cl.hash[:])
bc.apl = cl.apl
bc.spl = cl.spl
bc.hl = cl.hl
copy(bc.apk[:], cl.apk[:])
copy(bc.spk[:], cl.spk[:])
copy(bc.h[:], cl.h[:])

if cl.extLen > 0 {
binExt := compactToBin(cl.extension[:cl.extLen])
Expand Down
38 changes: 19 additions & 19 deletions erigon-lib/commitment/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ func (branchData BranchData) String() string {
fmt.Fprintf(&sb, "hashedKey=[%x]", cell.downHashedKey[:cell.downHashedLen])
comma = ","
}
if cell.accountPlainKeyLen > 0 {
fmt.Fprintf(&sb, "%saccountPlainKey=[%x]", comma, cell.accountPlainKey[:cell.accountPlainKeyLen])
if cell.apl > 0 {
fmt.Fprintf(&sb, "%saccountPlainKey=[%x]", comma, cell.apk[:cell.apl])
comma = ","
}
if cell.storagePlainKeyLen > 0 {
fmt.Fprintf(&sb, "%sstoragePlainKey=[%x]", comma, cell.storagePlainKey[:cell.storagePlainKeyLen])
if cell.spl > 0 {
fmt.Fprintf(&sb, "%sstoragePlainKey=[%x]", comma, cell.spk[:cell.spl])
comma = ","
}
if cell.HashLen > 0 {
fmt.Fprintf(&sb, "%shash=[%x]", comma, cell.hash[:cell.HashLen])
if cell.hl > 0 {
fmt.Fprintf(&sb, "%shash=[%x]", comma, cell.h[:cell.hl])
}
sb.WriteString("}\n")
}
Expand Down Expand Up @@ -291,16 +291,16 @@ func (be *BranchEncoder) EncodeBranch(bitmap, touchMap, afterMap uint16, readCel

if bitmap&bit != 0 {
var fieldBits PartFlags
if cell.extLen > 0 && cell.storagePlainKeyLen == 0 {
if cell.extLen > 0 && cell.spl == 0 {
fieldBits |= HashedKeyPart
}
if cell.accountPlainKeyLen > 0 {
if cell.apl > 0 {
fieldBits |= AccountPlainPart
}
if cell.storagePlainKeyLen > 0 {
if cell.spl > 0 {
fieldBits |= StoragePlainPart
}
if cell.HashLen > 0 {
if cell.hl > 0 {
fieldBits |= HashPart
}
if err := be.buf.WriteByte(byte(fieldBits)); err != nil {
Expand All @@ -312,17 +312,17 @@ func (be *BranchEncoder) EncodeBranch(bitmap, touchMap, afterMap uint16, readCel
}
}
if fieldBits&AccountPlainPart != 0 {
if err := putUvarAndVal(uint64(cell.accountPlainKeyLen), cell.accountPlainKey[:cell.accountPlainKeyLen]); err != nil {
if err := putUvarAndVal(uint64(cell.apl), cell.apk[:cell.apl]); err != nil {
return nil, 0, err
}
}
if fieldBits&StoragePlainPart != 0 {
if err := putUvarAndVal(uint64(cell.storagePlainKeyLen), cell.storagePlainKey[:cell.storagePlainKeyLen]); err != nil {
if err := putUvarAndVal(uint64(cell.spl), cell.spk[:cell.spl]); err != nil {
return nil, 0, err
}
}
if fieldBits&HashPart != 0 {
if err := putUvarAndVal(uint64(cell.HashLen), cell.hash[:cell.HashLen]); err != nil {
if err := putUvarAndVal(uint64(cell.hl), cell.h[:cell.hl]); err != nil {
return nil, 0, err
}
}
Expand Down Expand Up @@ -751,14 +751,14 @@ func DecodeBranchAndCollectStat(key, branch []byte, tv TrieVariant) *BranchStat
stat.MinCellSize = min(stat.MinCellSize, enc)
stat.MaxCellSize = max(stat.MaxCellSize, enc)
switch {
case c.accountPlainKeyLen > 0:
stat.APKSize += uint64(c.accountPlainKeyLen)
case c.apl > 0:
stat.APKSize += uint64(c.apl)
stat.APKCount++
case c.storagePlainKeyLen > 0:
stat.SPKSize += uint64(c.storagePlainKeyLen)
case c.spl > 0:
stat.SPKSize += uint64(c.spl)
stat.SPKCount++
case c.HashLen > 0:
stat.HashSize += uint64(c.HashLen)
case c.hl > 0:
stat.HashSize += uint64(c.hl)
stat.HashCount++
default:
panic("no plain key" + fmt.Sprintf("#+%v", c))
Expand Down
12 changes: 6 additions & 6 deletions erigon-lib/commitment/commitment_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func BenchmarkBranchData_ReplacePlainKeys(b *testing.B) {
if c == nil {
continue
}
if c.accountPlainKeyLen > 0 {
offt, _ := binary.Uvarint(c.accountPlainKey[:c.accountPlainKeyLen])
b.Logf("%d apk %x, offt %d\n", i, c.accountPlainKey[:c.accountPlainKeyLen], offt)
if c.apl > 0 {
offt, _ := binary.Uvarint(c.apk[:c.apl])
b.Logf("%d apk %x, offt %d\n", i, c.apk[:c.apl], offt)
}
if c.storagePlainKeyLen > 0 {
offt, _ := binary.Uvarint(c.storagePlainKey[:c.storagePlainKeyLen])
b.Logf("%d spk %x offt %d\n", i, c.storagePlainKey[:c.storagePlainKeyLen], offt)
if c.spl > 0 {
offt, _ := binary.Uvarint(c.spk[:c.spl])
b.Logf("%d spk %x offt %d\n", i, c.spk[:c.spl], offt)
}

}
Expand Down
34 changes: 17 additions & 17 deletions erigon-lib/commitment/commitment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ func generateCellRow(tb testing.TB, size int) (row []*Cell, bitmap uint16) {
var bm uint16
for i := 0; i < len(row); i++ {
row[i] = new(Cell)
row[i].HashLen = 32
n, err := rand.Read(row[i].hash[:])
row[i].hl = 32
n, err := rand.Read(row[i].h[:])
require.NoError(tb, err)
require.EqualValues(tb, row[i].HashLen, n)
require.EqualValues(tb, row[i].hl, n)

th := rand.Intn(120)
switch {
case th > 70:
n, err = rand.Read(row[i].accountPlainKey[:])
n, err = rand.Read(row[i].apk[:])
require.NoError(tb, err)
row[i].accountPlainKeyLen = n
row[i].apl = n
case th > 20 && th <= 70:
n, err = rand.Read(row[i].storagePlainKey[:])
n, err = rand.Read(row[i].spk[:])
require.NoError(tb, err)
row[i].storagePlainKeyLen = n
row[i].spl = n
case th <= 20:
n, err = rand.Read(row[i].extension[:th])
row[i].extLen = n
Expand Down Expand Up @@ -92,10 +92,10 @@ func TestBranchData_MergeHexBranches2(t *testing.T) {
}
require.EqualValues(t, row[i].extLen, c.extLen)
require.EqualValues(t, row[i].extension, c.extension)
require.EqualValues(t, row[i].accountPlainKeyLen, c.accountPlainKeyLen)
require.EqualValues(t, row[i].accountPlainKey, c.accountPlainKey)
require.EqualValues(t, row[i].storagePlainKeyLen, c.storagePlainKeyLen)
require.EqualValues(t, row[i].storagePlainKey, c.storagePlainKey)
require.EqualValues(t, row[i].apl, c.apl)
require.EqualValues(t, row[i].apk, c.apk)
require.EqualValues(t, row[i].spl, c.spl)
require.EqualValues(t, row[i].spk, c.spk)
i++
}
}
Expand Down Expand Up @@ -201,13 +201,13 @@ func TestBranchData_ReplacePlainKeys(t *testing.T) {
if c == nil {
continue
}
if c.accountPlainKeyLen > 0 {
offt, _ := binary.Uvarint(c.accountPlainKey[:c.accountPlainKeyLen])
t.Logf("%d apk %x, offt %d\n", i, c.accountPlainKey[:c.accountPlainKeyLen], offt)
if c.apl > 0 {
offt, _ := binary.Uvarint(c.apk[:c.apl])
t.Logf("%d apk %x, offt %d\n", i, c.apk[:c.apl], offt)
}
if c.storagePlainKeyLen > 0 {
offt, _ := binary.Uvarint(c.storagePlainKey[:c.storagePlainKeyLen])
t.Logf("%d spk %x offt %d\n", i, c.storagePlainKey[:c.storagePlainKeyLen], offt)
if c.spl > 0 {
offt, _ := binary.Uvarint(c.spk[:c.spl])
t.Logf("%d spk %x offt %d\n", i, c.spk[:c.spl], offt)
}

}
Expand Down
Loading

0 comments on commit e6a10a9

Please sign in to comment.