diff --git a/internal/trie/node/branch.go b/internal/trie/node/branch.go index 09005d2723..ead394b801 100644 --- a/internal/trie/node/branch.go +++ b/internal/trie/node/branch.go @@ -21,7 +21,7 @@ type Branch struct { // from the node stored in the database. dirty bool hashDigest []byte - Encoding []byte + encoding []byte // generation is incremented on every trie Snapshot() call. // Nodes that are part of the trie are then gradually updated // to have a matching generation number as well, if they are diff --git a/internal/trie/node/branch_encode.go b/internal/trie/node/branch_encode.go index 6520e234be..76700cc567 100644 --- a/internal/trie/node/branch_encode.go +++ b/internal/trie/node/branch_encode.go @@ -76,8 +76,8 @@ func (b *Branch) hash(digestBuffer io.Writer) (err error) { // Encode encodes a branch with the encoding specified at the top of this package // to the buffer given. func (b *Branch) Encode(buffer Buffer) (err error) { - if !b.dirty && b.Encoding != nil { - _, err = buffer.Write(b.Encoding) + if !b.dirty && b.encoding != nil { + _, err = buffer.Write(b.encoding) if err != nil { return fmt.Errorf("cannot write stored encoding to buffer: %w", err) } diff --git a/internal/trie/node/branch_encode_test.go b/internal/trie/node/branch_encode_test.go index 60be03aa18..54504665bf 100644 --- a/internal/trie/node/branch_encode_test.go +++ b/internal/trie/node/branch_encode_test.go @@ -22,7 +22,7 @@ func Test_Branch_Encode(t *testing.T) { }{ "clean branch with encoding": { branch: &Branch{ - Encoding: []byte{1, 2, 3}, + encoding: []byte{1, 2, 3}, }, writes: []writeCall{ { // stored encoding @@ -32,7 +32,7 @@ func Test_Branch_Encode(t *testing.T) { }, "write error for clean branch with encoding": { branch: &Branch{ - Encoding: []byte{1, 2, 3}, + encoding: []byte{1, 2, 3}, }, writes: []writeCall{ { // stored encoding diff --git a/internal/trie/node/copy.go b/internal/trie/node/copy.go index ef5d599eb9..a90be5a680 100644 --- a/internal/trie/node/copy.go +++ b/internal/trie/node/copy.go @@ -14,7 +14,7 @@ func (b *Branch) Copy() Node { Value: nil, dirty: b.dirty, hashDigest: make([]byte, len(b.hashDigest)), - Encoding: make([]byte, len(b.Encoding)), + encoding: make([]byte, len(b.encoding)), generation: b.generation, } copy(cpy.Key, b.Key) @@ -26,7 +26,7 @@ func (b *Branch) Copy() Node { } copy(cpy.hashDigest, b.hashDigest) - copy(cpy.Encoding, b.Encoding) + copy(cpy.encoding, b.encoding) return cpy } @@ -43,12 +43,12 @@ func (l *Leaf) Copy() Node { Value: make([]byte, len(l.Value)), dirty: l.dirty, hashDigest: make([]byte, len(l.hashDigest)), - Encoding: make([]byte, len(l.Encoding)), + encoding: make([]byte, len(l.encoding)), generation: l.generation, } copy(cpy.Key, l.Key) copy(cpy.Value, l.Value) copy(cpy.hashDigest, l.hashDigest) - copy(cpy.Encoding, l.Encoding) + copy(cpy.encoding, l.encoding) return cpy } diff --git a/internal/trie/node/hash.go b/internal/trie/node/hash.go index 5fefe928dd..ac8a584572 100644 --- a/internal/trie/node/hash.go +++ b/internal/trie/node/hash.go @@ -13,7 +13,7 @@ import ( // SetEncodingAndHash sets the encoding and hash slices // given to the branch. Note it does not copy them, so beware. func (b *Branch) SetEncodingAndHash(enc, hash []byte) { - b.Encoding = enc + b.encoding = enc b.hashDigest = hash } @@ -30,8 +30,8 @@ func (b *Branch) GetHash() []byte { // If the encoding is less than 32 bytes, the hash returned // is the encoding and not the hash of the encoding. func (b *Branch) EncodeAndHash() (encoding, hash []byte, err error) { - if !b.dirty && b.Encoding != nil && b.hashDigest != nil { - return b.Encoding, b.hashDigest, nil + if !b.dirty && b.encoding != nil && b.hashDigest != nil { + return b.encoding, b.hashDigest, nil } buffer := pools.EncodingBuffers.Get().(*bytes.Buffer) @@ -45,9 +45,9 @@ func (b *Branch) EncodeAndHash() (encoding, hash []byte, err error) { bufferBytes := buffer.Bytes() - b.Encoding = make([]byte, len(bufferBytes)) - copy(b.Encoding, bufferBytes) - encoding = b.Encoding // no need to copy + b.encoding = make([]byte, len(bufferBytes)) + copy(b.encoding, bufferBytes) + encoding = b.encoding // no need to copy if buffer.Len() < 32 { b.hashDigest = make([]byte, len(bufferBytes)) diff --git a/internal/trie/node/leaf.go b/internal/trie/node/leaf.go index 59202829a9..3aab730cbb 100644 --- a/internal/trie/node/leaf.go +++ b/internal/trie/node/leaf.go @@ -20,7 +20,7 @@ type Leaf struct { // from the node stored in the database. dirty bool hashDigest []byte - Encoding []byte + encoding []byte encodingMu sync.RWMutex // generation is incremented on every trie Snapshot() call. // Nodes that are part of the trie are then gradually updated diff --git a/internal/trie/node/leaf_encode.go b/internal/trie/node/leaf_encode.go index b203d7d9f0..291b45ae40 100644 --- a/internal/trie/node/leaf_encode.go +++ b/internal/trie/node/leaf_encode.go @@ -19,7 +19,7 @@ import ( // given to the branch. Note it does not copy them, so beware. func (l *Leaf) SetEncodingAndHash(enc, hash []byte) { l.encodingMu.Lock() - l.Encoding = enc + l.encoding = enc l.encodingMu.Unlock() l.hashDigest = hash } @@ -38,9 +38,9 @@ func (l *Leaf) GetHash() []byte { // is the encoding and not the hash of the encoding. func (l *Leaf) EncodeAndHash() (encoding, hash []byte, err error) { l.encodingMu.RLock() - if !l.IsDirty() && l.Encoding != nil && l.hashDigest != nil { + if !l.IsDirty() && l.encoding != nil && l.hashDigest != nil { l.encodingMu.RUnlock() - return l.Encoding, l.hashDigest, nil + return l.encoding, l.hashDigest, nil } l.encodingMu.RUnlock() @@ -58,10 +58,10 @@ func (l *Leaf) EncodeAndHash() (encoding, hash []byte, err error) { l.encodingMu.Lock() // TODO remove this copying since it defeats the purpose of `buffer` // and the sync.Pool. - l.Encoding = make([]byte, len(bufferBytes)) - copy(l.Encoding, bufferBytes) + l.encoding = make([]byte, len(bufferBytes)) + copy(l.encoding, bufferBytes) l.encodingMu.Unlock() - encoding = l.Encoding // no need to copy + encoding = l.encoding // no need to copy if len(bufferBytes) < 32 { l.hashDigest = make([]byte, len(bufferBytes)) @@ -87,8 +87,8 @@ func (l *Leaf) EncodeAndHash() (encoding, hash []byte, err error) { // NodeHeader | Extra partial key length | Partial Key | Value func (l *Leaf) Encode(buffer Buffer) (err error) { l.encodingMu.RLock() - if !l.dirty && l.Encoding != nil { - _, err = buffer.Write(l.Encoding) + if !l.dirty && l.encoding != nil { + _, err = buffer.Write(l.encoding) l.encodingMu.RUnlock() if err != nil { return fmt.Errorf("cannot write stored encoding to buffer: %w", err) @@ -122,8 +122,8 @@ func (l *Leaf) Encode(buffer Buffer) (err error) { // and the sync.Pool. l.encodingMu.Lock() defer l.encodingMu.Unlock() - l.Encoding = make([]byte, buffer.Len()) - copy(l.Encoding, buffer.Bytes()) + l.encoding = make([]byte, buffer.Len()) + copy(l.encoding, buffer.Bytes()) return nil } diff --git a/internal/trie/node/leaf_encode_test.go b/internal/trie/node/leaf_encode_test.go index fdac0713c8..61eb78ad9b 100644 --- a/internal/trie/node/leaf_encode_test.go +++ b/internal/trie/node/leaf_encode_test.go @@ -26,7 +26,7 @@ func Test_Leaf_Encode(t *testing.T) { }{ "clean leaf with encoding": { leaf: &Leaf{ - Encoding: []byte{1, 2, 3}, + encoding: []byte{1, 2, 3}, }, writes: []writeCall{ { @@ -37,7 +37,7 @@ func Test_Leaf_Encode(t *testing.T) { }, "write error for clean leaf with encoding": { leaf: &Leaf{ - Encoding: []byte{1, 2, 3}, + encoding: []byte{1, 2, 3}, }, writes: []writeCall{ { @@ -153,7 +153,7 @@ func Test_Leaf_Encode(t *testing.T) { } else { require.NoError(t, err) } - assert.Equal(t, testCase.expectedEncoding, testCase.leaf.Encoding) + assert.Equal(t, testCase.expectedEncoding, testCase.leaf.encoding) }) } } @@ -204,7 +204,7 @@ func Test_Leaf_hash(t *testing.T) { }{ "small leaf buffer write error": { leaf: &Leaf{ - Encoding: []byte{1, 2, 3}, + encoding: []byte{1, 2, 3}, }, writeCall: true, write: writeCall{ @@ -217,7 +217,7 @@ func Test_Leaf_hash(t *testing.T) { }, "small leaf success": { leaf: &Leaf{ - Encoding: []byte{1, 2, 3}, + encoding: []byte{1, 2, 3}, }, writeCall: true, write: writeCall{ @@ -226,7 +226,7 @@ func Test_Leaf_hash(t *testing.T) { }, "leaf hash sum buffer write error": { leaf: &Leaf{ - Encoding: []byte{ + encoding: []byte{ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, @@ -250,7 +250,7 @@ func Test_Leaf_hash(t *testing.T) { }, "leaf hash sum success": { leaf: &Leaf{ - Encoding: []byte{ + encoding: []byte{ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8,