fsm

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IdleStateName              = "Idle"
	NGStateName                = "NG"
	WaitSnapshotStateName      = "WaitSnapshot"
	WaitMicroSnapshotStateName = "WaitMicroSnapshot"
	PersistStateName           = "Persist"
	SyncStateName              = "Sync"
	HaltStateName              = "Halt"
)

States.

View Source
const (
	NewPeerEvent       = "NewPeer"
	PeerErrorEvent     = "PeerError"
	ScoreEvent         = "Score"
	BlockEvent         = "Block"
	MinedBlockEvent    = "MinedBlock"
	BlockIDsEvent      = "BlockIDs"
	TaskEvent          = "Task"
	MicroBlockEvent    = "MicroBlock"
	MicroBlockInvEvent = "MicroBlockInv"
	TransactionEvent   = "Transaction"
	HaltEvent          = "Halt"

	StopSyncEvent           = "StopSync"
	StopMiningEvent         = "StopMining"
	StartMiningEvent        = "StartMining"
	ChangeSyncPeerEvent     = "ChangeSyncPeer"
	BlockSnapshotEvent      = "BlockSnapshotEvent"
	BlockEndorsementEvent   = "EndorseBlock"
	MicroBlockSnapshotEvent = "MicroBlockSnapshotEvent"
)

Events. TODO: Consider replacing with empty structs with Stringer implemented.

Variables

View Source
var TimeoutErr = proto.NewInfoMsg(errors.New("timeout"))

Functions

func NewFSM

func NewFSM(
	services services.Services,
	microblockInterval, obsolescence time.Duration,
	syncPeer *network.SyncPeer,
	enableLightMode bool,
	logger, netLogger *slog.Logger,
	generationPeriod uint64,
) (*FSM, Async, error)

Types

type Actions

type Actions interface {
	SendScore(currentScorer)
	SendBlock(block *proto.Block)
	SendEndorseBlock(endorse *proto.EndorseBlock)
}

type ActionsImpl

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

func (*ActionsImpl) SendBlock

func (a *ActionsImpl) SendBlock(block *proto.Block)

func (*ActionsImpl) SendEndorseBlock

func (a *ActionsImpl) SendEndorseBlock(endorse *proto.EndorseBlock)

func (*ActionsImpl) SendScore

func (a *ActionsImpl) SendScore(s currentScorer)

type Async

type Async []tasks.Task

type BaseInfo

type BaseInfo struct {
	MicroBlockCache    services.MicroBlockCache
	MicroBlockInvCache services.MicroBlockInvCache
	// contains filtered or unexported fields
}

func (*BaseInfo) AddToUtx

func (a *BaseInfo) AddToUtx(t proto.Transaction) error

func (*BaseInfo) BroadcastTransaction

func (a *BaseInfo) BroadcastTransaction(t proto.Transaction, receivedFrom peer.Peer)

func (*BaseInfo) CancelCleanUTX

func (a *BaseInfo) CancelCleanUTX()

CancelCleanUTX cancels the ongoing UTX cleaning process if it is running. It does nothing if no cleaning process is running. This method is not thread-safe and should be called from a single goroutine.

func (*BaseInfo) CleanUtx

func (a *BaseInfo) CleanUtx()

CleanUtx starts a goroutine to clean the UTX pool. It uses an internal context to allow cancellation of the cleaning process. If a cleaning process is already running, it does nothing. Not thread-safe, should be called from a single goroutine.

type BlocksApplier

type BlocksApplier interface {
	BlockExists(state storage.State, block *proto.Block) (bool, error)
	Apply(
		state storage.State,
		block []*proto.Block,
	) (proto.Height, error)
	ApplyMicro(
		state storage.State,
		block *proto.Block,
	) (proto.Height, error)
	ApplyWithSnapshots(
		state storage.State,
		block []*proto.Block,
		snapshots []*proto.BlockSnapshot,
	) (proto.Height, error)
	ApplyMicroWithSnapshots(
		state storage.State,
		block *proto.Block,
		snapshots *proto.BlockSnapshot,
	) (proto.Height, error)
}

type FSM

type FSM struct {
	State *StateData
	// contains filtered or unexported fields
}

func (*FSM) Block

func (f *FSM) Block(p peer.Peer, block *proto.Block) (Async, error)

func (*FSM) BlockEndorsement

func (f *FSM) BlockEndorsement(endorseBlock *proto.EndorseBlock) (Async, error)

func (*FSM) BlockIDs

func (f *FSM) BlockIDs(peer peer.Peer, signatures []proto.BlockID) (Async, error)

BlockIDs receives signatures that was requested by GetSignatures.

func (*FSM) BlockSnapshot

func (f *FSM) BlockSnapshot(p peer.Peer, blockID proto.BlockID, snapshots proto.BlockSnapshot) (Async, error)

func (*FSM) ChangeSyncPeer

func (f *FSM) ChangeSyncPeer(p peer.Peer) (Async, error)

func (*FSM) Halt

func (f *FSM) Halt() (Async, error)

func (*FSM) MicroBlock

func (f *FSM) MicroBlock(p peer.Peer, micro *proto.MicroBlock) (Async, error)

func (*FSM) MicroBlockInv

func (f *FSM) MicroBlockInv(p peer.Peer, inv *proto.MicroBlockInv) (Async, error)

func (*FSM) MicroBlockSnapshot

func (f *FSM) MicroBlockSnapshot(p peer.Peer, blockID proto.BlockID, snapshots proto.BlockSnapshot) (Async, error)

func (*FSM) MinedBlock

func (f *FSM) MinedBlock(
	block *proto.Block,
	limits proto.MiningLimits,
	keyPair proto.KeyPair,
	vrf []byte,
) (Async, error)

func (*FSM) NewPeer

func (f *FSM) NewPeer(p peer.Peer) (Async, error)

func (*FSM) PeerError

func (f *FSM) PeerError(p peer.Peer, e error) (Async, error)

func (*FSM) Score

func (f *FSM) Score(p peer.Peer, score *proto.Score) (Async, error)

func (*FSM) StartMining

func (f *FSM) StartMining() (Async, error)

func (*FSM) StopMining

func (f *FSM) StopMining() (Async, error)

func (*FSM) StopSync

func (f *FSM) StopSync() (Async, error)

func (*FSM) Task

func (f *FSM) Task(task tasks.AsyncTask) (Async, error)

func (*FSM) Transaction

func (f *FSM) Transaction(p peer.Peer, t proto.Transaction) (Async, error)

type HaltState

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

func (*HaltState) Errorf

func (a *HaltState) Errorf(err error) error

func (*HaltState) String

func (a *HaltState) String() string

type IdleState

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

func (*IdleState) Errorf

func (a *IdleState) Errorf(err error) error

func (*IdleState) Halt

func (a *IdleState) Halt() (State, Async, error)

func (*IdleState) MinedBlock

func (a *IdleState) MinedBlock(
	block *proto.Block, limits proto.MiningLimits, keyPair proto.KeyPair, vrf []byte,
) (State, Async, error)

func (*IdleState) Score

func (a *IdleState) Score(p peer.Peer, score *proto.Score) (State, Async, error)

func (*IdleState) StartMining

func (a *IdleState) StartMining() (State, Async, error)

func (*IdleState) String

func (a *IdleState) String() string

func (*IdleState) Task

func (a *IdleState) Task(task tasks.AsyncTask) (State, Async, error)

func (*IdleState) Transaction

func (a *IdleState) Transaction(p peer.Peer, t proto.Transaction) (State, Async, error)

type InvRequester

type InvRequester interface {
	Add2Cache(id proto.BlockID) (existed bool)
	Request(p types.MessageSender, id proto.BlockID) (existed bool)
}

type NGState

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

func (*NGState) Block

func (a *NGState) Block(peer peer.Peer, block *proto.Block) (State, Async, error)

func (*NGState) BlockEndorsement

func (a *NGState) BlockEndorsement(blockEndorsement *proto.EndorseBlock) (State, Async, error)

func (*NGState) Endorse

func (a *NGState) Endorse(parentBlockID proto.BlockID, height proto.Height,
	endorserPK bls.PublicKey, endorserSK bls.SecretKey) error

func (*NGState) EndorseParentWithEachKey

func (a *NGState) EndorseParentWithEachKey(
	pks []bls.PublicKey,
	sks []bls.SecretKey,
	block *proto.Block,
	height proto.Height,
) error

func (*NGState) Errorf

func (a *NGState) Errorf(err error) error

func (*NGState) Halt

func (a *NGState) Halt() (State, Async, error)

func (*NGState) MicroBlock

func (a *NGState) MicroBlock(p peer.Peer, micro *proto.MicroBlock) (State, Async, error)

func (*NGState) MicroBlockInv

func (a *NGState) MicroBlockInv(p peer.Peer, inv *proto.MicroBlockInv) (State, Async, error)

func (*NGState) MinedBlock

func (a *NGState) MinedBlock(
	block *proto.Block, limits proto.MiningLimits, keyPair proto.KeyPair, vrf []byte,
) (State, Async, error)

func (*NGState) Score

func (a *NGState) Score(p peer.Peer, score *proto.Score) (State, Async, error)

func (*NGState) StopMining

func (a *NGState) StopMining() (State, Async, error)

func (*NGState) String

func (a *NGState) String() string

func (*NGState) Task

func (a *NGState) Task(task tasks.AsyncTask) (State, Async, error)

func (*NGState) Transaction

func (a *NGState) Transaction(p peer.Peer, t proto.Transaction) (State, Async, error)

type PersistState

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

func (*PersistState) Errorf

func (a *PersistState) Errorf(err error) error

func (*PersistState) Halt

func (a *PersistState) Halt() (State, Async, error)

func (*PersistState) Score

func (a *PersistState) Score(p peer.Peer, score *proto.Score) (State, Async, error)

func (*PersistState) StopMining

func (a *PersistState) StopMining() (State, Async, error)

func (*PersistState) String

func (a *PersistState) String() string

func (*PersistState) Task

func (a *PersistState) Task(t tasks.AsyncTask) (State, Async, error)

type ReceivedScore

type ReceivedScore struct {
	Peer  peer.Peer
	Score *proto.Score
}

type State

type State interface {
	String() string
	Errorf(error) error
}

type StateData

type StateData struct {
	Name  stateless.State
	State State
}

type SyncState

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

func (*SyncState) Block

func (a *SyncState) Block(p peer.Peer, block *proto.Block) (State, Async, error)

func (*SyncState) BlockIDs

func (a *SyncState) BlockIDs(peer peer.Peer, signatures []proto.BlockID) (State, Async, error)

func (*SyncState) BlockSnapshot

func (a *SyncState) BlockSnapshot(
	p peer.Peer,
	blockID proto.BlockID,
	snapshot proto.BlockSnapshot,
) (State, Async, error)

func (*SyncState) ChangeSyncPeer

func (a *SyncState) ChangeSyncPeer(p peer.Peer) (State, Async, error)

func (*SyncState) Errorf

func (a *SyncState) Errorf(err error) error

func (*SyncState) Halt

func (a *SyncState) Halt() (State, Async, error)

func (*SyncState) MinedBlock

func (a *SyncState) MinedBlock(
	block *proto.Block, limits proto.MiningLimits, keyPair proto.KeyPair, vrf []byte,
) (State, Async, error)

func (*SyncState) Score

func (a *SyncState) Score(p peer.Peer, score *proto.Score) (State, Async, error)

func (*SyncState) StopSync

func (a *SyncState) StopSync() (State, Async, error)

func (*SyncState) String

func (a *SyncState) String() string

func (*SyncState) Task

func (a *SyncState) Task(task tasks.AsyncTask) (State, Async, error)

func (*SyncState) Transaction

func (a *SyncState) Transaction(p peer.Peer, t proto.Transaction) (State, Async, error)

type WaitMicroSnapshotState

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

func (*WaitMicroSnapshotState) Errorf

func (a *WaitMicroSnapshotState) Errorf(err error) error

func (*WaitMicroSnapshotState) MicroBlockSnapshot

func (a *WaitMicroSnapshotState) MicroBlockSnapshot(
	_ peer.Peer,
	blockID proto.BlockID,
	snapshot proto.BlockSnapshot,
) (State, Async, error)

func (*WaitMicroSnapshotState) Score

func (a *WaitMicroSnapshotState) Score(p peer.Peer, score *proto.Score) (State, Async, error)

func (*WaitMicroSnapshotState) String

func (a *WaitMicroSnapshotState) String() string

func (*WaitMicroSnapshotState) Task

type WaitSnapshotState

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

func (*WaitSnapshotState) BlockSnapshot

func (a *WaitSnapshotState) BlockSnapshot(
	_ peer.Peer,
	blockID proto.BlockID,
	snapshot proto.BlockSnapshot,
) (State, Async, error)

func (*WaitSnapshotState) Errorf

func (a *WaitSnapshotState) Errorf(err error) error

func (*WaitSnapshotState) Score

func (a *WaitSnapshotState) Score(p peer.Peer, score *proto.Score) (State, Async, error)

func (*WaitSnapshotState) String

func (a *WaitSnapshotState) String() string

func (*WaitSnapshotState) Task

func (a *WaitSnapshotState) Task(task tasks.AsyncTask) (State, Async, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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