-
Notifications
You must be signed in to change notification settings - Fork 721
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 Compact Path Bytes #2010
Conversation
This reverts commit 79684fa.
This reverts commit 9b8a7ac.
Co-authored-by: Dan Laine <[email protected]> Signed-off-by: David Boehm <[email protected]>
@@ -944,7 +959,7 @@ func (db *merkleDB) VerifyChangeProof( | |||
} | |||
|
|||
// Note that if [start] is Nothing, smallestPath is the empty path. |
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.
This comment seems out of date now
// check that the tokens in the partially filled final byte of [prefix] are | ||
// equal to the tokens in the final byte of [p]. | ||
for i := prefix.tokensLength - remainderTokens; i < prefix.tokensLength; i++ { | ||
if p.Token(i) != prefix.Token(i) { | ||
return false | ||
} | ||
} |
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 feel like we should be able to do some masking here rather than explicitly checking each token
bytesNeeded := tokens / p.tokensPerByte | ||
if tokens%p.tokensPerByte > 0 { | ||
bytesNeeded++ | ||
} | ||
return bytesNeeded |
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.
return (tokens + p.tokensPerByte - 1) / p.tokensPerByte
func shiftCopy(dst []byte, src string, shift byte) { | ||
i := 0 | ||
for ; i < len(src)-1; i++ { | ||
dst[i] = src[i]<<shift + src[i+1]>>(8-shift) |
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'd probably have written this as:
dst[i] = src[i]<<shift | src[i+1]>>(8-shift)
// We want to zero out everything to the right of the last token, which is at index [tokensToTake] - 1 | ||
// Mask will be (8-bitsToShift) number of 1's followed by (bitsToShift) number of 0's | ||
mask := byte(0xFF << p.bitsToShift(tokensToTake-1)) | ||
buffer[len(buffer)-1] = buffer[len(buffer)-1] & mask |
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.
buffer[len(buffer)-1] &= mask
bytesKey := stringToByteSlice(key) | ||
if !changes.ConsumeBytes { | ||
bytesKey = slices.Clone(bytesKey) | ||
} |
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.
Either this doesn't feel needed - or this always feels needed... Either way I feel like something is weird here
if !changes.ConsumeBytes { | ||
key = slices.Clone(op.Key) | ||
} |
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.
Super nit - but the order of var declaration + updating seems really weird here
We wish to support merkle trie branch factors other than 16, so this PR attempts to change paths to support that. At the same time, it reworks them to be stored in compressed format so that they don't have to be converted back and forth when interacting with the database.