basicstates

package
v0.0.0-...-5a6e01e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package basicstates is the rewritten consensus states, based on primitive.

Index

Constants

View Source
const (
	ContextValueError              util.ContextKey = "error"
	ContextValueStateSwitchContext util.ContextKey = "state_switch_context"
	ContextValueNewSealContext     util.ContextKey = "new_seal"
	ContextValueBlockSaved         util.ContextKey = "block_saved"
)
View Source
const (
	TimerIDBroadcastINITBallot         localtime.TimerID = "broadcast-init-ballot"
	TimerIDBroadcastJoingingINITBallot localtime.TimerID = "broadcast-joining-init-ballot"
	TimerIDBroadcastProposal           localtime.TimerID = "broadcast-proposal"
	TimerIDBroadcastACCEPTBallot       localtime.TimerID = "broadcast-accept-ballot"
	TimerIDSyncingWaitVoteproof        localtime.TimerID = "syncing-wait-new-voteproof"
	TimerIDFindProposal                localtime.TimerID = "find-proposal"
)

Variables

View Source
var BlockPrefixFailedProcessProposal = []byte("processproposalfailed")
View Source
var ConsensusStuckError = util.NewError("consensus looks stuck")
View Source
var EmptySwitchFunc = func() error { return nil }
View Source
var SyncByVoteproofError = util.NewError("sync by voteproof")

Functions

func CheckBlockWithINITVoteproof

func CheckBlockWithINITVoteproof(db storage.Database, voteproof base.Voteproof) error

func LogSeal

func LogSeal(sl seal.Seal) *zerolog.Event

func NextINITBallotFromACCEPTVoteproof

func NextINITBallotFromACCEPTVoteproof(
	db storage.Database,
	local node.Local,
	voteproof base.Voteproof,
	networkID base.NetworkID,
) (base.INITBallot, error)

func NextINITBallotFromINITVoteproof

func NextINITBallotFromINITVoteproof(
	db storage.Database,
	local node.Local,
	voteproof,
	acceptVoteproof base.Voteproof,
	networkID base.NetworkID,
) (base.INITBallot, error)

Types

type BallotChecker

type BallotChecker struct {
	*logging.Logging
	// contains filtered or unexported fields
}

func NewBallotChecker

func NewBallotChecker(blt base.Ballot, lvp base.Voteproof) *BallotChecker

func (*BallotChecker) CheckWithLastVoteproof

func (bc *BallotChecker) CheckWithLastVoteproof() (bool, error)

type BaseConsensusState

type BaseConsensusState struct {
	*logging.Logging
	*BaseState
	// contains filtered or unexported fields
}

func NewBaseConsensusState

func NewBaseConsensusState(
	st base.State,
	db storage.Database,
	policy *isaac.LocalPolicy,
	nodepool *network.Nodepool,
	suffrage base.Suffrage,
	proposalMaker *isaac.ProposalMaker,
	pps *prprocessor.Processors,
) *BaseConsensusState

func (*BaseConsensusState) Enter

func (st *BaseConsensusState) Enter(sctx StateSwitchContext) (func() error, error)

Enter starts consensus state with the voteproof, - height of last init voteproof + 1

func (*BaseConsensusState) Exit

func (st *BaseConsensusState) Exit(sctx StateSwitchContext) (func() error, error)

func (*BaseConsensusState) ProcessProposal

func (st *BaseConsensusState) ProcessProposal(proposal base.Proposal) error

ProcessProposal processes incoming proposal, not from local

func (*BaseConsensusState) ProcessVoteproof

func (st *BaseConsensusState) ProcessVoteproof(voteproof base.Voteproof) error

type BaseState

type BaseState struct {
	States *States
	// contains filtered or unexported fields
}

func NewBaseState

func NewBaseState(st base.State) *BaseState

func (*BaseState) BroadcastBallot

func (st *BaseState) BroadcastBallot(blt base.Ballot, toLocal bool) error

func (*BaseState) Enter

func (st *BaseState) Enter(sctx StateSwitchContext) (func() error, error)

func (*BaseState) Exit

func (st *BaseState) Exit(sctx StateSwitchContext) (func() error, error)

func (*BaseState) LastINITVoteproof

func (st *BaseState) LastINITVoteproof() base.Voteproof

