ya-runtime-sdk

ya-runtime-sdk is a Rust library for building Computation Environments and Self-contained Runtimes, executed by Provider nodes in the Golem network.

ya-runtime-sdk provides facilitation in the following areas:


Table of contents - Runtime overview - Runtime orchestration - Runtime execution mode - Command execution mode - Complementary functions - Events - Implementation - Context - Configuration - Debugging - Deploying


Runtime overview

Runtime is responsible for performing computation specified in an Agreement between a Provider and a Requestor. Runtimes are executed only after a successful marketplace negotiation has taken place, where prices, computation deadlines and rented hardware resources have been agreed upon.

The degree of remote control that a Requestor can have over a Runtime depends on its flavour:

  1. Computation Environment

    Fully controlled by the Requestor via a well-defined set of commands ("ExeScript"). Requestor is responsible for triggering deployment of the payload (e.g. a Virtual Machine image) specified in an Agreement, starting the environment, executing commands within that environment and terminating the setup.

  2. Self-contained Runtime

    The payload is pre-defined by the developer. In this case, deploying, starting, executing commands and terminating the runtime can be only hinted by the Requestor; the implementation determines the exact behaviour of those actions.

Runtime orchestration

Runtimes are orchestrated by their parent process, the ExeUnit Supervisor, via a standardized set of command line arguments and a Runtime API protocol. ya-runtime-sdk handles all the communication automatically for any struct implementing the Runtime trait.

The Runtime trait specifies handlers for each of the execution phases:

Runtime execution mode

Runtime::MODE specifies one of 2 possible execution modes:

Command execution mode

run_command implementation should distinguish each of the execution modes but is not required to support both.

Complementary functions

In addition to the lifecycle and execution logic, runtimes can implement 2 additional customization functions:

Events

(TBD) Future versions of ya-runtime-sdk may cover additional types of events:


Implementation

Runtimes can be implemented by performing the following steps:

See the example-runtime for more details.

Context

Each of the Runtime trait functions is parameterized with a mutable reference to the runtime, and a runtime execution context object.

The Context struct exposes the following properties:

Context also exposes functions for configuration persistence:

Configuration

Configuration struct can be set via a #[conf(..)] attribute of the RuntimeDef derive macro. On runtime startup, configuration is read from a file located at ~/.local/share/<crate_name>/<crate_name>.<format>.

Debugging

Developers can use the ya-runtime-dbg tool to interact with a runtime running in Server mode. See the README.md file in the linked repository for more details.

Deploying

  1. Create a ya-runtime-<runtime_name>.json descriptor file in the plugins directory.

json [ { "name": "<runtime_name>", "version": "0.1.0", "supervisor-path": "exe-unit", "runtime-path": "<runtime_dir>/<runtime_bin>", "description": "Custom runtime ", "extra-args": ["--runtime-managed-image"] } ]

  1. Edit ~/.local/share/ya-provider/presets.json:

  2. Start golemsp or ya-provider.

The plugins directory is by default located at: