checkpoint

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

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
}

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
}

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 NewManager(cfg *Config) *Manager

func (*Manager) Close

func (m *Manager) Close()

Close will clean all related resources.

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)

OnBlockSaved is an event fired after block saved to chain db, which means block has been settled in block chain.

func (*Manager) OnRollbackTo

func (m *Manager) OnRollbackTo(height uint32) error

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

func (m *Manager) Restore() (err error)

Restore will load all data of each checkpoints file and store in corresponding meta-data.

func (*Manager) SafeHeight

func (m *Manager) SafeHeight() uint32

SafeHeight returns the minimum height of all checkpoints from which we can rescan block chain data.

func (*Manager) SetDataPath

func (m *Manager) SetDataPath(path string)

SetDataPath set root path of all checkpoints.

func (*Manager) Unregister

func (m *Manager) Unregister(key string)

Unregister will unregister a checkpoint with key in checkpoint as the unique id.

type Priority

type Priority byte
const (
	DefaultCheckpoint = "default"

	VeryHigh   Priority = 0x00
	High       Priority = 0x01
	MediumHigh Priority = 0x02
	Medium     Priority = 0x03
	MediumLow  Priority = 0x04
	Low        Priority = 0x05
	VeryLow    Priority = 0x06
)

Jump to

Keyboard shortcuts

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