Skip to content

fix(identity): keep back the balance the network needs for a transfer out of an identity - #1083

Merged
lklimek merged 1 commit into
v1.0-devfrom
fix/identity-transfer-fee-reserve
Oct 13, 2026
Merged

lklimek merged 1 commit into
v1.0-devfrom
fix/identity-transfer-fee-reserve

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Sending credits out of an identity kept back far less than the network requires, so a Max transfer passed the app's own check and was then refused by the network. The app now keeps back what the network actually asks for, with a small margin, for transfers to another identity and to a Platform address.

User story

As a user moving credits out of my identity, I want Max and the check before sending to leave what the network needs, so that a transfer the app accepts is not refused after I confirm it.

Scenario

Base flow

  1. Open an identity that holds its transfer key and choose to transfer credits to another identity.
  2. Press Max and confirm.

Actual behavior

The form fills almost the whole balance and says about 0.000001 DASH is reserved for fees. After confirmation the network refuses the transfer: "Not enough balance. You have 0.0101 DASH but this operation requires 0.0101865572 DASH."

Expected behavior

Max leaves about 0.000096 DASH for a transfer to another identity and about 0.000192 DASH for a transfer to a Platform address, and an amount that leaves less is refused before it is sent. The network then charges less than that (about 0.00003 DASH for a transfer to another identity); the rest stays in the identity.

Detailed discussion

Found by driving the application on a real display against testnet. The same behaviour exists on v1.0-dev in the identity transfer screen; nothing here depends on #1074.

What was done

  • src/model/fee_estimation.rs: estimate_credit_transfer() and estimate_credit_transfer_to_addresses(n) returned Platform's minimum fee (100,000 and 6,500,000 credits). Platform accepts a transfer out of an identity only while the balance holds, above the amount, its own advance estimate of the cost (validate_fees_of_event_v0), which is far higher than the minimum fee and higher than what it finally charges. Both functions now return that requirement with a 10% margin, never less than the minimum fee, scaled by the fee multiplier:
    • to another identity: 8,755,720 × 1.10 = 9,631,292 credits;
    • to n Platform addresses: (11,261,680 + 6,176,980 × n) × 1.10, i.e. 19,182,526 credits for one address.
  • The estimate for funding an address from the wallet was derived from the address-transfer estimate. It keeps its previous value through a separate helper.
  • docs/ai-design/2026-10-13-identity-transfer-fee-reserve/README.md records where the figures come from.

Platform has no client-side function for this requirement (dashpay/platform#5265 asks for one), so the figures are fitted constants, as for username registration in #1075. They were read from Platform's engine offline at the pinned revision (9f7ed169), each confirmed by a refusal one credit below, for protocol versions 11 to 14, ECDSA and BLS keys, and one to three addresses. The engine agrees with the two refusals seen on testnet to 0.02%. The requirement does not depend on the amount for a transfer to an identity; for an address it rises once by 109,600 credits per address when the address receives 2,147,483,648 credits or more, and the constants are fitted to the higher figure.

Known limitations:

  • On v1.0-dev the wallet send form uses the identity estimate when the source is an identity and the destination a Platform address, so there it keeps back 0.000096 DASH instead of 0.000192 DASH and a Max transfer can still be refused. feat(identity): align Home and reuse identity-bound send flows #1074 makes that form use the address estimate; the identity transfer screen already does.
  • The identity transfer screen shows the reserve under the label "Estimated fee:", about three times what the network charges. The label is unchanged. The message that refuses an amount above the maximum does not say that the difference is kept for the fee.
  • The backend's "Fee mismatch" log line now fires on every transfer, because the reserve is deliberately above the charge. Narrowing it is left for a follow-up, to avoid a conflict with feat(identity): align Home and reuse identity-bound send flows #1074.
  • The last 0.000096 DASH of an identity cannot be transferred to another identity, and the last 0.000192 DASH not to an address.

Testing

  • New unit tests fail on the previous code ("100000 is below 8555220", "6500000 is below 17091200"): each estimate covers every balance read from the engine and from testnet, and stays within 15% of it. Three more pin the fee multiplier, the minimum-fee floor and the unchanged wallet-funding estimate; each was confirmed by breaking the line it covers.
  • 287 unit tests across fee estimation, the transfer and send screens and the identity and wallet backends pass; lint clean.
  • Live check on testnet, on a real display, with a build of this branch: a Max transfer to a Platform address (reserve stated 0.00019182526 DASH, charged 0.0000375 DASH), an ordinary transfer to another identity (charged 0.0000299 DASH) and a Max transfer to another identity, the case the network refused before (reserve 0.00009631292 DASH, charged 0.0000294 DASH, 0.00006692 DASH left), were all accepted. An amount of the balance minus half the reserve is refused before sending.
  • Not verified: the engine was read for protocol versions 11 to 14 only; mainnet was not exercised; a transfer to an address of 2,147,483,648 credits or more with a balance exactly at the reserve was not tried live.

Breaking changes

None.

Prior work

🤖 Generated with Claude Code

https://claude.ai/code/session_012YneRVSNLhVnGiedWDr3fw

🤖 Co-authored by Claudius the Magnificent AI Agent

PR Hygiene · 96fd12c

  • Bots — coderabbitai ✓ · thepastaclaw ✓
  • Self-review — not asked of a bot author
  • Build green
  • Approvals
    • files with no dedicated owner (CHANGELOG.md, docs/ai-design/2026-10-13-identity-transfer-fee-reserve/README.md, src/model/fee_estimation.rs) — lklimek

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • Updates
    • Transfer reserve estimates are now approximately 0.000096 DASH for transfers to another identity and 0.000192 DASH for transfers to a Platform address.
    • The reserves account for estimated network balance requirements and a 10% margin, while respecting the network minimum fee. Any amount not charged as a fee remains in the identity.
    • Wallet address-funding estimates now use the network minimum fee rather than the larger transfer reserve.

… out of an identity

Max and the check made before sending kept back the minimum fee of the
network: 100,000 credits for a transfer to another identity and 6,500,000
for a transfer to a Platform address. The network accepts a transfer only
while the identity holds its own advance estimate of the fee above the
amount, about 8.76 million and 17.3 million credits, so a Max transfer
passed the check and was refused after it was sent.

Both estimates now return that balance with a 10% margin, and never less
than the minimum fee. The figures were read from Platform's engine at the
pinned revision and agree with two refusals seen on testnet to 0.02%; the
design note records the method and the tables. The network charges less
than it wants kept back, and the rest stays in the identity.

The estimate for funding an address from the wallet was derived from the
address transfer estimate; it keeps its own figure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: dashpay/dash-evo-tool/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 10498d96-910a-4ce5-8b40-6d7ce39db129
📥 Commits

Reviewing files that changed from the base of the PR and between 0e08dec and 96fd12c.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • docs/ai-design/2026-10-13-identity-transfer-fee-reserve/README.md
  • src/model/fee_estimation.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Transfer estimates now use measured balance reserves for identity transfers and transfers to Platform addresses, with a 10% margin and a network minimum-fee floor. Address-funding estimates use the multiplier-adjusted network minimum fee.

Changes: Identity Transfer Fee Reserves

Layer / File(s) Summary
Reserve inputs and measurement basis
docs/ai-design/2026-10-13-identity-transfer-fee-reserve/README.md, src/model/fee_estimation.rs
The documentation records reserve formulas, engine and testnet measurements, fee comparisons, and known limits. The estimator adds reserve constants and a margin helper.
Apply reserves to transfer estimates
src/model/fee_estimation.rs, CHANGELOG.md
Transfer estimates apply the margin and a minimum-fee floor. Address funding uses the multiplier-adjusted network minimum fee. Tests cover estimates across recipients, multipliers, and minimum-fee floors. The changelog records the reserve amounts.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: lklimek

Merge Risk: ⚪ Minimal · up to 96fd1

The reviewed reserve change has no identified merge-blocking issue and is ready to merge after normal checks.

Pre-merge checks · Passed 5
Passed Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 1 files. (2 skipped: 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: reserving the balance required by the network for transfers from an identity. The wording is somewhat awkward, but it is specific and related to the change…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 13, 2026
@thepastaclaw

thepastaclaw commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 96fd12c) · triage: low · Phase 2 only (no Phase 1 for this repository)

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 2 only (no Phase 1 for this repository)

The exact-head diff and surrounding callers support the supplied clean reviews: identity transfers now reserve the higher advance balance requirement with a margin, while retaining multiplier scaling, minimum-fee floors, and the previous wallet address-funding estimate. No actionable in-scope defects were identified; the documented shared Send-screen limitation predates this change. Validation was static only: the supplied CI snapshot shows Clippy and the Platform pin guard passing, with the Test Suite still in progress.

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — The diff makes a small, contained change to fee-reserve arithmetic in src/model/fee_estimation.rs with focused regression tests, rather than a large or intricate change to funds movement.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); agent phase2-reviewer

@github-actions

Copy link
Copy Markdown
Contributor

Ready for review — files with no dedicated owner: lklimek.
Full checklist in the description.

@github-actions github-actions Bot added ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. and removed waiting-bots Waiting for the review bots to report on this head labels Oct 13, 2026
@github-actions
github-actions Bot requested a review from lklimek October 13, 2026 15:43
@lklimek
lklimek enabled auto-merge (squash) October 13, 2026 16:15
@lklimek
lklimek disabled auto-merge October 13, 2026 16:21
@lklimek
lklimek merged commit bd60907 into v1.0-dev Oct 13, 2026
11 of 13 checks passed
@lklimek
lklimek deleted the fix/identity-transfer-fee-reserve branch October 13, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants