Skip to content

Conversation

dboehm-avalabs
Copy link
Contributor

There have been several bugs related to the nil key being confused for no end bound. By converting the end bounds to Maybe[T], it will be more explicit in the code which bound is meant (nil key vs no bound)

rangeProof, err := db.GetRangeProofAtRoot(context.Background(), root, step.key, step.value, 100)
require.NoError(err)
end := Nothing[[]byte]()
if len(step.value) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we update the comments on the randStep struct to mention value/key are used differently for getting range/change proofs?


if err := db.VerifyChangeProof(ctx, &changeProof, req.StartKey, req.EndKey, endRoot); err != nil {
endKey := merkledb.Nothing[[]byte]()
if req.EndKey != nil && !req.EndKey.IsNothing {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand if we have a valid representation where req.EndKey can be nil, why do we need an explicit IsNothing?

Copy link
Contributor Author

@dboehm-avalabs dboehm-avalabs Aug 2, 2023

Choose a reason for hiding this comment

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

quirk of proto, ideally that shouldnt be possible, but I need to figure out if it is possible to enforce. If it were just a []byte, then it wouldn't be clear when it was nothing vs nil

Copy link
Contributor

Choose a reason for hiding this comment

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

We can keep the existing semantics for now and possibly avoid the IsNothing bool field in a separate PR

// TODO there's probably a better way to do this.
var errString string
if err := s.db.VerifyChangeProof(ctx, &proof, req.StartKey, req.EndKey, rootID); err != nil {
if err := s.db.VerifyChangeProof(ctx, &proof, req.StartKey, merkledb.Some(req.EndKey), rootID); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we always pass Some here? (shouldn't nil value map to Nothing?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This just hasn't been updated yet to support Maybes yet.

m.config.Log.Info("completed range",
zap.Binary("start", work.start),
zap.Binary("end", largestHandledKey),
zap.Binary("end", largestHandledKey.Value()),
Copy link

Choose a reason for hiding this comment

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

+1 for String()

proof.StartProof,
insertChildrenLessThan,
insertChildrenGreaterThan,
Some(smallestPath),
Copy link

Choose a reason for hiding this comment

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

Why do we now always pass in Some instead of passing in Nothing when len(smallestPath) == 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

functionally makes no difference, since nil is the smallest possible key, it is equivalent to no bounds.

proof.EndProof,
insertChildrenLessThan,
insertChildrenGreaterThan,
Some(smallestPath),
Copy link

Choose a reason for hiding this comment

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

Why do we now always pass in Some instead of passing in Nothing when len(smallestPath) == 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

functionally makes no difference, since nil is the smallest possible key, it is equivalent to no bounds.

proof *ChangeProof,
start []byte,
end []byte,
end Maybe[[]byte],
Copy link

Choose a reason for hiding this comment

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

Should we also use end Maybe[[]byte] in GetChangeProof above and GetRangeProofAtRoot below for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Part 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants