diff --git a/internal/primitives/state-machine/in_memory_backend.go b/internal/primitives/state-machine/in_memory_backend.go index 6e6b675894..87536c8530 100644 --- a/internal/primitives/state-machine/in_memory_backend.go +++ b/internal/primitives/state-machine/in_memory_backend.go @@ -14,7 +14,7 @@ type MemoryDBTrieBackend[H runtime.Hash, Hasher runtime.Hasher[H]] struct { *TrieBackend[H, Hasher] } -// / Create a new empty instance of in-memory backend. +// Create a new empty instance of in-memory backend. func NewMemoryDBTrieBackend[H runtime.Hash, Hasher runtime.Hasher[H]]() MemoryDBTrieBackend[H, Hasher] { mdb := trie.NewPrefixedMemoryDB[H, Hasher]() root := (*new(Hasher)).Hash([]byte{0}) diff --git a/pkg/trie/triedb/cache.go b/pkg/trie/triedb/cache.go index a690662caa..d48553eea4 100644 --- a/pkg/trie/triedb/cache.go +++ b/pkg/trie/triedb/cache.go @@ -70,7 +70,7 @@ type CachedNodeHandleTypes[H hash.Hash] interface { // Cached version of [codec.MerkleValue]. type CachedNodeHandle interface { - /// Returns [CachedNodeHandle] as a [ChildReference]. + // Returns [CachedNodeHandle] as a [ChildReference]. ChildReference() ChildReference } diff --git a/pkg/trie/triedb/iterator.go b/pkg/trie/triedb/iterator.go index 8389e65f7e..9c0471bd83 100644 --- a/pkg/trie/triedb/iterator.go +++ b/pkg/trie/triedb/iterator.go @@ -468,9 +468,9 @@ func (ri *TrieDBRawIterator[H, Hasher]) NextItem() (*TrieItem, error) { } } -// / Fetches the next key. -// / -// / Must be called with the same `db` as when the iterator was created. +// Fetches the next key. +// +// Must be called with the same `db` as when the iterator was created. func (ri *TrieDBRawIterator[H, Hasher]) NextKey() ([]byte, error) { for { rawItem, err := ri.nextRawItem(true) @@ -499,20 +499,20 @@ type TrieItem struct { Value []byte } -// / A trie iterator that also supports random access (`seek()`). +// A trie iterator that also supports random access (`seek()`). type TrieIterator[H hash.Hash, Item any] interface { Seek(key []byte) error Next() (Item, error) // Items() iter.Seq2[Item, error] } -// / Iterator for going through all values in the trie in pre-order traversal order. +// Iterator for going through all values in the trie in pre-order traversal order. type TrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]] struct { db *TrieDB[H, Hasher] rawIter TrieDBRawIterator[H, Hasher] } -// / Create a new iterator. +// Create a new iterator. func NewTrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]]( db *TrieDB[H, Hasher], ) (*TrieDBIterator[H, Hasher], error) { @@ -526,7 +526,7 @@ func NewTrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]]( }, nil } -// / Create a new iterator, but limited to a given prefix. +// Create a new iterator, but limited to a given prefix. func NewPrefixedTrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]]( db *TrieDB[H, Hasher], prefix []byte, ) (*TrieDBIterator[H, Hasher], error) { @@ -540,9 +540,9 @@ func NewPrefixedTrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]]( }, nil } -// / Create a new iterator, but limited to a given prefix. -// / It then do a seek operation from prefixed context (using `seek` lose -// / prefix context by default). +// Create a new iterator, but limited to a given prefix. +// It then do a seek operation from prefixed context (using `seek` lose +// prefix context by default). func NewPrefixedTrieDBIteratorThenSeek[H hash.Hash, Hasher hash.Hasher[H]]( db *TrieDB[H, Hasher], prefix []byte, startAt []byte, ) (*TrieDBIterator[H, Hasher], error) { @@ -582,12 +582,12 @@ func (tdbi *TrieDBIterator[H, Hasher]) Items() iter.Seq2[TrieItem, error] { } } -// / Iterator for going through all of key with values in the trie in pre-order traversal order. +// Iterator for going through all of key with values in the trie in pre-order traversal order. type TrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]] struct { rawIter TrieDBRawIterator[H, Hasher] } -// / Create a new iterator. +// Create a new iterator. func NewTrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]]( db *TrieDB[H, Hasher], ) (*TrieDBKeyIterator[H, Hasher], error) { @@ -600,7 +600,7 @@ func NewTrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]]( }, nil } -// / Create a new iterator, but limited to a given prefix. +// Create a new iterator, but limited to a given prefix. func NewPrefixedTrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]]( db *TrieDB[H, Hasher], prefix []byte, ) (*TrieDBKeyIterator[H, Hasher], error) { @@ -613,9 +613,9 @@ func NewPrefixedTrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]]( }, nil } -// / Create a new iterator, but limited to a given prefix. -// / It then do a seek operation from prefixed context (using `seek` lose -// / prefix context by default). +// Create a new iterator, but limited to a given prefix. +// It then do a seek operation from prefixed context (using `seek` lose +// prefix context by default). func NewPrefixedTrieDBKeyIteratorThenSeek[H hash.Hash, Hasher hash.Hasher[H]]( db *TrieDB[H, Hasher], prefix []byte, startAt []byte, ) (*TrieDBKeyIterator[H, Hasher], error) { diff --git a/pkg/trie/triedb/lookup.go b/pkg/trie/triedb/lookup.go index 70bf8d042f..f6577e2048 100644 --- a/pkg/trie/triedb/lookup.go +++ b/pkg/trie/triedb/lookup.go @@ -57,12 +57,12 @@ func (l *TrieLookup[H, Hasher, QueryItem]) recordAccess(access TrieAccess) { } } -// / Look up the merkle value (hash) of the node that is the closest descendant for the provided -// / key. -// / -// / When the provided key leads to a node, then the merkle value (hash) of that node -// / is returned. However, if the key does not lead to a node, then the merkle value -// / of the closest descendant is returned. `None` if no such descendant exists. +// Look up the merkle value (hash) of the node that is the closest descendant for the provided +// key. +// +// When the provided key leads to a node, then the merkle value (hash) of that node +// is returned. However, if the key does not lead to a node, then the merkle value +// of the closest descendant is returned. `None` if no such descendant exists. func (l *TrieLookup[H, Hasher, QueryItem]) LookupFirstDescendant( fullKey []byte, nibbleKey nibbles.Nibbles, ) (MerkleValue[H], error) { diff --git a/pkg/trie/triedb/nibbles/nibbleslice.go b/pkg/trie/triedb/nibbles/nibbleslice.go index e9f6e12603..a52e944527 100644 --- a/pkg/trie/triedb/nibbles/nibbleslice.go +++ b/pkg/trie/triedb/nibbles/nibbleslice.go @@ -68,7 +68,7 @@ func (n *NibbleSlice) Pop() *uint8 { return &popped } -// / Append another [NibbleSlice]. Can be slow (alignment of second slice). +// Append another [NibbleSlice]. Can be slow (alignment of second slice). func (n *NibbleSlice) Append(v NibbleSlice) { if v.len == 0 { return diff --git a/pkg/trie/triedb/node_storage.go b/pkg/trie/triedb/node_storage.go index 933d825945..0fe9edaae7 100644 --- a/pkg/trie/triedb/node_storage.go +++ b/pkg/trie/triedb/node_storage.go @@ -11,7 +11,7 @@ import ( var EmptyNode = []byte{0} -// StorageHandle is a pointer to a node contained in `NodeStorage` +// StorageHandle is a pointer to a node contained in nodeStorage type storageHandle int // NodeHandle is an enum for the different types of nodes that can be stored in diff --git a/pkg/trie/triedb/triedb.go b/pkg/trie/triedb/triedb.go index a95c5e582b..11722730dc 100644 --- a/pkg/trie/triedb/triedb.go +++ b/pkg/trie/triedb/triedb.go @@ -283,7 +283,7 @@ func (t *TrieDB[H, Hasher]) Set(key, value []byte) error { } // insertAt inserts the given key / value pair into the node referenced by the -// node handle `handle` +// node handle func (t *TrieDB[H, Hasher]) insertAt( handle NodeHandle, keyNibbles *nibbles.Nibbles, @@ -359,7 +359,7 @@ type inspectResult struct { changed bool } -// inspect inspects the given node `stored` and calls the `inspector` function +// inspect inspects the given node stored and calls the inspector function // then returns the new node and a boolean indicating if the node has changed func (t *TrieDB[H, Hasher]) inspect( stored StoredNode, @@ -536,7 +536,7 @@ func combineKey(start nodeKey, end nodeKey) nodeKey { return start } -// removeInspector removes the key node from the given node `stored` +// removeInspector removes the key node from the given node stored func (t *TrieDB[H, Hasher]) removeInspector( stored Node, keyNibbles *nibbles.Nibbles, oldValue *nodeValue, ) (action, error) { @@ -624,7 +624,7 @@ func (t *TrieDB[H, Hasher]) removeInspector( } } -// insertInspector inserts the new key / value pair into the given node `stored` +// insertInspector inserts the new key / value pair into the given node stored func (t *TrieDB[H, Hasher]) insertInspector( stored Node, keyNibbles *nibbles.Nibbles, value []byte, oldValue *nodeValue, ) (action, error) { @@ -833,7 +833,7 @@ func (t *TrieDB[H, Hasher]) lookupNode(hash H, key nibbles.Prefix) (storageHandl return newNodeFromEncoded[H](hash, encodedNode, &t.storage) } - // We only check the `cache` for a node with `get_node` and don't insert + // We only check the cache for a node with GetNode and don't insert // the node if it wasn't there, because in substrate we only access the node while computing // a new trie (aka some branch). We assume that this node isn't that important // to have it being cached. @@ -1171,23 +1171,23 @@ type MerkleValues[H any] interface { MerkleValue[H] } -// / Either the `hash` or `value` of a node depending on its size. -// / -// / If the size of the node `value` is bigger or equal than `MAX_INLINE_VALUE` the `hash` is -// / returned. +// Either the hash or value of a node depending on its size. +// +// If the size of the node value is bigger or equal than 32 bytes the hash is +// returned. type MerkleValue[H any] interface { isMerkleValue() } -// / The merkle value is the node data itself when the -// / node data is smaller than `MAX_INLINE_VALUE`. -// / -// / Note: The case of inline nodes. +// The merkle value is the node data itself when the +// node data byte length is less than or equal to 32 bytes. +// +// Note: The case of inline nodes. type NodeMerkleValue []byte func (NodeMerkleValue) isMerkleValue() {} -// / The merkle value is the hash of the node. +// The merkle value is the hash of the node. type HashMerkleValue[H any] struct { Hash H } diff --git a/pkg/trie/triedb/triedb_test.go b/pkg/trie/triedb/triedb_test.go index fef2590a79..2a027ce8a0 100644 --- a/pkg/trie/triedb/triedb_test.go +++ b/pkg/trie/triedb/triedb_test.go @@ -617,7 +617,7 @@ func TestDBCommits(t *testing.T) { err = trie.commit() assert.NoError(t, err) - // // 1 leaf + // 1 leaf assert.Len(t, inmemoryDB.Keys(), 1) // Get values using lazy loading @@ -639,7 +639,7 @@ func TestDBCommits(t *testing.T) { err = trie.commit() assert.NoError(t, err) - // // 1 branch with its inlined leaf + // 1 branch with its inlined leaf assert.Len(t, inmemoryDB.Keys(), 1) // Get values using lazy loading @@ -663,8 +663,8 @@ func TestDBCommits(t *testing.T) { err = tr.commit() assert.NoError(t, err) - // // 1 branch with 1 hashed leaf child - // // 1 hashed leaf + // 1 branch with 1 hashed leaf child + // 1 hashed leaf assert.Len(t, inmemoryDB.Keys(), 2) // Get values using lazy loading