statevar

package
v0.73.10 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownStateVar is returned when we get a request (vote, result) for a state variable we don't have.
	ErrUnknownStateVar  = errors.New("unknown state variable")
	ErrNameAlreadyExist = errors.New("state variable already exists with the same name")
)
View Source
var (
	ErrSnapshotKeyDoesNotExist = errors.New("unknown key for floating point consensus snapshot")
)

Functions

This section is empty.

Types

type Broker

type Broker interface {
	SendBatch(events []events.Event)
}

Broker send events.

type Commander

type Commander interface {
	Command(ctx context.Context, cmd txn.Command, payload proto.Message, f func(string, error), bo *backoff.ExponentialBackOff)
}

type Config

type Config struct {
	Level encoding.LogLevel `long:"log-level"`
}

Config represent the configuration of the collateral engine.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig creates an instance of the package specific configuration, given a pointer to a logger instance to be used for logging within the package.

type ConsensusState added in v0.55.0

type ConsensusState int

ConsensusState trakcs the state transitions of a state variable.

const (
	ConsensusStateUnspecified ConsensusState = iota
	ConsensusStateCalculationStarted
	ConsensusStatePerfectMatch
	ConsensusStateSeekingConsensus
	ConsensusStateconsensusReachedLocked
	ConsensusStateCalculationAborted
	ConsensusStateError
	ConsensusStateStale
)

type Engine

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

Engine is an engine for creating consensus for floaing point "state variables".

func New

func New(log *logging.Logger, config Config, broker Broker, top Topology, cmd Commander) *Engine

New instantiates the state variable engine.

func (*Engine) GetState

func (e *Engine) GetState(k string) ([]byte, []types.StateProvider, error)

func (*Engine) Keys

func (e *Engine) Keys() []string

func (*Engine) LoadState

func (e *Engine) LoadState(ctx context.Context, p *types.Payload) ([]types.StateProvider, error)

func (*Engine) Namespace

func (e *Engine) Namespace() types.SnapshotNamespace

func (*Engine) NewEvent

func (e *Engine) NewEvent(asset, market string, eventType statevar.EventType)

NewEvent triggers calculation of state variables that depend on the event type.

func (*Engine) OnBlockEnd

func (e *Engine) OnBlockEnd(ctx context.Context)

OnBlockEnd calls all state vars to notify them that the block ended and its time to flush events.

func (*Engine) OnDefaultValidatorsVoteRequiredUpdate

func (e *Engine) OnDefaultValidatorsVoteRequiredUpdate(ctx context.Context, d num.Decimal) error

OnDefaultValidatorsVoteRequiredUpdate updates the required majority for a vote on a proposed value.

func (*Engine) OnFloatingPointUpdatesDurationUpdate

func (e *Engine) OnFloatingPointUpdatesDurationUpdate(ctx context.Context, updateFrequency time.Duration) error

OnFloatingPointUpdatesDurationUpdate updates the update frequency from the network parameter.

func (*Engine) OnStateLoaded

func (e *Engine) OnStateLoaded(ctx context.Context) error

OnStateLoaded is called after all snapshots have been loaded and hence all state variables have been created and sets the internal state for all state variables.

func (*Engine) OnTick

func (e *Engine) OnTick(_ context.Context, t time.Time)

OnTick triggers the calculation of state variables whose next scheduled calculation is due.

func (*Engine) ProposedValueReceived

func (e *Engine) ProposedValueReceived(ctx context.Context, ID, nodeID, eventID string, bundle *statevar.KeyValueBundle) error

ProposedValueReceived is called when we receive a result from another node with a proposed result for the calculation triggered by an event.

func (*Engine) ReadyForTimeTrigger

func (e *Engine) ReadyForTimeTrigger(asset, mktID string)

ReadyForTimeTrigger is called when the market is ready for time triggered event and sets the next time to run for all state variables of that market that are time triggered. This is expected to be called at the end of the opening auction for the market.

func (*Engine) RegisterStateVariable

func (e *Engine) RegisterStateVariable(asset, market, name string, converter statevar.Converter, startCalculation func(string, statevar.FinaliseCalculation), trigger []statevar.EventType, result func(context.Context, statevar.StateVariableResult) error) error

RegisterStateVariable register a new state variable for which consensus should be managed. converter - converts from the native format of the variable and the key value bundle format and vice versa startCalculation - a callback to trigger an asynchronous state var calc - the result of which is given through the FinaliseCalculation interface trigger - a slice of events that should trigger the calculation of the state variable frequency - if time based triggering the frequency to trigger, Duration(0) for no time based trigger result - a callback for returning the result converted to the native structure.

func (*Engine) Stopped

func (e *Engine) Stopped() bool

func (*Engine) UnregisterStateVariable

func (e *Engine) UnregisterStateVariable(asset, market string)

UnregisterStateVariable when a market is settled it no longer exists in the execution engine, and so we don't need to keep setting off the time triggered events for it anymore.

type EpochEngine

type EpochEngine interface {
	NotifyOnEpoch(f func(context.Context, types.Epoch))
}

EpochEngine for being notified on epochs.

type StateVariable

type StateVariable struct {
	ID string // the unique identifier of the state variable
	// contains filtered or unexported fields
}

func NewStateVar

func NewStateVar(
	log *logging.Logger,
	broker Broker,
	top Topology,
	cmd Commander,
	currentTime time.Time,
	ID, asset,
	market string,
	converter statevar.Converter,
	startCalculation func(string, statevar.FinaliseCalculation),
	trigger []statevar.EventType,
	result func(context.Context, statevar.StateVariableResult) error,
) *StateVariable

func (*StateVariable) AddNoise

func (sv *StateVariable) AddNoise(kvb []*vegapb.KeyValueBundle) []*vegapb.KeyValueBundle

func (*StateVariable) CalculationFinished

func (sv *StateVariable) CalculationFinished(eventID string, result statevar.StateVariableResult, err error)

CalculationFinished is called from the owner when the calculation is completed to kick off consensus.

func (*StateVariable) GetAsset

func (sv *StateVariable) GetAsset() string

GetAsset returns the asset of the state variable.

func (*StateVariable) GetMarket

func (sv *StateVariable) GetMarket() string

GetMarket returns the market of the state variable.

type Topology

type Topology interface {
	IsValidatorVegaPubKey(node string) bool
	AllNodeIDs() []string
	Get(key string) *validators.ValidatorData
	IsValidator() bool
	SelfNodeID() string
	GetTotalVotingPower() int64
	GetVotingPower(pubkey string) int64
}

Topology the topology service.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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