logical

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package logical implements the whole logic of the consensus engine. Including the verifyGroup manager process

Index

Constants

View Source
const ConsensusConfSection = "consensus"
View Source
const TimestampLayout = "2006-01-02/15:04:05.000"

Variables

This section is empty.

Functions

func InitConsensus

func InitConsensus()

Types

type FutureMessageHolder

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

FutureMessageHolder store some messages non-processable currently and may be processed in the future

func NewFutureMessageHolder

func NewFutureMessageHolder() *FutureMessageHolder

type MinerPoolReader

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

MinerPoolReader provides some functions for access to the miner pool

func (*MinerPoolReader) GetCanJoinGroupMinersAt

func (access *MinerPoolReader) GetCanJoinGroupMinersAt(h uint64) []*model.MinerDO

func (*MinerPoolReader) GetLatestVerifyMiner

func (access *MinerPoolReader) GetLatestVerifyMiner(id groupsig.ID) *model.MinerDO

func (*MinerPoolReader) SelfMinerInfo

func (access *MinerPoolReader) SelfMinerInfo() *model.SelfMinerDO

type Processor

type Processor struct {
	Ticker *ticker.GlobalTicker // Global timer responsible for some cron tasks

	MainChain types.BlockChain // Blockchain access interface

	NetServer net.NetworkServer // Responsible for network messaging
	// contains filtered or unexported fields
}

Processor is the consensus engine implementation struct that implements all the consensus logic and contextual information needed in the consensus process

func (*Processor) AddTransaction

func (p *Processor) AddTransaction(tx *types.Transaction) (bool, error)

func (*Processor) CalcBlockHeaderQN

func (p *Processor) CalcBlockHeaderQN(bh *types.BlockHeader) uint64

CalcBlockHeaderQN calculates the qn value of the given block header

func (*Processor) CalcVerifyGroup

func (p *Processor) CalcVerifyGroup(preBH *types.BlockHeader, height uint64) common.Hash

func (*Processor) GetAllMinerDOs

func (p *Processor) GetAllMinerDOs() []*model.MinerDO

GetAllMinerDOs returns all available miner infos

func (*Processor) GetBlockHeaderByHash

func (p *Processor) GetBlockHeaderByHash(hash common.Hash) *types.BlockHeader

func (*Processor) GetBlockMinElapse

func (p *Processor) GetBlockMinElapse(height uint64) int32

GetBlockMinElapse return the min elapsed milliseconds for blocks

func (*Processor) GetGroupBySeed

func (p *Processor) GetGroupBySeed(seed common.Hash) *verifyGroup

func (*Processor) GetGroupSignatureSeckey

func (p *Processor) GetGroupSignatureSeckey(seed common.Hash) groupsig.Seckey

func (Processor) GetMinerID

func (p Processor) GetMinerID() groupsig.ID

GetMinerID get current miner ID

func (Processor) GetMinerInfo

func (p Processor) GetMinerInfo() *model.MinerDO

func (*Processor) GetRewardManager

func (p *Processor) GetRewardManager() types.RewardManager

func (*Processor) GetVctxByHeight

func (p *Processor) GetVctxByHeight(height uint64) *VerifyContext

func (*Processor) GetVrfThreshold

func (p *Processor) GetVrfThreshold(stake uint64) float64

GetVrfThreshold returns the vrf threshold of current node under the specified stake

func (*Processor) GroupSkipCountsBetween

func (p *Processor) GroupSkipCountsBetween(preBH *types.BlockHeader, h uint64) map[common.Hash]uint16

func (*Processor) Init

func (p *Processor) Init(mi model.SelfMinerDO, conf common.ConfManager) bool

Init initialize the process engine

func (*Processor) OnMessageCast

func (p *Processor) OnMessageCast(ccm *model.ConsensusCastMessage) (err error)

