forked from onflow/flow-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request onflow#5211 from onflow/alex/receipt-validator_err…
…or-handling receipt validator error handling
- Loading branch information
Showing
19 changed files
with
769 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package module | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// UnknownBlockError indicates that a referenced block is missing | ||
type UnknownBlockError struct { | ||
err error | ||
} | ||
|
||
func NewUnknownBlockError(msg string, args ...interface{}) error { | ||
return UnknownBlockError{ | ||
err: fmt.Errorf(msg, args...), | ||
} | ||
} | ||
|
||
func (e UnknownBlockError) Unwrap() error { | ||
return e.err | ||
} | ||
|
||
func (e UnknownBlockError) Error() string { | ||
return e.err.Error() | ||
} | ||
|
||
func IsUnknownBlockError(err error) bool { | ||
var unknownExecutedBlockError UnknownBlockError | ||
return errors.As(err, &unknownExecutedBlockError) | ||
} | ||
|
||
// UnknownResultError indicates that a referenced result is missing | ||
type UnknownResultError struct { | ||
err error | ||
} | ||
|
||
func NewUnknownResultError(msg string, args ...interface{}) error { | ||
return UnknownResultError{ | ||
err: fmt.Errorf(msg, args...), | ||
} | ||
} | ||
|
||
func (e UnknownResultError) Unwrap() error { | ||
return e.err | ||
} | ||
|
||
func (e UnknownResultError) Error() string { | ||
return e.err.Error() | ||
} | ||
|
||
func IsUnknownResultError(err error) bool { | ||
var unknownParentResultError UnknownResultError | ||
return errors.As(err, &unknownParentResultError) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,51 @@ | ||
package module | ||
|
||
import "github.com/onflow/flow-go/model/flow" | ||
import ( | ||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
// ReceiptValidator is an interface which is used for validating | ||
// receipts with respect to current protocol state. | ||
type ReceiptValidator interface { | ||
|
||
// Validate verifies that the ExecutionReceipt satisfies | ||
// the following conditions: | ||
// * is from Execution node with positive weight | ||
// * has valid signature | ||
// * chunks are in correct format | ||
// * execution result has a valid parent and satisfies the subgraph check | ||
// Returns nil if all checks passed successfully. | ||
// Validate verifies that the ExecutionReceipt satisfies the following conditions: | ||
// - is from Execution node with positive weight | ||
// - has valid signature | ||
// - chunks are in correct format | ||
// - execution result has a valid parent and satisfies the subgraph check | ||
// | ||
// In order to validate a receipt, both the executed block and the parent result | ||
// referenced in `receipt.ExecutionResult` must be known. We return nil if all checks | ||
// pass successfully. | ||
// | ||
// Expected errors during normal operations: | ||
// * engine.InvalidInputError | ||
// if receipt violates protocol condition | ||
// * engine.UnverifiableInputError | ||
// if receipt's parent result is unknown | ||
Validate(receipts *flow.ExecutionReceipt) error | ||
// - engine.InvalidInputError if receipt violates protocol condition | ||
// - module.UnknownResultError if the receipt's parent result is unknown | ||
// - module.UnknownBlockError if the executed block is unknown | ||
// | ||
// All other error are potential symptoms critical internal failures, such as bugs or state corruption. | ||
Validate(receipt *flow.ExecutionReceipt) error | ||
|
||
// ValidatePayload verifies the ExecutionReceipts and ExecutionResults | ||
// in the payload for compliance with the protocol: | ||
// Receipts: | ||
// * are from Execution node with positive weight | ||
// * have valid signature | ||
// * chunks are in correct format | ||
// * no duplicates in fork | ||
// - are from Execution node with positive weight | ||
// - have valid signature | ||
// - chunks are in correct format | ||
// - no duplicates in fork | ||
// | ||
// Results: | ||
// * have valid parents and satisfy the subgraph check | ||
// * extend the execution tree, where the tree root is the latest | ||
// finalized block and only results from this fork are included | ||
// * no duplicates in fork | ||
// - have valid parents and satisfy the subgraph check | ||
// - extend the execution tree, where the tree root is the latest | ||
// finalized block and only results from this fork are included | ||
// - no duplicates in fork | ||
// | ||
// Expected errors during normal operations: | ||
// * engine.InvalidInputError | ||
// if some receipts in the candidate block violate protocol condition | ||
// * engine.UnverifiableInputError | ||
// if for some of the receipts, their respective parent result is unknown | ||
// - engine.InvalidInputError if some receipts in the candidate block violate protocol condition | ||
// - module.UnknownBlockError if the candidate block's _parent_ is unknown | ||
// | ||
// All other error are potential symptoms critical internal failures, such as bugs or state corruption. | ||
// Note that module.UnknownResultError is not possible; we have either an invalid candidate block | ||
// (yields engine.InvalidInputError) or a missing parent block (yields module.UnknownBlockError). | ||
ValidatePayload(candidate *flow.Block) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.