Skip to content
KontorProtocolPublic

About

Kontor Protocol indexer

Resources

Security policy

Stars

7 stars

Watchers

2 watching

Forks

Repository files navigation

Kontor

CI License

⚠️ WARNING: This code is experimental and pre-release. Use at your own risk.

This repo contains the indexer for the Kontor Protocol, comprised of:

  • Bitcoin follower: Reconciles streams of block data from Bitcoin's ZMQ socket and RPC API.
  • Bitcoin block parser: Extracts Kontor Instructions from Bitcoin transactions and converts them into Operations.
  • Reactor (event loop): Synchronizes Operations and handles them.
  • WASM Component Model-based Runtime: Deterministically runs Call Operations on smart-contract WASM components.
  • HTTP API: Exposes indexer data, supports "view" (read-only contract call) functionality, and provides endpoints for the composition of Bitcoin transactions with embedded Kontor Instructions.
  • WebSocket API: Emits contract call results enabling applications to build and maintain their own derived state by reacting to incremental updates and deliver a real-time experience to end-users.

Workspaces

core

  • indexer: Builds into the kontor binary, the primary executable for the Kontor Protocol.
  • stdlib and testlib: Crates used when developing contracts.
  • macros: Contains the procedural macros used in the Sigil smart contract framework.

native-contracts

Contains the contracts native to Kontor, providing the core functionality of the protocol.

test-contracts

Contains a variety of contracts used to test the indexer.

Development

Health probes

GET /healthz/live is process liveness. GET /healthz/ready returns 503 until the reactor is initialized and indexed state is within one block of a recent, non-IBD Bitcoin observation on the configured network. Observations expire after 30 seconds; successful existing getblockchaininfo calls refresh them across client clones. Probes read local state and send no additional RPCs. The response includes bitcoin_height and bitcoin_synced and is marked no-store.

Use readiness, not liveness, to withdraw traffic during startup/replay or shutdown. A failed readiness check must not restart a healthy replay. Public request draining and protocol/consensus behavior are unchanged. This compares local progress with the configured Bitcoin backend; it is not proof of external network freshness, checkpoint agreement or validator signing eligibility.

For deployment, both Kubernetes readiness and load-balancer HTTP health checks must use /healthz/ready. Older pinned images do not implement this contract; do not change their probe path before a compatible image and isolated recovery rehearsal pass. This source change alone does not upgrade retained production.

GET /api/protocol supplies exact checkpoint and protocol context for comparing nodes at a common completed position. GET /metrics supplies cached operational progress, freshness, and managed consensus metrics. See Node observations and metrics for comparison rules, metric semantics, and example queries.

Install build dependencies:

MacOS:

brew install cmake pkgconf libevent boost zmq brotli

Ubuntu:

sudo apt install cmake pkgconf libevent-dev libboost-all-dev libzmq3-dev brotli

If rust tooling is not installed follow steps from rust-lang.org

Host builds use Rust 1.100.0, pinned in CI and the linked-node builder. Install it with rustup toolchain install 1.100.0 --component rustfmt,clippy,llvm-tools-preview. For local Cargo commands, select it with RUSTUP_TOOLCHAIN=1.100.0 (including when using the shared local-build helper).

Reproducible contract and SDK component generation also uses Rust 1.100.0, through the published image pinned in tools/build.json. Keep the host and reproducible build compiler versions aligned when upgrading Rust, regenerate the outputs, and verify them with ./tools/kontor build --check. Host selection stays explicit so local toolchain overrides cannot silently replace the compiler pinned inside the build container.

Add wasm compile target:

rustup target add wasm32-unknown-unknown

Install cargo components

cargo install cargo-expand wasm-opt

Compile Bitcoin

A local copy of bitcoind is required to run all tests successfully.

Install dependencies for compiling Bitcoin:

Clone Bitcoin:

git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
git checkout v30.0

Compile Bitcoin:

cmake -B build -DENABLE_WALLET=OFF -DENABLE_IPC=OFF -DWITH_ZMQ=ON
cmake --build build

Compiled binaries including bitcoind are located in build/bin. This directory must be on your $PATH when running tests.

Run Tests

git clone https://github.com/KontorProtocol/Kontor.git
cd Kontor/core
cargo test --workspace

Some machines may not have the resources to compile all tests concurrently. In these cases, use the --jobs flag or the CARGO_BUILD_JOBS environment variable to limit the number of simultaneous compilation jobs.

Long running tests are ignored by default. To run them, use the --ignored or --include-ignored flags.

Docker

Build the Alpine-based image:

docker build -t kontor-indexer .

Run with environment variables:

docker run -d \
  -p 9333:9333 \
  -v kontor-data:/data \
  -e BITCOIN_RPC_URL=http://your-node:8332 \
  -e BITCOIN_RPC_USER=your-username \
  -e BITCOIN_RPC_PASSWORD=your-password \
  -e ZMQ_ADDRESS=tcp://your-node:28332 \
  -e NETWORK=bitcoin \
  kontor-indexer

Or pass CLI arguments directly:

docker run -d -p 9333:9333 -v kontor-data:/data kontor-indexer \
  --bitcoin-rpc-url http://your-node:8332 \
  --bitcoin-rpc-user your-username \
  --bitcoin-rpc-password your-password \
  --network testnet \
  --api-port 9333

Available networks: bitcoin, testnet, testnet4, signet, regtest

About

Kontor Protocol indexer

Resources

Security policy

Stars

7 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages