coordinator

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NodeAPIRouteDebugComputeWhiteFlag is the debug route to compute the white flag confirmation for the cone of the given parents.
	// POST computes the white flag confirmation.
	NodeAPIRouteDebugComputeWhiteFlag = "/api/plugins/debug/whiteflag"
)

Variables

View Source
var (
	// ErrNoTipsGiven is returned when no tips were given to issue a checkpoint.
	ErrNoTipsGiven = errors.New("no tips given")
	// ErrNetworkBootstrapped is returned when the flag for bootstrap network was given, but a state file already exists.
	ErrNetworkBootstrapped = errors.New("network already bootstrapped")
	// ErrInvalidSiblingsTrytesLength is returned when the computed siblings trytes do not fit into the signature message fragment.
	ErrInvalidSiblingsTrytesLength = errors.New("siblings trytes too long")
)
View Source
var (
	// ErrQuorumMerkleTreeHashMismatch is fired when a client in the quorum returns a different merkle tree hash.
	ErrQuorumMerkleTreeHashMismatch = errors.New("coordinator quorum merkle tree hash mismatch")
	// ErrQuorumGroupNoAnswer is fired when none of the clients in a quorum group answers.
	ErrQuorumGroupNoAnswer = errors.New("coordinator quorum group did not answer in time")
)

Functions

func CheckpointCaller

func CheckpointCaller(handler interface{}, params ...interface{})

CheckpointCaller is used to signal issued checkpoints.

func MilestoneCaller

func MilestoneCaller(handler interface{}, params ...interface{})

MilestoneCaller is used to signal issued milestones.

func QuorumFinishedCaller added in v1.2.2

func QuorumFinishedCaller(handler interface{}, params ...interface{})

QuorumFinishedCaller is used to signal a finished quorum call.

Types

type BackPressureFunc

type BackPressureFunc func() bool

BackPressureFunc is a function which tells the Coordinator to stop issuing milestones and checkpoints under high load.

type Coordinator

type Coordinator struct {
	// the logger used to log events.
	*utils.WrappedLogger

	// events of the coordinator.
	Events *Events
	// contains filtered or unexported fields
}

Coordinator is used to issue signed messages, called "milestones" to secure an IOTA network and prevent double spends.

func New

func New(
	dbStorage *storage.Storage,
	syncManager *syncmanager.SyncManager,
	networkID uint64,
	signerProvider MilestoneSignerProvider,
	migratorService *migrator.MigratorService,
	utxoManager *utxo.Manager,
	powHandler *pow.Handler,
	sendMessageFunc SendMessageFunc,
	opts ...Option) (*Coordinator, error)

New creates a new coordinator instance.

func (*Coordinator) AddBackPressureFunc

func (coo *Coordinator) AddBackPressureFunc(bpFunc BackPressureFunc)

AddBackPressureFunc adds a BackPressureFunc. This function can be called multiple times to add additional BackPressureFunc.

func (*Coordinator) Bootstrap

func (coo *Coordinator) Bootstrap() (hornet.MessageID, error)

Bootstrap creates the first milestone, if the network was not bootstrapped yet. Returns critical errors.

func (*Coordinator) InitState

func (coo *Coordinator) InitState(bootstrap bool, startIndex milestone.Index) error

InitState loads an existing state file or bootstraps the network. All errors are critical.

func (*Coordinator) Interval added in v1.2.2

func (coo *Coordinator) Interval() time.Duration

Interval returns the interval milestones should be issued.

func (*Coordinator) IssueCheckpoint

func (coo *Coordinator) IssueCheckpoint(checkpointIndex int, lastCheckpointMessageID hornet.MessageID, tips hornet.MessageIDs) (hornet.MessageID, error)

IssueCheckpoint tries to create and send a "checkpoint" to the network. a checkpoint can contain multiple chained messages to reference big parts of the unreferenced cone. this is done to keep the confirmation rate as high as possible, even if there is an attack ongoing. new checkpoints always reference the last checkpoint or the last milestone if it is the first checkpoint after a new milestone.

func (*Coordinator) IssueMilestone

func (coo *Coordinator) IssueMilestone(parents hornet.MessageIDs) (hornet.MessageID, error)

IssueMilestone creates the next milestone. Returns non-critical and critical errors.

func (*Coordinator) QuorumStats added in v1.2.2

func (coo *Coordinator) QuorumStats() []QuorumClientStatistic

QuorumStats returns statistics about the response time and errors of every node in the quorum.

func (*Coordinator) State

func (coo *Coordinator) State() *State

State returns the current state of the coordinator.

type DebugNodeAPIClient added in v1.2.2

type DebugNodeAPIClient struct {
	*iotago.NodeHTTPAPIClient
}

DebugNodeAPIClient is a client for node HTTP REST APIs.

func NewDebugNodeAPIClient added in v1.2.2

func NewDebugNodeAPIClient(baseURL string, opts ...iotago.NodeHTTPAPIClientOption) *DebugNodeAPIClient

NewDebugNodeAPIClient returns a new DebugNodeAPIClient with the given BaseURL.

func (*DebugNodeAPIClient) Whiteflag added in v1.2.2

func (api *DebugNodeAPIClient) Whiteflag(index milestone.Index, parents hornet.MessageIDs) (*MerkleTreeHash, error)

Whiteflag is the debug route to compute the white flag confirmation for the cone of the given parents. This function returns the merkle tree hash calculated by the node.

type Events added in v1.2.2

type Events struct {
	// Fired when a checkpoint message is issued.
	IssuedCheckpointMessage *events.Event
	// Fired when a milestone is issued.
	IssuedMilestone *events.Event
	// SoftError is triggered when a soft error is encountered.
	SoftError *events.Event
	// QuorumFinished is triggered after a coordinator quorum call was finished.
	QuorumFinished *events.Event
}

Events are the events issued by the coordinator.

type InMemoryEd25519MilestoneIndexSigner added in v1.2.2

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

InMemoryEd25519MilestoneIndexSigner is an in memory signer for a particular milestone.

func (*InMemoryEd25519MilestoneIndexSigner) PublicKeys added in v1.2.2

PublicKeys returns a slice of the used public keys.

func (*InMemoryEd25519MilestoneIndexSigner) PublicKeysSet added in v1.2.2

PublicKeysSet returns a map of the used public keys.

func (*InMemoryEd25519MilestoneIndexSigner) SigningFunc added in v1.2.2

SigningFunc returns a function to sign the particular milestone.

type InMemoryEd25519MilestoneSignerProvider added in v1.2.2

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

InMemoryEd25519MilestoneSignerProvider provides InMemoryEd25519MilestoneIndexSigner.

func NewInMemoryEd25519MilestoneSignerProvider added in v1.2.2

func NewInMemoryEd25519MilestoneSignerProvider(privateKeys []ed25519.PrivateKey, keyManager *keymanager.KeyManager, publicKeysCount int) *InMemoryEd25519MilestoneSignerProvider

NewInMemoryEd25519MilestoneSignerProvider creates a new InMemoryEd25519MilestoneSignerProvider.

func (*InMemoryEd25519MilestoneSignerProvider) MilestoneIndexSigner added in v1.2.2

MilestoneIndexSigner returns a new signer for the milestone index.

func (*InMemoryEd25519MilestoneSignerProvider) PublicKeysCount added in v1.2.2

func (p *InMemoryEd25519MilestoneSignerProvider) PublicKeysCount() int

PublicKeysCount returns the amount of public keys in a milestone.

type InsecureRemoteEd25519MilestoneIndexSigner added in v1.2.2

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

InsecureRemoteEd25519MilestoneIndexSigner is an in memory signer for a particular milestone.

func (*InsecureRemoteEd25519MilestoneIndexSigner) PublicKeys added in v1.2.2

PublicKeys returns a slice of the used public keys.

func (*InsecureRemoteEd25519MilestoneIndexSigner) PublicKeysSet added in v1.2.2

PublicKeysSet returns a map of the used public keys.

func (*InsecureRemoteEd25519MilestoneIndexSigner) SigningFunc added in v1.2.2

SigningFunc returns a function to sign the particular milestone.

type InsecureRemoteEd25519MilestoneSignerProvider added in v1.2.2

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

InsecureRemoteEd25519MilestoneSignerProvider provides InsecureRemoteEd25519MilestoneIndexSigner.

func NewInsecureRemoteEd25519MilestoneSignerProvider added in v1.2.2

func NewInsecureRemoteEd25519MilestoneSignerProvider(remoteEndpoint string, keyManager *keymanager.KeyManager, publicKeysCount int) *InsecureRemoteEd25519MilestoneSignerProvider

NewInsecureRemoteEd25519MilestoneSignerProvider creates a new InsecureRemoteEd25519MilestoneSignerProvider.

func (*InsecureRemoteEd25519MilestoneSignerProvider) MilestoneIndexSigner added in v1.2.2

MilestoneIndexSigner returns a new signer for the milestone index.

func (*InsecureRemoteEd25519MilestoneSignerProvider) PublicKeysCount added in v1.2.2

PublicKeysCount returns the amount of public keys in a milestone.

type MerkleTreeHash added in v1.2.2

MerkleTreeHash is the merkle tree root hash of all messages.

type MilestoneIndexSigner added in v1.2.2

type MilestoneIndexSigner interface {
	// PublicKeys returns a slice of the used public keys.
	PublicKeys() []iotago.MilestonePublicKey
	// PublicKeysSet returns a map of the used public keys.
	PublicKeysSet() iotago.MilestonePublicKeySet
	// SigningFunc returns a function to sign the particular milestone.
	SigningFunc() iotago.MilestoneSigningFunc
}

MilestoneIndexSigner is a signer for a particular milestone.

type MilestoneSignerProvider added in v1.2.2

type MilestoneSignerProvider interface {
	// MilestoneIndexSigner returns a new signer for the milestone index.
	MilestoneIndexSigner(milestone.Index) MilestoneIndexSigner
	// PublicKeysCount returns the amount of public keys in a milestone.
	PublicKeysCount() int
}

MilestoneSignerProvider provides milestone signers.

type Option added in v1.2.2

type Option func(opts *Options)

Option is a function setting a coordinator option.

func WithLogger added in v1.2.2

func WithLogger(logger *logger.Logger) Option

WithLogger enables logging within the coordinator.

func WithMilestoneInterval added in v1.2.2

func WithMilestoneInterval(milestoneInterval time.Duration) Option

WithMilestoneInterval defines interval milestones are issued.

func WithPoWWorkerCount added in v1.2.2

func WithPoWWorkerCount(powWorkerCount int) Option

WithPoWWorkerCount defines the amount of workers used for calculating PoW when issuing checkpoints and milestones.

func WithQuorum added in v1.2.2

func WithQuorum(quorumEnabled bool, quorumGroups map[string][]*QuorumClientConfig, timeout time.Duration) Option

WithQuorum defines a quorum, which is used to check the correct ledger state of the coordinator. If no quorumGroups are given, the quorum is disabled.

func WithSigningRetryAmount added in v1.2.2

func WithSigningRetryAmount(amount int) Option

WithSigningRetryAmount defines signing retry amount.

func WithSigningRetryTimeout added in v1.2.2

func WithSigningRetryTimeout(timeout time.Duration) Option

WithSigningRetryTimeout defines signing retry timeout.

func WithStateFilePath added in v1.2.2

func WithStateFilePath(stateFilePath string) Option

WithStateFilePath defines the path to the state file of the coordinator.

type Options added in v1.2.2

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

Options define options for the Coordinator.

type PublicKeyRange added in v1.2.2

type PublicKeyRange struct {
	Key        string          `json:"key" koanf:"key"`
	StartIndex milestone.Index `json:"start" koanf:"start"`
	EndIndex   milestone.Index `json:"end" koanf:"end"`
}

PublicKeyRange is a public key of milestones with a valid range.

type PublicKeyRanges added in v1.2.2

type PublicKeyRanges []*PublicKeyRange

PublicKeyRanges are public keys of milestones with their valid ranges.

type QuorumClientConfig added in v1.2.2

type QuorumClientConfig struct {
	// optional alias of the quorum client.
	Alias string `json:"alias" koanf:"alias"`
	// baseURL of the quorum client.
	BaseURL string `json:"baseURL" koanf:"baseURL"`
	// optional username for basic auth.
	UserName string `json:"userName" koanf:"userName"`
	// optional password for basic auth.
	Password string `json:"password" koanf:"password"`
}

QuorumClientConfig holds the configuration of a quorum client.

type QuorumClientStatistic added in v1.2.2

type QuorumClientStatistic struct {
	// name of the quorum group the client is member of.
	Group string
	// optional alias of the quorum client.
	Alias string
	// baseURL of the quorum client.
	BaseURL string
	// last response time of the whiteflag API call.
	ResponseTimeSeconds float64
	// error of last whiteflag API call.
	Error error
}

QuorumClientStatistic holds statistics of a quorum client.

type QuorumFinishedResult added in v1.2.2

type QuorumFinishedResult struct {
	Duration time.Duration
	Err      error
}

QuorumFinishedResult holds statistics of a finished quorum.

type SendMessageFunc added in v1.2.2

type SendMessageFunc = func(msg *storage.Message, msIndex ...milestone.Index) error

SendMessageFunc is a function which sends a message to the network.

type State

type State struct {
	LatestMilestoneIndex     milestone.Index
	LatestMilestoneMessageID hornet.MessageID
	LatestMilestoneTime      time.Time
}

State stores the latest state of the coordinator.

func (*State) MarshalJSON added in v1.2.2

func (cs *State) MarshalJSON() ([]byte, error)

func (*State) UnmarshalJSON added in v1.2.2

func (cs *State) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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