-
Notifications
You must be signed in to change notification settings - Fork 25
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
Refactor cleanChild() #57
Refactor cleanChild() #57
Conversation
I would recommend fuzz testing this as well (generate random trees, add and remove a mapping and check the root cid hasn't changed). We found that useful after @rvagg pointed out the same problem in our champ implementation in Peergos. |
1308362
to
01a1eaf
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.
I'm leaving a couple of blobs of notes that I made as I both reviewed this and wandered around the codebase at large -- so if they're not topical to you, just mark 'em resolved. :)
Love the very explicit way the TestFillAndCollapse
function steps through things. It talks its way through a lot of the scenarios I felt I was still looking for as I took stock of the other existing tests.
e96eff7
to
853bd9c
Compare
853bd9c
to
18c8cac
Compare
rebased to master and autosquashed |
18c8cac
to
faf6c31
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.
I don't know why I balked on giving this a thumbs-up earlier, but looking at it more, the tests again look pretty comprehensive, so it seems likely that this is pretty solid.
Closes: https://github.com/ipfs/go-hamt-ipld/issues/56
I've tried to push
cleanChild()
around in the various ways I was suspecting it might be flawed, but couldn't make it misbehave, so I'm going to call it good. Added more testing for CHAMP compaction along with aprintHamt()
that can show you the kinds of shapes you have.(edit: note that the below examples are using identity hash with a bitWidth of 8 so each character is treated as an index at one level, so
AAA1
andAAA2
collide for 3 levels, it's a useful way to force perverse structures without having to deal with the annoying randomness of a hash function).So in this test we do things like:
overflows when we add another colliding element to:
and then back again.
It also tests a mid-way state where collisions happen at half that tree height with a collection of elements that collide in another way:
and rolls that back out to see if it behaves properly. And it does.
I've refactored
cleanChild()
to a state that I think has more clarity about the various states it can be in and reasons it has to take action or not. I think this more closely matches the CHAMP semantics if you want to read the paper and see those semantics in this code. Maybe that's subjective, but I think I've reduced the number of branches here which should in itself clear up some confusion.