pov

package
Version: v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PovConsensusModeFake = iota
	PovConsensusModePow
)
View Source
const (
	EventConnectPovBlock    = byte(1)
	EventDisconnectPovBlock = byte(2)
)
View Source
const (
	MaxTxsInPool = 10000000
)

Variables

View Source
var (
	ErrPovInvalidHash     = errors.New("invalid pov block hash")
	ErrPovNoGenesis       = errors.New("pov genesis block not found in chain")
	ErrPovUnknownAncestor = errors.New("unknown pov block ancestor")
	ErrPovFutureBlock     = errors.New("pov block in the future")
	ErrPovInvalidHeight   = errors.New("invalid pov block height")
	ErrPovInvalidPrevious = errors.New("invalid pov block previous")
	ErrPovFailedVerify    = errors.New("failed to verify block")
	ErrPovForkHashZero    = errors.New("fork point hash is zero")
	ErrPovInvalidHead     = errors.New("invalid pov head block")
	ErrPovInvalidFork     = errors.New("invalid pov fork point")
)
View Source
var (
	CheckPeerStatusTime = 30 * time.Second
	ForceSyncTimeInSec  = 60 * time.Second
)

Functions

This section is empty.

Types

type ChainState

type ChainState uint
const (
	ChainStateNone ChainState = iota
	ChainStateMain
	ChainStateSide
)

func (ChainState) String

func (s ChainState) String() string

type ConsensusFake

type ConsensusFake struct {
	// contains filtered or unexported fields
}

func NewConsensusFake

func NewConsensusFake(chainR PovConsensusChainReader) *ConsensusFake

func (*ConsensusFake) FinalizeHeader

func (c *ConsensusFake) FinalizeHeader(header *types.PovHeader) error

func (*ConsensusFake) Init

func (c *ConsensusFake) Init() error

func (*ConsensusFake) PrepareHeader

func (c *ConsensusFake) PrepareHeader(header *types.PovHeader) error

func (*ConsensusFake) Start

func (c *ConsensusFake) Start() error

func (*ConsensusFake) Stop

func (c *ConsensusFake) Stop() error

func (*ConsensusFake) VerifyHeader

func (c *ConsensusFake) VerifyHeader(header *types.PovHeader) error

type ConsensusPov

type ConsensusPov interface {
	Init() error
	Start() error
	Stop() error

	PrepareHeader(header *types.PovHeader) error
	FinalizeHeader(header *types.PovHeader) error
	VerifyHeader(header *types.PovHeader) error
}

func NewPovConsensus

func NewPovConsensus(mode int, chainR PovConsensusChainReader) ConsensusPov

type ConsensusPow

type ConsensusPow struct {
	// contains filtered or unexported fields
}

func NewConsensusPow

func NewConsensusPow(chainR PovConsensusChainReader) *ConsensusPow

func (*ConsensusPow) FinalizeHeader

func (c *ConsensusPow) FinalizeHeader(header *types.PovHeader) error

func (*ConsensusPow) Init

func (c *ConsensusPow) Init() error

func (*ConsensusPow) PrepareHeader

func (c *ConsensusPow) PrepareHeader(header *types.PovHeader) error

func (*ConsensusPow) Start

func (c *ConsensusPow) Start() error

func (*ConsensusPow) Stop

func (c *ConsensusPow) Stop() error

func (*ConsensusPow) VerifyHeader

func (c *ConsensusPow) VerifyHeader(header *types.PovHeader) error

type EventListener

type EventListener interface {
	OnPovBlockEvent(event byte, block *types.PovBlock)
}

type PoVEngine

type PoVEngine struct {
	// contains filtered or unexported fields
}

func NewPovEngine

func NewPovEngine(cfgFile string, fakePow bool) (*PoVEngine, error)

func (*PoVEngine) AddBlock

func (pov *PoVEngine) AddBlock(block *types.PovBlock, from types.PovBlockFrom, peerID string) error

func (*PoVEngine) AddMinedBlock

func (pov *PoVEngine) AddMinedBlock(block *types.PovBlock) error

func (*PoVEngine) GetAccounts

func (pov *PoVEngine) GetAccounts() []*types.Account

func (*PoVEngine) GetChain

