Skip to content
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

Merged

Conversation

durkmurder
Copy link
Member

  • 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 {
Copy link
Member Author

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 {
Copy link
Member Author

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.

Copy link
Contributor

@arrivets arrivets left a 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.

@durkmurder
Copy link
Member Author

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) {
Copy link
Member

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

Copy link
Member

@zhangchiqing zhangchiqing left a comment

Choose a reason for hiding this comment

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

LGTM

module/validation/receipt_validator.go Outdated Show resolved Hide resolved
Co-authored-by: Leo Zhang <zhangchiqing@gmail.com>
@zhangchiqing zhangchiqing merged commit 32c47ac into leo/validate-multi-receipts Jan 25, 2021
@zhangchiqing zhangchiqing deleted the yurii/validate-multi-receipts branch January 25, 2021 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants