consensus

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoundInterval        = 2 * time.Second
	RoundTimeoutInterval = RoundInterval * 4 // round timeout 8 secs.
	ProposeTimeLimit     = 1300 * time.Millisecond
	BroadcastTimeLimit   = 1400 * time.Millisecond
)
View Source
const (
	RegularRound = roundType(1)
	TimeoutRound = roundType(3)
)
View Source
const (
	IN_QUEUE_TTL = time.Second * 5
)
View Source
const (
	PMCmdRegulate = 0 // regulate pacemaker with all fresh start, could be used any time when pacemaker is out of sync
)

Variables

View Source
var (
	ErrUnrecognizedPayload = errors.New("unrecognized payload")
	ErrVersionMismatch     = errors.New("version mismatch")
	ErrMalformattedMsg     = errors.New("malformatted msg")
	ErrKnownMsg            = errors.New("known msg")
	ErrProposalRejected    = errors.New("proposal rejected")
	ErrProposalUnknown     = errors.New("proposal unknown")
	ErrForkHappened        = errors.New("fork happened")
)
View Source
var (
	ErrParentBlockEmpty     = errors.New("parent block empty")
	ErrPackerEmpty          = errors.New("packer is empty")
	ErrFlowEmpty            = errors.New("flow is empty")
	ErrProposalEmpty        = errors.New("proposal is empty")
	ErrStateCreaterNotReady = errors.New("state creater not ready")
	ErrInvalidRound         = errors.New("invalid round")
)
View Source
var (
	ErrInvalidBlock = errors.New("invalid block")
)

Functions

func BuildTimeoutVotingHash

func BuildTimeoutVotingHash(epoch uint64, round uint32) [32]byte

Timeout Vote Message Hash

func CalcAddedValidators

func CalcAddedValidators(curVSet, nxtVSet *cmttypes.ValidatorSet) (added []*cmttypes.Validator)

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 ...

Types

type BlockProbe

type BlockProbe struct {
	Height uint32
	Round  uint32
	ID     types.Bytes32
}

type ConsensusPeer

type ConsensusPeer struct {
	Name string
	IP   string
}

Consensus Topology Peer

func NewConsensusPeer

func NewConsensusPeer(name string, ip string) *ConsensusPeer

func (*ConsensusPeer) String

func (cp *ConsensusPeer) String() string

type EpochEndInfo

type EpochEndInfo struct {
	Height     uint32
	LastKBlock uint32
	Nonce      uint64
	Epoch      uint64
}

type EpochState

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

func NewEpochState

func NewEpochState(c *chain.Chain, leaf *block.Block, myPubKey cmtcrypto.PubKey) (*EpochState, error)

func NewPendingEpochState

func NewPendingEpochState(vset *cmttypes.ValidatorSet, myPubKey bls.PublicKey, curEpoch uint64) (*EpochState, error)

func (*EpochState) AddQCVote

func (es *EpochState) AddQCVote(signerIndex uint32, round uint32, blockID types.Bytes32, sig []byte) *block.QuorumCert

func (*EpochState) AddTCVote

func (es *EpochState) AddTCVote(signerIndex uint32, round uint32, sig []byte, hash [32]byte) *types.TimeoutCert

func (*EpochState) CommitteeIndex

func (es *EpochState) CommitteeIndex() int

func (*EpochState) CommitteeSize

func (es *EpochState) CommitteeSize() uint32

func (*EpochState) GetMyself

func (es *EpochState) GetMyself() *cmttypes.Validator

func (*EpochState) GetValidatorByIndex

func (es *EpochState) GetValidatorByIndex(index int) ([]byte, *cmttypes.Validator)

func (*EpochState) InCommittee

func (es *EpochState) InCommittee() bool

func (*EpochState) PrintCommittee

func (es *EpochState) PrintCommittee()

type Executor

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

func NewExecutor

func NewExecutor(proxyApp cmtproxy.AppConnConsensus, c *chain.Chain) *Executor

func (*Executor) ApplyBlock

