-
Notifications
You must be signed in to change notification settings - Fork 54
fix: case-insensitive .dash + atomic state on broadcast failure #3585
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
Open
Claudius-Maginificent
wants to merge
28
commits into
v3.1-dev
Choose a base branch
from
fix/dpns-case-and-utxo-race-v3.1-dev
base: v3.1-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
fe6d7c1
fix(rs-sdk): case-insensitive .dash suffix in resolve_dpns_name
lklimek 26f13d9
fix(rs-platform-wallet): prevent UTXO double-spend race in send_to_ad…
lklimek 0d17a63
Merge branch 'v3.1-dev' into fix/dpns-case-and-utxo-race-v3.1-dev
lklimek 1bd306a
fix: improve platform wallet UTXO checks and DPNS parsing (#3595)
thepastaclaw 4616cba
Merge branch 'v3.1-dev' into fix/dpns-case-and-utxo-race-v3.1-dev
lklimek 23d8943
fix(rs-platform-wallet): defer change-address advance until after rev…
lklimek a3a5d96
fix(rs-platform-wallet): typed ConcurrentSpendConflict variant for re…
lklimek 41c9493
fix(rs-sdk): skip DPNS contract fetch when label is empty (CMT-001)
lklimek 2c7e22a
docs(rs-platform-wallet): rewrite revalidation comment to match build…
lklimek 97d1532
fix(rs-platform-wallet): structured event for post-broadcast !is_rele…
lklimek 79843e3
test(rs-platform-wallet): broadcast ordering + rollback contract (CMT…
lklimek 391768c
docs(rs-platform-wallet): tighten and deduplicate inline comments on …
lklimek 43e3f9d
fix(rs-platform-wallet): defer change-address commit past broadcast (…
lklimek 5d4a61b
test(rs-platform-wallet): rename broadcast pass-through tests to matc…
lklimek cc2104f
Merge remote-tracking branch 'origin/v3.1-dev' into fix/dpns-case-and…
lklimek 6aa4f42
Merge branch 'v3.1-dev' into fix/dpns-case-and-utxo-race-v3.1-dev
lklimek 4dd55d2
fix: close same-UTXO concurrent-selection race in send_to_addresses (…
lklimek 349b95b
feat(rs-platform-wallet): attach outpoint context to ConcurrentSpendC…
lklimek 6239fda
chore(rs-platform-wallet): drop CMT-NNN review tombstones from broadc…
lklimek 4d204cd
fix(rs-platform-wallet): structured tracing fields on wallet-missing …
lklimek 543a8dc
Merge remote-tracking branch 'origin/v3.1-dev' into fix/dpns-case-and…
lklimek 0bacd25
chore: improve error type
lklimek 0188fa9
chore: improve docs
lklimek 9902cbd
chore: fix build
lklimek 371e2c3
fix(rs-platform-wallet): restore defensive post-build UTXO revalidation
lklimek ff56c56
chore(rs-platform-wallet-ffi): use Result::is_err in group_info tests
lklimek 5466501
chore: fmt
lklimek e4cf6b3
Merge remote-tracking branch 'origin/v3.1-dev' into fix/dpns-case-and…
lklimek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
632 changes: 616 additions & 16 deletions
632
packages/rs-platform-wallet/src/wallet/core/broadcast.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
packages/rs-platform-wallet/src/wallet/core/reservations.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| //! Per-wallet outpoint reservation set for [`CoreWallet::send_to_addresses`](super::broadcast). | ||
| //! | ||
| //! Closes the same-UTXO concurrent-selection race: the first caller reserves its selected | ||
| //! outpoints under the write lock; subsequent callers filter them out and short-circuit with | ||
| //! [`PlatformWalletError::NoSpendableInputs`](crate::PlatformWalletError) before hitting the | ||
| //! network. Reservations are released by an RAII guard on success, error, or panic. | ||
|
|
||
| use std::collections::HashSet; | ||
| use std::sync::{Arc, Mutex}; | ||
|
|
||
| use dashcore::OutPoint; | ||
|
|
||
| /// Per-wallet set of outpoints that have been selected for an in-flight | ||
| /// broadcast but not yet marked spent in `ManagedWalletInfo`. | ||
| /// | ||
| /// Cheaply cloneable: holds an `Arc<Mutex<…>>` internally. All clones share | ||
| /// the same set. | ||
| #[derive(Debug, Default, Clone)] | ||
| pub(crate) struct OutpointReservations { | ||
| inner: Arc<Mutex<HashSet<OutPoint>>>, | ||
| } | ||
|
|
||
| impl OutpointReservations { | ||
| pub(crate) fn new() -> Self { | ||
| Self::default() | ||
| } | ||
|
|
||
| /// Test whether `outpoint` is currently reserved. | ||
| #[cfg(test)] | ||
| pub(crate) fn contains(&self, outpoint: &OutPoint) -> bool { | ||
| let guard = self | ||
| .inner | ||
| .lock() | ||
| .unwrap_or_else(|poisoned| poisoned.into_inner()); | ||
| guard.contains(outpoint) | ||
| } | ||
|
|
||
| /// Clone the current reservation set under a single lock acquisition. | ||
| /// | ||
| /// Callers filter spendable UTXOs against the returned snapshot to | ||
| /// avoid one mutex lock per candidate outpoint. | ||
| pub(crate) fn snapshot(&self) -> HashSet<OutPoint> { | ||
| let guard = self | ||
| .inner | ||
| .lock() | ||
| .unwrap_or_else(|poisoned| poisoned.into_inner()); | ||
| guard.clone() | ||
| } | ||
|
|
||
| /// Reserve `outpoints`, returning an RAII guard that releases them on | ||
| /// drop. The guard must be held until the broadcast outcome is | ||
| /// reconciled into wallet state (success → `check_core_transaction` | ||
| /// has run; failure → caller has propagated the error). | ||
| pub(crate) fn reserve(&self, outpoints: Vec<OutPoint>) -> OutpointReservationGuard { | ||
| { | ||
| let mut guard = self | ||
| .inner | ||
| .lock() | ||
| .unwrap_or_else(|poisoned| poisoned.into_inner()); | ||
| for op in &outpoints { | ||
| guard.insert(*op); | ||
| } | ||
| } | ||
| OutpointReservationGuard { | ||
| reservations: Arc::clone(&self.inner), | ||
| outpoints, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// RAII guard releasing reservations on drop. | ||
| /// | ||
| /// Drop is infallible and panic-safe — the underlying `Mutex` is recovered | ||
| /// from poisoning so a panicking caller still releases its outpoints. | ||
| #[must_use = "dropping the guard immediately releases the reservation"] | ||
| pub(crate) struct OutpointReservationGuard { | ||
| reservations: Arc<Mutex<HashSet<OutPoint>>>, | ||
| outpoints: Vec<OutPoint>, | ||
| } | ||
|
|
||
| impl Drop for OutpointReservationGuard { | ||
| fn drop(&mut self) { | ||
| let mut guard = self | ||
| .reservations | ||
| .lock() | ||
| .unwrap_or_else(|poisoned| poisoned.into_inner()); | ||
| for op in &self.outpoints { | ||
| guard.remove(op); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use dashcore::hashes::Hash; | ||
| use dashcore::Txid; | ||
|
|
||
| fn op(n: u32) -> OutPoint { | ||
| OutPoint::new(Txid::all_zeros(), n) | ||
| } | ||
|
|
||
| #[test] | ||
| fn reserve_then_drop_releases() { | ||
| let res = OutpointReservations::new(); | ||
| let a = op(1); | ||
| { | ||
| let _g = res.reserve(vec![a]); | ||
| assert!(res.contains(&a)); | ||
| } | ||
| assert!(!res.contains(&a)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn second_reservation_is_disjoint() { | ||
| let res = OutpointReservations::new(); | ||
| let a = op(1); | ||
| let b = op(2); | ||
| let _g1 = res.reserve(vec![a]); | ||
| let _g2 = res.reserve(vec![b]); | ||
| assert!(res.contains(&a)); | ||
| assert!(res.contains(&b)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn poisoned_mutex_still_releases() { | ||
| let res = OutpointReservations::new(); | ||
| let a = op(7); | ||
| let res_clone = res.clone(); | ||
| let _ = std::thread::spawn(move || { | ||
| let _g = res_clone.reserve(vec![a]); | ||
| panic!("intentional"); | ||
| }) | ||
| .join(); | ||
| // Guard dropped during unwind — outpoint must be released even | ||
| // though the mutex was poisoned. | ||
| assert!(!res.contains(&a)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.