isaacstates

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: GPL-3.0 Imports: 20 Imported by: 14

Documentation

Overview

Package isaacstates handles node states

Index

Constants

View Source
const (
	StateEmpty = StateType("")
	// StateStopped indicates all processes is finished.
	StateStopped = StateType("STOPPED")
	// StateBooting indicates node checks it's state.
	StateBooting = StateType("BOOTING")
	// StateJoining indicates node is trying to join consensus.
	StateJoining = StateType("JOINING")
	// StateConsensus indicates node participates consensus with the other
	// nodes.
	StateConsensus = StateType("CONSENSUS")
	// StateSyncing indicates node is syncing block.
	StateSyncing = StateType("SYNCING")
	// StateHandover indicates node tries to replace the existing same node.
	StateHandover = StateType("HANDOVER")
	// StateBroken is used when something wrong in states.
	StateBroken = StateType("BROKEN")
)

Variables

View Source
var ErrIgnoreSwithingState = util.NewError("failed to switch state, but ignored")
View Source
var ErrSyncerCanNotCancel = util.NewError("can not cancel syncer")
View Source
var ErrUnpromising = util.NewError("unpromising broken error")
View Source
var MissingBallotsRequestsMessageHint = hint.MustNewHint("missing-ballots-request-message-v0.0.1")

Functions

func FindMissingBallotsFromBallotboxFunc

func FindMissingBallotsFromBallotboxFunc(
	local base.Address,
	params *isaac.LocalParams,
	getSuffragef isaac.GetSuffrageByBlockHeight,
	ballotbox *Ballotbox,
) func(context.Context, base.StagePoint, bool) ([]base.Address, bool, error)

func ImportBlocks

func ImportBlocks(
	ctx context.Context,
	from, to base.Height,
	batchlimit int64,
	blockMapf SyncerBlockMapFunc,
	blockMapItemf SyncerBlockMapItemFunc,
	newBlockImporter func(base.BlockMap) (isaac.BlockImporter, error),
	setLastVoteproofsFunc func(isaac.BlockReader) error,
	mergeBlockWriterDatabasesf func(context.Context) error,
) error

func IsNewVoteproofbyPoint

func IsNewVoteproofbyPoint(
	last LastPoint,
	point base.StagePoint,
	isMajority, isSuffrageConfirm bool,
) bool

func RequestMissingBallots

func RequestMissingBallots(
	localci quicstream.UDPConnInfo,
	broadcastf func(string, []byte, chan struct{}) error,
) func(context.Context, base.StagePoint, []base.Address) error

func VoteSuffrageVotingFunc

func VoteSuffrageVotingFunc(
	local base.LocalNode,
	params *isaac.LocalParams,
	ballotbox *Ballotbox,
	sv *isaac.SuffrageVoting,
	getSuffragef isaac.GetSuffrageByBlockHeight,
) func(context.Context, base.StagePoint, []base.Address) (base.Voteproof, error)

Types

type BallotBroadcaster

type BallotBroadcaster interface {
	Broadcast(base.Ballot) error
	Ballot(_ base.Point, _ base.Stage, isSuffrageConfirm bool) (base.Ballot, bool, error)
}

type BallotStuckResolver

type BallotStuckResolver interface {
	NewPoint(context.Context, base.StagePoint) bool
	Voteproof() <-chan base.Voteproof
	Clean()
	Cancel(base.StagePoint)
}

type Ballotbox

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

func NewBallotbox

func NewBallotbox(
	local base.Address,
	getSuffragef isaac.GetSuffrageByBlockHeight,
) *Ballotbox

func (*Ballotbox) Count

func (box *Ballotbox) Count(threshold base.Threshold) bool

func (*Ballotbox) LastPoint

func (box *Ballotbox) LastPoint() LastPoint

func (*Ballotbox) MissingNodes

func (box *Ballotbox) MissingNodes(point base.StagePoint, threshold base.Threshold) ([]base.Address, bool, error)

func (*Ballotbox) SetCountAfter

func (box *Ballotbox) SetCountAfter(d time.Duration) *Ballotbox

func (*Ballotbox) SetInterval

func (box *Ballotbox) SetInterval(d time.Duration) *Ballotbox

func (*Ballotbox) SetIsValidVoteproofFunc

func (box *Ballotbox) SetIsValidVoteproofFunc(f func(base.Voteproof, base.Suffrage) error) *Ballotbox

func (*Ballotbox) SetLastPoint

func (box *Ballotbox) SetLastPoint(point LastPoint) bool

func (*Ballotbox) SetLastPointFromVoteproof

func (box *Ballotbox) SetLastPointFromVoteproof(vp base.Voteproof) bool

func (*Ballotbox) SetNewBallotFunc

func (box *Ballotbox) SetNewBallotFunc(f func(base.Ballot)) *Ballotbox

func (*Ballotbox) SetSuffrageVoteFunc

func (box *Ballotbox) SetSuffrageVoteFunc(f func(base.SuffrageWithdrawOperation) error) *Ballotbox

func (*Ballotbox) StuckVoteproof

func (box *Ballotbox) StuckVoteproof(
	point base.StagePoint,
	threshold base.Threshold,
	withdraws []base.SuffrageWithdrawOperation,
) (vp base.Voteproof, _ error)

func (*Ballotbox) Vote

func (box *Ballotbox) Vote(bl base.Ballot, threshold base.Threshold) (bool, error)

func (*Ballotbox) VoteSignFact

func (box *Ballotbox) VoteSignFact(sf base.BallotSignFact, threshold base.Threshold) (bool, error)

func (*Ballotbox) Voted

func (box *Ballotbox) Voted(point base.StagePoint, nodes []base.Address) []base.BallotSignFact

func (*Ballotbox) Voteproof

func (box *Ballotbox) Voteproof() <-chan base.Voteproof

type BootingHandler

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

type BootingHandlerArgs

type BootingHandlerArgs struct {
	LastManifestFunc         func() (base.Manifest, bool, error)
	NodeInConsensusNodesFunc isaac.NodeInConsensusNodesFunc
}

func NewBootingHandlerArgs

func NewBootingHandlerArgs() *BootingHandlerArgs

type BrokenHandler

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

type ConsensusHandler

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

type ConsensusHandlerArgs

type ConsensusHandlerArgs struct {
	ProposalProcessors    *isaac.ProposalProcessors
	GetManifestFunc       func(base.Height) (base.Manifest, error)
	WhenNewBlockSaved     func(base.Height)
	WhenNewBlockConfirmed func(base.Height)
	// contains filtered or unexported fields
}

func NewConsensusHandlerArgs

func NewConsensusHandlerArgs() *ConsensusHandlerArgs

type DefaultBallotBroadcaster

type DefaultBallotBroadcaster struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDefaultBallotBroadcaster

func NewDefaultBallotBroadcaster(
	local base.Address,
	pool isaac.BallotPool,
	broadcastFunc func(base.Ballot) error,
) *DefaultBallotBroadcaster

func (*DefaultBallotBroadcaster) Ballot

func (bb *DefaultBallotBroadcaster) Ballot(
	point base.Point,
	stage base.Stage,
	isSuffrageConfirm bool,
) (base.Ballot, bool, error)

func (*DefaultBallotBroadcaster) Broadcast

func (bb *DefaultBallotBroadcaster) Broadcast(bl base.Ballot) error

type DefaultBallotStuckResolver

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

func NewDefaultBallotStuckResolver

func NewDefaultBallotStuckResolver(
	initialWait,
	interval, resolveAfter time.Duration,
	findMissingBallotsf func(context.Context, base.StagePoint, bool) ([]base.Address, bool, error),
	requestMissingBallotsf func(context.Context, base.StagePoint, []base.Address) error,
	voteSuffrageVotingf func(context.Context, base.StagePoint, []base.Address) (base.Voteproof, error),
) *DefaultBallotStuckResolver

func (*DefaultBallotStuckResolver) Cancel

func (c *DefaultBallotStuckResolver) Cancel(point base.StagePoint)

func (*DefaultBallotStuckResolver) Clean

func (c *DefaultBallotStuckResolver) Clean()

func (*DefaultBallotStuckResolver) NewPoint

func (*DefaultBallotStuckResolver) SetLogging

func (*DefaultBallotStuckResolver) Voteproof

func (c *DefaultBallotStuckResolver) Voteproof() <-chan base.Voteproof

type JoiningHandler

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

type JoiningHandlerArgs

type JoiningHandlerArgs struct {
	LastManifestFunc    func() (base.Manifest, bool, error)
	JoinMemberlistFunc  func(context.Context, base.Suffrage) error
	LeaveMemberlistFunc func(time.Duration) error
	WaitFirstVoteproof  time.Duration
	// contains filtered or unexported fields
}

func NewJoiningHandlerArgs

func NewJoiningHandlerArgs(params *isaac.LocalParams) *JoiningHandlerArgs

type LastPoint

type LastPoint struct {
	base.StagePoint
	// contains filtered or unexported fields
}

func (LastPoint) Before

