Documentation ¶
Index ¶
- Variables
- type Broker
- type Commander
- type Config
- type Engine
- func (e *Engine) GetState(k string) ([]byte, []types.StateProvider, error)
- func (e *Engine) HasChanged(k string) bool
- func (e *Engine) Keys() []string
- func (e *Engine) LoadState(ctx context.Context, p *types.Payload) ([]types.StateProvider, error)
- func (e *Engine) Namespace() types.SnapshotNamespace
- func (e *Engine) NewEvent(asset, market string, eventType statevar.StateVarEventType)
- func (e *Engine) OnBlockEnd(ctx context.Context)
- func (e *Engine) OnDefaultValidatorsVoteRequiredUpdate(ctx context.Context, d num.Decimal) error
- func (e *Engine) OnFloatingPointUpdatesDurationUpdate(ctx context.Context, updateFrequency time.Duration) error
- func (e *Engine) OnStateLoaded(ctx context.Context) error
- func (e *Engine) OnTick(ctx context.Context, t time.Time)
- func (e *Engine) ProposedValueReceived(ctx context.Context, ID, nodeID, eventID string, ...) error
- func (e *Engine) ReadyForTimeTrigger(asset, mktID string)
- func (e *Engine) RegisterStateVariable(asset, market, name string, converter statevar.Converter, ...) error
- func (e *Engine) Stopped() bool
- func (e *Engine) UnregisterStateVariable(asset, market string)
- type EpochEngine
- type StateVarConsensusState
- type StateVariable
- type Topology
Constants ¶
This section is empty.
Variables ¶
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") )
var (
ErrSnapshotKeyDoesNotExist = errors.New("unknown key for floating point consensus snapshot")
)
Functions ¶
This section is empty.
Types ¶
type Config ¶
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 Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is an engine for creating consensus for floaing point "state variables".
func (*Engine) HasChanged ¶
func (*Engine) Namespace ¶
func (e *Engine) Namespace() types.SnapshotNamespace
func (*Engine) NewEvent ¶
func (e *Engine) NewEvent(asset, market string, eventType statevar.StateVarEventType)
NewEvent triggers calculation of state variables that depend on the event type.
func (*Engine) OnBlockEnd ¶
OnBlockEnd calls all state vars to notify them that the block ended and its time to flush events.
func (*Engine) OnDefaultValidatorsVoteRequiredUpdate ¶
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 ¶
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 ¶
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 ¶
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.StateVarEventType, 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) UnregisterStateVariable ¶
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 ¶
EpochEngine for being notified on epochs.
type StateVarConsensusState ¶
type StateVarConsensusState int
StateVarConsensusState trakcs the state transitions of a state variable.
const ( StateVarConsensusStateUnspecified StateVarConsensusState = iota StateVarConsensusStateCalculationStarted StateVarConsensusStatePerfectMatch StateVarConsensusStateSeekingConsensus StateVarConsensusStateconsensusReachedLocked StateVarConsensusStateCalculationAborted StateVarConsensusStateError StateVarConsensusStateStale )
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.StateVarEventType, 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 }
Topology the topology service.