Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.apl = cell.apl
cl.spl = cell.spl
cl.hl = cell.hl
cl.accountPlainKeyLen = cell.apl
cl.storagePlainKeyLen = cell.spl
cl.HashLen = cell.hl

copy(cl.apk[:], cell.apk[:])
copy(cl.spk[:], cell.spk[:])
copy(cl.h[:], cell.h[:])
copy(cl.accountPlainKey[:], cell.apk[:])
copy(cl.storagePlainKey[:], cell.spk[:])
copy(cl.hash[:], 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.apl
bc.spl = cl.spl
bc.hl = cl.hl
copy(bc.apk[:], cl.apk[:])
copy(bc.spk[:], cl.spk[:])
copy(bc.h[:], cl.h[:])
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[:])

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.apl > 0 {
fmt.Fprintf(&sb, "%saccountPlainKey=[%x]", comma, cell.apk[:cell.apl])
if cell.accountPlainKeyLen > 0 {
fmt.Fprintf(&sb, "%saccountPlainKey=[%x]", comma, cell.accountPlainKey[:cell.accountPlainKeyLen])
comma = ","
}
if cell.spl > 0 {
fmt.Fprintf(&sb, "%sstoragePlainKey=[%x]", comma, cell.spk[:cell.spl])
if cell.storagePlainKeyLen > 0 {
fmt.Fprintf(&sb, "%sstoragePlainKey=[%x]", comma, cell.storagePlainKey[:cell.storagePlainKeyLen])
comma = ","
}
if cell.hl > 0 {
fmt.Fprintf(&sb, "%shash=[%x]", comma, cell.h[:cell.hl])
if cell.HashLen > 0 {
fmt.Fprintf(&sb, "%shash=[%x]", comma, cell.hash[:cell.HashLen])
}
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.spl == 0 {
if cell.extLen > 0 && cell.storagePlainKeyLen == 0 {
fieldBits |= HashedKeyPart
}
if cell.apl > 0 {
if cell.accountPlainKeyLen > 0 {
fieldBits |= AccountPlainPart
}
if cell.spl > 0 {
if cell.storagePlainKeyLen > 0 {
fieldBits |= StoragePlainPart
}
if cell.hl > 0 {
if cell.HashLen > 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.apl), cell.apk[:cell.apl]); err != nil {
if err := putUvarAndVal(uint64(cell.accountPlainKeyLen), cell.accountPlainKey[:cell.accountPlainKeyLen]); err != nil {
return nil, 0, err
}
}
if fieldBits&StoragePlainPart != 0 {
if err := putUvarAndVal(uint64(cell.spl), cell.spk[:cell.spl]); err != nil {
if err := putUvarAndVal(uint64(cell.storagePlainKeyLen), cell.storagePlainKey[:cell.storagePlainKeyLen]); err != nil {
return nil, 0, err
}
}
if fieldBits&HashPart != 0 {
if err := putUvarAndVal(uint64(cell.hl), cell.h[:cell.hl]); err != nil {
if err := putUvarAndVal(uint64(cell.HashLen), cell.hash[:cell.HashLen]); 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.apl > 0:
stat.APKSize += uint64(c.apl)
case c.accountPlainKeyLen > 0:
stat.APKSize += uint64(c.accountPlainKeyLen)
stat.APKCount++
case c.spl > 0:
stat.SPKSize += uint64(c.spl)
case c.storagePlainKeyLen > 0:
stat.SPKSize += uint64(c.storagePlainKeyLen)
stat.SPKCount++
case c.hl > 0:
stat.HashSize += uint64(c.hl)
case c.HashLen > 0:
stat.HashSize += uint64(c.HashLen)
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.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.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.spl > 0 {
offt, _ := binary.Uvarint(c.spk[:c.spl])
b.Logf("%d spk %x offt %d\n", i, c.spk[:c.spl], 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)
}

}
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].hl = 32
n, err := rand.Read(row[i].h[:])
row[i].HashLen = 32
n, err := rand.Read(row[i].hash[:])
require.NoError(tb, err)
require.EqualValues(tb, row[i].hl, n)
require.EqualValues(tb, row[i].HashLen, n)

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

}
Expand Down
Loading