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

Simplify createTransactionBody #333

Merged
merged 22 commits into from
Oct 29, 2023
Merged

Conversation

newhoggy
Copy link
Collaborator

@newhoggy newhoggy commented Oct 20, 2023

Changelog

- description: |
    Simplify `createTransactionBody`
# 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
  - improvement    # QoL changes e.g. refactoring
  # - 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

Includes commits from #333 so review that first.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

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

@newhoggy newhoggy changed the title Newhoggy/simplify create transaction body WIP Simplify create transaction body Oct 20, 2023
(txOuts bc)
(txFee bc)
(txWithdrawals bc)
createTransactionBody sbe bc =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The focus of this PR is to simplify this function.

The earlier version of this code case matches on sbe and handles each era therein separately resulting in a lot of duplicate code.

The new version of this function instead eliminates the large case expression and instead uses eons allow each feature to determine for themselves if they need to set their values into the TxBody.

@newhoggy newhoggy changed the title WIP Simplify create transaction body WIP Simplify createTransactionBody Oct 21, 2023
@newhoggy newhoggy force-pushed the newhoggy/simplify-createTransactionBody branch from 6c5a15b to 64936bc Compare October 21, 2023 03:41
@newhoggy newhoggy changed the title WIP Simplify createTransactionBody Simplify createTransactionBody Oct 21, 2023
@newhoggy newhoggy marked this pull request as ready for review October 21, 2023 04:16
caseShelleyToBabbageOrConwayEraOnwards
(\w -> (L.apiUpdateTxBodyL w .~) <$> convTxUpdateProposal sbe (txUpdateProposal bc))
(const $ pure id)
sbe
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With this refactoring we can deal with each tx body feature in isolation without duplication.

This can be simplified further in a future PR.

& modifyWith setReqSignerHashes
& modifyWith setReferenceInputs
& modifyWith setCollateralReturn
& modifyWith setTotalCollateral
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

modityWith shouldn't be necessary but ghc's type inference isn't quite there.

@@ -3025,27 +2933,28 @@ makeShelleyTransactionBody sbe@ShelleyBasedEraBabbage
txMintValue,
txScriptValidity
} = do

let aOn = AllegraEraOnwardsBabbage
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just temporary because we need a witness. A future PR will get rid of this.

& L.totalCollateralTxBodyL .~ convTotalCollateral txTotalCollateral
& L.certsTxBodyL .~ convCertificates sbe txCertificates
& L.invalidBeforeTxBodyL aOn .~ convValidityLowerBound txValidityLowerBound
& L.invalidHereAfterTxBodyL sbe .~ convValidityUpperBound sbe txValidityUpperBound
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These lenses take witnesses instead of constraints. This can be used in future to simplify code.


in case sbe of
ShelleyBasedEraShelley -> do
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One of the goals of this PR is to eliminate to need to case match on the era and handle each era separately. Doing away with this case expression vastly reduces code duplication and the potential for error.

@newhoggy newhoggy force-pushed the newhoggy/simplify-createTransactionBody branch 2 times, most recently from ec971ff to 994f811 Compare October 21, 2023 06:22
Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

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

@newhoggy newhoggy force-pushed the newhoggy/simplify-createTransactionBody branch from 994f811 to ac1f2fd Compare October 23, 2023 13:51
@newhoggy newhoggy requested a review from carbolymer October 23, 2023 13:53
@newhoggy newhoggy dismissed carbolymer’s stale review October 23, 2023 13:54

Comments addressed

Comment on lines +1842 to +1847
setMint <-
caseShelleyToAllegraOrMaryEraOnwards
(const $ pure id)
(const $ pure $ L.mintTxBodyL .~ convMintValue apiMintValue)
sbe
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need >>= here? Why not:

Suggested change
setMint <-
caseShelleyToAllegraOrMaryEraOnwards
(const $ pure id)
(const $ pure $ L.mintTxBodyL .~ convMintValue apiMintValue)
sbe
let setMint =
caseShelleyToAllegraOrMaryEraOnwards
(const $ id)
(const $ L.mintTxBodyL .~ convMintValue apiMintValue)
sbe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is mostly to make all of the units of code have the same shape rather than have some unit use let and others use <-.

You are right in that the >>= is not needed.

@newhoggy newhoggy force-pushed the newhoggy/simplify-createTransactionBody branch from ac1f2fd to 2aeb30b Compare October 28, 2023 07:06
@newhoggy newhoggy added this pull request to the merge queue Oct 29, 2023
Merged via the queue into main with commit c943234 Oct 29, 2023
20 checks passed
@newhoggy newhoggy deleted the newhoggy/simplify-createTransactionBody branch October 29, 2023 04:19
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