datahaven/operator
Steve Degosserie 9bca5c467b
fix: Use block authorship as liveness indicator for validator rewards (#367)
## Summary

Use block authorship as direct proof of liveness for the 30% liveness
component of validator rewards. Validators who author at least one block
in a session are considered online and receive the full liveness bonus.

## Problem

The rewards pallet was checking validator liveness via ImOnline
**after** the session had rotated - at which point ImOnline had already
cleared its `AuthoredBlocks` storage. This caused all validators to
appear offline, resulting in only ~70% of expected rewards being
allocated (missing the 30% liveness bonus).

## Solution

Use **block authorship as the proxy for liveness**:

- A validator who authored at least one block is definitively online
- Liveness is determined directly in `award_session_performance_points`
via `blocks_authored > 0`
- No dependency on external liveness checks (ImOnline)

### Rewards Formula

- **60%** Block authorship (proportional to blocks produced)
- **30%** Liveness (full bonus if authored ≥1 block, zero otherwise)
- **10%** Base reward (for being in the validator set)

### Files Changed

- `pallets/external-validators-rewards/src/lib.rs` - Core logic changes
- `pallets/external-validators-rewards/src/mock.rs` - Test mock updates
- `pallets/external-validators-rewards/src/tests.rs` - Test updates
- `runtime/{mainnet,testnet,stagenet}/src/configs/mod.rs` - Config
updates

## Testing

- All 76 pallet tests pass
- Local testing should show correct points per session (e.g., 3200
points for 2 validators with 10 blocks)

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2026-01-07 13:41:40 +00:00
..
benchmarking fix: pallet collective weights aliases (#337) 2025-12-05 14:22:52 +01:00
node feat: add feature to build binary with postgres bundled (#346) 2026-01-06 13:13:25 +00:00
pallets fix: Use block authorship as liveness indicator for validator rewards (#367) 2026-01-07 13:41:40 +00:00
precompiles feat: Add datahaven native transfer precompile (#309) 2025-12-02 13:57:40 +01:00
primitives fix: 🛡️ Check origin for validator set messages (#343) 2025-12-15 14:11:08 +01:00
runtime fix: Use block authorship as liveness indicator for validator rewards (#367) 2026-01-07 13:41:40 +00:00
scripts feat: add feature to build binary with postgres bundled (#346) 2026-01-06 13:13:25 +00:00
.dockerignore refactor: 🐳 Improve docker caching (again) (#86) 2025-05-27 16:14:15 +00:00
.gitignore test: Native token transfer e2e tests (#120) 2025-08-22 18:27:14 +02:00
Cargo.lock fix: Use block authorship as liveness indicator for validator rewards (#367) 2026-01-07 13:41:40 +00:00
Cargo.toml fix: Use block authorship as liveness indicator for validator rewards (#367) 2026-01-07 13:41:40 +00:00
DOCKER-COMPOSE.md feat: Add Docker Compose setup for local DataHaven network (#314) 2025-11-22 14:07:46 +01:00
docker-compose.yml feat: Add Docker Compose setup for local DataHaven network (#314) 2025-11-22 14:07:46 +01:00
Dockerfile feat: Add Docker Compose setup for local DataHaven network (#314) 2025-11-22 14:07:46 +01:00
README.md doc: Fix fast-runtime documentation (#311) 2025-11-19 17:23:10 +00:00
rust-toolchain.toml build: ⬆️ Bump Rust version to 1.90.0 (#362) 2025-12-19 08:43:01 +01:00

DataHaven Operator (Substrate Node) 🫎

The DataHaven operator is a Substrate-based blockchain node that serves as an EigenLayer AVS operator. It combines Substrate's modular framework with EVM compatibility (via Frontier) and cross-chain capabilities (via Snowbridge).

Overview

Built on the polkadot-sdk-solochain-template, this node implements:

  • EVM Compatibility: Full Ethereum compatibility via Frontier pallets
  • EigenLayer Integration: Operator registration and management via AVS contracts
  • External Validators: Dynamic validator set controlled by EigenLayer registry
  • Cross-chain Communication: Token and message passing via Snowbridge
  • Rewards System: Performance-based validator rewards from Ethereum

Project Structure

operator/
├── node/                          # Node implementation
│   ├── src/
│   │   ├── chain_spec.rs         # Chain specification & genesis config
│   │   ├── cli.rs                # CLI interface
│   │   ├── command.rs            # Command handlers
│   │   ├── rpc.rs                # RPC configuration
│   │   └── service.rs            # Node service setup
├── pallets/                       # Custom pallets
│   ├── external-validators/      # EigenLayer validator set management
│   ├── native-transfer/          # Cross-chain token transfers
│   └── rewards/                   # Validator rewards distribution
├── runtime/                       # Runtime configurations
│   ├── mainnet/                  # Mainnet runtime
│   ├── stagenet/                 # Stagenet runtime
│   └── testnet/                  # Testnet runtime (with fast-runtime feature)
└── scripts/                       # Utility scripts
    └── run-benchmarks.sh         # Runtime benchmarking automation

Prerequisites

Building

Development Build (Fast Runtime)

For local development with shorter epochs and eras:

cargo build --release --features fast-runtime

This switches runtime parameters to the fast variants (1-minute epochs, 3 sessions per era) while the block time remains 6 seconds.

Production Build

For production or stagenet deployments:

cargo build --release

Running Tests

# Run all tests
cargo test

# Run tests for specific pallet
cargo test -p pallet-external-validators

# Run with output
cargo test -- --nocapture

Code Quality

# Format code
cargo fmt

# Lint with clippy
cargo clippy --all-targets --all-features

Benchmarking

DataHaven uses runtime benchmarking to generate accurate weight calculations for all pallets. The benchmarking process is automated using frame-omni-bencher.

Requirements

  • Latest Rust stable version
  • frame-omni-bencher: Install with cargo install frame-omni-bencher --profile=production

Running Benchmarks

Execute from the operator directory:

# Benchmark all pallets for testnet runtime (default)
./scripts/run-benchmarks.sh

# Benchmark specific runtime
./scripts/run-benchmarks.sh mainnet

# Custom steps and repetitions
./scripts/run-benchmarks.sh testnet 100 50

The script will:

  1. Discover all available pallets
  2. Build runtime WASM with runtime-benchmarks feature
  3. Generate weight files in runtime/{runtime}/src/weights/
  4. Provide summary of results

Parameters:

  • runtime: Runtime to benchmark (testnet, stagenet, mainnet). Default: testnet
  • steps: Number of steps. Default: 50
  • repeat: Number of repetitions. Default: 20

Zombienet Testing

Zombienet provides local multi-validator network testing.

Setup

  1. Install Zombienet:

    # Download binary from releases
    # Or install via npm
    npm install -g @zombienet/cli
    
  2. Spawn local network with four validators:

    zombienet -p native spawn test/config/zombie-datahaven-local.toml
    

This launches a local solochain with BABE consensus for testing validator coordination.

Docker Image

Build local Docker image for testing:

cd ../test
bun build:docker:operator

This creates datahavenxyz/datahaven:local using optimized caching:

  • sccache: Rust build caching
  • cargo-chef: Dependency layer caching
  • BuildKit cache mounts: External cache restoration

Type Generation

After runtime changes, regenerate Polkadot-API TypeScript types:

cd ../test
bun generate:types           # Production runtime
bun generate:types:fast      # Fast runtime (development)

Integration Testing

For full network integration tests with Ethereum, Snowbridge, and contracts:

cd ../test
bun cli launch               # Interactive launcher
bun test:e2e                 # Run E2E test suite

See the test directory for comprehensive testing documentation.

Custom Pallets

External Validators

Manages the dynamic validator set based on EigenLayer operator registry. Syncs validator changes from Ethereum to the Substrate consensus layer.

Location: pallets/external-validators/

Native Transfer

Handles cross-chain token transfers between Ethereum and DataHaven via Snowbridge messaging.

Location: pallets/native-transfer/

Rewards

Distributes performance-based rewards to validators, processing reward messages from the Ethereum RewardsRegistry contract.

Location: pallets/rewards/

Each pallet includes its own tests and benchmarks. See pallet-specific README files for details.