core

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Overview

Package core implements IBFT consensus backend.go defines interfaces of backend, that performs detailed procedure rather than consensus

Index

Constants

View Source
const (
	// DefaultBaseRoundTimeout is the default base round (round 0) timeout
	DefaultBaseRoundTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func SetMeasurementTime

func SetMeasurementTime(prefix string, startTime time.Time)

SetMeasurementTime function set duration to gauge

Types

type Backend

type Backend interface {
	MessageConstructor
	Verifier
	ValidatorBackend
	Notifier

	// BuildProposal builds a new proposal for the given view (height and round)
	BuildProposal(view *proto.View) []byte

	// InsertProposal inserts a proposal with the specified committed seals
	// the reason why we are including round here is because a single committedSeal
	// has signed the tuple of (rawProposal, round)
	InsertProposal(proposal *proto.Proposal, committedSeals []*messages.CommittedSeal)

	// ID returns the validator's ID
	ID() []byte
}

Backend defines an interface all backend implementations need to implement

type IBFT

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

IBFT represents a single instance of the IBFT state machine

func NewIBFT

func NewIBFT(
	log Logger,
	backend Backend,
	transport Transport,
) *IBFT

NewIBFT creates a new instance of the IBFT consensus protocol

func (*IBFT) AddMessage

func (i *IBFT) AddMessage(message *proto.IbftMessage)

AddMessage adds a new message to the IBFT message system

func (*IBFT) ExtendRoundTimeout

func (i *IBFT) ExtendRoundTimeout(amount time.Duration)

ExtendRoundTimeout extends each round's timer by the specified amount.

func (*IBFT) RunSequence

func (i *IBFT) RunSequence(ctx context.Context, h uint64)

RunSequence runs the IBFT sequence for the specified height

func (*IBFT) SetBaseRoundTimeout

func (i *IBFT) SetBaseRoundTimeout(baseRoundTimeout time.Duration)

SetBaseRoundTimeout sets the base (round 0) timeout

type Logger

type Logger interface {
	Info(msg string, args ...any)
	Debug(msg string, args ...any)
	Error(msg string, args ...any)
}

Logger represents the logger behaviour

type MessageConstructor

type MessageConstructor interface {
	// BuildPrePrepareMessage builds a PREPREPARE message based on the passed in view and proposal
	BuildPrePrepareMessage(
		rawProposal []byte,
		certificate *proto.RoundChangeCertificate,
		view *proto.View,
	) *proto.IbftMessage

	// BuildPrepareMessage builds a PREPARE message based on the passed in view and proposal hash
	BuildPrepareMessage(proposalHash []byte, view *proto.View) *proto.IbftMessage

	// BuildCommitMessage builds a COMMIT message based on the passed in view and proposal hash
	// Must create a committed seal for proposal hash and include it into the message
	BuildCommitMessage(proposalHash []byte, view *proto.View) *proto.IbftMessage

	// BuildRoundChangeMessage builds a ROUND_CHANGE message based on the passed in view,
	// latest prepared proposal, and latest prepared certificate
	BuildRoundChangeMessage(
		proposal *proto.Proposal,
		certificate *proto.PreparedCertificate,
		view *proto.View,
	) *proto.IbftMessage
}

MessageConstructor defines a message constructor interface All constructed messages must be signed by a validator for the whole message

type Messages

type Messages interface {
	// Messages modifiers //
	AddMessage(message *proto.IbftMessage)
	PruneByHeight(height uint64)

	SignalEvent(messageType proto.MessageType, view *proto.View)

	// Messages fetchers //
	GetValidMessages(
		view *proto.View,
		messageType proto.MessageType,
		isValid func(*proto.IbftMessage) bool,
	) []*proto.IbftMessage
	GetExtendedRCC(
		height uint64,
		isValidMessage func(message *proto.IbftMessage) bool,
		isValidRCC func(round uint64, msgs []*proto.IbftMessage) bool,
	) []*proto.IbftMessage
	GetMostRoundChangeMessages(minRound, height uint64) []*proto.IbftMessage

	// Messages subscription handlers //
	Subscribe(details messages.SubscriptionDetails) *messages.Subscription
	Unsubscribe(id messages.SubscriptionID)
}

Messages represents the message managing behaviour

type Notifier

type Notifier interface {
	// RoundStarts notifies the backend implementation whenever new round is about to start
	RoundStarts(view *proto.View) error

	// SequenceCancelled notifies the backend implementation whenever a sequence is cancelled
	SequenceCancelled(view *proto.View) error
}

Notifier contains callback functions that notifies about consensus execution

type Transport

type Transport interface {
	// Multicast multicasts the message to other peers
	Multicast(message *proto.IbftMessage)
}

Transport defines an interface the node uses to communicate with other peers

type ValidatorBackend

type ValidatorBackend interface {
	// GetVotingPowers returns map of validators addresses and their voting powers for the specified height.
	GetVotingPowers(height uint64) (map[string]*big.Int, error)
}

ValidatorBackend defines interface that has GetVotingPower

type ValidatorManager

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

ValidatorManager keeps voting power and other information about validators

func NewValidatorManager

func NewValidatorManager(backend ValidatorBackend, log Logger) *ValidatorManager

NewValidatorManager creates new ValidatorManager

func (*ValidatorManager) HasPrepareQuorum

func (vm *ValidatorManager) HasPrepareQuorum(stateName stateType, proposalMessage *proto.IbftMessage,
	msgs []*proto.IbftMessage) bool

HasPrepareQuorum provides information on whether prepared messages have reached the quorum

func (*ValidatorManager) HasQuorum

func (vm *ValidatorManager) HasQuorum(sendersAddrs map[string]struct{}) bool

HasQuorum provides information on whether messages have reached the quorum

func (*ValidatorManager) Init

func (vm *ValidatorManager) Init(height uint64) error

Init sets voting power and quorum size

type Verifier

type Verifier interface {
	// IsValidProposal checks if the proposal is valid
	IsValidProposal(rawProposal []byte) bool

	// IsValidValidator checks if a signature in message is signed by sender
	// Must check the following things:
	// (1) recover the signature and the signer matches from address in message
	// (2) the signer address is one of the validators at the height in message
	IsValidValidator(msg *proto.IbftMessage) bool

	// IsProposer checks if the passed in ID is the Proposer for current view (sequence, round)
	IsProposer(id []byte, height, round uint64) bool

	// IsValidProposalHash checks if the hash matches the proposal
	IsValidProposalHash(proposal *proto.Proposal, hash []byte) bool

	// IsValidCommittedSeal checks
	// if signature for proposal hash in committed seal is signed by a validator
	IsValidCommittedSeal(proposalHash []byte, committedSeal *messages.CommittedSeal) bool
}

Verifier defines the verifier interface

Jump to

Keyboard shortcuts

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