consensus

package
v0.0.0-...-5d85a61 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateChannel       = 0x20
	DataChannel        = 0x21
	VoteChannel        = 0x22
	VoteSetBitsChannel = 0x23
)
View Source
const (
	RoundStepNewHeight         = RoundStepType(0x01)
	RoundStepNewRound          = RoundStepType(0x02)
	RoundStepWaitForMinerBlock = RoundStepType(0x03)
	RoundStepPropose           = RoundStepType(0x04)
	RoundStepPrevote           = RoundStepType(0x05)
	RoundStepPrevoteWait       = RoundStepType(0x06)
	RoundStepPrecommit         = RoundStepType(0x07)
	RoundStepPrecommitWait     = RoundStepType(0x08)
	RoundStepCommit            = RoundStepType(0x09)
)
View Source
const ROUND_NOT_PROPOSED int = 0
View Source
const ROUND_PROPOSED int = 1

Variables

View Source
var (
	ErrPeerStateHeightRegression = errors.New("Error peer state height regression")
	ErrPeerStateInvalidStartTime = errors.New("Error peer state invalid startTime")
)
View Source
var (
	ErrMinerBlock               = errors.New("Miner block is nil")
	ErrInvalidProposalSignature = errors.New("Error invalid proposal signature")
	ErrInvalidProposalPOLRound  = errors.New("Error invalid proposal POL round")
	ErrAddingVote               = errors.New("Error adding vote")
	ErrVoteHeightMismatch       = errors.New("Error vote height mismatch")
	ErrInvalidSignatureAggr     = errors.New("Invalid signature aggregation")
	ErrDuplicateSignatureAggr   = errors.New("Duplicate signature aggregation")
	ErrNotMaj23SignatureAggr    = errors.New("Signature aggregation has no +2/3 power")
)
View Source
var Major = "6"
View Source
var Minor = "5"
View Source
var NodeID = ""
View Source
var Revision = "1"
View Source
var Spec = "1"
View Source
var Version = Fmt("v%s/%s.%s.%s", Spec, Major, Minor, Revision)

Functions

func BytesToBig

func BytesToBig(data []byte) *big.Int

func CompareHRS

func CompareHRS(h1 uint64, r1 int, s1 RoundStepType, h2 uint64, r2 int, s2 RoundStepType) int

Types

type Backend

type Backend interface {
	Commit(proposal *types.NCBlock, seals [][]byte, isProposer func() bool) error
	ChainReader() consss.ChainReader
	GetBroadcaster() consss.Broadcaster
	GetLogger() log.Logger
}

type BlockPartMessage

type BlockPartMessage struct {
	Height uint64
	Round  int
	Part   *types.Part
}

func (*BlockPartMessage) String

func (m *BlockPartMessage) String() string

type CommitStepMessage

type CommitStepMessage struct {
	Height           uint64
	BlockPartsHeader types.PartSetHeader
	BlockParts       *BitArray
}

func (*CommitStepMessage) String

func (m *CommitStepMessage) String() string

type ConsensusMessage

type ConsensusMessage interface{}

func DecodeMessage

func DecodeMessage(bz []byte) (msgType byte, msg ConsensusMessage, err error)

type ConsensusReactor

type ConsensusReactor struct {
	BaseService

	ChainId string
	// contains filtered or unexported fields
}

func NewConsensusReactor

func NewConsensusReactor(consensusState *ConsensusState) *ConsensusReactor

func (*ConsensusReactor) AddPeer

func (conR *ConsensusReactor) AddPeer(peer consensus.Peer)

func (*ConsensusReactor) AfterStart

func (conR *ConsensusReactor) AfterStart()

func (*ConsensusReactor) OnStart

func (conR *ConsensusReactor) OnStart() error

func (*ConsensusReactor) OnStop

func (conR *ConsensusReactor) OnStop()

func (*ConsensusReactor) Receive

func (conR *ConsensusReactor) Receive(chID uint64, src consensus.Peer, msgBytes []byte)

func (*ConsensusReactor) RemovePeer

func (conR *ConsensusReactor) RemovePeer(peer consensus.Peer, reason interface{})

func (*ConsensusReactor) SetEventSwitch

func (conR *ConsensusReactor) SetEventSwitch(evsw types.EventSwitch)

func (*ConsensusReactor) String

func (conR *ConsensusReactor) String() string

type ConsensusState

type ConsensusState struct {
	BaseService

	RoundState
	Epoch *ep.Epoch
	// contains filtered or unexported fields
}

func NewConsensusState

func NewConsensusState(backend Backend, config cfg.Config, chainConfig *params.ChainConfig, cch core.CrossChainHelper, epoch *ep.Epoch) *ConsensusState

func (*ConsensusState) AddProposalBlockPart

func (cs *ConsensusState) AddProposalBlockPart(height uint64, round int, part *types.Part, peerKey string) error

func (*ConsensusState) AddVote

func (cs *ConsensusState) AddVote(vote *types.Vote, peerKey string) (added bool, err error)

func (*ConsensusState) BLSVerifySignAggr

func (cs *ConsensusState) BLSVerifySignAggr(signAggr *types.SignAggr) (bool, error)

func (*ConsensusState) GetChainReader

func (bs *ConsensusState) GetChainReader() consss.ChainReader

func (*ConsensusState) GetProposer

func (cs *ConsensusState) GetProposer() *types.Validator

func (*ConsensusState) GetRoundState

func (cs *ConsensusState) GetRoundState() *RoundState

func (*ConsensusState) GetState

func (cs *ConsensusState) GetState() *sm.State

func (*ConsensusState) GetValidators

func (cs *ConsensusState) GetValidators() (uint64, []*types.Validator)

func (*ConsensusState) InitState

func (cs *ConsensusState) InitState(epoch *ep.Epoch) *sm.State

func (*ConsensusState) Initialize

func (cs *ConsensusState) Initialize()

func (*ConsensusState) IsProposer

func (cs *ConsensusState) IsProposer() bool

func (*ConsensusState) LoadBlock

func (cs *ConsensusState) LoadBlock(height uint64) *types.NCBlock

func (*ConsensusState) LoadCommit

func (cs *ConsensusState) LoadCommit(height uint64) *types.Commit

func (*ConsensusState) LoadLastTendermintExtra

func (cs *ConsensusState) LoadLastTendermintExtra() (*types.TendermintExtra, uint64)

func (*ConsensusState) LoadTendermintExtra

func (cs *ConsensusState) LoadTendermintExtra(height uint64) (*types.TendermintExtra, uint64)

func (*ConsensusState) OnStart

func (cs *ConsensusState) OnStart() error

func (*ConsensusState) OnStop

func (cs *ConsensusState) OnStop()

func (*ConsensusState) ReconstructLastCommit

func (cs *ConsensusState) ReconstructLastCommit(state *sm.State)

func (*ConsensusState) SetEventSwitch

func (cs *ConsensusState) SetEventSwitch(evsw types.EventSwitch)

func (*ConsensusState) SetPrivValidator

func (cs *ConsensusState) SetPrivValidator(priv PrivValidator)

func (*ConsensusState) SetProposal

func (cs *ConsensusState) SetProposal(proposal *types.Proposal, peerKey string) error

func (*ConsensusState) SetProposalAndBlock

func (cs *ConsensusState) SetProposalAndBlock(proposal *types.Proposal, block *types.NCBlock, parts *types.PartSet, peerKey string) error

func (*ConsensusState) SetTimeoutTicker

func (cs *ConsensusState) SetTimeoutTicker(timeoutTicker TimeoutTicker)

func (*ConsensusState) StartNewHeight

func (cs *ConsensusState) StartNewHeight()

func (*ConsensusState) String

func (cs *ConsensusState) String() string

func (*ConsensusState) UpdateToState

func (cs *ConsensusState) UpdateToState(state *sm.State)

func (*ConsensusState) ValidateTX4

func (cs *ConsensusState) ValidateTX4(b *types.NCBlock) error

func (*ConsensusState) Wait

func (cs *ConsensusState) Wait()

type HasVoteMessage

type HasVoteMessage struct {
	Height uint64
	Round  int
	Type   byte
	Index  int
}

func (*HasVoteMessage) String

func (m *HasVoteMessage) String() string

type HeightVoteSet

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

func NewHeightVoteSet

func NewHeightVoteSet(chainID string, height uint64, valSet *types.ValidatorSet, logger log.Logger) *HeightVoteSet

func (*HeightVoteSet) AddVote

func (hvs *HeightVoteSet) AddVote(vote *types.Vote, peerKey string) (added bool, err error)

func (*HeightVoteSet) Height

func (hvs *HeightVoteSet) Height() uint64

func (*HeightVoteSet) POLInfo

func (hvs *HeightVoteSet) POLInfo() (polRound int, polBlockID types.BlockID)

func (*HeightVoteSet) Precommits

func (hvs *HeightVoteSet) Precommits(round int) *types.VoteSet

func (*HeightVoteSet) Prevotes

func (hvs *HeightVoteSet) Prevotes(round int) *types.VoteSet

func (*HeightVoteSet) Reset

func (hvs *HeightVoteSet) Reset(height uint64, valSet *types.ValidatorSet)

func (*HeightVoteSet) ResetTop2Round

func (hvs *HeightVoteSet) ResetTop2Round(round int)

func (*HeightVoteSet) Round

func (hvs *HeightVoteSet) Round() int

func (*HeightVoteSet) SetPeerMaj23

func (hvs *HeightVoteSet) SetPeerMaj23(round int, type_ byte, peerID string, blockID types.BlockID)

func (*HeightVoteSet) SetRound

func (hvs *HeightVoteSet) SetRound(round int)

func (*HeightVoteSet) String

func (hvs *HeightVoteSet) String() string

func (*HeightVoteSet) StringIndented

func (hvs *HeightVoteSet) StringIndented(indent string) string

type HeightVoteSignAggr

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

func NewHeightVoteSignAggr

func NewHeightVoteSignAggr(chainID string, height uint64, valSet *types.ValidatorSet, logger log.Logger) *HeightVoteSignAggr

func (*HeightVoteSignAggr) AddSignAggr

func (hvs *HeightVoteSignAggr) AddSignAggr(signAggr *types.SignAggr) (added bool, err error)

func (*HeightVoteSignAggr) Height

func (hvs *HeightVoteSignAggr) Height() uint64

func (*HeightVoteSignAggr) POLInfo

func (hvs *HeightVoteSignAggr) POLInfo() (polRound int, polBlockID types.BlockID)

func (*HeightVoteSignAggr) Precommits

func (hvs *HeightVoteSignAggr) Precommits(round int) *types.SignAggr

func (*HeightVoteSignAggr) Prevotes

func (hvs *HeightVoteSignAggr) Prevotes(round int) *types.SignAggr

func (*HeightVoteSignAggr) Reset

func (hvs *HeightVoteSignAggr) Reset(height uint64, valSet *types.ValidatorSet)

func (*HeightVoteSignAggr) ResetTop2Round

func (hvs *HeightVoteSignAggr) ResetTop2Round(round int)

func (*HeightVoteSignAggr) Round

func (hvs *HeightVoteSignAggr) Round() int

func (*HeightVoteSignAggr) SetRound

func (hvs *HeightVoteSignAggr) SetRound(round int)

func (*HeightVoteSignAggr) String

func (hvs *HeightVoteSignAggr) String() string

func (*HeightVoteSignAggr) StringIndented

func (hvs *HeightVoteSignAggr) StringIndented(indent string) string

type Maj23SignAggrMessage

type Maj23SignAggrMessage struct {
	Maj23SignAggr *types.SignAggr
}