func (e *Executor) ApplyBlock(block *block.Block, syncingToHeight int64) ([]byte, *cmttypes.ValidatorSet, error)

ApplyBlock validates the block against the state, executes it against the app, fires the relevant events, commits the app, and saves the new state and responses. It returns the new state. It's the only function that needs to be called from outside this package to process and commit an entire block. It takes a blockID to avoid recomputing the parts hash.

func (*Executor) Commit

func (e *Executor) Commit() (*abcitypes.CommitResponse, error)

func (*Executor) ExtendVote

func (*Executor) FinalizeBlock

func (*Executor) InitChain

func (*Executor) PrepareProposal

func (e *Executor) PrepareProposal(parent *block.DraftBlock, proposerIndex int) (*abcitypes.PrepareProposalResponse, error)

func (*Executor) ProcessProposal

func (e *Executor) ProcessProposal(blk *block.Block) (bool, error)

func (*Executor) SetEventBus

func (e *Executor) SetEventBus(eventBus cmttypes.BlockEventPublisher)

SetEventBus - sets the event bus for publishing block related events. If not called, it defaults to types.NopEventBus.

type Handshaker

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

func NewHandshaker

func NewHandshaker(c *chain.Chain, genDoc *cmttypes.GenesisDoc,
) *Handshaker

func (*Handshaker) Handshake

func (h *Handshaker) Handshake(ctx context.Context, proxyApp proxy.AppConns) error

TODO: retry the handshake/replay if it fails ?

func (*Handshaker) NBlocks

func (h *Handshaker) NBlocks() int

NBlocks returns the number of blocks applied to the state.

func (*Handshaker) ReplayBlocks

func (h *Handshaker) ReplayBlocks(
	ctx context.Context,
	appHash []byte,
	appBlockHeight int64,
	proxyApp proxy.AppConns,
) ([]byte, error)

ReplayBlocks replays all blocks since appBlockHeight and ensures the result matches the current state. Returns the final AppHash or an error.

func (*Handshaker) SetEventBus

func (h *Handshaker) SetEventBus(eventBus cmttypes.BlockEventPublisher)

SetEventBus - sets the event bus for publishing block related events. If not called, it defaults to types.NopEventBus.

func (*Handshaker) SetLogger

func (h *Handshaker) SetLogger(l log.Logger)

type IncomingMsg

type IncomingMsg struct {
	//Msg    block.ConsensusMessage
	// from envelope
	Msg        block.ConsensusMessage
	SenderAddr common.Address

	// extras
	Hash         types.Bytes32
	ShortHashStr string
	EnqueueAt    time.Time
	ExpireAt     time.Time
	ProcessCount uint32
}

func (*IncomingMsg) Expired

func (m *IncomingMsg) Expired() bool

type IncomingQueue

type IncomingQueue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewIncomingQueue

func NewIncomingQueue() *IncomingQueue

func (*IncomingQueue) Add

func (q *IncomingQueue) Add(mi IncomingMsg) error

func (*IncomingQueue) DelayedAdd

func (q *IncomingQueue) DelayedAdd(mi IncomingMsg)

func (*IncomingQueue) Len

func (q *IncomingQueue) Len() int

func (*IncomingQueue) Queue

func (q *IncomingQueue) Queue() chan (IncomingMsg)

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 PMBeatInfo

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

type PMCmd

type PMCmd uint32

enum PMCmd

func (PMCmd) String

func (cmd PMCmd) String() string

type PMProbeResult

type PMProbeResult struct {
	CurRound       uint32
	InCommittee    bool
	CommitteeIndex int
	CommitteeSize  int

	LastVotingHeight uint32
	LastOnBeatRound  uint32
	QCHigh           *block.QuorumCert
	LastCommitted    *BlockProbe

	ProposalCount int
}

type PMRoundTimeoutInfo

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

struct

type PMVoteInfo

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

type Pacemaker

type Pacemaker struct {
	QCHigh *block.DraftQC

	TCHigh *types.TimeoutCert
	// contains filtered or unexported fields
}

func NewPacemaker

func NewPacemaker(ctx context.Context, version string, c *chain.Chain, txpool *txpool.TxPool, p2pSrv p2p.P2P, blsMaster *types.BlsMaster, proxyApp cmtproxy.AppConns) *Pacemaker

func (*Pacemaker) AddIncoming added in v0.0.2

func (p *Pacemaker) AddIncoming(mi IncomingMsg)

func (*Pacemaker) AddTxToCurProposal

func (p *Pacemaker) AddTxToCurProposal(newTxID []byte) error

Build MBlock

func (*Pacemaker) Broadcast added in v0.0.2

func (p *Pacemaker) Broadcast(msg block.ConsensusMessage)

func (*Pacemaker) BuildProposalMessage

func (p *Pacemaker) BuildProposalMessage(height, round uint32, bnew *block.DraftBlock, tc *types.TimeoutCert) (*block.PMProposalMessage, error)

func (*Pacemaker) BuildQueryMessage

func (p *Pacemaker) BuildQueryMessage() (*block.PMQueryMessage, error)

BuildQueryMessage

func (*Pacemaker) BuildTimeoutMessage

func (p *Pacemaker) BuildTimeoutMessage(qcHigh *block.DraftQC, ti *PMRoundTimeoutInfo, lastVoteMsg *block.PMVoteMessage) (*block.PMTimeoutMessage, error)

BuildVoteForProposalMsg build VFP message for proposal

func (*Pacemaker) BuildVoteMessage

func (p *Pacemaker) BuildVoteMessage(proposalMsg *block.PMProposalMessage) (*block.PMVoteMessage, error)

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

func (*Pacemaker) CommitBlock

func (p *Pacemaker) CommitBlock(blk *block.Block, escortQC *block.QuorumCert) error

finalize the block with its own QC

func (*Pacemaker) CreateLeaf

func (p *Pacemaker) CreateLeaf(parent *block.DraftBlock, justify *block.DraftQC, round uint32) (error, *block.DraftBlock)

func (*Pacemaker) EpochStartKBlockNum

func (p *Pacemaker) EpochStartKBlockNum() uint32

func (*Pacemaker) ExtendedFromLastCommitted

func (p *Pacemaker) ExtendedFromLastCommitted(b *block.DraftBlock) bool

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

func (*Pacemaker) OnBeat

func (p *Pacemaker) OnBeat(epoch uint64, round uint32)

func (*Pacemaker) OnBroadcastProposal

func (p *Pacemaker) OnBroadcastProposal()

func (*Pacemaker) OnCommit

func (p *Pacemaker) OnCommit(commitReady []commitReadyBlock) (lastCommitted *block.Block)

func (*Pacemaker) OnPropose

func (p *Pacemaker) OnPropose(qc *block.DraftQC, round uint32) *block.DraftBlock

func (*Pacemaker) OnReceiveProposal

func (p *Pacemaker) OnReceiveProposal(mi IncomingMsg)

func (*Pacemaker) OnReceiveQuery

func (p *Pacemaker) OnReceiveQuery(mi IncomingMsg)

func (*Pacemaker) OnReceiveTimeout

func (p *Pacemaker) OnReceiveTimeout(mi IncomingMsg)

func (*Pacemaker) OnReceiveVote

func (p *Pacemaker) OnReceiveVote(mi IncomingMsg)

func (*Pacemaker) OnRoundTimeout

func (p *Pacemaker) OnRoundTimeout(ti PMRoundTimeoutInfo)

func (*Pacemaker) Probe

func (p *Pacemaker) Probe() *PMProbeResult

func (*Pacemaker) Regulate

func (p *Pacemaker) Regulate()

Committee Leader triggers

func (*Pacemaker) ScheduleRegulate

func (p *Pacemaker) ScheduleRegulate()

func (*Pacemaker) SignMessage

func (p *Pacemaker) SignMessage(msg block.ConsensusMessage)

func (*Pacemaker) Start

func (p *Pacemaker) Start()

func (*Pacemaker) Update

func (p *Pacemaker) Update(qc *block.QuorumCert) (lastCommitted *block.Block)

b_exec <- b_lock <- b <- b' <- bnew*

func (*Pacemaker) UpdateQCHigh

func (p *Pacemaker) UpdateQCHigh(qc *block.DraftQC) bool

func (*Pacemaker) ValidateProposal

func (p *Pacemaker) ValidateProposal(b *block.DraftBlock) error

func (*Pacemaker) ValidateQC

func (p *Pacemaker) ValidateQC(b *block.Block, escortQC *block.QuorumCert) bool

type QCVoteManager

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

func NewQCVoteManager

func NewQCVoteManager(committeeSize uint32) *QCVoteManager

func (*QCVoteManager) AddVote

func (m *QCVoteManager) AddVote(index uint32, epoch uint64, round uint32, blockID types.Bytes32, sig []byte) *block.QuorumCert

func (*QCVoteManager) Aggregate

func (m *QCVoteManager) Aggregate(round uint32, blockID types.Bytes32, epoch uint64) *block.QuorumCert

func (*QCVoteManager) CleanUpTo

func (m *QCVoteManager) CleanUpTo(blockNum uint32)

func (*QCVoteManager) Count

func (m *QCVoteManager) Count(round uint32, blockID types.Bytes32) uint32

func (*QCVoteManager) Size

func (m *QCVoteManager) Size() uint32

type Reactor

type Reactor struct {
	Pacemaker

	SyncDone bool
	// contains filtered or unexported fields
}

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

func NewConsensusReactor

func NewConsensusReactor(ctx context.Context, config *cmtcfg.Config, chain *chain.Chain, p2pSrv p2p.P2P, txpool *txpool.TxPool, blsMaster *types.BlsMaster, proxyApp cmtproxy.AppConns) *Reactor

NewConsensusReactor returns a new Reactor with config

func (*Reactor) Start

func (r *Reactor) Start(ctx context.Context) 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 (*Reactor) ValidateSyncedBlock

func (r *Reactor) ValidateSyncedBlock(blk *block.Block, nowTimestamp uint64) error

Process process a block.

type ReactorConfig

type ReactorConfig struct {
	EpochMBlockCount uint32
	MinCommitteeSize int
	MaxCommitteeSize int
}

type TCVoteManager

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

func NewTCVoteManager

func NewTCVoteManager(committeeSize uint32) *TCVoteManager

func (*TCVoteManager) AddVote

func (m *TCVoteManager) AddVote(index uint32, epoch uint64, round uint32, sig []byte, hash [32]byte) *types.TimeoutCert

func (*TCVoteManager) Aggregate

func (m *TCVoteManager) Aggregate(epoch uint64, round uint32) *types.TimeoutCert

func (*TCVoteManager) CleanUpTo

func (m *TCVoteManager) CleanUpTo(epoch uint64)

func (*TCVoteManager) Count

func (m *TCVoteManager) Count(epoch uint64, round uint32) uint32

func (*TCVoteManager) Size

func (m *TCVoteManager) Size() uint32

type ValidatorSetRegistry

type ValidatorSetRegistry struct {
	CurrentVSet map[uint32]*cmttypes.ValidatorSet
	NextVSet    map[uint32]*cmttypes.ValidatorSet
	Chain       *chain.Chain
	// contains filtered or unexported fields
}

func NewValidatorSetRegistry

func NewValidatorSetRegistry(c *chain.Chain) *ValidatorSetRegistry

func (*ValidatorSetRegistry) Get

func (*ValidatorSetRegistry) GetNext

func (*ValidatorSetRegistry) Prune

func (vr *ValidatorSetRegistry) Prune()

func (*ValidatorSetRegistry) Update

func (vr *ValidatorSetRegistry) Update(num uint32, vset *cmttypes.ValidatorSet, updates abcitypes.ValidatorUpdates, events []abcitypes.Event) (nxtVSet *cmttypes.ValidatorSet, addedValidators []*cmttypes.Validator, err error)

Jump to

Keyboard shortcuts

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