-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic repo cleanup #43
base: dev/iavl_data_locality
Are you sure you want to change the base?
Conversation
baa713d
to
50c2850
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm. Could we get changelog entries for things
@@ -14,7 +14,7 @@ type ImmutableTree struct { | |||
|
|||
Using the root and the nodeDB, the ImmutableTree can retrieve any node that is a part of the IAVL tree at this version. | |||
|
|||
Users can get information about the IAVL tree by calling getter functions such as `Size()` and `Height()` which will return the tree's size and height by querying the root node's size and height. | |||
Users can get information about the IAVL tree by calling getter functions such as `Size()` and `Height()` which will return the tree's size and depth by querying the root node's size and depth. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users can get information about the IAVL tree by calling getter functions such as `Size()` and `Height()` which will return the tree's size and depth by querying the root node's size and depth. | |
Users can get information about the IAVL tree by calling getter functions such as `Size()` and `Depth()` which will return the tree's size and depth by querying the root node's size and depth. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it actually be depth though? It seems to be returning "subtree height"
@@ -29,13 +30,13 @@ func NewFastNode(key []byte, value []byte, version int64) *FastNode { | |||
|
|||
// DeserializeFastNode constructs an *FastNode from an encoded byte slice. | |||
func DeserializeFastNode(key []byte, buf []byte) (*FastNode, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move the regular Node
to this package as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really feels like they belong together / grouped into the same package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they should, just takes more refactors to get there
import dbm "github.com/tendermint/tm-db" | ||
|
||
// Traverse all keys with a certain prefix. Return error if any, nil otherwise | ||
func IterateThroughAllSubtreeKeys(db dbm.DB, prefix []byte, fn func(k, v []byte) error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a test for this?
return nil | ||
} | ||
|
||
func GatherSubtreeKVPairs(db dbm.DB, prefix []byte) (keys [][]byte, values [][]byte, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere?
if err != nil { | ||
return err | ||
} | ||
_, err = w.Write(bz) | ||
return err | ||
} | ||
|
||
// encodeBytesSlice length-prefixes the byte slice and returns it. | ||
func encodeBytesSlice(bz []byte) ([]byte, error) { | ||
// utils.EncodeBytesSlice length-prefixes the byte slice and returns it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// utils.EncodeBytesSlice length-prefixes the byte slice and returns it. | |
// EncodeBytesSlice length-prefixes the byte slice and returns it. |
if u == 0 { | ||
return 1 | ||
} | ||
return (bits.Len64(u) + 6) / 7 | ||
} | ||
|
||
// encodeVarint writes a varint-encoded integer to an io.Writer. | ||
func encodeVarint(w io.Writer, i int64) error { | ||
// utils.EncodeVarint writes a varint-encoded integer to an io.Writer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// utils.EncodeVarint writes a varint-encoded integer to an io.Writer. | |
// EncodeVarint writes a varint-encoded integer to an io.Writer. |
@@ -144,8 +144,8 @@ func encodeVarint(w io.Writer, i int64) error { | |||
return err | |||
} | |||
|
|||
// encodeVarintSize returns the byte size of the given integer as a varint. | |||
func encodeVarintSize(i int64) int { | |||
// utils.EncodeVarintSize returns the byte size of the given integer as a varint. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// utils.EncodeVarintSize returns the byte size of the given integer as a varint. | |
// EncodeVarintSize returns the byte size of the given integer as a varint. |
// TODO: Make better static guarantee in tree, | ||
// for what nodes exist in deserialized memory, and just not getting extra nodes | ||
// and a clear decision criteria between "no branch node", "new branch with as of yet unknown hash" | ||
func (tree *MutableTree) saveBranch(node *Node) []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this was moved but would be great to eventually cover this with a test
if node.version <= genesisVersion { | ||
tree.ndb.resetBatch() | ||
} | ||
// TODO: This should be deletable? Is it just here for garbage collection purposes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right. We should probably run benchmarks before removing them. Wdyt?
tree.ndb.SaveNode(node) | ||
|
||
// resetBatch only working on generate a genesis block | ||
// TODO: What is this? It should almost certainly be deleted / moved elsewhere. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -109,12 +109,12 @@ func (t *ImmutableTree) Version() int64 { | |||
return t.version | |||
} | |||
|
|||
// Height returns the height of the tree. | |||
// Height returns the depth of the tree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this to SubtreeHeight()
and update the docs? The docs seem to say that this returns depth
This commit does some repository cleanup, at the moment it does:
ndb.roots()
method, that is only used in a test to avoid checking an error lmaoIf you want to review this, it should be reviewed commit by commit