consensus

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: LGPL-3.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FSM of Committee Leader
	COMMITTEE_LEADER_INIT      = byte(0x01)
	COMMITTEE_LEADER_ANNOUNCED = byte(0x02)
	// COMMITTEE_LEADER_NOTARYSENT = byte(0x03)
	COMMITTEE_LEADER_COMMITED = byte(0x04)

	THRESHOLD_TIMER_TIMEOUT = 4 * time.Second //wait for reach 2/3 consensus timeout
)
View Source
const (
	// FSM of VALIDATOR
	COMMITTEE_VALIDATOR_INIT       = byte(0x01)
	COMMITTEE_VALIDATOR_COMMITSENT = byte(0x02)
)

for all committee mermbers

View Source
const (
	//Consensus Message Type
	CONSENSUS_MSG_NEW_COMMITTEE      = byte(0x01)
	CONSENSUS_MSG_ANNOUNCE_COMMITTEE = byte(0x02)
	CONSENSUS_MSG_COMMIT_COMMITTEE   = byte(0x03)
	CONSENSUS_MSG_NOTARY_ANNOUNCE    = byte(0x04)
	// CONSENSUS_MSG_PROPOSAL_BLOCK              = byte(0x03)
	// CONSENSUS_MSG_NOTARY_BLOCK                = byte(0x05)
	// CONSENSUS_MSG_VOTE_FOR_PROPOSAL           = byte(0x06)
	// CONSENSUS_MSG_VOTE_FOR_NOTARY             = byte(0x07)
	// CONSENSUS_MSG_MOVE_NEW_ROUND              = byte(0x08)
	PACEMAKER_MSG_PROPOSAL       = byte(0x10)
	PACEMAKER_MSG_VOTE           = byte(0x11)
	PACEMAKER_MSG_NEW_VIEW       = byte(0x12)
	PACEMAKER_MSG_QUERY_PROPOSAL = byte(0x13)
)
View Source
const (
	RoundInterval        = 2 * time.Second
	RoundTimeoutInterval = 20 * time.Second // move the timeout from 30 to 20 secs.

	MIN_MBLOCKS_AN_EPOCH = uint32(4)

	CATCH_UP_THRESHOLD = 5
)
View Source
const (
	PMModeNormal  PMMode = 1
	PMModeCatchUp        = 2
	PMModeObserve        = 3
)
View Source
const (
	UpdateOnBeat                = roundUpdateReason(1)
	UpdateOnRegularProposal     = roundUpdateReason(2)
	UpdateOnTimeout             = roundUpdateReason(3)
	UpdateOnTimeoutCertProposal = roundUpdateReason(4)

	BeatOnInit     = beatReason(0)
	BeatOnHigherQC = beatReason(1)
	BeatOnTimeout  = beatReason(2)

	TimerInit = roundTimerUpdateReason(0)
	TimerInc  = roundTimerUpdateReason(1)
)
View Source
const (
	MsgHashSize = 8

	//normally when a block is committed, wait for a while to let whole network to sync and move to next round
	WHOLE_NETWORK_BLOCK_SYNC_TIME = 5 * time.Second

	CHAN_DEFAULT_BUF_SIZE = 100

	DEFAULT_EPOCHS_PERDAY = 24
)
View Source
const (
	CONSENSUS_MODE_OTHER     = byte(0x01)
	CONSENSUS_MODE_OBSERVER  = byte(0x02)
	CONSENSUS_MODE_DELEGATE  = byte(0x03)
	CONSENSUS_MODE_COMMITTEE = byte(0x04)

	// Flags of Roles
	CONSENSUS_COMMIT_ROLE_NONE      = uint(0x0)
	CONSENSUS_COMMIT_ROLE_LEADER    = uint(0x01)
	CONSENSUS_COMMIT_ROLE_PROPOSER  = uint(0x02)
	CONSENSUS_COMMIT_ROLE_VALIDATOR = uint(0x04)
)
View Source
const (
	MSG_KEEP_HEIGHT = 80
)
View Source
const (
	NEW_COMMITTEE_INIT_INTV = 30 * time.Second // 30s
)
View Source
const PROPOSAL_MAP_MAX_SIZE = 40
View Source
const (
	STAKING_MAX_VALIDATOR_REWARDS = 1200
)

Variables

View Source
var (
	ErrUnrecognizedPayload = errors.New("unrecognized payload")
	ErrMagicMismatch       = errors.New("magic mismatch")
	ErrMalformattedMsg     = errors.New("Malformatted msg")
	ErrInvalidSignature    = errors.New("invalid signature")
	ErrInvalidMsgType      = errors.New("invalid msg type")
)

Functions

func GetAuctionInitialRelease added in v1.2.0

func GetAuctionInitialRelease() float64

func GetAuctionReservedPrice added in v1.2.0

func GetAuctionReservedPrice() *big.Int

func GetRelayPeers

func GetRelayPeers(myIndex, size int) (peers []int)

Assumptions to use this: myIndex is always 0 for proposer (or leader in consensus) indexes starts from 0 1st layer: 0 (proposer) 2nd layer: [1, 2], [3, 4], [5, 6], [7, 8] 3rd layer (32 groups): [9..] ...

func HandleScheduleLeader

func HandleScheduleLeader(conR *ConsensusReactor, epochID uint64, height uint32, round uint32, ev *NCEvidence) bool

func HandleScheduleReplayLeader

func HandleScheduleReplayLeader(conR *ConsensusReactor, epochID uint64, height uint32, round uint32, ev *NCEvidence) bool

-------------------------------

func IsCritical

func IsCritical(err error) bool

IsCritical returns if the error is consensus related.

func IsFutureBlock

func IsFutureBlock(err error) bool

IsFutureBlock returns if the error indicates that the block should be processed later.

func IsKnownBlock

func IsKnownBlock(err error) bool

IsKnownBlock returns if the error means the block was already in the chain.

func IsParentMissing

func IsParentMissing(err error) bool

IsParentMissing ...

func LeaderMajorityTwoThird

func LeaderMajorityTwoThird(voterNum, committeeSize uint32) bool

for committee The voteNum does not include leader himself

func MajorityTwoThird

func MajorityTwoThird(voterNum, committeeSize uint32) bool

since votes of pacemaker include propser, but committee votes do not have leader itself, we seperate the majority func Easier adjust the logic of major 2/3, for pacemaker

func NewConsensusCommonFromBlsCommon

func NewConsensusCommonFromBlsCommon(blsCommon *BlsCommon) *types.ConsensusCommon

func PrintDelegates

func PrintDelegates(delegates []*types.Delegate)

func RegisterConsensusMessages

func RegisterConsensusMessages(cdc *amino.Codec)

func SetConsensusGlobInst

func SetConsensusGlobInst(inst *ConsensusReactor)

func UserHomeDir

func UserHomeDir() string

func VerifyMsgType

func VerifyMsgType(m ConsensusMessage) bool

func VerifySignature

func VerifySignature(m ConsensusMessage) bool

Types

type AnnounceCommitteeMessage

type AnnounceCommitteeMessage struct {
	CSMsgCommonHeader ConsensusMsgCommonHeader

	AnnouncerID    []byte //ecdsa.PublicKey
	AnnouncerBlsPK []byte //bls.PublicKey

	CommitteeSize  uint32
	Nonce          uint64 //nonce is 8 bytes
	KBlockHeight   uint32 // kblockdata
	POWBlockHeight uint32

	//collected NewCommittee signature
	VotingBitArray *cmn.BitArray
	VotingMsgHash  [32]byte // all message hash from Newcommittee msgs
	VotingAggSig   []byte   // aggregate signature of voterSig above
}

New Consensus Message Definitions --------------------------------------- AnnounceCommitteeMessage is sent when new committee is relayed. The leader of new committee send out to announce the new committee is setup, after collects the majority signature from new committee members.

func (*AnnounceCommitteeMessage) EpochID

func (m *AnnounceCommitteeMessage) EpochID() uint64

func (*AnnounceCommitteeMessage) Header

func (*AnnounceCommitteeMessage) MsgType

func (m *AnnounceCommitteeMessage) MsgType() byte

func (*AnnounceCommitteeMessage) SigningHash

func (m *AnnounceCommitteeMessage) SigningHash() (hash meter.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*AnnounceCommitteeMessage) String

func (m *AnnounceCommitteeMessage) String() string

String returns a string representation.

type ApiCommitteeMember

type ApiCommitteeMember struct {
	Name        string
	Address     meter.Address
	PubKey      string
	VotingPower int64
	NetAddr     string
	CsPubKey    string
	CsIndex     int
	InCommittee bool
}

type BlockProbe added in v1.2.0

type BlockProbe struct {
	Height uint32
	Round  uint32
	Type   uint32
	Raw    []byte
}

type BlockType

type BlockType uint32
const (
	KBlockType        BlockType = 1
	MBlockType        BlockType = 2
	StopCommitteeType BlockType = 255 //special message to stop pacemake, not a block
)

type BlsCommon

type BlsCommon struct {
	PrivKey bls.PrivateKey //my private key
	PubKey  bls.PublicKey  //my public key
	// contains filtered or unexported fields
}

func NewBlsCommon

func NewBlsCommon() *BlsCommon

func NewBlsCommonFromParams

func NewBlsCommonFromParams(pubKey bls.PublicKey, privKey bls.PrivateKey, system bls.System, params bls.Params, pairing bls.Pairing) *BlsCommon

func (*BlsCommon) GetPrivKey

func (cc *BlsCommon) GetPrivKey() bls.PrivateKey

func (*BlsCommon) GetPubKey

func (cc *BlsCommon) GetPubKey() *bls.PublicKey

func (*BlsCommon) GetSystem

func (cc *BlsCommon) GetSystem() *bls.System

type CommitCommitteeMessage

type CommitCommitteeMessage struct {
	CSMsgCommonHeader ConsensusMsgCommonHeader

	CommitterID    []byte //ecdsa.PublicKey
	CommitterBlsPK []byte //bls.PublicKey
	CommitterIndex uint32

	BlsSignature  []byte   //bls.Signature
	SignedMsgHash [32]byte //bls signed message hash
}

CommitCommitteMessage is sent after announce committee is received. Told the Leader there is enough member to setup the committee.

func (*CommitCommitteeMessage) EpochID

func (m *CommitCommitteeMessage) EpochID() uint64

func (*CommitCommitteeMessage) Header

func (*CommitCommitteeMessage) MsgType

func (m *CommitCommitteeMessage) MsgType() byte

func (*CommitCommitteeMessage) SigningHash

func (m *CommitCommitteeMessage) SigningHash() (hash meter.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*CommitCommitteeMessage) String

func (m *CommitCommitteeMessage) String() string

String returns a string representation.

type ConsensusConfig

type ConsensusConfig struct {
	ForceLastKFrame    bool
	SkipSignatureCheck bool
	InitCfgdDelegates  bool
	EpochMBlockCount   uint32
	MinCommitteeSize   int
	MaxCommitteeSize   int
	MaxDelegateSize    int
	InitDelegates      []*types.Delegate
}

type ConsensusLeader

type ConsensusLeader struct {
	EpochID uint64
	Nonce   uint64
	// contains filtered or unexported fields
}

func NewCommitteeLeader

func NewCommitteeLeader(conR *ConsensusReactor) *ConsensusLeader

New CommitteeLeader

func (*ConsensusLeader) CreateAnnounceMsgPeers

func (cl *ConsensusLeader) CreateAnnounceMsgPeers() []*ConsensusPeer

curCommittee others except myself

func (*ConsensusLeader) CreateNotaryMsgPeers

func (cl *ConsensusLeader) CreateNotaryMsgPeers() []*ConsensusPeer

ActulCommittee except myself

func (*ConsensusLeader) GenerateAnnounceMsg

func (cl *ConsensusLeader) GenerateAnnounceMsg(height uint32, round uint32) bool

Committee leader create AnnounceCommittee to all peers

func (*ConsensusLeader) GenerateNotaryAnnounceMsg

func (cl *ConsensusLeader) GenerateNotaryAnnounceMsg() bool

After announce vote > 2/3, Leader generate Notary Committee leader create NotaryAnnounce to all members

func (*ConsensusLeader) MoveInitState

func (cl *ConsensusLeader) MoveInitState(curState byte) bool

Move to the init State

func (*ConsensusLeader) ProcessCommitMsg

func (cl *ConsensusLeader) ProcessCommitMsg(commitMsg *CommitCommitteeMessage, src *ConsensusPeer) bool

process commitCommittee in response of announce committee

func (*ConsensusLeader) SendMsg

func (cl *ConsensusLeader) SendMsg(msg ConsensusMessage) bool

send consensus message to all connected peers

type ConsensusMessage

type ConsensusMessage interface {
	String() string
	EpochID() uint64
	MsgType() byte
	Header() *ConsensusMsgCommonHeader
	SigningHash() meter.Bytes32
}

ConsensusMessage is a message that can be sent and received on the ConsensusReactor

type ConsensusMsgCommonHeader

type ConsensusMsgCommonHeader struct {
	Height     uint32
	Round      uint32
	Sender     []byte //ecdsa.PublicKey
	Timestamp  time.Time
	MsgType    byte
	MsgSubType byte
	EpochID    uint64

	Signature []byte // ecdsa signature of whole consensus message
}

ConsensusMsgCommonHeader

func (*ConsensusMsgCommonHeader) SetMsgSignature

func (cmh *ConsensusMsgCommonHeader) SetMsgSignature(sig []byte)

type ConsensusPeer

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

Consensus Topology Peer

func (*ConsensusPeer) FullString

func (cp *ConsensusPeer) FullString() string

func (*ConsensusPeer) String

func (cp *ConsensusPeer) String() string

type ConsensusReactor

