From d3af2d186cd370e5d88cc9113e7e8d1dbd3b3ba4 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Tue, 3 Nov 2026 11:47:48 -0500 Subject: [PATCH] fix(localnet): run current Studio (v0.123) with genlayer init/up The bundled compose still described the pre-v0.80 Studio topology, so the CLI defaulted to localnet v0.65.0 and any newer version failed in sequence: missing simulator-hardhat image, migration ignoring DB_URL, partial GenVM web override (missing extra_tld), jsonrpc requiring REDIS_URL with no redis/consensus-worker, healthcheck shorter than the ~95 s GenVM precompile, and chain id 61999 instead of 61127. - compose: add redis and consensus-worker, drop hardhat, pass DB* variables to the migration, share a genvm_cache volume, raise the jsonrpc start_period to 300 s. - .env.example: GENLAYER_CHAIN_ID=61127 to match the SDK localnet chain. - setupLocalhostAccess: mount the web override on the worker too (it executes contracts) and write the full GenVM web schema, since the backend replaces the image's file instead of merging it. - localnetCompatibleVersion: v0.123.0 (default and minimum). - isLocalnetRunning: expect consensus-worker instead of the removed webrequest container. Validated with a cold start (down -v) of Studio v0.123.0-rc.10: all services healthy, a v0.3 contract deploy reached FINALIZED and its read returned the stored value. Unit tests: 842 passed. --- .env.example | 1 + README.md | 4 +- docker-compose.yml | 68 ++++++++++++++++++++---- docs/api-references/environment/init.mdx | 2 +- src/lib/config/simulator.ts | 4 +- src/lib/services/simulator.ts | 19 +++++++ tests/services/simulator.test.ts | 47 +++++++++++++++- 7 files changed, 127 insertions(+), 18 deletions(-) diff --git a/.env.example b/.env.example index ea3e9b5a..05d2d492 100644 --- a/.env.example +++ b/.env.example @@ -83,6 +83,7 @@ HARDHAT_URL = 'http://hardhat' HARDHAT_PORT = '8545' HARDHAT_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' HARDHAT_CHAIN_ID=61999 +GENLAYER_CHAIN_ID=61127 COMPOSE_PROFILES='hardhat' BACKEND_BUILD_TARGET = 'debug' diff --git a/README.md b/README.md index 2658970e..0faee252 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ OPTIONS: EXAMPLES: genlayer init - genlayer init --numValidators 10 --headless --reset-db --localnet-version v0.10.2 + genlayer init --numValidators 10 --headless --reset-db --localnet-version v0.123.0 genlayer init --ollama ``` @@ -71,7 +71,7 @@ EXAMPLES: The GenLayer CLI always uses the latest compatible version of the environment, ensuring that you benefit from the most recent features, bug fixes, and optimizations without requiring manual updates. If a specific version is needed, you can specify it using the --localnet-version option when initializing the environment. ```bash -genlayer init --localnet-version v0.10.2 +genlayer init --localnet-version v0.123.0 ``` #### Start GenLayer environment diff --git a/docker-compose.yml b/docker-compose.yml index 6e8c4a0b..5ded3611 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,6 +34,7 @@ services: - RPCDEBUGPORT=${RPCDEBUGPORT:-5001} - WEBDRIVERHOST=${WEBDRIVERHOST:-webdriver} - WEBDRIVERPORT=${WEBDRIVERPORT:-4444} + - REDIS_URL=${REDIS_URL:-redis://redis:6379/0} ports: - "${RPCPORT:-5000}:${RPCPORT:-5000}" - "${RPCDEBUGPORT:-5001}:${RPCDEBUGPORT:-5001}" @@ -44,12 +45,14 @@ services: interval: 30s timeout: 10s retries: 3 - start_period: 30s + start_period: 300s depends_on: database-migration: condition: service_completed_successfully webdriver: - condition: service_healthy + condition: service_healthy + redis: + condition: service_healthy expose: - "${RPCPORT:-5000}" restart: always @@ -63,6 +66,7 @@ services: deploy: replicas: ${JSONRPC_REPLICAS:-1} volumes: + - genvm_cache:/genvm-cache - hardhat_artifacts:/app/hardhat/artifacts - hardhat_deployments:/app/hardhat/deployments @@ -130,23 +134,65 @@ services: image: yeagerai/simulator-database-migration:${LOCALNETVERSION:-latest} environment: - DB_URL=postgresql://${DBUSER:-postgres}:${DBPASSWORD:-postgres}@postgres/${DBNAME:-simulator_db} + - DBUSER=${DBUSER:-postgres} + - DBPASSWORD=${DBPASSWORD:-postgres} + - DBHOST=${DBHOST:-postgres} + - DBPORT=${DBPORT:-5432} + - DBNAME=${DBNAME:-simulator_db} depends_on: postgres: condition: service_healthy - hardhat: - image: yeagerai/simulator-hardhat:${LOCALNETVERSION:-latest} - ports: - - "${HARDHAT_PORT:-8545}:8545" + consensus-worker: + image: yeagerai/simulator-consensus-worker:${LOCALNETVERSION:-latest} environment: - - HARDHAT_NETWORK=hardhat + - PYTHONUNBUFFERED=1 + - WORKER_PORT=4001 + - WEBDRIVERHOST=${WEBDRIVERHOST:-webdriver} + - WEBDRIVERPORT=${WEBDRIVERPORT:-4444} + - REDIS_URL=${REDIS_URL:-redis://redis:6379/0} + env_file: + - ./.env volumes: - - hardhat_artifacts:/app/artifacts - - hardhat_deployments:/app/deployments - - hardhat_cache:/app/cache - - hardhat_snapshots:/app/snapshots + - genvm_cache:/genvm-cache + depends_on: + database-migration: + condition: service_completed_successfully + webdriver: + condition: service_healthy + redis: + condition: service_healthy + jsonrpc: + condition: service_healthy + deploy: + replicas: ${CONSENSUS_WORKERS:-1} + restart: always + security_opt: + - "no-new-privileges=true" + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + + redis: + image: redis:8-alpine + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 3s + retries: 3 + restart: always + security_opt: + - "no-new-privileges=true" + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" volumes: + genvm_cache: hardhat_artifacts: hardhat_deployments: hardhat_cache: diff --git a/docs/api-references/environment/init.mdx b/docs/api-references/environment/init.mdx index e3b3e85c..a4a4e31e 100644 --- a/docs/api-references/environment/init.mdx +++ b/docs/api-references/environment/init.mdx @@ -15,6 +15,6 @@ Initialize the GenLayer Environment | | --numValidators <numValidators> | Number of validators | No | `5` | | | --headless | Headless mode | No | `false` | | | --reset-db | Reset Database | No | `false` | -| | --localnet-version <localnetVersion> | Select a specific localnet version (minimum: v0.65.0) | No | `v0.65.0` | +| | --localnet-version <localnetVersion> | Select a specific localnet version (minimum: v0.123.0) | No | `v0.123.0` | | | --ollama | Enable Ollama container | No | `false` | | -h | --help | display help for command | No | | diff --git a/src/lib/config/simulator.ts b/src/lib/config/simulator.ts index 12ade540..2f34944b 100644 --- a/src/lib/config/simulator.ts +++ b/src/lib/config/simulator.ts @@ -1,4 +1,4 @@ -export const localnetCompatibleVersion = "v0.65.0"; +export const localnetCompatibleVersion = "v0.123.0"; export const DEFAULT_JSON_RPC_URL = "http://localhost:4000/api"; export const CONTAINERS_NAME_PREFIX = "/genlayer-"; export const IMAGES_NAME_PREFIX = "yeagerai"; @@ -63,6 +63,6 @@ export const AI_PROVIDERS_CONFIG: AiProvidersConfigType = { export const GENLAYER_REQUIRED_CONTAINERS = [ "genlayer-jsonrpc", - "genlayer-webrequest", + "genlayer-consensus-worker", "genlayer-postgres" ] \ No newline at end of file diff --git a/src/lib/services/simulator.ts b/src/lib/services/simulator.ts index cc8b3450..c9eabab9 100644 --- a/src/lib/services/simulator.ts +++ b/src/lib/services/simulator.ts @@ -349,6 +349,12 @@ services: extra_hosts: - "host.docker.internal:host-gateway" - "anvil-local:host-gateway" + consensus-worker: + volumes: + - ./config-overrides/genvm-module-web.yaml:/genvm/config/genvm-module-web.yaml:ro + extra_hosts: + - "host.docker.internal:host-gateway" + - "anvil-local:host-gateway" `; fs.writeFileSync(overridePath, overrideContent); @@ -358,7 +364,20 @@ services: } const genvmConfigPath = path.join(configDir, 'genvm-module-web.yaml'); + // The backend replaces (not merges) the image's web config, so every field of the GenVM schema must be present. const genvmConfigContent = `# Auto-generated by genlayer CLI — allows GenVM to reach localhost services +bind_address: 127.0.0.1:3032 +webdriver_host: http://127.0.0.1:4444 +lua_script_path: \${exeDir}/../config/genvm-web-default.lua +vm_count: 6 +lua_path: \${exeDir}/../lib/genvm-lua/?.lua +data_dir: \${exeDir}/../data +signer_url: '#{signerUrl}' +signer_headers: {} +threads: 4 +blocking_threads: 16 +log_disable: '' +extra_tld: [] always_allow_hosts: - "localhost" - "127.0.0.1" diff --git a/tests/services/simulator.test.ts b/tests/services/simulator.test.ts index 70e184a3..bf7c8077 100644 --- a/tests/services/simulator.test.ts +++ b/tests/services/simulator.test.ts @@ -375,7 +375,7 @@ describe("SimulatorService - Docker Tests", () => { test("isLocalnetRunning should return true when all required containers are running", async () => { const mockContainers = [ {Id: "container1", Names: ["/genlayer-jsonrpc1"], State: "running"}, - {Id: "container2", Names: ["/genlayer-webrequest1"], State: "running"}, + {Id: "container2", Names: ["/genlayer-consensus-worker1"], State: "running"}, {Id: "container3", Names: ["/genlayer-postgres1"], State: "running"}, {Id: "container4", Names: ["/genlayer-other-container1"], State: "running"}, {Id: "container5", Names: ["/genlayer-another-container1"], State: "exited"}, @@ -389,7 +389,7 @@ describe("SimulatorService - Docker Tests", () => { test("isLocalnetRunning should return false when not all required containers are running", async () => { const mockContainers = [ {Id: "container1", Names: ["/genlayer-jsonrpc2"], State: "running"}, - {Id: "container2", Names: ["/genlayer-webrequest2"], State: "running"}, + {Id: "container2", Names: ["/genlayer-consensus-worker2"], State: "running"}, {Id: "container3", Names: ["/genlayer-postgres2"], State: "exited"}, {Id: "container4", Names: ["/genlayer-other-container2"], State: "running"}, {Id: "container5", Names: ["/unrelated-container2"], State: "running"}, @@ -743,6 +743,49 @@ describe("setupLocalhostAccess", () => { consoleWarnSpy.mockRestore(); }); + test("should mount the web override on the consensus worker", () => { + vi.mocked(fs.existsSync).mockReturnValue(true); + const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {}); + + simulatorService.setupLocalhostAccess(); + + const overrideCall = vi.mocked(fs.writeFileSync).mock.calls.find(c => + (c[0] as string).includes("docker-compose.override.yml") + ); + const content = overrideCall![1] as string; + const workerSection = content.slice(content.indexOf("consensus-worker:")); + expect(content).toContain("consensus-worker:"); + expect(workerSection).toContain("genvm-module-web.yaml:/genvm/config/genvm-module-web.yaml:ro"); + expect(workerSection).toContain("host.docker.internal:host-gateway"); + + consoleWarnSpy.mockRestore(); + }); + + test("should write a complete GenVM web module config", () => { + vi.mocked(fs.existsSync).mockReturnValue(true); + const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {}); + + simulatorService.setupLocalhostAccess(); + + const configCall = vi.mocked(fs.writeFileSync).mock.calls.find(c => + (c[0] as string).includes("genvm-module-web.yaml") + ); + expect(configCall).toBeDefined(); + const content = configCall![1] as string; + for (const field of [ + "bind_address:", + "webdriver_host:", + "lua_script_path:", + "signer_url:", + "extra_tld:", + "always_allow_hosts:", + ]) { + expect(content).toContain(field); + } + + consoleWarnSpy.mockRestore(); + }); + test("should create config-overrides directory if it does not exist", () => { vi.mocked(fs.existsSync).mockReturnValue(false); const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});