mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
17a43c1158
* new stategen.StateReplayer/ReplayerBuilder to give more fine-grained control of replaying state+block history * all rpc/api methods updated to use the new interface, return post-state Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
33 lines
626 B
Go
33 lines
626 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 {
|
|
ByRoot([32]byte) (state.BeaconState, error)
|
|
}
|
|
|
|
type CombinedCache struct {
|
|
getters []CachedGetter
|
|
}
|
|
|
|
func (c CombinedCache) ByRoot(root [32]byte) (state.BeaconState, error) {
|
|
for _, getter := range c.getters {
|
|
st, err := getter.ByRoot(root)
|
|
if err == nil {
|
|
return st, nil
|
|
}
|
|
if errors.Is(err, ErrNotInCache) {
|
|
continue
|
|
}
|
|
return nil, err
|
|
}
|
|
return nil, ErrNotInCache
|
|
}
|
|
|
|
var _ CachedGetter = &CombinedCache{}
|