type ConsensusReactor struct {
	SyncDone bool

	// kBlock data
	KBlockDataQueue    chan block.KBlockData // from POW simulation
	RcvKBlockInfoQueue chan RecvKBlockInfo   // this channel for kblock notify from node module.
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------- ConsensusReactor defines a reactor for the consensus service.

var (
	ConsensusGlobInst *ConsensusReactor
)

func GetConsensusGlobInst

func GetConsensusGlobInst() *ConsensusReactor

Glob Instance

func NewConsensusReactor

func NewConsensusReactor(ctx *cli.Context, chain *chain.Chain, state *state.Creator, privKey *ecdsa.PrivateKey, pubKey *ecdsa.PublicKey, magic [4]byte, blsCommon *BlsCommon, initDelegates []*types.Delegate) *ConsensusReactor

NewConsensusReactor returns a new ConsensusReactor with the given consensusState.

func (*ConsensusReactor) BuildAnnounceSignMsg

func (conR *ConsensusReactor) BuildAnnounceSignMsg(pubKey ecdsa.PublicKey, epochID uint64, height uint64, round uint32) string

---------------------------------------------------------------------------- Sign Announce Committee "Announce Committee Message: Leader <pubkey 64(hexdump 32x2) bytes> EpochID <16 (8x2)bytes> Height <16 (8x2) bytes> Round <8(4x2)bytes>

func (*ConsensusReactor) BuildCommitteeInfoFromMember

func (conR *ConsensusReactor) BuildCommitteeInfoFromMember(system *bls.System, cms []types.CommitteeMember) []block.CommitteeInfo

build block committee info part

func (*ConsensusReactor) BuildCommitteeMemberFromInfo

func (conR *ConsensusReactor) BuildCommitteeMemberFromInfo(system *bls.System, cis []block.CommitteeInfo) []types.CommitteeMember

de-serialize the block committee info part

func (*ConsensusReactor) BuildKBlock

func (conR *ConsensusReactor) BuildKBlock(parentBlock *block.Block, data *block.KBlockData, rewards []powpool.PowReward) *ProposedBlockInfo

func (*ConsensusReactor) BuildMBlock

func (conR *ConsensusReactor) BuildMBlock(parentBlock *block.Block) *ProposedBlockInfo

Build MBlock

func (*ConsensusReactor) BuildNewCommitteeSignMsg

func (conR *ConsensusReactor) BuildNewCommitteeSignMsg(pubKey ecdsa.PublicKey, epochID uint64, height uint64) string

---------------------------------------------------------------------------- Sign New Committee "New Committee Message: Leader <pubkey 64(hexdump 32x2) bytes> EpochID <16 (8x2)bytes> Height <16 (8x2) bytes>

func (*ConsensusReactor) BuildNotaryAnnounceSignMsg

func (conR *ConsensusReactor) BuildNotaryAnnounceSignMsg(pubKey ecdsa.PublicKey, epochID uint64, height uint64, round uint32) string

Sign Notary Announce Message "Announce Notarization Message: Leader <pubkey 64(32x2)> EpochID <16 (8x2)bytes> Height <16 (8x2) bytes> Round <8 (4x2) bytes>

func (*ConsensusReactor) BuildProposalBlockSignMsg

func (conR *ConsensusReactor) BuildProposalBlockSignMsg(blockType uint32, height uint64, id, txsRoot, stateRoot *meter.Bytes32) string

Sign Propopal Message "Proposal Block Message: BlockType <8 bytes> Height <16 (8x2) bytes> Round <8 (4x2) bytes>

func (*ConsensusReactor) BuildStopCommitteeBlock

func (conR *ConsensusReactor) BuildStopCommitteeBlock(parentBlock *block.Block) *ProposedBlockInfo

func (*ConsensusReactor) CalcCommitteeByNonce

func (conR *ConsensusReactor) CalcCommitteeByNonce(nonce uint64) (*types.ValidatorSet, uint, int, bool)

This is similar routine of NewValidatorSetByNonce. it is used for temp calculate committee set by a given nonce in the fly. also return the committee

func (*ConsensusReactor) CheckEstablishedCommittee

func (conR *ConsensusReactor) CheckEstablishedCommittee(kHeight uint32) bool

if best block is moving ahead, and lastkblock is match, we consider there is an established committee and proposing

func (*ConsensusReactor) CommitteeInfoCompare

func (conR *ConsensusReactor) CommitteeInfoCompare(cm1, cm2 []block.CommitteeInfo) bool

func (*ConsensusReactor) ConsensusHandleReceivedNonce

func (conR *ConsensusReactor) ConsensusHandleReceivedNonce(kBlockHeight uint32, nonce, epoch uint64, replay bool)

Consensus module handle received nonce from kblock

func (*ConsensusReactor) FinalizeCommitBlock

func (conR *ConsensusReactor) FinalizeCommitBlock(blkInfo *ProposedBlockInfo, bestQC *block.QuorumCert) error

finalize the block with its own QC

func (*ConsensusReactor) GetActualCommitteeMemberIndex

func (conR *ConsensusReactor) GetActualCommitteeMemberIndex(pubKey *ecdsa.PublicKey) int

func (*ConsensusReactor) GetCommitteeMember

func (conR *ConsensusReactor) GetCommitteeMember(pubKey []byte) *types.CommitteeMember

input is serialized ecdsa.PublicKey

func (*ConsensusReactor) GetCommitteeMemberIndex

func (conR *ConsensusReactor) GetCommitteeMemberIndex(pubKey ecdsa.PublicKey) int

func (*ConsensusReactor) GetConsensusDelegates

func (conR *ConsensusReactor) GetConsensusDelegates() ([]*types.Delegate, int, int)

entry point for each committee return with delegates list, delegateSize, committeeSize maxDelegateSize >= maxCommiteeSize >= minCommitteeSize

func (*ConsensusReactor) GetDelegateNameByIP

func (conR *ConsensusReactor) GetDelegateNameByIP(ip net.IP) string

func (*ConsensusReactor) GetDelegatesSource added in v1.2.0

func (conR *ConsensusReactor) GetDelegatesSource() string

func (*ConsensusReactor) GetLastKBlockHeight

func (conR *ConsensusReactor) GetLastKBlockHeight() uint32

func (*ConsensusReactor) GetLatestCommitteeList

func (conR *ConsensusReactor) GetLatestCommitteeList() ([]*ApiCommitteeMember, error)

func (*ConsensusReactor) GetMyActualCommitteeIndex

func (conR *ConsensusReactor) GetMyActualCommitteeIndex() int

func (*ConsensusReactor) GetMyName

func (conR *ConsensusReactor) GetMyName() string

func (*ConsensusReactor) GetMyNetAddr

func (conR *ConsensusReactor) GetMyNetAddr() types.NetAddress

func (*ConsensusReactor) GetMyPeers

func (conR *ConsensusReactor) GetMyPeers() ([]*ConsensusPeer, error)

func (*ConsensusReactor) GetRelayPeers

func (conR *ConsensusReactor) GetRelayPeers(round int) ([]*ConsensusPeer, error)

func (*ConsensusReactor) HandleKBlockData

func (conR *ConsensusReactor) HandleKBlockData(kd block.KBlockData)

func (*ConsensusReactor) HandleRecvKBlockInfo

func (conR *ConsensusReactor) HandleRecvKBlockInfo(ki RecvKBlockInfo)

func (*ConsensusReactor) HandleSchedule

func (conR *ConsensusReactor) HandleSchedule(fn func()) bool

Handle Schedules from conR.scheduleQueue

func (*ConsensusReactor) IsCommitteeMember

func (conR *ConsensusReactor) IsCommitteeMember() bool

func (*ConsensusReactor) IsPacemakerRunning

func (conR *ConsensusReactor) IsPacemakerRunning() bool

used for probe API

func (*ConsensusReactor) JoinEstablishedCommittee

func (conR *ConsensusReactor) JoinEstablishedCommittee(kBlock *block.Block, replay bool)

func (*ConsensusReactor) LoadBlockBytes

func (conR *ConsensusReactor) LoadBlockBytes(num uint32) []byte

func (*ConsensusReactor) MakeBlockCommitteeInfo

func (conR *ConsensusReactor) MakeBlockCommitteeInfo(system *bls.System, cms []types.CommitteeMember) []block.CommitteeInfo

build block committee info part

func (*ConsensusReactor) MarshalMsg

func (conR *ConsensusReactor) MarshalMsg(msg *ConsensusMessage) ([]byte, error)

func (*ConsensusReactor) NewCommitteeCleanup

func (conR *ConsensusReactor) NewCommitteeCleanup()

func (*ConsensusReactor) NewCommitteeInit

func (conR *ConsensusReactor) NewCommitteeInit(height uint32, nonce uint64, replay bool)

func (*ConsensusReactor) NewCommitteeTimeout

func (conR *ConsensusReactor) NewCommitteeTimeout()

func (*ConsensusReactor) NewCommitteeTimerStart

func (conR *ConsensusReactor) NewCommitteeTimerStart()

func (*ConsensusReactor) NewCommitteeTimerStop

func (conR *ConsensusReactor) NewCommitteeTimerStop()

func (*ConsensusReactor) NewCommitteeUpdateRound

func (conR *ConsensusReactor) NewCommitteeUpdateRound(round uint32)

func (*ConsensusReactor) NewConsensusStart

func (conR *ConsensusReactor) NewConsensusStart() int

Entry point of new consensus

func (*ConsensusReactor) NewConsensusStop

func (conR *ConsensusReactor) NewConsensusStop() int

called by reactor stop

func (*ConsensusReactor) NewRuntimeForReplay

func (c *ConsensusReactor) NewRuntimeForReplay(header *block.Header) (*runtime.Runtime, error)

func (*ConsensusReactor) NewValidatorSetByNonce

func (conR *ConsensusReactor) NewValidatorSetByNonce(nonce uint64) (uint, bool)

create validatorSet by a given nonce. return by my self role

func (*ConsensusReactor) OnStart

func (conR *ConsensusReactor) OnStart() error

OnStart implements BaseService by subscribing to events, which later will be broadcasted to other peers and starting state if we're not in fast sync.

func (*ConsensusReactor) OnStop

func (conR *ConsensusReactor) OnStop()

OnStop implements BaseService by unsubscribing from events and stopping state.

func (*ConsensusReactor) PacemakerProbe added in v1.2.0

func (conR *ConsensusReactor) PacemakerProbe() *PMProbeResult

func (*ConsensusReactor) PreCommitBlock

func (conR *ConsensusReactor) PreCommitBlock(blkInfo *ProposedBlockInfo) error

========================================================

func (*ConsensusReactor) PrepareEnvForPacemaker added in v1.2.0

func (conR *ConsensusReactor) PrepareEnvForPacemaker() error

func (*ConsensusReactor) Process

func (c *ConsensusReactor) Process(blk *block.Block, nowTimestamp uint64) (*state.Stage, tx.Receipts, error)

Process process a block.

func (*ConsensusReactor) ProcessNewCommitteeMessage

func (conR *ConsensusReactor) ProcessNewCommitteeMessage(newCommitteeMsg *NewCommitteeMessage, src *ConsensusPeer) bool

once reach 2/3 send aout annouce message

func (*ConsensusReactor) ProcessProposedBlock

func (c *ConsensusReactor) ProcessProposedBlock(parentHeader *block.Header, blk *block.Block, nowTimestamp uint64) (*state.Stage, tx.Receipts, error)

func (*ConsensusReactor) ReceiveCommitteeMsg

func (conR *ConsensusReactor) ReceiveCommitteeMsg(w http.ResponseWriter, r *http.Request)

func (*ConsensusReactor) ReceivePacemakerMsg

func (conR *ConsensusReactor) ReceivePacemakerMsg(w http.ResponseWriter, r *http.Request)

func (*ConsensusReactor) RefreshCurHeight

func (conR *ConsensusReactor) RefreshCurHeight() error

Refresh the current Height from the best block normally call this routine after block chain changed

func (*ConsensusReactor) ScheduleLeader

func (conR *ConsensusReactor) ScheduleLeader(epochID uint64, height uint32, round uint32, ev *NCEvidence, d time.Duration) bool

======end of New consensus ========================================= ----------------------------------------------------------------------------- New consensus timed schedule util type Scheduler func(conR *ConsensusReactor) bool

func (*ConsensusReactor) ScheduleReplayLeader

func (conR *ConsensusReactor) ScheduleReplayLeader(epochID uint64, height uint32, round uint32, ev *NCEvidence, d time.Duration) bool

func (*ConsensusReactor) SignConsensusMsg

func (conR *ConsensusReactor) SignConsensusMsg(msgHash []byte) (sig []byte, err error)

============================================

func (*ConsensusReactor) String

func (conR *ConsensusReactor) String() string

String returns a string representation of the ConsensusReactor. NOTE: For now, it is just a hard-coded string to avoid accessing unprotected shared variables. TODO: improve!

func (*ConsensusReactor) SwitchToConsensus

func (conR *ConsensusReactor) SwitchToConsensus()

SwitchToConsensus switches from fast_sync mode to consensus mode. It resets the state, turns off fast_sync, and starts the consensus state-machine

func (*ConsensusReactor) UnmarshalMsg

func (conR *ConsensusReactor) UnmarshalMsg(data []byte) (*consensusMsgInfo, error)

func (*ConsensusReactor) UpdateActualCommittee

func (conR *ConsensusReactor) UpdateActualCommittee(leaderIndex uint32) bool

after announce/commit, Leader got the actual committee, which is the subset of curCommittee if some committee member offline. indexs and pubKeys are not sorted slice, AcutalCommittee must be sorted. Only Leader can call this method. indexes do not include the leader itself.

func (*ConsensusReactor) UpdateCurDelegates

func (conR *ConsensusReactor) UpdateCurDelegates()

//////////////////////////////////////////////////// update current delegates with new delegates from staking or config file keep this standalone method intentionly

func (*ConsensusReactor) UpdateHeight

func (conR *ConsensusReactor) UpdateHeight(height uint32) bool

func (*ConsensusReactor) UpdateLastKBlockHeight

func (conR *ConsensusReactor) UpdateLastKBlockHeight(height uint32) bool

update the LastKBlockHeight

type ConsensusValidator

type ConsensusValidator struct {
	EpochID uint64 // epoch ID of this committee
	// contains filtered or unexported fields
}

func NewConsensusValidator

func NewConsensusValidator(conR *ConsensusReactor) *ConsensusValidator

validator receives the initiated messages

func (*ConsensusValidator) GenerateCommitMessage

func (cv *ConsensusValidator) GenerateCommitMessage(sig bls.Signature, msgHash [32]byte, round uint32) *CommitCommitteeMessage

Generate commitCommittee Message

func (*ConsensusValidator) ProcessAnnounceCommittee

func (cv *ConsensusValidator) ProcessAnnounceCommittee(announceMsg *AnnounceCommitteeMessage, src *ConsensusPeer) bool

process Announcement from committee leader, join the committee

func (*ConsensusValidator) ProcessNotaryAnnounceMessage

func (cv *ConsensusValidator) ProcessNotaryAnnounceMessage(notaryMsg *NotaryAnnounceMessage, src *ConsensusPeer) bool

process notary Block Message

func (*ConsensusValidator) RemoveAllcsPeers

func (cv *ConsensusValidator) RemoveAllcsPeers() bool

validator need to build consensus peer topology

func (*ConsensusValidator) SendMsgToPeer

func (cv *ConsensusValidator) SendMsgToPeer(msg *ConsensusMessage, netAddr types.NetAddress) bool

type MsgCache

type MsgCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMsgCache

func NewMsgCache(size int) *MsgCache

NewMsgCache creates the msg cache instance

func (*MsgCache) Add

func (c *MsgCache) Add(id []byte) bool

func (*MsgCache) CleanAll

func (c *MsgCache) CleanAll()

func (*MsgCache) Contains

func (c *MsgCache) Contains(id []byte) bool

type NCEvidence

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

func NewNCEvidence

func NewNCEvidence(bitArray *cmn.BitArray, msgHash [32]byte, aggSig bls.Signature) *NCEvidence

type NewCommittee

type NewCommittee struct {
	KblockHeight uint32
	Round        uint32
	Nonce        uint64
	Replay       bool
	TimeoutTimer *time.Timer

	//precalc committee for given nonce
	Committee   *types.ValidatorSet
	Role        uint //leader, validator, none
	Index       int  //the index of delegates
	InCommittee bool
	// contains filtered or unexported fields
}

type NewCommitteeKey

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

type NewCommitteeMessage

type NewCommitteeMessage struct {
	CSMsgCommonHeader ConsensusMsgCommonHeader

	NewLeaderID    []byte //ecdsa.PublicKey
	ValidatorID    []byte //ecdsa.PublicKey
	ValidatorBlsPK []byte //bls publickey

	NextEpochID   uint64
	Nonce         uint64 // 8 bytes  Kblock info
	KBlockHeight  uint32
	SignedMsgHash [32]byte // BLS signed message hash
	BlsSignature  []byte   // BLS signed signature
}

------------------------------------

func (*NewCommitteeMessage) EpochID

func (m *NewCommitteeMessage) EpochID() uint64

func (*NewCommitteeMessage) Header

func (*NewCommitteeMessage) MsgType

func (m *NewCommitteeMessage) MsgType() byte

func (*NewCommitteeMessage) SigningHash

func (m *NewCommitteeMessage) SigningHash() (hash meter.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*NewCommitteeMessage) String

func (m *NewCommitteeMessage) String() string

String returns a string representation.

type NewViewReason

type NewViewReason byte

NewViewReason is the reason for new view

const (
	// HigherQCSeen
	HigherQCSeen NewViewReason = NewViewReason(1)
	RoundTimeout NewViewReason = NewViewReason(2)
)

func (NewViewReason) String

func (r NewViewReason) String() string

type NotaryAnnounceMessage

type NotaryAnnounceMessage struct {
	CSMsgCommonHeader ConsensusMsgCommonHeader

	AnnouncerID    []byte //ecdsa.PublicKey
	AnnouncerBlsPK []byte //bls.PublicKey

	//collected NewCommittee messages
	VotingBitArray *cmn.BitArray
	VotingMsgHash  [32]byte // all message hash from Newcommittee msgs
	VotingAggSig   []byte   // aggregate signature of voterSig above

	// collected from commitcommittee messages
	NotarizeBitArray *cmn.BitArray
	NotarizeMsgHash  [32]byte // all message hash from Newcommittee msgs
	NotarizeAggSig   []byte   // aggregate signature of voterSig above

	CommitteeSize    uint32 // summarized committee info
	CommitteeMembers []block.CommitteeInfo
}

-------------------------------------

func (*NotaryAnnounceMessage) EpochID

func (m *NotaryAnnounceMessage) EpochID() uint64

func (*NotaryAnnounceMessage) Header

func (*NotaryAnnounceMessage) MsgType

func (m *NotaryAnnounceMessage) MsgType() byte

func (*NotaryAnnounceMessage) SigningHash

func (m *NotaryAnnounceMessage) SigningHash() (hash meter.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*NotaryAnnounceMessage) String

func (m *NotaryAnnounceMessage) String() string

String returns a string representation.

type PMBeatInfo

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

type PMCmd

type PMCmd uint32
const (
	PMCmdStop    PMCmd = 1
	PMCmdRestart       = 2
)

func (PMCmd) String

func (cmd PMCmd) String() string

type PMCmdInfo

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

type PMMode

type PMMode uint32

func (PMMode) String

func (m PMMode) String() string

type PMNewViewMessage

type PMNewViewMessage struct {
	CSMsgCommonHeader ConsensusMsgCommonHeader

	QCHeight       uint32
	QCRound        uint32
	QCHigh         []byte
	Reason         NewViewReason
	TimeoutHeight  uint32
	TimeoutRound   uint32
	TimeoutCounter uint64

	PeerID            []byte
	PeerIndex         uint32
	SignedMessageHash [32]byte
	PeerSignature     []byte
}

PMNewViewMessage is sent to the next leader in these two senarios 1. leader relay 2. repica timeout

func (*PMNewViewMessage) EpochID

func (m *PMNewViewMessage) EpochID() uint64

func (*PMNewViewMessage) Header

func (*PMNewViewMessage) MsgType

func (m *PMNewViewMessage) MsgType() byte

func (*PMNewViewMessage) SigningHash

func (m *PMNewViewMessage) SigningHash() (hash meter.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*PMNewViewMessage) String

func (m *PMNewViewMessage) String() string

String returns a string representation.

type PMProbeResult added in v1.2.0

type PMProbeResult struct {
	Mode             string
	StartHeight      uint32
	StartRound       uint32
	CurRound         uint32
	MyCommitteeIndex int

	LastVotingHeight uint32
	QCHigh           *block.QuorumCert
	BlockLeaf        *BlockProbe
	BlockExecuted    *BlockProbe
	BlockLocked      *BlockProbe

	ProposalCount int
	PendingCount  int
	PendingLowest uint32
}

type PMProposalMessage

type PMProposalMessage struct {
	CSMsgCommonHeader ConsensusMsgCommonHeader

	ParentHeight uint32
	ParentRound  uint32

	ProposerID    []byte //ecdsa.PublicKey
	ProposerBlsPK []byte //bls.PublicKey
	KBlockHeight  uint32
	// SignOffset        uint
	// SignLength        uint
	ProposedSize      uint32
	ProposedBlock     []byte
	ProposedBlockType BlockType

	TimeoutCert *PMTimeoutCert
}

PMProposalMessage is sent when a new block leaf is proposed

func (*PMProposalMessage) CompactString added in v1.2.0

func (m *PMProposalMessage) CompactString() string

func (*PMProposalMessage) EpochID

func (m *PMProposalMessage) EpochID() uint64

func (*PMProposalMessage) Header

func (*PMProposalMessage) MsgType

func (m *PMProposalMessage) MsgType() byte

func (*PMProposalMessage) SigningHash

func (m *PMProposalMessage) SigningHash() (hash meter.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*PMProposalMessage) String

func (m *PMProposalMessage) String() string

String returns a string representation.

type PMQueryProposalMessage

type PMQueryProposalMessage struct {
	CSMsgCommonHeader ConsensusMsgCommonHeader
	FromHeight        uint32
	ToHeight          uint32
	Round             uint32
	ReturnAddr        types.NetAddress
}

PMQueryProposalMessage is sent to current leader to get the parent proposal

func (*PMQueryProposalMessage) EpochID

func (m *PMQueryProposalMessage) EpochID() uint64

func (*PMQueryProposalMessage) Header

func (*PMQueryProposalMessage) MsgType

func (m *PMQueryProposalMessage) MsgType() byte

func (*PMQueryProposalMessage) SigningHash

func (m *PMQueryProposalMessage) SigningHash() (hash meter.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*PMQueryProposalMessage) String

func (m *PMQueryProposalMessage) String() string

String returns a string representation.

type PMRoundState

type PMRoundState byte

PMRoundState is the const state for pacemaker state machine

const (
	PMRoundStateInit                 PMRoundState = 1
	PMRoundStateProposalRcvd         PMRoundState = 2
	PMRoundStateProposalSent         PMRoundState = 3
	PMRoundStateProposalMajorReached PMRoundState = 4
	PMRoundStateProposalCommitted    PMRoundState = 4
	PMRoundStateProposalDecided      PMRoundState = 4
)

type PMRoundTimeoutInfo

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

type PMTimeoutCert

type PMTimeoutCert struct {
	TimeoutRound   uint32
	TimeoutHeight  uint32
	TimeoutCounter uint32

	TimeoutBitArray *cmn.BitArray
	TimeoutAggSig   []byte
}

TimeoutCert

func (*PMTimeoutCert) DecodeRLP

func (tc *PMTimeoutCert) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*PMTimeoutCert) EncodeRLP

func (tc *PMTimeoutCert) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*PMTimeoutCert) SigningHash

func (tc *PMTimeoutCert) SigningHash() (hash meter.Bytes32)

func (*PMTimeoutCert) String

func (tc *PMTimeoutCert) String() string

type PMTimeoutCertManager

type PMTimeoutCertManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

type PMVoteMessage

type PMVoteMessage struct {
	CSMsgCommonHeader ConsensusMsgCommonHeader

	VoterID           []byte //ecdsa.PublicKey
	VoterBlsPK        []byte //bls.PublicKey
	BlsSignature      []byte //bls.Signature
	VoterIndex        uint32
	SignedMessageHash [32]byte
}

PMVoteResponseMessage is sent when voting for a proposal (or lack thereof).

func (*PMVoteMessage) EpochID

func (m *PMVoteMessage) EpochID() uint64

func (*PMVoteMessage) Header

func (*PMVoteMessage) MsgType

func (m *PMVoteMessage) MsgType() byte

func (*PMVoteMessage) SigningHash

func (m *PMVoteMessage) SigningHash() (hash meter.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*PMVoteMessage) String

func (m *PMVoteMessage) String() string

String returns a string representation.

type Pacemaker

type Pacemaker struct {
	QCHigh *pmQuorumCert
	// contains filtered or unexported fields
}

func NewPaceMaker

func NewPaceMaker(conR *ConsensusReactor) *Pacemaker

func (*Pacemaker) AddressBlock

func (p *Pacemaker) AddressBlock(height uint32) *pmBlock

find out b b' b"

func (*Pacemaker) BlockMatchQC

func (p *Pacemaker) BlockMatchQC(b *pmBlock, qc *block.QuorumCert) (bool, error)

qc is for that block? blk is derived from pmBlock message. pass it in if already decoded

func (*Pacemaker) BuildNewViewMessage

func (p *Pacemaker) BuildNewViewMessage(nextHeight, nextRound uint32, qcHigh *pmQuorumCert, reason NewViewReason, ti *PMRoundTimeoutInfo) (*PMNewViewMessage, error)

BuildVoteForProposalMsg build VFP message for proposal

func (*Pacemaker) BuildNewViewSignMsg

func (p *Pacemaker) BuildNewViewSignMsg(pubKey ecdsa.PublicKey, reason NewViewReason, height, round uint32, qc *block.QuorumCert) string

func (*Pacemaker) BuildProposalMessage

func (p *Pacemaker) BuildProposalMessage(height, round uint32, bnew *pmBlock, tc *PMTimeoutCert) (*PMProposalMessage, error)

func (*Pacemaker) BuildQueryProposalMessage

