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

Add transaction generation to db-synthesizer #1048

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
51 changes: 42 additions & 9 deletions ouroboros-consensus-cardano/app/DBSynthesizer/Parsers.hs
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@

{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
module DBSynthesizer.Parsers (parseCommandLine) where

import Cardano.Tools.DBSynthesizer.Types
import Data.Word (Word64)
import Options.Applicative as Opt
import Ouroboros.Consensus.Block.Abstract (SlotNo (..))


parseCommandLine :: IO (NodeFilePaths, NodeCredentials, DBSynthesizerOptions)
parseCommandLine =
Opt.customExecParser p opts
import Cardano.Tools.DBSynthesizer.Tx
import Cardano.Ledger.Crypto
import Cardano.Ledger.Shelley.Genesis
import Cardano.Api.Any
import Cardano.Api.KeysShelley
import Cardano.Api.Key
import Cardano.Api.SerialiseTextEnvelope
import Cardano.Ledger.Credential
import Cardano.Ledger.Keys
import Cardano.Ledger.Address
import Cardano.Ledger.BaseTypes

parseCommandLine :: IO (NodeFilePaths, NodeCredentials, DBSynthesizerOptions, OwnedTxIn StandardCrypto)
parseCommandLine = do
(nfp, nc, dbso, genesisKeyPath) <- Opt.customExecParser p opts
(skey, cred) <- readFileTextEnvelope (AsSigningKey AsGenesisUTxOKey) genesisKeyPath >>= \case
Left e -> throwErrorAsException e
Right sk@(GenesisUTxOSigningKey k)
| GenesisUTxOVerificationKey vk <- getVerificationKey sk -> pure (k, KeyHashObj (hashKey vk))
pure ( nfp
, nc
, dbso
, OwnedTxIn
{ owned = initialFundsPseudoTxIn $ Addr Testnet cred StakeRefNull
, skey
}
)
where
p = Opt.prefs Opt.showHelpOnEmpty
opts = Opt.info parserCommandLine mempty

parserCommandLine :: Parser (NodeFilePaths, NodeCredentials, DBSynthesizerOptions)
parserCommandLine :: Parser (NodeFilePaths, NodeCredentials, DBSynthesizerOptions, FilePath)
parserCommandLine =
(,,)
(,,,)
<$> parseNodeFilePaths
<*> parseNodeCredentials
<*> parseDBSynthesizerOptions
<*> parseGenesisUTxOKeyPath

parseNodeFilePaths :: Parser NodeFilePaths
parseNodeFilePaths =
Expand Down Expand Up @@ -101,6 +124,16 @@ parseBulkFilePath =
<> completer (bashCompleter "file")
)

-- TODO Support arbitrary UTxOs not just genesis, on the command line
parseGenesisUTxOKeyPath :: Parser FilePath
parseGenesisUTxOKeyPath =
strOption
( long "genesis-utxo-signing-key-file"
<> metavar "FILE"
<> help "Path to the signing key file of the genesis UTxO to use to create UTxOs"
<> completer (bashCompleter "file")
)

parseSlotLimit :: Parser SlotNo
parseSlotLimit =
SlotNo <$> option auto
Expand Down
27 changes: 25 additions & 2 deletions ouroboros-consensus-cardano/app/db-synthesizer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,37 @@ module Main (main) where

import Cardano.Crypto.Init (cryptoInit)
import Cardano.Tools.DBSynthesizer.Run
import Cardano.Tools.DBSynthesizer.Tx
import DBSynthesizer.Parsers
import Main.Utf8 (withStdTerminalHandles)
import qualified Data.Set as Set
import System.Exit


main :: IO ()
main = withStdTerminalHandles $ do
cryptoInit
(paths, creds, forgeOpts) <- parseCommandLine
result <- initialize paths creds forgeOpts >>= either die (uncurry synthesize)
(paths, creds, forgeOpts, utxo) <- parseCommandLine
let
-- TODO Parse this from a config file
spec =
[ TxOutsSpec
{ duplicates = 14999999
, txOut = TxOutSpec
{ nativeAssets = []
, datum = Nothing
, delegation = DelegateHash
}
}
, TxOutsSpec
{ duplicates = 14999999
, txOut = TxOutSpec
{ nativeAssets = [ NativeAssetMintsSpec { nameLengths = Set.singleton 5 } ]
, datum = Just $ Inline 54
, delegation = NoDelegate
}
}
]
genTxs <- makeGenTxs utxo spec
result <- initialize paths creds forgeOpts >>= either die (uncurry (synthesize genTxs))
putStrLn $ "--> done; result: " ++ show result
19 changes: 15 additions & 4 deletions ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -470,20 +470,21 @@ library unstable-cardano-tools
Cardano.Tools.DBSynthesizer.Forging
Cardano.Tools.DBSynthesizer.Orphans
Cardano.Tools.DBSynthesizer.Run
Cardano.Tools.DBSynthesizer.Tx
Cardano.Tools.DBSynthesizer.Types
Cardano.Tools.DBTruncater.Run
Cardano.Tools.DBTruncater.Types
Cardano.Tools.GitRev
Cardano.Tools.ImmDBServer.Diffusion
Cardano.Tools.ImmDBServer.MiniProtocols
Cardano.Api.SerialiseTextEnvelope
Cardano.Api.KeysShelley
Cardano.Api.Key

other-modules:
Cardano.Api.Key
Cardano.Api.KeysByron
Cardano.Api.KeysPraos
Cardano.Api.KeysShelley
Cardano.Api.OperationalCertificate
Cardano.Api.SerialiseTextEnvelope
Cardano.Api.SerialiseUsing
Cardano.Node.Protocol.Alonzo
Cardano.Node.Protocol.Byron
Expand All @@ -493,10 +494,14 @@ library unstable-cardano-tools

build-depends:
, aeson
, time
, base >=4.14 && <4.20
, base16-bytestring >=1.0
, bytestring >=0.10 && <0.13
, cardano-crypto
, plutus-core
, groups
, plutus-ledger-api
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-git-rev ^>=0.2.1
Expand All @@ -518,6 +523,7 @@ library unstable-cardano-tools
, compact
, containers >=0.5 && <0.7
, contra-tracer
, data-default
, directory
, filepath
, fs-api ^>=0.2
Expand Down Expand Up @@ -582,8 +588,10 @@ executable db-synthesizer
build-depends:
, base
, cardano-crypto-class
, cardano-ledger-core
, cardano-ledger-shelley
, containers
, optparse-applicative
, ouroboros-consensus
, unstable-cardano-tools
, with-utf8

Expand Down Expand Up @@ -627,6 +635,9 @@ test-suite tools-test
build-depends:
, base
, ouroboros-consensus-cardano
, cardano-ledger-core
, cardano-ledger-shelley
, containers
, ouroboros-consensus:unstable-consensus-testlib
, tasty
, tasty-hunit
Expand Down
Loading