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 MockStateManager
- func (m *MockStateManager) AddStateForRoot(state state.BeaconState, blockRoot [32]byte)
- func (m *MockStateManager) AddStateForSlot(state state.BeaconState, slot types.Slot)
- func (m *MockStateManager) DisableSaveHotStateToDB(_ context.Context) error
- func (m *MockStateManager) EnableSaveHotStateToDB(_ context.Context)
- func (m *MockStateManager) ForceCheckpoint(_ context.Context, _ []byte) error
- func (m *MockStateManager) HasState(_ context.Context, _ [32]byte) (bool, error)
- func (m *MockStateManager) HasStateInCache(_ context.Context, _ [32]byte) (bool, error)
- func (m *MockStateManager) LoadBlocks(_ context.Context, _, _ types.Slot, _ [32]byte) ([]block.SignedBeaconBlock, error)
- func (m *MockStateManager) MigrateToCold(_ context.Context, _ [32]byte) error
- func (m *MockStateManager) RecoverStateSummary(_ context.Context, _ [32]byte) (*ethpb.StateSummary, error)
- func (m *MockStateManager) ReplayBlocks(_ context.Context, _ state.BeaconState, _ []block.SignedBeaconBlock, ...) (state.BeaconState, error)
- func (m *MockStateManager) Resume(_ context.Context) (state.BeaconState, error)
- func (m *MockStateManager) SaveFinalizedState(_ types.Slot, _ [32]byte, _ state.BeaconState)
- func (m *MockStateManager) SaveState(_ context.Context, _ [32]byte, _ state.BeaconState) error
- func (m *MockStateManager) StateByRoot(_ context.Context, blockRoot [32]byte) (state.BeaconState, error)
- func (m *MockStateManager) StateByRootInitialSync(_ context.Context, _ [32]byte) (state.BeaconState, error)
- func (m *MockStateManager) StateBySlot(_ context.Context, slot types.Slot) (state.BeaconState, error)
- type State
- func (s *State) DisableSaveHotStateToDB(ctx context.Context) error
- func (s *State) EnableSaveHotStateToDB(_ context.Context)
- func (s *State) ForceCheckpoint(ctx context.Context, root []byte) error
- func (s *State) HasState(ctx context.Context, blockRoot [32]byte) (bool, error)
- func (s *State) HasStateInCache(ctx context.Context, blockRoot [32]byte) (bool, error)
- func (s *State) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, endBlockRoot [32]byte) ([]block.SignedBeaconBlock, error)
- func (s *State) MigrateToCold(ctx context.Context, fRoot [32]byte) error
- func (s *State) RecoverStateSummary(ctx context.Context, blockRoot [32]byte) (*ethpb.StateSummary, error)
- func (s *State) ReplayBlocks(ctx context.Context, state state.BeaconState, signed []block.SignedBeaconBlock, ...) (state.BeaconState, error)
- func (s *State) Resume(ctx context.Context) (state.BeaconState, error)
- func (s *State) SaveFinalizedState(fSlot types.Slot, fRoot [32]byte, fState state.BeaconState)
- func (s *State) SaveState(ctx context.Context, root [32]byte, st state.BeaconState) error
- 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 types.Slot) (state.BeaconState, error)
- type StateManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockStateManager ¶
type MockStateManager struct { StatesByRoot map[[32]byte]state.BeaconState StatesBySlot map[types.Slot]state.BeaconState }
MockStateManager is a fake implementation of StateManager.
func (*MockStateManager) AddStateForRoot ¶
func (m *MockStateManager) AddStateForRoot(state state.BeaconState, blockRoot [32]byte)
AddStateForRoot --
func (*MockStateManager) AddStateForSlot ¶
func (m *MockStateManager) AddStateForSlot(state state.BeaconState, slot types.Slot)
AddStateForSlot --
func (*MockStateManager) DisableSaveHotStateToDB ¶
func (m *MockStateManager) DisableSaveHotStateToDB(_ context.Context) error
DisableSaveHotStateToDB --
func (*MockStateManager) EnableSaveHotStateToDB ¶
func (m *MockStateManager) EnableSaveHotStateToDB(_ context.Context)
EnableSaveHotStateToDB --
func (*MockStateManager) ForceCheckpoint ¶
func (m *MockStateManager) ForceCheckpoint(_ context.Context, _ []byte) error
ForceCheckpoint --
func (*MockStateManager) HasStateInCache ¶
HasStateInCache --
func (*MockStateManager) LoadBlocks ¶
func (m *MockStateManager) LoadBlocks( _ context.Context, _, _ types.Slot, _ [32]byte, ) ([]block.SignedBeaconBlock, error)
LoadBlocks --
func (*MockStateManager) MigrateToCold ¶
func (m *MockStateManager) MigrateToCold(_ context.Context, _ [32]byte) error
MigrateToCold --
func (*MockStateManager) RecoverStateSummary ¶
func (m *MockStateManager) RecoverStateSummary( _ context.Context, _ [32]byte, ) (*ethpb.StateSummary, error)
RecoverStateSummary --
func (*MockStateManager) ReplayBlocks ¶
func (m *MockStateManager) ReplayBlocks( _ context.Context, _ state.BeaconState, _ []block.SignedBeaconBlock, _ types.Slot, ) (state.BeaconState, error)
ReplayBlocks --
func (*MockStateManager) Resume ¶
func (m *MockStateManager) Resume(_ context.Context) (state.BeaconState, error)
Resume --
func (*MockStateManager) SaveFinalizedState ¶
func (m *MockStateManager) SaveFinalizedState(_ types.Slot, _ [32]byte, _ state.BeaconState)
SaveFinalizedState --
func (*MockStateManager) SaveState ¶
func (m *MockStateManager) SaveState(_ context.Context, _ [32]byte, _ state.BeaconState) error
SaveState --
func (*MockStateManager) StateByRoot ¶
func (m *MockStateManager) StateByRoot(_ context.Context, blockRoot [32]byte) (state.BeaconState, error)
StateByRoot --
func (*MockStateManager) StateByRootInitialSync ¶
func (m *MockStateManager) StateByRootInitialSync(_ context.Context, _ [32]byte) (state.BeaconState, error)
StateByRootInitialSync --
func (*MockStateManager) StateBySlot ¶
func (m *MockStateManager) StateBySlot(_ context.Context, slot types.Slot) (state.BeaconState, error)
StateBySlot --
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is a concrete implementation of StateManager.
func New ¶
func New(beaconDB db.NoHeadAccessDatabase) *State
New returns a new state management object.
func (*State) DisableSaveHotStateToDB ¶
DisableSaveHotStateToDB exits the mode that saves beacon state to DB for the hot states. This usually gets triggered once there's finality after long duration since finality.
func (*State) EnableSaveHotStateToDB ¶
EnableSaveHotStateToDB enters the mode that saves hot beacon state to the DB. This usually gets triggered when there's long duration since finality.
func (*State) ForceCheckpoint ¶
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) HasStateInCache ¶
HasStateInCache returns true if the state exists in cache.
func (*State) LoadBlocks ¶
func (s *State) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, endBlockRoot [32]byte) ([]block.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 ¶
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) RecoverStateSummary ¶
func (s *State) RecoverStateSummary(ctx context.Context, blockRoot [32]byte) (*ethpb.StateSummary, error)
RecoverStateSummary recovers state summary object of a given block root by using the saved block in DB.
func (*State) ReplayBlocks ¶
func (s *State) ReplayBlocks( ctx context.Context, state state.BeaconState, signed []block.SignedBeaconBlock, targetSlot types.Slot, ) (state.BeaconState, error)
ReplayBlocks replays the input blocks on the input state until the target slot is reached.
func (*State) Resume ¶
Resume resumes a new state management object from previously saved finalized check point in DB.
func (*State) SaveFinalizedState ¶
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) StateByRoot ¶
StateByRoot retrieves the state using input block root.
func (*State) StateByRootInitialSync ¶
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 ¶
StateBySlot retrieves the state using input slot.
type StateManager ¶
type StateManager interface { Resume(ctx context.Context) (state.BeaconState, error) SaveFinalizedState(fSlot types.Slot, fRoot [32]byte, fState state.BeaconState) MigrateToCold(ctx context.Context, fRoot [32]byte) error ReplayBlocks(ctx context.Context, state state.BeaconState, signed []block.SignedBeaconBlock, targetSlot types.Slot) (state.BeaconState, error) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, endBlockRoot [32]byte) ([]block.SignedBeaconBlock, error) HasState(ctx context.Context, blockRoot [32]byte) (bool, error) HasStateInCache(ctx context.Context, blockRoot [32]byte) (bool, error) StateByRoot(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error) StateByRootInitialSync(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error) StateBySlot(ctx context.Context, slot types.Slot) (state.BeaconState, error) RecoverStateSummary(ctx context.Context, blockRoot [32]byte) (*ethpb.StateSummary, error) SaveState(ctx context.Context, root [32]byte, st state.BeaconState) error ForceCheckpoint(ctx context.Context, root []byte) error EnableSaveHotStateToDB(_ context.Context) DisableSaveHotStateToDB(ctx context.Context) error }
StateManager represents a management object that handles the internal logic of maintaining both hot and cold states in DB.