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

Rewrite transaction balance / fee calculation logic #241

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

cjkoepke
Copy link
Collaborator

@cjkoepke cjkoepke commented Feb 5, 2025

This PR comletely rewrites the core complete() method.

This rewrite accomplishes a number of things:

  • The algorithm is now much simpler;
    • The old code did an initial estimation, then a utxo selection, and then a second, different round of utxo selection, etc.
    • This meant it was fairly error prone, and in practice we at Sundae would have to add padding to the fees
    • The new algorithm correctly structures things so that we search for a fixed point in a uniform way, and are very likely to find that fixed point within 1 or 2 iterations
  • It is heavily commented;
    • This means it should be easy to add to it as future hardforks update the logic, or to fix bugs as needed
  • It is more robust;
    • The simplicity above means we're more confident in it selecting an accurate fee, and in our testing it results in much more reliable UTxO selection
    • We employ several tricks to ensure UTxO selection succeeds;
    • For example, if UTxO selection and change balancing changes the fee, and there's spare ADA in the change UTxO, we can re-absorb that in the fee, rather than searching for another transaction input
    • As another example, we also use UTxO selection for selecting collateral, and set the collateral change as necessary
  • We added tracing support, so that we can print verbose debugging logs when needed, but avoid being noisy for the external consumers

Copy link

changeset-bot bot commented Feb 5, 2025

🦋 Changeset detected

Latest commit: cdfd54b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@blaze-cardano/tx Patch
@blaze-cardano/emulator Patch
@blaze-cardano/sdk Patch
@blaze-cardano/uplc Patch
@blaze-cardano/wallet Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Quantumplation Quantumplation changed the title Collateral Selection Rewrite transaction balance / fee calculation logic Feb 18, 2025
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.

3 participants