types

package
v0.8.18 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package types contains the types and interfaces a consumer of the OCR library needs to be aware of

Index

Constants

View Source
const MaxOracles = 31

The maximum number of oracles supported

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryMessageWithSender

type BinaryMessageWithSender struct {
	Msg    []byte
	Sender OracleID
}

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 Bootstrapper interface {
	Start() error
	Close() error
}

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

func (ConfigDigest) Value

func (c ConfigDigest) Value() (driver.Value, error)

Value returns this instance serialized for database storage.

type ContractConfig

type ContractConfig struct {
	ConfigDigest         ConfigDigest
	Signers              []common.Address // TODO: use OnChainSigningAddress?
	Transmitters         []common.Address
	Threshold            uint8
	EncodedConfigVersion uint64
	Encoded              []byte
}

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 LogFields

type LogFields map[string]interface{}

type Logger

type Logger interface {
	Trace(msg string, fields LogFields)
	Debug(msg string, fields LogFields)
	Info(msg string, fields LogFields)
	Warn(msg string, fields LogFields)
	Error(msg string, fields LogFields)
}

type MonitoringEndpoint

type MonitoringEndpoint interface {
	SendLog(log []byte)
}

MonitoringEndpoint is where the OCR protocol sends monitoring output

type Observation

type Observation *big.Int

Observation is the type returned by the DataSource.Observe method. Represents an int256 at time of writing

type OffchainPublicKey

type OffchainPublicKey ed25519.PublicKey

OffChainPublicKey is the public key used to cryptographically identify an oracle in inter-oracle communications.

type OnChainSigningAddress

type OnChainSigningAddress common.Address

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 PendingTransmission struct {
	Time             time.Time
	Median           Observation
	SerializedReport []byte
	Rs               [][32]byte
	Ss               [][32]byte
	Vs               [32]byte
}

type PendingTransmissionKey

type PendingTransmissionKey struct {
	ConfigDigest ConfigDigest
	Epoch        uint32
	Round        uint8
}

type PersistentState

type PersistentState struct {
	Epoch                uint32
	HighestSentEpoch     uint32
	HighestReceivedEpoch []uint32 // length: at most MaxOracles
}

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.

Jump to

Keyboard shortcuts

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