Skip to content

Basic repo cleanup#43

Open
ValarDragon wants to merge 19 commits intodev/iavl_data_localityfrom
dev/repo_cleanup
Open

Basic repo cleanup#43
ValarDragon wants to merge 19 commits intodev/iavl_data_localityfrom
dev/repo_cleanup

Conversation

@ValarDragon
Copy link
Copy Markdown
Member

@ValarDragon ValarDragon commented Aug 20, 2022

This commit does some repository cleanup, at the moment it does:

  • Moves key format logic to its own package
  • Moves key format instantiation to its own file
  • Makes methods for getting key bytes no longer defined off nodeDB, and put it into their own file
  • Move various utils functions to a utils package
  • Deletes repair.go
  • Deletes useless ndb.roots() method, that is only used in a test to avoid checking an error lmao
  • Make an encoding package
  • Move tree-methods off of the node, to instead be defined on the tree
  • Move fast node to its own package
  • Rename node.height -> node.subtreeHeight
  • move ndb.SaveBranch to instead be tree.saveBranch which just calls a nodeDB.saveNode function.
  • Make an interface for DRY'ing the node save function with fast node save

If you want to review this, it should be reviewed commit by commit

@ValarDragon ValarDragon changed the title Some minimal repo cleanup Basic repo cleanup Aug 20, 2022
Copy link
Copy Markdown
Collaborator

@tac0turtle tac0turtle left a 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

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Member

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) {
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

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 {
Copy link
Copy Markdown
Member

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?


// 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// utils.EncodeBytesSlice length-prefixes the byte slice and returns it.
// EncodeBytesSlice length-prefixes the byte slice and returns it.


// 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// utils.EncodeVarint writes a varint-encoded integer to an io.Writer.
// EncodeVarint writes a varint-encoded integer to an io.Writer.


// 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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 {
Copy link
Copy Markdown
Member

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?
Copy link
Copy Markdown
Member

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

}

// Height returns the height of the tree.
// Height returns the depth of the tree.
Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants