prysm-pulse/beacon-chain/state/stategen/cacher.go
Radosław Kapka 5d94030b4f
Cleanup of stategen package (#10607)
* powchain and stategen

* revert powchain changes

* rename field to blockRootsOfSavedStates

* rename params to blockRoot

* review feedback

* fix loop

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2022-05-09 22:25:47 +00:00

33 lines
635 B
Go

package stategen
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
)
var ErrNotInCache = errors.New("state not found in cache")
type CachedGetter interface {
ByBlockRoot([32]byte) (state.BeaconState, error)
}
type CombinedCache struct {
getters []CachedGetter
}
func (c CombinedCache) ByBlockRoot(r [32]byte) (state.BeaconState, error) {
for _, getter := range c.getters {
st, err := getter.ByBlockRoot(r)
if err == nil {
return st, nil
}
if errors.Is(err, ErrNotInCache) {
continue
}
return nil, err
}
return nil, ErrNotInCache
}
var _ CachedGetter = &CombinedCache{}