forked from cosmos/iavl
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fast Cache - Downgrade - reupgrade protection and other improvements (#…
…12) * add leaf hash to fast node and unit test * refactor get with index and get by index, fix migration in load version and lazy load version * use Get in GetVersioned of mutable tree * refactor non membership proof to use fast storage if available * bench non-membership proof * fix bench tests to work with the new changes * add downgrade-reupgrade protection and unit test * remove leaf hash from fast node * resolve multithreading bug related to iterators not being closed * clean up * use correct tree in bench tests * add cache to tree used to bench non membership proofs * add benc tests for GetWithIndex and GetByIndex * revert GetWithIndex and GetByIndex * remove unused import * unit test re-upgrade protection and fix small issues * remove redundant setStorageVersion method * fix bug with appending to live stage version to storage version and nit test * add comment for setFastStorageVersionToBatch * refactor and improve unit tests for reupgrade protection * rename ndb's isFastStorageEnabled to hasUpgradedToFastStorage and add comments * comment out new implementation for GetNonMembershipProof * update comments in nodedb to reflect the difference between hasUpgradedToFastStorage and shouldForceFastStorageUpdate * refactor nodedb tests * downgrade tendermint to 0.34.14 - osmosis's latest cosmos sdk does not support 0.35.0 * fix bug where fast storage was not enabled when version 0 was attempted to be loaded * implement unsaved fast iterator to be used in mutable tree (#16)
- Loading branch information
Showing
19 changed files
with
1,300 additions
and
976 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package iavl | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFastNode_encodedSize(t *testing.T) { | ||
fastNode := &FastNode{ | ||
key: randBytes(10), | ||
versionLastUpdatedAt: 1, | ||
value: randBytes(20), | ||
} | ||
|
||
expectedSize := 1 + len(fastNode.value) + 1 | ||
|
||
require.Equal(t, expectedSize, fastNode.encodedSize()) | ||
} | ||
|
||
func TestFastNode_encode_decode(t *testing.T) { | ||
testcases := map[string]struct { | ||
node *FastNode | ||
expectHex string | ||
expectError bool | ||
}{ | ||
"nil": {nil, "", true}, | ||
"empty": {&FastNode{}, "0000", false}, | ||
"inner": {&FastNode{ | ||
key: []byte{0x4}, | ||
versionLastUpdatedAt: 1, | ||
value: []byte{0x2}, | ||
}, "020102", false}, | ||
} | ||
for name, tc := range testcases { | ||
tc := tc | ||
t.Run(name, func(t *testing.T) { | ||
var buf bytes.Buffer | ||
err := tc.node.writeBytes(&buf) | ||
if tc.expectError { | ||
require.Error(t, err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
require.Equal(t, tc.expectHex, hex.EncodeToString(buf.Bytes())) | ||
|
||
node, err := DeserializeFastNode(tc.node.key, buf.Bytes()) | ||
require.NoError(t, err) | ||
// since value and leafHash are always decoded to []byte{} we augment the expected struct here | ||
if tc.node.value == nil { | ||
tc.node.value = []byte{} | ||
} | ||
require.Equal(t, tc.node, node) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.