Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0824d0
commit 97a4840
Showing
6 changed files
with
158 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
cardano-tx-generator/src/Cardano/Benchmarking/GeneratorTx/Callback.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE GADTs #-} | ||
module Cardano.Benchmarking.GeneratorTx.Callback | ||
( | ||
mkCallback | ||
) where | ||
|
||
import Prelude (error) | ||
import Cardano.Prelude hiding (TypeError, show) | ||
|
||
import qualified Ouroboros.Consensus.Cardano as Consensus | ||
import Ouroboros.Consensus.Config | ||
( configBlock, configCodec) | ||
import Ouroboros.Consensus.Config.SupportsNode | ||
(ConfigSupportsNode(..), getNetworkMagic) | ||
import Ouroboros.Consensus.Node.ProtocolInfo | ||
(ProtocolInfo (..)) | ||
import Ouroboros.Network.NodeToClient (IOManager) | ||
|
||
import Cardano.Chain.Slotting | ||
import Cardano.Api | ||
import Cardano.Api.Typed | ||
import qualified Cardano.Api.Typed as Api | ||
|
||
-- Node imports | ||
import Cardano.Node.Types (SocketPath(..)) | ||
import Cardano.Tracing.OrphanInstances.Byron() | ||
import Cardano.Tracing.OrphanInstances.Common() | ||
import Cardano.Tracing.OrphanInstances.Consensus() | ||
import Cardano.Tracing.OrphanInstances.Network() | ||
import Cardano.Tracing.OrphanInstances.Shelley() | ||
|
||
import Cardano.Benchmarking.GeneratorTx.Benchmark | ||
import Cardano.Benchmarking.GeneratorTx.Era | ||
import Cardano.Benchmarking.GeneratorTx.NodeToNode | ||
import Cardano.Benchmarking.GeneratorTx | ||
import Cardano.Benchmarking.GeneratorTx.Genesis (GeneratorFunds) | ||
|
||
type Funding era = Benchmark -> GeneratorFunds -> ExceptT TxGenError IO (SigningKey PaymentKey, [(TxIn, TxOut era)]) | ||
type BenchmarkAction era | ||
= Benchmark -> (SigningKey PaymentKey, [(TxIn, TxOut era)]) -> ExceptT TxGenError IO () | ||
|
||
type Action era = Benchmark -> GeneratorFunds -> ExceptT TxGenError IO () | ||
|
||
mkCallback | ||
:: forall blok ptcl era. | ||
( | ||
IsShelleyBasedEra era | ||
, ConfigSupportsTxGen CardanoMode era | ||
) | ||
=> Consensus.Protocol IO blok ptcl | ||
-> Maybe NetworkMagic | ||
-> Bool | ||
-> IOManager | ||
-> SocketPath | ||
-> BenchTracers IO CardanoBlock | ||
-> Proxy era | ||
-> Action era | ||
|
||
mkCallback ptcl@(Consensus.ProtocolCardano | ||
_ | ||
Consensus.ProtocolParamsShelleyBased{Consensus.shelleyBasedGenesis} | ||
_ _ _ _ _ _) | ||
nmagic_opt is_addr_mn iom (SocketPath sock) tracers _proxy | ||
= action | ||
where | ||
action benchmark fundOptions | ||
= funding benchmark fundOptions >>= benchmarkAction benchmark | ||
|
||
ProtocolInfo{pInfoConfig} = Consensus.protocolInfo ptcl | ||
localConnectInfo = LocalNodeConnectInfo | ||
sock | ||
(Api.Testnet . getNetworkMagic . configBlock $ pInfoConfig) | ||
(CardanoMode (EpochSlots 21600)) -- TODO: get this from genesis | ||
|
||
connectClient :: ConnectClient | ||
connectClient = benchmarkConnectTxSubmit | ||
iom | ||
(btConnect_ tracers) | ||
(btSubmission_ tracers) | ||
(configCodec pInfoConfig) | ||
(getNetworkMagic $ configBlock pInfoConfig) | ||
|
||
funding :: Funding era | ||
funding = secureFunds | ||
(btTxSubmit_ tracers) | ||
localConnectInfo | ||
networkId | ||
shelleyBasedGenesis | ||
|
||
benchmarkAction :: BenchmarkAction era | ||
benchmarkAction = runBenchmark (btTxSubmit_ tracers) (btN2N_ tracers) networkId connectClient | ||
|
||
networkId = if is_addr_mn | ||
then Mainnet | ||
else Testnet $ getNetworkMagic $ configBlock pInfoConfig | ||
|
||
mkCallback _ _ _ _ _ _ _ = error "mkCallbacks" |
Oops, something went wrong.