func (p *Pacemaker) BuildQueryProposalMessage(fromHeight, toHeight, round uint32, epochID uint64, retAddr types.NetAddress) (*PMQueryProposalMessage, error)

func (*Pacemaker) BuildVoteForProposalMessage

func (p *Pacemaker) BuildVoteForProposalMessage(proposalMsg *PMProposalMessage, blockID, txsRoot, stateRoot meter.Bytes32) (*PMVoteMessage, error)

BuildVoteForProposalMsg build VFP message for proposal txRoot, stateRoot is decoded from proposalMsg.ProposedBlock, carry in cos already decoded outside

func (*Pacemaker) CreateLeaf

func (p *Pacemaker) CreateLeaf(parent *pmBlock, qc *pmQuorumCert, height, round uint32) *pmBlock

func (*Pacemaker) Execute

func (p *Pacemaker) Execute(b *pmBlock)

TBD: how to emboy b.cmd

func (*Pacemaker) GetRelayPeers

func (p *Pacemaker) GetRelayPeers(round uint32) []*ConsensusPeer

func (*Pacemaker) IsExtendedFromBLocked

func (p *Pacemaker) IsExtendedFromBLocked(b *pmBlock) bool

check a pmBlock is the extension of b_locked, max 10 hops

func (*Pacemaker) IsStopped

func (p *Pacemaker) IsStopped() bool

func (*Pacemaker) OnBeat

func (p *Pacemaker) OnBeat(height, round uint32, reason beatReason) error

func (*Pacemaker) OnCommit

func (p *Pacemaker) OnCommit(commitReady []*pmBlock)

func (*Pacemaker) OnNextSyncView

func (p *Pacemaker) OnNextSyncView(nextHeight, nextRound uint32, reason NewViewReason, ti *PMRoundTimeoutInfo)

func (*Pacemaker) OnPreCommitBlock

func (p *Pacemaker) OnPreCommitBlock(b *pmBlock) error

func (*Pacemaker) OnPropose

