Skip to content

Commit bed2e44

Browse files
author
Denis Shevchenko
committed
CAD-426: submit transactions to Explorer's WebAPI using tx gen.
1 parent 9b929e1 commit bed2e44

File tree

6 files changed

+298
-65
lines changed

6 files changed

+298
-65
lines changed

cardano-node/cardano-node.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ library
8181
, filepath
8282
, formatting
8383
, hostname
84+
, http-client
85+
, http-types
8486
, io-sim-classes
8587
, iohk-monitoring
8688
, iproute
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Submit Transactions to WebAPI using Transaction Generator
2+
3+
This document demonstrates how to submit transactions to `cardano-tx-submit-webapi` using [transaction generator](https://github.com/input-output-hk/cardano-node/blob/master/cardano-node/src/Cardano/CLI/Tx/Generation.hs).
4+
5+
## Prepare Local Cluster to Start
6+
7+
Go to `cardano-node` repository and remove nodes' local databases if needed:
8+
9+
```
10+
$ rm -rf db/
11+
```
12+
13+
Also remove an old genesis files:
14+
15+
```
16+
$ rm -rf configuration/genesis/*
17+
```
18+
19+
Now create the new genesis:
20+
21+
```
22+
$ ./scripts/genesis.sh
23+
```
24+
25+
Please see an output, you should see something like this:
26+
27+
```
28+
...
29+
genesis created with hash = b8f44e852982a88aaf352684bc507fd337a15117f01f43816abfb2487a67d348
30+
...
31+
```
32+
33+
## Run Local Cluster
34+
35+
Go to `tmux` and launch the local cluster (Shelley in Live View mode):
36+
37+
```
38+
$ tmux
39+
$ ./scripts/shelley-testnet-live.sh
40+
```
41+
42+
You will see 3 `tmux` panes with the nodes. Please see the `block number` value: if it increases, the cluster is working correctly.
43+
44+
## Run Tx Submit WebAPI
45+
46+
Go to `cardano-explorer` repository and create configuration for `cardano-tx-submit-webapi`:
47+
48+
```
49+
$ ./scripts/gen-tx-submit-config.sh --require-magic --genesis-hash GEN_HASH --output config.yaml
50+
```
51+
52+
where `GEN_HASH` is the hash of genesis you've got from the output of `./scripts/genesis.sh` script. As a result, you will see the file `config.yaml` in the current directory.
53+
54+
Run `cardano-tx-submit-webapi`:
55+
56+
```
57+
$ cabal new-run cardano-tx-submit-webapi -- --config config.yaml --genesis-file /path-to/cardano-node/configuration/genesis/genesis.json --socket-path /path-to/cardano-node/socket/0 --port 8101
58+
```
59+
60+
Possible output is this:
61+
62+
```
63+
[cardano-tx-submit:Info:9] [2020-02-11 08:05:34.82 UTC] Running tx-submit node
64+
[cardano-tx-submit:Info:9] [2020-02-11 08:05:34.82 UTC] NetworkMagic: RequiresMagic 459045235
65+
[cardano-tx-submit:Info:9] [2020-02-11 08:05:34.82 UTC] localInitiatorNetworkApplication: connecting to node via "/path-to/cardano-node/socket/0"
66+
[cardano-tx-submit:Info:10] [2020-02-11 08:05:34.82 UTC] Running tx-submit web server on http://localhost:8101/
67+
```
68+
69+
It means that `cardano-tx-submit-webapi` is listening to the port `8101` and ready to receive transactions.
70+
71+
## Run transaction Generator
72+
73+
Go to `cardano-node` repository again and run transaction generator. For example, if you have built it using `stack`:
74+
75+
```
76+
$ stack exec -- cardano-cli generate-txs --config /path-to/tx-gen-log-config.yaml --signing-key /path-to/cardano-node/configuration/genesis/delegate-keys.000.key --delegation-certificate /path-to/cardano-node/configuration/genesis/delegation-cert.000.json --genesis-file /path-to/cardano-node/configuration/genesis/genesis.json --socket-path /path-to/cardano-node/socket/0 --num-of-txs 100 --add-tx-size 0 --inputs-per-tx 1 --outputs-per-tx 1 --tx-fee 10000000 --tps 2 --sig-key /path-to/cardano-node/configuration/genesis/delegate-keys.000.key --sig-key /path-to/cardano-node/configuration/genesis/delegate-keys.001.key --sig-key /path-to/cardano-node/configuration/genesis/delegate-keys.002.key --submit-to-api "http://localhost:8101/api/submit/tx" --target-node '("127.0.0.1",3000)'
77+
```
78+
79+
In this example 100 transactions will be generated. Please note that this number **does not** include genesis transaction and splitting transactions, so technically **103** tranactions will be generated: 1 genesis transaction + 2 splitting transactions + 100 main transactions. You can see it in the output of `cardano-tx-submit-webapi`:
80+
81+
82+
```
83+
[cardano-tx-submit:Info:22] [2020-02-11 08:10:25.30 UTC] txSubmitPost: received 249 bytes <- genesis transaction
84+
[cardano-tx-submit:Info:22] [2020-02-11 08:10:25.30 UTC] Success
85+
[cardano-tx-submit:Info:24] [2020-02-11 08:10:25.30 UTC] txSubmitPost: received 3849 bytes <- splitting transaction #1
86+
[cardano-tx-submit:Info:24] [2020-02-11 08:10:25.30 UTC] Success
87+
[cardano-tx-submit:Info:25] [2020-02-11 08:10:25.31 UTC] txSubmitPost: received 2646 bytes <- splitting transaction #2
88+
[cardano-tx-submit:Info:25] [2020-02-11 08:10:25.31 UTC] Success
89+
[cardano-tx-submit:Info:26] [2020-02-11 08:10:45.33 UTC] txSubmitPost: received 307 bytes <- main transaction #1
90+
[cardano-tx-submit:Info:26] [2020-02-11 08:10:45.33 UTC] Success
91+
...
92+
[cardano-tx-submit:Info:141] [2020-02-11 08:11:35.82 UTC] txSubmitPost: received 308 bytes <- main transaction #100
93+
[cardano-tx-submit:Info:141] [2020-02-11 08:11:35.83 UTC] Success
94+
```
95+
96+
Please note that an argument `--submit-to-api` specifies the full API endpoint, for example, `"http://localhost:8101/api/submit/tx"`. In this case, an argument `--target-node '("127.0.0.1",3000)'` will be **ignored**, because all 103 transactions will be sent to specified API endpoint (not to the node as usual).

cardano-node/src/Cardano/CLI/Parsers.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ parseBenchmarkingCommands =
126126
"add-tx-size"
127127
"Additional size of transaction, in bytes."
128128
)
129+
<*> optional (
130+
parseExplorerAPIEndpoint
131+
"submit-to-api"
132+
"Explorer's API endpoint to submit transaction."
133+
)
129134
<*> parseSigningKeysFiles
130135
"sig-key"
131136
"Path to signing key file, for genesis UTxO using by generator."
@@ -404,6 +409,9 @@ parseTPSRate opt desc = TPSRate <$> parseIntegral opt desc
404409
parseTxAdditionalSize :: String -> String -> Parser TxAdditionalSize
405410
parseTxAdditionalSize opt desc = TxAdditionalSize <$> parseIntegral opt desc
406411

