consensus

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigEnginePriority = 2
	ConfigSyncerPriority = 3

	ConfigBlockPartSize = 1024 * 100
)
View Source
const (
	ProtoProposal module.ProtocolInfo = iota << 8
	ProtoBlockPart
	ProtoVote
	ProtoRoundState
	ProtoVoteList
)

Variables

Functions

func DecodePatch

func DecodePatch(t string, bs []byte) (module.Patch, error)

func IsCorruptedWAL

func IsCorruptedWAL(err error) bool

func IsEOF

func IsEOF(err error) bool

func IsNotExist

func IsNotExist(err error) bool

func IsUnexpectedEOF

func IsUnexpectedEOF(err error) bool

func New added in v0.9.10

func New(
	c base.Chain,
	walDir string,
	wm WALManager,
	timestamper module.Timestamper,
	bpp fastsync.BlockProofProvider,
	lastVoteData *LastVoteData,
) *consensus

func NewCommitVoteList added in v0.9.10

func NewCommitVoteList(pcm module.BTPProofContextMap, msgs ...*VoteMessage) module.CommitVoteSet

func NewCommitVoteSetFromBytes

func NewCommitVoteSetFromBytes(bs []byte) module.CommitVoteSet

NewCommitVoteSetFromBytes returns VoteList from serialized bytes

func NewConsensus

func NewConsensus(
	c base.Chain,
	walDir string,
	timestamper module.Timestamper,
	bpp fastsync.BlockProofProvider,
) module.Consensus

func NewEmptyCommitVoteList added in v0.9.10

func NewEmptyCommitVoteList() module.CommitVoteSet

func NewTestWAL added in v1.3.2

func NewTestWAL() *testWAL

func ResetWAL added in v0.9.4

func ResetWAL(height int64, dir string, voteListBytes []byte) error

func StartConsensusWithLastVotes added in v1.3.0

func StartConsensusWithLastVotes(cs module.Consensus, lastVoteData *LastVoteData) error

func WALRecordBytesFromCommitVoteListBytes added in v1.1.1

func WALRecordBytesFromCommitVoteListBytes(
	bs []byte, h int64, bid []byte, result []byte,
	validators module.ValidatorList,
	ntsHashEntries module.NTSHashEntryList,
	dbase db.Database, c codec.Codec,
) ([]byte, error)

Types

type BlockPartMessage added in v0.9.10

type BlockPartMessage struct {
	// V1 Fields
	// for debugging
	Height int64
	Index  uint16

	BlockPart []byte

	// V2 Fields
	Nonce int32
}

func (*BlockPartMessage) String added in v0.9.10

func (msg *BlockPartMessage) String() string

func (*BlockPartMessage) Verify added in v0.9.10

func (msg *BlockPartMessage) Verify() error

type CommitVoteList added in v1.3.0

type CommitVoteList struct {
	NTSDProves [][]byte
	// contains filtered or unexported fields
}

func (*CommitVoteList) BlockVoteSetBytes added in v1.3.0

func (bvl *CommitVoteList) BlockVoteSetBytes() []byte

func (*CommitVoteList) Bytes added in v1.3.0

func (vl *CommitVoteList) Bytes() []byte

func (*CommitVoteList) Hash added in v1.3.0

func (vl *CommitVoteList) Hash() []byte

func (*CommitVoteList) NTSDProofAt added in v1.3.0

func (vl *CommitVoteList) NTSDProofAt(i int) []byte

func (*CommitVoteList) NTSDProofCount added in v1.3.0

func (vl *CommitVoteList) NTSDProofCount() int

func (*CommitVoteList) RLPDecodeSelf added in v1.3.0

func (vl *CommitVoteList) RLPDecodeSelf(d codec.Decoder) error

func (*CommitVoteList) RLPEncodeSelf added in v1.3.0

func (vl *CommitVoteList) RLPEncodeSelf(e codec.Encoder) error

func (*CommitVoteList) String added in v1.3.0

func (vl *CommitVoteList) String() string

func (*CommitVoteList) Timestamp added in v1.3.0

func (bvl *CommitVoteList) Timestamp() int64

func (*CommitVoteList) VerifyBlock added in v1.3.0

func (bvl *CommitVoteList) VerifyBlock(block module.BlockData, validators module.ValidatorList) ([]bool, error)

func (*CommitVoteList) VoteRound added in v1.3.0

func (bvl *CommitVoteList) VoteRound() int32

type Engine

