Skip to content

Improve autobalancing errors when change has no lovelace#816

Merged
carbolymer merged 1 commit into
masterfrom
mgalazyn/refactor/improve-balancing-errors
Apr 25, 2025
Merged

Improve autobalancing errors when change has no lovelace#816
carbolymer merged 1 commit into
masterfrom
mgalazyn/refactor/improve-balancing-errors

Conversation

@carbolymer
Copy link
Copy Markdown
Contributor

@carbolymer carbolymer commented Apr 16, 2025

Changelog

- description: |
    Improve autobalancing errors when change has no lovelace
    `checkMinUTxOValue` has its arguments flipped.
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
   - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
   - refactoring    # QoL changes
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Previously for txout with 0 lovelace and some non-ada assets the returned error was about negative balance, which doesn't make sense.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

@carbolymer carbolymer self-assigned this Apr 16, 2025
@carbolymer carbolymer marked this pull request as ready for review April 16, 2025 17:03
@carbolymer carbolymer requested a review from Copilot April 18, 2025 06:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

Files not reviewed (2)
  • cardano-api/src/Cardano/Api/Internal/Fees.hs: Language not supported
  • cardano-api/test/cardano-api-test/Test/Cardano/Api/Orphans.hs: Language not supported

Copy link
Copy Markdown
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

Nice 👍

| L.isZero outValue -> pure () -- empty TxOut - ok, it's removed at the end
| L.isZero coin -> -- no ADA, just non-ADA assets
Left $
TxBodyErrorAdaBalanceTooSmall
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You may want to give @mkoura a heads up if he is depending on the error output for this failure case.

Copy link
Copy Markdown
Contributor

@palas palas left a comment

Choose a reason for hiding this comment

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

I have limited understanding of this code. But I am pretty confident it is all refactoring except for the addition of the TxBodyErrorAdaBalanceTooSmall error, which I don't understand why it is there, but I imagine it is correct.

I just added a suggestion that I think can improve readability a little bit

else do
-- check if the balance is positive or negative
-- in one case we can produce change, in the other the inputs are insufficient
balanceCheck sbe pp change
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would put this check outside the if, even though I understand it is equivalent (since the balanceCheck already has an exception for this). But the code would be slightly simpler

Copy link
Copy Markdown
Contributor Author

@carbolymer carbolymer Apr 24, 2025

Choose a reason for hiding this comment

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

Good idea. I think I'll do a single check for the txout emptiness in the balance check only i.e. I'll change the output type to:

balanceCheck :: ... -> Either (TxBodyErrorAutoBalance era) IsEmpty

data IsEmpty = Empty | NonEmpty

@carbolymer carbolymer force-pushed the mgalazyn/refactor/improve-balancing-errors branch from 3487606 to 266eb04 Compare April 25, 2025 07:10
@carbolymer carbolymer enabled auto-merge April 25, 2025 07:11
@carbolymer carbolymer added this pull request to the merge queue Apr 25, 2025
Merged via the queue into master with commit eb61fa3 Apr 25, 2025
29 checks passed
@carbolymer carbolymer deleted the mgalazyn/refactor/improve-balancing-errors branch April 25, 2025 08:31
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