Skip to content

Commit

Permalink
comment govAct script Action sequence compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
NadiaYvette committed Nov 13, 2024
1 parent 5316d74 commit 7913fc8
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 6 deletions.
22 changes: 17 additions & 5 deletions bench/tx-generator/src/Cardano/Benchmarking/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,27 @@ benchmarkingPhase wallet collateralWallet = do
Just TxGenGovActParams {..}
| mkVote <- \propIdx drepIdx ->
Vote wallet payMode propIdx Yes drepIdx Nothing
, mkBatchDRep <- \propIdx ->
Take (fromIntegral gapQuorum) . Cycle . Sequence $
, stripeDRepsAcrossProp <- \propIdx ->
-- The number of DRep keys might be lower than the batch size,
-- so cycling in this manner is intended to stripe the votes to
-- issue across DRep keys.
-- Batches are meant to be restricted to a set of votes issued
-- within an epoch having a corresponding set of proposals only
-- ever voted on during that particular epoch.
Take (fromIntegral gapBatchSize) . Cycle . Sequence $
map (mkVote propIdx) [0 .. fromIntegral gapDRepKeys - 1]
, mkBatchProp <- \batchIdx ->
, voteOnPropsForBatch <- \batchIdx ->
-- mkBatchEpoch is intended to represent the set of votes to
-- issue within a given batch / epoch. This layer of the call
-- stack is intended to stripe the votes across the proposals
-- of a batch / epoch.
let batchLo = batchIdx * fromIntegral gapBatchSize
batchHi = batchLo + fromIntegral gapBatchSize - 1
in RoundRobin $ map mkBatchDRep [batchLo .. batchHi]
in RoundRobin $ map stripeDRepsAcrossProp [batchLo .. batchHi]
, voteGen <- Sequence $
map mkBatchProp [0 .. fromIntegral gapProposalBatches - 1]
-- Enforcing the correspondence between batches and epochs
-- needs as-of-yet unimplemented logic.
map voteOnPropsForBatch [0 .. fromIntegral gapProposalBatches - 1]
-> emit . Submit era submitMode txParams $
RoundRobin [generator, voteGen]
Nothing -> emit $ Submit era submitMode txParams generator
Expand Down
18 changes: 18 additions & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module Cardano.Benchmarking.Script.Env (
, getBenchTracers
, setBenchTracers
, getEnvDRepKeys
, getEnvDRepKeyByIdx
, setEnvDRepKeys
, getEnvGenesis
, setEnvGenesis
Expand All @@ -61,6 +62,7 @@ module Cardano.Benchmarking.Script.Env (
, getEnvSocketPath
, setEnvSocketPath
, getEnvStakeCredentials
, getEnvStakeCredentialByIdx
, setEnvStakeCredentials
, getEnvThreads
, setEnvThreads
Expand Down Expand Up @@ -90,12 +92,14 @@ import Prelude

import Control.Concurrent.STM (STM)
import qualified Control.Concurrent.STM as STM (TVar, atomically, newTVar, readTVar, writeTVar)
import Control.Monad (guard)
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.Trans.Except
import Control.Monad.Trans.Except.Extra (hoistEither)
import Control.Monad.Trans.RWS.Strict (RWST)
import qualified Control.Monad.Trans.RWS.Strict as RWS
import Data.List.Extra ((!?))
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Ratio
Expand Down Expand Up @@ -316,6 +320,20 @@ getEnvDRepKeys = lift $ RWS.gets envDRepKeys
getEnvStakeCredentials :: ActionM [StakeCredential]
getEnvStakeCredentials = lift $ RWS.gets envStakeCredentials

getEnvValByIdx :: (Env -> [t]) -> Int -> ActionM (Maybe t)
getEnvValByIdx accessor idx = do
vals <- lift $ RWS.gets accessor
let listLength = length vals
pure do
guard $ listLength /= 0
vals !? (idx `mod` listLength)

getEnvDRepKeyByIdx :: Int -> ActionM (Maybe (SigningKey DRepKey))
getEnvDRepKeyByIdx = getEnvValByIdx envDRepKeys

getEnvStakeCredentialByIdx :: Int -> ActionM (Maybe StakeCredential)
getEnvStakeCredentialByIdx = getEnvValByIdx envStakeCredentials

-- | Read accessor for `envNetworkId`.
getEnvNetworkId :: ActionM NetworkId
getEnvNetworkId = getEnvVal envNetworkId "Genesis"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ data NixServiceOptions = NixServiceOptions {
, _nix_plutus :: Maybe TxGenPlutusParams
, _nix_govAct :: Maybe TxGenGovActParams
, _nix_keepalive :: Maybe Integer
, _nix_drep_voting :: Maybe Bool
, _nix_nodeConfigFile :: Maybe FilePath
, _nix_cardanoTracerSocket :: Maybe FilePath
, _nix_sigKey :: SigningKeyFile In
Expand Down
3 changes: 2 additions & 1 deletion bench/tx-generator/src/Cardano/TxGenerator/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ data TxGenGovActParams = TxGenGovActParams
, gapDRepKeys :: Natural
, gapStakeKeys :: Natural
, gapProposalBatches :: Natural
, gapQuorum :: Natural
, gapQuorum :: Double
, gapTPS :: Double
} deriving (Eq, Read, Show, Generic, FromJSON, ToJSON)

data TxGenPlutusType
Expand Down
42 changes: 42 additions & 0 deletions nix/nixos/tx-generator-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ pkgs:
let
cleanNixServiceOptions = cfg: with cfg;
{
govAct = if (!cfg.drep_voting or null) == null then null else
{
# Default values until they land in the workbench profile.
gapBatchSize = 5000;
gapProposalBatches = 1;
gapQuorum = 51;
# These need to be fixed.
gapDRepKeys = 100;
gapStakeKeys = 100;
};
plutus = if (cfg.plutus.type or null) == null then null else
{
inherit (cfg.plutus) type;
Expand Down Expand Up @@ -101,6 +111,38 @@ in pkgs.commonLib.defServiceModule
};

drep_voting = mayOpt bool "Activate DRep voting workload (mutually excl. with plutus)";
govAct = {
# My suspicion is that batches may be meant to correspond to
# epochs. The staging is then:
# 1. Issue all proposals to ever use at the beginning.
# 2. During each epoch (gapProposalBatches epochs?):
# A. vote on the gapBatchSize proposals in the batch
# B. stripe the votes cyclically across available DReps
# C. keep doing it for long enough to fill the epoch
# 3. When the grand total proposal pool runs out, stop
# trying to keep running the tx-generator in new epochs.
gapBatchSize = mayOpt int "Governance action batch size.";
gapProposalBatches = mayOpt int "Number of batches of proposals.";

# Bug, does the Conway genesis value need to be used?
# I likely had in mind the ShelleyGenesis sgUpdateQuorum
# It may not have been intended to be used for govAct votes.
# Is quorum logic even used for govActs?
# dRepVotingThresholds in the sample Conway genesis files seems
# to be closer to the fraction seen elsewhere.
# The controlling parameter seems to be the batch size.
# Voting thresholds would be fractions, which are meaningless
# because the only votes ever issued are Yes votes.
# There is no reason to use a quorum as a limit to the number
# of votes to issue, because the number of votes to issue is
# the gapBatchSize.
gapQuorum = opt int 51 "Number of votes needed to ratify proposals.";
# could be inconsistent with the number elsewhere
gapDRepKeys = mayOpt int "Number of DRep keys.";
gapStakeKeys = mayOpt int "Number of stake keys.";
gapTPS = opt (either float int) 0.2
"TPS of governeance actions";
};

# Overrides the usage of Nix Store paths by default.
plutusRedeemerFile = mayOpt str "Plutus redeemer file path.";
Expand Down

0 comments on commit 7913fc8

Please sign in to comment.