median

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 16 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_offchainreporting2_median_config_proto protoreflect.FileDescriptor
View Source
var File_offchainreporting2_median_observation_proto protoreflect.FileDescriptor

Functions

func DecodeValue

func DecodeValue(s []byte) (*big.Int, error)

Decodes a value using 24-byte big endian two's complement representation. This function never panics.

func Deviates

func Deviates(thresholdPPB uint64, old *big.Int, new *big.Int) bool

func EncodeValue

func EncodeValue(i *big.Int) ([]byte, error)

Encodes a value using 24-byte big endian two's complement representation. This function never panics.

func MaxValue

func MaxValue() *big.Int

2**191-1

func MinValue

func MinValue() *big.Int

-2**191

Types

type DataSource

type DataSource interface {
	// Observe queries the data source. Returns a value or an error. Once the
	// context is expires, Observe may still do cheap computations and return a
	// result, but should return as quickly as possible.
	//
	// More details: In the current implementation, the context passed to
	// Observe will time out after MaxDurationObservation. However, Observe
	// should *not* make any assumptions about context timeout behavior. Once
	// the context times out, Observe should prioritize returning as quickly as
	// possible, but may still perform fast computations to return a result
	// rather than error. For example, if Observe medianizes a number of data
	// sources, some of which already returned a result to Observe prior to the
	// context's expiry, Observe might still compute their median, and return it
	// instead of an error.
	//
	// Important: Observe should not perform any potentially time-consuming
	// actions like database access, once the context passed has expired.
	Observe(context.Context, types.ReportTimestamp) (*big.Int, error)
}

DataSource implementations must be thread-safe. Observe may be called by many different threads concurrently.

type MedianContract

type MedianContract interface {
	LatestTransmissionDetails(
		ctx context.Context,
	) (
		configDigest types.ConfigDigest,
		epoch uint32,
		round uint8,
		latestAnswer *big.Int,
		latestTimestamp time.Time,
		err error,
	)

	// LatestRoundRequested returns the configDigest, epoch, and round from the latest
	// RoundRequested event emitted by the contract. LatestRoundRequested may or may not
	// return a result if the latest such event was emitted in a block b such that
	// b.timestamp < tip.timestamp - lookback.
	//
	// If no event is found, LatestRoundRequested should return zero values, not an error.
	// An error should only be returned if an actual error occurred during execution,
	// e.g. because there was an error querying the blockchain or the database.
	//
	// As an optimization, this function may also return zero values, if no
	// RoundRequested event has been emitted after the latest NewTransmission event.
	LatestRoundRequested(
		ctx context.Context,
		lookback time.Duration,
	) (
		configDigest types.ConfigDigest,
		epoch uint32,
		round uint8,
		err error,
	)
}

type NumericalMedianConfigProto

type NumericalMedianConfigProto struct {
	AlphaReportInfinite bool   `protobuf:"varint,1,opt,name=alpha_report_infinite,json=alphaReportInfinite,proto3" json:"alpha_report_infinite,omitempty"`
	AlphaReportPpb      uint64 `protobuf:"varint,2,opt,name=alpha_report_ppb,json=alphaReportPpb,proto3" json:"alpha_report_ppb,omitempty"`
	AlphaAcceptInfinite bool   `protobuf:"varint,3,opt,name=alpha_accept_infinite,json=alphaAcceptInfinite,proto3" json:"alpha_accept_infinite,omitempty"`
	AlphaAcceptPpb      uint64 `protobuf:"varint,4,opt,name=alpha_accept_ppb,json=alphaAcceptPpb,proto3" json:"alpha_accept_ppb,omitempty"`
	DeltaCNanoseconds   uint64 `protobuf:"varint,5,opt,name=delta_c_nanoseconds,json=deltaCNanoseconds,proto3" json:"delta_c_nanoseconds,omitempty"`
	// contains filtered or unexported fields
}

func (*NumericalMedianConfigProto) Descriptor deprecated

func (*NumericalMedianConfigProto) Descriptor() ([]byte, []int)

Deprecated: Use NumericalMedianConfigProto.ProtoReflect.Descriptor instead.

func (*NumericalMedianConfigProto) GetAlphaAcceptInfinite

func (x *NumericalMedianConfigProto) GetAlphaAcceptInfinite() bool

func (*NumericalMedianConfigProto) GetAlphaAcceptPpb

func (x *NumericalMedianConfigProto) GetAlphaAcceptPpb() uint64

func (*NumericalMedianConfigProto) GetAlphaReportInfinite

func (x *NumericalMedianConfigProto) GetAlphaReportInfinite() bool

func (*NumericalMedianConfigProto) GetAlphaReportPpb

func (x *NumericalMedianConfigProto) GetAlphaReportPpb() uint64

func (*NumericalMedianConfigProto) GetDeltaCNanoseconds

func (x *NumericalMedianConfigProto) GetDeltaCNanoseconds() uint64

func (*NumericalMedianConfigProto) ProtoMessage

func (*NumericalMedianConfigProto) ProtoMessage()

func (*NumericalMedianConfigProto) ProtoReflect

func (*NumericalMedianConfigProto) Reset

func (x *NumericalMedianConfigProto) Reset()

func (*NumericalMedianConfigProto) String

func (x *NumericalMedianConfigProto) String() string

type NumericalMedianFactory

type NumericalMedianFactory struct {
	ContractTransmitter       MedianContract
	DataSource                DataSource
	JuelsPerFeeCoinDataSource DataSource
	// The Observe() function of the following DataSource returns a non-zero value if the underlying
	// chain does not support reading tx.gasPrice during execution. This is useful e.g. on Starknet.
	// The returned price is expected to be in subunits of the coin used for gas. E.g. on chains that
	// use Ether for gas this would be denominated in Wei.
	GasPriceSubunitsDataSource DataSource
	// Set this to false unless you need GasPriceSubunits to be included in reports
	// for the chain you're targeting.
	// Be careful! Older versions of the ReportingPlugin will discard observations
	// made by newer versions of the ReportingPlugin with this value
	// set to true. This could lead to liveness failures. Only set this to true if all
	// oracles in the protocol instance are running the newer version of the
	// ReportingPlugin.
	IncludeGasPriceSubunitsInObservation bool
	Logger                               commontypes.Logger
	OnchainConfigCodec                   OnchainConfigCodec
	ReportCodec                          ReportCodec
}

func (NumericalMedianFactory) NewReportingPlugin

type NumericalMedianObservationProto

type NumericalMedianObservationProto struct {
	Timestamp        uint32 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	Value            []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	JuelsPerFeeCoin  []byte `protobuf:"bytes,3,opt,name=juelsPerFeeCoin,proto3" json:"juelsPerFeeCoin,omitempty"`
	GasPriceSubunits []byte `protobuf:"bytes,4,opt,name=gasPriceSubunits,proto3" json:"gasPriceSubunits,omitempty"`
	// contains filtered or unexported fields
}

func (*NumericalMedianObservationProto) Descriptor deprecated

func (*NumericalMedianObservationProto) Descriptor() ([]byte, []int)

Deprecated: Use NumericalMedianObservationProto.ProtoReflect.Descriptor instead.

func (*NumericalMedianObservationProto) GetGasPriceSubunits

func (x *NumericalMedianObservationProto) GetGasPriceSubunits() []byte

func (*NumericalMedianObservationProto) GetJuelsPerFeeCoin

func (x *NumericalMedianObservationProto) GetJuelsPerFeeCoin() []byte

func (*NumericalMedianObservationProto) GetTimestamp

func (x *NumericalMedianObservationProto) GetTimestamp() uint32

func (*NumericalMedianObservationProto) GetValue

func (x *NumericalMedianObservationProto) GetValue() []byte

func (*NumericalMedianObservationProto) ProtoMessage

func (*NumericalMedianObservationProto) ProtoMessage()

func (*NumericalMedianObservationProto) ProtoReflect

func (*NumericalMedianObservationProto) Reset

func (*NumericalMedianObservationProto) String

type OffchainConfig

type OffchainConfig struct {
	// If AlphaReportInfinite is true, the deviation check parametrized by
	// AlphaReportPPB will never be satisfied.
	AlphaReportInfinite bool
	// AlphaReportPPB determines the relative deviation between the median (i.e.
	// answer) in the contract and the current median of observations (offchain)
	// at which a report should be issued. That is, a report is issued if
	// abs((offchainMedian - contractMedian)/contractMedian) >= alphaReport.
	AlphaReportPPB uint64 // PPB is parts-per-billion
	// If AlphaAcceptInfinite is true, the deviation check parametrized by
	// AlphaAcceptPPB will never be satisfied.
	AlphaAcceptInfinite bool
	// AlphaAcceptPPB determines the relative deviation between the median in a
	// newly generated report considered for transmission and the median of the
	// currently pending report. That is, a report is accepted for transmission
	// if abs((newMedian - pendingMedian)/pendingMedian) >= alphaAccept. If no
	// report is pending, this variable has no effect.
	AlphaAcceptPPB uint64 // PPB is parts-per-billion
	// DeltaC is the maximum age of the latest report in the contract. If the
	// maximum age is exceeded, a new report will be created by the report
	// generation protocol.
	DeltaC time.Duration
}

func DecodeOffchainConfig

func DecodeOffchainConfig(b []byte) (OffchainConfig, error)

func (OffchainConfig) Encode

func (c OffchainConfig) Encode() []byte

type OnchainConfig

type OnchainConfig struct {
	Min *big.Int
	Max *big.Int
}

type OnchainConfigCodec

type OnchainConfigCodec interface {
	Encode(context.Context, OnchainConfig) ([]byte, error)
	Decode(context.Context, []byte) (OnchainConfig, error)
}

type ParsedAttributedObservation

type ParsedAttributedObservation struct {
	Timestamp        uint32
	Value            *big.Int
	JuelsPerFeeCoin  *big.Int
	GasPriceSubunits *big.Int
	Observer         commontypes.OracleID
}

type ReportCodec

type ReportCodec interface {
	// Implementers may assume that there is at most one
	// ParsedAttributedObservation per observer, and that all observers are
	// valid. However, observation values, timestamps, etc... should all be
	// treated as untrusted.
	BuildReport(context.Context, []ParsedAttributedObservation) (types.Report, error)

	// Gets the "median" (the n//2-th ranked element to be more precise where n
	// is the length of the list) observation from the report. The input to this
	// function should be an output of BuildReport in the benign case.
	// Nevertheless, make sure to treat the input to this function as untrusted.
	MedianFromReport(context.Context, types.Report) (*big.Int, error)

	// Returns the maximum length of a report based on n, the number of oracles.
	// The output of BuildReport must respect this maximum length.
	MaxReportLength(ctx context.Context, n int) (int, error)
}

All functions on ReportCodec should be pure and thread-safe. Be careful validating and parsing any data passed.

type StandardOnchainConfigCodec

type StandardOnchainConfigCodec struct{}

StandardOnchainConfigCodec provides a standard implementation of OnchainConfigCodec. This is the implementation used by the EVM and Solana integrations.

An encoded onchain config is expected to be in the format <version><min><max> where version is a uint8 and min and max are in the format returned by EncodeValue.

func (StandardOnchainConfigCodec) Decode

func (StandardOnchainConfigCodec) Encode

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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