consensus

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consensus

type Consensus interface {
	// AddVoter adds a voting member into the cluster, voter is eligible to become leader.
	AddVoter(id, addr string) error
	// AddNonVoter adds a non-voting member into the cluster, non-voter is not eligible to become leader.
	AddNonVoter(id, addr string) error
	// DemoteVoter demotes a voting member into a non-voting member, if leader is being demoted, it will cause a new leader election.
	DemoteVoter(id string) error
	// RemoveServer removes a member (both voter or non-voter) from the cluster, if leader is being removed, it will cause a new leader election.
	RemoveServer(id string) error
	// LeaderCh returns a channel that will be notified when leadership status changes (true = leader, false = follower)
	LeaderCh() <-chan bool
	// Leader returns if it is the leader of the cluster.
	Leader() bool
	// LeaderWithID returns the leader's server ID and address.
	LeaderWithID() *ServerInfo
	// ServerID returns the server ID of the consensus.
	ServerID() string
	// TransferLeader triggers leadership transfer to another member in the cluster.
	TransferLeader() error
	// TransferLeaderTo triggers leadership transfer to a specific member in the cluster.
	TransferLeaderTo(id, addr string) error
	// ClusterMembership returns the current cluster membership configuration.
	ClusterMembership() ([]*ServerInfo, error)

	// CommitPayload commits latest unsafe payload to the FSM.
	CommitUnsafePayload(payload *eth.ExecutionPayloadEnvelope) error
	// LatestUnsafeBlock returns the latest unsafe payload from FSM.
	LatestUnsafePayload() *eth.ExecutionPayloadEnvelope

	// Shutdown shuts down the consensus protocol client.
	Shutdown() error
}

Consensus defines the consensus interface for leadership election.

type RaftConsensus

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

RaftConsensus implements Consensus using raft protocol.

func NewRaftConsensus

func NewRaftConsensus(log log.Logger, serverID, serverAddr, storageDir string, bootstrap bool, rollupCfg *rollup.Config) (*RaftConsensus, error)

NewRaftConsensus creates a new RaftConsensus instance.

func (*RaftConsensus) AddNonVoter

func (rc *RaftConsensus) AddNonVoter(id string, addr string) error

AddNonVoter implements Consensus, it tries to add a non-voting member into the cluster.

func (*RaftConsensus) AddVoter

func (rc *RaftConsensus) AddVoter(id string, addr string) error

AddVoter implements Consensus, it tries to add a voting member into the cluster.

func (*RaftConsensus) ClusterMembership added in v1.7.0

func (rc *RaftConsensus) ClusterMembership() ([]*ServerInfo, error)

ClusterMembership implements Consensus, it returns the current cluster membership configuration.

func (*RaftConsensus) CommitUnsafePayload

func (rc *RaftConsensus) CommitUnsafePayload(payload *eth.ExecutionPayloadEnvelope) error

CommitUnsafePayload implements Consensus, it commits latest unsafe payload to the cluster FSM.

func (*RaftConsensus) DemoteVoter

func (rc *RaftConsensus) DemoteVoter(id string) error

DemoteVoter implements Consensus, it tries to demote a voting member into a non-voting member in the cluster.

func (*RaftConsensus) LatestUnsafePayload

func (rc *RaftConsensus) LatestUnsafePayload() *eth.ExecutionPayloadEnvelope

LatestUnsafePayload implements Consensus, it returns the latest unsafe payload from FSM.

func (*RaftConsensus) Leader

func (rc *RaftConsensus) Leader() bool

Leader implements Consensus, it returns true if it is the leader of the cluster.

func (*RaftConsensus) LeaderCh

func (rc *RaftConsensus) LeaderCh() <-chan bool

LeaderCh implements Consensus, it returns a channel that will be notified when leadership status changes (true = leader, false = follower).

func (*RaftConsensus) LeaderWithID added in v1.5.0

func (rc *RaftConsensus) LeaderWithID() *ServerInfo

LeaderWithID implements Consensus, it returns the leader's server ID and address.

func (*RaftConsensus) RemoveServer

func (rc *RaftConsensus) RemoveServer(id string) error

RemoveServer implements Consensus, it tries to remove a member (both voter or non-voter) from the cluster, if leader is being removed, it will cause a new leader election.

func (*RaftConsensus) ServerID

func (rc *RaftConsensus) ServerID() string

ServerID implements Consensus, it returns the server ID of the current server.

func (*RaftConsensus) Shutdown

func (rc *RaftConsensus) Shutdown() error

Shutdown implements Consensus, it shuts down the consensus protocol client.

func (*RaftConsensus) TransferLeader

func (rc *RaftConsensus) TransferLeader() error

TransferLeader implements Consensus, it triggers leadership transfer to another member in the cluster.

func (*RaftConsensus) TransferLeaderTo

func (rc *RaftConsensus) TransferLeaderTo(id string, addr string) error

TransferLeaderTo implements Consensus, it triggers leadership transfer to a specific member in the cluster.

type ServerInfo added in v1.7.0

type ServerInfo struct {
	ID       string         `json:"id"`
	Addr     string         `json:"addr"`
	Suffrage ServerSuffrage `json:"suffrage"`
}

ServerInfo defines the server information.

type ServerSuffrage added in v1.7.0

type ServerSuffrage int

ServerSuffrage determines whether a Server in a Configuration gets a vote.

const (
	// Voter is a server whose vote is counted in elections.
	Voter ServerSuffrage = iota
	// Nonvoter is a server that receives log entries but is not considered for
	// elections or commitment purposes.
	Nonvoter
)

func (ServerSuffrage) String added in v1.7.0

func (s ServerSuffrage) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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