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
[Sealing] Validation of multiple receipts in payload #323
[Sealing] Validation of multiple receipts in payload #323
Conversation
durkmurder
commented
Jan 25, 2021
- Add implementation for looking up receipt in payload
// local storage. This is needed to handle a case when same block payload contains receipts that | ||
// reference each other. | ||
previousResult := func(executionResult *flow.ExecutionResult) (*flow.ExecutionResult, error) { | ||
for _, receipt := range receipts { |
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.
can build a small cache here to perform lookups faster, but the question is if we need it, what is the expected average size of receipts payload?
if err != nil { | ||
return fmt.Errorf("could not validate receipt %v at index %v: %w", r.ID(), i, err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (v *receiptValidator) validate(receipt *flow.ExecutionReceipt) error { | ||
func (v *receiptValidator) validate(receipt *flow.ExecutionReceipt, previousResult GetPreviousResult) error { |
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.
Did it this way to postpone storage lookup till it's needed and not too put validation in loop body.
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.
Looks good but I think you need to update the tests in the matching engine.. some tests related to validating receipts are not passing anymore.
Fixed, thanks. |
// Build a functor that performs lookup first in receipts that were passed as payload and only then in | ||
// local storage. This is needed to handle a case when same block payload contains receipts that | ||
// reference each other. | ||
previousResult := func(executionResult *flow.ExecutionResult) (*flow.ExecutionResult, error) { |
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.
when validating a receipt, we assume the previous result from the same payload is "valid", and so that if this assumption fails, eventually the entire validation will fail.
The solution is simple and elegant, however I'm still not feeling very comfortable about it, even though I couldn't think of case that leads to an incorrect behavior yet
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.
LGTM
Co-authored-by: Leo Zhang <zhangchiqing@gmail.com>