Documentation
¶
Index ¶
- Variables
- func DecodeValueInt192(s []byte) (*big.Int, error)
- func EncodeValueInt192(i *big.Int) ([]byte, error)
- func GetConsensusAsk(paos []ParsedAttributedObservation, f int) (*big.Int, error)
- func GetConsensusBenchmarkPrice(paos []ParsedAttributedObservation, f int) (*big.Int, error)
- func GetConsensusBid(paos []ParsedAttributedObservation, f int) (*big.Int, error)
- func GetConsensusCurrentBlock(paos []ParsedAttributedObservation, f int) (hash []byte, num int64, ts uint64, err error)
- func GetConsensusMaxFinalizedBlockNum(paos []ParsedAttributedObservation, f int) (int64, error)
- func GetConsensusTimestamp(paos []ParsedAttributedObservation) uint32
- func MustEncodeValueInt192(i *big.Int) []byte
- func ValidateAsk(paos []ParsedAttributedObservation, f int, min, max *big.Int) error
- func ValidateBenchmarkPrice(paos []ParsedAttributedObservation, f int, min, max *big.Int) error
- func ValidateBid(paos []ParsedAttributedObservation, f int, min, max *big.Int) error
- func ValidateCurrentBlock(paos []ParsedAttributedObservation, f int, validFromBlockNum int64) error
- type DataSource
- type Factory
- type Fetcher
- type MercuryConfigProto
- type MercuryObservationProto
- func (*MercuryObservationProto) Descriptor() ([]byte, []int)deprecated
- func (x *MercuryObservationProto) GetAsk() []byte
- func (x *MercuryObservationProto) GetBenchmarkPrice() []byte
- func (x *MercuryObservationProto) GetBid() []byte
- func (x *MercuryObservationProto) GetCurrentBlockHash() []byte
- func (x *MercuryObservationProto) GetCurrentBlockNum() int64
- func (x *MercuryObservationProto) GetCurrentBlockTimestamp() uint64
- func (x *MercuryObservationProto) GetCurrentBlockValid() bool
- func (x *MercuryObservationProto) GetMaxFinalizedBlockNumber() int64
- func (x *MercuryObservationProto) GetMaxFinalizedBlockNumberValid() bool
- func (x *MercuryObservationProto) GetPricesValid() bool
- func (x *MercuryObservationProto) GetTimestamp() uint32
- func (*MercuryObservationProto) ProtoMessage()
- func (x *MercuryObservationProto) ProtoReflect() protoreflect.Message
- func (x *MercuryObservationProto) Reset()
- func (x *MercuryObservationProto) String() string
- type ObsResult
- type Observation
- type OffchainConfig
- type OnchainConfig
- type OnchainConfigCodec
- type ParsedAttributedObservation
- type ReportCodec
- type StandardOnchainConfigCodec
- type Transmitter
Constants ¶
This section is empty.
Variables ¶
var File_mercury_config_proto protoreflect.FileDescriptor
var File_mercury_observation_proto protoreflect.FileDescriptor
Functions ¶
func DecodeValueInt192 ¶
Decodes a value using 24-byte big endian two's complement representation. This function never panics.
func EncodeValueInt192 ¶
Encodes a value using 24-byte big endian two's complement representation. This function never panics.
func GetConsensusAsk ¶
func GetConsensusAsk(paos []ParsedAttributedObservation, f int) (*big.Int, error)
GetConsensusAsk gets the median ask
func GetConsensusBenchmarkPrice ¶
func GetConsensusBenchmarkPrice(paos []ParsedAttributedObservation, f int) (*big.Int, error)
GetConsensusBenchmarkPrice gets the median benchmark price
func GetConsensusBid ¶
func GetConsensusBid(paos []ParsedAttributedObservation, f int) (*big.Int, error)
GetConsensusBid gets the median bid
func GetConsensusCurrentBlock ¶
func GetConsensusCurrentBlock(paos []ParsedAttributedObservation, f int) (hash []byte, num int64, ts uint64, err error)
GetConsensusCurrentBlock gets the most common (mode) block hash/number/timestamps. In the event of a tie, use the lowest numerical value
func GetConsensusMaxFinalizedBlockNum ¶
func GetConsensusMaxFinalizedBlockNum(paos []ParsedAttributedObservation, f int) (int64, error)
GetConsensusMaxFinalizedBlockNum gets the most common (mode) ConsensusMaxFinalizedBlockNum In the event of a tie, the lower number is chosen
func GetConsensusTimestamp ¶
func GetConsensusTimestamp(paos []ParsedAttributedObservation) uint32
GetConsensusTimestamp gets the median timestamp
func MustEncodeValueInt192 ¶
func ValidateAsk ¶
func ValidateAsk(paos []ParsedAttributedObservation, f int, min, max *big.Int) error
func ValidateBenchmarkPrice ¶
func ValidateBenchmarkPrice(paos []ParsedAttributedObservation, f int, min, max *big.Int) error
func ValidateBid ¶
func ValidateBid(paos []ParsedAttributedObservation, f int, min, max *big.Int) error
func ValidateCurrentBlock ¶
func ValidateCurrentBlock(paos []ParsedAttributedObservation, f int, validFromBlockNum int64) error
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(ctx context.Context, repts ocrtypes.ReportTimestamp, fetchMaxFinalizedBlockNum bool) (Observation, error) }
DataSource implementations must be thread-safe. Observe may be called by many different threads concurrently.
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
func NewFactory ¶
func NewFactory(ds DataSource, lggr logger.Logger, occ OnchainConfigCodec, rc ReportCodec) Factory
func (Factory) NewMercuryPlugin ¶
func (fac Factory) NewMercuryPlugin(configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error)
type MercuryConfigProto ¶
type MercuryConfigProto struct {
// contains filtered or unexported fields
}
Empty for now; might add in future
func (*MercuryConfigProto) Descriptor
deprecated
func (*MercuryConfigProto) Descriptor() ([]byte, []int)
Deprecated: Use MercuryConfigProto.ProtoReflect.Descriptor instead.
func (*MercuryConfigProto) ProtoMessage ¶
func (*MercuryConfigProto) ProtoMessage()
func (*MercuryConfigProto) ProtoReflect ¶
func (x *MercuryConfigProto) ProtoReflect() protoreflect.Message
func (*MercuryConfigProto) Reset ¶
func (x *MercuryConfigProto) Reset()
func (*MercuryConfigProto) String ¶
func (x *MercuryConfigProto) String() string
type MercuryObservationProto ¶
type MercuryObservationProto struct { Timestamp uint32 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` // Prices BenchmarkPrice []byte `protobuf:"bytes,2,opt,name=benchmarkPrice,proto3" json:"benchmarkPrice,omitempty"` Bid []byte `protobuf:"bytes,3,opt,name=bid,proto3" json:"bid,omitempty"` Ask []byte `protobuf:"bytes,4,opt,name=ask,proto3" json:"ask,omitempty"` // All three prices must be valid, or none are (they all should come from one API query and hold invariant bid <= bm <= ask) PricesValid bool `protobuf:"varint,5,opt,name=pricesValid,proto3" json:"pricesValid,omitempty"` // Current block CurrentBlockNum int64 `protobuf:"varint,6,opt,name=currentBlockNum,proto3" json:"currentBlockNum,omitempty"` CurrentBlockHash []byte `protobuf:"bytes,7,opt,name=currentBlockHash,proto3" json:"currentBlockHash,omitempty"` CurrentBlockTimestamp uint64 `protobuf:"varint,8,opt,name=currentBlockTimestamp,proto3" json:"currentBlockTimestamp,omitempty"` // All three block observations must be valid, or none are (they all come from the same block) CurrentBlockValid bool `protobuf:"varint,9,opt,name=currentBlockValid,proto3" json:"currentBlockValid,omitempty"` // MaxFinalizedBlockNumber comes from previous report when present and is // only observed from mercury server when previous report is nil MaxFinalizedBlockNumber int64 `protobuf:"varint,10,opt,name=maxFinalizedBlockNumber,proto3" json:"maxFinalizedBlockNumber,omitempty"` MaxFinalizedBlockNumberValid bool `protobuf:"varint,11,opt,name=maxFinalizedBlockNumberValid,proto3" json:"maxFinalizedBlockNumberValid,omitempty"` // contains filtered or unexported fields }
TODO: what about different report formats for different clients?
func (*MercuryObservationProto) Descriptor
deprecated
func (*MercuryObservationProto) Descriptor() ([]byte, []int)
Deprecated: Use MercuryObservationProto.ProtoReflect.Descriptor instead.
func (*MercuryObservationProto) GetAsk ¶
func (x *MercuryObservationProto) GetAsk() []byte
func (*MercuryObservationProto) GetBenchmarkPrice ¶
func (x *MercuryObservationProto) GetBenchmarkPrice() []byte
func (*MercuryObservationProto) GetBid ¶
func (x *MercuryObservationProto) GetBid() []byte
func (*MercuryObservationProto) GetCurrentBlockHash ¶
func (x *MercuryObservationProto) GetCurrentBlockHash() []byte
func (*MercuryObservationProto) GetCurrentBlockNum ¶
func (x *MercuryObservationProto) GetCurrentBlockNum() int64
func (*MercuryObservationProto) GetCurrentBlockTimestamp ¶
func (x *MercuryObservationProto) GetCurrentBlockTimestamp() uint64
func (*MercuryObservationProto) GetCurrentBlockValid ¶
func (x *MercuryObservationProto) GetCurrentBlockValid() bool
func (*MercuryObservationProto) GetMaxFinalizedBlockNumber ¶
func (x *MercuryObservationProto) GetMaxFinalizedBlockNumber() int64
func (*MercuryObservationProto) GetMaxFinalizedBlockNumberValid ¶
func (x *MercuryObservationProto) GetMaxFinalizedBlockNumberValid() bool
func (*MercuryObservationProto) GetPricesValid ¶
func (x *MercuryObservationProto) GetPricesValid() bool
func (*MercuryObservationProto) GetTimestamp ¶
func (x *MercuryObservationProto) GetTimestamp() uint32
func (*MercuryObservationProto) ProtoMessage ¶
func (*MercuryObservationProto) ProtoMessage()
func (*MercuryObservationProto) ProtoReflect ¶
func (x *MercuryObservationProto) ProtoReflect() protoreflect.Message
func (*MercuryObservationProto) Reset ¶
func (x *MercuryObservationProto) Reset()
func (*MercuryObservationProto) String ¶
func (x *MercuryObservationProto) String() string
type Observation ¶
type Observation struct { BenchmarkPrice ObsResult[*big.Int] Bid ObsResult[*big.Int] Ask ObsResult[*big.Int] CurrentBlockNum ObsResult[int64] CurrentBlockHash ObsResult[[]byte] CurrentBlockTimestamp ObsResult[uint64] // MaxFinalizedBlockNumber comes from previous report when present and is // only observed from mercury server when previous report is nil MaxFinalizedBlockNumber ObsResult[int64] }
type OffchainConfig ¶
type OffchainConfig struct{}
func DecodeOffchainConfig ¶
func DecodeOffchainConfig(b []byte) (o OffchainConfig, err error)
func (OffchainConfig) Encode ¶
func (c OffchainConfig) Encode() []byte
type OnchainConfig ¶
type OnchainConfigCodec ¶
type OnchainConfigCodec interface { Encode(OnchainConfig) ([]byte, error) Decode([]byte) (OnchainConfig, error) }
type ParsedAttributedObservation ¶
type ParsedAttributedObservation struct { Timestamp uint32 Observer commontypes.OracleID BenchmarkPrice *big.Int Bid *big.Int Ask *big.Int // All three prices must be valid, or none are (they all should come from one API query and hold invariant bid <= bm <= ask) PricesValid bool CurrentBlockNum int64 // inclusive; current block CurrentBlockHash []byte CurrentBlockTimestamp uint64 // All three block observations must be valid, or none are (they all come from the same block) CurrentBlockValid bool // MaxFinalizedBlockNumber comes from previous report when present and is // only observed from mercury server when previous report is nil // // MaxFinalizedBlockNumber will be -1 if there is none MaxFinalizedBlockNumber int64 MaxFinalizedBlockNumberValid bool }
type ReportCodec ¶
type ReportCodec interface { // BuildReport 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(paos []ParsedAttributedObservation, f int, validFromBlockNum int64) (ocrtypes.Report, error) // MaxReportLength Returns the maximum length of a report based on n, the number of oracles. // The output of BuildReport must respect this maximum length. MaxReportLength(n int) (int, error) // CurrentBlockNumFromReport returns the median current block number from a report CurrentBlockNumFromReport(types.Report) (int64, error) }
ReportCodec 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 mercury-specific implementation of OnchainConfigCodec.
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 EncodeValueInt192.
func (StandardOnchainConfigCodec) Decode ¶
func (StandardOnchainConfigCodec) Decode(b []byte) (OnchainConfig, error)
func (StandardOnchainConfigCodec) Encode ¶
func (StandardOnchainConfigCodec) Encode(c OnchainConfig) ([]byte, error)
type Transmitter ¶
type Transmitter interface { Fetcher // NOTE: Mercury doesn't actually transmit on-chain, so there is no // "contract" involved with the transmitter. // - Transmit should be implemented and send to Mercury server // - LatestConfigDigestAndEpoch is a stub method, does not need to do anything // - FromAccount() should return CSA public key ocrtypes.ContractTransmitter }