func (p *Pacemaker) OnPropose(b *pmBlock, qc *pmQuorumCert, height, round uint32) (*pmBlock, error)

func (*Pacemaker) OnReceiveNewView

func (p *Pacemaker) OnReceiveNewView(mi *consensusMsgInfo) error

func (*Pacemaker) OnReceiveProposal

func (p *Pacemaker) OnReceiveProposal(mi *consensusMsgInfo) error

func (*Pacemaker) OnReceiveQueryProposal

func (p *Pacemaker) OnReceiveQueryProposal(mi *consensusMsgInfo) error

func (*Pacemaker) OnReceiveVote

func (p *Pacemaker) OnReceiveVote(mi *consensusMsgInfo) error

func (*Pacemaker) OnRoundTimeout

func (p *Pacemaker) OnRoundTimeout(ti PMRoundTimeoutInfo)

func (*Pacemaker) OnTimeoutBeat

func (p *Pacemaker) OnTimeoutBeat(height, round uint32, reason beatReason) error

func (*Pacemaker) Probe added in v1.2.0

func (p *Pacemaker) Probe() *PMProbeResult

func (*Pacemaker) Restart

func (p *Pacemaker) Restart(mode PMMode)

func (*Pacemaker) ScheduleOnBeat

func (p *Pacemaker) ScheduleOnBeat(height, round uint32, reason beatReason, d time.Duration) bool

func (*Pacemaker) SendCatchUpQuery

func (p *Pacemaker) SendCatchUpQuery()

func (*Pacemaker) SendConsensusMessage

func (p *Pacemaker) SendConsensusMessage(round uint32, msg ConsensusMessage, copyMyself bool) bool

------------------------------------------------------ Message Delivery Utilities ------------------------------------------------------

func (*Pacemaker) SendKblockInfo

func (p *Pacemaker) SendKblockInfo(b *pmBlock)

func (*Pacemaker) Start

func (p *Pacemaker) Start(mode PMMode)

Committee Leader triggers

func (*Pacemaker) Stop

func (p *Pacemaker) Stop()

actions of commites/receives kblock, stop pacemake to next committee all proposal txs need to be reclaimed before stop

func (*Pacemaker) Update

func (p *Pacemaker) Update(bnew *pmBlock) error

b_exec b_lock b <- b' <- b" b*

func (*Pacemaker) UpdateQCHigh

func (p *Pacemaker) UpdateQCHigh(qc *pmQuorumCert) bool

func (*Pacemaker) ValidateProposal

func (p *Pacemaker) ValidateProposal(b *pmBlock) error

type PendingList

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

func NewPendingList

func NewPendingList() *PendingList

func (*PendingList) Add

func (p *PendingList) Add(mi *consensusMsgInfo)

func (*PendingList) CleanAll

func (p *PendingList) CleanAll()

clean all the pending messages

func (*PendingList) CleanUpTo

func (p *PendingList) CleanUpTo(height uint32)

func (*PendingList) GetLowestHeight

func (p *PendingList) GetLowestHeight() uint32

func (*PendingList) Len added in v1.2.0

func (p *PendingList) Len() int

type ProposalMap added in v1.2.0

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

func NewProposalMap added in v1.2.0

func NewProposalMap() *ProposalMap

func (*ProposalMap) Add added in v1.2.0

func (p *ProposalMap) Add(blk *pmBlock)

func (*ProposalMap) Get added in v1.2.0

func (p *ProposalMap) Get(key uint32) *pmBlock

func (*ProposalMap) Len added in v1.2.0

func (p *ProposalMap) Len() int

func (*ProposalMap) Reset added in v1.2.0

func (p *ProposalMap) Reset()

func (*ProposalMap) RevertTo added in v1.2.0

func (p *ProposalMap) RevertTo(height uint32)

type ProposedBlockInfo

type ProposedBlockInfo struct {
	ProposedBlock *block.Block
	Stage         *state.Stage
	Receipts      *tx.Receipts

	CheckPoint int
	BlockType  BlockType
	// contains filtered or unexported fields
}

proposed block info

func (*ProposedBlockInfo) String

func (pb *ProposedBlockInfo) String() string

type RecvKBlockInfo

type RecvKBlockInfo struct {
	Height           uint32
	LastKBlockHeight uint32
	Nonce            uint64
	Epoch            uint64
}

type SignatureAggregator

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

func (*SignatureAggregator) Add

func (sa *SignatureAggregator) Add(index int, msgHash [32]byte, signature []byte, pubkey bls.PublicKey) bool

func (*SignatureAggregator) Aggregate

func (sa *SignatureAggregator) Aggregate() []byte

func (*SignatureAggregator) BitArrayString

func (sa *SignatureAggregator) BitArrayString() string

func (*SignatureAggregator) Count

func (sa *SignatureAggregator) Count() uint32

func (*SignatureAggregator) Seal

func (sa *SignatureAggregator) Seal()

seal the signature, no future modification could be done anymore

type ValidatorReward added in v1.2.0

type ValidatorReward struct {
	Epoch            uint32
	BaseReward       *big.Int
	ExpectDistribute *big.Int
	ActualDistribute *big.Int
}

func (*ValidatorReward) ToString added in v1.2.0

func (v *ValidatorReward) ToString() string

type ValidatorRewardList added in v1.2.0

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

func NewValidatorRewardList added in v1.2.0

func NewValidatorRewardList(rewards []*ValidatorReward) *ValidatorRewardList

func (*ValidatorRewardList) Count added in v1.2.0

func (v *ValidatorRewardList) Count() int

func (*ValidatorRewardList) Get added in v1.2.0

func (*ValidatorRewardList) GetList added in v1.2.0

func (v *ValidatorRewardList) GetList() []*ValidatorReward

func (*ValidatorRewardList) String added in v1.2.0

func (v *ValidatorRewardList) String() string

func (*ValidatorRewardList) ToList added in v1.2.0

func (v *ValidatorRewardList) ToList() []*ValidatorReward

func (*ValidatorRewardList) ToString added in v1.2.0

func (v *ValidatorRewardList) ToString() string

Jump to

Keyboard shortcuts

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