feat: opt-in chain security — per-chain validator support, rewards, consensus, and liquidity caps

🔎 Visual review of 03061a2b: explainer, review flags and prompts to ask an AI about the change

Still verifying the claims against the diff; next I'm checking the churn/ragnarok and reward-distribution code.

Summary

Allow validators to opt in to specific external chains they want to support, replacing the current all-or-nothing model. Fee income from each chain is tracked and paid only to that chain's vault members. Emission and other protocol-level allocations stay global.

Key changes

  • NodeAccount.SupportedChains: New field allowing validators to declare which chains they support. Empty = all chains (backwards compatible, no migration needed). THORChain cannot be removed. Removing the last explicit chain reverts the node to the implicit all-chains default.
  • MsgAddNodeChainSupport / MsgRemoveNodeChainSupport: Two new message types for node operators to manage their chain list. The list updates immediately; vault membership only changes at the next churn. Removal is rejected if it would drop the node below MinNodeChainSupport chains.
  • Chain-aware keygen partitioning: At churn, eligible nodes are partitioned by their supported chains set. Every partition always includes THORChain. All implicit (all-chains) nodes share one partition. Each viable partition (size ≥ MinNodeChainSupport) gets its own keygen, scoped by a new target_chains field on Keygen. If any partition cannot form a safe keygen, the whole churn is aborted. XMR stays on its dedicated monovault keygen.
  • Per-chain reward bucketing: The liquidity-fee part of the bond reward is split by chain in proportion to layer-1 pool fees and stored in Network.ChainIncome. Emission and native-pool fee shares stay in the global BondRewardRune. Outbound fees are not attributed, since they stay in the Reserve to fund gas. At churn, each chain's bucket is paid pro-rata by effective bond to that chain's active vault members. Anything left undistributed goes back to BondRewardRune. BondReward events carry a new reward_chain attribute.
  • Chain-aware consensus: Observation (txin/txout), network fee, solvency and errata handlers require a 2/3 supermajority of the chain's members (active vaults plus retiring vaults for that chain). If no members can be found, they fall back to all active validators.
  • Chain-aware slashing: At final consensus, non-signers forfeit their pro-rata share of the chain's pending income to BondRewardRune. Slash points still apply.
  • Liquidity cap: When a chain is supported by fewer than ⌈2N/3⌉ active validators, new inflows are capped at ChainLiquidityRunePerValidator × validatorsForChain. The cap applies to add-liquidity, secured-asset deposits, trade-account deposits, swaps and swap quotes. For swaps and quotes it checks only the source (credited) chain. Breaches emit chain_liquidity_cap_breach. Inflows to a chain with no active vault are rejected.
  • Auto-ragnarok: At churn, chains with no viable partition automatically ragnarok. Trading on the chain is halted (the chain itself stays live so the drain outbounds can sign), its pools are marked for ragnarok, and chain_ragnarok_initiated is emitted. Members of vaults on a ragnaroking chain cannot leave or unbond until the drain completes.
  • Bifrost integration:
    • Chain clients gain SetShouldObserveCallback, which pauses and resumes block scanning based on the node's vault membership (active, retiring and inactive vaults).
    • The scan position is kept while paused.
    • Nodes that are not in any vault keep scanning every chain.
    • A new /status/chains health endpoint shows the configured and observed chains.
  • API additions:
    • Node account: supported_chains and supports_all_chains.
    • Inbound addresses: supporting_validators, active_validator_fraction, liquidity_cap_applied and liquidity_cap_rune.
    • Network: chain_income.
    • Keygen: target_chains.
  • New events: chain_support_added, chain_support_removed, chain_liquidity_cap_breach, chain_ragnarok_initiated.

New Mimir keys

Key Default Purpose
MinNodeChainSupport 1 Minimum chains a node must declare; also the minimum number of nodes per chain partition at churn
ChainLiquidityRunePerValidator 100k RUNE Per-validator cap when chain support < 2/3

The 2/3 sub-BFT ratio is hardcoded (no longer a tunable mimir).

Regression tests

  • opt-in-chain-security/happy-path: supported_chains and inbound_addresses queries, idempotent opt-in, BTC swap through the chain-scoped vault
  • opt-in-chain-security/liquidity-cap: support below 2/3; add-liquidity, secured deposit and trade deposit are rejected over the cap; withdrawals still succeed (swap-side cap is covered by unit tests)
  • opt-in-chain-security/chain-ragnarok: chain support below MinNodeChainSupport triggers auto-ragnarok; MsgLeave is blocked until the drain completes
  • Existing regression exports regenerated for the new chain_income network field and the per-chain bond reward split

🤖 Generated with Claude Code

Edited by Huginn Ai

Merge request reports

Loading
Loading