Documentation ¶
Index ¶
- Constants
- Variables
- type ChainState
- type ConsensusFake
- func (c *ConsensusFake) FinalizeHeader(header *types.PovHeader) error
- func (c *ConsensusFake) Init() error
- func (c *ConsensusFake) PrepareHeader(header *types.PovHeader) error
- func (c *ConsensusFake) SealHeader(header *types.PovHeader, cbAccount *types.Account, quitCh chan struct{}, ...) error
- func (c *ConsensusFake) Start() error
- func (c *ConsensusFake) Stop() error
- func (c *ConsensusFake) VerifyHeader(header *types.PovHeader) error
- type ConsensusPov
- type ConsensusPow
- func (c *ConsensusPow) FinalizeHeader(header *types.PovHeader) error
- func (c *ConsensusPow) Init() error
- func (c *ConsensusPow) PrepareHeader(header *types.PovHeader) error
- func (c *ConsensusPow) SealHeader(header *types.PovHeader, cbAccount *types.Account, quitCh chan struct{}, ...) error
- func (c *ConsensusPow) Start() error
- func (c *ConsensusPow) Stop() error
- func (c *ConsensusPow) VerifyHeader(header *types.PovHeader) error
- type EventListener
- type PoVEngine
- func (pov *PoVEngine) AddBlock(block *types.PovBlock, from types.PovBlockFrom, peerID string) error
- func (pov *PoVEngine) AddMinedBlock(block *types.PovBlock) error
- func (pov *PoVEngine) GetAccounts() []*types.Account
- func (pov *PoVEngine) GetChain() *PovBlockChain
- func (pov *PoVEngine) GetConfig() *config.Config
- func (pov *PoVEngine) GetConsensus() ConsensusPov
- func (pov *PoVEngine) GetEventBus() event.EventBus
- func (pov *PoVEngine) GetLedger() ledger.Store
- func (pov *PoVEngine) GetLogger() *zap.SugaredLogger
- func (pov *PoVEngine) GetSyncState() common.SyncState
- func (pov *PoVEngine) GetSyncer() *PovSyncer
- func (pov *PoVEngine) GetTxPool() *PovTxPool
- func (pov *PoVEngine) GetVerifier() *PovVerifier
- func (pov *PoVEngine) Init() error
- func (pov *PoVEngine) Start() error
- func (pov *PoVEngine) Stop() error
- type PovBlockChain
- func (bc *PovBlockChain) ApplyTransaction(trie *trie.Trie, stateBlock *types.StateBlock) error
- func (bc *PovBlockChain) CalcPastMedianTime(prevHeader *types.PovHeader) int64
- func (bc *PovBlockChain) CalcTotalDifficulty(target types.Signature) *big.Int
- func (bc *PovBlockChain) FindAncestor(header *types.PovHeader, height uint64) *types.PovHeader
- func (bc *PovBlockChain) GenStateTrie(prevStateHash types.Hash, txs []*types.PovTransaction) (*trie.Trie, error)
- func (bc *PovBlockChain) GenesisBlock() *types.PovBlock
- func (bc *PovBlockChain) GetAccountState(trie *trie.Trie, address types.Address) *types.PovAccountState
- func (bc *PovBlockChain) GetBestBlockByHash(hash types.Hash) *types.PovBlock
- func (bc *PovBlockChain) GetBlockByHash(hash types.Hash) *types.PovBlock
- func (bc *PovBlockChain) GetBlockByHeight(height uint64) (*types.PovBlock, error)
- func (bc *PovBlockChain) GetBlockLocator(hash types.Hash) []*types.Hash
- func (bc *PovBlockChain) GetBlockTDByHash(hash types.Hash) *big.Int
- func (bc *PovBlockChain) GetBlockTDByHashAndHeight(hash types.Hash, height uint64) *big.Int
- func (bc *PovBlockChain) GetHeaderByHash(hash types.Hash) *types.PovHeader
- func (bc *PovBlockChain) GetHeaderByHeight(height uint64) *types.PovHeader
- func (bc *PovBlockChain) GetStateTrie(stateHash *types.Hash) *trie.Trie
- func (bc *PovBlockChain) HasBestBlock(hash types.Hash, height uint64) bool
- func (bc *PovBlockChain) HasFullBlock(hash types.Hash, height uint64) bool
- func (bc *PovBlockChain) HasHeader(hash types.Hash, height uint64) bool
- func (bc *PovBlockChain) Init() error
- func (bc *PovBlockChain) InsertBlock(block *types.PovBlock, stateTrie *trie.Trie) error
- func (bc *PovBlockChain) IsGenesisBlock(block *types.PovBlock) bool
- func (bc *PovBlockChain) LatestBlock() *types.PovBlock
- func (bc *PovBlockChain) LatestHeader() *types.PovHeader
- func (bc *PovBlockChain) LocateBestBlock(locator []*types.Hash) *types.PovBlock
- func (bc *PovBlockChain) NewStateTrie() *trie.Trie
- func (bc *PovBlockChain) RegisterListener(listener EventListener)
- func (bc *PovBlockChain) RelativeAncestor(header *types.PovHeader, distance uint64) *types.PovHeader
- func (bc *PovBlockChain) ResetChainState() error
- func (bc *PovBlockChain) SetAccountState(trie *trie.Trie, address types.Address, as *types.PovAccountState)
- func (bc *PovBlockChain) Start() error
- func (bc *PovBlockChain) Stop() error
- func (bc *PovBlockChain) StoreLatestBlock(block *types.PovBlock)
- func (bc *PovBlockChain) TrieDb() db.Store
- func (bc *PovBlockChain) UnRegisterListener(listener EventListener)
- type PovBlockProcessor
- func (bp *PovBlockProcessor) AddBlock(block *types.PovBlock, from types.PovBlockFrom, peerID string) error
- func (bp *PovBlockProcessor) AddMinedBlock(block *types.PovBlock) error
- func (bp *PovBlockProcessor) GetOrphanRoot(oHash types.Hash) types.Hash
- func (bp *PovBlockProcessor) HasOrphanBlock(blockHash types.Hash) bool
- func (bp *PovBlockProcessor) HasPendingBlock(blockHash types.Hash) bool
- func (bp *PovBlockProcessor) Init() error
- func (bp *PovBlockProcessor) Start() error
- func (bp *PovBlockProcessor) Stop() error
- type PovBlockResult
- type PovBlockSource
- type PovConsensusChainReader
- type PovOrphanBlock
- type PovPendingBlock
- type PovProcessorChainReader
- type PovProcessorSyncer
- type PovProcessorVerifier
- type PovSyncEvent
- type PovSyncMessage
- type PovSyncPeer
- type PovSyncPeerSetByHeight
- type PovSyncPeerSetByTD
- type PovSyncer
- func (ss *PovSyncer) FindPeer(peerID string) *PovSyncPeer
- func (ss *PovSyncer) FindPeerWithStatus(peerID string, status int) *PovSyncPeer
- func (ss *PovSyncer) GetBestPeer(lastPeerID string) *PovSyncPeer
- func (ss *PovSyncer) GetBestPeers(limit int) []*PovSyncPeer
- func (ss *PovSyncer) GetPeerLocators() []*PovSyncPeer
- func (ss *PovSyncer) GetRandomPeers(limit int) []*PovSyncPeer
- func (ss *PovSyncer) GetRandomTopPeer(top int) *PovSyncPeer
- func (ss *PovSyncer) PeerCount() int
- func (ss *PovSyncer) PeerCountWithStatus(status int) int
- func (ss *PovSyncer) Start()
- func (ss *PovSyncer) Stop()
- type PovTxChainReader
- type PovTxEntry
- type PovTxEvent
- type PovTxPendingEntry
- type PovTxPool
- type PovVerifier
- func (pv *PovVerifier) BlockCheck(block types.Block) (process.ProcessResult, error)
- func (pv *PovVerifier) Process(block types.Block) (process.ProcessResult, error)
- func (pv *PovVerifier) VerifyFull(block *types.PovBlock) *PovVerifyStat
- func (pv *PovVerifier) VerifyNet(block *types.PovBlock) *PovVerifyStat
- type PovVerifierChainReader
- type PovVerifyStat
Constants ¶
const ( PovConsensusModeFake = iota PovConsensusModePow )
const ( EventConnectPovBlock = byte(1) EventDisconnectPovBlock = byte(2) )
Variables ¶
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 (*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 (*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 PoVEngine ¶
type PoVEngine struct {
// contains filtered or unexported fields
}
func NewPovEngine ¶
func (*PoVEngine) GetAccounts ¶
func (*PoVEngine) GetChain ¶
func (pov *PoVEngine) GetChain() *PovBlockChain
func (*PoVEngine) GetConsensus ¶
func (pov *PoVEngine) GetConsensus() ConsensusPov
func (*PoVEngine) GetEventBus ¶
func (*PoVEngine) GetLogger ¶
func (pov *PoVEngine) GetLogger() *zap.SugaredLogger
func (*PoVEngine) GetSyncState ¶
func (*PoVEngine) GetVerifier ¶
func (pov *PoVEngine) GetVerifier() *PovVerifier
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 (*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 (*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 (*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 (*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 NewPovBlockProcessor ¶
func NewPovBlockProcessor(eb event.EventBus, ledger ledger.Store, chain PovProcessorChainReader, verifier PovProcessorVerifier, syncer PovProcessorSyncer) *PovBlockProcessor
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 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 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 (*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) PeerCountWithStatus ¶
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 (*PovTxPool) LastUpdated ¶
func (*PovTxPool) OnPovBlockEvent ¶ added in v1.2.4
func (*PovTxPool) SelectPendingTxs ¶
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