Skip to content

Conversation

@chaitika
Copy link

@chaitika chaitika commented Oct 2, 2025

Fixes #604

@chaitika chaitika force-pushed the fix-list-methods-cloning branch 2 times, most recently from dcaed45 to 592b197 Compare October 5, 2025 12:07
Copy link
Collaborator

@0xEgao 0xEgao left a comment

Choose a reason for hiding this comment

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

Approach looks good.
can you fix the test and format the code.
cc:- @chaitika

@chaitika chaitika force-pushed the fix-list-methods-cloning branch 2 times, most recently from 659b22e to 8d2769a Compare October 9, 2025 05:11
@codecov
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

❌ Patch coverage is 72.88136% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.35%. Comparing base (776b75d) to head (668c963).
⚠️ Report is 37 commits behind head on master.

Files with missing lines Patch % Lines
src/wallet/api.rs 72.72% 6 Missing ⚠️
src/utill.rs 0.00% 5 Missing ⚠️
src/maker/rpc/server.rs 0.00% 3 Missing ⚠️
src/bin/taker.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
+ Coverage   68.87%   75.35%   +6.47%     
==========================================
  Files          35       40       +5     
  Lines        4932     6480    +1548     
==========================================
+ Hits         3397     4883    +1486     
- Misses       1535     1597      +62     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chaitika chaitika force-pushed the fix-list-methods-cloning branch from 8d2769a to 668c963 Compare October 9, 2025 12:50
Copy link
Collaborator

@hulxv hulxv left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +520 to +524
self.print_swap_report(
prereset_swapstate,
swap_start_time,
self.wallet.list_all_utxo(),
)?;
Copy link

@mojoX911 mojoX911 Oct 12, 2025

Choose a reason for hiding this comment

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

This won't work. The initial utxo set passed on here previously was the set that existed before the swap. This will pass the utxo set after the swap. They are different. So this will mess up the report logic.

Revert back to previous way of capturing the initial (pre-swap) utxo set.

Comment on lines +564 to +567
let (initial_outpoints, input_utxos): (HashSet<_>, Vec<_>) = initial_utxos
.into_iter()
.map(|utxo| {
let outpoint = OutPoint {

Choose a reason for hiding this comment

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

Try not to change logic not related to this PR, to reduce review surface. The previous way was just fine.

}

/// Lists swap coin UTXOs along with their Spend info.
pub fn list_swap_coin_utxo_spend_info(&self) -> Vec<(ListUnspentResultEntry, UTXOSpendInfo)> {

Choose a reason for hiding this comment

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

Why aren't we changing this too?

Comment on lines 801 to 802
/// Lists descriptor UTXOs along with their Spend info.
pub fn list_descriptor_utxo_spend_info(&self) -> Vec<(ListUnspentResultEntry, UTXOSpendInfo)> {

Choose a reason for hiding this comment

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

Same, why not change?

Comment on lines 836 to 837
/// Lists all swept incoming swapcoin UTXOs along with their Spend info.
pub fn list_swept_incoming_swap_utxos(&self) -> Vec<(ListUnspentResultEntry, UTXOSpendInfo)> {

Choose a reason for hiding this comment

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

Can be changed.

Comment on lines +168 to 169
let coins = [(utxo.clone(), spend_info.clone())];
let tx = self.spend_coins(&coins, destination, feerate)?;

Choose a reason for hiding this comment

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

This is not looking clean. We are cloning again which destroys the purpose of the PR.

Can we change spend_coin to take a reference too? In theory, it should work with refs. But it might need more refactoring changes internally.

.map(|(utxo, _)| utxo.clone())
.collect()
pub fn list_all_utxo(&self) -> impl Iterator<Item = &ListUnspentResultEntry> {
self.store.utxo_cache.values().map(|(utxo, _)| utxo)

Choose a reason for hiding this comment

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

better to use list_all_utxo_spend_info to avoid repeating change later.

Comment on lines +758 to +760
self.store
.utxo_cache
.values()

Choose a reason for hiding this comment

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

Same, use list_all_utxo_spend_info whenever possible.

If we keep the API pipeline same everywhere, then later if any changes needed, we can add it only to list_alll_utxo_spend_info without changing any other API.

Comment on lines +194 to +195
let coins = [(utxo.clone(), spend_info.clone())];
let tx: Transaction = self.spend_coins(&coins, destination, feerate)?;

Choose a reason for hiding this comment

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

Same. Avoid cloning by changing spend_coins definitions.

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.

Avoid unnecessary cloning in list_* methods

4 participants