functions

package
v2.7.2-beta0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPruneMaxStoredRequests uint32 = 20_000
	DefaultPruneCheckFrequencySec uint32 = 60 * 10
	DefaultPruneBatchSize         uint32 = 500

	FlagCBORMaxSize    uint32 = 1
	FlagSecretsMaxSize uint32 = 2
)
View Source
const (
	LocationInline     = 0
	LocationRemote     = 1
	LocationDONHosted  = 2
	LanguageJavaScript = 0
)
View Source
const RequestIDLength int = 32

Variables

View Source
var ErrDuplicateRequestID = errors.New("Functions ORM: duplicate request ID")

Functions

func CheckStateTransition

func CheckStateTransition(prev RequestState, next RequestState) error

* +-----------+ * +----+IN_PROGRESS+----------------+ * | +-----+-----+ | * | | | * | v v * | +------------+ +---------+ * | |RESULT_READY+---------->|TIMED_OUT| * | +------+-----+ +---------+ * | | ^ * | v | * | +---------+ | * +---->|FINALIZED|-----------------+ * +---------+ * * \ / * | * v * +---------+ * |CONFIRMED| * +---------+

func NewFunctionsConnectorHandler added in v2.3.0

func NewFunctionsConnectorHandler(nodeAddress string, signerKey *ecdsa.PrivateKey, storage s4.Storage, allowlist functions.OnchainAllowlist, rateLimiter *hc.RateLimiter, subscriptions functions.OnchainSubscriptions, minimumBalance assets.Link, lggr logger.Logger) (*functionsConnectorHandler, error)

Types

type AggregationMethod added in v2.4.0

type AggregationMethod int8

type BridgeAccessor added in v2.3.0

type BridgeAccessor interface {
	NewExternalAdapterClient() (ExternalAdapterClient, error)
}

func NewBridgeAccessor added in v2.3.0

func NewBridgeAccessor(bridgeORM bridges.ORM, bridgeName string, maxResponseBytes int64) BridgeAccessor

type DONHostedSecrets added in v2.4.0

type DONHostedSecrets struct {
	SlotID  uint   `json:"slotId" cbor:"slotId"`
	Version uint64 `json:"version" cbor:"version"`
}

type ErrType

type ErrType int8
const (
	NONE ErrType = iota
	// caused by internal infra problems, potentially retryable
	INTERNAL_ERROR
	// caused by user's code (exception, crash, timeout, ...)
	USER_ERROR
)

func (ErrType) String

func (e ErrType) String() string

type ExternalAdapterClient added in v2.3.0

type ExternalAdapterClient interface {
	RunComputation(
		ctx context.Context,
		requestId string,
		jobName string,
		subscriptionOwner string,
		subscriptionId uint64,
		flags RequestFlags,
		nodeProvidedSecrets string,
		requestData *RequestData,
	) (userResult, userError []byte, domains []string, err error)

	FetchEncryptedSecrets(ctx context.Context, encryptedSecretsUrls []byte, requestId string, jobName string) (encryptedSecrets, userError []byte, err error)
}

ExternalAdapterClient supports two endpoints:

  1. Request (aka "lambda") for executing Functions requests via RunComputation()
  2. Secrets (aka "fetcher") for fetching offchain secrets via FetchEncryptedSecrets()

Both endpoints share the same response format. All methods are thread-safe.

func NewExternalAdapterClient added in v2.3.0

func NewExternalAdapterClient(adapterURL url.URL, maxResponseBytes int64) ExternalAdapterClient

type FunctionsListener

type FunctionsListener struct {
	utils.StartStopOnce
	// contains filtered or unexported fields
}

func NewFunctionsListener

func NewFunctionsListener(
	job job.Job,
	client client.Client,
	contractAddressHex string,
	bridgeAccessor BridgeAccessor,
	pluginORM ORM,
	pluginConfig config.PluginConfig,
	s4Storage s4.Storage,
	lggr logger.Logger,
	urlsMonEndpoint commontypes.MonitoringEndpoint,
	decryptor threshold.Decryptor,
	logPollerWrapper evmrelayTypes.LogPollerWrapper,
) *FunctionsListener

func (*FunctionsListener) Close

func (l *FunctionsListener) Close() error

Close complies with job.Service

func (*FunctionsListener) HealthReport added in v2.6.0

func (l *FunctionsListener) HealthReport() map[string]error

