Skip to main content

Responsibilities and boundaries

Python Executor runs user functions inside the CPython host process. It receives function execution work from the Worker and routes suspended backend operations through the host bridge. EVM queries carry the chain and block supplied by the function. Use Write EVM data functions for the programming workflow. This page describes the execution component.

Code location

Core types and interfaces

python/blockx_runtime/host.py defines the Python-facing host bridge. Capability names available to audited code are maintained in python/blockx_audit/tables.py.

Data flow / execution flow

  1. The Worker dispatches a function and its arguments to the Executor host.
  2. The runtime loads the function definition and invokes its entry point.
  3. State reads and contract queries pass through NodeRPCBridgeProvider with chain and request parameters.
  4. Worker IO serves the backend request and the host resumes the computation.
  5. The function returns its output; the Worker collects it for the selected Writer Plugin.
The function’s EVM object supplies the read context. A task’s function-code snapshot fixes definitions separately from the block used by data reads.

Function loading and entry resolution

ModuleRegistry caches compiled source by digest and maintains per-task namespaces. It can fetch missing source through host.fetch_source. Releasing a task drops its namespaces; function identity and version selection are described in Function Code View. resolve_entry_name in python/blockx_audit/tables.py supplies the shared selection rule. The runtime applies it to entrySelector:
  1. Use the selector’s final segment when it names an eligible top-level function.
  2. Otherwise use _, defined as a function or as an alias to a top-level function.
  3. Otherwise use the first eligible public top-level function in source order.
  4. If none exists, resolve to _ and report the missing callable during loading.
Names beginning with __ and dangerous builtin names cannot be selected by the named-entry rule. The public fallback skips names beginning with _ and dangerous builtin names. Audit binding checks reject an alias that rebinds an existing _ definition.

Return-value serialization

python/blockx_runtime/wire.py converts Python values before the host packs them into a value program. The Worker converts that program to the JSON carried in results. Keep EVM uint256 values as Python integers through the computation. Consumers must also decode JSON integers without precision loss. Wire conversion does not grant audited functions additional imports or capabilities.

State and lifecycle

The Worker manages Executor host processes and their connections. Runtime initialization installs bridges and prepares function execution. Function source loading and version identity are coordinated with Function Code View.

Suspension and resume invariants

The native host keeps multiple calls resident on one interpreter thread and runs one coroutine at a time. Preserve these invariants when changing scheduling or bridges: The scheduler tracks CS_QUEUED, CS_RUNNABLE, CS_RUNNING, CS_WAIT_IO, CS_WAIT_FUNCTION_CODE, CS_WAIT_SUBCALL, CS_WAIT_SLEEP, and CS_DONE. Cancellation and deadline decisions belong to the host scheduler; the runtime encodes their terminal outcomes. An EVM backend response resumes the waiting function with its existing call context.

Configuration

The host embeds CPython 3.14 or later. Follow the Quickstart to build it and supply the virtual environment’s package directory.

Extension points

Add function-visible capabilities through the runtime bridge and the owning backend adapter. Update audit capability tables when changing the allowed function interface. Verify that chain and block context reach the backend request unchanged.

Testing

The following tests in the BlockX repository cover bridge integration, entry selection, module namespaces, and return-value conversion, using host doubles where needed:
Host and process tests also cover the native execution boundary. Their shared environment setup is in internal/testutil/pyhost.go. Design reference in the BlockX repository: docs/specs/function-code-python-whitelist.md.