Skip to content

3.x.x: require a pool fee in every settlement mode and default a fresh setup to a 0-bps fee (#535) - #568

Merged
djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b535-pool-fee-mandatory
Sep 29, 2026
Merged

djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b535-pool-fee-mandatory

Conversation

@djh58

@djh58 djh58 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Closes #535

Upgrade notes

  • A cluster that runs without a pool fee must enable one with policy-transition before upgrading. After this PR its frontends refuse to start, check-config and self-check fail, and make doctor fails. docs/prism-ledger-ops.md gives the target file. A 0-bps fee is enough.
  • Production refuses the lab recipient that .env.example now ships (PRISM_POOL_FEE_P2MR_PROGRAM_HEX=dfee…). A real pool names its own address or program.
  • qbit-tools needs no change. Its role already renders PRISM_POOL_FEE_ENABLED=1 with an address, and compose.yaml adds no fee or recipient default that could collide with it.

Problem

Without a pool fee, sub-floor dust cannot be settled. apply_payout_policy pays only balances that reach the payout floor, so once any positive balance sits below it, the paid balances fall short of the coinbase. Only a pool fee, at any rate, can take the difference (add_swept_dust_to_pool_fee). Without one, every work build fails with PayoutExceedsCandidateBalance and mining stops.

#534 refused this only for CTV settlement. Direct settlement applies the same policy, and it was the default in .env.example, compose.yaml and the load harness.

This PR takes option 1 from the issue: a pool fee is required in every settlement mode, and 0 bps is allowed. apply_payout_policy is unchanged.

1. The refusal, in both modes

Config::ensure_pool_fee_settles_dust now refuses a pool without a fee whatever PRISM_CTV_SETTLEMENT_ENABLED says. The message names the mode, the setting and the reason:

direct settlement (PRISM_CTV_SETTLEMENT_ENABLED=0) requires PRISM_POOL_FEE_ENABLED=1 (PRISM_POOL_FEE_BPS=0 is allowed) with a pool fee recipient: without a pool fee, sub-floor dust cannot be settled, so the first positive balance below the payout floor fails every work build and stops mining

Entry point Behaviour
run refuses before any listener or database connection, in both modes
check-config fails in both modes
self-check fails in both modes, report ok: false
policy-transition target refused in both modes
policy-transition current side, operator tools still read a fee-less configuration, so policy-transition can enable a fee on a cluster that ran without one
make doctor (check-env.sh) mirrors the rule in both modes, in its own check_pool_fee_config. With the fee enabled it also requires a recipient, and in production it refuses the lab program when no address replaces it. Process-environment overrides of the address and program apply, as for the flag.

Two existing messages now say what to set:

  • "configure exactly one pool fee address or P2MR program" names the settings;
  • "pool fee configuration requires PRISM_POOL_FEE_ENABLED=1" adds that every settlement mode requires it.

2. Defaults: a fresh setup is valid, and deployments are unaffected

compose.yaml keeps its fee-off defaults and sets no recipient. A deployment enables the fee and names exactly one recipient. One that names neither gets the clear refusal at startup, while every tool and policy-transition's current side still read its configuration.

  • Why not default the flag to 1: compose cannot also supply a recipient. An enabled flag with no recipient fails inside Config::from_env, so every tool would fail, including the current side of policy-transition, the repair path. This came out of review; the first commit had :-1.
  • The same reasoning keeps PRISM_POOL_FEE_BPS empty by default rather than 0. The server reads an unset rate as 0 bps.
  • Why no recipient default: the qbit-tools deploy role runs compose.yaml alone. It renders PRISM_POOL_FEE_ADDRESS and omits the program line. A program default here would give mainnet both an address and a program, and every server would refuse "configure exactly one pool fee address or P2MR program". Compose interpolation cannot express "default only when the address is unset".
  • qbit-tools needs no change. The role already sets PRISM_POOL_FEE_ENABLED=1 with its own address.

.env.example carries the lab recipient. A fresh setup copies it to .env.

  • It sets PRISM_POOL_FEE_ENABLED=1, PRISM_POOL_FEE_BPS=0, PRISM_POOL_FEE_P2MR_PROGRAM_HEX=dfee…dfee and PRISM_POOL_FEE_RECIPIENT_ID=dev-pool-fee.
  • The program is synthetic, and nobody holds a key for it. It is exported as config::DEVELOPMENT_POOL_FEE_P2MR_PROGRAM_HEX.
  • Production refuses it (mainnet, or QBIT_PRODUCTION / QBIT_TOOLS_PRODUCTION). The check compares the decoded bytes, so a change of case does not get past it.
  • The file tells operators how to set their own recipient. Either set PRISM_POOL_FEE_ADDRESS and leave the program and recipient ID empty, or set their own program and a recipient ID. It must be exactly one of the two.

A cluster that ran without a fee now refuses to start until it enables one offline with policy-transition. docs/prism-ledger-ops.md gives the target file.

3. Load harness

Every frontend is launched with the fee on:

  • apply_pool_fee no longer returns early at 0 bps;
  • frontend_environment no longer sets PRISM_POOL_FEE_ENABLED=0;
  • the side report always records pool_fee_address.

Legacy presets keep --pool-fee-bps 0, and no preset file changes.

The legacy presets' results reproduce.

  • A 0-bps fee adds no coinbase output until dust must be swept. zero_bps_pool_fee_is_audited_without_onchain_fee_output already pins that.
  • At the point where dust must be swept, a fee-off frontend would have stalled. Any run that completed fee-off therefore builds the same outputs at 0 bps.
  • Every legacy preset schedules no blocks, so its results carry no payouts at all.

Measured on the pr-smoke preset (then named smoke; seed 1, debug server): c99abdd8 with the fee off, against this branch on the same base at 0 bps. #540 and #559, rebased in afterwards, add a live test and rename presets; load_smoke passes on the final tree.

Run committed rows rejections offered (warm-up, churn)
base, 5 runs 984 ×4, 983 ×1 none ×4, one stale-job (expected) ×1 390/594 ×4, 389/594 ×1
branch, 3 runs 984 ×1, 983 ×2 none ×1, one stale-job (expected) ×2 390/594 ×1, 389/594 ×2

Both builds produce the same outcome set. The single stale-job is a pre-existing race between a warm-up share and a tip change, which base hits too.

Every other field that differs between base and branch also differs between two base runs: timings, latencies and rates. The exceptions are the fee's own traces:

  • the frontend environment's fee keys;
  • topology.pool_fee_address;
  • one more validateaddress call, as the frontend validates its fee address at startup.

Tests

Test Kind What it proves
config::tests::settlement_without_a_pool_fee_is_refused_in_every_mode / …_with_any_pool_fee_is_accepted_in_every_mode (0 and 200 bps) unit the guard, per mode, and its message
pool_fee_guard (8 tests) CLI subprocess, no DB check-config, run and self-check refuse either mode, with the flag unset, 0 or CTV=0 implicit; they accept 0 and 200 bps; a transition target is refused in both modes but a fee-less current configuration is not; production refuses the lab program (in either case) but not a pool's own; .env.example itself passes check-config in both modes, and its recipient instructions hold: an address beside the lab program is refused, while an address with the program cleared is accepted; policy-transition from compose's fee-off defaults (every fee setting empty, the flag unset or 0, both modes) reads the current configuration and accepts a 0-bps target
test_settlement_requires_a_pool_fee_in_every_mode_before_docker_check, test_env_example_defaults_enable_a_pool_fee_in_every_mode, test_settlement_accepts_any_enabled_pool_fee_in_every_mode, test_an_enabled_pool_fee_needs_a_recipient, test_production_rejects_the_lab_pool_fee_recipient Python doctor doctor refusal per mode; the .env.example defaults pass; a missing recipient is refused; production refuses the lab program without an address, but not with one, not a pool's own program, and not in lab mode
test_role_rendered_compose_names_exactly_one_pool_fee_recipient Python, Docker renders compose.yaml alone with an address-only env, as the deploy role does: fee on, the address, an empty program, in both modes; a bare env gets compose's fee-off default and no recipient
realism realism_presets_run_mainnets_fee_and_legacy_ones_do_not unit apply_pool_fee enables the fee at 0 and at 200 bps

None of the new tests needs PostgreSQL or qbitd, so none is gated, and test/prism-gated-tests.txt is unchanged. No gated test was added or renamed.

Mutants (each applied, rebuilt and run)

Mutant Caught by
guard back to CTV-only (#534's behaviour) config unit test, and 4 of 7 pool_fee_guard tests
production check on the lab program removed production_refuses_the_development_pool_fee_recipient
harness skips the fee at 0 bps again realism_presets_run_mainnets_fee_and_legacy_ones_do_not
doctor recipient check removed test_an_enabled_pool_fee_needs_a_recipient
doctor production lab-program check removed test_production_rejects_the_lab_pool_fee_recipient
policy-transition also refuses a fee-less current configuration both pool_fee_guard transition tests
doctor refuses only under CTV 3 subtests of test_settlement_requires_a_pool_fee_in_every_mode_before_docker_check

Fixtures changed (additive; each launched a fee-less server)

  • New tests/support/pool_fee.rs:
    • ZERO_BPS_POOL_FEE;
    • default_pool_fee, which yields to a case that configures its own PRISM_POOL_FEE_*, since an address beside the default program would be refused.
  • It is used by config_cli, self_check_cli, stratum_protocol, api_config, audit_completeness, work_refresh_metric, stratum_restart_bind and candidate_storm_restart.
  • live_regtest: the 0-bps default now covers every server, not only CTV ones. The in-process coordinator in live_highdiff pins the same policy through live_payout_policy(); otherwise its fingerprint differs from the servers'.
  • fatal_state: the one-shot-tools case pins a 0-bps fee on its cluster and gives it to every tool.

Local verification

  • cargo test -p qbit-prism-server --lib: 575 passed.
  • Integration suites, PRISM_TEST_REQUIRE_INTEGRATION=1, PostgreSQL 16:
    • ledger_postgres: 183 passed;
    • config_cli 21, api_config 5, self_check_cli 5, audit_completeness 3, work_refresh_metric 1, stratum_restart_bind 5, stratum_protocol 39, candidate_storm_restart 19, healthcheck_cli 2, signing_transition 14 and public_database_config 5 all passed. public_database_config ran under test/prism-native-tests.sh for its SCRAM cluster.
  • live_regtest against a real regtest node: every case passes; in the last full run on the final tree, 5 cases failed only because another job deleted the borrowed qbitd binary mid-run and all 5 passed on rerun; real_async_failover_mid_landing_loses_only_the_replication_gap failed once under host load (lease-bound 120 s landing wait) and passed 3 times alone. The opt-in nightly dense soak also passes, at PRISM_DENSE_SOAK_SECONDS=120.
  • qbit-prism-load: load_smoke (gated), realism 21, harness 136 and churn 6 all passed.
  • cargo clippy -p qbit-prism-server -p qbit-prism-load --all-targets -D warnings and cargo fmt --check are clean.
  • Python: the doctor, settings, public-credentials, Makefile, compose-profile, container-hardening and docs suites pass. check_prism_settings.py, check_gate_env_reads.py and check_deleted_test_map.py pass.
  • test_mainnet_compose_contract needs Docker, which the local host does not have, so CI runs it.

Per-PR CI runtime added

  • rust-tests: pool_fee_guard adds about 15 s wall-clock. The policy-transition case now waits out the closed-port database pool timeout once per mode. The compose-default transition cases run concurrently inside that window, so the test binary's wall-clock is unchanged at about 30 s. The other new cases are sub-second subprocesses.
  • prism-native-postgres / live: no new gated tests. Fixtures only gain environment variables.
  • Python and compose checks: a few seconds for 5 doctor tests and 3 compose renders.

🤖 Generated with Claude Code

…h setup to a 0-bps fee (#535)

Without a pool fee, apply_payout_policy cannot settle sub-floor dust, so
the first positive balance below the payout floor fails every work build
and mining stops. #534 refused this only for CTV settlement; direct
settlement applies the same policy and was the default in .env.example,
compose.yaml and the load harness.

Config::ensure_pool_fee_settles_dust now refuses a pool without a fee in
both modes, naming the mode, the setting and the reason. run,
check-config, self-check and a policy-transition target refuse it; the
current side of a transition still reads a fee-less configuration, so
policy-transition remains the way to enable a fee on a cluster that ran
without one. make doctor mirrors the rule. PRISM_POOL_FEE_BPS=0 is still
allowed and pays nothing until dust must be swept. apply_payout_policy is
unchanged.

Defaults: compose.yaml enables the fee (rate unset, so 0 bps) but sets no
recipient, because the deploy role runs compose.yaml alone and renders an
address without a program; a recipient default there would put both
beside each other and every server would refuse to start. .env.example,
which a fresh setup copies to .env, enables a 0-bps fee to a synthetic lab
program (recipient dev-pool-fee) that nobody holds a key for, and
production refuses that program. The "exactly one address or program" and
"requires PRISM_POOL_FEE_ENABLED=1" messages now say what to set.

The load harness launches every frontend with the fee on; legacy presets
run it at 0 bps. A 0-bps fee adds no output until dust must be swept,
where a fee-off frontend would have stalled, so a run that completed
fee-off reproduces its results at 0 bps.

Tests: config unit tests and the pool_fee_guard CLI tests cover refusal
and acceptance in both modes (0 and 200 bps), the production refusal of
the lab program, and .env.example as a valid configuration in both modes;
doctor tests cover both modes and the .env.example defaults; the mainnet
compose contract renders compose.yaml as the deploy role does and checks
it names exactly one recipient. Every test fixture that launched a
fee-less server now runs a 0-bps fee.

Closes #535

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58
djh58 requested a review from kiwidream September 28, 2026 21:07
@djh58

djh58 commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

… recipient in make doctor (#535 review)

Review of the first commit found that compose.yaml's new
PRISM_POOL_FEE_ENABLED default of 1, with no recipient default, broke a
deployment that never set the flag. Such a deployment got the fee enabled
with an empty address and an empty program, so Config::from_env failed.
Every tool that reads the configuration failed with it, including the
current side of policy-transition, which is the documented way to enable
a fee. Compose cannot supply a recipient, so the default goes back to 0:
that deployment now gets the clear startup refusal, and policy-transition
still reads it. .env.example stays the valid fresh setup.

make doctor now also refuses an enabled fee with no recipient. In
production it refuses .env.example's lab program where no address replaces
it; an address beside the sourced lab program is left to the server, which
sees only what Compose passes. As with the flag, process-environment
overrides of the address and program apply.

Tests: policy-transition from compose's fee-off defaults (every fee
setting empty, the flag unset or 0, both modes) reads the current
configuration and accepts a 0-bps target; doctor tests for the missing
recipient and the production lab program. The 0-bps fixture now lives
only in tests/support/pool_fee.rs, which live_regtest and fatal_state
reuse.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58

djh58 commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5e5d38e. Configure here.

@djh58

djh58 commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

Deep-review ledger (head 5e5d38ea, CI green)

This PR is high-stakes: it changes pool-fee and settlement configuration.

@kiwidream, two things to check:

  1. The compose default was reversed after review. The first commit set PRISM_POOL_FEE_ENABLED:-1 in compose.yaml, with no recipient default. A deployment that never set the flag then got the fee enabled with no address and no program. Config::from_env failed for every tool, including the current side of policy-transition, which is the documented way to enable a fee. 5e5d38ea restores :-0. Such a deployment now gets the clear startup refusal and can still be migrated. .env.example remains the valid fresh setup.
  2. Migration test: pool_fee_guard::policy_transition_enables_a_fee_on_compose_default_configurations covers it. It takes compose's fee-off defaults (every fee setting empty, the flag unset or 0, both settlement modes), shows check-config refuses them, and shows policy-transition reads them and accepts a 0-bps target.
Finding Source Disposition
The compose :-1 default with no recipient made a flag-unset deployment unreadable by every tool, policy-transition included (compose.yaml) code-review fixed in 5e5d38ea: reverted to :-0, plus the migration test above
make doctor passed a config with no recipient, or with the lab program in production (scripts/check-env.sh) code-review fixed in 5e5d38ea: an enabled fee needs a recipient; production refuses the lab program where no address replaces it; process-environment overrides of the address and program apply
The doctor read an empty PRISM_POOL_FEE_ENABLED as 0, while compose's :-1 read it as 1 adversarial fixed in 5e5d38ea: resolved by the :-0 revert; both now read it as 0
The 0-bps fee fixture was defined in three places (support/pool_fee.rs, live_regtest, fatal_state) quality fixed in 5e5d38ea: live_regtest and fatal_state reuse tests/support/pool_fee.rs
Cursor Bugbot on db75bbab and on 5e5d38ea bugbot no issues

Every new check was mutation-tested. Each mutant was caught:

  • the guard back to CTV-only;
  • no production refusal of the lab program;
  • the harness skipping the fee at 0 bps;
  • the doctor refusing only under CTV;
  • the doctor's recipient check removed;
  • the doctor's production lab check removed;
  • policy-transition also refusing a fee-less current configuration.

The PR body has the full results.

@djh58
djh58 merged commit 65c9751 into 3.x.x Sep 29, 2026
22 checks passed
Anatolie added a commit that referenced this pull request Sep 30, 2026
…uilds from #536 to #568 launched (#511)

From 0c8842e (#536) up to 65c9751 (#568) the harness has
--pool-fee-bps but leaves the fee off at 0, so the comparison FAILed a
base in that range at every throughput preset. A fee-off frontend now
satisfies a pinned 0, as legacy-flags.json already accepts; a fee off
at a nonzero pin or an enabled fee at another rate still fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant