Skip to content

Commit

Permalink
Merge branch 'hex-patricia-reader' into hex-patricia-reader-proof
Browse files Browse the repository at this point in the history
  • Loading branch information
shotasilagadzetaal committed Feb 8, 2025
2 parents 75221e2 + 3b8fc40 commit ea8ed57
Show file tree
Hide file tree
Showing 6 changed files with 425 additions and 307 deletions.
18 changes: 17 additions & 1 deletion erigon-lib/commitment/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/erigontech/erigon-lib/types/accounts"
"math/bits"
"sort"
"strings"
"unsafe"

"github.com/erigontech/erigon-lib/types/accounts"

"github.com/holiman/uint256"

"github.com/google/btree"
Expand Down Expand Up @@ -120,6 +121,8 @@ type TrieVariant string
const (
// VariantHexPatriciaTrie used as default commitment approach
VariantHexPatriciaTrie TrieVariant = "hex-patricia-hashed"
// VariantHexPatriciaTrieReader used as read only commitment trie
VariantHexPatriciaTrieReader TrieVariant = "hex-patricia-hashed-reader"
// VariantBinPatriciaTrie - Experimental mode with binary key representation
VariantBinPatriciaTrie TrieVariant = "bin-patricia-hashed"
)
Expand Down Expand Up @@ -922,6 +925,13 @@ func DecodeBranchAndCollectStat(key, branch []byte, tv TrieVariant) *BranchStat
return stat
}

type ReadOrUpdate int

const (
ReadTouch ReadOrUpdate = 0
UpdateTouch ReadOrUpdate = 1
)

// Defines how to evaluate commitments
type Mode uint

Expand Down Expand Up @@ -967,6 +977,9 @@ type Updates struct {
tmpdir string
}

type Reads = Updates
type ReadsOrUpdates = Updates

type keyHasher func(key []byte) []byte

func keyHasherNoop(key []byte) []byte { return key }
Expand All @@ -986,6 +999,9 @@ func NewUpdates(m Mode, tmpdir string, hasher keyHasher) *Updates {
}
return t
}

var NewReads = NewUpdates

func (t *Updates) SetMode(m Mode) {
t.mode = m
if t.mode == ModeDirect && t.keys == nil {
Expand Down
10 changes: 5 additions & 5 deletions erigon-lib/commitment/commitment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ func TestBranchData_ReplacePlainKeys_WithEmpty(t *testing.T) {
})
}

func TestNewUpdates(t *testing.T) {
func TestNewReadsOrUpdates(t *testing.T) {
t.Parallel()

t.Run("ModeUpdate", func(t *testing.T) {
ut := NewUpdates(ModeUpdate, t.TempDir(), keyHasherNoop)
ut := NewReadsOrUpdates(ModeUpdate, t.TempDir(), keyHasherNoop)

require.NotNil(t, ut.tree)
require.NotNil(t, ut.keccak)
Expand All @@ -315,7 +315,7 @@ func TestNewUpdates(t *testing.T) {
})

t.Run("ModeDirect", func(t *testing.T) {
ut := NewUpdates(ModeDirect, t.TempDir(), keyHasherNoop)
ut := NewReadsOrUpdates(ModeDirect, t.TempDir(), keyHasherNoop)

require.NotNil(t, ut.keccak)
require.NotNil(t, ut.keys)
Expand All @@ -327,8 +327,8 @@ func TestNewUpdates(t *testing.T) {
func TestUpdates_TouchPlainKey(t *testing.T) {
t.Parallel()

utUpdate := NewUpdates(ModeUpdate, t.TempDir(), keyHasherNoop)
utDirect := NewUpdates(ModeDirect, t.TempDir(), keyHasherNoop)
utUpdate := NewReadsOrUpdates(ModeUpdate, t.TempDir(), keyHasherNoop)
utDirect := NewReadsOrUpdates(ModeDirect, t.TempDir(), keyHasherNoop)

type tc struct {
key []byte
Expand Down
Loading

0 comments on commit ea8ed57

Please sign in to comment.