func (pov *PoVEngine) GetChain() *PovBlockChain

func (*PoVEngine) GetConfig

func (pov *PoVEngine) GetConfig() *config.Config

func (*PoVEngine) GetConsensus

func (pov *PoVEngine) GetConsensus() ConsensusPov

func (*PoVEngine) GetEventBus

func (pov *PoVEngine) GetEventBus() event.EventBus

func (*PoVEngine) GetLedger

func (pov *PoVEngine) GetLedger() ledger.Store

func (*PoVEngine) GetLogger

func (pov *PoVEngine) GetLogger() *zap.SugaredLogger

func (*PoVEngine) GetTxPool

func (pov *PoVEngine) GetTxPool() *PovTxPool

func (*PoVEngine) GetVerifier

func (pov *PoVEngine) GetVerifier() *PovVerifier

func (*PoVEngine) Init

func (pov *PoVEngine) Init() error

func (*PoVEngine) Start

func (pov *PoVEngine) Start() error

func (*PoVEngine) Stop

func (pov *PoVEngine) Stop() error

type PovBlockChain

type PovBlockChain struct {
	// contains filtered or unexported fields
}

func NewPovBlockChain

func NewPovBlockChain(cfg *config.Config, eb event.EventBus, l ledger.Store) *PovBlockChain

func (*PovBlockChain) ApplyTransaction

func (bc *PovBlockChain) ApplyTransaction(height uint64, sdb *statedb.PovGlobalStateDB, tx *types.PovTransaction) error

func (*PovBlockChain) CalcBlockReward

func (bc *PovBlockChain) CalcBlockReward(header *types.PovHeader) (types.Balance, types.Balance, error)

func (*PovBlockChain) CalcBlockRewardByQLC

func (bc *PovBlockChain) CalcBlockRewardByQLC(header *types.PovHeader) (types.Balance, types.Balance, error)

func (*PovBlockChain) CalcBlockRewardByStakingBonus

func (bc *PovBlockChain) CalcBlockRewardByStakingBonus(header *types.PovHeader) (types.Balance, types.Balance, error)

func (*PovBlockChain) CalcPastMedianTime

func (bc *PovBlockChain) CalcPastMedianTime(prevHeader *types.PovHeader) uint32

func (*PovBlockChain) CalcTotalDifficulty

func (bc *PovBlockChain) CalcTotalDifficulty(prevTD *types.PovTD, header *types.PovHeader) *types.PovTD

func (*PovBlockChain) FindAncestor

func (bc *PovBlockChain) FindAncestor(header *types.PovHeader, height uint64) *types.PovHeader

func (*PovBlockChain) GenesisBlock

func (bc *PovBlockChain) GenesisBlock() *types.PovBlock

func (*PovBlockChain) GetAllOnlineRepStates

func (bc *PovBlockChain) GetAllOnlineRepStates(header *types.PovHeader) []*types.PovRepState

func (*PovBlockChain) GetBestBlockByHash

func (bc *PovBlockChain) GetBestBlockByHash(hash types.Hash) *types.PovBlock

func (*PovBlockChain) GetBlockByHash

func (bc *PovBlockChain) GetBlockByHash(hash types.Hash) *types.PovBlock

func (*PovBlockChain) GetBlockByHeight

func (bc *PovBlockChain) GetBlockByHeight(height uint64) (*types.PovBlock, error)

func (*PovBlockChain) GetBlockLocator

func (bc *PovBlockChain) GetBlockLocator(hash types.Hash) []*types.Hash

func (*PovBlockChain) GetBlockTDByHash

func (bc *PovBlockChain) GetBlockTDByHash(hash types.Hash) *types.PovTD

func (*PovBlockChain) GetBlockTDByHashAndHeight

func (bc *PovBlockChain) GetBlockTDByHashAndHeight(hash types.Hash, height uint64) *types.PovTD

func (*PovBlockChain) GetConfig

func (bc *PovBlockChain) GetConfig() *config.Config

func (*PovBlockChain) GetDebugInfo

func (bc *PovBlockChain) GetDebugInfo() map[string]interface{}

func (*PovBlockChain) GetHeaderByHash

func (bc *PovBlockChain) GetHeaderByHash(hash types.Hash) *types.PovHeader