func (*FunctionsListener) Name added in v2.6.0

func (l *FunctionsListener) Name() string

func (*FunctionsListener) Start

Start complies with job.Service

type ORM

type ORM interface {
	CreateRequest(request *Request, qopts ...pg.QOpt) error

	SetResult(requestID RequestID, computationResult []byte, readyAt time.Time, qopts ...pg.QOpt) error
	SetError(requestID RequestID, errorType ErrType, computationError []byte, readyAt time.Time, readyForProcessing bool, qopts ...pg.QOpt) error
	SetFinalized(requestID RequestID, reportedResult []byte, reportedError []byte, qopts ...pg.QOpt) error
	SetConfirmed(requestID RequestID, qopts ...pg.QOpt) error

	TimeoutExpiredResults(cutoff time.Time, limit uint32, qopts ...pg.QOpt) ([]RequestID, error)

	FindOldestEntriesByState(state RequestState, limit uint32, qopts ...pg.QOpt) ([]Request, error)
	FindById(requestID RequestID, qopts ...pg.QOpt) (*Request, error)

	PruneOldestRequests(maxRequestsInDB uint32, batchSize uint32, qopts ...pg.QOpt) (total uint32, pruned uint32, err error)
}

func NewORM

func NewORM(db *sqlx.DB, lggr logger.Logger, cfg pg.QConfig, contractAddress common.Address) ORM

type Request

type Request struct {
	RequestID                  RequestID
	ReceivedAt                 time.Time
	RequestTxHash              *common.Hash
	State                      RequestState
	ResultReadyAt              *time.Time
	Result                     []byte
	ErrorType                  *ErrType
	Error                      []byte
	TransmittedResult          []byte
	TransmittedError           []byte
	Flags                      []byte
	AggregationMethod          *AggregationMethod
	CallbackGasLimit           *uint32
	CoordinatorContractAddress *common.Address
	OnchainMetadata            []byte
	ProcessingMetadata         []byte
}

type RequestData added in v2.3.0

type RequestData struct {
	Source          string   `json:"source" cbor:"source"`
	Language        int      `json:"language" cbor:"language"`
	CodeLocation    int      `json:"codeLocation" cbor:"codeLocation"`
	Secrets         []byte   `json:"secrets,omitempty" cbor:"secrets"`
	SecretsLocation int      `json:"secretsLocation" cbor:"secretsLocation"`
	Args            []string `json:"args,omitempty" cbor:"args"`
	BytesArgs       [][]byte `json:"bytesArgs,omitempty" cbor:"bytesArgs"`
}

type RequestFlags added in v2.5.0

type RequestFlags [32]byte

type RequestID

type RequestID [RequestIDLength]byte

func (*RequestID) Scan

func (r *RequestID) Scan(value interface{}) error

func (RequestID) String

func (r RequestID) String() string

func (RequestID) Value

func (r RequestID) Value() (driver.Value, error)

type RequestState

type RequestState int8
const (
	// IN_PROGRESS is the initial state of a request, set right after receiving it in an on-chain event.
	IN_PROGRESS RequestState = iota

	// RESULT_READY means that computation has finished executing (with either success or user error).
	// OCR2 reporting includes only requests in RESULT_READY state (for Query and Observation phases).
	RESULT_READY

	// TIMED_OUT request has been waiting to get confirmed on chain for too long.
	// It won't be included in OCR2 reporting rounds any more.
	TIMED_OUT

	// FINALIZED request is a part of a report produced by OCR2 and has now entered the transmission protocol
	// (i.e. passed through ShouldAcceptFinalizedReport()).
	FINALIZED

	// CONFIRMED state indicates that we received an on-chain confirmation event
	// (with or without this node's participation in an earlier OCR round).
	// We can transition here at any time (full fan-in) and cannot transition out (empty fan-out).
	// This is a desired and expected final state for every request.
	CONFIRMED
)

func (RequestState) String

func (s RequestState) String() string

type SignedRequestData added in v2.5.0

type SignedRequestData struct {
	CodeLocation    int    `json:"codeLocation" cbor:"codeLocation"`
	Language        int    `json:"language" cbor:"language"`
	Secrets         []byte `json:"secrets" cbor:"secrets"`
	SecretsLocation int    `json:"secretsLocation" cbor:"secretsLocation"`
	Source          string `json:"source" cbor:"source"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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