Documentation
¶
Overview ¶
Package oraclevm implements the Oracle Virtual Machine (O-Chain) for the Lux network. OracleVM provides decentralized oracle services for external data feeds.
Key features:
- Observation: operators fetch data from external sources
- Commit: signed observations submitted to chain
- Aggregate: compute canonical output (median/TWAP/bounded deviation)
- ZK aggregation proofs for correctness
- Threshold attestation for compatibility fallback
Index ¶
- Variables
- func NewService(vm *VM) http.Handler
- type AggregatedValue
- type Block
- func (blk *Block) Accept(ctx context.Context) error
- func (blk *Block) Bytes() []byte
- func (blk *Block) Height() uint64
- func (blk *Block) ID() ids.ID
- func (blk *Block) Parent() ids.ID
- func (blk *Block) ParentID() ids.ID
- func (blk *Block) Reject(ctx context.Context) error
- func (blk *Block) Status() uint8
- func (blk *Block) Timestamp() time.Time
- func (blk *Block) Verify(ctx context.Context) error
- type Config
- type Factory
- type Feed
- type Genesis
- type GetAttestationArgs
- type GetAttestationReply
- type GetFeedArgs
- type GetFeedReply
- type GetValueArgs
- type GetValueReply
- type HealthArgs
- type HealthReply
- type Observation
- type RegisterFeedArgs
- type RegisterFeedReply
- type Service
- func (s *Service) GetAttestation(r *http.Request, args *GetAttestationArgs, reply *GetAttestationReply) error
- func (s *Service) GetFeed(r *http.Request, args *GetFeedArgs, reply *GetFeedReply) error
- func (s *Service) GetValue(r *http.Request, args *GetValueArgs, reply *GetValueReply) error
- func (s *Service) Health(r *http.Request, args *HealthArgs, reply *HealthReply) error
- func (s *Service) RegisterFeed(r *http.Request, args *RegisterFeedArgs, reply *RegisterFeedReply) error
- func (s *Service) SubmitObservation(r *http.Request, args *SubmitObservationArgs, reply *SubmitObservationReply) error
- type SubmitObservationArgs
- type SubmitObservationReply
- type VM
- func (vm *VM) BuildBlock(ctx context.Context) (chain.Block, error)
- func (vm *VM) Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion *chain.VersionInfo) error
- func (vm *VM) CreateAttestation(feedID ids.ID, epoch uint64) (*artifacts.OracleAttestation, error)
- func (vm *VM) CreateHandlers(ctx context.Context) (map[string]http.Handler, error)
- func (vm *VM) Disconnected(ctx context.Context, nodeID ids.NodeID) error
- func (vm *VM) GetBlock(ctx context.Context, id ids.ID) (chain.Block, error)
- func (vm *VM) GetBlockIDAtHeight(ctx context.Context, height uint64) (ids.ID, error)
- func (vm *VM) GetFeed(feedID ids.ID) (*Feed, error)
- func (vm *VM) GetLatestValue(feedID ids.ID) (*AggregatedValue, error)
- func (vm *VM) HealthCheck(ctx context.Context) (*chain.HealthResult, error)
- func (vm *VM) Initialize(ctx context.Context, init vmcore.Init) error
- func (vm *VM) LastAccepted(ctx context.Context) (ids.ID, error)
- func (vm *VM) NewHTTPHandler(ctx context.Context) (http.Handler, error)
- func (vm *VM) ParseBlock(ctx context.Context, bytes []byte) (chain.Block, error)
- func (vm *VM) RegisterFeed(feed *Feed) error
- func (vm *VM) SetPreference(ctx context.Context, id ids.ID) error
- func (vm *VM) SetState(ctx context.Context, state uint32) error
- func (vm *VM) Shutdown(ctx context.Context) error
- func (vm *VM) SubmitObservation(obs *Observation) error
- func (vm *VM) Version(ctx context.Context) (string, error)
- func (vm *VM) WaitForEvent(ctx context.Context) (vmcore.Message, error)
Constants ¶
This section is empty.
Variables ¶
var ( Version = &version.Semantic{ Major: 1, Minor: 0, Patch: 0, } ErrNotInitialized = errors.New("vm not initialized") ErrFeedNotFound = errors.New("feed not found") ErrInvalidObservation = errors.New("invalid observation") ErrStaleObservation = errors.New("stale observation") ErrInvalidAggregation = errors.New("invalid aggregation") )
var VMID = ids.ID{'o', 'r', 'a', 'c', 'l', 'e', 'v', 'm'}
VMID is the unique identifier for OracleVM (O-Chain)
Functions ¶
Types ¶
type AggregatedValue ¶
type AggregatedValue struct {
FeedID ids.ID `json:"feedId"`
Epoch uint64 `json:"epoch"`
Value []byte `json:"value"`
Timestamp time.Time `json:"timestamp"`
Observations int `json:"observationCount"`
AggProof []byte `json:"aggProof,omitempty"`
QuorumCert []byte `json:"quorumCert,omitempty"`
}
AggregatedValue represents the canonical output for a feed
type Block ¶
type Block struct {
ID_ ids.ID `json:"id"`
ParentID_ ids.ID `json:"parentID"`
Height_ uint64 `json:"height"`
Timestamp_ time.Time `json:"timestamp"`
// Oracle-specific data
Observations []*Observation `json:"observations,omitempty"`
Aggregations []*AggregatedValue `json:"aggregations,omitempty"`
FeedUpdates []*Feed `json:"feedUpdates,omitempty"`
Attestations []*artifacts.OracleAttestation `json:"attestations,omitempty"`
// contains filtered or unexported fields
}
Block represents an OracleVM block
type Config ¶
type Config struct {
// Feed settings
MaxFeedsPerBlock int `json:"maxFeedsPerBlock"`
ObservationWindow string `json:"observationWindow"`
MinObservers int `json:"minObservers"`
// Aggregation settings
AggregationMethod string `json:"aggregationMethod"` // median, twap, weighted
DeviationThreshold uint64 `json:"deviationThreshold"` // basis points
// ZK settings
EnableZKAggregation bool `json:"enableZkAggregation"`
ZKProofSystem string `json:"zkProofSystem"` // groth16, plonk
// Attestation settings
RequireQuorumCert bool `json:"requireQuorumCert"`
QuorumThreshold int `json:"quorumThreshold"`
}
Config contains OracleVM configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns default OracleVM configuration
type Feed ¶
type Feed struct {
ID ids.ID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Sources []string `json:"sources"`
UpdateFreq time.Duration `json:"updateFreq"`
PolicyHash [32]byte `json:"policyHash"`
Operators []ids.NodeID `json:"operators"`
CreatedAt time.Time `json:"createdAt"`
Status string `json:"status"`
Metadata map[string]string `json:"metadata"`
}
Feed represents an oracle data feed
type Genesis ¶
type Genesis struct {
Version int `json:"version"`
Message string `json:"message"`
Timestamp int64 `json:"timestamp"`
InitialFeeds []*Feed `json:"initialFeeds,omitempty"`
}
Genesis represents the genesis state
type GetAttestationArgs ¶
GetAttestationArgs are arguments for GetAttestation
type GetAttestationReply ¶
type GetAttestationReply struct {
Attestation []byte `json:"attestation"`
}
GetAttestationReply is the reply for GetAttestation
type GetFeedArgs ¶
type GetFeedArgs struct {
FeedID string `json:"feedId"`
}
GetFeedArgs are arguments for GetFeed
type GetFeedReply ¶
type GetFeedReply struct {
Feed *Feed `json:"feed"`
}
GetFeedReply is the reply for GetFeed
type GetValueArgs ¶
type GetValueArgs struct {
FeedID string `json:"feedId"`
}
GetValueArgs are arguments for GetValue
type GetValueReply ¶
type GetValueReply struct {
Value *AggregatedValue `json:"value"`
}
GetValueReply is the reply for GetValue
type HealthReply ¶
HealthReply is the reply for Health
type Observation ¶
type Observation struct {
FeedID ids.ID `json:"feedId"`
Value []byte `json:"value"`
Timestamp time.Time `json:"timestamp"`
SourceMeta [32]byte `json:"sourceMetaHash"`
OperatorID ids.NodeID `json:"operatorId"`
Signature []byte `json:"signature"`
}
Observation represents a signed observation from an operator
type RegisterFeedArgs ¶
type RegisterFeedArgs struct {
Name string `json:"name"`
Description string `json:"description"`
Sources []string `json:"sources"`
UpdateFreq string `json:"updateFreq"`
Operators []string `json:"operators"`
Metadata map[string]string `json:"metadata"`
}
RegisterFeedArgs are arguments for RegisterFeed
type RegisterFeedReply ¶
type RegisterFeedReply struct {
FeedID string `json:"feedId"`
}
RegisterFeedReply is the reply for RegisterFeed
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides RPC access to the OracleVM
func (*Service) GetAttestation ¶
func (s *Service) GetAttestation(r *http.Request, args *GetAttestationArgs, reply *GetAttestationReply) error
GetAttestation returns an oracle attestation
func (*Service) GetFeed ¶
func (s *Service) GetFeed(r *http.Request, args *GetFeedArgs, reply *GetFeedReply) error
GetFeed returns a feed by ID
func (*Service) GetValue ¶
func (s *Service) GetValue(r *http.Request, args *GetValueArgs, reply *GetValueReply) error
GetValue returns the latest value for a feed
func (*Service) Health ¶
func (s *Service) Health(r *http.Request, args *HealthArgs, reply *HealthReply) error
Health returns health status
func (*Service) RegisterFeed ¶
func (s *Service) RegisterFeed(r *http.Request, args *RegisterFeedArgs, reply *RegisterFeedReply) error
RegisterFeed registers a new oracle feed
func (*Service) SubmitObservation ¶
func (s *Service) SubmitObservation(r *http.Request, args *SubmitObservationArgs, reply *SubmitObservationReply) error
SubmitObservation submits an observation
type SubmitObservationArgs ¶
type SubmitObservationArgs struct {
FeedID string `json:"feedId"`
Value []byte `json:"value"`
Signature []byte `json:"signature"`
}
SubmitObservationArgs are arguments for SubmitObservation
type SubmitObservationReply ¶
type SubmitObservationReply struct {
Success bool `json:"success"`
}
SubmitObservationReply is the reply for SubmitObservation
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM implements the Oracle Virtual Machine
func (*VM) Connected ¶
func (vm *VM) Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion *chain.VersionInfo) error
Connected notifies the VM about connected nodes
func (*VM) CreateAttestation ¶
CreateAttestation creates an OracleAttestation artifact
func (*VM) CreateHandlers ¶
CreateHandlers returns HTTP handlers
func (*VM) Disconnected ¶
Disconnected notifies the VM about disconnected nodes
func (*VM) GetBlockIDAtHeight ¶
func (*VM) GetLatestValue ¶
func (vm *VM) GetLatestValue(feedID ids.ID) (*AggregatedValue, error)
GetLatestValue returns the latest aggregated value for a feed
func (*VM) HealthCheck ¶
func (*VM) Initialize ¶
Initialize initializes the VM with the unified Init struct
func (*VM) ParseBlock ¶
func (*VM) RegisterFeed ¶
RegisterFeed registers a new oracle feed
func (*VM) SubmitObservation ¶
func (vm *VM) SubmitObservation(obs *Observation) error
SubmitObservation submits an observation for a feed