Skip to content

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

76 stars

Watchers

9 watching

Forks

Latest commit

 

History

3,774 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ocean Node

Ocean Node is the all-in-one backend for the Ocean Protocol stack. A single Node process replaces three legacy components — Provider (data access, encryption, compute), Aquarius (metadata cache) and the subgraph (on-chain event indexing) — and adds Compute-to-Data, payment settlement and more. It exposes an HTTP API and a libp2p peer-to-peer interface, both of which dispatch to one shared set of command handlers.

This README is a quick guide for operators and developers. See the docs/ directory (indexed at the bottom) for the detailed references.

Capabilities

  • Metadata indexing — per-chain indexer for DDOs, orders, pricing (fixed-rate / dispenser), access lists and escrow events, with reindexing and purgatory support.
  • Provider / consume flows — asset download streaming, encrypt/decrypt, fees, nonce/signature checks and order validation.
  • Compute-to-Data (C2D) — Docker-based compute jobs with CPU/RAM/disk/GPU resource matching, free and paid compute, and job result/log retrieval.
  • Service-on-Demand — template-driven long-running services (start/stop/restart/extend).
  • Escrow / payment settlement — on-chain settlement for paid compute and services.
  • Auth tokens — JWT-based auth as an alternative to per-request signatures.
  • Persistent storage — local filesystem (localfs) storage for C2D outputs and user buckets, configured via PERSISTENT_STORAGE (the S3 backend is a stub).
  • Policy Server integration — delegate access decisions to an external policy server.
  • Pluggable key management — node identity and signer behind a KeyManager abstraction.
  • Observability — OpenTelemetry traces/metrics and rotating file logging.

Architecture at a glance

Ocean Node has two front doors and one dispatcher:

  • HTTP — POST /directCommand (plus ergonomic REST routes under provider, ddo, query, compute, auth, escrow, …) normalizes each request into a Command.
  • P2P — a libp2p protocol handler reads length-prefixed command frames off the stream.

Both paths converge on the same CoreHandlersRegistry, where every capability is a command handler reachable identically over HTTP, over P2P and (for most) via a dedicated REST route. See Architecture for the layered model and Mermaid diagrams.

System requirements

  • Basic node (indexer + provider + P2P): ~2 vCPU, 4 GB RAM, a few GB of storage for the databases and logs.
  • Node running C2D / GPU: C2D runs jobs as Docker containers on the host, so size for the workloads you intend to accept — multiple cores, substantial RAM/disk, and one or more GPUs for GPU compute environments. Resource ceilings are declared in DOCKER_COMPUTE_ENVIRONMENTS.
  • OS: latest LTS Ubuntu or latest macOS recommended; other OSes (including Windows) should also work.

A persistent databases/ volume is REQUIRED, not optional. It holds databases/p2p-store, the libp2p datastore that backs this node's DHT provider records, and, with DB_TYPE=sqlite, all the data of the node. Starting it empty silently drops content the node still serves. The Dockerfile declares VOLUME ["/usr/src/app/databases"] for this reason — see "Persistent node data" in Docker deployment.

Quick start (operators)

Option 1 — Docker (recommended)

The recommended way to host a node and be eligible for incentives. Follow the Docker deployment guide. The other options below are aimed at developers who want to tinker.

Option 2 — Docker Compose via the quickstart script (pulls the published image)

npm run quickstart
# OR
scripts/ocean-node-quickstart.sh

This walks you through setting up the environment variables and deploying the node.

Note

The quickstart script auto-detects GPUs (NVIDIA via nvidia-smi, others via lspci) and appends them to DOCKER_COMPUTE_ENVIRONMENTS. Detected GPUs are added to DOCKER_COMPUTE_ENVIRONMENTS[0].resources (the connection-level pool) plus a lightweight ref in environments[0].resources. If you pre-configure DOCKER_COMPUTE_ENVIRONMENTS yourself, auto-detected GPUs are merged in, which can duplicate entries — for most users it is best to let the script handle GPU detection.

Option 3 — PM2

PM2 is a process manager that makes it easy to run and monitor Node.js apps.

npm install -g pm2

# 1. Install deps and build — `npm run start` runs dist/index.js, so a prior build is required
npm install
npm run build

# 2. Set up env vars. The node does NOT auto-load .env at runtime (dotenv is only used in
#    tests), so the vars must be in the shell environment before `pm2 start`.
#    Interactive helper, then load the generated .env into this shell:
npm run setupEnv
source .env
# …or set them manually (only PRIVATE_KEY is mandatory; keep the 0x prefix):
# export PRIVATE_KEY="0x<64-hex-characters>"   # or generate one: node dist/helpers/scripts/generatePK.js
# if you use a JSON config file instead, point CONFIG_PATH at its absolute path:
# export CONFIG_PATH="/absolute/path/to/config.json"

# 3. Start under PM2
pm2 start npm --name "ocean-node" -- run start

Manage it with pm2 list, pm2 logs ocean-node, pm2 restart|stop|delete ocean-node. The node also writes daily-rotating files to logs/ (see Logs); PM2 keeps its own stdout copy in ~/.pm2/logs with no size cap unless pm2-logrotate is installed.

Option 4 — Plain npm (development)

Prerequisites

  • Node.js: use the version pinned in .nvmrc (run nvm use). The effective supported runtime is Node 24+ (package.json engines), and the .nvmrc/Dockerfile pin the exact tested version (currently 26.12.1).
  • Docker + Docker Compose (for C2D, and for PostgreSQL or Elasticsearch if you select one of them; SQLite needs no container).
# 1. Install and build
nvm use
npm install
npm run build

# 3. Configure env vars (interactive helper, or set PRIVATE_KEY manually)
./src/helpers/scripts/setupNodeEnv.sh && source .env

# 4. Start
npm run start

npm run start is not a plain node dist/index.js. It runs node --import ./dist/telemetry/otel.js --max-old-space-size=28784 --trace-warnings --experimental-specifier-resolution=node dist/index.js (identical to the Docker CMD), so a prior npm run build is required.

Configuration

  • PRIVATE_KEY (exactly 66 characters: 0x + 64 hex) and DB_TYPE are the mandatory variables. PRIVATE_KEY seeds the node identity (libp2p peerId), the EVM signer and the encryption keys; DB_TYPE selects the database (sqlite needs no other setting). Everything else has defaults. Generate a key with node dist/helpers/scripts/generatePK.js.
  • Config sources: a JSON config file plus environment-variable overrides. The file is resolved from CONFIG_PATH, else ./config.json in the working directory, and must exist — the repo ships a ready-to-run config.json (chain 8996/development, a single Docker C2D environment). Environment variables are merged on top of the file and take precedence.
    • ⚠️ Blank env vars override the file. Only unset variables fall through to config.json; an empty value (e.g. export HTTP_API_PORT=) is treated as set and overrides the file's value. npm run setupEnv creates .env by copying .env.example, which has many blank export VAR= lines, so after source .env those blanks shadow your config.json. Remove or comment out the lines you are not actually setting, and keep only the vars you want to override.
  • INTERFACES (JSON array, e.g. ["HTTP","P2P"]) toggles which front doors are enabled; omitted means both.
  • docs/env.md is the authoritative reference. Key groups worth knowing:
    • RPCS — per-chain RPC endpoint map (JSON).
    • DB_TYPE — the database, required: sqlite, postgresql or elasticsearch. DB_URL / DB_USERNAME / DB_PASSWORD — the connection, for the last two.
    • ALLOWED_ADMINS, AUTHORIZED_DECRYPTERS, AUTHORIZED_PUBLISHERS, ALLOWED_VALIDATORS (and their access-list variants) — admin / decrypter / validator allow-lists.
    • MAX_REQ_PER_MINUTE, RATE_DENY_LIST — rate limiting.
    • DOCKER_COMPUTE_ENVIRONMENTS — C2D environments, resources and GPUs.
    • POLICY_SERVER_URL — external policy server.
    • JWT_SECRET — signing secret for auth tokens.
    • P2P_* — bind addresses/ports, bootstrap nodes, NAT/relay toggles, announce filtering.

Databases

The node keeps all its data in one database, selected with DB_TYPE:

  • sqlite: no database container and no other setting. The files are in the databases/ folder. One folder is for one node instance.
  • postgresql or elasticsearch: for several node instances on one database. Set DB_URL, DB_USERNAME and DB_PASSWORD (or dbConfig in config.json); without them the configuration fails validation and the node does not start. The repo has a compose file for each: postgresql-compose.yml and elasticsearch-compose.yml.

With no DB_TYPE the node does not start: it does not get the type from DB_URL. See "Upgrade" in the Database guide.

Move the node state to PostgreSQL or Elasticsearch

Version 5.1.0 and older keep the node state (nonces, compute jobs, auth tokens, buckets, metrics history) in the SQLite files of databases/, and the DDO index in Typesense or Elasticsearch. A node of this release with DB_TYPE=sqlite keeps all of it in these files. To move the state of such a node, run this in the folder of its docker-compose.yml:

