consensus

package
v1.1.0-hotfix Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigEnginePriority = 2
	ConfigSyncerPriority = 3
)
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(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 NewPrecommitMessage added in v0.9.10

func NewPrecommitMessage(
	w module.Wallet,
	height int64, round int32, id []byte, partSetID *PartSetID, ts int64,
) *voteMessage

func NewVoteMessage added in v0.9.10

func NewVoteMessage(
	w module.Wallet,
	voteType VoteType, height int64, round int32, id []byte,
	partSetID *PartSetID, ts int64,
) *voteMessage

func ResetWAL added in v0.9.4

func ResetWAL(height int64, dir string) error

func WALReadObject added in v0.9.10

func WALReadObject(w WALReader, v interface{}) ([]byte, error)

func WALWriteObject added in v0.9.10

func WALWriteObject(w WALWriter, v interface{}) 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 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
}

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

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
}

type VoteSet added in v0.9.10

type VoteSet interface {
	CommitVoteSet() module.CommitVoteSet
	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)
	// multiple 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)

id is in the form /wal/dir/prefix

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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