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
6 changes: 3 additions & 3 deletions x/merkledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func (db *merkleDB) NewView(
return nil, database.ErrClosed
}

newView, err := newView(db, db, changes)
view, err := newView(db, db, changes)
if err != nil {
return nil, err
}
Expand All @@ -788,8 +788,8 @@ func (db *merkleDB) NewView(
db.lock.Lock()
defer db.lock.Unlock()

db.childViews = append(db.childViews, newView)
return newView, nil
db.childViews = append(db.childViews, view)
return view, nil
}

func (db *merkleDB) Has(k []byte) (bool, error) {
Expand Down
4 changes: 2 additions & 2 deletions x/merkledb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,11 +1061,11 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, token
})
}

newView, err := newDB.NewView(context.Background(), ViewChanges{BatchOps: ops})
view, err := newDB.NewView(context.Background(), ViewChanges{BatchOps: ops})
require.NoError(err)

// Check that the root of the view is the same as the root of [db]
newRoot, err := newView.GetMerkleRoot(context.Background())
newRoot, err := view.GetMerkleRoot(context.Background())
require.NoError(err)

dbRoot, err := db.GetMerkleRoot(context.Background())
Expand Down
8 changes: 4 additions & 4 deletions x/merkledb/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func Test_Trie_ViewOnCommitedView(t *testing.T) {

require.NoError(committedTrie.CommitToDB(context.Background()))

newView, err := committedTrie.NewView(
view, err := committedTrie.NewView(
context.Background(),
ViewChanges{
BatchOps: []database.BatchOp{
Expand All @@ -267,7 +267,7 @@ func Test_Trie_ViewOnCommitedView(t *testing.T) {
},
)
require.NoError(err)
require.NoError(newView.CommitToDB(context.Background()))
require.NoError(view.CommitToDB(context.Background()))

val0, err := dbTrie.GetValue(context.Background(), []byte{0})
require.NoError(err)
Expand Down Expand Up @@ -1235,9 +1235,9 @@ func Test_Trie_ConcurrentNewViewAndCommit(t *testing.T) {
require.NoError(newTrie.CommitToDB(context.Background()))
}()

newView, err := newTrie.NewView(context.Background(), ViewChanges{})
view, err := newTrie.NewView(context.Background(), ViewChanges{})
require.NoError(err)
require.NotNil(newView)
require.NotNil(view)
}

// Returns the path of the only child of this node.
Expand Down
22 changes: 11 additions & 11 deletions x/merkledb/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (v *view) NewView(
return nil, err
}

newView, err := newView(v.db, v, changes)
childView, err := newView(v.db, v, changes)
if err != nil {
return nil, err
}
Expand All @@ -132,9 +132,9 @@ func (v *view) NewView(
if v.invalidated {
return nil, ErrInvalid
}
v.childViews = append(v.childViews, newView)
v.childViews = append(v.childViews, childView)

return newView, nil
return childView, nil
}

// Creates a new view with the given [parentTrie].
Expand All @@ -143,7 +143,7 @@ func newView(
parentTrie View,
changes ViewChanges,
) (*view, error) {
newView := &view{
v := &view{
root: maybe.Bind(parentTrie.getRoot(), (*node).clone),
db: db,
parentTrie: parentTrie,
Expand All @@ -164,19 +164,19 @@ func newView(
newVal = maybe.Some(slices.Clone(op.Value))
}
}
if err := newView.recordValueChange(toKey(key), newVal); err != nil {
if err := v.recordValueChange(toKey(key), newVal); err != nil {
return nil, err
}
}
for key, val := range changes.MapOps {
if !changes.ConsumeBytes {
val = maybe.Bind(val, slices.Clone[[]byte])
}
if err := newView.recordValueChange(toKey(stringToByteSlice(key)), val); err != nil {
if err := v.recordValueChange(toKey(stringToByteSlice(key)), val); err != nil {
return nil, err
}
}
return newView, nil
return v, nil
}

// Creates a view of the db at a historical root using the provided [changes].
Expand All @@ -189,7 +189,7 @@ func newViewWithChanges(
return nil, ErrNoChanges
}

newView := &view{
v := &view{
root: changes.rootChange.after,
db: db,
parentTrie: db,
Expand All @@ -198,9 +198,9 @@ func newViewWithChanges(
}
// since this is a set of historical changes, all nodes have already been calculated
// since no new changes have occurred, no new calculations need to be done
newView.calculateNodesOnce.Do(func() {})
newView.nodesAlreadyCalculated.Set(true)
return newView, nil
v.calculateNodesOnce.Do(func() {})
v.nodesAlreadyCalculated.Set(true)
return v, nil
}

func (v *view) getTokenSize() int {
Expand Down