stategen

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2021 License: GPL-3.0 Imports: 24 Imported by: 24

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockStateManager added in v1.2.2

type MockStateManager struct {
	StatesByRoot map[[32]byte]iface.BeaconState
	StatesBySlot map[types.Slot]iface.BeaconState
}

MockStateManager is a fake implementation of StateManager.

func NewMockService added in v1.2.2

func NewMockService() *MockStateManager

NewMockService --

func (*MockStateManager) AddStateForRoot added in v1.2.2

func (m *MockStateManager) AddStateForRoot(state iface.BeaconState, blockRoot [32]byte)

AddStateForRoot --

func (*MockStateManager) AddStateForSlot added in v1.2.2

func (m *MockStateManager) AddStateForSlot(state iface.BeaconState, slot types.Slot)

AddStateForSlot --

func (*MockStateManager) DisableSaveHotStateToDB added in v1.2.2

func (m *MockStateManager) DisableSaveHotStateToDB(ctx context.Context) error

DisableSaveHotStateToDB --

func (*MockStateManager) EnableSaveHotStateToDB added in v1.2.2

func (m *MockStateManager) EnableSaveHotStateToDB(_ context.Context)

EnableSaveHotStateToDB --

func (*MockStateManager) ForceCheckpoint added in v1.2.2

func (m *MockStateManager) ForceCheckpoint(ctx context.Context, root []byte) error

ForceCheckpoint --

func (*MockStateManager) HasState added in v1.2.2

func (m *MockStateManager) HasState(ctx context.Context, blockRoot [32]byte) (bool, error)

HasState --

func (*MockStateManager) HasStateInCache added in v1.2.2

func (m *MockStateManager) HasStateInCache(ctx context.Context, blockRoot [32]byte) (bool, error)

HasStateInCache --

func (*MockStateManager) LoadBlocks added in v1.2.2

func (m *MockStateManager) LoadBlocks(
	ctx context.Context,
	startSlot, endSlot types.Slot,
	endBlockRoot [32]byte,
) ([]interfaces.SignedBeaconBlock, error)

LoadBlocks --

func (*MockStateManager) MigrateToCold added in v1.2.2

func (m *MockStateManager) MigrateToCold(ctx context.Context, fRoot [32]byte) error

MigrateToCold --

func (*MockStateManager) RecoverStateSummary added in v1.2.2

func (m *MockStateManager) RecoverStateSummary(
	ctx context.Context,
	blockRoot [32]byte,
) (*ethereum_beacon_p2p_v1.StateSummary, error)

RecoverStateSummary --

func (*MockStateManager) ReplayBlocks added in v1.2.2

func (m *MockStateManager) ReplayBlocks(
	ctx context.Context,
	state iface.BeaconState,
	signed []interfaces.SignedBeaconBlock,
	targetSlot types.Slot,
) (iface.BeaconState, error)

ReplayBlocks --

func (*MockStateManager) Resume added in v1.2.2

Resume --

func (*MockStateManager) SaveFinalizedState added in v1.2.2

func (m *MockStateManager) SaveFinalizedState(fSlot types.Slot, fRoot [32]byte, fState iface.BeaconState)

SaveFinalizedState --

func (*MockStateManager) SaveState added in v1.2.2

func (m *MockStateManager) SaveState(ctx context.Context, root [32]byte, st iface.BeaconState) error

SaveState --

func (*MockStateManager) StateByRoot added in v1.2.2

func (m *MockStateManager) StateByRoot(ctx context.Context, blockRoot [32]byte) (iface.BeaconState, error)

StateByRoot --

func (*MockStateManager) StateByRootInitialSync added in v1.2.2

func (m *MockStateManager) StateByRootInitialSync(ctx context.Context, blockRoot [32]byte) (iface.BeaconState, error)

StateByRootInitialSync --

func (*MockStateManager) StateBySlot added in v1.2.2

func (m *MockStateManager) StateBySlot(ctx context.Context, slot types.Slot) (iface.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 added in v1.0.0

func (s *State) DisableSaveHotStateToDB(ctx context.Context) error

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 added in v1.0.0

func (s *State) EnableSaveHotStateToDB(_ context.Context)

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 added in v1.0.0

func (s *State) ForceCheckpoint(ctx context.Context, root []byte) error

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

func (s *State) HasState(ctx context.Context, blockRoot [32]byte) (bool, error)

HasState returns true if the state exists in cache or in DB.

func (*State) HasStateInCache added in v1.0.0

func (s *State) HasStateInCache(ctx context.Context, blockRoot [32]byte) (bool, error)

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) ([]interfaces.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

func (s *State) MigrateToCold(ctx context.Context, fRoot [32]byte) error

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 added in v1.0.2

func (s *State) RecoverStateSummary(ctx context.Context, blockRoot [32]byte) (*pb.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 iface.BeaconState,
	signed []interfaces.SignedBeaconBlock,
	targetSlot types.Slot,
) (iface.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

func (s *State) Resume(ctx context.Context) (iface.BeaconState, error)

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 types.Slot, fRoot [32]byte, fState iface.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

func (s *State) SaveState(ctx context.Context, root [32]byte, st iface.BeaconState) error

SaveState saves the state in the cache and/or DB.

func (*State) StateByRoot added in v0.3.5

func (s *State) StateByRoot(ctx context.Context, blockRoot [32]byte) (iface.BeaconState, error)

StateByRoot retrieves the state using input block root.

func (*State) StateByRootInitialSync added in v1.0.0

func (s *State) StateByRootInitialSync(ctx context.Context, blockRoot [32]byte) (iface.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

func (s *State) StateBySlot(ctx context.Context, slot types.Slot) (iface.BeaconState, error)

StateBySlot retrieves the state using input slot.

type StateManager added in v1.2.2

type StateManager interface {
	Resume(ctx context.Context) (iface.BeaconState, error)
	SaveFinalizedState(fSlot types.Slot, fRoot [32]byte, fState iface.BeaconState)
	MigrateToCold(ctx context.Context, fRoot [32]byte) error
	ReplayBlocks(ctx context.Context, state iface.BeaconState, signed []interfaces.SignedBeaconBlock, targetSlot types.Slot) (iface.BeaconState, error)
	LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, endBlockRoot [32]byte) ([]interfaces.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) (iface.BeaconState, error)
	StateByRootInitialSync(ctx context.Context, blockRoot [32]byte) (iface.BeaconState, error)
	StateBySlot(ctx context.Context, slot types.Slot) (iface.BeaconState, error)
	RecoverStateSummary(ctx context.Context, blockRoot [32]byte) (*ethereum_beacon_p2p_v1.StateSummary, error)
	SaveState(ctx context.Context, root [32]byte, st iface.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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL