-
Notifications
You must be signed in to change notification settings - Fork 164
Apply RBF replacements to the wallet before sync #1124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -539,8 +539,13 @@ impl Wallet { | |
| // Collect all conflict txids | ||
| let mut conflict_txids: Vec<Txid> = | ||
| conflicts.iter().map(|(_, conflict_txid)| *conflict_txid).collect(); | ||
| if let Some(previous) = self.pending_payment_store.get(&payment_id).await? { | ||
| conflict_txids.extend(previous.conflicting_txids); | ||
| } | ||
|
|
||
| conflict_txids.push(txid); | ||
| conflict_txids.sort_unstable(); | ||
| conflict_txids.dedup(); | ||
| // The payment already exists in the store at this point: `bump_fee_rbf` | ||
| // updates the payment store with the replacement txid before the next sync | ||
| // cycle, and an id resolved through the candidate history comes from a | ||
|
|
@@ -2084,6 +2089,13 @@ impl Wallet { | |
| }, | ||
| }; | ||
|
|
||
| let mut conflicts = self | ||
| .pending_payment_store | ||
| .get(&payment_id) | ||
| .await? | ||
| .map(|p| p.conflicting_txids) | ||
| .unwrap_or_default(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is independent of #1117. A session of mine found this a little while ago, so I took the opportunity to clean it up. Could you base your PR on https://github.com/jkczyz/ldk-node/commits/2026-09-rbf-middle-round-conflict-list? Then you can drop this and the push/sort/dedup below. Worth updating your commit's message to include something like: Once the bump applies the replacement to the wallet, sync no longer emits TxReplaced for the replaced transaction (BDK derives events from a before/after diff of the canonical set), so nothing else populates conflicting_txids after a bump until a later eviction or confirmation flips the canonical set. |
||
|
|
||
| let mut locked_persister = self.persister.lock().await; | ||
| let mut locked_wallet = self.inner.lock().expect("lock"); | ||
|
|
||
|
|
@@ -2260,8 +2272,26 @@ impl Wallet { | |
| ConfirmationStatus::Unconfirmed, | ||
| ); | ||
|
|
||
| conflicts.push(txid); | ||
| conflicts.sort_unstable(); | ||
| conflicts.dedup(); | ||
| let pending_payment_store = | ||
| self.create_pending_payment_from_tx(new_payment.clone(), Vec::new()); | ||
| self.create_pending_payment_from_tx(new_payment.clone(), conflicts); | ||
| let seen_at = std::time::SystemTime::now() | ||
| .duration_since(std::time::UNIX_EPOCH) | ||
| .unwrap_or_default() | ||
| .as_secs(); | ||
| let previous_seen_at = locked_wallet | ||
| .tx_details(txid) | ||
| .and_then(|details| match details.chain_position { | ||
| bdk_chain::ChainPosition::Unconfirmed { last_seen, .. } => last_seen, | ||
| _ => None, | ||
| }) | ||
| .unwrap_or(0); | ||
| locked_wallet.apply_unconfirmed_txs([( | ||
| fee_bumped_tx.clone(), | ||
| seen_at.max(previous_seen_at.saturating_add(1)), | ||
| )]); | ||
|
Comment on lines
+2291
to
+2294
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth adding a one-line comment on why + 1 is needed. |
||
| let change_set = locked_wallet.take_staged().unwrap_or_default(); | ||
| drop(locked_wallet); | ||
| locked_persister.persist_changeset(change_set).await.map_err(|e| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this ever add anything?