consensus

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockingManager added in v0.10.0

func MockingManager(ts *testsuite.TestSuite, valKeys []*bls.ValidatorKey) (Manager, []*MockConsensus)

Types

type ConcreteMediator added in v0.10.0

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

ConcreteMediator struct.

func (*ConcreteMediator) OnBlockAnnounce added in v0.10.0

func (m *ConcreteMediator) OnBlockAnnounce(from Consensus)

func (*ConcreteMediator) OnPublishProposal added in v0.10.0

func (m *ConcreteMediator) OnPublishProposal(from Consensus, prop *proposal.Proposal)

func (*ConcreteMediator) OnPublishVote added in v0.10.0

func (m *ConcreteMediator) OnPublishVote(from Consensus, vte *vote.Vote)

func (*ConcreteMediator) Register added in v0.10.0

func (m *ConcreteMediator) Register(cons Consensus)

Register a new Consensus instance to the mediator.

type Config

type Config struct {
	ChangeProposerTimeout    time.Duration `toml:"-"`
	ChangeProposerDelta      time.Duration `toml:"-"`
	MinimumAvailabilityScore float64       `toml:"-"`
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) BasicCheck added in v0.15.0

func (conf *Config) BasicCheck() error

BasicCheck performs basic checks on the configuration.

func (*Config) CalculateChangeProposerTimeout

func (conf *Config) CalculateChangeProposerTimeout(round int16) time.Duration

type ConfigError added in v1.0.0

type ConfigError struct {
	Reason string
}

ConfigError is returned when the config is not valid with a descriptive Reason message.

func (ConfigError) Error added in v1.0.0

func (e ConfigError) Error() string

type Consensus

type Consensus interface {
	Reader

	Start()
	MoveToNewHeight()
	AddVote(vote *vote.Vote)
	SetProposal(proposal *proposal.Proposal)
}

func NewConsensus

func NewConsensus(
	conf *Config,
	bcState state.Facade,
	valKey *bls.ValidatorKey,
	rewardAddr crypto.Address,
	broadcastCh chan message.Message,
	mediator mediator,
) Consensus

type Manager added in v0.10.0

type Manager interface {
	ManagerReader

	Start() error
	Stop()
	MoveToNewHeight()
	AddVote(vote *vote.Vote)
	SetProposal(proposal *proposal.Proposal)
}

func NewManager added in v0.10.0

func NewManager(
	conf *Config,
	st state.Facade,
	valKeys []*bls.ValidatorKey,
	rewardAddrs []crypto.Address,
	broadcastCh chan message.Message,
) Manager

NewManager creates a new manager instance that manages a set of consensus instances, each associated with a validator key and a reward address. It is not thread-safe.

type ManagerReader added in v0.10.0

type ManagerReader interface {
	Instances() []Reader
	PickRandomVote(round int16) *vote.Vote
	Proposal() *proposal.Proposal
	HeightRound() (uint32, int16)
	HasActiveInstance() bool
}

type MockConsensus

type MockConsensus struct {
	ValKey      *bls.ValidatorKey
	Votes       []*vote.Vote
	CurProposal *proposal.Proposal
	Active      bool
	Height      uint32
	Round       int16
	// contains filtered or unexported fields
}

func MockingConsensus

func MockingConsensus(ts *testsuite.TestSuite, valKey *bls.ValidatorKey) *MockConsensus

func (*MockConsensus) AddVote

func (m *MockConsensus) AddVote(v *vote.Vote)

func (*MockConsensus) AllVotes

func (m *MockConsensus) AllVotes() []*vote.Vote

func (*MockConsensus) ConsensusKey added in v0.15.0

func (m *MockConsensus) ConsensusKey() *bls.PublicKey

func (*MockConsensus) HasVote added in v0.11.0

func (m *MockConsensus) HasVote(h hash.Hash) bool

func (*MockConsensus) HeightRound

func (m *MockConsensus) HeightRound() (uint32, int16)

func (*MockConsensus) IsActive added in v0.10.0

func (m *MockConsensus) IsActive() bool

func (*MockConsensus) MoveToNewHeight

func (m *MockConsensus) MoveToNewHeight()

func (*MockConsensus) PickRandomVote

func (m *MockConsensus) PickRandomVote(_ int16) *vote.Vote

func (*MockConsensus) Proposal

func (m *MockConsensus) Proposal() *proposal.Proposal

func (*MockConsensus) SetActive added in v0.10.0

func (m *MockConsensus) SetActive(active bool)

func (*MockConsensus) SetProposal

func (m *MockConsensus) SetProposal(p *proposal.Proposal)

func (*MockConsensus) Start

func (m *MockConsensus) Start()

func (*MockConsensus) String added in v0.15.0

func (m *MockConsensus) String() string

type Reader

type Reader interface {
	ConsensusKey() *bls.PublicKey
	AllVotes() []*vote.Vote
	PickRandomVote(round int16) *vote.Vote
	Proposal() *proposal.Proposal
	HasVote(h hash.Hash) bool
	HeightRound() (uint32, int16)
	IsActive() bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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