Skip to content
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

merkledb -- dynamic root #2177

Merged
merged 171 commits into from
Dec 14, 2023
Merged

merkledb -- dynamic root #2177

merged 171 commits into from
Dec 14, 2023

Conversation

danlaine
Copy link

@danlaine danlaine commented Oct 17, 2023

Why this should be merged

The root field of a trieView or the database should be the actual root.

How this works

  • root is now a maybe.Maybe[*node] which is Nothing iff the trie is empty.
  • A trie reports an ids.Empty root ID iff the trie is empty.
  • changeSummary now explicitly tracks the rootChange.
  • In trieview the root is now the actual root of the trie.
  • getPathTo may now return an empty path.
  • Prohibit empty proofs.

How this was tested

Update existing and add new UT.

@danlaine danlaine self-assigned this Oct 17, 2023
@danlaine danlaine marked this pull request as ready for review December 1, 2023 22:12
@@ -51,11 +51,11 @@ var (
intermediateNodePrefix = []byte{2}

cleanShutdownKey = []byte(string(metadataPrefix) + "cleanShutdown")
rootDBKey = []byte(string(metadataPrefix) + "root")
Copy link
Contributor

Choose a reason for hiding this comment

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

realized belatedly that you don't actually need this since the root should always be the smallest key present in your nodes db. You should be able to just grab the first key on the iterator, right?

Copy link
Author

Choose a reason for hiding this comment

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

We could do that, but I feel like this is a bit cleaner than having to check both the value and intermediate node databases

Copy link
Contributor

@dboehm-avalabs dboehm-avalabs Dec 13, 2023

Choose a reason for hiding this comment

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

The current code still checks both dbs

Copy link
Contributor

@dboehm-avalabs dboehm-avalabs left a comment

Choose a reason for hiding this comment

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

I still have reservations about this change. This almost doubles the code length of trieview.insert and trieview.remove for almost no functional change. I think the empty trie/proof changes do add something, but those could be separated out.

@@ -249,6 +254,13 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start maybe.Maybe[[]
for i := mostRecentChangeIndex; i > lastRootChangeIndex; i-- {
changes, _ := th.history.Index(i)

if i == mostRecentChangeIndex {
Copy link
Contributor

Choose a reason for hiding this comment

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

should these just be outside the loop?

Copy link
Author

Choose a reason for hiding this comment

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

They could be, but then we'd end up having to get it from th.history again anyway, so I don't think that'd really buy us anything

@danlaine danlaine force-pushed the merkledb-dynamic-root branch from 5a316b7 to 473a264 Compare December 13, 2023 22:24
@danlaine danlaine requested review from abi87 and marun as code owners December 13, 2023 22:24
@danlaine danlaine force-pushed the merkledb-dynamic-root branch from 5023fb8 to 7963a0b Compare December 13, 2023 22:36
@danlaine danlaine merged commit f80cb92 into dev Dec 14, 2023
17 checks passed
@danlaine danlaine deleted the merkledb-dynamic-root branch December 14, 2023 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Status: In Review 👀
Development

Successfully merging this pull request may close these issues.

3 participants