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 transaction autobalancing when deregistering credential #718

Merged

Conversation

carbolymer
Copy link
Contributor

@carbolymer carbolymer commented Jan 7, 2025

Changelog

- description: |
    Fix transaction autobalancing when deregistering a credential
# 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

The first step of autobalancing was not considering ADA inflow from deregistering a credential, so the resulting change could get negative and it was blowing up in ledger code.

Detailed cause explanation

The negative intermediate change value could be a result of the first call to:

calculateChangeValue sbe totalValueAtSpendableUTxO txbodycontent

calculateChangeValue considers only:

  • tx inputs
  • tx outputs
  • minted assets

so if there's not enough input value, meaning tx outs > tx ins, the calculated intermediate change gets negative. Note, that's a valid scenario if enough funds are coming in from certificate deposit return.

If that change is then used as a new transaction output (the change output), it will throw an exception in the ledger code.

The fix

We're using the exact change value in the first step of autobalancing, for the execution units calculation.

Regression tests executed in:

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 force-pushed the mgalazyn/fix/autobalancing-when-credential-deregistration branch 2 times, most recently from b70d25e to 65f7e5b Compare January 8, 2025 14:32
@smelc
Copy link
Contributor

smelc commented Jan 9, 2025

LGTM. Ask me for approval when this is ready 👍

@carbolymer carbolymer force-pushed the mgalazyn/fix/autobalancing-when-credential-deregistration branch 3 times, most recently from 6577cbc to 45c03e1 Compare January 14, 2025 13:21
@carbolymer carbolymer force-pushed the mgalazyn/fix/autobalancing-when-credential-deregistration branch 3 times, most recently from e0d4049 to 8642abb Compare January 14, 2025 13:29
@carbolymer carbolymer marked this pull request as ready for review January 14, 2025 13:32
@carbolymer carbolymer force-pushed the mgalazyn/fix/autobalancing-when-credential-deregistration branch from 8642abb to c6bba1b Compare January 14, 2025 13:36
@carbolymer carbolymer changed the title Fix autobalancing, when deregistering credential Fix transaction autobalancing when deregistering credential Jan 14, 2025
Copy link
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.

Can you add some more details as to exactly how you fixed this? It's not obvious to me what changes are the fix as they are overlapped with formatting changes.

@carbolymer carbolymer requested a review from Jimbo4350 January 16, 2025 14:32
@carbolymer carbolymer force-pushed the mgalazyn/fix/autobalancing-when-credential-deregistration branch from c6bba1b to 5416989 Compare January 16, 2025 14:33
Copy link
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.

Still unclear. Separate the formatting changes and the semantic changes with git add --patch I understand the change now after reading the PR description. However we need to confirm that the change value does not influence the execution units calculation. I think it may as a larger change value means a larger script context. Confirm this with the plutus team.

@Jimbo4350 Jimbo4350 self-requested a review January 16, 2025 16:52
@carbolymer carbolymer self-assigned this Jan 30, 2025
@carbolymer carbolymer force-pushed the mgalazyn/fix/autobalancing-when-credential-deregistration branch 5 times, most recently from 12a4f6d to 3e12ec8 Compare January 31, 2025 14:13
@carbolymer carbolymer requested a review from Jimbo4350 January 31, 2025 14:13
@carbolymer carbolymer force-pushed the mgalazyn/fix/autobalancing-when-credential-deregistration branch 5 times, most recently from 23ebe4f to a26c2c7 Compare February 4, 2025 11:05
cardano-api/internal/Cardano/Api/Fees.hs Outdated Show resolved Hide resolved
:: ShelleyBasedEra era -> Value -> TxBodyContent build era -> Value
calculateChangeValue sbe incoming txbodycontent =
let outgoing = calculateCreatedUTOValue sbe txbodycontent
-- | Calculate the partial change - this does not include certificates' deposits
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@carbolymer carbolymer force-pushed the mgalazyn/fix/autobalancing-when-credential-deregistration branch from a26c2c7 to 63651cd Compare February 4, 2025 14:36
@carbolymer carbolymer enabled auto-merge February 4, 2025 14:36
@carbolymer carbolymer added this pull request to the merge queue Feb 4, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Feb 4, 2025
@carbolymer carbolymer merged commit 7005f4d into master Feb 4, 2025
29 checks passed
@carbolymer carbolymer deleted the mgalazyn/fix/autobalancing-when-credential-deregistration branch February 4, 2025 15:12
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.

[BUG] - Incorrect change output computation inside makeTransactionBodyAutoBalance
3 participants