type Engine interface {
	fastsync.BlockProofProvider

	GetCommitBlockParts(h int64) PartSet
	GetCommitPrecommits(h int64) *VoteList
	GetPrecommits(r int32) *VoteList
	// GetVotes returns union of a set of prevotes pv(i) where
	// pvMask.Get(i) == 0 and a set of precommits pc(i) where
	// pcMask.Get(i) == 0. For example, if the all bits for mask is 1,
	// no votes are returned.
	GetVotes(r int32, pvMask *bitArray, pcMask *bitArray) *VoteList
	GetRoundState() *peerRoundState

	Height() int64
	Round() int32
	Step() step

	ReceiveBlockPartMessage(msg *BlockPartMessage, unicast bool) (int, error)
	ReceiveVoteListMessage(msg *VoteListMessage, unicast bool) error
	ReceiveBlock(br fastsync.BlockResult)
}

type LastVoteData added in v0.9.10

type LastVoteData struct {
	Height     int64
	VotesBytes []byte
}

type Message added in v0.9.10

type Message interface {
	Verify() error
	// contains filtered or unexported methods
}

func UnmarshalMessage added in v0.9.10

func UnmarshalMessage(sp uint16, bs []byte) (Message, error)

type Part

type Part interface {
	Index() int
	Bytes() []byte
}

func NewPart added in v0.9.10

func NewPart(b []byte) (Part, error)

type PartSet

type PartSet interface {
	ID() *PartSetID
	Parts() int
	GetPart(int) Part
	IsComplete() bool
	NewReader() io.Reader
	AddPart(Part) error
	GetMask() *bitArray
}

func NewPartSetFromID added in v0.9.10

func NewPartSetFromID(h *PartSetID) PartSet

type PartSetBuffer

type PartSetBuffer interface {
	io.Writer
	PartSet() PartSet
}

func NewPartSetBuffer added in v1.3.0

func NewPartSetBuffer(sz int) PartSetBuffer

type PartSetID

type PartSetID struct {
	Count uint16
	Hash  []byte
}

func (*PartSetID) Equal

func (id *PartSetID) Equal(id2 *PartSetID) bool

func (PartSetID) String

func (id PartSetID) String() string

func (*PartSetID) WithAppData added in v1.3.0

func (id *PartSetID) WithAppData(appData uint16) *PartSetIDAndAppData

type PartSetIDAndAppData added in v1.3.0

type PartSetIDAndAppData struct {
	// CountWord: MSB AppData(16) Count(16)
	// Use bitfield not to break existing message protocol
	CountWord uint32
	Hash      []byte
}

func (*PartSetIDAndAppData) AppData added in v1.3.0

func (ida *PartSetIDAndAppData) AppData() uint16

func (*PartSetIDAndAppData) ID added in v1.3.0

func (ida *PartSetIDAndAppData) ID() *PartSetID

type ProposalMessage added in v0.9.10

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

func NewProposalMessage added in v0.9.10

func NewProposalMessage() *ProposalMessage

func (*ProposalMessage) String added in v0.9.10

func (msg *ProposalMessage) String() string

func (*ProposalMessage) Verify added in v0.9.10

func (msg *ProposalMessage) Verify() error

type RoundStateMessage added in v0.9.10

type RoundStateMessage struct {
	Timestamp int64
	// contains filtered or unexported fields
}

func (RoundStateMessage) String added in v0.9.10

func (msg RoundStateMessage) String() string

func (*RoundStateMessage) Verify added in v0.9.10

func (msg *RoundStateMessage) Verify() error

type Syncer

type Syncer interface {
	Start() error
	Stop()
	OnEngineStepChange()
}

type VoteItem

type VoteItem struct {
	PrototypeIndex int16
	Timestamp      int64
	Signature      common.Signature
	NTSDProofParts [][]byte
}

type VoteList added in v1.3.2

type VoteList struct {
	Prototypes []voteBase
	VoteItems  []VoteItem
}

func NewVoteList added in v1.3.2

func NewVoteList() *VoteList

func (*VoteList) AddVote added in v1.3.2

func (vl *VoteList) AddVote(msg *VoteMessage)

func (*VoteList) Get added in v1.3.2

func (vl *VoteList) Get(i int) *VoteMessage

func (*VoteList) Len added in v1.3.2

func (vl *VoteList) Len() int

func (VoteList) String added in v1.3.2

func (vl VoteList) String() string

type VoteListMessage added in v1.3.2

type VoteListMessage struct {
	VoteList *VoteList
}

func (VoteListMessage) String added in v1.3.2

func (msg VoteListMessage) String() string

func (*VoteListMessage) Verify added in v1.3.2

func (msg *VoteListMessage) Verify() error

type VoteMessage added in v1.3.0

type VoteMessage struct {
	Timestamp      int64
	NTSDProofParts [][]byte
	// contains filtered or unexported fields
}