func (*PovBlockChain) GetHeaderByHeight

func (bc *PovBlockChain) GetHeaderByHeight(height uint64) *types.PovHeader

func (*PovBlockChain) GetPreviousDayAvgDiffRatio

func (bc *PovBlockChain) GetPreviousDayAvgDiffRatio(header *types.PovHeader) (uint64, error)

func (*PovBlockChain) HasBestBlock

func (bc *PovBlockChain) HasBestBlock(hash types.Hash, height uint64) bool

func (*PovBlockChain) HasFullBlock

func (bc *PovBlockChain) HasFullBlock(hash types.Hash, height uint64) bool

func (*PovBlockChain) HasHeader

func (bc *PovBlockChain) HasHeader(hash types.Hash, height uint64) bool

func (*PovBlockChain) Init

func (bc *PovBlockChain) Init() error

func (*PovBlockChain) InsertBlock

func (bc *PovBlockChain) InsertBlock(block *types.PovBlock, gsdb *statedb.PovGlobalStateDB) error

func (*PovBlockChain) IsGenesisBlock

func (bc *PovBlockChain) IsGenesisBlock(block *types.PovBlock) bool

func (*PovBlockChain) LatestBlock

func (bc *PovBlockChain) LatestBlock() *types.PovBlock

func (*PovBlockChain) LatestHeader

func (bc *PovBlockChain) LatestHeader() *types.PovHeader

func (*PovBlockChain) LocateBestBlock

func (bc *PovBlockChain) LocateBestBlock(locator []*types.Hash) *types.PovBlock

func (*PovBlockChain) RegisterListener

func (bc *PovBlockChain) RegisterListener(listener EventListener)

func (*PovBlockChain) RelativeAncestor

func (bc *PovBlockChain) RelativeAncestor(header *types.PovHeader, distance uint64) *types.PovHeader

func (*PovBlockChain) ResetChainState

func (bc *PovBlockChain) ResetChainState() error

func (*PovBlockChain) Start

func (bc *PovBlockChain) Start() error

func (*PovBlockChain) Stop

func (bc *PovBlockChain) Stop() error

func (*PovBlockChain) StoreLatestBlock

func (bc *PovBlockChain) StoreLatestBlock(block *types.PovBlock)

func (*PovBlockChain) TransitStateDB

func (bc *PovBlockChain) TransitStateDB(height uint64, txs []*types.PovTransaction, gsdb *statedb.PovGlobalStateDB) error

func (*PovBlockChain) TrieDb

func (bc *PovBlockChain) TrieDb() storage.Store

func (*PovBlockChain) UnRegisterListener

func (bc *PovBlockChain) UnRegisterListener(listener EventListener)

type PovBlockProcessor

type PovBlockProcessor struct {
	// contains filtered or unexported fields
}

func (*PovBlockProcessor) AddBlock

func (bp *PovBlockProcessor) AddBlock(block *types.PovBlock, from types.PovBlockFrom, peerID string) error

func (*PovBlockProcessor) AddMinedBlock

func (bp *PovBlockProcessor) AddMinedBlock(block *types.PovBlock) error

func (*PovBlockProcessor) GetDebugInfo

func (bp *PovBlockProcessor) GetDebugInfo() map[string]interface{}

func (*PovBlockProcessor) GetNextPendingBlockForDebug

func (bp *PovBlockProcessor) GetNextPendingBlockForDebug() *PovPendingBlock

func (*PovBlockProcessor) GetOrphanRoot

func (bp *PovBlockProcessor) GetOrphanRoot(oHash types.Hash) types.Hash

func (*PovBlockProcessor) HasOrphanBlock

func (bp *PovBlockProcessor) HasOrphanBlock(blockHash types.Hash) bool

func (*PovBlockProcessor) HasPendingBlock

func (bp *PovBlockProcessor) HasPendingBlock(blockHash types.Hash) bool

func (*PovBlockProcessor) Init

func (bp *PovBlockProcessor) Init() error

func (*PovBlockProcessor) Start

func (bp *PovBlockProcessor) Start() error

func (*PovBlockProcessor) Stop

func (bp *PovBlockProcessor) Stop() error

type PovBlockResult

type PovBlockResult struct {
	// contains filtered or unexported fields
}

