Skip to content

fix(activity): fill unknown stored fee rate on sync (#186) - #187

Merged
pwltr merged 1 commit into
synonymdev:masterfrom
Tyagiquamar:fix/activity-sync-fill-unknown-fee-rate
Nov 9, 2026
Merged

pwltr merged 1 commit into
synonymdev:masterfrom
Tyagiquamar:fix/activity-sync-fill-unknown-fee-rate

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Summary

Fixes #186 by allowing an unknown stored fee_rate (value 0) to be populated from subsequent activity sync snapshots when preserving known fee rates.

Problem & Root Cause

When outgoing on-chain activities are first created, they may be stored with an unknown fee rate (0).

In src/modules/activity/implementation.rs, upsert_onchain_activity_preserving_fee_rate executes:

fee_rate = CASE WHEN ?16 THEN onchain_activity.fee_rate ELSE excluded.fee_rate END

When preserve_fee_rate (?16) is true, this unconditionally retains onchain_activity.fee_rate, causing an initial 0 to persist permanently across later confirmed snapshots even when those snapshots carry the confirmed transaction's actual fee rate.

Solution

Updated the upsert query in upsert_onchain_activities_with_fee_rate_policy to:

fee_rate = CASE WHEN ?16 AND onchain_activity.fee_rate > 0 THEN onchain_activity.fee_rate ELSE excluded.fee_rate END

This ensures:

  1. When a positive fee rate is already known, it is preserved against background sync overwrites.
  2. When the stored rate is unknown (0), later syncs that carry the actual fee rate can populate it.
  3. Added unit regression test preserving_sync_fills_unknown_stored_fee_rate in src/modules/activity/rbf_tests.rs.

Test Plan

  • Executed targeted tests in Docker rust:1.99-bookworm:
    cargo test rbf_tests
    Result:
    running 12 tests
    test modules::activity::rbf_tests::preserving_sync_fills_unknown_stored_fee_rate ... ok
    test modules::activity::rbf_tests::invalid_record_requests_do_not_write_anything ... ok
    test modules::activity::rbf_tests::original_fee_rate_survives_boost_recording_confirmation_and_reopen ... ok
    test modules::activity::rbf_tests::recording_failure_rolls_back_original_state_pending_metadata_and_replacement ... ok
    test modules::activity::rbf_tests::pending_tags_survive_recording_before_replacement_arrives ... ok
    test modules::activity::rbf_tests::recording_and_preserving_rates_are_wallet_scoped ... ok
    test modules::activity::rbf_tests::full_updates_and_upserts_still_allow_deliberate_fee_corrections ... ok
    test modules::activity::rbf_tests::recording_after_replacement_arrives_preserves_other_fields_and_tags ... ok
    test modules::activity::rbf_tests::sync_id_collision_cannot_overwrite_another_transaction ... ok
    test modules::activity::rbf_tests::removed_original_is_not_resurrected_by_late_boost_completion ... ok
    test modules::activity::rbf_tests::replacement_fee_survives_creation_stale_sync_confirmation_and_reopen ... ok
    test modules::activity::rbf_tests::sync_metadata_failure_rolls_back_activity_creation_and_keeps_pending_rate ... ok
    
    test result: ok. 12 passed; 0 failed; 0 ignored; finished in 6.37s
    
  • Executed cargo fmt -- --check with 0 formatting warnings.

@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. Lets a preserving sync fill a stored fee_rate of 0 (unknown) from a later snapshot while still keeping a known positive rate, fixing #186. Reviewed db7d76be, full tier, static: the head is on a fork, so I did not build or run it.

What I checked, and 3 candidates I ruled out

Read in full: upsert_onchain_activities_with_fee_rate_policy, upsert_onchain_activity_preserving_fee_rate and its export in src/lib.rs, record_rbf_boost, transfer_pre_activity_metadata_in_transaction, the new test.
CI: SwiftPM, manifests and wake-tests green; iOS/Android bindgen and usdt-tests pending. No workflow runs modules::activity (only modules::wake and modules::usdt), so the new test is not exercised by CI.

Ruled out

  • A real zero rate gets overwritten: the schema allows fee_rate >= 0, but record_rbf_boost rejects 0 and a broadcast send cannot pay 0 sat/vB, so a stored 0 only ever means unknown. A snapshot that also carries 0 writes 0 again, no regression.
  • Snapshot rate from another txid filling the gap: the preserving path resolves the row by (wallet_id, tx_id) and refuses an id that belongs to a different transaction, so the filled rate always describes the stored txid.
  • Pending RBF metadata losing to the snapshot: metadata with fee_rate > 0 is applied after the upsert in the same transaction, so a pending replacement rate still wins over the snapshot's.

Merge confidence: 4/5, the change is covered by preserving_sync_fills_unknown_stored_fee_rate, but CI does not run the activity tests and the fork head was not run here.

@pwltr
pwltr requested review from coreyphillips and pwltr November 6, 2026 13:51

@coreyphillips coreyphillips 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.

Two independent reviews, nothing blocking a merge.

worth doing, does not block

  • README still says the preserving upsert keeps the stored rate (src/modules/activity/README.md:127-131). The README paragraph on upsert_onchain_activity_preserving_fee_rate still says it preserves the stored rate, which is no longer true for a stored 0. It also omits the rule callers now depend on: the first positive rate to reach a stored 0 sticks. A scratch test with snapshots of 0, 12, then 30 left 12. So a caller that sends a fallback such as 1 for an unknown rate turns the row into a known rate of 1, and the real confirmed rate can no longer replace it. Before this change that row stayed at 0. The README should say that 0 means unknown, that the first positive snapshot rate fills it, and that callers should send 0 rather than a fallback. The doc comments in implementation.rs and lib.rs say "known" rate and remain accurate.

@pwltr pwltr 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.

No correctness defects identified in the reviewed change at db7d76b. Preserving sync upserts now fill a stored zero fee rate from the incoming snapshot while retaining positive stored rates. Ordinary overwrite behavior, wallet/txid identity safeguards and transactional metadata precedence remain intact.

The supplied validation result reports all 12 focused RBF tests passing, including the new regression, addressing the earlier execution gap. This informed verification ran no tests. Dedicated security coverage remains unestablished: the general review's request to clarify prior security coverage is unresolved, rather than evidence of an established bug. Full-suite, external-caller and device coverage are not established by this packet.

@pwltr

pwltr commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

@Tyagiquamar Thank you for another patch! Please sign commits :)

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
@Tyagiquamar
Tyagiquamar force-pushed the fix/activity-sync-fill-unknown-fee-rate branch from db7d76b to 01160d0 Compare November 7, 2026 16:14
@Tyagiquamar

Copy link
Copy Markdown
Contributor Author

Hi @pwltr, re-signed the commit with verified GPG signature as requested.

@pwltr
pwltr merged commit d10afd4 into synonymdev:master Nov 9, 2026
6 checks passed
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.

bug: activity sync keeps an unknown fee rate

4 participants