consensus

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateChangeReq = errors.New("duplicate ir change request")
View Source
var ErrVoteIsNil = errors.New("vote is nil")

Functions

This section is empty.

Types

type CertReqReason

type CertReqReason uint8
const (
	Quorum CertReqReason = iota
	QuorumNotPossible
)

type ConsensusManager

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

func NewConsensusManager

func NewConsensusManager(
	nodeID peer.ID,
	rg *genesis.RootGenesis,
	trustBase types.RootTrustBase,
	orchestration Orchestration,
	net RootNet,
	signer abcrypto.Signer,
	observe Observability,
	opts ...Option,
) (*ConsensusManager, error)

NewConsensusManager creates new "Atomic Broadcast" protocol based distributed consensus manager

func (*ConsensusManager) CertificationResult

func (x *ConsensusManager) CertificationResult() <-chan *certification.CertificationResponse

func (*ConsensusManager) RequestCertification

func (x *ConsensusManager) RequestCertification(ctx context.Context, cr IRChangeRequest) error

func (*ConsensusManager) Run

func (x *ConsensusManager) Run(ctx context.Context) error

func (*ConsensusManager) ShardInfo

func (x *ConsensusManager) ShardInfo(partition types.PartitionID, shard types.ShardID) (*storage.ShardInfo, error)

type ConsensusWithSignatures

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

type IRChangeReqVerifier

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

func NewIRChangeReqVerifier

func NewIRChangeReqVerifier(c *Parameters, orchestration Orchestration, sMonitor State) (*IRChangeReqVerifier, error)

func (*IRChangeReqVerifier) VerifyIRChangeReq

func (x *IRChangeReqVerifier) VerifyIRChangeReq(round uint64, irChReq *drctypes.IRChangeReq) (*storage.InputData, error)

type IRChangeRequest

type IRChangeRequest struct {
	Partition types.PartitionID
	Shard     types.ShardID
	Reason    CertReqReason
	Requests  []*certification.BlockCertificationRequest
}

type IRChangeVerifier

type IRChangeVerifier interface {
	VerifyIRChangeReq(round uint64, irChReq *drctypes.IRChangeReq) (*storage.InputData, error)
}

type InProgressFn

type InProgressFn func(partition types.PartitionID, shard types.ShardID) *types.InputRecord

type IrReqBuffer

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

func NewIrReqBuffer

func NewIrReqBuffer(log *slog.Logger) *IrReqBuffer

func (*IrReqBuffer) Add

func (x *IrReqBuffer) Add(round uint64, irChReq *drctypes.IRChangeReq, ver IRChangeVerifier) error

Add validates incoming IR change request and buffers valid requests. If for any reason the IR request is found not valid, reason is logged, error is returned and request is ignored.

func (*IrReqBuffer) GeneratePayload

func (x *IrReqBuffer) GeneratePayload(round uint64, timeouts []types.PartitionID, inProgress InProgressFn) *drctypes.Payload

GeneratePayload generates new proposal payload from buffered IR change requests.

func (*IrReqBuffer) IsChangeInBuffer

func (x *IrReqBuffer) IsChangeInBuffer(id types.PartitionID) bool

IsChangeInBuffer returns true if there is a request for IR change from the partition in the buffer

type Leader

type Leader interface {
	// GetLeaderForRound returns valid leader (node id) for round/view number
	GetLeaderForRound(round uint64) peer.ID
	// GetNodes - get all node id's currently active
	GetNodes() []peer.ID
	// Update - what PaceMaker considers to be the current round at the time QC is processed.
	Update(qc *drctypes.QuorumCert, currentRound uint64, b leader.BlockLoader) error
}

Leader provides interface to different leader selection algorithms

type Observability

type Observability interface {
	Meter(name string, opts ...metric.MeterOption) metric.Meter
	Tracer(name string, options ...trace.TracerOption) trace.Tracer
	Logger() *slog.Logger
	RoundLogger(curRound func() uint64) *slog.Logger
}

type Option

type Option func(c *Optional)

func WithStorage

func WithStorage(db keyvaluedb.KeyValueDB) Option

type Optional

type Optional struct {
	Storage keyvaluedb.KeyValueDB
}

Optional are common optional parameters for consensus managers

func LoadConf

func LoadConf(opts []Option) (*Optional, error)

type Orchestration

type Orchestration interface {
	ShardEpoch(partition types.PartitionID, shard types.ShardID, round uint64) (uint64, error)
	ShardConfig(partition types.PartitionID, shard types.ShardID, epoch uint64) (*partitions.ValidatorAssignmentRecord, error)
	RoundPartitions(rootRound uint64) ([]*types.PartitionDescriptionRecord, error)
	PartitionDescription(partition types.PartitionID, epoch uint64) (*types.PartitionDescriptionRecord, error)
}

type Pacemaker

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

Pacemaker tracks the current round/view number - a new round/view starts if there is a quorum certificate or timeout certificate for the previous round. It also provides "round clock" which allows to make sure that rounds are not produced too fast but also do not take too long (timeout). In addition it keeps track of validator data related to the active round (votes received if next leader or votes sent if follower).

func NewPacemaker

func NewPacemaker(minRoundLen, maxRoundLen time.Duration, observe Observability) (*Pacemaker, error)

NewPacemaker initializes new Pacemaker instance (zero value is not usable).

  • minRoundLen is the minimum round duration, rounds shouldn't advance faster than that;
  • maxRoundLen is maximum round duration, after that round is considered to be timed out;

The maxRoundLen must be greater than minRoundLen or the Pacemaker will crash at some point!

func (*Pacemaker) AdvanceRoundQC

func (x *Pacemaker) AdvanceRoundQC(ctx context.Context, qc *types.QuorumCert) bool

AdvanceRoundQC - trigger next round/view on quorum certificate

func (*Pacemaker) AdvanceRoundTC

func (x *Pacemaker) AdvanceRoundTC(ctx context.Context, tc *types.TimeoutCert)

AdvanceRoundTC - trigger next round/view on timeout certificate

func (*Pacemaker) GetCurrentRound

func (x *Pacemaker) GetCurrentRound() uint64

func (*Pacemaker) GetTimeoutVote

func (x *Pacemaker) GetTimeoutVote() *abdrc.TimeoutMsg

GetTimeoutVote - has the node voted for timeout in this round, returns either vote or nil

func (*Pacemaker) GetVoted

func (x *Pacemaker) GetVoted() *abdrc.VoteMsg

GetVoted - has the node voted in this round, returns either vote or nil

func (*Pacemaker) LastRoundTC

func (x *Pacemaker) LastRoundTC() *types.TimeoutCert

func (*Pacemaker) RegisterTimeoutVote

func (x *Pacemaker) RegisterTimeoutVote(ctx context.Context, vote *abdrc.TimeoutMsg, quorum QuorumInfo) (*types.TimeoutCert, error)

RegisterTimeoutVote registers time-out vote from root node (including vote from self) and tries to assemble a timeout quorum certificate for the round.

func (*Pacemaker) RegisterVote

func (x *Pacemaker) RegisterVote(vote *abdrc.VoteMsg, quorum QuorumInfo) (*types.QuorumCert, bool, error)

RegisterVote register vote for the round and assembles quorum certificate when quorum condition is met. It returns non nil QC in case of quorum is achieved. It also returns bool which indicates is the round "mature", ie it has lasted at least the minimum required amount of time to make proposal.

func (*Pacemaker) Reset

func (x *Pacemaker) Reset(ctx context.Context, highQCRound uint64, lastTc *types.TimeoutCert, lastVote any)

Reset sets the pacemaker's "last committed round" and starts next round. This method should only used to start the pacemaker and reset it's status on system recovery, during normal operation current round is advanced by calling AdvanceRoundQC or AdvanceRoundTC.

func (*Pacemaker) RoundQC

func (x *Pacemaker) RoundQC() *types.QuorumCert

RoundQC returns the latest QC produced by calling RegisterVote.

func (*Pacemaker) SetTimeoutVote

func (x *Pacemaker) SetTimeoutVote(vote *abdrc.TimeoutMsg)

SetTimeoutVote - remember timeout vote sent in this view

func (*Pacemaker) SetVoted

func (x *Pacemaker) SetVoted(vote *abdrc.VoteMsg)

SetVoted - remember vote sent in this view

