v1

package
v0.0.0-...-4339141 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const MaxAllowedBlocks = 10

MaxAllowedBlocks indicates the maximum len of LatestBlocks in any given observation. observations that violate this will be discarded

Variables

View Source
var File_mercury_observation_v1_proto protoreflect.FileDescriptor

Functions

func GetConsensusLatestBlock

func GetConsensusLatestBlock(paos []PAO, f int) (hash []byte, num int64, ts uint64, err error)

GetConsensusLatestBlock gets the latest block that has at least f+1 votes Assumes that LatestBlocks are ordered by block number desc

func GetConsensusMaxFinalizedBlockNum

func GetConsensusMaxFinalizedBlockNum(paos []PAO, f int) (int64, error)

GetConsensusMaxFinalizedBlockNum gets the most common (mode) ConsensusMaxFinalizedBlockNum In the event of a tie, the lower number is chosen

func ValidateCurrentBlock

func ValidateCurrentBlock(rf v1.ReportFields) error

ValidateCurrentBlock sanity checks number and hash

Types

type BlockProto

type BlockProto struct {
	Num  int64  `protobuf:"varint,1,opt,name=num,proto3" json:"num,omitempty"`
	Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
	Ts   uint64 `protobuf:"varint,3,opt,name=ts,proto3" json:"ts,omitempty"`
	// contains filtered or unexported fields
}

func (*BlockProto) Descriptor deprecated

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

Deprecated: Use BlockProto.ProtoReflect.Descriptor instead.

func (*BlockProto) GetHash

func (x *BlockProto) GetHash() []byte

func (*BlockProto) GetNum

func (x *BlockProto) GetNum() int64

func (*BlockProto) GetTs

func (x *BlockProto) GetTs() uint64

func (*BlockProto) ProtoMessage

func (*BlockProto) ProtoMessage()

func (*BlockProto) ProtoReflect

func (x *BlockProto) ProtoReflect() protoreflect.Message

func (*BlockProto) Reset

func (x *BlockProto) Reset()

func (*BlockProto) String

func (x *BlockProto) String() string

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 types.ReportTimestamp, fetchMaxFinalizedBlockNum bool) (v1.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 (Factory) NewMercuryPlugin

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"`
	// DEPRECATED: replaced by "latestBlocks"
	// 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"`
	// Latest blocks
	LatestBlocks []*BlockProto `protobuf:"bytes,12,rep,name=latestBlocks,proto3" json:"latestBlocks,omitempty"`
	// contains filtered or unexported fields
}

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) GetLatestBlocks

func (x *MercuryObservationProto) GetLatestBlocks() []*BlockProto

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 PAO

type PAO interface {
	mercury.PAO

	GetBid() (*big.Int, bool)
	GetAsk() (*big.Int, bool)

	// DEPRECATED
	// TODO: Remove this handling after deployment (https://smartcontract-it.atlassian.net/browse/MERC-2272)
	GetCurrentBlockNum() (int64, bool)
	GetCurrentBlockHash() ([]byte, bool)
	GetCurrentBlockTimestamp() (uint64, bool)

	GetLatestBlocks() []v1.Block
	GetMaxFinalizedBlockNumber() (int64, bool)
}

func NewParsedAttributedObservation

func NewParsedAttributedObservation(ts uint32, observer commontypes.OracleID, bp *big.Int, bid *big.Int, ask *big.Int, pricesValid bool,
	currentBlockNum int64, currentBlockHash []byte, currentBlockTimestamp uint64, currentBlockValid bool,
	maxFinalizedBlockNumber int64, maxFinalizedBlockNumberValid bool) PAO

Jump to

Keyboard shortcuts

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