func NewVoteMessage added in v0.9.10

func NewVoteMessage(
	w module.Wallet,
	voteType VoteType, height int64, round int32, id []byte,
	partSetID *PartSetID, ts int64,
	ntsHashEntries []module.NTSHashEntryFormat,
	ntsdProofParts [][]byte,
	ntsVoteCount int,
) *VoteMessage

NewVoteMessage returns a new VoteMessage. Used only for test.

func NewVoteMessageFromBlock added in v1.3.0

func NewVoteMessageFromBlock(
	w module.Wallet,
	wp module.WalletProvider,
	blk module.BlockData,
	round int32,
	voteType VoteType,
	bpsIDAndNTSVoteCount *PartSetIDAndAppData,
	ts int64,
	nid int,
	pcm module.BTPProofContextMap,
) (*VoteMessage, error)

NewVoteMessageFromBlock creates a new VoteMessage from block data. pcm is blk.Height()-1's nextPCM. Used only for test

func (*VoteMessage) Equal added in v1.3.0

func (v *VoteMessage) Equal(v2 *voteBase) bool

func (*VoteMessage) EqualExceptSigs added in v1.3.0

func (msg *VoteMessage) EqualExceptSigs(msg2 *VoteMessage) bool

func (*VoteMessage) RLPDecodeSelf added in v1.3.0

func (msg *VoteMessage) RLPDecodeSelf(d codec.Decoder) error

func (*VoteMessage) RLPEncodeSelf added in v1.3.0

func (msg *VoteMessage) RLPEncodeSelf(e codec.Encoder) error

func (*VoteMessage) RoundDecisionDigest added in v1.3.0

func (v *VoteMessage) RoundDecisionDigest() []byte

RoundDecisionDigest returns digest for a vote. The digest values of two votes are different if their BlockID, BlockPartSetIDAndNTSVoteCount, len(NTSVotes), NTSVotes[i].NetworkTypeID or NTSVotes[i].NetworkTypeSectionHash is different where 0 <= i < len(NTSVotes).

func (*VoteMessage) SetRoundDecision added in v1.3.0

func (v *VoteMessage) SetRoundDecision(bid []byte, bpsIDAndNTSVoteCount *PartSetIDAndAppData, ntsVoteBases []ntsVoteBase)

func (*VoteMessage) String added in v1.3.0

func (msg *VoteMessage) String() string

func (*VoteMessage) Verify added in v1.3.0

func (msg *VoteMessage) Verify() error

func (*VoteMessage) VerifyNTSDProofParts added in v1.3.0

func (msg *VoteMessage) VerifyNTSDProofParts(
	pcm module.BTPProofContextMap,
	srcUID []byte,
	expValIndex int,
) error

type VoteSet added in v0.9.10

type VoteSet interface {
	// CommitVoteSet converts VoteSet to CommitVoteSet.
	CommitVoteSet(pcm module.BTPProofContextMap) (module.CommitVoteSet, error)
	Add(idx int, vote interface{}) bool
}

type VoteType added in v0.9.10

type VoteType byte
const (
	VoteTypePrevote VoteType = iota
	VoteTypePrecommit
)

func (VoteType) String added in v0.9.10

func (vt VoteType) String() string

type WALConfig

type WALConfig struct {
	FileLimit            int64
	TotalLimit           int64
	HousekeepingInterval time.Duration
	SyncInterval         time.Duration
}

type WALManager

type WALManager interface {
	OpenForRead(id string) (WALReader, error)
	OpenForWrite(id string, cfg *WALConfig) (WALWriter, error)
}

type WALReader

type WALReader interface {
	ReadBytes() ([]byte, error)
	// Close closes reader. Multiple call of Close is safe.
	Close() error
	// CloseAndRepair closes and repairs UnexpectedEOF or CorruptedWAL by
	// truncating.
	CloseAndRepair() error
}

func OpenWALForRead

func OpenWALForRead(id string) (WALReader, error)

type WALWriter

type WALWriter interface {
	WriteBytes([]byte) (int, error)
	Sync() error
	Close() error
}

func OpenWALForWrite

func OpenWALForWrite(id string, cfg *WALConfig) (WALWriter, error)

OpenWALForWrite opens WALWriter. id is in the form /wal/dir/prefix

type WalMessageWriter added in v1.3.2

type WalMessageWriter struct {
	WALWriter
}

func (*WalMessageWriter) WriteMessage added in v1.3.2

func (w *WalMessageWriter) WriteMessage(msg Message) error

func (*WalMessageWriter) WriteMessageBytes added in v1.3.2

func (w *WalMessageWriter) WriteMessageBytes(sp uint16, msg []byte) error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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