-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Return contexts with correct base keys from views #4983
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
Return contexts with correct base keys from views #4983
Conversation
afck
left a comment
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.
Great catch! Looks good to me, but let's wait for at least one more approval, ideally by someone more familiar with the storage internals.
|
Ideally we'd also have a test proving that this was necessary but maybe that's too complicated to automate? |
I can try. It should be relatively easy to create a dummy view type in a test module that would exhibit this issue. |
6030c6d to
ff114a2
Compare
|
@deuszx I added a test and verified that it was failing before the changes from this PR. |
ma2bd
left a comment
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.
nice catch!
Motivation
The derived implementation of
View::contextcurrently returns just the context of the first sub-view of the view. This means that if a view A has a sub-view B, and view B has a sub-view C, when A callscontext()on B and assumes that its own base key is eg. a byte shorter than what it gets as a result, it will in fact get a context with C's base key, which may lead to wrong results if B also appends some bytes to the base key before passing the context on to C (which happens in hashable wrappers, for example!).Proposal
Make the implementation of
context()in all views correctly trim the base key contained in the context before returning the value.This unfortunately introduces the necessity of cloning the context and returning it by value instead of by reference.
An alternative (but somewhat more complicated) solution would be to require all views to store their inner contexts, and make the
Viewderive macro require acontextfield in all structs for whichViewis derived.Test Plan
CI will catch regressions.
This was also manually confirmed to fix a bug that surfaced in #4977.
Release Plan
Links