Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Automatic removal of orphan nodes #24

Merged
merged 5 commits into from
Jul 9, 2021
Merged

Conversation

tzdybal
Copy link
Member

@tzdybal tzdybal commented Mar 4, 2021

Work in progress.

TODO:

  • AutoOrphanRemoval option (false by default)
  • configuration mechanism (With(opt Option)?) (variadic arguments in constructor)
  • simple test
  • implement the actual removing of orphans
  • more extensive testing (update/delete operations, tree with multiple entries)

@tzdybal tzdybal force-pushed the tzdybal/remove_orhpans branch from 68aff8b to e270db6 Compare March 16, 2021 20:04
Using variadic arguments is very non-intrusive way to introduce options.
This is very generic, and will allow to implement other options in the
future.
@tzdybal tzdybal force-pushed the tzdybal/remove_orhpans branch from 0f1bea1 to 969532b Compare March 16, 2021 20:29
@musalbas
Copy link
Member

Closing, as superseded by #36 and #37.

@musalbas musalbas closed this Jun 21, 2021
@liamsi

This comment has been minimized.

@musalbas musalbas reopened this Jun 21, 2021
* Implement orphan pruning

* Correct tests comments

sha256(testKey)  = 0001...
sha256(testKey2) = 1000...
sha256(foo)      = 0010...

* Remove redundant checks and copies

no case produces nil sideNodes; nothing modifies the stored hashes

* Refactor value storage

Store values in a separate mapstore indexed by (hash(value)+key);
allows pruning values

Simplify pruning loops slightly as well

* Fix array copy

* Avoid extra key param

* Fix idempotent Set

can short circuit when the same value is already set

* Deprecate past root access, remove prune as option

* Index values by just path

* Cleanup

* Update deepsubtree.go

Co-authored-by: John Adler <[email protected]>

* verifyProofWithUpdates - Fix unused return value

Co-authored-by: John Adler <[email protected]>
@liamsi
Copy link
Member

liamsi commented Jul 9, 2021

Now that #37 was merged in here. Can we actually resolve the merge conflicts, mark this as ready for review, give it a 2nd pass and finally merge it?
@tzdybal @adlerjohn @musalbas

@adlerjohn
Copy link
Member

This should be fully superseded by #37 unless I'm mistaken, so it can be closed @liamsi

@liamsi
Copy link
Member

liamsi commented Jul 9, 2021

This should be fully superseded by #37 unless I'm mistaken, so it can be closed @liamsi

No, #37 builds on the changes here. Hence the changes of #37 were merged into this branch / PR in 763105b

Completes work from #24.
Revises work from #36.

ref: #24 (comment)
ref: #36 (comment)

@liamsi
Copy link
Member

liamsi commented Jul 9, 2021

Resolved the merge conflicts. Happy to help push this over the finish line if necessary!

@adlerjohn adlerjohn marked this pull request as ready for review July 9, 2021 14:02
@adlerjohn adlerjohn requested review from adlerjohn and liamsi July 9, 2021 14:02
@adlerjohn
Copy link
Member

The only difference between the head from #37 and this PR is in smt.go unless I'm mistaken.

diff celestiaorg/smt/smt.go roysc/smt/smt.go

The diff:

305,308d304
< 	// The offset from the bottom of the tree to the start of the side nodes.
< 	// Note: i-offsetOfSideNodes is the index into sideNodes[]
< 	offsetOfSideNodes := smt.depth() - len(sideNodes)
< 
312c308,312
< 		if i-offsetOfSideNodes < 0 || sideNodes[i-offsetOfSideNodes] == nil {
---
> 		// The offset from the bottom of the tree to the start of the side nodes
> 		// i-offsetOfSideNodes is the index into sideNodes[]
> 		offsetOfSideNodes := smt.depth() - len(sideNodes)
> 
> 		if i-offsetOfSideNodes < 0 {

Moving the offset calculation is from #35, so nothing to see there. The only thing of interest is that #37 removes the condition sideNodes[i-offsetOfSideNodes] == nil. That condition should never be hit, since none of the sideNodes will be nil, so shouldn't be a problem to remove. All tests pass in #37, so looks like it's indeed not needed.

Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

Thanks @adlerjohn 👍🏼

@adlerjohn adlerjohn merged commit 03ea407 into master Jul 9, 2021
@adlerjohn adlerjohn deleted the tzdybal/remove_orhpans branch July 9, 2021 23:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants