updatable_configs

package
v0.29.6 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyRegistered = fmt.Errorf("config name already registered")

ErrAlreadyRegistered is returned when a config field is registered with a name conflicting with an already registered config field.

Functions

func IsValidationError

func IsValidationError(err error) bool

func NewSealingConfigs

func NewSealingConfigs(
	requiredApprovalsForSealConstruction uint,
	requiredApprovalsForSealVerification uint,
	chunkAlpha uint,
	emergencySealingActive bool,
) (module.SealingConfigsSetter, error)

Types

type Field

type Field struct {
	// Name is the name of the config field, must be globally unique.
	Name string
	// TypeName is a human-readable string defining the expected type of inputs.
	TypeName string
	// Set is the setter function for the config field. It enforces validation rules
	// and applies the new config value.
	// Returns ValidationError if the new config value is invalid.
	Set SetAnyConfigFunc
	// Get is the getter function for the config field. It returns the current value
	// for the config field.
	Get GetAnyConfigFunc
}

Field represents one dynamically configurable config field.

type GetAnyConfigFunc

type GetAnyConfigFunc func() any

type GetBoolConfigFunc

type GetBoolConfigFunc func() bool

type GetDurationConfigFunc

type GetDurationConfigFunc func() time.Duration

type GetIdentifierListConfigFunc

type GetIdentifierListConfigFunc func() flow.IdentifierList

type GetUintConfigFunc

type GetUintConfigFunc func() uint

type Manager

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

Manager manages setter and getter for updatable configs, across all components. Components register updatable config fields with the manager at startup, then the Manager exposes the ability to dynamically update these configs while the node is running, for example, via admin commands.

The Manager maintains a list of type-agnostic updatable config fields. The typed registration function (Register*Config) is responsible for type conversion. The registration functions must convert input types (as parsed from JSON) to the Go type expected by the config field setter. They must also convert Go types from config field getters to displayable types (see structpb.NewValue for details).

func NewManager

func NewManager() *Manager

func (*Manager) AllFields

func (m *Manager) AllFields() []Field

AllFields returns all currently registered fields.

func (*Manager) GetField

func (m *Manager) GetField(name string) (Field, bool)

GetField returns the updatable config field with the given name, if one exists.

func (*Manager) RegisterBoolConfig

func (m *Manager) RegisterBoolConfig(name string, get GetBoolConfigFunc, set SetBoolConfigFunc) error

RegisterBoolConfig registers a new bool config. Setter inputs must be bool-typed values. Returns ErrAlreadyRegistered if a config is already registered with name.

func (*Manager) RegisterDurationConfig

func (m *Manager) RegisterDurationConfig(name string, get GetDurationConfigFunc, set SetDurationConfigFunc) error

RegisterDurationConfig registers a new duration config. Setter inputs must be duration-parseable string-typed values. Returns ErrAlreadyRegistered if a config is already registered with name.

func (*Manager) RegisterIdentifierListConfig

func (m *Manager) RegisterIdentifierListConfig(name string, get GetIdentifierListConfigFunc, set SetIdentifierListConfigFunc) error

RegisterIdentifierListConfig registers a new []Identifier config Setter inputs must be []any-typed values, with string elements parseable as Identifier. Returns ErrAlreadyRegistered if a config is already registered with name.

func (*Manager) RegisterUintConfig

func (m *Manager) RegisterUintConfig(name string, get GetUintConfigFunc, set SetUintConfigFunc) error

RegisterUintConfig registers a new uint config. Setter inputs must be float64-typed values and will be truncated if not integral. Returns ErrAlreadyRegistered if a config is already registered with name.

type Registrar

type Registrar interface {
	// RegisterBoolConfig registers a new bool config.
	// Returns ErrAlreadyRegistered if a config is already registered with name.
	RegisterBoolConfig(name string, get GetBoolConfigFunc, set SetBoolConfigFunc) error
	// RegisterUintConfig registers a new uint config.
	// Returns ErrAlreadyRegistered if a config is already registered with name.
	RegisterUintConfig(name string, get GetUintConfigFunc, set SetUintConfigFunc) error
	// RegisterDurationConfig registers a new duration config.
	// Returns ErrAlreadyRegistered if a config is already registered with name.
	RegisterDurationConfig(name string, get GetDurationConfigFunc, set SetDurationConfigFunc) error
	// RegisterIdentifierListConfig registers a new []Identifier config
	// Returns ErrAlreadyRegistered if a config is already registered with name.
	RegisterIdentifierListConfig(name string, get GetIdentifierListConfigFunc, set SetIdentifierListConfigFunc) error
}

Registrar provides an interface for registering config fields which can be dynamically updated while the node is running. Configs must have globally unique names. Setter functions are responsible for enforcing component-specific validation rules, and returning a ValidationError if the new config value is invalid.

type SetAnyConfigFunc

type SetAnyConfigFunc func(any) error

type SetBoolConfigFunc

type SetBoolConfigFunc func(bool) error

type SetDurationConfigFunc

type SetDurationConfigFunc func(time.Duration) error

type SetIdentifierListConfigFunc

type SetIdentifierListConfigFunc func(flow.IdentifierList) error

type SetUintConfigFunc

type SetUintConfigFunc func(uint) error

type ValidationError

type ValidationError struct {
	Err error
}

ValidationError is returned by a config setter function (Set*ConfigFunc) when the provided config field is invalid, and was not applied.

func NewValidationErrorf

func NewValidationErrorf(msg string, args ...any) ValidationError

func (ValidationError) Error

func (err ValidationError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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