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

tx-generator: stop supporting Byron and use more recent API way to handle eras #6087

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Jan 24, 2025

Note

On top of #6085

Description

  • Stop using IsShelleyBasedEra, which is not the usual way to interact with cardano-api anymore.
  • Use a ShelleyBasedEra era witness instead.
  • As a consequence, this avoids picking the era in many places with shelleyBasedEra. Passing the witness around makes sure the era being used is consistent.
  • This also simplifies the code, as you don't need type applications anymore.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • CI passes. See note on CI. The following CI checks are required:
    • Code is linted with hlint. See .github/workflows/check-hlint.yml to get the hlint version
    • Code is formatted with stylish-haskell. See .github/workflows/stylish-haskell.yml to get the stylish-haskell version
  • Self-reviewed the diff

@smelc smelc force-pushed the smelc/more-tx-generator-simplifications branch 2 times, most recently from 7880076 to 615930a Compare January 24, 2025 16:30
Base automatically changed from smelc/tx-generator-simplifications to master January 24, 2025 17:49
Copy link
Contributor

Choose a reason for hiding this comment

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

ScopedTypeVariables could also be dropped, not that this should be held up for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a chance to switch return to pure in selectCollateralFunds and interpretPayMode if it wouldn't slow you down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

If you can sneak more cleanups in here, that would be great e.g.

diff --git a/bench/tx-generator/src/Cardano/TxGenerator/Genesis.hs b/bench/tx-generator/src/Cardano/TxGenerator/Genesis.hs
index f412dcdc7..c401bd1c7 100644
--- a/bench/tx-generator/src/Cardano/TxGenerator/Genesis.hs
+++ b/bench/tx-generator/src/Cardano/TxGenerator/Genesis.hs
@@ -1,7 +1,6 @@
-{-# LANGUAGE DerivingStrategies #-}
 {-# LANGUAGE NamedFieldPuns #-}
-{-# LANGUAGE RankNTypes #-}
-{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TupleSections #-}
+{-# LANGUAGE ViewPatterns #-}
 
 {- HLINT ignore "Use map" -}
 
@@ -49,9 +48,8 @@ genesisSecureInitialFund :: ()
 genesisSecureInitialFund sbe networkId genesis srcKey destKey TxGenTxParams{txParamFee, txParamTTL}
   = case genesisInitialFundForKey sbe networkId genesis srcKey of
       Nothing             -> Left $ TxGenError "genesisSecureInitialFund: no fund found for given key in genesis"
-      Just (_, lovelace)  ->
-        let txOutValue = lovelaceToTxOutValue sbe $ lovelace - txParamFee
-        in genesisExpenditure sbe networkId srcKey destAddr txOutValue txParamFee txParamTTL destKey
+      Just (_, lovelaceToTxOutValue sbe . subtract txParamFee -> txOutValue) ->
+        genesisExpenditure sbe networkId srcKey destAddr txOutValue txParamFee txParamTTL destKey
   where
     destAddr = keyAddress sbe networkId destKey
 
@@ -128,7 +126,7 @@ mkGenesisTransaction sbe key ttl fee txins txouts
       (createAndValidateTransactionBody sbe txBodyContent)
  where
   txBodyContent = defaultTxBodyContent sbe
-    & setTxIns (zip txins $ repeat $ BuildTxWith $ KeyWitness KeyWitnessForSpending)
+    & setTxIns (map (, BuildTxWith $ KeyWitness KeyWitnessForSpending) txins)
     & setTxOuts txouts
     & setTxFee (mkTxFee sbe fee)
     & setTxValidityLowerBound TxValidityNoLowerBound

No need to hold up the show if it's too much of a bother.

Copy link
Contributor

Choose a reason for hiding this comment

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

This could also be worth getting in there too:

@@ -75,9 +73,9 @@ genesisInitialFundForKey :: ()
   -> SigningKey PaymentKey
   -> Maybe (AddressInEra era, L.Coin)
 genesisInitialFundForKey sbe networkId genesis key
-  = find (isTxOutForKey . fst) (genesisInitialFunds sbe networkId genesis)
+  = find isTxOutForKey $ genesisInitialFunds sbe networkId genesis
  where
-  isTxOutForKey = (keyAddress sbe networkId key ==)
+  isTxOutForKey = (keyAddress sbe networkId key ==) . fst
 
 genesisTxInput ::
      NetworkId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NadiaYvette> I did the changes, except for the usage of ViewPatterns. I think ViewPatterns is a niche extension that augments the entry-level to a codebase, usually for little gain. Feel free to amend yourself!

Copy link
Contributor

Choose a reason for hiding this comment

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

This is great! I think ScopedTypeVariables can go too wrt. extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed 👍

@NadiaYvette
Copy link
Contributor

This is great too. I can't do an approve/etc. yet because it says it's WIP & whatever went on with the flake and garnix checks, but the instant those bits are all cleared up, I'm ready to hit the approve button.

@smelc smelc force-pushed the smelc/more-tx-generator-simplifications branch from 615930a to 851c531 Compare January 27, 2025 09:59
@smelc smelc marked this pull request as ready for review January 27, 2025 09:59
@smelc smelc requested a review from a team as a code owner January 27, 2025 09:59
@smelc
Copy link
Contributor Author

smelc commented Jan 27, 2025

@NadiaYvette> I acted on your comments and this is now ready to go IMO.

You can ignore the Garnix and flake.nix checks. Those are not required yet as they are still being worked on.

@smelc
Copy link
Contributor Author

smelc commented Jan 27, 2025

Convert to draft until @mgmeier confirms that we can drop Byron support.

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