Documentation
¶
Overview ¶
Package types contains the types and interfaces a consumer of the OCR library needs to be aware of
Index ¶
- Constants
- type BinaryMessageWithSender
- type BinaryNetworkEndpoint
- type BinaryNetworkEndpointFactory
- type Bootstrapper
- type BootstrapperFactory
- type ConfigDigest
- type ContractConfig
- type ContractConfigSubscription
- type ContractConfigTracker
- type ContractTransmitter
- type DataSource
- type Database
- type LocalConfig
- type LogFields
- type Logger
- type MonitoringEndpoint
- type Observation
- type OffchainPublicKey
- type OnChainSigningAddress
- type OracleID
- type PendingTransmission
- type PendingTransmissionKey
- type PersistentState
- type PrivateKeys
- type SharedSecretEncryptionPublicKey
Constants ¶
const MaxOracles = 31
The maximum number of oracles supported
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinaryMessageWithSender ¶
BinaryMessageWithSender contains the information from a Receive() channel message: The binary representation of the message, and the ID of its sender.
type BinaryNetworkEndpoint ¶
type BinaryNetworkEndpoint interface {
// SendTo(msg, to) sends msg to "to"
SendTo(payload []byte, to OracleID)
// Broadcast(msg) sends msg to all oracles
Broadcast(payload []byte)
// Receive returns channel which carries all messages sent to this oracle.
Receive() <-chan BinaryMessageWithSender
// Start starts the endpoint
Start() error
// Close stops the endpoint
Close() error
}
BinaryNetworkEndpoint contains the network methods a consumer must implement SendTo and Broadcast must not block. They should buffer messages and (optionally) drop the oldest buffered messages if the buffer reaches capacity.
The protocol trusts the sender in BinaryMessageWithSender. Implementors of this interface are responsible for securely authenticating that messages come from their indicated senders.
type BinaryNetworkEndpointFactory ¶
type BinaryNetworkEndpointFactory interface {
MakeEndpoint(cd ConfigDigest, peerIDs []string, bootstrappers []string, failureThreshold int) (BinaryNetworkEndpoint, error)
PeerID() string
}
type Bootstrapper ¶
type BootstrapperFactory ¶
type BootstrapperFactory interface {
MakeBootstrapper(cd ConfigDigest, peerIDs []string, bootstrappers []string, failureThreshold int) (Bootstrapper, error)
}
type ConfigDigest ¶
type ConfigDigest [16]byte
func BytesToConfigDigest ¶
func BytesToConfigDigest(b []byte) (g ConfigDigest)
func (ConfigDigest) Hex ¶
func (c ConfigDigest) Hex() string
func (*ConfigDigest) Scan ¶
func (c *ConfigDigest) Scan(value interface{}) error
Scan complies with sql Scanner interface
type ContractConfig ¶
type ContractConfigSubscription ¶
type ContractConfigSubscription interface {
// May be closed by sender at any time
Configs() <-chan ContractConfig
Close()
}
type ContractConfigTracker ¶
type ContractConfigTracker interface {
SubscribeToNewConfigs(ctx context.Context) (ContractConfigSubscription, error)
LatestConfigDetails(ctx context.Context) (changedInBlock uint64, configDigest ConfigDigest, err error)
ConfigFromLogs(ctx context.Context, changedInBlock uint64) (ContractConfig, error)
// LatestBlockHeight returns the height of the most recent block in the chain.
LatestBlockHeight(ctx context.Context) (blockheight uint64, err error)
}
ContractConfigTracker tracks OffchainAggregator.ConfigSet events emitted from blockchain
type ContractTransmitter ¶
type ContractTransmitter interface {
// Transmit sends the report to the on-chain OffchainAggregator smart contract's Transmit method
Transmit(
report []byte,
rs, ss [][32]byte, vs [32]byte,
) (
*types.Transaction, error,
)
LatestTransmissionDetails(
ctx context.Context,
) (
configDigest ConfigDigest,
epoch uint32,
round uint8,
latestAnswer Observation,
latestTimestamp time.Time,
err error,
)
FromAddress() common.Address
}
ContractTransmitter sends new reports to the OffchainAggregator smart contract
type DataSource ¶
type DataSource interface {
// Observe queries the data source. Returns a value or an error.
// Must not block indefinitely.
Observe(context.Context) (Observation, error)
}
DataSource implementations must be thread-safe. Observe may be called by many different threads concurrently.
type Database ¶
type Database interface {
ReadState(configDigest ConfigDigest) (*PersistentState, error)
WriteState(configDigest ConfigDigest, state PersistentState) error
ReadConfig() (*ContractConfig, error)
WriteConfig(config ContractConfig) error
StorePendingTransmission(PendingTransmissionKey, PendingTransmission) error
PendingTransmissionsWithConfigDigest(ConfigDigest) (map[PendingTransmissionKey]PendingTransmission, error)
DeletePendingTransmission(PendingTransmissionKey) error
DeletePendingTransmissionsOlderThan(time.Time) error
}
Database persistently stores information on-disk. All its functions should be thread-safe.
type LocalConfig ¶
type LocalConfig struct {
// Timeout for making observations.
// (This is necessary because an oracle's operations are serialized, so
// blocking forever on an observation would break the oracle.)
DataSourceTimeout time.Duration
// Timeout for blockchain interactions (mediated through
// ContractConfigTracker and ContractTransmitter).
// (This is necessary because an oracle's operations are serialized, so
// blocking forever on a chain interaction would break the oracle.)
BlockchainTimeout time.Duration
// Polling interval at which ContractConfigTracker is queried for
// updated on-chain configurations. Recommended values are between
// fifteen seconds and two minutes.
ContractConfigTrackerPollInterval time.Duration
// Interval at which we try to establish a subscription on ContractConfigTracker
// if one doesn't exist. Recommended values are between two and five minutes.
ContractConfigTrackerSubscribeInterval time.Duration
// Number of block confirmations to wait for before enacting an on-chain
// configuration change. This value doesn't need to be very high (in
// particular, it does not need to protect against malicious re-orgs).
// Since configuration changes create some overhead, and mini-reorgs
// are fairly common, recommended values are between two and ten.
//
// Malicious re-orgs are not any more of concern here than they are in
// blockchain applications in general: Since nodes check the contract for the
// latest config every ContractConfigTrackerPollInterval.Seconds(), they will
// come to a common view of the current config within any interval longer than
// that, as long as the latest setConfig transaction in the longest chain is
// stable. They will thus be able to continue reporting after the poll
// interval, unless an adversary is able to repeatedly re-org the transaction
// out during every poll interval, which would amount to the capability to
// censor any transaction.
ContractConfigConfirmations uint16
}
LocalConfig contains oracle-specific configuration details which are not mandated by the on-chain configuration specification via OffchainAggregator.SetConfig
type MonitoringEndpoint ¶
type MonitoringEndpoint interface {
SendLog(log []byte)
}
MonitoringEndpoint is where the OCR protocol sends monitoring output
type Observation ¶
Observation is the type returned by the DataSource.Observe method. Represents an int256 at time of writing
type OffchainPublicKey ¶
OffChainPublicKey is the public key used to cryptographically identify an oracle in inter-oracle communications.
type OnChainSigningAddress ¶
OnChainSigningAddress is the public key used to cryptographically identify an oracle to the on-chain smart contract.
type OracleID ¶
type OracleID int
OracleID is an index over the oracles, used as a succinct attribution to an oracle in communication with the on-chain contract. It is not a cryptographic commitment to the oracle's private key, like a public key is.
type PendingTransmission ¶
type PendingTransmissionKey ¶
type PendingTransmissionKey struct {
ConfigDigest ConfigDigest
Epoch uint32
Round uint8
}
type PersistentState ¶
type PrivateKeys ¶
type PrivateKeys interface {
// SignOnChain returns an ethereum-style ECDSA secp256k1 signature on msg. See
// signature.OnChainPrivateKey.Sign for the logic it needs to implement
SignOnChain(msg []byte) (signature []byte, err error)
// SignOffChain returns an EdDSA-Ed25519 signature on msg. See
// signature.OffChainPrivateKey.Sign for the logic it needs to implement
SignOffChain(msg []byte) (signature []byte, err error)
// ConfigDiffieHellman multiplies base, as a representative of a Curve 25519
// point, by a secret scalar, which is also the scalar to multiply
// curve25519.BasePoint to, in order to get PublicKeyConfig
ConfigDiffieHellman(base *[curve25519.ScalarSize]byte) (sharedPoint *[curve25519.PointSize]byte, err error)
// PublicKeyAddressOnChain returns the address corresponding to the
// public component of the keypair used in SignOnChain
PublicKeyAddressOnChain() OnChainSigningAddress
// PublicKeyOffChain returns the pbulic component of the keypair used in SignOffChain
PublicKeyOffChain() OffchainPublicKey
// PublicKeyConfig returns the public component of the keypair used in ConfigKeyShare
PublicKeyConfig() [curve25519.PointSize]byte
}
PrivateKeys contains the secret keys needed for the OCR protocol, and methods which use those keys without exposing them to the rest of the application. There are three key pairs to track, here:
- The on-chain signing key, a secp256k1 scalar, used to sign contract reports
- The off-chain key signing key, an Ed25519 scalar, used to sign observations
- The config encryption key, an Ed25519 scalar used to decrypt the symmetric key which encrypts the offchain configuration data passed through the OffchainAggregator smart contract.
type SharedSecretEncryptionPublicKey ¶
type SharedSecretEncryptionPublicKey [curve25519.PointSize]byte // X25519
SharedSecretEncryptionPublicKey is the public key used to receive an encrypted version of the secret shared amongst all oracles on a common contract.