func (*Maj23SignAggrMessage) String

func (m *Maj23SignAggrMessage) String() string

type NewRoundStepMessage

type NewRoundStepMessage struct {
	Height                uint64
	Round                 int
	Step                  RoundStepType
	SecondsSinceStartTime int
	LastCommitRound       int
}

func (*NewRoundStepMessage) String

func (m *NewRoundStepMessage) String() string

type PeerRoundState

type PeerRoundState struct {
	Height                   uint64
	Round                    int
	Step                     RoundStepType
	StartTime                time.Time
	Proposal                 bool
	ProposalBlockPartsHeader types.PartSetHeader
	ProposalBlockParts       *BitArray
	ProposalPOLRound         int
	ProposalPOL              *BitArray
	Prevotes                 *BitArray
	Precommits               *BitArray

	PrevoteMaj23SignAggr   bool
	PrecommitMaj23SignAggr bool
}

func (PeerRoundState) String

func (prs PeerRoundState) String() string

func (PeerRoundState) StringIndented

func (prs PeerRoundState) StringIndented(indent string) string

type PeerState

type PeerState struct {
	Peer consensus.Peer

	PeerRoundState

	Connected bool
	// contains filtered or unexported fields
}

func NewPeerState

func NewPeerState(peer consensus.Peer, logger log.Logger) *PeerState

func (*PeerState) ApplyCommitStepMessage

func (ps *PeerState) ApplyCommitStepMessage(msg *CommitStepMessage)

func (*PeerState) ApplyHasVoteMessage

func (ps *PeerState) ApplyHasVoteMessage(msg *HasVoteMessage)

func (*PeerState) ApplyNewRoundStepMessage

func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage)

func (*PeerState) ApplyProposalPOLMessage

func (ps *PeerState) ApplyProposalPOLMessage(msg *ProposalPOLMessage)

func (*PeerState) ApplyVoteSetBitsMessage

func (ps *PeerState) ApplyVoteSetBitsMessage(msg *VoteSetBitsMessage, ourVotes *BitArray)

func (*PeerState) Disconnect

func (ps *PeerState) Disconnect()

func (*PeerState) EnsureVoteBitArrays

func (ps *PeerState) EnsureVoteBitArrays(height uint64, numValidators uint64)

func (*PeerState) GetHeight

func (ps *PeerState) GetHeight() uint64

func (*PeerState) GetRoundState

func (ps *PeerState) GetRoundState() *PeerRoundState

func (*PeerState) PickSendSignAggr

func (ps *PeerState) PickSendSignAggr(signAggr *types.SignAggr) (ok bool)

func (*PeerState) PickSendVote

func (ps *PeerState) PickSendVote(votes types.VoteSetReader) (ok bool)

func (*PeerState) PickVoteToSend

func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote, ok bool)

func (*PeerState) SetHasMaj23SignAggr

func (ps *PeerState) SetHasMaj23SignAggr(signAggr *types.SignAggr)

func (*PeerState) SetHasProposal

func (ps *PeerState) SetHasProposal(proposal *types.Proposal)

func (*PeerState) SetHasProposalBlockPart

func (ps *PeerState) SetHasProposalBlockPart(height uint64, round int, index int)

func (*PeerState) SetHasVote

func (ps *PeerState) SetHasVote(vote *types.Vote)

func (*PeerState) String

func (ps *PeerState) String() string

func (*PeerState) StringIndented

func (ps *PeerState) StringIndented(indent string) string

type PrivValidator

type PrivValidator interface {
	GetAddress() []byte
	GetPubKey() tmdcrypto.PubKey
	SignVote(chainID string, vote *types.Vote) error
	SignProposal(chainID string, proposal *types.Proposal) error
}

type ProposalMessage

type ProposalMessage struct {
	Proposal *types.Proposal
}

func (*ProposalMessage) String

func (m *ProposalMessage) String() string

type ProposalPOLMessage

type ProposalPOLMessage struct {
	Height           uint64
	ProposalPOLRound int
	ProposalPOL      *BitArray
}

func (*ProposalPOLMessage) String

func (m *ProposalPOLMessage) String() string

type RoundState

type RoundState struct {
	Height             uint64
	Round              int
	Step               RoundStepType
	StartTime          time.Time
	CommitTime         time.Time
	Validators         *types.ValidatorSet
	Proposal           *types.Proposal
	ProposalBlock      *types.NCBlock
	ProposalBlockParts *types.PartSet
	ProposerPeerKey    string
	LockedRound        int
	LockedBlock        *types.NCBlock
	LockedBlockParts   *types.PartSet
	Votes              *HeightVoteSet
	VoteSignAggr       *HeightVoteSignAggr
	CommitRound        int

	PrevoteMaj23SignAggr   *types.SignAggr
	PrecommitMaj23SignAggr *types.SignAggr
	// contains filtered or unexported fields
}

func (*RoundState) RoundStateEvent

func (rs *RoundState) RoundStateEvent() types.EventDataRoundState

func (*RoundState) String

func (rs *RoundState) String() string

func (*RoundState) StringIndented

func (rs *RoundState) StringIndented(indent string) string

func (*RoundState) StringShort

func (rs *RoundState) StringShort() string

type RoundStepType

type RoundStepType uint8

func (RoundStepType) String

func (rs RoundStepType) String() string

type RoundVoteSet

type RoundVoteSet struct {
	Prevotes   *types.VoteSet
	Precommits *types.VoteSet
}

type RoundVoteSignAggr

type RoundVoteSignAggr struct {
	Prevotes   *types.SignAggr
	Precommits *types.SignAggr
}

type TimeoutParams

type TimeoutParams struct {
	WaitForMinerBlock0 int
	Propose0           int
	ProposeDelta       int
	Prevote0           int
	PrevoteDelta       int
	Precommit0         int
	PrecommitDelta     int
	Commit0            int
	SkipTimeoutCommit  bool
}

func InitTimeoutParamsFromConfig

func InitTimeoutParamsFromConfig(config cfg.Config) *TimeoutParams

func (*TimeoutParams) Commit

func (tp *TimeoutParams) Commit(t time.Time) time.Time

func (*TimeoutParams) Precommit

func (tp *TimeoutParams) Precommit(round int) time.Duration

func (*TimeoutParams) Prevote

func (tp *TimeoutParams) Prevote(round int) time.Duration

func (*TimeoutParams) Propose

func (tp *TimeoutParams) Propose(round int) time.Duration

func (*TimeoutParams) WaitForMinerBlock

func (tp *TimeoutParams) WaitForMinerBlock() time.Duration

type TimeoutTicker

type TimeoutTicker interface {
	Start() (bool, error)
	Stop() bool
	Chan() <-chan timeoutInfo
	ScheduleTimeout(ti timeoutInfo)
}

func NewTimeoutTicker

func NewTimeoutTicker(logger log.Logger) TimeoutTicker

type VRFProposer

type VRFProposer struct {
	Height uint64
	Round  int

	Proposer *types.Validator
	// contains filtered or unexported fields
}

func (*VRFProposer) Validate

func (propser *VRFProposer) Validate(height uint64, round int) bool

type VoteMessage

type VoteMessage struct {
	Vote *types.Vote
}

func (*VoteMessage) String

func (m *VoteMessage) String() string

type VoteSetBitsMessage

type VoteSetBitsMessage struct {
	Height  uint64
	Round   int
	Type    byte
	BlockID types.BlockID
	Votes   *BitArray
}

func (*VoteSetBitsMessage) String

func (m *VoteSetBitsMessage) String() string

type VoteSetMaj23Message

type VoteSetMaj23Message struct {
	Height  uint64
	Round   int
	Type    byte
	BlockID types.BlockID
}

func (*VoteSetMaj23Message) String

func (m *VoteSetMaj23Message) String() string

Jump to

Keyboard shortcuts

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