pov

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: MIT Imports: 27 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 = 1000000
)

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")
)

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

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) (*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 *PovStateDB, stateBlock *types.StateBlock) error

func (*PovBlockChain) CalcBlockReward added in v1.3.0

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

func (*PovBlockChain) CalcBlockRewardByQLC added in v1.3.0

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

func (*PovBlockChain) CalcBlockRewardByStakingBonus added in v1.3.1

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) GenStateTrie

func (bc *PovBlockChain) GenStateTrie(height uint64, prevStateHash types.Hash,
	txs []*types.PovTransaction) (*trie.Trie, error)

func (*PovBlockChain) GenesisBlock

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

func (*PovBlockChain) GetAccountState

func (bc *PovBlockChain) GetAccountState(trie *trie.Trie, address types.Address) *types.PovAccountState

func (*PovBlockChain) GetAllOnlineRepStates added in v1.3.0

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) GetDebugInfo added in v1.3.0

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

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

func (*PovBlockChain) GetRepState added in v1.3.0

func (bc *PovBlockChain) GetRepState(trie *trie.Trie, address types.Address) *types.PovRepState

func (*PovBlockChain) GetStateTrie

func (bc *PovBlockChain) GetStateTrie(stateHash *types.Hash) *trie.Trie

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, stateTrie *trie.Trie) 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) NewStateTrie

func (bc *PovBlockChain) NewStateTrie() *trie.Trie

func (*PovBlockChain) RegisterListener added in v1.2.4

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) SetAccountState

func (bc *PovBlockChain) SetAccountState(trie *trie.Trie, address types.Address, as *types.PovAccountState) error

func (*PovBlockChain) SetRepState added in v1.3.0

func (bc *PovBlockChain) SetRepState(trie *trie.Trie, address types.Address, rs *types.PovRepState) 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) TrieDb

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

func (*PovBlockChain) UnRegisterListener added in v1.2.4

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

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

func (*PovBlockProcessor) GetNextPendingBlockForDebug added in v1.3.0

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 {
	GetHeaderByHash(hash types.Hash) *types.PovHeader
	RelativeAncestor(header *types.PovHeader, distance uint64) *types.PovHeader
	GetStateTrie(stateHash *types.Hash) *trie.Trie
	GetAccountState(trie *trie.Trie, address types.Address) *types.PovAccountState
	GetRepState(trie *trie.Trie, address types.Address) *types.PovRepState
}

type PovOrphanBlock

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

type PovPendingBlock

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

type PovProcessorChainReader added in v1.2.4

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

type PovProcessorSyncer added in v1.2.4

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

type PovProcessorVerifier added in v1.2.4

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

type PovStateDB added in v1.3.1

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

func NewPovStateDB added in v1.3.1

func NewPovStateDB(t *trie.Trie) *PovStateDB

func (*PovStateDB) CommitToTrie added in v1.3.1

func (sdb *PovStateDB) CommitToTrie() error

func (*PovStateDB) GetAccountState added in v1.3.1

func (sdb *PovStateDB) GetAccountState(address types.Address) (*types.PovAccountState, error)

func (*PovStateDB) GetRepState added in v1.3.1

func (sdb *PovStateDB) GetRepState(address types.Address) (*types.PovRepState, error)

func (*PovStateDB) SetAccountState added in v1.3.1

func (sdb *PovStateDB) SetAccountState(address types.Address, as *types.PovAccountState) error

func (*PovStateDB) SetRepState added in v1.3.1

func (sdb *PovStateDB) SetRepState(address types.Address, rs *types.PovRepState) error

type PovSyncBlock added in v1.3.0

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

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

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

type PovTxChainReader interface {
	RegisterListener(listener EventListener)
	UnRegisterListener(listener EventListener)
	GetAccountState(trie *trie.Trie, address types.Address) *types.PovAccountState
}

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

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

func (*PovTxPool) GetPendingTxNum added in v1.3.0

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

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

func (*PovTxPool) SelectPendingTxs

func (tp *PovTxPool) SelectPendingTxs(stateTrie *trie.Trie, 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) BlockCheck

func (pv *PovVerifier) BlockCheck(block types.Block) (process.ProcessResult, error)

func (*PovVerifier) Process

func (pv *PovVerifier) Process(block types.Block) (process.ProcessResult, error)

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 {
	GetHeaderByHash(hash types.Hash) *types.PovHeader
	CalcPastMedianTime(prevHeader *types.PovHeader) uint32
	GenStateTrie(height uint64, prevStateHash types.Hash, txs []*types.PovTransaction) (*trie.Trie, error)
	GetStateTrie(stateHash *types.Hash) *trie.Trie
	GetAccountState(trie *trie.Trie, address types.Address) *types.PovAccountState
	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
	PrevStateTrie *trie.Trie
	StateTrie     *trie.Trie
	TxBlocks      map[types.Hash]*types.StateBlock
}

func NewPovVerifyStat

func NewPovVerifyStat() *PovVerifyStat

Jump to

Keyboard shortcuts

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