Skip to content
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

fix: utxo consolidation works without prev key #4903

Merged
merged 4 commits into from
May 30, 2024

Conversation

msgmaxim
Copy link
Contributor

@msgmaxim msgmaxim commented May 27, 2024

Pull Request

Checklist

  • I am confident that the code works.
  • I have updated documentation where appropriate.

Summary

@j4m1ef0rd noticed that consolidation test didn't work on localnet, so I had a look (it is part of full bouncer, but not run by default in PRs). Looks like at some point the code was changed resulting in consolidation being skipped if the previous key isn't available (which it is not the case unless you've rotated multiple times on localnet).
Arguably, we don't care about this edge case, but it is still techincally a bug and it is annoying that the test stopped working on localnet (it wasn't a problem in full bouncer because we rotate more than once there), so I fix it here.

Update: This turned out to be more work than I originally thought, but I decided that I might as well finish what I started. Specifically, some changes were required in unit tests, which I found a bit messy. Some of them expliclty asserted that consolidation shouldn't happen if no previous key is set, which was simply "how thing worked" rather than "how things should work". "Consolidation" of old utxos still only happens when previous key is provided. (I really wish we didn't merge the two mechanisms into the same function.)

I also noticed that "consolidation" of old utxos worked even for "stale" utxos (corresponding to the key older than previous). We should only "consolidate" old uxtos that belong to the previous key because we shouldn't assume that we can sign anything older than that (and we already discard such utxos in practice). I changed the code to only "consolidate" old utxos from previous key (in addition to normal consolidation of current key utxos).

This fix probably doesn't matter in practice since old utxos would be discarded elsewhere, but the original behaviour made it more difficult to reason about tests, where we expect "stale" utxos to be discarded rather than "consolidated" (the original tests were hiding this due to the consolidation function not always being called), and the code is now more consistent with "telling the story" about how stale utxos are handled.

@msgmaxim msgmaxim requested a review from dandanlen as a code owner May 27, 2024 05:28
@msgmaxim msgmaxim marked this pull request as draft May 27, 2024 07:12
@msgmaxim
Copy link
Contributor Author

Looks like some tests are faiing. Will re-open once I've fixed them.

Copy link

codecov bot commented May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72%. Comparing base (512cb60) to head (30070ec).

Additional details and impacted files
@@          Coverage Diff           @@
##            main   #4903    +/-   ##
======================================
- Coverage     72%     72%    -0%     
======================================
  Files        428     428            
  Lines      73488   73311   -177     
  Branches   73488   73311   -177     
======================================
- Hits       52810   52574   -236     
- Misses     18047   18100    +53     
- Partials    2631    2637     +6     

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

@msgmaxim msgmaxim marked this pull request as ready for review May 28, 2024 06:12
Copy link
Collaborator

@dandanlen dandanlen left a comment

Choose a reason for hiding this comment

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

Thanks, I agree this is an improvement.

@dandanlen dandanlen added this pull request to the merge queue May 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 28, 2024
@msgmaxim msgmaxim added this pull request to the merge queue May 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 29, 2024
@msgmaxim msgmaxim added this pull request to the merge queue May 30, 2024
Merged via the queue into main with commit dec587e May 30, 2024
45 checks passed
@msgmaxim msgmaxim deleted the fix/consolidate-no-prev-key branch May 30, 2024 01:57
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.

2 participants