-
Notifications
You must be signed in to change notification settings - Fork 15
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
Feat: don't include dust btc amounts on rotation #4063
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4063 +/- ##
=====================================
Coverage 71% 71%
=====================================
Files 376 376
Lines 59662 59672 +10
Branches 59662 59672 +10
=====================================
+ Hits 42554 42563 +9
- Misses 14961 14962 +1
Partials 2147 2147
... and 3 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
non_dust_utxos | ||
.iter() | ||
.map(|utxo| utxo.amount) | ||
.sum::<u64>() | ||
.checked_sub(total_fee) | ||
.map(|change_amount| (non_dust_utxos, change_amount)) |
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.
We want to return None
if this is empty, right?
Could we not just do the same as before except:
let available_utxos = BitcoinAvailableUtxos::<T>::take()
.into_iter()
.filter(|utxo| utxo.amount > fee_per_input_utxo)
.collect();
// Same as before
(!available_utxos.is_empty()).then_some(available_utxos).and_then(
//etc.
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.
We want to return None if this is empty, right?
New code also returns None
if the list is empty, and we even have a test for that. Is your suggestion purely due to style preference?
I'm not convinced that "no utxo" needs to be handled separately. Conceptually it is really not any different from "not enough utxo". If you want, I could inline total_fee
and combine the first two expressions, but personally don't really mind giving names to these intermediate expressions.
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.
Ok I see that now. I guess it's stylistic thing then.
I think I missed it because the new code reads to me like "Return None if the utxo sum minus the total fee saturates", which (indirectly, because we filter the list above) implies that the list is empty. This seems less obvious than simply "return None if there are no utxos above the dust amount".
I don't mind breaking this up in some way / adding intermediate expressions, but it would be easier to follow if we handle the empty case explicitly (if x.is_empty()
or whatever, doesn't have to be !available_utxos.is_empty()).then_some(
which I admit is not easy to read either).
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.
I would say the unnecessary check for is_empty()
is the cause of the initial confusion. It made it seem like it was a case that needed a special treatment (different from the more general "not enough funds" case) when it doesn't.
Anyway, it doesn't make a big difference to me, so I will make the change you are suggesting before merging.
non_dust_utxos | ||
.iter() | ||
.map(|utxo| utxo.amount) | ||
.sum::<u64>() | ||
.checked_sub(total_fee) | ||
.map(|change_amount| (non_dust_utxos, change_amount)) |
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.
Ok I see that now. I guess it's stylistic thing then.
I think I missed it because the new code reads to me like "Return None if the utxo sum minus the total fee saturates", which (indirectly, because we filter the list above) implies that the list is empty. This seems less obvious than simply "return None if there are no utxos above the dust amount".
I don't mind breaking this up in some way / adding intermediate expressions, but it would be easier to follow if we handle the empty case explicitly (if x.is_empty()
or whatever, doesn't have to be !available_utxos.is_empty()).then_some(
which I admit is not easy to read either).
* origin/main: Feat: don't include dust btc amounts on rotation (#4063) chore: update dependency and config.toml for RUSTSEC-2023-0065 (#4066) fix: loop_select conditions (PRO-587) (#4061) chore: remove unused config items (#4064) feat: size limit for CCM (#4015) fix: warn -> info (#4060) Fix: correctly handle peer updates while waiting to reconnect (#4052) # Conflicts: # state-chain/chains/src/lib.rs
* feat: don't include dust btc amounts on rotation * chore: return None early on empty utxo list --------- Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
* feat: don't include dust btc amounts on rotation * chore: return None early on empty utxo list --------- Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
Pull Request
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
Noticed that we used "all or nothing" approach when sweeping utxos on rotation, when it is better to skip dust utxos to avoid paying more for their fees than they are worth. Another potential benefit of this is reducing the number of payloads we would need to sign on rotation. (Already discussed this with @ramizhasan111 to make sure that we want this change.)