Documentation ¶
Overview ¶
Package stategen defines functions to regenerate beacon chain states by replaying blocks from a stored state checkpoint, useful for optimization and reducing a beacon node's resource consumption.
Index ¶
- type State
- func (s *State) ComputeStateUpToSlot(ctx context.Context, targetSlot uint64) (*state.BeaconState, error)
- func (s *State) ForceCheckpoint(ctx context.Context, root []byte) error
- func (s *State) HasState(ctx context.Context, blockRoot [32]byte) bool
- func (s *State) LoadBlocks(ctx context.Context, startSlot uint64, endSlot uint64, endBlockRoot [32]byte) ([]*ethpb.SignedBeaconBlock, error)
- func (s *State) MigrateToCold(ctx context.Context, fRoot [32]byte) error
- func (s *State) ReplayBlocks(ctx context.Context, state *state.BeaconState, ...) (*state.BeaconState, error)
- func (s *State) Resume(ctx context.Context) (*state.BeaconState, error)
- func (s *State) SaveFinalizedState(fSlot uint64, fRoot [32]byte, fState *state.BeaconState)
- func (s *State) SaveState(ctx context.Context, root [32]byte, state *state.BeaconState) error
- func (s *State) SaveStateSummary(ctx context.Context, blk *ethpb.SignedBeaconBlock, blockRoot [32]byte)
- func (s *State) StateByRoot(ctx context.Context, blockRoot [32]byte) (*state.BeaconState, error)
- func (s *State) StateByRootInitialSync(ctx context.Context, blockRoot [32]byte) (*state.BeaconState, error)
- func (s *State) StateBySlot(ctx context.Context, slot uint64) (*state.BeaconState, error)
- func (s *State) StateSummaryExists(ctx context.Context, blockRoot [32]byte) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
State represents a management object that handles the internal logic of maintaining both hot and cold states in DB.
func New ¶
func New(db db.NoHeadAccessDatabase, stateSummaryCache *cache.StateSummaryCache) *State
New returns a new state management object.
func (*State) ComputeStateUpToSlot ¶ added in v0.3.4
func (s *State) ComputeStateUpToSlot(ctx context.Context, targetSlot uint64) (*state.BeaconState, error)
ComputeStateUpToSlot returns a processed state up to input target slot. If the last processed block is at slot 32, given input target slot at 40, this returns processed state up to slot 40 via empty slots. If there's duplicated blocks in a single slot, the canonical block will be returned.
func (*State) ForceCheckpoint ¶ added in v1.0.0
ForceCheckpoint initiates a cold state save of the given state. This method does not update the "last archived state" but simply saves the specified state from the root argument into the DB.
func (*State) HasState ¶ added in v1.0.0
HasState returns true if the state exists in cache or in DB.
func (*State) LoadBlocks ¶
func (s *State) LoadBlocks(ctx context.Context, startSlot uint64, endSlot uint64, endBlockRoot [32]byte) ([]*ethpb.SignedBeaconBlock, error)
LoadBlocks loads the blocks between start slot and end slot by recursively fetching from end block root. The Blocks are returned in slot-descending order.
func (*State) MigrateToCold ¶ added in v0.3.4
MigrateToCold advances the finalized info in between the cold and hot state sections. It moves the recent finalized states from the hot section to the cold section and only preserve the ones that's on archived point.
func (*State) ReplayBlocks ¶
func (s *State) ReplayBlocks(ctx context.Context, state *state.BeaconState, signed []*ethpb.SignedBeaconBlock, targetSlot uint64) (*state.BeaconState, error)
ReplayBlocks replays the input blocks on the input state until the target slot is reached.
func (*State) Resume ¶ added in v0.3.5
Resume resumes a new state management object from previously saved finalized check point in DB.
func (*State) SaveFinalizedState ¶ added in v1.0.0
func (s *State) SaveFinalizedState(fSlot uint64, fRoot [32]byte, fState *state.BeaconState)
SaveFinalizedState saves the finalized slot, root and state into memory to be used by state gen service. This used for migration at the correct start slot and used for hot state play back to ensure lower bound to start is always at the last finalized state.
func (*State) SaveState ¶ added in v0.3.5
SaveState saves the state in the DB. It knows which cold and hot state section the input state should belong to.
func (*State) SaveStateSummary ¶ added in v1.0.0
func (s *State) SaveStateSummary(ctx context.Context, blk *ethpb.SignedBeaconBlock, blockRoot [32]byte)
SaveStateSummary saves the relevant state summary for a block and its corresponding state slot in the state summary cache.
func (*State) StateByRoot ¶ added in v0.3.5
StateByRoot retrieves the state from DB using input block root. It retrieves state from the hot section if the state summary slot is below the split point cut off.
func (*State) StateByRootInitialSync ¶ added in v1.0.0
func (s *State) StateByRootInitialSync(ctx context.Context, blockRoot [32]byte) (*state.BeaconState, error)
StateByRootInitialSync retrieves the state from the DB for the initial syncing phase. It assumes initial syncing using a block list rather than a block tree hence the returned state is not copied. It invalidates cache for parent root because pre state will get mutated. Do not use this method for anything other than initial syncing purpose or block tree is applied.
func (*State) StateBySlot ¶ added in v0.3.5
StateBySlot retrieves the state from DB using input slot. It retrieves state from the cold section if the input slot is below the split point cut off. Note: `StateByRoot` is preferred over this. Retrieving state by root `StateByRoot` is more performant than retrieving by slot.