Skip to content

Fix #2040: Update Balance immature calculation for MTP-based maturity#2226

Open
kallal79 wants to merge 1 commit into
bitcoindevkit:masterfrom
kallal79:fix-mtp-maturity-2040
Open

Fix #2040: Update Balance immature calculation for MTP-based maturity#2226
kallal79 wants to merge 1 commit into
bitcoindevkit:masterfrom
kallal79:fix-mtp-maturity-2040

Conversation

@kallal79

@kallal79 kallal79 commented Jun 11, 2026

Copy link
Copy Markdown

Description

This PR fixes #2040 by updating the Balance immature category calculation to consider Median Time Past (MTP) based maturity for time-locked transactions.

Previously, Balance.immature only tracked coinbase outputs that hadn't reached 100 block confirmations, ignoring absolute time-locks (nLockTime). With this change, time-locked transactions (those with absolute nLockTime >= 500,000,000) are also properly classified as immature until the chain tip's MTP exceeds their locktime.

Changes made:

  • Added lock_time: LockTime to the FullTxOut struct in crates/chain/src/chain_data.rs.
  • Implemented is_mature_at_mtp() and is_confirmed_and_spendable_at_mtp() on FullTxOut to handle time-based locktime checks against an optional mtp parameter.
  • Updated the signature of CanonicalView::balance() to safely accept an mtp: Option<u32> and delegate to the new MTP maturity checks.
  • Updated the Balance documentation in crates/chain/src/balance.rs to reflect the updated classification definition.
  • Modified existing tests to supply None for MTP in older benchmarks/tests, maintaining compatibility.
  • Added a robust unit test test_balance_mtp_maturity in test_indexed_tx_graph.rs to explicitly verify time-locked outputs accurately shift from immature to confirmed as the MTP increases past the locktime.

Notes to the reviewers

Because MTP isn't always available (e.g. missing block timestamps in some local state), the new balance() parameter uses Option<u32>. If None is provided, time-locked transactions are conservatively classified as immature to avoid falsely showing them as confirmed and spendable.

Changelog notice

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Update Balance immature category calculation to consider MTP-based maturity

1 participant