mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
d17996f8b0
* Update V3 from V4 * Fix build v3 -> v4 * Update ssz * Update beacon_chain.pb.go * Fix formatter import * Update update-mockgen.sh comment to v4 * Fix conflicts. Pass build and tests * Fix test
33 lines
638 B
Go
33 lines
638 B
Go
package stategen
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v4/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{}
|