curl -fsSL https://raw.githubusercontent.com/oceanprotocol/ocean-node/main/scripts/ocean-node-migrate-db.sh | bash

The script:

  1. Asks for the database: p (PostgreSQL), e (Elasticsearch) or s (SQLite). The new database takes the place of the old one (Typesense, or Elasticsearch when you select another one; on a SQLite node it is added) in docker-compose.yml (or .yaml), and in the dbConfig of config.json when the compose file mounts it. With s the old database goes: the state is in SQLite already, so the node uses the same files and upgrades their tables when it starts. The old files stay in <file>.old; the volume of the old database stays. When the volume of the new database exists already, it asks to remove it. When you keep Elasticsearch, the script protects it: an Elasticsearch with xpack.security.enabled: false gets security and a new password for the user elastic, and restarts when the node stops. Without that line Elasticsearch 8 has security, so the compose file needs ELASTIC_PASSWORD. The node gets the same user and password. The changes that it shows hide the passwords and the private key: they are in the files. When the compose file sets PostgreSQL already (after a quickstart run), the script does not ask and does not change the files: it only copies. Docker compose reads only docker-compose.yml (-f). The script stops when COMPOSE_FILE or COMPOSE_ENV_FILES is set, or the folder has a compose.yaml or an override file, because docker compose reads them without -f.
  2. Shows what it will copy and asks you to confirm. The node still runs.
  3. Stops the node, keeps a copy of the state files in the folder backup-<time> of the node volume (node-sqlite), and copies the state. A row that is in the target already is written again; a nonce keeps the higher value.
  4. Starts the node. When the copy fails, it puts back the old files and starts the node as before the script. After a good copy the SQLite files move to the backup folder; when the node then does not start, the script shows the error and the command to start it.

The indexed data is not copied: the node indexes the chains again. The script copies only from the SQLite files: a node on PostgreSQL or Elasticsearch does not move to another database. It refuses files of a newer node than its image.

DDO search is the same on all three: a typed query (filters, sort key, page) that each database runs with its own fixed queries. See "DDO search" in the Database guide.

There is no DEGRADED mode: if the database cannot be opened when the node starts (after the init retries), the node logs Database failed to initialize, exiting and exits with code 1. A config value of the wrong type instead fails OceanNodeConfigSchema (zod) validation and stops startup before any DB is initialized. See Database guide, also for the upgrade from an older release.

Compute (C2D) & services

Compute-to-Data runs jobs as Docker containers through the host Docker socket. The lifecycle is initializeCompute → startCompute / freeStartCompute → getComputeStatus → getComputeResult (+ streamable logs) → stopCompute. Requested CPU/RAM/disk/GPU are matched against environment resource pools, and paid compute settles through the Escrow component. Service-on-Demand runs template-driven long-lived services with a similar lifecycle.

Developer guide

  • Build: npm run build (clean + tsc). Lint/format: npm run lint, npm run lint:fix, npm run format.

  • Tests run against compiled JS in dist/test/, not the TypeScript source. The test:* scripts call npm run build-tests first, so re-run it after editing source or tests.

    npm run test:unit                 # unit suite
    npm run test:integration          # integration suite (needs Barge)
    npm run test:computeunit          # C2D unit tests (fast)
    npm run test:computeintegration   # C2D integration tests
    npm run test:servicesintegration  # Service-on-Demand integration
    npm run test:indexer              # indexer integration
  • Integration tests require a running local stack — clone oceanprotocol/barge and start it with C2D (see testing guide for exact flags per DB backend).

  • Adding a command/handler: register the name in PROTOCOL_COMMANDS + SUPPORTED_PROTOCOL_COMMANDS, add a handler under src/components/core/, register it in the CoreHandlersRegistry, add param validation, and optionally wire a REST route. See CLAUDE.md for the full architecture notes and testing guide.

Observability

The node emits OpenTelemetry traces and metrics (loaded via --import ./dist/telemetry/otel.js at startup) and writes per-module daily-rotating logs to logs/. See Telemetry and Logging.

Note

npm run logs (the signed /logs API helper) is currently broken — see docs/Logs.md for the current way to access logs.

Networking & P2P

Ocean Node builds a libp2p node (TCP + WebSockets, Noise, Yamux, Kademlia DHT + mDNS discovery, circuit-relay v2, AutoNAT, UPnP, auto-TLS) and forwards commands between peers. See Network configuration.

Documentation index

Related repositories

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

76 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages