-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix GetAsOf() for commitment , so that it handles dereferencing
#17687
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
Conversation
yperbasis
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.
Please add a test
|
@yperbasis just added some more test cases. The last test case will fetch branch data at blockNum=5 via So the test case tests exactly the scenario in the PR description. |
I see that
Maybe |
awskii
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.
reading from commitment domain required to be done on aggregator or shared domain level - this is lowest possible level where we have access to other domains as well,but here if we read the value, it will contain accounts and storage file pointers and will become error on another level - while unfolding the branch
So what is the change you would like me to make? Even with this if guard not removed, I don't see the read from shared domains happening. As I see it this is a separate issue, I don't see any fallback to shared domains. |
GetAsOf() for commitmentGetAsOf() for commitment , so that it handles dereferencing
| func (at *AggregatorRoTx) GetAsOf(name kv.Domain, k []byte, ts uint64, tx kv.Tx) (v []byte, ok bool, err error) { | ||
| return at.d[name].GetAsOf(k, ts, tx) | ||
| v, ok, err = at.d[name].GetAsOf(k, ts, tx) | ||
| if name == kv.CommitmentDomain && !ok { |
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.
please move !ok as first condition - it just almost slit from me when i started CR
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.
but with !ok && commitmentDomain it looks cleaner. Also you have to make sure [Commitment].GetAsOf returns nil, false right before domain reading with proper comment about branch plain keys dereferencing bad reads protection.
Currently this fix wount work - OK=true in case of successful reading from commtiment domain - value will contain references and this fallback will not take place
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 thought the theory was that that when [Commitment].GetAsOf() returns nil, false then we fall back to func (at *AggregatorRoTx) GetLatest() . I already put back this code in DomainRoTx.GetAsOf() :
if dt.name == kv.CommitmentDomain {
// we need to dereference commitment keys to get actual value. DomainRoTx itself does not have
// pointers to storage and account domains to do the reference. Aggregator tx must be called instead
return nil, false, nil
}Are you saying that if Commitment].GetAsOf() returns ok = true from history, that still needs special handling???
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.
yes indeed that was introduced way ago 0774823
no problem then
| func (at *AggregatorRoTx) GetAsOf(name kv.Domain, k []byte, ts uint64, tx kv.Tx) (v []byte, ok bool, err error) { | ||
| return at.d[name].GetAsOf(k, ts, tx) | ||
| v, ok, err = at.d[name].GetAsOf(k, ts, tx) | ||
| if name == kv.CommitmentDomain && !ok { |
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.
but with !ok && commitmentDomain it looks cleaner. Also you have to make sure [Commitment].GetAsOf returns nil, false right before domain reading with proper comment about branch plain keys dereferencing bad reads protection.
Currently this fix wount work - OK=true in case of successful reading from commtiment domain - value will contain references and this fallback will not take place
| func (at *AggregatorRoTx) GetAsOf(name kv.Domain, k []byte, ts uint64, tx kv.Tx) (v []byte, ok bool, err error) { | ||
| return at.d[name].GetAsOf(k, ts, tx) | ||
| v, ok, err = at.d[name].GetAsOf(k, ts, tx) | ||
| if name == kv.CommitmentDomain && !ok { |
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.
yes indeed that was introduced way ago 0774823
no problem then
…7687) Fixes #17488, and is a prerequisite for fixing: #17561 In `GetAsOf()` if a value is not found in history, `DomainRoTx.GetLatest()` is called. However, for commitment domain `AggregatorRoTx.GetLatest()` needs to be called instead, which handles foreign key dereferencing (account and storage offsets). --------- Co-authored-by: antonis19 <[email protected]>


Fixes #17488, and is a prerequisite for fixing:
#17561
In
GetAsOf()if a value is not found in history,DomainRoTx.GetLatest()is called. However, for commitment domainAggregatorRoTx.GetLatest()needs to be called instead, which handles foreign key dereferencing (account and storage offsets).