Skip to content

fix: preserve boosted activity fee rates - #1429

Merged
ovitrif merged 1 commit into
masterfrom
codex/fix-rbf-activity-fee-rate
Nov 12, 2026
Merged

ovitrif merged 1 commit into
masterfrom
codex/fix-rbf-activity-fee-rate

Conversation

@pwltr

@pwltr pwltr commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Related: iOS #485.
Twin: synonymdev/bitkit-ios#879
Dependency: synonymdev/bitkit-core#166 (released in bitkit-core 0.8.0-rc15, already pinned on master)

This PR preserves the fee rate a user picks for an outgoing RBF boost, so the replacement transaction keeps the correct confirmation estimate through publication, wallet sync, reorgs and evictions.

Description

  • Records the replacement txid and the approved Boost quote's fee rate in core (recordRbfBoost) right after the node returns the replacement, before publishRbfBoost publishes it. This works in either arrival order: core stores the rate as pre-activity metadata for a replacement it has not seen yet, and updates it directly if it already exists.
  • Keeps the boost successful if the rate cannot be recorded: the failure is logged as a warning, and publication and the success or pending state work as before.
  • Writes onchain sync and event snapshots through core's fee-preserving upsert (upsertOnchainActivityPreservingFeeRate) — payment sync merges, replaced-original retirement, replacement linking, reorg and eviction — so a stale or fallback rate cannot overwrite the recorded one. repairVerifiedSentOnchainFee keeps the generic upsert because it is an intentional fee correction.
  • Adds the shared RBF fee-rate journey under journeys/boost/, next to rbf-own-send.xml, with the same path and actions as iOS.

Out of Scope

Design

N/A — no UI changes.

Preview

BeforeAfter
before.mov
Screen.Recording.2026-10-06.at.17.44.28.mov

Note: both recordings were made on the earlier revision of this PR, with a local core SDK build, before it was merged onto master's current boost flow and the released 0.8.0-rc15 core. They show the intended behaviour but were not re-recorded on the current head.

QA Notes

Setup

Dev flavor on staging regtest with a disposable native wallet holding at least 100,000 confirmed Savings sats (./lsp deposit and mine — see Backend preconditions in journeys/README.md), plus a regtest recipient address from another wallet. Core: com.synonym:bitkit-core-android 0.8.0-rc15 as pinned on master; no local SDK substitution.

Journeys

  • J1: new rbf-replacement-fee-rate.xml — a low-fee outgoing send's replacement shows the boosted confirmation estimate, keeps its higher real total fee after sync and reopening, and confirms normally.
  • J2: updated route rbf-own-send.xml (file unchanged) — the same Boost route now records the fee rate before publication; the replacement still appears immediately as Boosting with a new TXID, and confirms after a block.

Manual Tests

  • J1 run by hand on a device at c05ad86d8 against staging regtest: passed.

Automated Checks

  • added ActivityServiceRbfTest.kt — the atomic core call receives the wallet, ids and rate; publication, external replacement, payment sync, reorg and eviction keep a recorded replacement rate and never use a generic write (updateActivity, upsertActivity, upsertActivities or insertActivity).
  • updated ActivityRepoTest.kt — recordRbfBoost passes the wallet-scoped ids and rate, notifies activity and tag observers, propagates storage failure without notifying, and preserves cancellation.
  • updated BoostTransactionViewModelTest.kt — the quoted rate is recorded before publication; a recording failure still publishes and reports success; a failed broadcast records nothing; a publication retry records the approved quote, not later fee edits.
  • updated ActivityServicePaykitContactsTest.kt, ActivityServiceTest.kt — the harnesses capture writes through the fee-preserving upsert, which the sync path now uses.

Evidence

On the branch with origin/master 2eb505a51 merged in, against bitkit-core-android 0.8.0-rc15: just compile, just test (5,883 tests, 0 failures, 2 skipped), just lint (detekt and lintDevDebug) and just build (dev debug APKs) all passed locally. After adding the generic-write guard to ActivityServiceRbfTest, the three RBF test classes (18, 28 and 87 tests) and just lint passed again; temporarily switching the reorg/eviction writes to upsertActivity made the guard fail as intended.

Gaps

  • J2 has not been driven separately; it uses the same Boost route as J1.
  • The iOS side of J1 ran on fix: preserve boosted activity fee rates bitkit-ios#879 (same journeys/boost/ path) against rc15 on a simulator: the replacement kept the boosted 3 sat/vB through reopening and confirmation.
  • If the Boost sheet is torn down between the node returning the replacement and recordRbfBoost, or the boost is made on another device, the replacement keeps core's default rate; out of scope here.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: Not exposed)
  • Implementation: Claude Opus 5.5 (reasoning: Not exposed)
  • Review: Claude Opus 5.5, independent read-only review of the full diff; no correctness bugs found, the test-guard finding is addressed

Metadata note: the original revision of this PR was written in an earlier session whose model metadata is not available here.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from c05ad86 (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

@pwltr
pwltr force-pushed the codex/fix-rbf-activity-fee-rate branch from eb891e2 to c05ad86 Compare November 12, 2026 13:13
@pwltr
pwltr marked this pull request as ready for review November 12, 2026 15:13
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no actionable issues were found.

Summary

Preserves the approved fee rate for outgoing RBF replacements.

  • Outgoing RBF replacements keep the fee rate chosen in the Boost sheet.

No actionable issues were found. Tests were inspected, not run.

Acknowledged scope: pwltr states that sheet teardown before recording, boosts from another device, historical corrections, and incoming CPFP are outside this fix.

Diagram

sequenceDiagram
    participant VM as BoostTransactionViewModel
    participant Node as LightningRepo
    participant Repo as ActivityRepo
    participant Core as Core
    VM->>Node: Broadcast replacement with approved rate
    Node-->>VM: Replacement transaction ID
    VM->>Repo: recordRbfBoost(original, replacement, approved rate)
    Repo->>Core: Record replacement fee rate
    Core-->>Repo: Success or failure
    Note over VM,Repo: A recording failure logs a warning
    VM->>Repo: publishRbfBoost(original, replacement)
    Repo->>Core: Discover and link replacement
    Note over Core: Later snapshot writes preserve the stored rate
Loading

Reviews (1) · Last reviewed commit: "fix: preserve boosted activity fee rates" · Reviewed by Greptile

@ovitrif ovitrif added this to the 3.2.0 milestone Nov 12, 2026
@ovitrif

ovitrif commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Milestone 3.2.0: this PR is the Android twin of synonymdev/bitkit-ios#879, whose issue synonymdev/bitkit-ios#485 is in 3.2.0, and it needs bitkit-core 0.8.0-rc15, which ships only in 3.2.0. It closes no issue, so the milestone sits on this PR.

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No findings. Records the approved Boost quote's rate through core's recordRbfBoost and moves the sync, replaced, replacement, reorg and eviction writes onto upsertOnchainActivityPreservingFeeRate, so the boosted rate survives. Reviewed c05ad86, full tier, static: per the Bitkit track's rule the branch was not built here; CI built and tested it.

What I checked, and 5 candidates I ruled out

Read in full: the diff of BoostTransactionViewModel.kt, ActivityRepo.kt, CoreService.kt (processOnchainPayment, buildUpdatedOnchainActivity, publishRbfBoost, markReplacedActivity, updateReplacementActivity, reorg and eviction handlers), and bitkit-core v0.8.0-rc15 record_rbf_boost and upsert_onchain_activities_with_fee_rate_policy.
Call sites traced: recordRbfBoost (one caller, the RBF success branch), every remaining updateActivity / upsertActivity / upsertActivities in ActivityService.
CI: green, including build-and-test, lint, detekt, compose-ui and all e2e-tests-local shards (onchain_boost_receive_widgets included).

Ruled out

  • Record before the replacement row exists: core writes pre_activity_metadata keyed by the replacement txid, and the preserving upsert transfers it inside the same transaction when the row first appears through getOrCreateReplacementActivity.
  • Preserving upsert keeps the original's 1 sat/vB on the replacement: the core statement keeps the stored rate only on conflict for the same wallet and id, and resolves the id by txid, so the replacement row gets its own rate.
  • Stale isBoosted on the original after recordRbfBoost: markReplacedActivity re-reads the original by txid inside publishRbfBoost before writing isBoosted = false, so the in-memory activity the sheet holds is never written back.
  • Publication retry records a later fee edit: the rate comes from broadcast.quote, captured when the broadcast started and locked by feeLocked.
  • Hardware-wallet and backup paths: mergeHwSnapshot, upsertList and repairVerifiedSentOnchainFee keep the generic writes; none of them can carry a boosted native rate, and the last is an intended correction.

Merge confidence: 4/5, CI green and ActivityServiceRbfTest.kt covers the write paths, but this review is static and the branch was not run here.

Reviewer model: Claude Opus 5.5
Reasoning effort: Not exposed

@pwltr
pwltr requested review from a team, ben-kaufman and ovitrif and removed request for a team November 12, 2026 15:49

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code scan at c05ad86d8: no findings.

  • The replacement records the same RbfBroadcastAttempt.quote.feeRate passed to bumpFeeByRbf. The next boost's floor (feeRate + RBF_MIN_INCREASE) now starts from the replacement's real rate instead of the 1 default, so a second boost can't be quoted below it.
  • Core's preserving upsert keeps a stored rate above 0 on sync, and record_rbf_boost handles both arrival orders through pre_activity_metadata. All changed writes run on the single ServiceQueue.CORE.
  • No schema change: v3.1.0 already pins core rc11 with these columns.
  • One changelog fragment. journeys/boost/rbf-replacement-fee-rate.xml matches the iOS twin's actions.

I checked one concern on device, and it didn't hold up. The worry was that recordRbfBoost marks the original boosted before publishing, so a replacement that never lands could leave the original stuck on "Boosting". With the network cut after opening the sheet, ldk-node fails the bump (Persistence failed writing the broadcast record to VSS) before returning a txid. So nothing is recorded, and the original stays "Confirming" with Boost enabled after a restart. The only window left needs VSS reachable while the Electrum broadcast fails, which I couldn't stage.

Device gate (partial): c05ad86d8 — not run yet; pending: boost/rbf-replacement-fee-rate.xml (J1) and rbf-own-send.xml (J2). Device results and the final review type follow. perf: one extra short transaction on the core queue before publish.

Reviewer model: Claude Fable 5.2 (claude-fable-5-2), Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: not exposed

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Device gate result: approving, nothing above LOW.

Device gate: c05ad86d8 — journeys: 2 passed (boost/rbf-replacement-fee-rate.xml 12/12; boost/rbf-own-send.xml 13/13 on a clean re-run). perf: not relevant; l10n: no UI text changed.

  • Setup: Gate_Throwaway emulator, dev regtest on staging Electrum, fresh wallet with 250 000 sats.
  • J1: a 1 sat/vB send (fee 141) boosted to the Fast tier (fee 422, new txid). The Home row reads "Confirms in ±10m" instead of the 1 sat/vB estimate, keeps it after background and reopen, and confirms after a block. The second-boost floor isn't reachable on this route ("Already Boosted" after one RBF); BoostTransactionViewModelTest covers it.
  • J2's first run failed actions 7-8 on a timing race in publishRbfBoost, code this PR doesn't change. One sync didn't find the replacement yet (Failed to publish RBF replacement [AppError='RBF replacement is not available']), and the replace event arrived 6 s later. The sheet took the pending path, and the original briefly showed "Removed from Mempool" before the replacement row healed. A clean re-run passed all 13 actions. No Failed to record RBF fee rate in either run, and the replacement kept the boosted estimate.
J2 run 1 log
16:34:38.651 DEBUG [BoostTransactionViewModel.kt:277] Boost successful. newTxId: 6ed355ff…
16:34:42.005 WARN  [BoostTransactionViewModel.kt:281] Failed to publish RBF replacement [AppError='RBF replacement is not available']
16:34:47.533 INFO  [ldk_node::chain:565] Onchain transaction d7b2c773… was replaced by 1 transaction(s)
16:34:48.593 INFO  [CoreService.kt:1828] Updated replacement '6ed355ff…' with boostTxId 'd7b2c773…'

@ovitrif

ovitrif commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Merging, as it is approved at c05ad86 with both boost journeys passing on device, and checks are green.

@ovitrif
ovitrif merged commit 0a6734c into master Nov 12, 2026
39 checks passed
@ovitrif
ovitrif deleted the codex/fix-rbf-activity-fee-rate branch November 12, 2026 16:47
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.

4 participants