Skip to content

Commit

Permalink
chore: remove deltas to tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Feb 7, 2024
1 parent c88b51f commit ae493f2
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 53 deletions.
40 changes: 0 additions & 40 deletions internal/trie/tracking/deltas.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
)

type DeltaEntry struct {
Key []byte
Value []byte
}

// Deltas tracks the trie deltas, for example deleted node hashes.
type Deltas struct {
entries []DeltaEntry
deletedNodeHashes map[common.Hash]struct{}
}

// New returns a new Deltas struct.
func New() *Deltas {
return &Deltas{
entries: make([]DeltaEntry, 0),
deletedNodeHashes: make(map[common.Hash]struct{}),
}
}
Expand All @@ -31,18 +24,6 @@ func (d *Deltas) RecordDeleted(nodeHash common.Hash) {
d.deletedNodeHashes[nodeHash] = struct{}{}
}

// RecordUpdated records a node hash that was created or updated.
func (d *Deltas) RecordUpdated(key, value []byte) {
newEntry := DeltaEntry{
Key: make([]byte, len(key)),
Value: make([]byte, len(value)),
}

copy(newEntry.Key[:], key[:])
copy(newEntry.Value[:], value[:])
d.entries = append(d.entries, newEntry)
}

func (d *Deltas) HasUpdated(partialKeyHash common.Hash) bool {
return false
}
Expand All @@ -54,20 +35,12 @@ func (d *Deltas) Deleted() (nodeHashes map[common.Hash]struct{}) {
return d.deletedNodeHashes
}

func (d *Deltas) Updated() []DeltaEntry {
return d.entries
}

// MergeWith merges the deltas given as argument in the receiving
// deltas struct.
func (d *Deltas) MergeWith(deltas Getter) {
for nodeHash := range deltas.Deleted() {
d.RecordDeleted(nodeHash)
}

for _, deltaEntry := range deltas.Updated() {
d.RecordUpdated(deltaEntry.Key, deltaEntry.Value)
}
}

// DeepCopy returns a deep copy of the deltas.
Expand All @@ -85,18 +58,5 @@ func (d *Deltas) DeepCopy() (deepCopy *Deltas) {
}
}

if len(d.entries) != 0 {
deepCopy.entries = make([]DeltaEntry, len(d.entries))
for idx, deltaEntry := range d.entries {
newEntry := DeltaEntry{
Key: make([]byte, len(deltaEntry.Key)),
Value: make([]byte, len(deltaEntry.Value)),
}

copy(newEntry.Key[:], deltaEntry.Key[:])
copy(newEntry.Value[:], deltaEntry.Value[:])
deepCopy.entries[idx] = newEntry
}
}
return deepCopy
}
1 change: 0 additions & 1 deletion internal/trie/tracking/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ import "github.com/ChainSafe/gossamer/lib/common"
// Getter gets deleted node hashes.
type Getter interface {
Deleted() (nodeHashes map[common.Hash]struct{})
Updated() []DeltaEntry
}
1 change: 0 additions & 1 deletion lib/trie/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ type DeltaMerger interface {
// DeltaRecorder records deltas done in a ongoing trie operation.
type DeltaRecorder interface {
RecordDeleted(nodeHash common.Hash)
RecordUpdated(key, value []byte)
}
1 change: 0 additions & 1 deletion lib/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ func (t *Trie) Put(keyLE, value []byte) (err error) {
t.handleTrackedDeltas(success, pendingDeltas)
}()

pendingDeltas.RecordUpdated(keyLE, value)
err = t.insertKeyLE(keyLE, value, pendingDeltas)
if err != nil {
return err
Expand Down
10 changes: 0 additions & 10 deletions lib/trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package trie
import (
"bytes"
"encoding/hex"
"fmt"
"reflect"
"testing"

Expand Down Expand Up @@ -4372,12 +4371,3 @@ func Benchmark_concatSlices(b *testing.B) {
}
})
}

func TestTrieDeltaRegisterUpdates(t *testing.T) {
trie := NewEmptyTrie()
trie.Put([]byte("alpha"), make([]byte, 40))
trie.Put([]byte("al"), make([]byte, 40))

fmt.Println("tries deltas updated", trie.deltas.Updated())
fmt.Println("tries deltas deleted", trie.deltas.Deleted())
}

0 comments on commit ae493f2

Please sign in to comment.