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

Merged
merged 54 commits into from
Mar 13, 2025
Merged

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: 4e44cf0

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 Minor
@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
@cjkoepke cjkoepke marked this pull request as ready for review March 3, 2025 20:24
Quantumplation
Quantumplation previously approved these changes Mar 4, 2025
Quantumplation
Quantumplation previously approved these changes Mar 5, 2025
Copy link
Collaborator

@Quantumplation Quantumplation left a comment

Choose a reason for hiding this comment

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

lol why did the formatter decide to remove all the trailing commas?

Quantumplation
Quantumplation previously approved these changes Mar 5, 2025
@cjkoepke
Copy link
Collaborator Author

cjkoepke commented Mar 5, 2025

lol why did the formatter decide to remove all the trailing commas?

There's a discrepancy between the formatter and prettier config on vscode I think.

When updating required witnesses, each provided input should have an available output in either the utxoScope or the collateralUtxo set
When updating required witnesses, each provided input should have an available output in either the utxoScope or the collateralUtxo set
@cjkoepke cjkoepke merged commit 12ae921 into main Mar 13, 2025
3 checks passed
@cjkoepke cjkoepke deleted the feat/collateral branch March 13, 2025 16:41
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.

4 participants