func (*BaseState) LastVoteproof

func (st *BaseState) LastVoteproof() base.Voteproof

func (*BaseState) NewBlocks

func (st *BaseState) NewBlocks(blks []block.Block) error

func (*BaseState) NewProposal

func (st *BaseState) NewProposal(proposal base.Proposal)

func (*BaseState) NewStateSwitchContext

func (st *BaseState) NewStateSwitchContext(next base.State) StateSwitchContext

func (*BaseState) NewVoteproof

func (st *BaseState) NewVoteproof(voteproof base.Voteproof)

func (*BaseState) ProcessProposal

func (*BaseState) ProcessProposal(base.Proposal) error

func (*BaseState) ProcessVoteproof

func (st *BaseState) ProcessVoteproof(voteproof base.Voteproof) error

func (*BaseState) SetLastVoteproof

func (st *BaseState) SetLastVoteproof(voteproof base.Voteproof) bool

func (*BaseState) SetStates

func (st *BaseState) SetStates(ss *States) State

func (*BaseState) StateSwitch

func (st *BaseState) StateSwitch(sctx StateSwitchContext) error

func (*BaseState) Timers

func (st *BaseState) Timers() *localtime.Timers

type BootingState

type BootingState struct {
	*logging.Logging
	*BaseState
	// contains filtered or unexported fields
}

func NewBootingState

func NewBootingState(
	local node.Local,
	db storage.Database,
	bd blockdata.Blockdata,
	policy *isaac.LocalPolicy,
	suffrage base.Suffrage,
) *BootingState

func (*BootingState) Enter

func (st *BootingState) Enter(sctx StateSwitchContext) (func() error, error)

type ConsensusState

type ConsensusState struct {
	*BaseConsensusState
}

func NewConsensusState

func NewConsensusState(
	db storage.Database,
	policy *isaac.LocalPolicy,
	nodepool *network.Nodepool,
	suffrage base.Suffrage,
	proposalMaker *isaac.ProposalMaker,
	pps *prprocessor.Processors,
) *ConsensusState

func (*ConsensusState) Enter

func (st *ConsensusState) Enter(sctx StateSwitchContext) (func() error, error)

func (*ConsensusState) Exit

func (st *ConsensusState) Exit(sctx StateSwitchContext) (func() error, error)

type ConsensusStuckChecker

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

func NewConsensusStuckChecker

func NewConsensusStuckChecker(
	lastVoteproof base.Voteproof,
	state base.State,
	endure time.Duration,
) *ConsensusStuckChecker

func (*ConsensusStuckChecker) IsOldLastVoteproofTime

func (cc *ConsensusStuckChecker) IsOldLastVoteproofTime() (bool, error)

func (*ConsensusStuckChecker) IsValidState

func (cc *ConsensusStuckChecker) IsValidState() (bool, error)

type DuplicatedError

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

func NewDuplicatedError

func NewDuplicatedError(ch network.Channel, ni network.NodeInfo) DuplicatedError

func (DuplicatedError) Error

func (DuplicatedError) Error() string

type EmptyState

type EmptyState struct{}

func NewEmptyState

func NewEmptyState() *EmptyState

func (*EmptyState) Enter

func (*EmptyState) Enter(sctx StateSwitchContext) (func() error, error)

func (*EmptyState) Exit

func (*EmptyState) Exit(StateSwitchContext) (func() error, error)

func (*EmptyState) ProcessProposal

func (*EmptyState) ProcessProposal(base.Proposal) error

func (*EmptyState) ProcessVoteproof

func (*EmptyState) ProcessVoteproof(base.Voteproof) error

func (*EmptyState) SetStates

func (*EmptyState) SetStates(*States) State

type Handover

type Handover struct {
	sync.Mutex
	*logging.Logging
	*util.ContextDaemon
	// contains filtered or unexported fields
}

func NewHandover

func NewHandover(
	localci network.ConnInfo,
	encs *encoder.Encoders,
	policy *isaac.LocalPolicy,
	nodepool *network.Nodepool,
	suffrage base.Suffrage,
) *Handover

func NewHandoverWithDiscoveryURL

func NewHandoverWithDiscoveryURL(
	localci network.ConnInfo,
	encs *encoder.Encoders,
	policy *isaac.LocalPolicy,
	nodepool *network.Nodepool,
	suffrage base.Suffrage,
	cis []network.ConnInfo,
) (*Handover, error)

func (*Handover) IsReady

func (hd *Handover) IsReady() bool

IsReady indicates node operator approves Handover.

func (*Handover) OldNode

func (hd *Handover) OldNode() network.Channel

func (*Handover) Refresh

func (hd *Handover) Refresh(chs ...network.Channel) error

func (*Handover) SetLogging

func (hd *Handover) SetLogging(l *logging.Logging) *logging.Logging

func (*Handover) Start

func (hd *Handover) Start() error

func (*Handover) Stop

func (hd *Handover) Stop() error

func (*Handover) UnderHandover

func (hd *Handover) UnderHandover() bool

type HandoverState

type HandoverState struct {
	*BaseConsensusState
	// contains filtered or unexported fields
}

func NewHandoverState

func NewHandoverState(
	db storage.Database,
	policy *isaac.LocalPolicy,
	nodepool *network.Nodepool,
	suffrage base.Suffrage,
	pps *prprocessor.Processors,
) *HandoverState

func (*HandoverState) Enter

func (st *HandoverState) Enter(sctx StateSwitchContext) (func() error, error)

func (*HandoverState) Exit

func (st *HandoverState) Exit(sctx StateSwitchContext) (func() error, error)

func (*HandoverState) ProcessVoteproof

func (st *HandoverState) ProcessVoteproof(voteproof base.Voteproof) error

type JoiningState

type JoiningState struct {
	*logging.Logging
	*BaseState
	// contains filtered or unexported fields
}

func NewJoiningState

func NewJoiningState(
	local node.Local,
	db storage.Database,
	policy *isaac.LocalPolicy,
	suffrage base.Suffrage,
	ballotbox *isaac.Ballotbox,
) *JoiningState

func (*JoiningState) Enter

func (st *JoiningState) Enter(sctx StateSwitchContext) (func() error, error)

func (*JoiningState) Exit

func (st *JoiningState) Exit(sctx StateSwitchContext) (func() error, error)

func (*JoiningState) ProcessVoteproof

func (st *JoiningState) ProcessVoteproof(voteproof base.Voteproof) error

ProcessVoteproof only receives the acceptable voteproof with last init voteproof

type State

type State interface {
	Enter(StateSwitchContext) (func() error, error)
	Exit(StateSwitchContext) (func() error, error)
	ProcessProposal(base.Proposal) error
	ProcessVoteproof(base.Voteproof) error
	SetStates(*States) State
}

type StateSwitchContext

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

func NewStateSwitchContext

func NewStateSwitchContext(from, to base.State) StateSwitchContext

func (StateSwitchContext) Context

func (sctx StateSwitchContext) Context() context.Context

func (StateSwitchContext) ContextWithValue

func (sctx StateSwitchContext) ContextWithValue(k util.ContextKey, v interface{}) StateSwitchContext

func (StateSwitchContext) Err

func (sctx StateSwitchContext) Err() error

func (StateSwitchContext) Error

func (sctx StateSwitchContext) Error() string

func (StateSwitchContext) FromState

func (sctx StateSwitchContext) FromState() base.State

func (StateSwitchContext) IsEmpty

func (sctx StateSwitchContext) IsEmpty() bool

func (StateSwitchContext) IsValid

func (sctx StateSwitchContext) IsValid([]byte) error

func (StateSwitchContext) MarshalText

func (sctx StateSwitchContext) MarshalText() ([]byte, error)

func (StateSwitchContext) MarshalZerologObject

func (sctx StateSwitchContext) MarshalZerologObject(e *zerolog.Event)

func (StateSwitchContext) Return

func (sctx StateSwitchContext) Return() StateSwitchContext

func (StateSwitchContext) SetContext

func (StateSwitchContext) SetError

func (sctx StateSwitchContext) SetError(err error) StateSwitchContext

func (StateSwitchContext) SetFromState

func (sctx StateSwitchContext) SetFromState(st base.State) StateSwitchContext

func (StateSwitchContext) SetToState

func (sctx StateSwitchContext) SetToState(st base.State) StateSwitchContext

func (StateSwitchContext) SetVoteproof

func (sctx StateSwitchContext) SetVoteproof(voteproof base.Voteproof) StateSwitchContext

func (StateSwitchContext) ToState

func (sctx StateSwitchContext) ToState() base.State

func (StateSwitchContext) Voteproof

func (sctx StateSwitchContext) Voteproof() base.Voteproof

type States

type States struct {
	sync.RWMutex
	*logging.Logging
	*util.ContextDaemon
	// contains filtered or unexported fields
}

func NewStates

func NewStates(
	db storage.Database,
	policy *isaac.LocalPolicy,
	nodepool *network.Nodepool,
	suffrage base.Suffrage,
	ballotbox *isaac.Ballotbox,
	stoppedState, bootingState, joiningState, consensusState, syncingState, handoverState State,
	dis *states.DiscoveryJoiner,
	hd *Handover,
) (*States, error)

func (*States) BlockSavedHook

func (ss *States) BlockSavedHook() *pm.Hooks

func (*States) BroadcastBallot

func (ss *States) BroadcastBallot(blt base.Ballot, toLocal bool)

BroadcastBallot broadcast seal to the known nodes, - suffrage nodes - if toLocal is true, sends to local

func (*States) EndHandover

func (ss *States) EndHandover(ci network.ConnInfo) error

func (*States) Handover

func (ss *States) Handover() states.Handover

func (*States) LastINITVoteproof

func (ss *States) LastINITVoteproof() base.Voteproof

func (*States) LastVoteproof

func (ss *States) LastVoteproof() base.Voteproof

func (*States) NewBlocks

func (ss *States) NewBlocks(blks []block.Block) error

func (*States) NewProposal

func (ss *States) NewProposal(proposal base.Proposal)

func (*States) NewSeal

func (ss *States) NewSeal(sl seal.Seal) error

func (*States) NewVoteproof

func (ss *States) NewVoteproof(voteproof base.Voteproof)

func (*States) SetLastVoteproof

func (ss *States) SetLastVoteproof(voteproof base.Voteproof) bool

func (*States) SetLogging

func (ss *States) SetLogging(l *logging.Logging) *logging.Logging

func (*States) Start

func (ss *States) Start() error

func (*States) StartHandover

func (ss *States) StartHandover() error

func (*States) State

func (ss *States) State() base.State

func (*States) Stop

func (ss *States) Stop() error

func (*States) SwitchState

func (ss *States) SwitchState(sctx StateSwitchContext) error

func (*States) Timers

func (ss *States) Timers() *localtime.Timers

type StoppedState

type StoppedState struct {
	*BaseState
}

func NewStoppedState

func NewStoppedState() *StoppedState

type SyncingState

type SyncingState struct {
	sync.RWMutex
	*logging.Logging
	*BaseState
	// contains filtered or unexported fields
}

func NewSyncingState

func NewSyncingState(
	db storage.Database,
	bd blockdata.Blockdata,
	policy *isaac.LocalPolicy,
	nodepool *network.Nodepool,
	suffrage base.Suffrage,
) *SyncingState

func (*SyncingState) Enter

func (st *SyncingState) Enter(sctx StateSwitchContext) (func() error, error)

func (*SyncingState) Exit

func (st *SyncingState) Exit(sctx StateSwitchContext) (func() error, error)

func (*SyncingState) ProcessVoteproof

func (st *SyncingState) ProcessVoteproof(voteproof base.Voteproof) error

type VoteproofChecker

type VoteproofChecker struct {
	*logging.Logging
	// contains filtered or unexported fields
}

func NewVoteproofChecker

func NewVoteproofChecker(
	db storage.Database,
	suffrage base.Suffrage,
	nodepool *network.Nodepool,
	lastVoteproof, voteproof base.Voteproof,
) *VoteproofChecker

func (*VoteproofChecker) CheckACCEPTVoteproofProposal

func (vc *VoteproofChecker) CheckACCEPTVoteproofProposal() (bool, error)

CheckACCEPTVoteproofProposal checks proposal of accept voteproof. If proposal not found in local, request to the voted nodes.

func (*VoteproofChecker) CheckINITVoteproofWithLocalBlock

func (vc *VoteproofChecker) CheckINITVoteproofWithLocalBlock() (bool, error)

func (*VoteproofChecker) CheckPoint

func (vc *VoteproofChecker) CheckPoint() (bool, error)

Jump to

Keyboard shortcuts

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