posemesh-compute-node
posemesh-compute-node hosts the node engine and all reusable infrastructure that
the binary crate (bin) wires together. The crate is responsible for
loading configuration, authenticating with DDS, polling DMS for work, managing
sessions, streaming heartbeats, and brokering storage traffic to the domain
server on behalf of capability-specific runners.
Responsibilities
- Environment-driven configuration (
config) with typed accessors and sane defaults where permitted. - Telemetry bootstrap (
telemetry) that installs atracingsubscriber and exposes helper spans. - DDS registration helpers (
dds::register) and the in-memory persistence stub used by legacy registration callbacks (dds::persist). - Authentication state machine for SIWE after registration (
authmodule). - DMS HTTP client (
dms::client) plus request/response data contracts. - Storage façade that turns leases into runner-facing input/output ports
(
storage::{input, output, client, token}). - Session lifecycle management and heartbeat scheduling (
session,heartbeat,engine::HeartbeatDriver). - Poller backoff helpers (
poller) and top-level execution loop (engine). - (Legacy) HTTP router for DDS callbacks (
http); compute nodes no longer need to expose inbound endpoints.
Runtime flow (engine overview)
telemetry::init_from_env()installs logging based onLOG_FORMAT.NodeConfig::from_env()loads operational settings. The node currently requires DDS configuration (see below) because SIWE tokens are mandatory.- Runners are registered in a
RunnerRegistry; the binary decides which capabilities to advertise. dds::register::spawn_registration_if_configured()starts the outbound SIWE-based registration bootstrap/recovery loop, andauth::SiweAfterRegistrationwaits for a successful registration before requesting access tokens.- The main
run_nodeloop obtains an access token from DDS, builds a DMS client, leases tasks, initializes session state, and dispatches to the correct runner viaRunnerRegistry::run_for_lease. HeartbeatDrivercoalesces progress updates and posts heartbeats on the TTL schedule computed bysession::HeartbeatPolicy, refreshing storage tokens when DDS returns new ones.- When a runner finishes, artifacts discovered by the storage layer are
reported to DMS via
completeorfail, and the cycle restarts.
Configuration surface
Required environment variables:
REG_SECRET— shared secret issued by DDS during provisioning.SECP256K1_PRIVHEX— 32-byte hex-encoded private key used to sign SIWE messages.
Optional environment variables:
DMS_BASE_URL(defaulthttps://dms.auki.network/v1) — base URL of the DMS REST API.DDS_BASE_URL(defaulthttps://dds.auki.network) — base URL of the DDS API (used for SIWE authentication).REQUEST_TIMEOUT_SECS(default60) — per-request timeout applied to DMS calls.NODE_VERSION(default crate version) — optional override for the advertised node version.HEARTBEAT_JITTER_MS(default250) — backoff applied when coalescing heartbeat updates for the legacy scheduler inheartbeat::run_scheduler.HEARTBEAT_MIN_RATIO/HEARTBEAT_MAX_RATIO(defaults0.25/0.35) — fraction of the lease TTL after which the engine schedules the next heartbeat.POLL_BACKOFF_MS_MIN/POLL_BACKOFF_MS_MAX(defaults1000/30000) — jitter range used between idle lease polls.TOKEN_SAFETY_RATIO(default0.75) — SIWE token renewal threshold.TOKEN_REAUTH_MAX_RETRIES(default3) — retries before bailing on token refresh.TOKEN_REAUTH_JITTER_MS(default500) — jitter applied between retries.REGISTER_INTERVAL_SECS(default120) — cooldown between registration attempts while the node is not yet registered or is recovering.REGISTER_MAX_RETRY(default-1, meaning infinite retries) — retry cap for transient registration failures before falling back to the regular cooldown.MAX_CONCURRENCY(default1) — staging knob for future multi-runner concurrency.LOG_FORMAT(defaultjson) — set totextfor pretty console logs.ENABLE_NOOP(defaultfalse) — when true the binary registers noop runners.NOOP_SLEEP_SECS(default5) — noop runner sleep duration.
Notable modules
auth::siwe_after_registration— waits for DDS registration, then spins up the SIWE token manager and refresh loop.dds::register— normalizes versions (stripping leadingv), validates the secp256k1 key, and launches the registration task usingposemesh-node-registration. Once acquired, registration is parked until the runtime needs recovery instead of being refreshed on a fixed cadence.engine— orchestrates leasing, cancellation, heartbeat posting, and completion/failure reporting. TheRunnerRegistryfaçade makes it easy to add new capabilities.storage::client— performs authenticated multipart downloads/uploads against the domain server using safe temporary directories.session— tracks lease metadata, computes TTL-driven heartbeat deadlines, and survives new heartbeats refreshing tokens or signalling cancellation.
Developing and testing
- Run
cargo test -p posemesh-compute-nodeto exercise storage, session, and DDS registration behaviour. - The crate uses Tokio throughout; tests rely on the multi-threaded runtime, so avoid enabling the single-threaded scheduler when adding new async tests.
LOG_FORMAT=textis useful during local development to keep logs readable.- The HTTP router is legacy; compute nodes do not require inbound callbacks.