OnMessageCast handles the message from the proposer Note that, if the pre-block of the block present int the message isn't on the blockchain, it will caches the message and trigger it after the pre-block added on chain

func (*Processor) OnMessageCastRewardSign

func (p *Processor) OnMessageCastRewardSign(msg *model.CastRewardTransSignMessage) error

OnMessageCastRewardSign receives signed messages for the reward transaction from verifyGroup members If threshold signature received and the verifyGroup signature recovered successfully, the node will submit the reward transaction to the pool

func (*Processor) OnMessageCastRewardSignReq

func (p *Processor) OnMessageCastRewardSignReq(msg *model.CastRewardTransSignReqMessage) error

OnMessageCastRewardSignReq handles reward transaction signature requests It signs the message if and only if the block of the transaction already added on chain, otherwise the message will be cached util the condition met

func (*Processor) OnMessageReqProposalBlock

func (p *Processor) OnMessageReqProposalBlock(msg *model.ReqProposalBlock, sourceID string) (err error)

OnMessageReqProposalBlock handles block body request from the verify verifyGroup members It only happens in the proposal role and when the verifyGroup signature generated by the verify-verifyGroup

func (*Processor) OnMessageResponseProposalBlock

func (p *Processor) OnMessageResponseProposalBlock(msg *model.ResponseProposalBlock) (err error)

OnMessageResponseProposalBlock handles block body response from proposal node It only happens in the verify roles and after block body request to the proposal node It will add the block on chain and then broadcast

func (*Processor) OnMessageVerify

func (p *Processor) OnMessageVerify(cvm *model.ConsensusVerifyMessage) (err error)

OnMessageVerify handles the verification messages from other members in the verifyGroup for a specified block proposal Note that, it will cache the messages if the corresponding proposal message doesn't come yet and trigger them as long as the condition met

func (*Processor) Ready

func (p *Processor) Ready() bool

Ready check if the processor engine is initialized and ready for message processing

func (*Processor) SendCastRewardSign

func (p *Processor) SendCastRewardSign(msg *model.CastRewardTransSignMessage)

func (*Processor) SendCastRewardSignReq

func (p *Processor) SendCastRewardSignReq(msg *model.CastRewardTransSignReqMessage)

func (*Processor) Start

func (p *Processor) Start() bool

Start starts miner process

func (*Processor) Stop

func (p *Processor) Stop()

Stop is reserved interface

func (*Processor) VerifyBlock

func (p *Processor) VerifyBlock(bh *types.BlockHeader, preBH *types.BlockHeader) (ok bool, err error)

VerifyBlock check if the block is legal, it will take the pre-block into consideration

func (*Processor) VerifyBlockHeaders

func (p *Processor) VerifyBlockHeaders(pre, bh *types.BlockHeader) (ok bool, err error)

VerifyBlockHeaders checks if the group is legal and the group signature is correct

func (*Processor) VerifyBlockSign

func (p *Processor) VerifyBlockSign(bh *types.BlockHeader) (ok bool, err error)

VerifyBlockSign mainly check the verifyGroup signature of the block

func (*Processor) VerifyRewardTransaction

func (p *Processor) VerifyRewardTransaction(tx *types.Transaction) (ok bool, err error)

type ProcessorInterface

type ProcessorInterface interface {
	GetMinerID() groupsig.ID
	GetRewardManager() types.RewardManager
	GetBlockHeaderByHash(hash common.Hash) *types.BlockHeader
	GetVctxByHeight(height uint64) *VerifyContext
	GetGroupBySeed(seed common.Hash) *verifyGroup
	GetGroupSignatureSeckey(seed common.Hash) groupsig.Seckey

	AddTransaction(tx *types.Transaction) (bool, error)

	SendCastRewardSign(msg *model.CastRewardTransSignMessage)
	SendCastRewardSignReq(msg *model.CastRewardTransSignReqMessage)
}

type RewardHandler

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

func NewRewardHandler