func (*Pacemaker) StatusEvents

func (x *Pacemaker) StatusEvents() <-chan paceMakerStatus

StatusEvents returns channel into which events are posted when round state changes.

Events are produced once per state change, except pmsRoundTimeout which will be repeated every time maxRoundLen elapses and new round hasn't been started yet.

pmsRoundInProgress (ie new round started) event is never produced!

func (*Pacemaker) Stop

func (x *Pacemaker) Stop()

type Parameters

type Parameters struct {
	BlockRate          time.Duration // also known as T3
	LocalTimeout       time.Duration
	ConsensusThreshold uint32
	HashAlgorithm      gocrypto.Hash
}

Parameters are basic consensus parameters that need to be the same in all root validators. Extracted from root genesis where all validators in the root cluster must have signed them to signal agreement

func NewConsensusParams

func NewConsensusParams(genesisRoot *genesis.GenesisRootRecord) *Parameters

NewConsensusParams extract common consensus parameters from genesis

type PartitionTimeout

type PartitionTimeout interface {
	GetT2Timeouts(currenRound uint64) ([]types.PartitionID, error)
}

type PartitionTimeoutGenerator

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

func NewLucBasedT2TimeoutGenerator

func NewLucBasedT2TimeoutGenerator(c *Parameters, orchestration Orchestration, sMonitor State) (*PartitionTimeoutGenerator, error)

func (*PartitionTimeoutGenerator) GetT2Timeouts

func (x *PartitionTimeoutGenerator) GetT2Timeouts(currentRound uint64) (_ []types.PartitionID, retErr error)

type QuorumInfo

type QuorumInfo interface {
	GetQuorumThreshold() uint64
	GetMaxFaultyNodes() uint64
}

type RootNet

type RootNet interface {
	Send(ctx context.Context, msg any, receivers ...peer.ID) error
	ReceivedChannel() <-chan any
}

type SafetyModule

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

func NewSafetyModule

func NewSafetyModule(id string, signer crypto.Signer, db keyvaluedb.KeyValueDB) (*SafetyModule, error)

func (*SafetyModule) GetHighestQcRound

func (s *SafetyModule) GetHighestQcRound() uint64

func (*SafetyModule) GetHighestVotedRound

func (s *SafetyModule) GetHighestVotedRound() uint64

func (*SafetyModule) MakeVote

func (s *SafetyModule) MakeVote(block *drctypes.BlockData, execStateID []byte, highQC *drctypes.QuorumCert, lastRoundTC *drctypes.TimeoutCert) (*abdrc.VoteMsg, error)

func (*SafetyModule) SetHighestQcRound

func (s *SafetyModule) SetHighestQcRound(highestQcRound uint64)

func (*SafetyModule) SetHighestVotedRound

func (s *SafetyModule) SetHighestVotedRound(highestVotedRound uint64)

func (*SafetyModule) Sign

func (s *SafetyModule) Sign(msg Signer) error

func (*SafetyModule) SignTimeout

func (s *SafetyModule) SignTimeout(tmoVote *abdrc.TimeoutMsg, lastRoundTC *drctypes.TimeoutCert) error

type Signer

type Signer interface {
	Sign(s crypto.Signer) error
}

type State

type State interface {
	ShardInfo(partition types.PartitionID, shard types.ShardID) (*storage.ShardInfo, error)
	GetCertificates() []*types.UnicityCertificate
	IsChangeInProgress(id types.PartitionID, shard types.ShardID) *types.InputRecord
}

type VoteRegister

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

func NewVoteRegister

func NewVoteRegister() *VoteRegister

func (*VoteRegister) InsertTimeoutVote

func (v *VoteRegister) InsertTimeoutVote(timeout *abdrc.TimeoutMsg, quorumInfo QuorumInfo) (*drctypes.TimeoutCert, uint64, error)

InsertTimeoutVote returns non nil TC when quorum has been achieved. Second return value is number of signatures in the TC.

func (*VoteRegister) InsertVote

func (v *VoteRegister) InsertVote(vote *abdrc.VoteMsg, quorumInfo QuorumInfo) (*drctypes.QuorumCert, error)

func (*VoteRegister) Reset

func (v *VoteRegister) Reset()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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