Skip to content

Debit a spent block reward from the scanner address balance (phantom genesis premint holder) - #2181

Open
nullPointerEnjoyer wants to merge 9 commits into
mintlayer:masterfrom
nullPointerEnjoyer:fix/genesis-address-debit
Open

nullPointerEnjoyer wants to merge 9 commits into
mintlayer:masterfrom
nullPointerEnjoyer:fix/genesis-address-debit

Conversation

@nullPointerEnjoyer

Copy link
Copy Markdown
Collaborator

Closes #2158.

Root cause

The scanner credits block-reward-sourced outputs (the genesis premint is one) to their destination address, but the spend arm of update_tables_from_transaction_inputs for OutPointSourceId::BlockReward(_) never debited address_amount for Transfer/LockThenTransfer outputs - unlike the OutPointSourceId::Transaction(_) arm, which always debits. The genesis premint output spent at block 134 therefore kept its 399.9M ML balance row forever: a phantom #1 top holder with zero UTXOs.

What changed

  • Scanner (scanner-lib/src/blockchain_state/mod.rs): the BlockReward spend arm now handles Transfer/LockThenTransfer exactly like the Transaction arm: the receiving address is recorded in the address history and the amount is debited from address_amount (coin or token). Output kinds that are never credited (Burn, IssueNft, DataDeposit, CreateDelegationId, DelegateStaking, IssueFungibleToken, Htlc, CreateOrder) stay no-ops, so no negative balances can appear. Pool arms unchanged.
  • History backfill mirror (collect_secondary_history): the same Transfer/LockThenTransfer spend now records the address in the deferred-history path too, so databases rebuilt via fast catch-up + backfill match fully-scanned ones (the mirror's per-source split for IssueNft/Htlc and pool decommission is preserved, and its comments are updated).
  • Storage version 28 -> 29: scanners re-initialize and re-scan on the next start, which rebuilds address_amount and the holders listing with the fixed logic and drops the existing phantom row.

Operational note: upgrading the scanner daemon (either backend) triggers a full re-scan - plan the maintenance window for the production api-servers accordingly.

Supply-chain check adjustments

  • Removed the RUSTSEC-2026-0383 ignore: the advisory now marks webpki-root-certs 0.26.11 as unaffected and >= 1.0.10 as patched; both locked versions (0.26.11, 1.0.11) are clean, so the ignore no longer matches anything.
  • Added an RUSTSEC-2026-0620 ignore with rationale: the curve25519-dalek AVX-512 scalar-multiplication bug is only reachable on nightly builds with the unstable_avx512 backend; our builds use stable toolchains without that cfg, and the patched >= 5.1.0 needs a schnorrkel release that supports dalek 5.x.

Tests

  • New spending_the_genesis_premint_debits_the_address (scanner sync tests): scans genesis, asserts the premint is credited, spends it to a different destination, and asserts the premint address is zeroed and absent from the holders listing, the recipient is credited, and the spend appears in both address histories. Fails without the fix, passes with it.
  • backfill_matches_full_scan and the full scanner suite pass; ./do_checks.sh green; workspace tests green.

Known follow-ups (pre-existing, not introduced here)

  • BalanceAccumulator address underflow panics (parity with the pre-aggregation behavior) instead of returning a scan error; the same for the i128 conversion of extreme token amounts.
  • Block-reward LockThenTransfer outputs are credited/debited unlocked-only (no timelock split), consistent on both sides.
  • A custom genesis carrying IssueNft/Htlc premints would keep the phantom class for those kinds (never credited, never debited); unreachable in shipped chains.

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.

[api-server] Genesis premint spend is not debited from ml.address_amount — phantom #1 top holder (399.9M ML, zero UTXOs)

1 participant