consensus

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: LGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func (*BlockAssembler) RunBlock

func (ba *BlockAssembler) RunBlock(block *types.Block) (*types.Block, error)

Seal packages all products into a block

func (*BlockAssembler) Seal

func (ba *BlockAssembler) Seal(header *types.Header, txProduct *account.TxsProduct, confirms []types.SignData) *types.Block

Seal 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 NewConfirmer(dm *deputynode.Manager, db protocol.ChainDB, stable *types.Block) *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) NeedFetchedConfirms

func (c *Confirmer) NeedFetchedConfirms(startHeight, endHeight uint32) []network.GetConfirmInfo

NeedFetchedConfirms

func (*Confirmer) SaveConfirm

func (c *Confirmer) SaveConfirm(block *types.Block, sigList []types.SignData) (*types.Block, error)

SaveConfirm save a confirm to store, then return a new block

func (*Confirmer) SetLastSig

func (c *Confirmer) SetLastSig(block *types.Block)

SetLastSig

func (*Confirmer) TryConfirm

func (c *Confirmer) TryConfirm(block *types.Block) (types.SignData, bool)

TryConfirm try to sign and save a confirm into a received block

type DPoVP

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

DPoVP process the fork logic

func NewDpovp

func NewDpovp(config Config, db protocol.ChainDB, dm *deputynode.Manager, am *account.Manager, loader BlockLoader, txPool TxPool, stable *types.Block) *DPoVP

func (*DPoVP) CheckFork

func (dp *DPoVP) CheckFork() bool

CheckFork check the current fork and update it if it is cut. Return true if the current fork change

func (*DPoVP) CurrentBlock

func (dp *DPoVP) CurrentBlock() *types.Block

func (*DPoVP) InsertBlock

func (dp *DPoVP) InsertBlock(rawBlock *types.Block) (*types.Block, error)

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

func (dp *DPoVP) MineBlock(material *BlockMaterial) (*types.Block, error)

func (*DPoVP) StableBlock

func (dp *DPoVP) StableBlock() *types.Block

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

func (dp *DPoVP) UpdateStable(block *types.Block) (bool, error)

UpdateStable check if the block can be stable. Then send notification and return true if the stable block changed

func (*DPoVP) VerifyAndSeal

func (dp *DPoVP) VerifyAndSeal(block *types.Block) (*types.Block, error)

VerifyAndSeal verify block then create a new block

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

func (fm *ForkManager) TrySwitchFork(stable, current *types.Block) (*types.Block, bool)

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

func (sm *StableManager) UpdateStable(block *types.Block) (bool, []*types.Block, error)

UpdateStable check if the block can be stable. Return true if the stable block changed, and return the pruned uncle blocks

type TxPool

type TxPool interface {
	Get(time uint32, size int) []*types.Transaction
	DelInvalidTxs(txs []*types.Transaction)
	VerifyTxInBlock(block *types.Block) bool
	RecvBlock(block *types.Block)
	PruneBlock(block *types.Block)
}

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

func (v *Validator) JudgeDeputy(newBlock *types.Block) bool

JudgeDeputy check if the deputy node is evil by his new block

func (*Validator) VerifyAfterTxProcess

func (v *Validator) VerifyAfterTxProcess(block, computedBlock *types.Block) error

VerifyAfterTxProcess verify the block data which computed from transactions

func (*Validator) VerifyBeforeTxProcess

func (v *Validator) VerifyBeforeTxProcess(block *types.Block) error

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

func (v *Validator) VerifyNewConfirms(block *types.Block, sigList []types.SignData, dm *deputynode.Manager) ([]types.SignData, error)

verifyConfirm verify the confirm data, return valid new confirms and last confirm verification error

Jump to

Keyboard shortcuts

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