diff --git a/.gitignore b/.gitignore index f8fd82235..dc56fa03c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ cabal.project.local gen/ /.vscode -cardano-chain-gen/test/testfiles/temp/ \ No newline at end of file +cardano-chain-gen/test/testfiles/temp/ +cardano-chain-gen/bench/benchfiles/temp/ diff --git a/cabal.project b/cabal.project index 9b235b29f..58e381381 100644 --- a/cabal.project +++ b/cabal.project @@ -241,3 +241,11 @@ source-repository-package location: https://github.com/input-output-hk/cardano-config tag: e9de7a2cf70796f6ff26eac9f9540184ded0e4e6 --sha256: 1wm1c99r5zvz22pdl8nhkp13falvqmj8dgkm8fxskwa9ydqz01ld + +source-repository-package + type: git + location: https://github.com/kderme/criterion + tag: 642ab88e01ec07ebf5937c9788a541f61bcbe332 + subdir: + . + criterion-measurement diff --git a/cardano-chain-gen/bench/Cardano/Db/Bench.hs b/cardano-chain-gen/bench/Cardano/Db/Bench.hs new file mode 100644 index 000000000..12368652d --- /dev/null +++ b/cardano-chain-gen/bench/Cardano/Db/Bench.hs @@ -0,0 +1,304 @@ +module Cardano.Db.Bench where + +import Control.DeepSeq +import Control.Monad +import Control.Monad.Class.MonadSTM.Strict +import qualified Data.Text.Encoding as Text +import Data.List.Split +import qualified Data.Map as Map +import Data.Text (Text) + +import Ouroboros.Network.Block (Point (..)) + +import Cardano.Slotting.Slot + +import Cardano.Ledger.Address +import Cardano.Ledger.BaseTypes +import Cardano.Ledger.Credential +import Cardano.Ledger.Mary.Value +import Cardano.Ledger.Shelley.TxBody + +import Cardano.Mock.ChainSync.Server +import Cardano.Mock.Db.Config hiding (withFullConfig) +import qualified Cardano.Mock.Db.Config as Config +import Cardano.Mock.Db.Validate +import Cardano.Mock.Forging.Interpreter +import qualified Cardano.Mock.Forging.Tx.Alonzo as Alonzo +import Cardano.Mock.Forging.Tx.Generic +import Cardano.Mock.Forging.Types + +import Criterion + +benchmark :: IOManager -> [(Text, Text)] -> Benchmark +benchmark iom knownMigrations = + bgroup "bench" + [ bgroup "empty blocks" + [ bnch 3 "empty blocks 10" $ emptyBlocks 10 + , bnch 3 "empty blocks 10" $ emptyBlocks 50 + , bnch 3 "empty blocks 10" $ emptyBlocks 100 + , longBnch "empty blocks 10" $ emptyBlocks 500 + ] + , bgroup "register addresses 1000 per block" + [ bnch 3 "1 block" $ registerAddressess 1 + , bnch 3 "10 block" $ registerAddressess 10 + , bnch 3 "100 block" $ registerAddressess 100 + , bnch 3 "200 block" $ registerAddressess 200 + ] + , bgroup "create UTxO. 200 per block" + [ bnch 3 "1 block" $ createUTXO 1 + , bnch 3 "10 block" $ createUTXO 10 + , longBnch "100 block" $ createUTXO 100 + , longBnch "100 block" $ createUTXO 1000 + ] + , bgroup "create UTxO. 1000 per block" + [ bnch 3 "1 block" $ createUTXO' 1 + , bnch 3 "10 block" $ createUTXO' 10 + , longBnch "100 block" $ createUTXO' 100 + , longBnch "1000 block" $ createUTXO' 1000 + ] + , bgroup "create multiasssets." + [ bnch 3 "1 block" $ createMaTxOut 1 + , bnch 3 "10 block" $ createMaTxOut 10 + , longBnch "100 block" $ createMaTxOut 100 + ] + , bgroup "delegate and send funds" + [ bnch 3 "3 block" $ delegateAndSend 1 + , bnch 3 "30 block" $ delegateAndSend 10 + , longBnch "300 block" $ delegateAndSend 100 + , longBnch "1200 block" $ delegateAndSend 400 + ] + , bgroup "rollback multiassets" + [ bnch 3 "1 block" $ rollbackMaTxOut 1 + , bnch 3 "10 block" $ rollbackMaTxOut 10 + , longBnch "100 block" $ rollbackMaTxOut 100 + , longBnch "500 block" $ rollbackMaTxOut 500 + ] + , bgroup "delegate and send funds" + [ bnch 3 "3 block" $ delegateAndSend 1 + , bnch 3 "30 block" $ delegateAndSend 10 + , longBnch "300 block" $ createMaTxOut 100 + , longBnch "1200 block" $ delegateAndSend 400 + ] + ] + where + _bnch' :: String -> (IOManager -> [(Text, Text)] -> Benchmarkable) -> Benchmark + _bnch' str action = bench str (action iom knownMigrations) + + bnch :: Int -> String -> (IOManager -> [(Text, Text)] -> Benchmarkable) -> Benchmark + bnch n str action = bench str (fixIterations n $ action iom knownMigrations) + + longBnch :: String -> (IOManager -> [(Text, Text)] -> Benchmarkable) -> Benchmark + longBnch str = bnch 1 str + +data BenchEnv = BenchEnv Interpreter (ServerHandle IO CardanoBlock) DBSyncEnv [CardanoBlock] + +instance NFData BenchEnv where + -- We don't really use many feautures of criterion. 'NFData' is not one of them. + rnf _ = () + +defaultConfigDir :: FilePath +defaultConfigDir = "config" + +rootTestDir :: FilePath +rootTestDir = "bench/benchfiles" + +withFullConfig :: FilePath -> FilePath + -> (Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO ()) + -> IOManager -> [(Text, Text)] -> IO () +withFullConfig = Config.withFullConfig rootTestDir + +benchmarkSyncing :: FilePath -> FilePath -> FilePath + -> (Interpreter -> IO [CardanoBlock]) + -> IOManager -> [(Text, Text)] + -> Benchmarkable +benchmarkSyncing rootDir config testLabel mkBlocks iom mig = + perRunEnvWithCleanup createEnv cleanupEnv runBench + where + createEnv :: IO BenchEnv + createEnv = do + (interpreter, mockServer, dbSync) <- mkFullConfig rootDir config testLabel iom mig + -- first block server and then start db-sync during env creation, so that + -- schema migrations doesn't affect benchmarking results.\ + atomically $ blockServing mockServer + startDBSync dbSync + blks <- mkBlocks interpreter + _ <- forM blks $ atomically . addBlock mockServer + -- This is here to wait for all migration to run before running the benchmark + assertBlocksCount dbSync 2 + pure $ BenchEnv interpreter mockServer dbSync blks + + cleanupEnv (BenchEnv interpreter mockServer dbSync _blks) = do + cleanFullConfig (interpreter, mockServer, dbSync) + + runBench (BenchEnv _interpreter mockServer dbSync blks) = do + -- unblock the server and wait for the blocks in db. + atomically $ unBlockServing mockServer + assertBlockNo dbSync (Just $ length blks - 1) [1,1..] + + +benchmarkRollback :: FilePath -> FilePath -> FilePath + -> (Interpreter -> IO [CardanoBlock]) + -> IOManager -> [(Text, Text)] + -> Benchmarkable +benchmarkRollback rootDir config testLabel mkBlocks iom mig = + perRunEnvWithCleanup createEnv cleanupEnv runBench + where + createEnv :: IO BenchEnv + createEnv = do + (interpreter, mockServer, dbSync) <- mkFullConfig rootDir config testLabel iom mig + startDBSync dbSync + blks <- mkBlocks interpreter + _ <- forM blks $ atomically . addBlock mockServer + -- Sync all blocks in db-sync + assertBlockNoBackoff dbSync (length blks - 1) + pure $ BenchEnv interpreter mockServer dbSync blks + + cleanupEnv (BenchEnv interpreter mockServer dbSync _blks) = do + cleanFullConfig (interpreter, mockServer, dbSync) + + runBench (BenchEnv _interpreter mockServer dbSync _blks) = do + -- unblock the server and wait for the blocks in db. + atomically $ rollback mockServer (Point Origin) + assertBlockNo dbSync Nothing [1,1..] + + +emptyBlocks :: Int -> IOManager -> [(Text, Text)] -> Benchmarkable +emptyBlocks n = + benchmarkSyncing rootTestDir defaultConfigDir testLabel $ \interpreter -> + replicateM n $ forgeNextFindLeader interpreter [] + where + testLabel = "emptyBlock_" <> show n + +registerAddressess :: Int -> IOManager -> [(Text, Text)] -> Benchmarkable +registerAddressess n = + benchmarkSyncing rootTestDir defaultConfigDir testLabel $ + registerAddressesBlocks n + where + testLabel = "registerAddressess_" <> show n + +registerAddressesBlocks :: Int -> Interpreter -> IO [CardanoBlock] +registerAddressesBlocks n interpreter = do + forM (chunksOf 1000 creds) $ \blockCreds -> do + blockTxs <- withAlonzoLedgerState interpreter $ \_st -> + forM (chunksOf 10 blockCreds) $ \txCreds -> -- 10 per tx + Alonzo.mkDCertTx (fmap (DCertDeleg . RegKey) txCreds) (Wdrl mempty) + forgeNextFindLeader interpreter (TxAlonzo <$> blockTxs) + where + creds = createStakeCredentials (1000 * n) + +createUTXO :: Int -> IOManager -> [(Text, Text)] -> Benchmarkable +createUTXO n = + benchmarkSyncing rootTestDir defaultConfigDir testLabel $ + createUTXOBlocks n + where + testLabel = "createUTXO_" <> show n + +-- 200 txs per block. 1 outputs per tx +createUTXOBlocks :: Int -> Interpreter -> IO [CardanoBlock] +createUTXOBlocks n interpreter = do + addr <- withAlonzoLedgerState interpreter $ resolveAddress (UTxOIndex 0) + -- we use the change output to create the next transaction. + let utxoIndex = UTxOAddress addr + forM (chunksOf 200 addresses) $ \blockAddresses -> do + blockTxs <- withAlonzoLedgerState interpreter $ \st -> + forM blockAddresses $ \sendAddr -> + Alonzo.mkPaymentTx utxoIndex (UTxOAddress sendAddr) 1 0 st + forgeNextFindLeader interpreter (TxAlonzo <$> blockTxs) + where + addresses = fmap (\addr -> Addr Testnet addr StakeRefNull) (createPaymentCredentials (200 * n)) + +createUTXO' :: Int -> IOManager -> [(Text, Text)] -> Benchmarkable +createUTXO' n = + benchmarkSyncing rootTestDir defaultConfigDir testLabel $ + createUTXOBlocks' n + where + testLabel = "createUTXO'_" <> show n + +-- 100 txs per block. 10 outputs per tx +createUTXOBlocks' :: Int -> Interpreter -> IO [CardanoBlock] +createUTXOBlocks' n interpreter = do + addrFrom <- withAlonzoLedgerState interpreter $ resolveAddress (UTxOIndex 0) + -- we use the change output to create the next transaction. + let utxoIndex = UTxOAddress addrFrom + forM (chunksOf 1000 addresses) $ \blockAddresses -> do + blockTxs <- withAlonzoLedgerState interpreter $ \st -> + forM (chunksOf 10 blockAddresses) $ \txAddresses -> + Alonzo.mkPaymentTx' utxoIndex (fmap (\addr -> (UTxOAddress addr, Value 1 mempty)) txAddresses) st + forgeNextFindLeader interpreter (TxAlonzo <$> blockTxs) + where + addresses = fmap (\addr -> Addr Testnet addr StakeRefNull) (createPaymentCredentials (1000 * n)) + +createMaTxOut :: Int -> IOManager -> [(Text, Text)] -> Benchmarkable +createMaTxOut n = + benchmarkSyncing rootTestDir defaultConfigDir testLabel $ + createMaTxOutBlocks n + where + testLabel = "createMaTxOut_" <> show n + +rollbackMaTxOut :: Int -> IOManager -> [(Text, Text)] -> Benchmarkable +rollbackMaTxOut n = + benchmarkRollback rootTestDir defaultConfigDir testLabel $ + createMaTxOutBlocks n + where + testLabel = "rollbackMaTxOut_" <> show n + +createMaTxOutBlocks :: Int -> Interpreter -> IO [CardanoBlock] +createMaTxOutBlocks n interpreter = do + addrFrom <- withAlonzoLedgerState interpreter $ resolveAddress (UTxOIndex 0) + -- we use the change output to create the next transaction. + let utxoIndex = UTxOAddress addrFrom + forM (zip [1..n] $ chunksOf 1000 addresses) $ \(_blockId, blockAddresses) -> do + blockTxs <- withAlonzoLedgerState interpreter $ \st -> + forM (zip [1..100] $ chunksOf 10 blockAddresses) $ \(txId, txAddresses) -> + let maMap = Map.fromList $ flip fmap [0..9] $ \maIndex -> + let assets = Map.fromList $ flip fmap [0..9] $ \assetIx -> + (AssetName $ Text.encodeUtf8 $ textShow (100 * assetIx + maIndex), 1) + in (PolicyID (mkDummyScriptHash $ 10 * maIndex + txId `mod` 10), assets) + in Alonzo.mkPaymentTx' utxoIndex (fmap (\addr -> (UTxOAddress addr, Value 1 maMap)) txAddresses) st + forgeNextFindLeader interpreter (TxAlonzo <$> blockTxs) + where + addresses = fmap (\addr -> Addr Testnet addr StakeRefNull) (createPaymentCredentials (1000 * n)) + +delegateAndSend :: Int -> IOManager -> [(Text, Text)] -> Benchmarkable +delegateAndSend n = + benchmarkSyncing rootTestDir defaultConfigDir testLabel $ + delegateAndSendBlocks n + where + testLabel = "delegateAndSend_" <> show n + +rollbackDelegateAndSend :: Int -> IOManager -> [(Text, Text)] -> Benchmarkable +rollbackDelegateAndSend n = + benchmarkRollback rootTestDir defaultConfigDir testLabel $ + delegateAndSendBlocks n + where + testLabel = "rollbackDelegateAndSend_" <> show n + +delegateAndSendBlocks :: Int -> Interpreter -> IO [CardanoBlock] +delegateAndSendBlocks n interpreter = do + addrFrom <- withAlonzoLedgerState interpreter $ resolveAddress (UTxOIndex 0) + registerBlocks <- forM (chunksOf 1000 creds) $ \blockCreds -> do + blockTxs <- withAlonzoLedgerState interpreter $ \_st -> + forM (chunksOf 10 blockCreds) $ \txCreds -> -- 10 per tx + Alonzo.mkDCertTx (fmap (DCertDeleg . RegKey) txCreds) (Wdrl mempty) + forgeNextFindLeader interpreter (TxAlonzo <$> blockTxs) + + delegateBlocks <- forM (chunksOf 1000 creds) $ \blockCreds -> do + blockTxs <- withAlonzoLedgerState interpreter $ \st -> + forM (chunksOf 10 blockCreds) $ \txCreds -> --do -- 10 per tx + Alonzo.mkDCertTx + (fmap (\ (poolIx, cred) -> DCertDeleg $ Delegate $ Delegation cred (resolvePool (PoolIndex poolIx) st)) + (zip (cycle [0,1,2]) txCreds)) + (Wdrl mempty) + forgeNextFindLeader interpreter (TxAlonzo <$> blockTxs) + + let utxoIndex = UTxOAddress addrFrom + sendBlocks <- forM (chunksOf 1000 addresses) $ \blockAddresses -> do + blockTxs <- withAlonzoLedgerState interpreter $ \st -> + forM (chunksOf 10 blockAddresses) $ \txAddresses -> + Alonzo.mkPaymentTx' utxoIndex (fmap (\addr -> (UTxOAddress addr, Value 1 mempty)) txAddresses) st + forgeNextFindLeader interpreter (TxAlonzo <$> blockTxs) + pure $ registerBlocks <> delegateBlocks <> sendBlocks + where + creds = createStakeCredentials (1000 * n) + pcreds = createPaymentCredentials (1000 * n) + addresses = fmap (\(pcred, cred) -> Addr Testnet pcred (StakeRefBase cred)) (zip pcreds creds) diff --git a/cardano-chain-gen/bench/Main.hs b/cardano-chain-gen/bench/Main.hs new file mode 100644 index 000000000..7fe07e9ea --- /dev/null +++ b/cardano-chain-gen/bench/Main.hs @@ -0,0 +1,48 @@ +import Cardano.Prelude (Text) + +import Prelude + +import Control.Monad (when, (>=>)) +import Data.Maybe (isNothing) + +import System.Directory (getCurrentDirectory) +import System.Environment (lookupEnv, setEnv) +import System.FilePath (()) + +import MigrationValidations (KnownMigration (..), knownMigrations) + +import Cardano.Mock.ChainSync.Server + +import Criterion.Main + +import qualified Cardano.Db.Bench as Bench + +main :: IO () +main = do + -- If the env is not set, set it to default. + mPgPassFile <- lookupEnv "PGPASSFILE" + when (isNothing mPgPassFile) $ do + currentDir <- getCurrentDirectory + setEnv "PGPASSFILE" (currentDir "bench/benchfiles/pgpass-bench") + withIOManager $ + benchmarks >=> defaultMain + where +-- config = defaultConfig +-- { resamples = 1 +-- , reportFile = Just "report.html" +-- , csvFile = Just "report.csv" +-- , jsonFile = Just "reprt.json" +-- , junitFile = Just "report.junit" +-- } + +benchmarks :: IOManager -> IO [Benchmark] +benchmarks iom = do + pure $ + [ bgroup + "cardano-chain" + [ Bench.benchmark iom knownMigrationsPlain + ] + ] + where + knownMigrationsPlain :: [(Text, Text)] + knownMigrationsPlain = (\x -> (hash x, filepath x)) <$> knownMigrations diff --git a/cardano-chain-gen/bench/benchfiles/config/genesis.alonzo.json b/cardano-chain-gen/bench/benchfiles/config/genesis.alonzo.json new file mode 100644 index 000000000..bcc2d3176 --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/config/genesis.alonzo.json @@ -0,0 +1,188 @@ +{ + "collateralPercentage": 1, + "maxBlockExUnits": { + "exUnitsMem": 500000000000, + "exUnitsSteps": 500000000000 + }, + "maxCollateralInputs": 5, + "maxValueSize": 4000, + "costModels": { + "PlutusV1": { + "sha2_256-memory-arguments": 4, + "equalsString-cpu-arguments-constant": 1000, + "cekDelayCost-exBudgetMemory": 100, + "lessThanEqualsByteString-cpu-arguments-intercept": 103599, + "divideInteger-memory-arguments-minimum": 1, + "appendByteString-cpu-arguments-slope": 621, + "blake2b-cpu-arguments-slope": 29175, + "iData-cpu-arguments": 150000, + "encodeUtf8-cpu-arguments-slope": 1000, + "unBData-cpu-arguments": 150000, + "multiplyInteger-cpu-arguments-intercept": 61516, + "cekConstCost-exBudgetMemory": 100, + "nullList-cpu-arguments": 150000, + "equalsString-cpu-arguments-intercept": 150000, + "trace-cpu-arguments": 150000, + "mkNilData-memory-arguments": 32, + "lengthOfByteString-cpu-arguments": 150000, + "cekBuiltinCost-exBudgetCPU": 29773, + "bData-cpu-arguments": 150000, + "subtractInteger-cpu-arguments-slope": 0, + "unIData-cpu-arguments": 150000, + "consByteString-memory-arguments-intercept": 0, + "divideInteger-memory-arguments-slope": 1, + "divideInteger-cpu-arguments-model-arguments-slope": 118, + "listData-cpu-arguments": 150000, + "headList-cpu-arguments": 150000, + "chooseData-memory-arguments": 32, + "equalsInteger-cpu-arguments-intercept": 136542, + "sha3_256-cpu-arguments-slope": 82363, + "sliceByteString-cpu-arguments-slope": 5000, + "unMapData-cpu-arguments": 150000, + "lessThanInteger-cpu-arguments-intercept": 179690, + "mkCons-cpu-arguments": 150000, + "appendString-memory-arguments-intercept": 0, + "modInteger-cpu-arguments-model-arguments-slope": 118, + "ifThenElse-cpu-arguments": 1, + "mkNilPairData-cpu-arguments": 150000, + "lessThanEqualsInteger-cpu-arguments-intercept": 145276, + "addInteger-memory-arguments-slope": 1, + "chooseList-memory-arguments": 32, + "constrData-memory-arguments": 32, + "decodeUtf8-cpu-arguments-intercept": 150000, + "equalsData-memory-arguments": 1, + "subtractInteger-memory-arguments-slope": 1, + "appendByteString-memory-arguments-intercept": 0, + "lengthOfByteString-memory-arguments": 4, + "headList-memory-arguments": 32, + "listData-memory-arguments": 32, + "consByteString-cpu-arguments-intercept": 150000, + "unIData-memory-arguments": 32, + "remainderInteger-memory-arguments-minimum": 1, + "bData-memory-arguments": 32, + "lessThanByteString-cpu-arguments-slope": 248, + "encodeUtf8-memory-arguments-intercept": 0, + "cekStartupCost-exBudgetCPU": 100, + "multiplyInteger-memory-arguments-intercept": 0, + "unListData-memory-arguments": 32, + "remainderInteger-cpu-arguments-model-arguments-slope": 118, + "cekVarCost-exBudgetCPU": 29773, + "remainderInteger-memory-arguments-slope": 1, + "cekForceCost-exBudgetCPU": 29773, + "sha2_256-cpu-arguments-slope": 29175, + "equalsInteger-memory-arguments": 1, + "indexByteString-memory-arguments": 1, + "addInteger-memory-arguments-intercept": 1, + "chooseUnit-cpu-arguments": 150000, + "sndPair-cpu-arguments": 150000, + "cekLamCost-exBudgetCPU": 29773, + "fstPair-cpu-arguments": 150000, + "quotientInteger-memory-arguments-minimum": 1, + "decodeUtf8-cpu-arguments-slope": 1000, + "lessThanInteger-memory-arguments": 1, + "lessThanEqualsInteger-cpu-arguments-slope": 1366, + "fstPair-memory-arguments": 32, + "modInteger-memory-arguments-intercept": 0, + "unConstrData-cpu-arguments": 150000, + "lessThanEqualsInteger-memory-arguments": 1, + "chooseUnit-memory-arguments": 32, + "sndPair-memory-arguments": 32, + "addInteger-cpu-arguments-intercept": 197209, + "decodeUtf8-memory-arguments-slope": 8, + "equalsData-cpu-arguments-intercept": 150000, + "mapData-cpu-arguments": 150000, + "mkPairData-cpu-arguments": 150000, + "quotientInteger-cpu-arguments-constant": 148000, + "consByteString-memory-arguments-slope": 1, + "cekVarCost-exBudgetMemory": 100, + "indexByteString-cpu-arguments": 150000, + "unListData-cpu-arguments": 150000, + "equalsInteger-cpu-arguments-slope": 1326, + "cekStartupCost-exBudgetMemory": 100, + "subtractInteger-cpu-arguments-intercept": 197209, + "divideInteger-cpu-arguments-model-arguments-intercept": 425507, + "divideInteger-memory-arguments-intercept": 0, + "cekForceCost-exBudgetMemory": 100, + "blake2b-cpu-arguments-intercept": 2477736, + "remainderInteger-cpu-arguments-constant": 148000, + "tailList-cpu-arguments": 150000, + "encodeUtf8-cpu-arguments-intercept": 150000, + "equalsString-cpu-arguments-slope": 1000, + "lessThanByteString-memory-arguments": 1, + "multiplyInteger-cpu-arguments-slope": 11218, + "appendByteString-cpu-arguments-intercept": 396231, + "lessThanEqualsByteString-cpu-arguments-slope": 248, + "modInteger-memory-arguments-slope": 1, + "addInteger-cpu-arguments-slope": 0, + "equalsData-cpu-arguments-slope": 10000, + "decodeUtf8-memory-arguments-intercept": 0, + "chooseList-cpu-arguments": 150000, + "constrData-cpu-arguments": 150000, + "equalsByteString-memory-arguments": 1, + "cekApplyCost-exBudgetCPU": 29773, + "quotientInteger-memory-arguments-slope": 1, + "verifySignature-cpu-arguments-intercept": 3345831, + "unMapData-memory-arguments": 32, + "mkCons-memory-arguments": 32, + "sliceByteString-memory-arguments-slope": 1, + "sha3_256-memory-arguments": 4, + "ifThenElse-memory-arguments": 1, + "mkNilPairData-memory-arguments": 32, + "equalsByteString-cpu-arguments-slope": 247, + "appendString-cpu-arguments-intercept": 150000, + "quotientInteger-cpu-arguments-model-arguments-slope": 118, + "cekApplyCost-exBudgetMemory": 100, + "equalsString-memory-arguments": 1, + "multiplyInteger-memory-arguments-slope": 1, + "cekBuiltinCost-exBudgetMemory": 100, + "remainderInteger-memory-arguments-intercept": 0, + "sha2_256-cpu-arguments-intercept": 2477736, + "remainderInteger-cpu-arguments-model-arguments-intercept": 425507, + "lessThanEqualsByteString-memory-arguments": 1, + "tailList-memory-arguments": 32, + "mkNilData-cpu-arguments": 150000, + "chooseData-cpu-arguments": 150000, + "unBData-memory-arguments": 32, + "blake2b-memory-arguments": 4, + "iData-memory-arguments": 32, + "nullList-memory-arguments": 32, + "cekDelayCost-exBudgetCPU": 29773, + "subtractInteger-memory-arguments-intercept": 1, + "lessThanByteString-cpu-arguments-intercept": 103599, + "consByteString-cpu-arguments-slope": 1000, + "appendByteString-memory-arguments-slope": 1, + "trace-memory-arguments": 32, + "divideInteger-cpu-arguments-constant": 148000, + "cekConstCost-exBudgetCPU": 29773, + "encodeUtf8-memory-arguments-slope": 8, + "quotientInteger-cpu-arguments-model-arguments-intercept": 425507, + "mapData-memory-arguments": 32, + "appendString-cpu-arguments-slope": 1000, + "modInteger-cpu-arguments-constant": 148000, + "verifySignature-cpu-arguments-slope": 1, + "unConstrData-memory-arguments": 32, + "quotientInteger-memory-arguments-intercept": 0, + "equalsByteString-cpu-arguments-constant": 150000, + "sliceByteString-memory-arguments-intercept": 0, + "mkPairData-memory-arguments": 32, + "equalsByteString-cpu-arguments-intercept": 112536, + "appendString-memory-arguments-slope": 1, + "lessThanInteger-cpu-arguments-slope": 497, + "modInteger-cpu-arguments-model-arguments-intercept": 425507, + "modInteger-memory-arguments-minimum": 1, + "sha3_256-cpu-arguments-intercept": 0, + "verifySignature-memory-arguments": 1, + "cekLamCost-exBudgetMemory": 100, + "sliceByteString-cpu-arguments-intercept": 150000 + } + }, + "executionPrices": { + "prMem": 0.1, + "prSteps": 0.1 + }, + "lovelacePerUTxOWord": 1, + "maxTxExUnits": { + "exUnitsMem": 500000000000, + "exUnitsSteps": 500000000000 + } +} \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/config/genesis.byron.json b/cardano-chain-gen/bench/benchfiles/config/genesis.byron.json new file mode 100644 index 000000000..cf088f937 --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/config/genesis.byron.json @@ -0,0 +1,31 @@ +{ "bootStakeholders": + { "1a3e49767796fd99b057ad54db3310fd640806fcb0927399bbca7b43": 1 } +, "heavyDelegation": + { } +, "startTime": 1637266922 +, "nonAvvmBalances": + { } +, "blockVersionData": + { "scriptVersion": 0 + , "slotDuration": "20000" + , "maxBlockSize": "2000000" + , "maxHeaderSize": "2000000" + , "maxTxSize": "4096" + , "maxProposalSize": "700" + , "mpcThd": "20000000000000" + , "heavyDelThd": "300000000000" + , "updateVoteThd": "1000000000000" + , "updateProposalThd": "100000000000000" + , "updateImplicit": "10000" + , "softforkRule": + { "initThd": "900000000000000" + , "minThd": "600000000000000" + , "thdDecrement": "50000000000000" + } + , "txFeePolicy": + { "summand": "155381000000000" , "multiplier": "43946000000" } + , "unlockStakeEpoch": "18446744073709551615" + } +, "protocolConsts": { "k": 216 , "protocolMagic": 42 } +, "avvmDistr": {} +} diff --git a/cardano-chain-gen/bench/benchfiles/config/genesis.json b/cardano-chain-gen/bench/benchfiles/config/genesis.json new file mode 100644 index 000000000..4a73b7c9e --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/config/genesis.json @@ -0,0 +1,109 @@ +{ + "maxLovelaceSupply": 60000000, + "securityParam": 216, + "slotsPerKESPeriod": 129600, + "updateQuorum": 5, + "activeSlotsCoeff": 0.2, + "protocolParams": { + "minUTxOValue": 0, + "eMax": 18, + "extraEntropy": { + "tag": "NeutralNonce" + }, + "minFeeB": 0, + "tau": 0.0, + "maxBlockBodySize": 65536, + "maxTxSize": 16384, + "minPoolCost": 0, + "minFeeA": 1, + "nOpt": 3, + "maxBlockHeaderSize": 1100, + "keyDeposit": 0, + "poolDeposit": 0, + "protocolVersion": { + "minor": 0, + "major": 6 + }, + "a0": 0.3, + "rho": 0.0, + "decentralisationParam": 0 + }, + "networkMagic": 42, + "initialFunds": { + "00ae51de0c8e130f9ec51755f163258fe661e95e2648080f8e5c9583571b9b85d81adacab01fd7ee2f6e1619a0ca67b619a849bbb069ef0e42": 900000, + "005fdb717fabe97938da294e151d96b4af375bea38d176021edb9975b8921c25093b263793a1baf36166b819543f5822c62f725715a4136b39": 900000, + "60b13227c296440956c2a014359d6d83e9a854deec46471b57bd2ed2b6": 900000, + "60959e277d0f9213ac343e7841dc247089879585c9b6f49e8e0a0e8ce7": 900000, + "607903a7c2c29c52a963f40cf58357cb5bae37e2d57e2463b51e747efb": 900000, + "00c34b6acfb276a6ec529b3ab56d56988dcd8968647ceeebc28be28751ed15a48df4d479feca6e418ad433041bce1e94cc58d0e104455189bf": 900000, + "005fdb717fabe97938da294e151d96b4af375bea38d176021ed1111111921c25093b263793a1baf36166b819543f5822c62f72571111111111": 900000, + "005fdb717fabe97938da294e151d96b4af375bea38d176021ed222222295be61304693df94ba89ff989e6542f174bb10d5ff49e8e8b1292519": 900000, + "005fdb717fabe97938da294e151d96b4af375bea38d176021ed3333333921c25093b263793a1baf36166b819543f5822c62f72573333333333": 900000, + "005fdb717fabe97938da294e151d96b4af375bea38d176021ed1231231b09771da66c23a23450a53420f25b609cfa3b776068da27bee2371e1": 900000 + }, + "networkId": "Testnet", + "maxKESEvolutions": 60, + "genDelegs": { }, + "slotLength": 1, + "systemStart": "2021-11-18T20:22:02Z", + "epochLength": 43200, + "staking": { + "pools": { + "9f1b441b9b781b3c3abb43b25679dc17dbaaf116dddca1ad09dc1de0": { + "publicKey": "9f1b441b9b781b3c3abb43b25679dc17dbaaf116dddca1ad09dc1de0", + "cost": 5, + "metadata": null, + "owners": [], + "vrf": "a78358019b160775d7b04f7c5e06462e1469823cead9b005c941ecefcc386c51", + "pledge": 0, + "margin": 0.01, + "rewardAccount": { + "network": "Testnet", + "credential": { + "key hash": "addfa484e8095ff53f45b25cf337923cf79abe6ec192fdf288d621f9" + } + }, + "relays": [] + }, + "5af582399de8c226391bfd21424f34d0b053419c4d93975802b7d107": { + "publicKey": "5af582399de8c226391bfd21424f34d0b053419c4d93975802b7d107", + "cost": 5, + "metadata": null, + "owners": ["95be61304693df94ba89ff989e6542f174bb10d5ff49e8e8b1292519"], + "vrf": "71833bb9a56532e952bdb30f5f2773ec375d0e02e81a5374246485979012b02a", + "pledge": 0, + "margin": 0.01, + "rewardAccount": { + "network": "Testnet", + "credential": { + "key hash": "95be61304693df94ba89ff989e6542f174bb10d5ff49e8e8b1292519" + } + }, + "relays": [] + }, + "58eef2925db2789f76ea057c51069e52c5e0a44550f853c6cdf620f8": { + "publicKey": "58eef2925db2789f76ea057c51069e52c5e0a44550f853c6cdf620f8", + "cost": 100, + "metadata": null, + "owners": ["921c25093b263793a1baf36166b819543f5822c62f72573333333333"], + "vrf": "8ce25eb830d7f4f7b79e65de7392dab4a156e0298446df022b6175fcaf7aba27", + "pledge": 0, + "margin": 0.01, + "rewardAccount": { + "network": "Testnet", + "credential": { + "key hash": "b09771da66c23a23450a53420f25b609cfa3b776068da27bee2371e1" + } + }, + "relays": [] + } + }, + "stake": { + "921c25093b263793a1baf36166b819543f5822c62f725715a4136b39": "58eef2925db2789f76ea057c51069e52c5e0a44550f853c6cdf620f8", + "ed15a48df4d479feca6e418ad433041bce1e94cc58d0e104455189bf": "5af582399de8c226391bfd21424f34d0b053419c4d93975802b7d107", + "1b9b85d81adacab01fd7ee2f6e1619a0ca67b619a849bbb069ef0e42": "9f1b441b9b781b3c3abb43b25679dc17dbaaf116dddca1ad09dc1de0", + "b09771da66c23a23450a53420f25b609cfa3b776068da27bee2371e1": "58eef2925db2789f76ea057c51069e52c5e0a44550f853c6cdf620f8", + "95be61304693df94ba89ff989e6542f174bb10d5ff49e8e8b1292519": "9f1b441b9b781b3c3abb43b25679dc17dbaaf116dddca1ad09dc1de0" + } + } +} \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/config/genesis.spec.json b/cardano-chain-gen/bench/benchfiles/config/genesis.spec.json new file mode 100644 index 000000000..b43b36f56 --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/config/genesis.spec.json @@ -0,0 +1,43 @@ +{ + "maxLovelaceSupply": 0, + "securityParam": 2160, + "slotsPerKESPeriod": 129600, + "updateQuorum": 5, + "activeSlotsCoeff": 5.0e-2, + "protocolParams": { + "minUTxOValue": 0, + "eMax": 18, + "extraEntropy": { + "tag": "NeutralNonce" + }, + "minFeeB": 0, + "tau": 0.0, + "maxBlockBodySize": 65536, + "maxTxSize": 16384, + "minPoolCost": 0, + "minFeeA": 1, + "nOpt": 100, + "maxBlockHeaderSize": 1100, + "keyDeposit": 0, + "poolDeposit": 0, + "protocolVersion": { + "minor": 0, + "major": 0 + }, + "a0": 0.0, + "rho": 0.0, + "decentralisationParam": 1.0 + }, + "networkMagic": 42, + "initialFunds": {}, + "networkId": "Testnet", + "maxKESEvolutions": 60, + "genDelegs": {}, + "slotLength": 1, + "systemStart": "1970-01-01T00:00:00Z", + "epochLength": 432000, + "staking": { + "pools": {}, + "stake": {} + } +} \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/config/pools/bulk1.creds b/cardano-chain-gen/bench/benchfiles/config/pools/bulk1.creds new file mode 100644 index 000000000..f0216586b --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/config/pools/bulk1.creds @@ -0,0 +1 @@ +[[{"cborHex":"8284582091bb7c5b3b409250d63addeaa4f41123c78b703d2612516a3c059f7c2b1e15310000584071ce22482933f85ffddf9cb90778cb0248ebe441b2697d413f9225b01ce786e2a120c227ec96ca8d713157758cf0ea45cc7723d2d9f3f9adad219500b3c6c80e582057ed87e13cbdc2fec8a4ebc6242b76d6c71fa483d3813799a2cb3eb710d1f577","description":"","type":"NodeOperationalCertificate"},{"cborHex":"58403467216a6c6555397c57c79830c9723ddc8668fc9c44c50386193a2ea559887bf8f07e0ad5c29d6080333329fa971867061ffeba0c30f2672fe5809f461b6ecb","description":"VRF Signing Key","type":"VrfSigningKey_PraosVRF"},{"cborHex":"590260d4ea8d759ab61e5dce8b6dfea931cd9e3918ea61d2870152a6146553c323bb7de6713109f8b9ac327796747cc3c85a48678d89cb3f09901b1c57dd2bd1dbc8a8e0f5fd64ce2c5c994e3382320a97ee17341bba737c92bfff4f1e213b5f606f32f91989d2a1b255cb8620abb8667ef3831eb752953052925412aea10b5a2b8649c3aadb079a19dee0387404d161804028f42984c44d6c90ce6366535acf6d712c973068222b6bd646cf037fa0b2aec7ab924a0a6668aebfb53282f6dd1baedd349909d3150dfd06068bd35efcd4db9cca6d9f43ec25864fbc2ee781ac7f9f0bd566544eb374e4663fbe18b513ac13a15c0c2b9dd5607d43c09afbf66ca70651cfc980562e4d69bb7d986f8203cd6c723463b0603e45a3be8ec288b40435d6c4c763122657892f5a558d7a1b52f435b2ae0727d3ef8ae37dee24cc1091002d33b2c9a46ffad59ead9c39e285a65b4911e7579b67550426765eff92d0bb47dd66c452df274d42aacb03ed094b698e2e5d2e188dbed041ae7bf2ee57d3fe7934d038c3a6920347d646eca70d6f403f2b5db5a37ecb1d39e593c1ed19838e2b6dc26228f03bc56f73495e17bc4b78b0ea16f7ef6eaef6ba11dd63d0807720cafd80c978b76c42b86bffc4b32710cba203656afb69fb266934869d2be758f33787f2365f5d65fe19a6a9c546c165cff0ff805fef2281b0b24706be9750c0401467aab795dfc931f3d8e943b7fe877c09816100a4bb1667cfe9753d9cf2477275e4eaef45aee37fa658cab049f8645b32447a0358df23f82f96f624bb0432486b9e755e179faef04387cb15210a2d17d147cbd693a3d56e1b899e3a66bd4d3dc1d4634d","description":"KES Signing Key","type":"KesSigningKey_ed25519_kes_2^6"}],[{"cborHex":"82845820970179a0f36e39aa8bb4095dc4fb219e8382d0ba20ec9b235c458e636d1e596f0000584098aad60b0bfbfda4981ba5f92b07a6b09990e7364191bf6d34558f15f39b51a04a07c852c4255a484353c5a0f325e79c448099fb3d859c12216029bd97f6090c5820d478654ee2c301f78446db60537377f69875ffcba2781a81c0e2bf3c77209410","description":"","type":"NodeOperationalCertificate"},{"cborHex":"58409da4aabcc214be4a6f7dd3efe77b1809c969edf867f3e592b6a84fd3ce2f33134f50bf8a1710b0854ba79a9a7e90c5b6a3082d4608d057e5ab432c933f293767","description":"VRF Signing Key","type":"VrfSigningKey_PraosVRF"},{"cborHex":"590260a65014be8d192af8cd1be12ed2e3aff1744f92bfea2406948344f4a6f07f5d92cfc2561ac2d8c8a52e3001c6b4d52c04dcedacc0bbf3e48a43dd230c5a6cbc2803922803a9c2245f0634e96d50b395644609794811b7d07f69fb8642af58a3fd51566a15976f198dd61ac47812d021c298038cca5af7f69d9be3b280c4d50e2f75c21a414cbecaf4ed3229563ca26934906df54d7e10a5d7e579cb34ce6d1932ac015fbd8c34610d7b63e42ac208fe5cee7c78938a61c57d7f5c917d70dfd7dfc456ffcd745b64d3aa282368e71dd22f2631eec3df03f6c482724936a3b687dc6c9f4f332cf1e185eceef8d8de538948aec9d0e1dcb9cc252db3eb722af488a3adcef9ecb560c737cfe736d5d89ea2cd0e38d5ddffb5a5f8645ce9acc1ece25ba1cac3c1e0b43d22d4479d4daa703b0cc95ec6954d90c7a5d4feae748417c01db58f6dc1f0e256bf0e886ec1268d7bd3ef603c999cdc3e431a3d823d2ae70353504baff71b1e308f410f3c6eea3f4fc3390771cca3625bde1afe4b1bce88c60e3472719fe716a5fe34e6adc94c9407c31e3837df08c2206e8f6462b7889c00c5a1b2e129abdc312131b2591affcce31ef301f136cc91a2453d11fe0bd03885284d8622c3b48fc1209fd1f802caa1028f8efd72f7b180eae644eb0134429ddd7f6035c8b1d696e33deff624faceec6fe1092f837ddb96ba5e5cf9ea145ec1d56527945ef3e0bb80245643dc1766bc0fcce58dcfdd718c3b84334def83d41f5ed693dfab9ce3f9ac2509929f4beef897dee36940c9f8a26ce577707d4a3125c08c6807a00f88d040da929cefb6f6b76494358e07f2e278bb5e7c6ee8a83d997205","description":"KES Signing Key","type":"KesSigningKey_ed25519_kes_2^6"}],[{"cborHex":"82845820112b314dfe4d619bb215c52c4973b51ac269f161370ea57aed3f334811f2923300005840c1715a7c12b52bca14e33d8b8d23e2c9b139e2be0beded4426bc401d3f8f16a5a6660f78f192329de7566c3b2d1fe5e9a2bb5476573689a03660a18b7f20850258200ba394a87622c06c4d67af4e3fa2314824c5d8db428f8200c6eb49033c7e27ec","description":"","type":"NodeOperationalCertificate"},{"cborHex":"58400def24a9256e667363b8a9529d6d8d4893c932a40c02eecd2777a55940254fffab6800ebfb93be0b69dbe2f9ef6dfe39fc0117304c6370485e48b11dc709d59c","description":"VRF Signing Key","type":"VrfSigningKey_PraosVRF"},{"cborHex":"5902605f91217f9ae5ea1ce6dd6b42eafdc5e95c4361e98be395dbf9fc87285eaf6171fd737c7d240941941555484ffdb6f01704a938e58a65ec522a9041df131ebb69fd876eaa1c3621a549c3c5e22eef483e267c2282d02f5a1a60d00786e6951f4ac4c9a8536a8333f02d5ccef2b3093851d10b903694ebc5f6b97039e0a5a48e385838b6db8143362c324e90ffdad680e6c18c7280495c2d4fc28600f93e48091eb0d92aed0ec63312a03d9d89d44ac5b71aa1c1ea289b31ef88a0ca7c0508e944af118730f5443ac68fdc227620234f663c8dfa75796935a14955fbb9f1f216984504b3fc391d6ca2275a4f202029981c4ca5d06cff3dec78c2b28aee2dd4594e5ef286705932e989e619030f5c54a47bf767b883b19eca6d0663008385c807a2da97e2a0d99810ade35e71254eb667cac8261f2990a903ef658942c19ef5109fe33539224b5fb98281c4f90757b7fc0dc3d7239f77b4d1905bed3083773daebfbe15e791b33a8d051325af9dbfe2b1451b7fddc8ae5b7454ba68a219d9b186686a02c57bccae68bc9bdf3c05a9008cf78adc0e5e464537769646b8cc0f6fa71b555d7426aa15f06635fbbdf48c2d3eba56f23ad26799cb5253b456e2b30eb7013775390278c761d35ddd129b0a07b686dad1ab09cd9416dcd7e476648d9d2e6dc7addc8a1b842b7c3a59bdbd803bec78fcb058c64251886ff7a3106387150c651edba78d20f890d2c3d208bc37eb2d449487d6b11160913af836ff4877153893179e739c3e483c75e7b26e8c06e35ed50d3e805879fdd8bb6281581fecee6b30a1343b0dd696103072f2afc35c90677706231c8daa754c401b49e47719cc219d","description":"KES Signing Key","type":"KesSigningKey_ed25519_kes_2^6"}]] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/config/test-config.json b/cardano-chain-gen/bench/benchfiles/config/test-config.json new file mode 100644 index 000000000..60a3306d4 --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/config/test-config.json @@ -0,0 +1,108 @@ +{ + "AlonzoGenesisFile": "genesis.alonzo.json", + "AlonzoGenesisHash": "7e94a15f55d1e82d10f09203fa1d40f8eede58fd8066542cf6566008068ed874", + "ApplicationName": "cardano-sl", + "ApplicationVersion": 0, + "ByronGenesisFile": "genesis.byron.json", + "ByronGenesisHash": "462bb9869a5a6e4325cc294ca659d68607e8a6f37b5be96ea663fdedfe2b5949", + "LastKnownBlockVersion-Alt": 0, + "LastKnownBlockVersion-Major": 5, + "LastKnownBlockVersion-Minor": 1, + "MaxKnownMajorProtocolVersion": 5, + "PBftSignatureThreshold": 1.1, + "Protocol": "Cardano", + "RequiresNetworkMagic": "RequiresMagic", + "ShelleyGenesisFile": "genesis.json", + "ShelleyGenesisHash": "733960b0b305cbfedcca13d2fea87b077f17501d257d4d2844d1f1e3d9dea0b7", + "TestAllegraHardForkAtEpoch": 0, + "TestAlonzoHardForkAtEpoch": 0, + "TestEnableDevelopmentHardForkEras": false, + "TestEnableDevelopmentNetworkProtocols": false, + "TestMaryHardForkAtEpoch": 0, + "TestShelleyHardForkAtEpoch": 0, + "TraceAcceptPolicy": true, + "TraceBlockFetchClient": false, + "TraceBlockFetchDecisions": false, + "TraceBlockFetchProtocol": false, + "TraceBlockFetchProtocolSerialised": false, + "TraceBlockFetchServer": false, + "TraceChainDb": true, + "TraceChainSyncBlockServer": false, + "TraceChainSyncClient": false, + "TraceChainSyncHeaderServer": false, + "TraceChainSyncProtocol": false, + "TraceConnectionManager": true, + "TraceDNSResolver": true, + "TraceDNSSubscription": true, + "TraceDiffusionInitialization": true, + "TraceErrorPolicy": true, + "TraceForge": true, + "TraceHandshake": false, + "TraceInboundGovernor": true, + "TraceIpSubscription": true, + "TraceLedgerPeers": true, + "TraceLocalChainSyncProtocol": false, + "TraceLocalErrorPolicy": true, + "TraceLocalHandshake": false, + "TraceLocalRootPeers": true, + "TraceLocalTxSubmissionProtocol": false, + "TraceLocalTxSubmissionServer": false, + "TraceMempool": true, + "TraceMux": false, + "TracePeerSelection": true, + "TracePeerSelectionActions": true, + "TracePublicRootPeers": true, + "TraceServer": true, + "TraceTxInbound": false, + "TraceTxOutbound": false, + "TraceTxSubmissionProtocol": false, + "TracingVerbosity": "NormalVerbosity", + "TurnOnLogMetrics": true, + "TurnOnLogging": true, + "defaultBackends": [ + "KatipBK" + ], + "defaultScribes": [ + [ + "StdoutSK", + "stdout" + ] + ], + "hasEKG": 12788, + "hasPrometheus": [ + "127.0.0.1", + 12798 + ], + "minSeverity": "Debug", + "options": { + "mapBackends": { + "cardano.node.metrics": [ + "EKGViewBK" + ], + "cardano.node.resources": [ + "EKGViewBK" + ] + }, + "mapSubtrace": { + "cardano.node.metrics": { + "subtrace": "Neutral" + } + } + }, + "rotation": { + "rpKeepFilesNum": 10, + "rpLogLimitBytes": 5000000, + "rpMaxAgeHours": 24 + }, + "setupBackends": [ + "KatipBK" + ], + "setupScribes": [ + { + "scFormat": "ScText", + "scKind": "StdoutSK", + "scName": "stdout", + "scRotation": null + } + ] +} diff --git a/cardano-chain-gen/bench/benchfiles/config/test-db-sync-config.json b/cardano-chain-gen/bench/benchfiles/config/test-db-sync-config.json new file mode 100644 index 000000000..a99805bd3 --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/config/test-db-sync-config.json @@ -0,0 +1,114 @@ +{ + "EnableLogMetrics": false, + "EnableLogging": true, + "NetworkName": "testing", + "NodeConfigFile": "test-config.json", + "PrometheusPort": 8080, + "RequiresNetworkMagic": "RequiresMagic", + "defaultBackends": [ + "KatipBK" + ], + "defaultScribes": [ + [ + "StdoutSK", + "stdout" + ] + ], + "minSeverity": "Warning", + "options": { + "cfokey": { + "value": "Release-1.0.0" + }, + "mapBackends": {}, + "mapSeverity": { + "db-sync-node": "Error", + "db-sync-node.Mux": "Error", + "db-sync-node.Subscription": "Error" + }, + "mapSubtrace": { + "#ekgview": { + "contents": [ + [ + { + "contents": "cardano.epoch-validation.benchmark", + "tag": "Contains" + }, + [ + { + "contents": ".monoclock.basic.", + "tag": "Contains" + } + ] + ], + [ + { + "contents": "cardano.epoch-validation.benchmark", + "tag": "Contains" + }, + [ + { + "contents": "diff.RTS.cpuNs.timed.", + "tag": "Contains" + } + ] + ], + [ + { + "contents": "#ekgview.#aggregation.cardano.epoch-validation.benchmark", + "tag": "StartsWith" + }, + [ + { + "contents": "diff.RTS.gcNum.timed.", + "tag": "Contains" + } + ] + ] + ], + "subtrace": "FilterTrace" + }, + "#messagecounters.aggregation": { + "subtrace": "NoTrace" + }, + "#messagecounters.ekgview": { + "subtrace": "NoTrace" + }, + "#messagecounters.katip": { + "subtrace": "NoTrace" + }, + "#messagecounters.monitoring": { + "subtrace": "NoTrace" + }, + "#messagecounters.switchboard": { + "subtrace": "NoTrace" + }, + "benchmark": { + "contents": [ + "GhcRtsStats", + "MonotonicClock" + ], + "subtrace": "ObservableTrace" + }, + "cardano.epoch-validation.utxo-stats": { + "subtrace": "NoTrace" + } + } + }, + "rotation": { + "rpKeepFilesNum": 10, + "rpLogLimitBytes": 5000000, + "rpMaxAgeHours": 24 + }, + "setupBackends": [ + "AggregationBK", + "KatipBK" + ], + "setupScribes": [ + { + "scFormat": "ScText", + "scKind": "StdoutSK", + "scName": "stdout", + "scRotation": null + } + ] +} diff --git a/cardano-chain-gen/bench/benchfiles/fingerprint/delegateAndSend_1 b/cardano-chain-gen/bench/benchfiles/fingerprint/delegateAndSend_1 new file mode 100644 index 000000000..df965face --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/fingerprint/delegateAndSend_1 @@ -0,0 +1 @@ +[0,1,9] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/fingerprint/delegateAndSend_10 b/cardano-chain-gen/bench/benchfiles/fingerprint/delegateAndSend_10 new file mode 100644 index 000000000..495236454 --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/fingerprint/delegateAndSend_10 @@ -0,0 +1 @@ +[0,1,9,14,23,28,29,31,34,69,74,75,80,82,84,88,95,98,104,106,108,113,115,127,129,144,146,147,151,153] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/fingerprint/delegateAndSend_400 b/cardano-chain-gen/bench/benchfiles/fingerprint/delegateAndSend_400 new file mode 100644 index 000000000..518717669 --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/fingerprint/delegateAndSend_400 @@ -0,0 +1 @@ +[0,1,9,14,23,28,29,31,34,69,74,75,80,82,84,88,95,98,104,106,108,113,115,127,129,144,146,147,151,153,161,163,171,176,177,178,179,186,189,195,197,198,204,207,210,211,212,213,219,222,226,233,241,252,265,266,274,290,291,294,295,298,304,305,309,312,314,317,326,328,329,332,333,336,346,351,352,357,365,367,385,387,391,400,401,404,411,413,414,424,427,430,436,444,449,455,458,460,461,462,473,474,476,477,482,491,497,498,499,502,506,507,514,521,547,563,566,575,578,581,594,599,602,607,614,623,631,638,639,641,649,652,653,654,665,666,670,672,673,682,683,688,692,696,700,701,708,710,714,725,735,737,746,750,763,772,776,783,793,795,797,802,804,817,818,822,824,826,827,832,834,836,841,847,851,855,861,868,870,873,876,877,882,883,891,894,905,908,913,915,925,934,942,943,949,956,960,967,968,974,980,987,998,1002,1004,1005,1012,1016,1019,1022,1023,1035,1036,1037,1039,1040,1051,1057,1058,1061,1064,1067,1074,1089,1091,1094,1096,1099,1104,1105,1107,1109,1121,1125,1133,1140,1145,1147,1148,1150,1153,1155,1159,1160,1172,1179,1185,1187,1194,1195,1201,1202,1211,1212,1216,1217,1221,1223,1233,1234,1235,1240,1241,1243,1250,1253,1259,1272,1273,1278,1280,1286,1289,1295,1298,1304,1310,1313,1320,1325,1328,1331,1332,1361,1379,1380,1382,1398,1402,1408,1411,1433,1436,1438,1449,1453,1454,1464,1468,1469,1480,1481,1482,1485,1492,1502,1504,1506,1512,1519,1524,1534,1537,1544,1545,1553,1559,1564,1565,1571,1578,1580,1583,1586,1587,1594,1597,1599,1605,1606,1609,1611,1613,1617,1623,1627,1630,1633,1634,1635,1640,1650,1655,1664,1666,1668,1670,1674,1682,1683,1684,1687,1697,1702,1710,1711,1712,1715,1718,1729,1739,1745,1750,1754,1757,1762,1775,1781,1794,1797,1801,1803,1808,1809,1812,1814,1820,1824,1825,1827,1832,1836,1854,1858,1865,1869,1872,1888,1890,1891,1892,1895,1905,1911,1917,1920,1921,1922,1928,1933,1943,1944,1962,1987,1992,1994,1998,2003,2008,2034,2037,2041,2043,2048,2051,2063,2065,2068,2070,2086,2099,2109,2122,2124,2127,2128,2129,2149,2152,2154,2160,2161,2162,2163,2168,2171,2175,2176,2180,2187,2191,2194,2201,2202,2203,2205,2206,2208,2218,2222,2229,2236,2238,2258,2266,2285,2289,2290,2293,2295,2299,2302,2308,2309,2311,2317,2325,2332,2333,2335,2337,2339,2341,2351,2357,2360,2361,2364,2366,2380,2383,2384,2386,2396,2397,2423,2429,2435,2438,2442,2448,2449,2458,2459,2463,2465,2470,2474,2477,2479,2491,2494,2496,2497,2499,2500,2505,2506,2509,2512,2519,2523,2540,2544,2546,2556,2558,2561,2562,2563,2566,2568,2569,2574,2580,2582,2600,2601,2605,2608,2620,2629,2633,2634,2637,2642,2654,2659,2660,2666,2673,2675,2683,2691,2693,2695,2697,2698,2699,2703,2705,2706,2709,2716,2717,2725,2726,2727,2731,2748,2758,2761,2767,2768,2777,2780,2787,2807,2811,2816,2818,2826,2830,2834,2835,2837,2842,2843,2846,2847,2849,2850,2854,2856,2857,2858,2860,2864,2867,2869,2872,2874,2879,2881,2887,2891,2898,2901,2903,2907,2909,2910,2933,2937,2941,2945,2947,2961,2969,2974,2975,2977,2980,2984,2990,3014,3023,3027,3036,3040,3042,3043,3050,3059,3063,3064,3068,3071,3073,3074,3087,3100,3103,3104,3111,3114,3123,3127,3131,3140,3143,3144,3150,3155,3157,3163,3169,3172,3179,3180,3193,3197,3200,3206,3211,3218,3220,3222,3232,3233,3234,3238,3249,3255,3256,3260,3280,3289,3291,3294,3299,3300,3301,3303,3308,3314,3322,3330,3333,3338,3343,3346,3352,3356,3357,3362,3365,3371,3379,3381,3383,3396,3398,3411,3413,3427,3440,3446,3457,3459,3461,3466,3471,3488,3490,3495,3496,3500,3506,3507,3509,3524,3539,3548,3555,3559,3569,3571,3575,3576,3578,3589,3595,3599,3600,3606,3608,3610,3611,3612,3616,3625,3628,3636,3649,3651,3657,3670,3673,3677,3688,3702,3706,3707,3709,3718,3736,3768,3776,3778,3785,3786,3787,3794,3802,3803,3810,3812,3819,3821,3822,3834,3844,3847,3848,3854,3856,3862,3863,3867,3869,3873,3876,3878,3879,3880,3881,3886,3888,3889,3891,3893,3903,3906,3912,3913,3916,3918,3920,3925,3926,3929,3938,3946,3956,3957,3964,3969,3980,3987,3990,3991,3997,4004,4005,4013,4014,4015,4019,4020,4023,4035,4039,4041,4048,4055,4057,4066,4071,4072,4083,4084,4090,4091,4092,4096,4125,4128,4137,4143,4145,4150,4151,4152,4158,4159,4166,4169,4174,4175,4183,4185,4189,4190,4194,4195,4196,4198,4201,4203,4210,4211,4217,4221,4222,4225,4228,4233,4240,4253,4256,4258,4261,4263,4265,4283,4287,4303,4306,4312,4314,4318,4323,4326,4333,4334,4335,4343,4345,4347,4350,4366,4374,4382,4401,4402,4405,4406,4419,4423,4425,4430,4432,4436,4440,4444,4446,4462,4467,4468,4472,4474,4484,4490,4497,4500,4502,4509,4510,4514,4516,4517,4519,4523,4534,4536,4544,4548,4556,4560,4572,4581,4584,4585,4602,4604,4607,4609,4612,4616,4620,4623,4625,4629,4631,4636,4638,4656,4664,4665,4666,4667,4669,4671,4673,4677,4679,4682,4688,4693,4698,4704,4715,4725,4727,4729,4733,4736,4743,4746,4747,4748,4752,4753,4757,4758,4760,4761,4767,4779,4785,4790,4793,4794,4795,4800,4804,4816,4820,4830,4835,4842,4843,4848,4851,4852,4853,4861,4864,4868,4873,4893,4900,4904,4905,4913,4914,4922,4934,4942,4945,4955,4959,4960,4978,4979,4986,4989,4996,5009,5016,5025,5028,5031,5035,5036,5040,5043,5047,5050,5053,5061,5063,5064,5068,5070,5073,5077,5095,5104,5107,5114,5117,5118,5120,5127,5132,5134,5148,5149,5159,5163,5164,5166,5171,5174,5175,5178,5185,5187,5200,5202,5212,5221,5224,5225,5229,5237,5242,5268,5276,5283,5287,5290,5299,5300,5301,5307,5318,5321,5322,5323,5361,5365,5366,5382,5389,5394,5398,5409,5410,5414,5417,5418,5431,5441,5443,5453,5456,5465,5468,5470,5480,5494,5500,5510,5519,5523,5532,5534,5535,5539,5543,5544,5546,5555,5558,5560,5562,5567,5568,5583,5585,5594,5600,5602,5606,5608,5611,5612,5615,5616,5617,5636,5639,5641,5650,5659,5664,5670,5672,5676,5679,5680,5688,5689,5692,5693,5694,5706,5709,5714,5715,5728,5729,5730,5734,5735,5739,5752,5755,5759,5776,5782,5783,5784,5792,5796,5799,5800,5803,5808,5810,5815,5818,5821,5824,5830,5835,5845,5847,5849,5861,5863,5867,5869,5874,5893,5897,5899,5900,5902,5903,5904,5906,5911,5924,5934,5939,5943,5947,5951,5963,5966,5968,5980,5985,5987,5992,5994] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_10 b/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_10 new file mode 100644 index 000000000..57041f55f --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_10 @@ -0,0 +1 @@ +[0,1,9,14,23,28,29,31,34,69] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_100 b/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_100 new file mode 100644 index 000000000..8b6e0e180 --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_100 @@ -0,0 +1 @@ +[0,1,9,14,23,28,29,31,34,69,74,75,80,82,84,88,95,98,104,106,108,113,115,127,129,144,146,147,151,153,161,163,171,176,177,178,179,186,189,195,197,198,204,207,210,211,212,213,219,222,226,233,241,252,265,266,274,290,291,294,295,298,304,305,309,312,314,317,326,328,329,332,333,336,346,351,352,357,365,367,385,387,391,400,401,404,411,413,414,424,427,430,436,444,449,455,458,460,461,462] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_50 b/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_50 new file mode 100644 index 000000000..fb966492b --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_50 @@ -0,0 +1 @@ +[0,1,9,14,23,28,29,31,34,69,74,75,80,82,84,88,95,98,104,106,108,113,115,127,129,144,146,147,151,153,161,163,171,176,177,178,179,186,189,195,197,198,204,207,210,211,212,213,219,222] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_500 b/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_500 new file mode 100644 index 000000000..ba054d4ce --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/fingerprint/emptyBlock_500 @@ -0,0 +1 @@ +[0,1,9,14,23,28,29,31,34,69,74,75,80,82,84,88,95,98,104,106,108,113,115,127,129,144,146,147,151,153,161,163,171,176,177,178,179,186,189,195,197,198,204,207,210,211,212,213,219,222,226,233,241,252,265,266,274,290,291,294,295,298,304,305,309,312,314,317,326,328,329,332,333,336,346,351,352,357,365,367,385,387,391,400,401,404,411,413,414,424,427,430,436,444,449,455,458,460,461,462,473,474,476,477,482,491,497,498,499,502,506,507,514,521,547,563,566,575,578,581,594,599,602,607,614,623,631,638,639,641,649,652,653,654,665,666,670,672,673,682,683,688,692,696,700,701,708,710,714,725,735,737,746,750,763,772,776,783,793,795,797,802,804,817,818,822,824,826,827,832,834,836,841,847,851,855,861,868,870,873,876,877,882,883,891,894,905,908,913,915,925,934,942,943,949,956,960,967,968,974,980,987,998,1002,1004,1005,1012,1016,1019,1022,1023,1035,1036,1037,1039,1040,1051,1057,1058,1061,1064,1067,1074,1089,1091,1094,1096,1099,1104,1105,1107,1109,1121,1125,1133,1140,1145,1147,1148,1150,1153,1155,1159,1160,1172,1179,1185,1187,1194,1195,1201,1202,1211,1212,1216,1217,1221,1223,1233,1234,1235,1240,1241,1243,1250,1253,1259,1272,1273,1278,1280,1286,1289,1295,1298,1304,1310,1313,1320,1325,1328,1331,1332,1361,1379,1380,1382,1398,1402,1408,1411,1433,1436,1438,1449,1453,1454,1464,1468,1469,1480,1481,1482,1485,1492,1502,1504,1506,1512,1519,1524,1534,1537,1544,1545,1553,1559,1564,1565,1571,1578,1580,1583,1586,1587,1594,1597,1599,1605,1606,1609,1611,1613,1617,1623,1627,1630,1633,1634,1635,1640,1650,1655,1664,1666,1668,1670,1674,1682,1683,1684,1687,1697,1702,1710,1711,1712,1715,1718,1729,1739,1745,1750,1754,1757,1762,1775,1781,1794,1797,1801,1803,1808,1809,1812,1814,1820,1824,1825,1827,1832,1836,1854,1858,1865,1869,1872,1888,1890,1891,1892,1895,1905,1911,1917,1920,1921,1922,1928,1933,1943,1944,1962,1987,1992,1994,1998,2003,2008,2034,2037,2041,2043,2048,2051,2063,2065,2068,2070,2086,2099,2109,2122,2124,2127,2128,2129,2149,2152,2154,2160,2161,2162,2163,2168,2171,2175,2176,2180,2187,2191,2194,2201,2202,2203,2205,2206,2208,2218,2222,2229,2236,2238,2258,2266,2285,2289,2290,2293,2295,2299,2302,2308,2309,2311,2317,2325,2332,2333,2335,2337,2339,2341,2351,2357,2360,2361,2364,2366,2380,2383,2384,2386,2396,2397,2423,2429,2435,2438,2442,2448,2449,2458,2459,2463,2465,2470,2474,2477,2479] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/fingerprint/registerAddressess_1 b/cardano-chain-gen/bench/benchfiles/fingerprint/registerAddressess_1 new file mode 100644 index 000000000..6e7ea636e --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/fingerprint/registerAddressess_1 @@ -0,0 +1 @@ +[0] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/fingerprint/registerAddressess_10 b/cardano-chain-gen/bench/benchfiles/fingerprint/registerAddressess_10 new file mode 100644 index 000000000..57041f55f --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/fingerprint/registerAddressess_10 @@ -0,0 +1 @@ +[0,1,9,14,23,28,29,31,34,69] \ No newline at end of file diff --git a/cardano-chain-gen/bench/benchfiles/pgpass-bench b/cardano-chain-gen/bench/benchfiles/pgpass-bench new file mode 100644 index 000000000..e42d64610 --- /dev/null +++ b/cardano-chain-gen/bench/benchfiles/pgpass-bench @@ -0,0 +1 @@ +/var/run/postgresql:5432:bench:*:* diff --git a/cardano-chain-gen/cardano-chain-gen.cabal b/cardano-chain-gen/cardano-chain-gen.cabal index 1978008a2..16a9af19e 100644 --- a/cardano-chain-gen/cardano-chain-gen.cabal +++ b/cardano-chain-gen/cardano-chain-gen.cabal @@ -208,3 +208,55 @@ test-suite cardano-chain-gen , persistent , plutus-example , postgresql-simple + +benchmark cardano-chain + type: exitcode-stdio-1.0 + default-language: Haskell2010 + main-is: Main.hs + hs-source-dirs: gen + hs-source-dirs: bench + + ghc-options: -Wall + -Wcompat + -fwarn-redundant-constraints + -fwarn-incomplete-patterns + -fwarn-unused-imports + -Wincomplete-record-updates + -Wincomplete-uni-patterns + -Wno-unsafe + -threaded + -rtsopts + -with-rtsopts=-N4 + + autogen-modules: Paths_cardano_chain_gen + MigrationValidations + other-modules: Paths_cardano_chain_gen + MigrationValidations + + other-modules: Cardano.Db.Bench + build-depends: async + , base >= 4.12 + , bytestring + , containers + , criterion + , deepseq + , directory + , filepath + , split + , strict-stm + , tasty + , tasty-hunit + , text + , cardano-prelude + , cardano-chain-gen + , cardano-db + , cardano-db-sync + , cardano-crypto-class + , cardano-ledger-alonzo + , cardano-ledger-core + , cardano-ledger-shelley + , cardano-ledger-shelley-ma + , cardano-slotting + , io-classes + , ouroboros-consensus-cardano + , ouroboros-network diff --git a/cardano-chain-gen/src/Cardano/Mock/ChainSync/Server.hs b/cardano-chain-gen/src/Cardano/Mock/ChainSync/Server.hs index 1516115a1..573351dd0 100644 --- a/cardano-chain-gen/src/Cardano/Mock/ChainSync/Server.hs +++ b/cardano-chain-gen/src/Cardano/Mock/ChainSync/Server.hs @@ -22,6 +22,8 @@ module Cardano.Mock.ChainSync.Server , addBlock , rollback , readChain + , blockServing + , unBlockServing , withIOManager ) where @@ -32,8 +34,9 @@ import Control.Concurrent (threadDelay) import Control.Concurrent.Async import Control.Exception (bracket) import Control.Monad (forever) -import Control.Monad.Class.MonadSTM.Strict (MonadSTM (atomically), STM, StrictTVar, - modifyTVar, newTVarIO, readTVar, retry, writeTVar) +import Control.Monad.Class.MonadSTM.Strict (MonadSTM (atomically), STM, StrictTMVar, + StrictTVar, modifyTVar, newTMVarIO, newTVarIO, putTMVar, readTMVar, readTVar, retry, + takeTMVar, writeTVar) import Control.Tracer (nullTracer) import Data.ByteString.Lazy.Char8 (ByteString) import qualified Data.Map.Strict as Map @@ -89,6 +92,7 @@ import Cardano.Mock.ChainSync.State data ServerHandle m blk = ServerHandle { chainProducerState :: StrictTVar m (ChainProducerState blk) , threadHandle :: Async () + , blocking :: StrictTMVar m () } replaceGenesis :: MonadSTM m => ServerHandle m blk -> State blk -> STM m () @@ -115,6 +119,13 @@ rollback handle point = stopServer :: ServerHandle m blk -> IO () stopServer = cancel . threadHandle +blockServing :: MonadSTM m => ServerHandle m blk -> STM m () +blockServing handle = + takeTMVar (blocking handle) + +unBlockServing :: MonadSTM m => ServerHandle m blk -> STM m () +unBlockServing handle = putTMVar (blocking handle) () + type MockServerConstraint blk = ( SerialiseNodeToClientConstraints blk , ShowQuery (BlockQuery blk) @@ -139,8 +150,9 @@ forkServerThread -> IO (ServerHandle IO blk) forkServerThread iom config initSt networkMagic path = do chainSt <- newTVarIO $ initChainProducerState config initSt - thread <- async $ runLocalServer iom (configCodec config) networkMagic path chainSt - pure $ ServerHandle chainSt thread + lock <- newTMVarIO () + thread <- async $ runLocalServer iom (configCodec config) networkMagic path chainSt lock + pure $ ServerHandle chainSt thread lock withServerHandle :: forall blk a. MockServerConstraint blk @@ -162,8 +174,9 @@ runLocalServer -> NetworkMagic -> FilePath -> StrictTVar IO (ChainProducerState blk) + -> StrictTMVar IO () -> IO () -runLocalServer iom codecConfig networkMagic localDomainSock chainProducerState = +runLocalServer iom codecConfig networkMagic localDomainSock chainProducerState lockServing = withSnocket iom localDomainSock $ \ localSocket localSnocket -> do networkState <- NodeToClient.newNetworkMutableState _ <- NodeToClient.withServer @@ -171,27 +184,26 @@ runLocalServer iom codecConfig networkMagic localDomainSock chainProducerState = NodeToClient.nullNetworkServerTracers -- debuggingNetworkServerTracers networkState localSocket - (versions chainProducerState) + versions NodeToClient.networkErrorPolicies pure () where - versions :: StrictTVar IO (ChainProducerState blk) - -> Versions NodeToClientVersion + versions :: Versions NodeToClientVersion NodeToClientVersionData (OuroborosApplication 'ResponderMode LocalAddress ByteString IO Void ()) - versions state = + versions = let version = fromJust $ snd $ latestReleasedNodeVersion (Proxy @blk) allVersions = supportedNodeToClientVersions (Proxy @blk) blockVersion = fromJust $ Map.lookup version allVersions in simpleSingletonVersions version (NodeToClientVersionData networkMagic) - (NTC.responder version $ mkApps state version blockVersion (NTC.defaultCodecs codecConfig blockVersion version)) + (NTC.responder version $ mkApps version blockVersion (NTC.defaultCodecs codecConfig blockVersion version)) - mkApps :: StrictTVar IO (ChainProducerState blk) -> NodeToClientVersion -> BlockNodeToClientVersion blk -> DefaultCodecs blk IO + mkApps :: NodeToClientVersion -> BlockNodeToClientVersion blk -> DefaultCodecs blk IO -> NTC.Apps IO (ConnectionId addrNTC) ByteString ByteString ByteString () - mkApps state _version blockVersion Codecs {..} = Apps {..} + mkApps _version blockVersion Codecs {..} = Apps {..} where aChainSyncServer :: localPeer @@ -203,7 +215,7 @@ runLocalServer iom codecConfig networkMagic localDomainSock chainProducerState = cChainSyncCodec channel $ chainSyncServerPeer - $ chainSyncServer state codecConfig blockVersion + $ chainSyncServer chainProducerState lockServing codecConfig blockVersion aTxSubmissionServer :: localPeer @@ -234,10 +246,11 @@ chainSyncServer , EncodeDisk blk blk ) => StrictTVar m (ChainProducerState blk) + -> StrictTMVar m () -> CodecConfig blk -> BlockNodeToClientVersion blk -> ChainSyncServer (Serialised blk) (Point blk) (Tip blk) m () -chainSyncServer state codec _blockVersion = +chainSyncServer state lockServing codec _blockVersion = ChainSyncServer $ idle <$> newFollower where idle :: FollowerId -> ServerStIdle (Serialised blk) (Point blk) (Tip blk) m () @@ -255,6 +268,7 @@ chainSyncServer state codec _blockVersion = -> m (Either (ServerStNext (Serialised blk) (Point blk) (Tip blk) m ()) (m (ServerStNext (Serialised blk) (Point blk) (Tip blk) m ()))) handleRequestNext r = do + atomically $ readTMVar lockServing mupdate <- tryReadChainUpdate r case mupdate of Just update -> pure (Left (sendNext r update)) diff --git a/cardano-chain-gen/src/Cardano/Mock/Db/Config.hs b/cardano-chain-gen/src/Cardano/Mock/Db/Config.hs index 9b2e9dc90..efd841083 100644 --- a/cardano-chain-gen/src/Cardano/Mock/Db/Config.hs +++ b/cardano-chain-gen/src/Cardano/Mock/Db/Config.hs @@ -50,20 +50,17 @@ import Cardano.SMASH.Server.PoolDataLayer import Cardano.Mock.ChainSync.Server import Cardano.Mock.Forging.Interpreter hiding (CardanoBlock) -rootTestDir :: FilePath -rootTestDir = "test/testfiles" +mkMutableDir :: FilePath -> FilePath -> FilePath +mkMutableDir rootTestDir testLabel = rootTestDir "temp" testLabel -mkMutableDir :: FilePath -> FilePath -mkMutableDir testLabel = rootTestDir "temp" testLabel +mkConfigDir :: FilePath -> FilePath -> FilePath +mkConfigDir rootTestDir config = rootTestDir config -mkConfigDir :: FilePath -> FilePath -mkConfigDir config = rootTestDir config +fingerprintRoot :: FilePath -> FilePath +fingerprintRoot rootTestDir = rootTestDir "fingerprint" -fingerprintRoot :: FilePath -fingerprintRoot = rootTestDir "fingerprint" - -mkFingerPrint :: FilePath -> FilePath -mkFingerPrint testLabel = fingerprintRoot testLabel +mkFingerPrint :: FilePath -> FilePath -> FilePath +mkFingerPrint rootTestDir testLabel = fingerprintRoot rootTestDir testLabel data Config = Config { topLevelConfig :: TopLevelConfig CardanoBlock @@ -192,17 +189,17 @@ emptyMetricsSetters = MetricSetters , metricsSetDbSlotHeight = \_ -> pure () } -withFullConfig :: FilePath -> FilePath +withFullConfig :: FilePath -> FilePath -> FilePath -> (Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO ()) -> IOManager -> [(Text, Text)] -> IO () -withFullConfig config testLabel action iom migr = do +withFullConfig rootTestDir config testLabel action iom migr = do recreateDir mutableDir cfg <- mkConfig configDir mutableDir - fingerFile <- prepareFingerprintFile testLabel + fingerFile <- prepareFingerprintFile rootTestDir testLabel let dbsyncParams = syncNodeParams cfg - let trce = nullTracer + -- let trce = nullTracer -- Replace with this for better debugging of tests - -- trce <- configureLogging dbsyncParams "db-sync-node" + trce <- configureLogging dbsyncParams "db-sync-node" let dbsyncRun = runDbSync emptyMetricsSetters migr iom trce dbsyncParams True 35 35 let initSt = Consensus.pInfoInitLedger $ protocolInfo cfg withInterpreter (protocolInfoForging cfg) nullTracer fingerFile $ \interpreter -> do @@ -215,15 +212,47 @@ withFullConfig config testLabel action iom migr = do _ <- hSilence [stderr] $ Db.recreateDB (getDBSyncPGPass dbSync) action interpreter mockServer dbSync where - configDir = mkConfigDir config - mutableDir = mkMutableDir testLabel - -prepareFingerprintFile :: FilePath -> IO FilePath -prepareFingerprintFile testLabel = do - createDirectoryIfMissing True fingerprintRoot + configDir = mkConfigDir rootTestDir config + mutableDir = mkMutableDir rootTestDir testLabel + +-- Same as 'withFullConfig' but doesn't use the bracket style. Can be used with +-- 'cleanFullConfig' to cleanup the env. +mkFullConfig :: FilePath -> FilePath -> FilePath + -> IOManager -> [(Text, Text)] + -> IO (Interpreter, ServerHandle IO CardanoBlock, DBSyncEnv) +mkFullConfig rootTestDir config testLabel iom migr = do + recreateDir mutableDir + cfg <- mkConfig configDir mutableDir + fingerFile <- prepareFingerprintFile rootTestDir testLabel + let dbsyncParams = syncNodeParams cfg + let trce = nullTracer + -- Replace with this for better debugging of tests + -- trce <- configureLogging dbsyncParams "db-sync-node" + let dbsyncRun = runDbSync emptyMetricsSetters migr iom trce dbsyncParams True 35 35 + let initSt = Consensus.pInfoInitLedger $ protocolInfo cfg + interpreter <- initInterpreter (protocolInfoForging cfg) nullTracer fingerFile + serverHandle <- forkServerThread @CardanoBlock iom (topLevelConfig cfg) initSt (NetworkMagic 42) + (unSocketPath (enpSocketPath $ syncNodeParams cfg)) + dbSync <- mkDBSyncEnv dbsyncParams dbsyncRun + _ <- hSilence [stderr] $ Db.recreateDB (getDBSyncPGPass dbSync) + pure (interpreter, serverHandle, dbSync) + where + configDir = mkConfigDir rootTestDir config + mutableDir = mkMutableDir rootTestDir testLabel + +cleanFullConfig :: (Interpreter, ServerHandle IO CardanoBlock, DBSyncEnv) + -> IO () +cleanFullConfig (interpreter, serverHandle, dbSync) = do + stopDBSyncIfRunning dbSync + stopServer serverHandle + finalizeFingerprint interpreter + +prepareFingerprintFile :: FilePath -> FilePath -> IO FilePath +prepareFingerprintFile rootTestDir testLabel = do + createDirectoryIfMissing True (fingerprintRoot rootTestDir) pure fingerprintFile where - fingerprintFile = mkFingerPrint testLabel + fingerprintFile = mkFingerPrint rootTestDir testLabel recreateDir :: FilePath -> IO () recreateDir path = do diff --git a/cardano-chain-gen/src/Cardano/Mock/Db/Validate.hs b/cardano-chain-gen/src/Cardano/Mock/Db/Validate.hs index 2db9efe4b..32954fba8 100644 --- a/cardano-chain-gen/src/Cardano/Mock/Db/Validate.hs +++ b/cardano-chain-gen/src/Cardano/Mock/Db/Validate.hs @@ -65,6 +65,10 @@ assertRewardCount :: DBSyncEnv -> Word64 -> IO () assertRewardCount env n = assertEqBackoff env queryRewardCount n defaultDelays "Unexpected rewards count" +assertBlockNo :: DBSyncEnv -> Maybe Int -> [Int] -> IO () +assertBlockNo env mBlockNo delays = + assertEqBackoff env queryBlockHeight (fromIntegral <$> mBlockNo) delays "Unexpected BlockNo" + assertBlockNoBackoff :: DBSyncEnv -> Int -> IO () assertBlockNoBackoff env blockNo = assertEqBackoff env queryBlockHeight (Just $ fromIntegral blockNo) defaultDelays "Unexpected BlockNo" diff --git a/cardano-chain-gen/src/Cardano/Mock/Forging/Interpreter.hs b/cardano-chain-gen/src/Cardano/Mock/Forging/Interpreter.hs index a8c584541..35f7aee32 100644 --- a/cardano-chain-gen/src/Cardano/Mock/Forging/Interpreter.hs +++ b/cardano-chain-gen/src/Cardano/Mock/Forging/Interpreter.hs @@ -18,6 +18,7 @@ module Cardano.Mock.Forging.Interpreter , NodeId (..) , initInterpreter , withInterpreter + , finalizeFingerprint , forgeNextFindLeader , forgeNext , forgeNextAfter diff --git a/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Alonzo.hs b/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Alonzo.hs index 55d7e4afb..665687452 100644 --- a/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Alonzo.hs +++ b/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Alonzo.hs @@ -8,7 +8,7 @@ module Cardano.Mock.Forging.Tx.Alonzo where -import Cardano.Prelude hiding ((.)) +import Cardano.Prelude hiding (sum, (.)) import qualified Data.Map.Strict as Map import Data.Maybe (fromJust) @@ -109,6 +109,24 @@ mkPaymentTx inputIndex outputIndex amount fees sta = do change = TxOut addr' (valueFromList (fromIntegral $ fromIntegral inputValue - amount - fees) []) Strict.SNothing Right $ mkSimpleTx True $ consPaymentTxBody input mempty (StrictSeq.fromList [output, change]) (Coin fees) mempty +mkPaymentTx' :: AlonzoUTxOIndex + -> [(AlonzoUTxOIndex, Value StandardCrypto)] + -> AlonzoLedgerState + -> Either ForgingError (ValidatedTx (AlonzoEra StandardCrypto)) +mkPaymentTx' inputIndex outputIndex sta = do + inputPair <- fst <$> resolveUTxOIndex inputIndex sta + outps <- mapM mkOuts outputIndex + + let inps = Set.singleton $ fst inputPair + TxOut addr' (Value inputValue _) _ = snd inputPair + outValue = sum ((\ (Value vl _) -> vl) . snd <$> outputIndex) + change = TxOut addr' (valueFromList (fromIntegral $ fromIntegral inputValue - outValue) []) Strict.SNothing + Right $ mkSimpleTx True $ consPaymentTxBody inps mempty (StrictSeq.fromList $ outps ++ [change]) (Coin 0) mempty + where + mkOuts (outIx, vl) = do + addr <- resolveAddress outIx sta + Right $ TxOut addr vl Strict.SNothing + mkLockByScriptTx :: AlonzoUTxOIndex -> [Bool] -> Integer -> Integer -> AlonzoLedgerState -> Either ForgingError (ValidatedTx (AlonzoEra StandardCrypto)) diff --git a/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Generic.hs b/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Generic.hs index fcc1d5148..810d5843e 100644 --- a/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Generic.hs +++ b/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Generic.hs @@ -11,6 +11,9 @@ module Cardano.Mock.Forging.Tx.Generic , resolveUTxOIndex , resolveStakeCreds , resolvePool + , createStakeCredentials + , createPaymentCredentials + , mkDummyScriptHash ) where import Cardano.Prelude hiding (length, (.)) @@ -24,7 +27,9 @@ import Cardano.Ledger.Address import Cardano.Ledger.BaseTypes import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Credential +import Cardano.Ledger.Crypto (ADDRHASH) import Cardano.Ledger.Era (Crypto) +import Cardano.Ledger.Hashes import Cardano.Ledger.Keys import Cardano.Ledger.Shelley.LedgerState hiding (LedgerState) import Cardano.Ledger.Shelley.TxBody @@ -39,6 +44,8 @@ import qualified Ouroboros.Consensus.Shelley.Ledger.Ledger as Consensus import Cardano.Mock.Forging.Tx.Alonzo.ScriptsExamples import Cardano.Mock.Forging.Types +import Test.Cardano.Ledger.Shelley.Examples.Consensus + resolveAddress :: forall era. (Crypto era ~ StandardCrypto, HasField "address" (Core.TxOut era) (Addr (Crypto era))) => UTxOIndex era -> LedgerState (ShelleyBlock era) -> Either ForgingError (Addr (Crypto era)) @@ -161,3 +168,14 @@ unregisteredPools = , KeyHash "222462543264795t3298745680239746523897456238974563298348" , KeyHash "33323876542397465497834256329487563428975634827956348975" ] + +createStakeCredentials :: Int -> [StakeCredential StandardCrypto] +createStakeCredentials n = + fmap (KeyHashObj . KeyHash . mkDummyHash (Proxy @(ADDRHASH StandardCrypto))) [1..n] + +createPaymentCredentials :: Int -> [PaymentCredential StandardCrypto] +createPaymentCredentials n = + fmap (KeyHashObj . KeyHash . mkDummyHash (Proxy @(ADDRHASH StandardCrypto))) [1..n] + +mkDummyScriptHash :: Int -> ScriptHash StandardCrypto +mkDummyScriptHash n = ScriptHash $ mkDummyHash (Proxy @(ADDRHASH StandardCrypto)) n diff --git a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit.hs b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit.hs index 1c0f8dafa..0e9b74206 100644 --- a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit.hs +++ b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit.hs @@ -37,7 +37,8 @@ import Cardano.SMASH.Server.Types import Cardano.Mock.ChainSync.Server import Cardano.Mock.Db.Validate -import Cardano.Mock.Db.Config +import Cardano.Mock.Db.Config hiding (withFullConfig) +import qualified Cardano.Mock.Db.Config as Config import Cardano.Mock.Forging.Interpreter import qualified Cardano.Mock.Forging.Tx.Alonzo as Alonzo import Cardano.Mock.Forging.Tx.Alonzo.ScriptsExamples @@ -133,6 +134,14 @@ unitTests iom knownMigrations = defaultConfigDir :: FilePath defaultConfigDir = "config" +rootTestDir :: FilePath +rootTestDir = "test/testfiles" + +withFullConfig :: FilePath -> FilePath + -> (Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO ()) + -> IOManager -> [(Text, Text)] -> IO () +withFullConfig = Config.withFullConfig rootTestDir + forgeBlocks :: IOManager -> [(Text, Text)] -> Assertion forgeBlocks = do withFullConfig defaultConfigDir testLabel $ \interpreter _mockServer _dbSync -> do diff --git a/cardano-db/src/Cardano/Db/Insert.hs b/cardano-db/src/Cardano/Db/Insert.hs index c68e55a6e..4cf89e223 100644 --- a/cardano-db/src/Cardano/Db/Insert.hs +++ b/cardano-db/src/Cardano/Db/Insert.hs @@ -19,7 +19,6 @@ module Cardano.Db.Insert , insertManyRewards , insertManyTxIn , insertMaTxMint - , insertMaTxOut , insertManyMaTxOut , insertMeta , insertMultiAsset @@ -73,7 +72,7 @@ import Data.Proxy (Proxy (..)) import Data.Text (Text) import qualified Data.Text as Text -import Database.Persist.Class (AtLeastOneUniqueKey, PersistEntityBackend, checkUnique, +import Database.Persist.Class (AtLeastOneUniqueKey, PersistEntityBackend, PersistEntity, checkUnique, insert, insertBy, replaceUnique) import Database.Persist.EntityDef.Internal (entityDB, entityUniques) import Database.Persist.Sql (OnlyOneUniqueKey, PersistRecordBackend, SqlBackend, @@ -146,9 +145,6 @@ insertManyTxIn = insertManyUncheckedUnique "Many TxIn" insertMaTxMint :: (MonadBaseControl IO m, MonadIO m) => MaTxMint -> ReaderT SqlBackend m MaTxMintId insertMaTxMint = insertCheckUnique "insertMaTxMint" -insertMaTxOut :: (MonadBaseControl IO m, MonadIO m) => MaTxOut -> ReaderT SqlBackend m MaTxOutId -insertMaTxOut = insertCheckUnique "insertMaTxOut" - insertManyMaTxOut :: (MonadBaseControl IO m, MonadIO m) => [MaTxOut] -> ReaderT SqlBackend m () insertManyMaTxOut = insertManyUncheckedUnique "Many MaTxOut" @@ -276,6 +272,40 @@ insertMany' vtype records = handle exceptHandler (insertMany records) exceptHandler e = liftIO $ throwIO (DbInsertException vtype e) +-- Used to benchmark tables without unique keys. +_insertManyNoUnique + :: forall m record. + ( MonadBaseControl IO m + , MonadIO m + , PersistEntity record + ) + => String -> [record] -> ReaderT SqlBackend m () +_insertManyNoUnique vtype records = + unless (null records) $ + handle exceptHandler (rawExecute query values) + where + query :: Text + query = + Text.concat + [ "INSERT INTO " + , unEntityNameDB (entityDB . entityDef $ records) + , " (", Util.commaSeparated fieldNames + , ") VALUES " + , Util.commaSeparated . replicate (length records) + . Util.parenWrapped . Util.commaSeparated $ placeholders + ] + + values :: [PersistValue] + values = concatMap (map toPersistValue . toPersistFields) records + + fieldNames, placeholders :: [Text] + (fieldNames, placeholders) = + unzip (Util.mkInsertPlaceholders (entityDef (Proxy @record)) escapeFieldName) + + exceptHandler :: SqlError -> ReaderT SqlBackend m a + exceptHandler e = + liftIO $ throwIO (DbInsertException vtype e) + insertManyUncheckedUnique :: forall m record. ( MonadBaseControl IO m