412+
parseExplorerAPIEndpoint :: String -> String -> Parser ExplorerAPIEnpoint
413+
parseExplorerAPIEndpoint opt desc = ExplorerAPIEnpoint <$> parseUrl opt desc
414+
407415
parseTxFile :: String -> Parser TxFile
408416
parseTxFile opt =
409417
TxFile

cardano-node/src/Cardano/CLI/Run.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Cardano.CLI.Run (
2525
, FeePerTx(..)
2626
, TPSRate(..)
2727
, TxAdditionalSize(..)
28+
, ExplorerAPIEnpoint(..)
2829
) where
2930

3031
import Cardano.Prelude hiding (option, trace)
@@ -61,6 +62,7 @@ import Cardano.CLI.Tx.Generation (NumberOfTxs (..),
6162
NumberOfOutputsPerTx (..),
6263
FeePerTx (..), TPSRate (..),
6364
TxAdditionalSize (..),
65+
ExplorerAPIEnpoint (..),
6466
genesisBenchmarkRunner)
6567
import Cardano.Common.Orphans ()
6668
import Cardano.Config.Protocol
@@ -181,6 +183,7 @@ data ClientCommand
181183
FeePerTx
182184
TPSRate
183185
(Maybe TxAdditionalSize)
186+
(Maybe ExplorerAPIEnpoint)
184187
[SigningKeyFile]
185188
deriving Show
186189
runCommand :: ClientCommand -> ExceptT CliError IO ()
@@ -311,6 +314,7 @@ runCommand (GenerateTxs
311314
feePerTx
312315
tps
313316
txAdditionalSize
317+
explorerAPIEndpoint
314318
sigKeysFiles) = do
315319
-- Default update value
316320
let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0
@@ -347,6 +351,7 @@ runCommand (GenerateTxs
347351
feePerTx
348352
tps
349353
txAdditionalSize
354+
explorerAPIEndpoint
350355
[fp | SigningKeyFile fp <- sigKeysFiles]
351356

352357
{-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)