Documentation ¶
Index ¶
- Variables
- func DivideSalary(totalSalary *big.Int, am *account.Manager, t *deputynode.TermRecord) []*deputynode.DeputySalary
- func GetMinerDistance(targetHeight uint32, parentBlockMiner, targetMiner common.Address, ...) (uint64, error)
- func IsConfirmEnough(block *types.Block, dm *deputynode.Manager) bool
- type BlockAssembler
- func (ba *BlockAssembler) Finalize(height uint32, am *account.Manager) error
- func (ba *BlockAssembler) MineBlock(parent *types.Block, extra []byte, txPool TxPool, timeLimitSeconds int64) (*types.Block, error)
- func (ba *BlockAssembler) RunBlock(block *types.Block) (*types.Block, error)
- func (ba *BlockAssembler) Seal(header *types.Header, txProduct *account.TxsProduct, confirms []types.SignData) *types.Block
- type BlockLoader
- type BlockMaterial
- type CandidateLoader
- type Config
- type Confirmer
- func (c *Confirmer) BatchConfirmStable(startHeight, endHeight uint32) []*network.BlockConfirmData
- func (c *Confirmer) NeedFetchedConfirms(startHeight, endHeight uint32) []network.GetConfirmInfo
- func (c *Confirmer) SaveConfirm(block *types.Block, sigList []types.SignData) (*types.Block, error)
- func (c *Confirmer) SetLastSig(block *types.Block)
- func (c *Confirmer) TryConfirm(block *types.Block) (types.SignData, bool)
- type DPoVP
- func (dp *DPoVP) CheckFork() bool
- func (dp *DPoVP) CurrentBlock() *types.Block
- func (dp *DPoVP) InsertBlock(rawBlock *types.Block) (*types.Block, error)
- func (dp *DPoVP) InsertConfirm(info *network.BlockConfirmData) error
- func (dp *DPoVP) InsertStableConfirms(pack network.BlockConfirms)
- func (dp *DPoVP) LoadTopCandidates(blockHash common.Hash) deputynode.DeputyNodes
- func (dp *DPoVP) MineBlock(material *BlockMaterial) (*types.Block, error)
- func (dp *DPoVP) StableBlock() *types.Block
- func (dp *DPoVP) SubscribeConfirm(ch chan *network.BlockConfirmData) subscribe.Subscription
- func (dp *DPoVP) SubscribeCurrent(ch chan *types.Block) subscribe.Subscription
- func (dp *DPoVP) SubscribeFetchConfirm(ch chan []network.GetConfirmInfo) subscribe.Subscription
- func (dp *DPoVP) SubscribeStable(ch chan *types.Block) subscribe.Subscription
- func (dp *DPoVP) TrySwitchFork()
- func (dp *DPoVP) TxProcessor() *transaction.TxProcessor
- func (dp *DPoVP) UpdateStable(block *types.Block) (bool, error)
- func (dp *DPoVP) VerifyAndSeal(block *types.Block) (*types.Block, error)
- type ForkManager
- type StableManager
- type TxPool
- type Validator
- func (v *Validator) JudgeDeputy(newBlock *types.Block) bool
- func (v *Validator) VerifyAfterTxProcess(block, computedBlock *types.Block) error
- func (v *Validator) VerifyBeforeTxProcess(block *types.Block) error
- func (v *Validator) VerifyConfirmPacket(height uint32, blockHash common.Hash, sigList []types.SignData) ([]types.SignData, error)
- func (v *Validator) VerifyNewConfirms(block *types.Block, sigList []types.SignData, dm *deputynode.Manager) ([]types.SignData, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrBlockNotExist = errors.New("block not exist in local") ErrIgnoreConfirm = errors.New("confirms is enough") ErrExistBlock = errors.New("block exist in local") ErrInvalidBlock = errors.New("invalid block") ErrSaveBlock = errors.New("save block to db error") ErrSaveAccount = errors.New("save account error") ErrVerifyHeaderFailed = errors.New("verify block's header error") ErrVerifyBlockFailed = errors.New("verify block error") ErrSnapshotIsNil = errors.New("local deputy nodes snapshot is nil") ErrInvalidConfirmSigner = errors.New("invalid confirm signer") ErrInvalidSignedConfirmInfo = errors.New("invalid signed data of confirm info") ErrMineGenesis = errors.New("can not mine genesis block") ErrNotDeputy = errors.New("not a deputy address in specific height") ErrSetStableBlockToDB = errors.New("set stable block to db error") ErrNoTermReward = errors.New("reward value has not been set") )
Functions ¶
func DivideSalary ¶
func DivideSalary(totalSalary *big.Int, am *account.Manager, t *deputynode.TermRecord) []*deputynode.DeputySalary
func GetMinerDistance ¶
func GetMinerDistance(targetHeight uint32, parentBlockMiner, targetMiner common.Address, dm *deputynode.Manager) (uint64, error)
GetMinerDistance get miner index distance. It is always greater than 0
func IsConfirmEnough ¶
func IsConfirmEnough(block *types.Block, dm *deputynode.Manager) bool
IsConfirmEnough test if the confirms in block is enough
Types ¶
type BlockAssembler ¶
type BlockAssembler struct {
// contains filtered or unexported fields
}
Assembler seal block
func NewBlockAssembler ¶
func NewBlockAssembler(am *account.Manager, dm *deputynode.Manager, txProcessor *transaction.TxProcessor, canLoader CandidateLoader) *BlockAssembler
func (*BlockAssembler) Finalize ¶
func (ba *BlockAssembler) Finalize(height uint32, am *account.Manager) error
Finalize increases miners' balance and fix all account changes
func (*BlockAssembler) MineBlock ¶
func (ba *BlockAssembler) MineBlock(parent *types.Block, extra []byte, txPool TxPool, timeLimitSeconds int64) (*types.Block, error)
MineBlock packages all products into a block
type BlockLoader ¶
type BlockLoader interface { // GetBlockByHash returns the hash corresponding to their hash. GetBlockByHash(hash common.Hash) *types.Block // GetBlockByHash returns the hash corresponding to their hash. GetParentByHeight(height uint32, sonBlockHash common.Hash) *types.Block }
BlockLoader supports retrieving headers and consensus parameters from the current blockchain to be used during transaction processing.
type BlockMaterial ¶
type BlockMaterial struct { Extra []byte MineTimeLimit int64 Txs types.Transactions Deputies deputynode.DeputyNodes }
BlockMaterial is used for mine a new block
type CandidateLoader ¶
type CandidateLoader interface {
LoadTopCandidates(blockHash common.Hash) deputynode.DeputyNodes
}
type Config ¶
type Config struct { // Show every forks change LogForks bool // RewardManager is the owner of reward setting precompiled contract RewardManager common.Address ChainID uint16 MineTimeout uint64 }
Config holds consensus options.
type Confirmer ¶
type Confirmer struct {
// contains filtered or unexported fields
}
Confirmer process the confirm logic
func NewConfirmer ¶
func (*Confirmer) BatchConfirmStable ¶
func (c *Confirmer) BatchConfirmStable(startHeight, endHeight uint32) []*network.BlockConfirmData
BatchConfirmStable confirm and broadcast unsigned stable blocks one by one
func (*Confirmer) NeedFetchedConfirms ¶
func (c *Confirmer) NeedFetchedConfirms(startHeight, endHeight uint32) []network.GetConfirmInfo
NeedFetchedConfirms
func (*Confirmer) SaveConfirm ¶
SaveConfirm save a confirm to store, then return a new block
type DPoVP ¶
type DPoVP struct {
// contains filtered or unexported fields
}
DPoVP process the fork logic
func (*DPoVP) CheckFork ¶
CheckFork check the current fork and update it if it is cut. Return true if the current fork change
func (*DPoVP) CurrentBlock ¶
func (*DPoVP) InsertBlock ¶
func (*DPoVP) InsertConfirm ¶
func (dp *DPoVP) InsertConfirm(info *network.BlockConfirmData) error
func (*DPoVP) InsertStableConfirms ¶
func (dp *DPoVP) InsertStableConfirms(pack network.BlockConfirms)
InsertStableConfirms receive confirm package from net connection. The block of these confirms has been confirmed by its son block already
func (*DPoVP) LoadTopCandidates ¶
func (dp *DPoVP) LoadTopCandidates(blockHash common.Hash) deputynode.DeputyNodes
SnapshotDeputyNodes get next epoch deputy nodes for snapshot block
func (*DPoVP) StableBlock ¶
func (*DPoVP) SubscribeConfirm ¶
func (dp *DPoVP) SubscribeConfirm(ch chan *network.BlockConfirmData) subscribe.Subscription
SubscribeConfirm subscribe the new confirm notification
func (*DPoVP) SubscribeCurrent ¶
func (dp *DPoVP) SubscribeCurrent(ch chan *types.Block) subscribe.Subscription
SubscribeCurrent subscribe the current block update notification. The blocks may be not continuous
func (*DPoVP) SubscribeFetchConfirm ¶
func (dp *DPoVP) SubscribeFetchConfirm(ch chan []network.GetConfirmInfo) subscribe.Subscription
SubscribeFetchConfirm subscribe fetch block confirms
func (*DPoVP) SubscribeStable ¶
func (dp *DPoVP) SubscribeStable(ch chan *types.Block) subscribe.Subscription
SubscribeStable subscribe the stable block update notification
func (*DPoVP) TrySwitchFork ¶
func (dp *DPoVP) TrySwitchFork()
TrySwitchFork try to switch to a better fork
func (*DPoVP) TxProcessor ¶
func (dp *DPoVP) TxProcessor() *transaction.TxProcessor
func (*DPoVP) UpdateStable ¶
UpdateStable check if the block can be stable. Then send notification and return true if the stable block changed
type ForkManager ¶
type ForkManager struct {
// contains filtered or unexported fields
}
ForkManager process the fork logic
func NewForkManager ¶
func NewForkManager(dm *deputynode.Manager, db protocol.ChainDB, stable *types.Block) *ForkManager
func (*ForkManager) ChooseNewFork ¶
func (fm *ForkManager) ChooseNewFork() *types.Block
ChooseNewFork choose a fork and return the last block on the fork. It would return nil if there is no unstable block
func (*ForkManager) GetHeadBlock ¶
func (fm *ForkManager) GetHeadBlock() *types.Block
CurrentBlock get latest block on current fork
func (*ForkManager) SetHeadBlock ¶
func (fm *ForkManager) SetHeadBlock(block *types.Block)
CurrentBlock get latest block on current fork
func (*ForkManager) TrySwitchFork ¶
TrySwitchFork switch fork if its length reached to a multiple of "deputy nodes count * 2/3"
type StableManager ¶
type StableManager struct {
// contains filtered or unexported fields
}
StableManager process the fork logic
func NewStableManager ¶
func NewStableManager(dm *deputynode.Manager, db protocol.ChainDB) *StableManager
func (*StableManager) StableBlock ¶
func (sm *StableManager) StableBlock() *types.Block
StableBlock get latest stable block
func (*StableManager) UpdateStable ¶
UpdateStable check if the block can be stable. Return true if the stable block changed, and return the pruned uncle blocks
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator verify block
func NewValidator ¶
func NewValidator(timeout uint64, db protocol.ChainDB, dm *deputynode.Manager, txPool TxPool, canLoader CandidateLoader) *Validator
func (*Validator) JudgeDeputy ¶
JudgeDeputy check if the deputy node is evil by his new block
func (*Validator) VerifyAfterTxProcess ¶
VerifyAfterTxProcess verify the block data which computed from transactions
func (*Validator) VerifyBeforeTxProcess ¶
VerifyBeforeTxProcess verify the block data which has no relationship with the transaction processing result