func (l LastPoint) Before(
	point base.StagePoint,
	isSuffrageConfirm bool,
) bool

type LastVoteproofs

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

func (LastVoteproofs) ACCEPT

func (l LastVoteproofs) ACCEPT() base.ACCEPTVoteproof

func (LastVoteproofs) Cap

func (l LastVoteproofs) Cap() base.Voteproof

func (LastVoteproofs) INIT

func (LastVoteproofs) IsNew

func (l LastVoteproofs) IsNew(vp base.Voteproof) bool

func (LastVoteproofs) PreviousBlockForNextRound

func (l LastVoteproofs) PreviousBlockForNextRound(vp base.Voteproof) util.Hash

PreviousBlockForNextRound finds the previous block hash from last majority voteproof.

-------------------------------------- | m | v | | heights | -------------------------------------- | init | init | X | | | accept | init | O | m == v - 1 | | init | accept | O | m == v | | accept | accept | O | m == v - 1 | --------------------------------------

* 'm' is last majority voteproof * 'v' is draw voteproof, new incoming voteproof for next round

type LastVoteproofsHandler

type LastVoteproofsHandler struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLastVoteproofsHandler

func NewLastVoteproofsHandler() *LastVoteproofsHandler

func (*LastVoteproofsHandler) ForceSet

func (l *LastVoteproofsHandler) ForceSet(vp base.Voteproof) bool

func (*LastVoteproofsHandler) IsNew

func (*LastVoteproofsHandler) Last

func (*LastVoteproofsHandler) Set

func (*LastVoteproofsHandler) Voteproofs

func (l *LastVoteproofsHandler) Voteproofs(point base.StagePoint) (LastVoteproofs, bool)

type MissingBallotsRequestMessage

type MissingBallotsRequestMessage struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewMissingBallotsRequestsMessage

func NewMissingBallotsRequestsMessage(
	point base.StagePoint,
	nodes []base.Address,
	ci quicstream.UDPConnInfo,
) MissingBallotsRequestMessage

func (MissingBallotsRequestMessage) ConnInfo

func (*MissingBallotsRequestMessage) DecodeJSON

func (m *MissingBallotsRequestMessage) DecodeJSON(b []byte, enc *jsonenc.Encoder) error

func (MissingBallotsRequestMessage) IsValid

func (MissingBallotsRequestMessage) MarshalJSON

func (m MissingBallotsRequestMessage) MarshalJSON() ([]byte, error)

func (MissingBallotsRequestMessage) Nodes

func (MissingBallotsRequestMessage) Point

type NewBlockImporterFunc

type NewBlockImporterFunc func(base.BlockMap) (isaac.BlockImporter, error)

type NewBootingHandlerType

type NewBootingHandlerType struct {
	*BootingHandler
}

func NewNewBootingHandlerType

func NewNewBootingHandlerType(
	local base.LocalNode,
	params *isaac.LocalParams,
	args *BootingHandlerArgs,
) *NewBootingHandlerType

type NewBrokenHandlerType

type NewBrokenHandlerType struct {
	*BrokenHandler
}

func NewNewBrokenHandlerType

func NewNewBrokenHandlerType(
	local base.LocalNode,
	params *isaac.LocalParams,
) *NewBrokenHandlerType

type NewConsensusHandlerType

type NewConsensusHandlerType struct {
	*ConsensusHandler
}

func NewNewConsensusHandlerType

func NewNewConsensusHandlerType(
	local base.LocalNode,
	params *isaac.LocalParams,
	args *ConsensusHandlerArgs,
) *NewConsensusHandlerType

type NewImportBlocksFunc

type NewImportBlocksFunc func(
	_ context.Context,
	from, to base.Height,
	batchlimit int64,
	blockMapFunc func(context.Context, base.Height) (base.BlockMap, bool, error),
) error

type NewJoiningHandlerType

type NewJoiningHandlerType struct {
	*JoiningHandler
}

func NewNewJoiningHandlerType

func NewNewJoiningHandlerType(
	local base.LocalNode,
	params *isaac.LocalParams,
	args *JoiningHandlerArgs,
) *NewJoiningHandlerType

type NewStoppedHandlerType

type NewStoppedHandlerType struct {
	*StoppedHandler
}

func NewNewStoppedHandlerType

func NewNewStoppedHandlerType(
	local base.LocalNode,
	params *isaac.LocalParams,
) *NewStoppedHandlerType

type NewSyncingHandlerType

type NewSyncingHandlerType struct {
	*SyncingHandler
}

func NewNewSyncingHandlerType

func NewNewSyncingHandlerType(
	local base.LocalNode,
	params *isaac.LocalParams,
	args *SyncingHandlerArgs,
) *NewSyncingHandlerType

type StateType

type StateType string

func (StateType) IsValid

func (s StateType) IsValid([]byte) error

func (StateType) String

func (s StateType) String() string

type States

type States struct {
	*logging.Logging

	*util.ContextDaemon
	// contains filtered or unexported fields
}

func NewStates

func NewStates(local base.LocalNode, params *isaac.LocalParams, args *StatesArgs) *States

func (*States) Current

func (st *States) Current() StateType

func (*States) Hold

func (st *States) Hold() error

func (*States) MoveState

func (st *States) MoveState(sctx switchContext) error

func (*States) SetHandler

func (st *States) SetHandler(state StateType, h newHandler) *States

func (*States) SetLogging

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

func (*States) SetWhenStateSwitched

func (st *States) SetWhenStateSwitched(f func(StateType))

func (*States) WhenEmptyMembers

func (st *States) WhenEmptyMembers()

type StatesArgs

type StatesArgs struct {
	Ballotbox              *Ballotbox
	BallotStuckResolver    BallotStuckResolver
	LastVoteproofsHandler  *LastVoteproofsHandler
	IsInSyncSourcePoolFunc func(base.Address) bool
	BallotBroadcaster      BallotBroadcaster
	WhenStateSwitchedFunc  func(StateType)
}

func NewStatesArgs

func NewStatesArgs() *StatesArgs

type StoppedHandler

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

type Syncer

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

func NewSyncer

func NewSyncer(prev base.BlockMap, args SyncerArgs) *Syncer

func (*Syncer) Add

func (s *Syncer) Add(height base.Height) bool

func (*Syncer) Cancel

func (s *Syncer) Cancel() error

func (*Syncer) Done

func (s *Syncer) Done() <-chan struct{}

func (*Syncer) Err

func (s *Syncer) Err() error

func (*Syncer) Finished

func (s *Syncer) Finished() <-chan base.Height

func (*Syncer) IsFinished

func (s *Syncer) IsFinished() (base.Height, bool)

type SyncerArgs

type SyncerArgs struct {
	LastBlockMapFunc     SyncerLastBlockMapFunc
	BlockMapFunc         SyncerBlockMapFunc
	TempSyncPool         isaac.TempSyncPool
	WhenStoppedFunc      func() error
	RemovePrevBlockFunc  func(base.Height) (bool, error)
	NewImportBlocksFunc  NewImportBlocksFunc
	BatchLimit           int64
	LastBlockMapInterval time.Duration
	LastBlockMapTimeout  time.Duration
}

func NewSyncerArgs

func NewSyncerArgs() SyncerArgs

type SyncerBlockMapFunc

type SyncerBlockMapFunc func(context.Context, base.Height) (base.BlockMap, bool, error)

type SyncerBlockMapItemFunc

type SyncerBlockMapItemFunc func(
	context.Context, base.Height, base.BlockMapItemType) (io.ReadCloser, func() error, bool, error)

type SyncerLastBlockMapFunc

type SyncerLastBlockMapFunc func(_ context.Context, manifest util.Hash) (

	_ base.BlockMap, updated bool, _ error) // NOTE BlockMap.IsValid() should be called

type SyncingHandler

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

type SyncingHandlerArgs

type SyncingHandlerArgs struct {
	NodeInConsensusNodesFunc isaac.NodeInConsensusNodesFunc
	NewSyncerFunc            func(base.Height) (isaac.Syncer, error)
	WhenFinishedFunc         func(base.Height)
	JoinMemberlistFunc       func(context.Context, base.Suffrage) error
	LeaveMemberlistFunc      func(time.Duration) error
	WhenNewBlockSavedFunc    func(base.Height)
	WaitStuckInterval        time.Duration
}

func NewSyncingHandlerArgs

func NewSyncingHandlerArgs(params *isaac.LocalParams) *SyncingHandlerArgs

type SyncingSwitchContext

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

func NewSyncingSwitchContextWithOK

func NewSyncingSwitchContextWithOK(height base.Height, okf func(StateType) bool) SyncingSwitchContext

func (SyncingSwitchContext) Error

func (s SyncingSwitchContext) Error() string

func (SyncingSwitchContext) MarshalZerologObject

func (s SyncingSwitchContext) MarshalZerologObject(e *zerolog.Event)

func (SyncingSwitchContext) String

func (s SyncingSwitchContext) String() string

Jump to

Keyboard shortcuts

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