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 collateral balancing when building transaction #631

Merged
merged 2 commits into from
Sep 16, 2024

Conversation

carbolymer
Copy link
Contributor

@carbolymer carbolymer commented Sep 10, 2024

Changelog

- description: |
    Fix collateral balancing when building transaction
# 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

This PR fixes:

This PR consist of two commits:

  • "Refactor: Remove Test.Cardano.Api.Typed and Test.Golden.Cardano.Api.Typed modules" - reorganisation of the test module - no new code was added there.
  • "Fix collateral balancing when transaction building, add unit and property tests" - actual fix

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 changed the title Refactor: Remove Test.Cardano.Api.Typed and Test.Golden.Cardano.Api.T… Fix collateral balancing when building transaction Sep 10, 2024
@carbolymer carbolymer force-pushed the mgalazyn/fix/collateral-autobalance branch 6 times, most recently from 8c6b528 to 02f6030 Compare September 16, 2024 18:07
@carbolymer carbolymer marked this pull request as ready for review September 16, 2024 18:38
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.

Great work, I can tell this was annoying to debug. Just one comment regarding the commit message.

@@ -114,6 +116,10 @@ conwayEraOnwardsToShelleyBasedEra :: ConwayEraOnwards era -> ShelleyBasedEra era
conwayEraOnwardsToShelleyBasedEra = \case
ConwayEraOnwardsConway -> ShelleyBasedEraConway

conwayEraOnwardsToBabbageEraOnwards :: ConwayEraOnwards era -> BabbageEraOnwards era
Copy link
Contributor

Choose a reason for hiding this comment

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

Yikes

, totalCollateral
)
else (TxReturnCollateralNone, TxTotalCollateralNone)
calcReturnAndTotalCollateral w fee pp' TxInsCollateral{} txReturnCollateral txTotalCollateral cAddr totalAvailableCollateral = babbageEraOnwardsConstraints w $ do
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this function exist in cardano-ledger? Or any function that can assist in this calculation? The more we can call from ledger the better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something similar is implemented here, but it's a validation, not a calculation, so we can't just reuse it. https://github.com/IntersectMBO/cardano-ledger/blob/master/eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Utxo.hs#L307

import Test.Tasty (TestTree, testGroup)
import Test.Tasty.Hedgehog (testProperty)

-- | Test that the fee is the same when spending minted asset manually or when autobalancing it
prop_make_transaction_body_autobalance_return_correct_fee_for_multi_asset :: Property
prop_make_transaction_body_autobalance_return_correct_fee_for_multi_asset = H.propertyOnce $ do
let sbe = ShelleyBasedEraConway
let ceo = ConwayEraOnwardsConway
beo = conwayEraOnwardsToBabbageEraOnwards ceo
Copy link
Contributor

Choose a reason for hiding this comment

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

Another good example as to why we have to ditch the Eons.

@carbolymer carbolymer force-pushed the mgalazyn/fix/collateral-autobalance branch from 02f6030 to 2bf5f99 Compare September 16, 2024 20:45
@carbolymer carbolymer added this pull request to the merge queue Sep 16, 2024
Merged via the queue into main with commit 680ed80 Sep 16, 2024
25 checks passed
@carbolymer carbolymer deleted the mgalazyn/fix/collateral-autobalance branch September 16, 2024 21:45
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