Skip to content

Conversation

@mise42
Copy link
Contributor

@mise42 mise42 commented Dec 17, 2025

Description

This is PR 1 of a 6-PR series to upstream the PVQ system. See tracking issue: #8251.

This PR introduces the foundation layer for PVQ (PolkaVM Query).

What's included

This PR adds three new foundational crates:

  • pvq-primitives (~50 lines): Core types including PvqResult, PvqResponse, and PvqError with both std and no_std support
  • pvq-runtime-api (~35 lines): Substrate runtime API definition with PvqApi trait providing execute_query and metadata methods
  • pvq-executor (~400-500 lines): PolkaVM execution wrapper including PvqExecutor, PvqExecutorContext trait for registering host functions, program execution with gas limits, and error handling

Integration

For Runtime Developers:

These crates provide the foundation infrastructure but are not yet ready for production use. No action is required from downstream teams at this time.

The complete PVQ system will be available after the all PRs are merged.

Once the full system is available, runtime developers can:

  1. Add pvq-executor and extensions to their runtime dependencies
  2. Implement the PvqApi runtime API
  3. Register desired extensions (core, fungibles, swap, or custom)
  4. Expose queryable functionality to client applications

For Node Operators & Client Developers:

No changes required. This is purely additive runtime infrastructure.

Review Notes

Architecture Overview

See tracking issue: #8251

Implementation Details

1. pvq-primitives

  • Minimal core types used across all PVQ components
  • no_std compatible with optional std feature
  • PvqResult encapsulates success/failure with structured errors
  • SCALE codec compatible for runtime/client communication

2. pvq-runtime-api

  • Standard Substrate sp_api::decl_runtime_apis! macro
  • execute_query: Takes program bytes, arguments, and gas limit
  • metadata: Returns available extensions and their capabilities
  • Designed to be implemented by any runtime wanting PVQ support

3. pvq-executor

  • Wraps polkavm for program execution
  • PvqExecutorContext trait allows runtimes to inject host functions
  • Gas metering prevents infinite loops and resource exhaustion
  • Proper error propagation from PolkaVM to Substrate types
  • Memory-safe execution environment

Testing

Future PRs

This foundation enables:

  • PR 2: Procedural macros for easy extension definition
  • PR 3-4: Concrete extensions (core, fungibles, swap)
  • PR 5: Guest-side SDK for writing PVQ programs
  • PR 6: Real-world integration example

This commit introduces three new crates: `pvq-executor`, `pvq-primitives`, and `pvq-runtime-api`. The `pvq-executor` crate provides functionality to execute PVQ programs on top of PolkaVM, including context management and error handling. The `pvq-primitives` crate defines shared types for PVQ execution, while the `pvq-runtime-api` crate exposes a runtime API for executing PVQ programs and retrieving metadata. Additionally, updates to `Cargo.toml` and `Cargo.lock` reflect the inclusion of these new crates in the workspace.

- Added `pvq-executor` crate with execution logic and context management.
- Added `pvq-primitives` crate for shared types.
- Added `pvq-runtime-api` crate for runtime API definitions.
- Updated workspace configuration in `Cargo.toml` and dependencies in `Cargo.lock`.
This commit deletes the `pvq-executor` and `pvq-runtime-api` crates, along with their associated README files. The `pvq-executor` crate, which provided functionality for executing PVQ programs on PolkaVM, and the `pvq-runtime-api` crate, which defined the runtime API for PVQ, have been removed from the project. Additionally, the `pvq-primitives` crate remains intact, as it defines shared types for PVQ execution.

- Deleted `pvq-executor` crate and its README.
- Deleted `pvq-runtime-api` crate and its README.
- Retained `pvq-primitives` crate for shared types.
@github-actions
Copy link
Contributor

Command "fmt" has failed ❌! See logs here

@paritytech-cmd-bot-polkadot-sdk paritytech-cmd-bot-polkadot-sdk bot added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Dec 17, 2025
@mise42
Copy link
Contributor Author

mise42 commented Dec 17, 2025

/cmd fmt

@mise42 mise42 marked this pull request as ready for review December 17, 2025 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T1-FRAME This PR/Issue is related to core FRAME, the framework.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant