prysm-pulse/beacon-chain/verification/result.go
kasey 4008ea736f
Verify roblobs (#13245)
* scaffolding for verification package

* WIP blob verification methods

* lock wrapper for safer forkchoice sharing

* more solid cache and verification designs; adding tests

* more test coverage, adding missing cache files

* clearer func name

* remove forkchoice borrower (it's in another PR)

* revert temporary interface experiment

* lint

* nishant feedback

* add comments with spec text to all verifications

* some comments on public methods

* invert confusing verification name

* deep source

* remove cache from ProposerCache + gaz

* more consistently early return on error paths

* messed up the test with the wrong config value

* terence naming feedback

* tests on BeginsAt

* lint

* deep source...

* name errors after failure, not expectation

* deep sooource

* check len()==0 instead of nil so empty lists work

* update test for EIP-7044

---------

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
2023-12-07 02:36:25 +00:00

64 lines
1.5 KiB
Go

package verification
// Requirement represents a validation check that needs to pass in order for a Verified form a consensus type to be issued.
type Requirement int
// results collects positive verification results.
// This bitmap can be used to test which verifications have been successfully completed in order to
// decide whether it is safe to issue a "Verified" type variant.
type results struct {
done map[Requirement]error
reqs []Requirement
}
func newResults(reqs ...Requirement) *results {
return &results{done: make(map[Requirement]error, len(reqs)), reqs: reqs}
}
func (r *results) record(req Requirement, err error) {
r.done[req] = err
}
// allSatisfied returns true if there is a nil error result for every Requirement.
func (r *results) allSatisfied() bool {
if len(r.done) != len(r.reqs) {
return false
}
for i := range r.reqs {
err, ok := r.done[r.reqs[i]]
if !ok || err != nil {
return false
}
}
return true
}
func (r *results) executed(req Requirement) bool {
_, ok := r.done[req]
return ok
}
func (r *results) result(req Requirement) error {
return r.done[req]
}
func (r *results) errors(err error) error {
return newVerificationMultiError(r, err)
}
func (r *results) failures() map[Requirement]error {
fail := make(map[Requirement]error, len(r.done))
for i := range r.reqs {
req := r.reqs[i]
err, ok := r.done[req]
if !ok {
fail[req] = ErrMissingVerification
continue
}
if err != nil {
fail[req] = err
}
}
return fail
}