pov

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

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

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

func (c *ConsensusFake) SealHeader(header *types.PovHeader, cbAccount *types.Account, quitCh chan struct{}, resultCh chan<- *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
	SealHeader(header *types.PovHeader, cbAccount *types.Account, quitCh chan struct{}, resultCh chan<- *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) SealHeader

func (c *ConsensusPow) SealHeader(header *types.PovHeader, cbAccount *types.Account, quitCh chan struct{}, resultCh chan<- *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(cfg *config.Config, accounts []*types.Account) (*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) GetSyncState

func (pov *PoVEngine) GetSyncState() common.SyncState

func (*PoVEngine) GetSyncer

func (pov *PoVEngine) GetSyncer() *PovSyncer

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, ledger ledger.Store) *PovBlockChain

func (*PovBlockChain) ApplyTransaction

func (bc *PovBlockChain) ApplyTransaction(trie *trie.Trie, stateBlock *types.StateBlock) error

func (*PovBlockChain) CalcPastMedianTime

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

func (*PovBlockChain) CalcTotalDifficulty

func (bc *PovBlockChain) CalcTotalDifficulty(target types.Signature) *big.Int

CalcTotalDifficulty calculates a total difficulty from target. PoV increases the difficulty for generating a block by decreasing the value which the generated vote signature must be less than. This difficulty target is stored in each block header as signature. The main chain is selected by choosing the chain that has the most proof of work (highest difficulty). Since a lower target difficulty value equates to higher actual difficulty, the work value which will be accumulated must be the inverse of the difficulty. Also, in order to avoid potential division by zero and really small floating point numbers, the result adds 1 to the denominator and multiplies the numerator by 2^512.

func (*PovBlockChain) FindAncestor

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

func (*PovBlockChain) GenStateTrie

func (bc *PovBlockChain) GenStateTrie(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) 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) *big.Int

func (*PovBlockChain) GetBlockTDByHashAndHeight

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

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

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

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
}

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 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(povEngine *PoVEngine) *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) 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()

func (*PovSyncer) Stop

func (ss *PovSyncer) Stop()

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, ledger ledger.Store, chain PovTxChainReader) *PovTxPool

func (*PovTxPool) Init

func (tp *PovTxPool) Init()

func (*PovTxPool) LastUpdated

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

func (*PovTxPool) OnPovBlockEvent added in v1.2.4

func (tp *PovTxPool) OnPovBlockEvent(event 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()

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) int64
	GenStateTrie(prevStateHash types.Hash, txs []*types.PovTransaction) (*trie.Trie, error)
	GetStateTrie(stateHash *types.Hash) *trie.Trie
	GetAccountState(trie *trie.Trie, address types.Address) *types.PovAccountState
}

type PovVerifyStat

type PovVerifyStat struct {
	Result    process.ProcessResult
	ErrMsg    string
	TxResults 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