Skip to content

Commit

Permalink
interim version of Propose Generator constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
NadiaYvette committed Oct 2, 2024
1 parent f8ac969 commit 7c36097
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ compileToScript = do
emit $ ReadDRepKeys nc
logMsg "Importing DRep SigningKeys. Done."

-- Can likely use genesisWallet for everything in voting workloads.
genesisWallet <- importGenesisFunds
collateralWallet <- addCollaterals genesisWallet
splitWallet <- splittingPhase genesisWallet
Expand Down
24 changes: 24 additions & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import Data.Bitraversable (bimapM)
import Data.ByteString.Lazy.Char8 as BSL (writeFile)
import Data.IntervalMap.Interval as IM (Interval (..), upperBound)
import Data.IntervalMap.Lazy as IM (adjust, containing, delete, insert, null, toList)
import qualified Data.Map.Strict as Map (fromList)
import Data.Ratio ((%))
import Data.Sequence as Seq (ViewL (..), fromList, viewl, (|>))
import qualified Data.Text as Text (unpack)
Expand Down Expand Up @@ -388,6 +389,29 @@ evalGenerator generator txParams@TxGenTxParams{txParamFee = fee} era = do

return $ Streaming.effect (Streaming.yield <$> sourceToStore)

Propose walletName coin stakeAddr -> do
wallet <- getEnvWallets walletName
let txGenerator = genTxProposal shelleyBasedEra ledgerParameters (collateral, collFunds) fee proposal metadata inputs outputs
fundSource = walletSource wallet 1
inToOut = Utils.inputsToOutputsWithFee fee count
sourceToStore = sourceToStoreTransactionNew txGenerator fundSource inToOut (mangle $ repeat toUTxO)
govAction = TreasuryWithdrawals (Map.fromList [(rewardAcct, coin)]) Nothing
rewardAcct = toShelleyStakeAddress stakeAddr
fundPreview <- liftIO $ walletPreview wallet inputs
case sourceTransactionPreview txGenerator fundPreview inToOut (mangle $ repeat toUTxO) of
Left err -> traceDebug $ "Error creating Tx preview: " ++ show err
Right tx -> do
let
txSize = txSizeInBytes tx
txFeeEstimate = case toLedgerPParams shelleyBasedEra protocolParameters of
Left{} -> Nothing
Right ledgerPParams -> Just $
evaluateTransactionFee shelleyBasedEra ledgerPParams (getTxBody tx) (fromIntegral $ inputs + 1) 0 0 -- 1 key witness per tx input + 1 collateral
traceDebug $ "Projected Tx size in bytes: " ++ show txSize
traceDebug $ "Projected Tx fee in Coin: " ++ show txFeeEstimate
-- TODO: possibly emit a warning when (Just txFeeEstimate) is lower than specified by config in TxGenTxParams.txFee
return $ Streaming.effect (Streaming.yield <$> sourceToStore)

Sequence l -> do
gList <- forM l $ \g -> evalGenerator g txParams era
return $ Streaming.for (Streaming.each gList) id
Expand Down
40 changes: 40 additions & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,46 @@ data Generator where
-- but it's difficult to tell what it's doing.
NtoM :: !String -> !PayMode -> !NumberOfInputsPerTx -> !NumberOfOutputsPerTx
-> !(Maybe Int) -> Maybe String -> Generator
-- | 'Propose' represents submitting a governance action proposal as
-- just a singleton.
-- The direct arguments of Propose likely need to be calculated from
-- what's now being passed in order to avoid existentials etc. breaking
-- the derivation clauses.
-- RewardAccount has needed instances.
-- Anchor also.
-- GovAction is it, we only use TreasuryWithdrawals after splitting phase.
-- Representing donations could be worthwhile for the setup/splitting phase.
-- The era seems to need to be got rid of.
-- RewardAccount and Anchor can likely be computed from something
-- without the polymorphism, shouldn't be tough to find what.
-- The translation to RewardAccount and Anchor must be done outside
-- cardano-node.
-- StakeAddress for RewardAccount
-- createAnchor, unclear where Url and anchorData (ByteString) come from.
--
-- RewardAccount better represented as a Cardano address -- StakeAddress?
-- It would be simpler avoiding the StakeAddress and just using the Cardano address if possible.
--
-- Also be conscious of what the Anchor represents.
-- Wait, does Anchor actually have the instances?
-- *** Ping Aniket or Carlos. ***
Propose :: !String
-> !L.Coin
-- -> !(RewardAccount (L.EraCrypto era))
-- The RewardAccount is represented by a StakeAddress
-> !StakeAddress
-- -> !(GovAction era)
-- The GovAction can be recovered from the RewardAccount and
-- Coin at least if the hash can be computed or omitted as
-- Nothing with no negative consequences.
-- -> !(L.Anchor (L.EraCrypto era))
-- the Anchor can be recovered from the Url and AnchorData,
-- though it's unclear where the AnchorData ByteString comes
-- from just yet.
-- *** Check in with Carlos and/or Aniket. ***
-- Wait, genTxProposal didn't seem to need to use an anchor at all.
-- -> !(Url, ByteString)
-> Generator
-- | 'Sequence' represents sequentially issuing a series in the form
-- of a list of transaction series represented by 'Generator' itself,
-- but the nesting is done by first translating to
Expand Down

0 comments on commit 7c36097

Please sign in to comment.