type PovBlockSource

type PovBlockSource struct {
	// contains filtered or unexported fields
}

type PovConsensusChainReader

type PovConsensusChainReader interface {
	TrieDb() storage.Store
	GetConfig() *config.Config
	GetHeaderByHash(hash types.Hash) *types.PovHeader
	RelativeAncestor(header *types.PovHeader, distance uint64) *types.PovHeader
}

type PovOrphanBlock

type PovOrphanBlock struct {
	// contains filtered or unexported fields
}

type PovPendingBlock

type PovPendingBlock struct {
	// contains filtered or unexported fields
}

type PovProcessorChainReader

type PovProcessorChainReader interface {
	HasBestBlock(hash types.Hash, height uint64) bool
	GetBlockByHash(hash types.Hash) *types.PovBlock
	InsertBlock(block *types.PovBlock, stateDB *statedb.PovGlobalStateDB) error
	LatestHeader() *types.PovHeader
}

type PovProcessorSyncer

type PovProcessorSyncer interface {
	// contains filtered or unexported methods
}

type PovProcessorVerifier

type PovProcessorVerifier interface {
	VerifyFull(block *types.PovBlock) *PovVerifyStat
}

type PovSyncBlock

type PovSyncBlock struct {
	PeerID       string
	Height       uint64
	Block        *types.PovBlock
	CheckTxIndex int
}

type PovSyncEvent

type PovSyncEvent struct {
	// contains filtered or unexported fields
}

type PovSyncMessage

type PovSyncMessage struct {
	// contains filtered or unexported fields
}

type PovSyncPeer

type PovSyncPeer struct {
	// contains filtered or unexported fields
}

type PovSyncPeerSetByHeight

type PovSyncPeerSetByHeight []*PovSyncPeer

func (PovSyncPeerSetByHeight) Len

func (s PovSyncPeerSetByHeight) Len() int

func (PovSyncPeerSetByHeight) Less

func (s PovSyncPeerSetByHeight) Less(i, j int) bool

func (PovSyncPeerSetByHeight) Swap

func (s PovSyncPeerSetByHeight) Swap(i, j int)

type PovSyncPeerSetByTD

type PovSyncPeerSetByTD []*PovSyncPeer

PeerSetByTD is in descend order

func (PovSyncPeerSetByTD) Len

func (s PovSyncPeerSetByTD) Len() int

func (PovSyncPeerSetByTD) Less

func (s PovSyncPeerSetByTD) Less(i, j int) bool

func (PovSyncPeerSetByTD) Swap

func (s PovSyncPeerSetByTD) Swap(i, j int)

type PovSyncer

type PovSyncer struct {
	// contains filtered or unexported fields
}

func NewPovSyncer

func NewPovSyncer(eb event.EventBus, l ledger.Store, chain PovSyncerChainReader) *PovSyncer

func (*PovSyncer) FindPeer

func (ss *PovSyncer) FindPeer(peerID string) *PovSyncPeer

func (*PovSyncer) FindPeerWithStatus

func (ss *PovSyncer) FindPeerWithStatus(peerID string, status int) *PovSyncPeer

func (*PovSyncer) GetBestPeer

func (ss *PovSyncer) GetBestPeer(lastPeerID string) *PovSyncPeer

func (*PovSyncer) GetBestPeers

func (ss *PovSyncer) GetBestPeers(limit int) []*PovSyncPeer

func (*PovSyncer) GetDebugInfo

func (ss *PovSyncer) GetDebugInfo() map[string]interface{}

func (*PovSyncer) GetPeerLocators

func (ss *PovSyncer) GetPeerLocators() []*PovSyncPeer

func (*PovSyncer) GetRandomPeers

func (ss *PovSyncer) GetRandomPeers(limit int) []*PovSyncPeer

func (*PovSyncer) GetRandomTopPeer

func (ss *PovSyncer) GetRandomTopPeer(top int) *PovSyncPeer

GetRandomTopPeer select one peer from top peers

func (*PovSyncer) Init

func (ss *PovSyncer) Init() error

func (*PovSyncer) PeerCount

func (ss *PovSyncer) PeerCount() int

func (*PovSyncer) PeerCountWithStatus

func (ss *PovSyncer) PeerCountWithStatus(status int) int

