Skip to content

feat: LDK-aligned dynamic fee estimation - #202

Open
ABallarini wants to merge 4 commits into
devfrom
feature/dynamic-fee-estimation-utexo
Open

ABallarini wants to merge 4 commits into
devfrom
feature/dynamic-fee-estimation-utexo

Conversation

@ABallarini

Copy link
Copy Markdown

Summary

This PR replaces the hardcoded static fee (7 sat/vB) with a dynamic, thread-safe fee estimation system built in compliance with LDK Fee Estimation Guidelines.

The default behavior is RLN will update the fees for each confirmation target dynamically every 60s in the background (as LDK recommends here) based on fee estimates from bitcoind, esplora, or electrum.

So in order of priority the fallback chain is:

  1. The fee_rate optionally passed in the request (for API endpoints like sendbtc, sendrgb, createutxos, inflate)
  2. The dynamic cache, refreshed every 60s by a background poller
  3. The static config value

Key Highlights

  • Reuses the existing FeeEstimator, no new module: channel funding, /estimatefee and the four spend APIs all read the one atomic cache LDK already polls every 60s; fee queries stay non-blocking (no I/O on the transaction path).
  • Sane-Range Gate & Safety Bounds: store_fee_estimates is the single gatekeeper for all three poll loops, validating every estimate within [MIN_FEERATE, MAX_FEERATE] (1.0–2500 sat/vB / 253–625,000 sat/kWu). Out-of-range remote responses log a warning and retain last-known-good values.
  • Unified Fee Resolution: the spend APIs resolve their fee via resolve_fee_sat_per_vb() — an explicit > 0 rate wins, an absent or 0 rate falls back to the OutputSpendingFee tier, the same tier channel funding reads directly.
  • Enhanced /estimatefee API: exposes structured fee_rates tiers (background, normal, high_prio, very_high_prio in sat/kWu) directly from the LDK fee cache alongside the legacy fee_rate.
  • Tested & Backward-Compatible: fee_rate becomes optional (additive schema), so existing clients keep working. A black-box regtest test (src/test/dynamic_fee.rs) measures real on-chain feerates, funding vs /estimatefee background, an explicit 120 sat/vB override, and the omitted-fee fallback, and passes alongside the existing suite.

Documentation Links

@ABallarini
ABallarini force-pushed the feature/dynamic-fee-estimation-utexo branch from b3618bd to dc03a8d Compare October 9, 2026 19:47

This branch has not been deployed

No deployments
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