Documentation ¶
Index ¶
- func NewFileChannels(cfg *Config) *fileChannels
- type BlockListener
- type Config
- type ICheckPoint
- type Manager
- func (m *Manager) Close()
- func (m *Manager) GetCheckpoint(key string, height uint32) (checkpoint ICheckPoint, found bool)
- func (m *Manager) OnBlockSaved(block *types.DposBlock, filter func(point ICheckPoint) bool, isPow bool)
- func (m *Manager) OnRollbackTo(height uint32, isPow bool) error
- func (m *Manager) Register(checkpoint ICheckPoint)
- func (m *Manager) Reset(filter func(point ICheckPoint) bool)
- func (m *Manager) Restore() (err error)
- func (m *Manager) RestoreTo(height int) (err error)
- func (m *Manager) SafeHeight() uint32
- func (m *Manager) SetDataPath(path string)
- func (m *Manager) SetNeedSave(needSave bool)
- func (m *Manager) Unregister(key string)
- type Priority
- type RollBackStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFileChannels ¶
func NewFileChannels(cfg *Config) *fileChannels
Types ¶
type BlockListener ¶
type BlockListener interface { // OnBlockSaved is an event fired after block saved to chain db, // which means block has been settled in block chain. OnBlockSaved(block *types.DposBlock) // OnRollbackTo is an event fired during the block chain rollback, // since we only tolerance 6 blocks rollback so out max rollback support // can be 6 blocks by default. OnRollbackTo(height uint32) error // OnRollbackSeekTo is an event fired during the block chain rollback, // only rollback history without do commit. OnRollbackSeekTo(height uint32) }
BlockListener defines events during block lifetime.
type Config ¶
type Config struct { // EnableHistory is a switch about recording history of snapshots of // checkpoints. EnableHistory bool // HistoryStartHeight defines the height manager should start to record // snapshots of checkpoints. HistoryStartHeight uint32 // DataPath defines root directory path of all checkpoint related files. DataPath string // NeedSave indicate whether or not manager should save checkpoints when // reached a save point. NeedSave bool }
Config holds checkpoint related configurations.
type ICheckPoint ¶
type ICheckPoint interface { common.Serializable BlockListener // Key is the unique id in manager to identity checkpoints. Key() string // Snapshot take a snapshot of current state, this should be a deep copy // because we are in a async environment. Snapshot() ICheckPoint // GetHeight returns current height of checkpoint by which determines how to // choose between multi-history checkpoints. GetHeight() uint32 // SetHeight set current height of checkpoint by which determines how to // choose between multi-history checkpoints. SetHeight(uint32) // SavePeriod defines how long should we save the checkpoint. SavePeriod() uint32 // EffectivePeriod defines the legal height a checkpoint can take // effect. EffectivePeriod() uint32 // DataExtension defines extension of checkpoint related data files. DataExtension() string // Generator returns a generator to create a checkpoint by a data buffer. Generator() func(buf []byte) ICheckPoint // LogError will output the specify error with custom log format. LogError(err error) // Priority defines the priority by which we decide the order when // process block and rollback block. Priority() Priority // OnInit fired after manager successfully loaded default checkpoint. OnInit() // GetHeight returns initial height checkpoint should start with. StartHeight() uint32 }
ICheckPoint is a interface defines operators that all memory state should implement to restore and get when needed.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds checkpoints save automatically.
func NewManager ¶
func (*Manager) GetCheckpoint ¶
func (m *Manager) GetCheckpoint(key string, height uint32) ( checkpoint ICheckPoint, found bool)
GetCheckpoint get a checkpoint by key and height. If height is lower than last height of checkpoints and EnableHistory in Config struct is true should return supported checkpoints, otherwise will return nil instead.
func (*Manager) OnBlockSaved ¶
func (m *Manager) OnBlockSaved(block *types.DposBlock, filter func(point ICheckPoint) bool, isPow bool)
OnBlockSaved is an event fired after block saved to chain db, which means block has been settled in block chain.
func (*Manager) OnRollbackTo ¶
OnRollbackTo is an event fired during the block chain rollback, since we only tolerance 6 blocks rollback so out max rollback support can be 6 blocks by default.
func (*Manager) Register ¶
func (m *Manager) Register(checkpoint ICheckPoint)
Register will register a checkpoint with key in checkpoint as the unique id.
func (*Manager) Reset ¶
func (m *Manager) Reset(filter func(point ICheckPoint) bool)
func (*Manager) Restore ¶
Restore will load all data of each checkpoints file and store in corresponding meta-data.
func (*Manager) RestoreTo ¶ added in v0.8.0
RestoreTo will load all data of specific height in each checkpoints file and store in corresponding meta-data.
func (*Manager) SafeHeight ¶
SafeHeight returns the minimum height of all checkpoints from which we can rescan block chain data.
func (*Manager) SetDataPath ¶
SetDataPath set root path of all checkpoints.
func (*Manager) SetNeedSave ¶
RegisterNeedSave register the need save function.
func (*Manager) Unregister ¶
Unregister will unregister a checkpoint with key in checkpoint as the unique id.
type RollBackStatus ¶ added in v0.8.0
type RollBackStatus byte