Documentation ¶
Index ¶
- Variables
- func DivideSalary(totalSalary *big.Int, am *account.Manager, t *deputynode.TermRecord) []*deputynode.DeputySalary
- func GetCorrectMiner(parent *types.Header, mineTime int64, mineTimeout int64, ...) (common.Address, error)
- func GetNextMineWindow(nextHeight uint32, distance uint32, parentTime int64, currentTime int64, ...) (int64, int64)
- func IsConfirmEnough(block *types.Block, dm *deputynode.Manager) bool
- func IsMinedByself(block *types.Block) bool
- func IsSigExist(sigs []types.SignData, sig types.SignData) bool
- func SignBlock(blockHash common.Hash) ([]byte, error)
- type BlockAssembler
- func (ba *BlockAssembler) Finalize(height uint32) error
- func (ba *BlockAssembler) MineBlock(header *types.Header, txs types.Transactions, applyTxTimeout int64) (*types.Block, types.Transactions, error)
- func (ba *BlockAssembler) PrepareHeader(parentHeader *types.Header, extra string) (*types.Header, 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) NeedConfirmList(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) CurrentBlock() *types.Block
- func (dp *DPoVP) FetchRemoteConfirms(startHeight, endHeight uint32, delay time.Duration)
- func (dp *DPoVP) InsertBlock(rawBlock *types.Block) (*types.Block, error)
- func (dp *DPoVP) InsertConfirms(height uint32, blockHash common.Hash, sigList []types.SignData) error
- func (dp *DPoVP) LoadRefundCandidates(height uint32) ([]common.Address, error)
- func (dp *DPoVP) LoadTopCandidates(blockHash common.Hash) types.DeputyNodes
- func (dp *DPoVP) MineBlock(txProcessTimeout int64) (*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) TxGuard() *txpool.TxGuard
- 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
- func (fm *ForkManager) ChooseNewFork(stableBlock *types.Block) *types.Block
- func (fm *ForkManager) GetHeadBlock() *types.Block
- func (fm *ForkManager) SetHeadBlock(block *types.Block)
- func (fm *ForkManager) UpdateFork(newBlock, stableBlock *types.Block) bool
- func (fm *ForkManager) UpdateForkForConfirm(stableBlock *types.Block) bool
- type StableBlockStore
- type StableManager
- type TxGuard
- 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, chainId uint16) error
- func (v *Validator) VerifyConfirmPacket(height uint32, blockHash common.Hash, sigList []types.SignData) ([]types.SignData, error)
- func (v *Validator) VerifyMiner(header *types.Header, parent *types.Header) 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") ErrConfirmsEnough = errors.New("confirms are enough") ErrNoNewConfirm = errors.New("no useful confirm") ErrIgnoreBlock = errors.New("block exist in local or the height of block is too small") 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") ErrExistedConfirm = errors.New("existed confirm info") ErrMineGenesis = errors.New("can not mine genesis block") ErrNotDeputy = errors.New("not a deputy address in specific height") ErrSmallerMineTime = errors.New("the time of block must not be smaller than parent's") ErrSetStableBlockToDB = errors.New("set stable block to db error") ErrSaveConfirmToDB = errors.New("save confirm to db error") ErrNoTermReward = errors.New("reward value has not been set") )
var ErrNoHeadBlock = errors.New("head block is required")
Functions ¶
func DivideSalary ¶
func DivideSalary(totalSalary *big.Int, am *account.Manager, t *deputynode.TermRecord) []*deputynode.DeputySalary
func GetCorrectMiner ¶ added in v1.4.0
func GetCorrectMiner(parent *types.Header, mineTime int64, mineTimeout int64, dm *deputynode.Manager) (common.Address, error)
GetCorrectMiner get the correct miner to mine a block after parent block
func GetNextMineWindow ¶ added in v1.4.0
func GetNextMineWindow(nextHeight uint32, distance uint32, parentTime int64, currentTime int64, mineTimeout int64, dm *deputynode.Manager) (int64, int64)
GetNextMineWindow get next time window to mine block. The times are timestamps in millisecond
func IsConfirmEnough ¶
func IsConfirmEnough(block *types.Block, dm *deputynode.Manager) bool
IsConfirmEnough test if the confirms in block is enough
func IsMinedByself ¶ added in v1.4.0
func IsSigExist ¶ added in v1.4.0
IsSigExist
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) error
Finalize increases miners' balance and fix all account changes
func (*BlockAssembler) MineBlock ¶
func (ba *BlockAssembler) MineBlock(header *types.Header, txs types.Transactions, applyTxTimeout int64) (*types.Block, types.Transactions, error)
MineBlock packages all products into a block
func (*BlockAssembler) PrepareHeader ¶ added in v1.4.0
type BlockLoader ¶
type BlockLoader interface { IterateUnConfirms(fn func(*types.Block)) GetUnConfirmByHeight(height uint32, leafBlockHash common.Hash) (*types.Block, error) GetBlockByHash(hash common.Hash) (*types.Block, error) // GetBlockByHeight returns stable blocks GetBlockByHeight(height uint32) (*types.Block, error) }
BlockLoader is the interface of ChainDB
type BlockMaterial ¶
type BlockMaterial struct { ParentHeader *types.Header Time uint32 // new block time in header Extra []byte Txs types.Transactions }
BlockMaterial is used for mine a new block
type CandidateLoader ¶
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 MinerExtra string // Extra data in mined block header. It is shorter than 256bytes }
Config holds consensus options.
type Confirmer ¶
type Confirmer struct {
// contains filtered or unexported fields
}
Confirmer process the confirm logic
func NewConfirmer ¶
func NewConfirmer(dm *deputynode.Manager, blockLoader BlockLoader, confirmStore confirmWriter, stableLoader StableBlockStore) *Confirmer
func (*Confirmer) BatchConfirmStable ¶
func (c *Confirmer) BatchConfirmStable(startHeight, endHeight uint32) []*network.BlockConfirmData
BatchConfirmStable confirm and broadcast unsigned stable blocks one by one
func (*Confirmer) NeedConfirmList ¶ added in v1.4.0
func (c *Confirmer) NeedConfirmList(startHeight, endHeight uint32) []network.GetConfirmInfo
NeedConfirmList
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 NewDPoVP ¶ added in v1.4.0
func NewDPoVP(config Config, db protocol.ChainDB, dm *deputynode.Manager, am *account.Manager, loader transaction.ParentBlockLoader, txPool *txpool.TxPool, txGuard *txpool.TxGuard) *DPoVP
func (*DPoVP) CurrentBlock ¶
func (*DPoVP) FetchRemoteConfirms ¶ added in v1.4.0
FetchRemoteConfirms fetch confirms from remote peer after the [delay] seconds
func (*DPoVP) InsertBlock ¶
func (*DPoVP) InsertConfirms ¶ added in v1.4.0
func (*DPoVP) LoadRefundCandidates ¶ added in v1.4.0
LoadRefundCandidates get the address list of candidates who need to refund
func (*DPoVP) LoadTopCandidates ¶
func (dp *DPoVP) LoadTopCandidates(blockHash common.Hash) types.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) 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 BlockLoader, stable *types.Block) *ForkManager
func (*ForkManager) ChooseNewFork ¶
func (fm *ForkManager) ChooseNewFork(stableBlock *types.Block) *types.Block
ChooseNewFork choose a fork and return the last block on the fork. It would return the current stable block 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) UpdateFork ¶ added in v1.4.0
func (fm *ForkManager) UpdateFork(newBlock, stableBlock *types.Block) bool
UpdateFork check if the current fork can be update, or switch to a better fork. Return true if the current block changed
func (*ForkManager) UpdateForkForConfirm ¶ added in v1.4.0
func (fm *ForkManager) UpdateForkForConfirm(stableBlock *types.Block) bool
UpdateForkForConfirm switch to a better fork if the current fork is not exist. Return true if the new current block changed
type StableBlockStore ¶ added in v1.4.0
type StableBlockStore interface { LoadLatestBlock() (*types.Block, error) SetStableBlock(hash common.Hash) ([]*types.Block, error) }
StableBlockStore is the interface of ChainDB
type StableManager ¶
type StableManager struct {
// contains filtered or unexported fields
}
StableManager process the fork logic
func NewStableManager ¶
func NewStableManager(dm *deputynode.Manager, store StableBlockStore) *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 TxGuard ¶ added in v1.4.0
type TxGuard interface {
ExistTxs(startBlockHash common.Hash, txs types.Transactions) bool
}
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator verify block
func NewValidator ¶
func NewValidator(mineTimeout uint64, blockLoader BlockLoader, dm *deputynode.Manager, txGuard TxGuard, 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
func (*Validator) VerifyConfirmPacket ¶
func (v *Validator) VerifyConfirmPacket(height uint32, blockHash common.Hash, sigList []types.SignData) ([]types.SignData, error)
VerifyConfirmPacket verify the confirm data in block body, return valid new confirms and last confirm verification error
func (*Validator) VerifyMiner ¶ added in v1.4.0
VerifyMiner verify the miner slot of deputy node