func (*PovSyncer) Start

func (ss *PovSyncer) Start() error

func (*PovSyncer) Stop

func (ss *PovSyncer) Stop()

type PovSyncerChainReader

type PovSyncerChainReader interface {
	GenesisBlock() *types.PovBlock
	LatestBlock() *types.PovBlock
	GetBlockLocator(hash types.Hash) []*types.Hash
	LocateBestBlock(locator []*types.Hash) *types.PovBlock
	GetBlockTDByHash(hash types.Hash) *types.PovTD
}

type PovTxChainReader

type PovTxChainReader interface {
	RegisterListener(listener EventListener)
	UnRegisterListener(listener EventListener)
}

type PovTxEntry

type PovTxEntry struct {
	// contains filtered or unexported fields
}

type PovTxEvent

type PovTxEvent struct {
	// contains filtered or unexported fields
}

type PovTxPendingEntry

type PovTxPendingEntry struct {
	// contains filtered or unexported fields
}

type PovTxPool

type PovTxPool struct {
	// contains filtered or unexported fields
}

func NewPovTxPool

func NewPovTxPool(eb event.EventBus, l ledger.Store, chain PovTxChainReader) *PovTxPool

func (*PovTxPool) GetDebugInfo

func (tp *PovTxPool) GetDebugInfo() map[string]interface{}

func (*PovTxPool) GetPendingTxNum

func (tp *PovTxPool) GetPendingTxNum() uint32

func (*PovTxPool) Init

func (tp *PovTxPool) Init() error

func (*PovTxPool) LastUpdated

func (tp *PovTxPool) LastUpdated() time.Time

func (*PovTxPool) OnPovBlockEvent

func (tp *PovTxPool) OnPovBlockEvent(evt byte, block *types.PovBlock)

func (*PovTxPool) SelectPendingTxs

func (tp *PovTxPool) SelectPendingTxs(gsdb *statedb.PovGlobalStateDB, limit int) []*types.StateBlock

func (*PovTxPool) Start

func (tp *PovTxPool) Start() error

func (*PovTxPool) Stop

func (tp *PovTxPool) Stop()

type PovVerifier

type PovVerifier struct {
	// contains filtered or unexported fields
}

func NewPovVerifier

func NewPovVerifier(store ledger.Store, chain PovVerifierChainReader, cs ConsensusPov) *PovVerifier

func (*PovVerifier) VerifyFull

func (pv *PovVerifier) VerifyFull(block *types.PovBlock) *PovVerifyStat

func (*PovVerifier) VerifyNet

func (pv *PovVerifier) VerifyNet(block *types.PovBlock) *PovVerifyStat

type PovVerifierChainReader

type PovVerifierChainReader interface {
	TrieDb() storage.Store
	GetHeaderByHash(hash types.Hash) *types.PovHeader
	CalcPastMedianTime(prevHeader *types.PovHeader) uint32
	TransitStateDB(height uint64, txs []*types.PovTransaction, gsdb *statedb.PovGlobalStateDB) error
	CalcBlockReward(header *types.PovHeader) (types.Balance, types.Balance, error)
}

type PovVerifyStat

type PovVerifyStat struct {
	Result process.ProcessResult
	ErrMsg string
	GapTxs map[types.Hash]process.ProcessResult

	CurHeader  *types.PovHeader
	PrevHeader *types.PovHeader
	StateDB    *statedb.PovGlobalStateDB
	TxBlocks   map[types.Hash]*types.StateBlock
}

func NewPovVerifyStat

func NewPovVerifyStat() *PovVerifyStat

type TimeSorter

type TimeSorter []uint32

timeSorter implements sort.Interface to allow a slice of timestamps to be sorted.

func (TimeSorter) Len

func (s TimeSorter) Len() int

Len returns the number of timestamps in the slice. It is part of the sort.Interface implementation.

func (TimeSorter) Less

func (s TimeSorter) Less(i, j int) bool

Less returns whether the timstamp with index i should sort before the timestamp with index j. It is part of the sort.Interface implementation.

func (TimeSorter) Swap

func (s TimeSorter) Swap(i, j int)

Swap swaps the timestamps at the passed indices. It is part of the sort.Interface implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to