func NewRewardHandler(pi ProcessorInterface) *RewardHandler

func (*RewardHandler) OnMessageCastRewardSign

func (rh *RewardHandler) OnMessageCastRewardSign(msg *model.CastRewardTransSignMessage) error

OnMessageCastRewardSign receives signed messages for the reward transaction from verifyGroup members If threshold signature received and the verifyGroup signature recovered successfully, the node will submit the reward transaction to the pool

func (*RewardHandler) OnMessageCastRewardSignReq

func (rh *RewardHandler) OnMessageCastRewardSignReq(msg *model.CastRewardTransSignReqMessage) error

OnMessageCastRewardSignReq handles reward transaction signature requests It signs the message if and only if the block of the transaction already added on chain, otherwise the message will be cached util the condition met

func (*RewardHandler) TriggerFutureRewardSign

func (rh *RewardHandler) TriggerFutureRewardSign(bh *types.BlockHeader)

type SlotContext

type SlotContext struct {

	// Verification related
	BH *types.BlockHeader // Detailed data in block header
	// contains filtered or unexported fields
}

SlotContext stores the contextual infos of a specified block proposal

func (*SlotContext) AcceptRewardPiece

func (sc *SlotContext) AcceptRewardPiece(sd *model.SignData) (accept, recover bool)

AcceptRewardPiece try to accept the signature piece of the reward transaction consensus

func (*SlotContext) AcceptVerifyPiece

func (sc *SlotContext) AcceptVerifyPiece(signer groupsig.ID, sign groupsig.Signature, randomSign groupsig.Signature) (ret int8, err error)

AcceptVerifyPiece received an in-verifyGroup verification signature piece

Returns:

1, the verification piece is accepted and the threshold not reached
2, the verification piece is accepted and the threshold reached
-1, piece denied

func (*SlotContext) GetAggregatedSign

func (sc *SlotContext) GetAggregatedSign() *groupsig.Signature

GetAggregatedSign returns the aggregated signature of proposer and verifier-verifyGroup

func (*SlotContext) GetSlotStatus

func (sc *SlotContext) GetSlotStatus() int32

func (*SlotContext) IsFailed

func (sc *SlotContext) IsFailed() bool

func (*SlotContext) IsRecovered

func (sc *SlotContext) IsRecovered() bool

func (*SlotContext) IsRewardSent

func (sc *SlotContext) IsRewardSent() bool

func (*SlotContext) IsSuccess

func (sc *SlotContext) IsSuccess() bool

func (*SlotContext) IsVerified

func (sc *SlotContext) IsVerified() bool

func (*SlotContext) IsWaiting

func (sc *SlotContext) IsWaiting() bool

func (SlotContext) MessageSize

func (sc SlotContext) MessageSize() int

func (*SlotContext) VerifyGroupSigns

func (sc *SlotContext) VerifyGroupSigns(pk groupsig.Pubkey, preRandom []byte) bool

VerifyGroupSigns verifies both the verifyGroup signature and the random number(also a signature in fact)

type VerifyContext

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

VerifyContext stores the context of verification consensus of each height. It is unique to each height which means replacement will take place when two different instance created for only one height

func (*VerifyContext) Clear

func (vc *VerifyContext) Clear()

Clear release the slot

func (*VerifyContext) GetSlotByHash

func (vc *VerifyContext) GetSlotByHash(hash common.Hash) *SlotContext

GetSlotByHash return the slot related to the given block hash

func (*VerifyContext) GetSlots

func (vc *VerifyContext) GetSlots() []*SlotContext

GetSlots gets all the slots

func (*VerifyContext) PrepareSlot

func (vc *VerifyContext) PrepareSlot(bh *types.BlockHeader) (*SlotContext, error)

PrepareSlot returns the slotContext related to the given blockHeader. Replacement will take place if the existing slots reaches the limit defined in the model.Param

Jump to

Keyboard shortcuts

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