github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/docs/source/app_developers_guide/docker.rst (about) 1 ********************************************* 2 Using Docker for your Development Environment 3 ********************************************* 4 5 This procedure explains how to set up Hyperledger Sawtooth for application 6 development using a multi-container Docker environment. It shows you how to 7 start Sawtooth and connect to the necessary Docker containers, then walks you 8 through the following tasks: 9 10 * Checking the status of Sawtooth components 11 * Using Sawtooth commands to submit transactions, display block data, and view 12 global state 13 * Examining Sawtooth logs 14 * Stopping Sawtooth and resetting the Docker environment 15 16 After completing this tutorial, you will have the application development 17 environment that is required for the other tutorials in this guide. The next 18 tutorial introduces the XO transaction family by using the ``xo`` client 19 commands to play a game of tic-tac-toe. The final set of tutorials describe how 20 to use an SDK to create a transaction family that implements your application's 21 business logic. 22 23 About the Application Development Environment 24 ============================================= 25 26 The Docker application development environment is a single validator node that 27 is running a validator, a REST API, and three transaction processors. This 28 environment uses Developer mode (dev mode) consensus and serial transaction 29 processing. 30 31 .. figure:: ../images/appdev-environment-one-node-3TPs.* 32 :width: 100% 33 :align: center 34 :alt: Docker application environment environment for Sawtooth 35 36 This environment introduces basic Sawtooth functionality with the 37 `IntegerKey 38 <../transaction_family_specifications/integerkey_transaction_family>`_ 39 and 40 `Settings <../transaction_family_specifications/settings_transaction_family>`_ 41 transaction processors for the business logic and Sawtooth commands as a client. 42 It also includes the 43 `XO <../transaction_family_specifications/xo_transaction_family>`_ 44 transaction processor, which is used in later tutorials. 45 46 The IntegerKey and XO families are simple examples of a transaction family, but 47 Settings is a reference implementation. In a production environment, you should 48 always run a transaction processor that supports the Settings transaction 49 family. 50 51 .. note:: 52 53 The Docker environment includes a Docker Compose file that 54 handles environment setup steps such as generating keys and creating a 55 genesis block. To learn how the typical startup process works, see 56 :doc:`ubuntu`. 57 58 59 Prerequisites 60 ============= 61 62 This application development environment requires Docker Engine and Docker 63 Compose. 64 65 * Windows: Install the latest version of 66 `Docker Engine for Windows <https://docs.docker.com/docker-for-windows/install/>`_ 67 (also installs Docker Compose). 68 69 * macOS: Install the latest version of 70 `Docker Engine for macOS <https://docs.docker.com/docker-for-mac/install/>`_ 71 (also installs Docker Compose). 72 73 * Linux: Install the latest versions of 74 `Docker Engine <https://docs.docker.com/engine/installation/linux/ubuntu>`_ 75 and 76 `Docker Compose <https://docs.docker.com/compose/install/#install-compose>`_. 77 Then follow 78 `Post-Install steps 79 <https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user>`_. 80 81 In this procedure, you will open six terminal windows to connect to the Docker 82 containers: one for each Sawtooth component and one to use for client commands. 83 84 .. note:: 85 86 The Docker Compose file for Sawtooth handles environment setup steps such as 87 generating keys and creating a genesis block. To learn how the typical 88 startup process works, see :doc:`ubuntu`. 89 90 91 Step 1: Download the Sawtooth Docker Compose File 92 ================================================= 93 94 Download the Docker Compose file for the Sawtooth environment, 95 `sawtooth-default.yaml <./sawtooth-default.yaml>`_. 96 97 This example Compose file defines the process for constructing a simple 98 Sawtooth environment with following containers: 99 100 * A single validator using dev mode consensus 101 * A REST API connected to the validator 102 * The Settings transaction processor (``sawtooth-settings``) 103 * The IntegerKey transaction processor (``intkey-tp-python``) 104 * The XO transaction processor (``xo-tp-python``) 105 * A client (shell) container for running Sawtooth commands 106 107 The Compose file also specifies the container images to download from Docker Hub 108 and the network settings needed for all the containers to communicate correctly. 109 110 After completing the tutorials in this guide, you can use this Compose file as 111 the basis for your own multi-container Sawtooth development environment or 112 application. 113 114 115 Step 2: Configure Proxy Settings (Optional) 116 =========================================== 117 118 To configure Docker to work with an HTTP or HTTPS proxy server, follow the 119 instructions for proxy configuration in the documentation for your operating 120 system: 121 122 * Windows - See "`Get Started with Docker for Windows 123 <https://docs.docker.com/docker-for-windows/#proxies>`_". 124 125 * macOS - See "`Get Started with Docker for Mac 126 <https://docs.docker.com/docker-for-mac/>`_". 127 128 * Linux - See "`Control and configure Docker with Systemd 129 <https://docs.docker.com/engine/admin/systemd/#httphttps-proxy>`_". 130 131 132 Step 3: Start the Sawtooth Docker Environment 133 ============================================= 134 135 To start the Sawtooth Docker environment, perform the following tasks: 136 137 1. Open a terminal window. 138 139 #. Change your working directory to the same directory where you saved the 140 Docker Compose file. 141 142 #. Run the following command: 143 144 .. _restart: 145 146 .. code-block:: console 147 148 user@host$ docker-compose -f sawtooth-default.yaml up 149 150 .. tip:: 151 If you previously ran ``docker-compose ... up`` without a clean shut down, 152 run the following command first: 153 154 ``docker-compose -f sawtooth-default.yaml down`` 155 156 #. Downloading the Docker images for the Sawtooth environment can take 157 several minutes. Wait until you see output that shows the containers 158 registering and creating initial blocks. Once you see output that resembles 159 the following example, you can move on to the next step. 160 161 .. code-block:: console 162 163 ... 164 sawtooth-settings-tp-default | [2018-03-08 22:55:10.537 INFO core] register attempt: OK 165 sawtooth-settings-tp-default | [2018-03-08 22:55:10.538 DEBUG core] received message of type: TP_PROCESS_REQUEST 166 sawtooth-settings-tp-default | [2018-03-08 22:55:10.550 INFO handler] Setting setting sawtooth.settings.vote.authorized_keys changed from None to 039fa17f2962706aae83f3cc1f7d0c51dda7ffe15f5811fefd4ea5fdd3e84d0755 167 sawtooth-validator-default | [2018-03-08 22:55:10.557 DEBUG genesis] Produced state hash 53d38378e8c61f42112c39f9c84d42d339320515ef44f50d6b4dd52f3f1b9054 for genesis block. 168 sawtooth-validator-default | [2018-03-08 22:55:10.560 INFO genesis] Genesis block created: 60e79c91757c73185b36802661833f586f4dd5ef3c4cb889f37c287921af8ad01a8b95e9d81af698e6c3f3eb7b65bfd6f6b834ffc9bc36317d8a1ae7ecc45668 (block_num:0, state:53d38378e8c61f42112c39f9c84d42d339320515ef44f50d6b4dd52f3f1b9054, previous_block_id:0000000000000000) 169 sawtooth-validator-default | [2018-03-08 22:55:10.561 DEBUG chain_id_manager] writing block chain id 170 sawtooth-validator-default | [2018-03-08 22:55:10.562 DEBUG genesis] Deleting genesis data. 171 sawtooth-validator-default | [2018-03-08 22:55:10.564 DEBUG selector_events] Using selector: ZMQSelector 172 sawtooth-validator-default | [2018-03-08 22:55:10.565 INFO interconnect] Listening on tcp://eth0:8800 173 sawtooth-validator-default | [2018-03-08 22:55:10.566 DEBUG dispatch] Added send_message function for connection ServerThread 174 sawtooth-validator-default | [2018-03-08 22:55:10.566 DEBUG dispatch] Added send_last_message function for connection ServerThread 175 sawtooth-validator-default | [2018-03-08 22:55:10.568 INFO chain] Chain controller initialized with chain head: 60e79c91757c73185b36802661833f586f4dd5ef3c4cb889f37c287921af8ad01a8b95e9d81af698e6c3f3eb7b65bfd6f6b834ffc9bc36317d8a1ae7ecc45668 (block_num:0, state:53d38378e8c61f42112c39f9c84d42d339320515ef44f50d6b4dd52f3f1b9054, previous_block_id:0000000000000000) 176 sawtooth-validator-default | [2018-03-08 22:55:10.569 INFO publisher] Now building on top of block: 60e79c91757c73185b36802661833f586f4dd5ef3c4cb889f37c287921af8ad01a8b95e9d81af698e6c3f3eb7b65bfd6f6b834ffc9bc36317d8a1ae7ecc45668 (block_num:0, state:53d38378e8c61f42112c39f9c84d42d339320515ef44f50d6b4dd52f3f1b9054, previous_block_id:0000000000000000) 177 ... 178 179 This terminal window will continue to display log messages as you run commands 180 in other containers. 181 182 .. note:: 183 184 If you need to reset the environment for any reason, see 185 :ref:`stop-sawtooth-docker-label`. 186 187 188 Step 4: Log Into the Client Container 189 ===================================== 190 191 Sawtooth includes commands that act as a client application. The client 192 container is used to run these Sawtooth commands, which interact with the 193 validator through the REST API. 194 195 To log into the client container, open a new terminal window and run the 196 following command: 197 198 .. code-block:: console 199 200 user@host$ docker exec -it sawtooth-shell-default bash 201 root@client# 202 203 In this procedure, the prompt ``root@client#`` is used for commands that should 204 be run in the terminal window for the client container. 205 206 .. important:: 207 208 Your environment is ready for experimenting with Sawtooth. However, any work 209 done in this environment will be lost once the container in which you ran 210 ``docker-compose`` exits. In order to use this application development 211 environment for application development, you would need to take additional 212 steps, such as mounting a host directory into the container. See the `Docker 213 documentation <https://docs.docker.com/>`_ for more information. 214 215 .. _confirming-connectivity-docker-label: 216 217 Step 5: Confirm Connectivity to the REST API 218 ============================================ 219 220 #. To confirm that the REST API and validator are running and reachable from 221 the client container, run this ``curl`` command: 222 223 .. code-block:: console 224 225 root@client# curl http://rest-api:8008/blocks 226 227 #. To check connectivity from the host computer, open a new terminal window on 228 your host system and run this ``curl`` command: 229 230 .. code-block:: console 231 232 user@host$ curl http://localhost:8008/blocks 233 234 If the validator and REST API are running and reachable, the output for each 235 command should be similar to this example: 236 237 .. code-block:: console 238 239 { 240 "data": [ 241 { 242 "batches": [], 243 "header": { 244 "batch_ids": [], 245 "block_num": 0, 246 "mconsensus": "R2VuZXNpcw==", 247 "previous_block_id": "0000000000000000", 248 "signer_public_key": "03061436bef428626d11c17782f9e9bd8bea55ce767eb7349f633d4bfea4dd4ae9", 249 "state_root_hash": "708ca7fbb701799bb387f2e50deaca402e8502abe229f705693d2d4f350e1ad6" 250 }, 251 "header_signature": "119f076815af8b2c024b59998e2fab29b6ae6edf3e28b19de91302bd13662e6e43784263626b72b1c1ac120a491142ca25393d55ac7b9f3c3bf15d1fdeefeb3b" 252 } 253 ], 254 "head": "119f076815af8b2c024b59998e2fab29b6ae6edf3e28b19de91302bd13662e6e43784263626b72b1c1ac120a491142ca25393d55ac7b9f3c3bf15d1fdeefeb3b", 255 "link": "http://rest-api:8008/blocks?head=119f076815af8b2c024b59998e2fab29b6ae6edf3e28b19de91302bd13662e6e43784263626b72b1c1ac120a491142ca25393d55ac7b9f3c3bf15d1fdeefeb3b", 256 "paging": { 257 "start_index": 0, 258 "total_count": 1 259 } 260 } 261 262 If the validator process or the validator container is not running, the 263 ``curl`` command will time out or return nothing. 264 265 266 .. _configure-tf-settings-docker-label: 267 268 Step 6: Use Sawtooth Commands as a Client 269 ========================================= 270 271 Sawtooth includes commands that act as a client application. This step describes 272 how to use the ``intkey`` and ``sawtooth`` commands to create and submit 273 transactions, display blockchain and block data, and examine global state data. 274 275 .. note:: 276 277 Use the ``--help`` option with any Sawtooth command to display the available 278 options and subcommands. 279 280 To run the commands in this section, use the terminal window for the client 281 container. 282 283 Creating and Submitting Transactions with intkey 284 ------------------------------------------------ 285 286 The ``intkey`` command creates and submits IntegerKey transactions for testing 287 purposes. 288 289 #. Use ``intkey create_batch`` to prepare batches of transactions that set 290 a few keys to random values, then randomly increment and decrement those 291 values. These batches are saved locally in the file ``batches.intkey``. 292 293 .. code-block:: console 294 295 root@client# intkey create_batch --count 10 --key-count 5 296 Writing to batches.intkey... 297 298 #. Use ``intkey load`` to submit the batches to the validator. 299 300 .. code-block:: console 301 302 root@client# intkey load -f batches.intkey --url http://rest-api:8008 303 batches: 11 batch/sec: 141.7800162868952 304 305 #. The terminal window in which you ran the ``docker-compose`` command displays 306 log messages showing that the validator is handling the submitted 307 transactions and that values are being incremented and decremented, as in 308 this example: 309 310 .. code-block:: console 311 312 sawtooth-intkey-tp-python-default | [2018-03-08 21:26:20.334 DEBUG core] received message of type: TP_PROCESS_REQUEST 313 sawtooth-intkey-tp-python-default | [2018-03-08 21:26:20.339 DEBUG handler] Decrementing "GEJTiZ" by 10 314 sawtooth-intkey-tp-python-default | [2018-03-08 21:26:20.347 DEBUG core] received message of type: TP_PROCESS_REQUEST 315 sawtooth-intkey-tp-python-default | [2018-03-08 21:26:20.352 DEBUG handler] Decrementing "lrAYjm" by 8 316 ... 317 sawtooth-validator-default | [2018-03-08 21:26:20.397 INFO chain] Fork comparison at height 50 is between - and 3d4d952d 318 sawtooth-validator-default | [2018-03-08 21:26:20.397 INFO chain] Chain head updated to: 3d4d952d4774988bd67a4deb85830155a5f505c68bea11d832a6ddbdd5eeebc34f5a63a9e59a426376cd2e215e19c0dfa679fe016be26307c3ee698cce171d51 (block_num:50, state:e18c2ce54859d1e9a6e4fb949f8d861e483d330b363b4060b069f53d7e6c6380, previous_block_id:e05737151717eb8787a2db46279fedf9d331a501c12cd8059df379996d9a34577cf605e95f531514558b200a386dc73e11de3fa17d6c00882acf6f9d9c387e82) 319 sawtooth-validator-default | [2018-03-08 21:26:20.398 INFO publisher] Now building on top of block: 3d4d952d4774988bd67a4deb85830155a5f505c68bea11d832a6ddbdd5eeebc34f5a63a9e59a426376cd2e215e19c0dfa679fe016be26307c3ee698cce171d51 (block_num:50, state:e18c2ce54859d1e9a6e4fb949f8d861e483d330b363b4060b069f53d7e6c6380, previous_block_id:e05737151717eb8787a2db46279fedf9d331a501c12cd8059df379996d9a34577cf605e95f531514558b200a386dc73e11de3fa17d6c00882acf6f9d9c387e82) 320 sawtooth-validator-default | [2018-03-08 21:26:20.401 DEBUG chain] Verify descendant blocks: 3d4d952d4774988bd67a4deb85830155a5f505c68bea11d832a6ddbdd5eeebc34f5a63a9e59a426376cd2e215e19c0dfa679fe016be26307c3ee698cce171d51 (block_num:50, state:e18c2ce54859d1e9a6e4fb949f8d861e483d330b363b4060b069f53d7e6c6380, previous_block_id:e05737151717eb8787a2db46279fedf9d331a501c12cd8059df379996d9a34577cf605e95f531514558b200a386dc73e11de3fa17d6c00882acf6f9d9c387e82) ([]) 321 sawtooth-validator-default | [2018-03-08 21:26:20.402 INFO chain] Finished block validation of: 3d4d952d4774988bd67a4deb85830155a5f505c68bea11d832a6ddbdd5eeebc34f5a63a9e59a426376cd2e215e19c0dfa679fe016be26307c3ee698cce171d51 (block_num:50, state:e18c2ce54859d1e9a6e4fb949f8d861e483d330b363b4060b069f53d7e6c6380, previous_block_id:e05737151717eb8787a2db46279fedf9d331a501c12cd8059df379996d9a34577cf605e95f531514558b200a386dc73e11de3fa17d6c00882acf6f9d9c387e82) 322 323 #. You can also use ``docker logs`` to examine at the Sawtooth log messages 324 from your host system. For example, this command displays the last five 325 entries in the log: 326 327 .. code-block:: console 328 329 user@host$ docker logs --tail 5 sawtooth-validator-default 330 sawtooth-validator-default | [2018-03-08 21:26:20.397 INFO chain] Fork comparison at height 50 is between - and 3d4d952d 331 sawtooth-validator-default | [2018-03-08 21:26:20.397 INFO chain] Chain head updated to: 3d4d952d4774988bd67a4deb85830155a5f505c68bea11d832a6ddbdd5eeebc34f5a63a9e59a426376cd2e215e19c0dfa679fe016be26307c3ee698cce171d51 (block_num:50, state:e18c2ce54859d1e9a6e4fb949f8d861e483d330b363b4060b069f53d7e6c6380, previous_block_id:e05737151717eb8787a2db46279fedf9d331a501c12cd8059df379996d9a34577cf605e95f531514558b200a386dc73e11de3fa17d6c00882acf6f9d9c387e82) 332 sawtooth-validator-default | [2018-03-08 21:26:20.398 INFO publisher] Now building on top of block: 3d4d952d4774988bd67a4deb85830155a5f505c68bea11d832a6ddbdd5eeebc34f5a63a9e59a426376cd2e215e19c0dfa679fe016be26307c3ee698cce171d51 (block_num:50, state:e18c2ce54859d1e9a6e4fb949f8d861e483d330b363b4060b069f53d7e6c6380, previous_block_id:e05737151717eb8787a2db46279fedf9d331a501c12cd8059df379996d9a34577cf605e95f531514558b200a386dc73e11de3fa17d6c00882acf6f9d9c387e82) 333 sawtooth-validator-default | [2018-03-08 21:26:20.401 DEBUG chain] Verify descendant blocks: 3d4d952d4774988bd67a4deb85830155a5f505c68bea11d832a6ddbdd5eeebc34f5a63a9e59a426376cd2e215e19c0dfa679fe016be26307c3ee698cce171d51 (block_num:50, state:e18c2ce54859d1e9a6e4fb949f8d861e483d330b363b4060b069f53d7e6c6380, previous_block_id:e05737151717eb8787a2db46279fedf9d331a501c12cd8059df379996d9a34577cf605e95f531514558b200a386dc73e11de3fa17d6c00882acf6f9d9c387e82) ([]) 334 sawtooth-validator-default | [2018-03-08 21:26:20.402 INFO chain] Finished block validation of: 3d4d952d4774988bd67a4deb85830155a5f505c68bea11d832a6ddbdd5eeebc34f5a63a9e59a426376cd2e215e19c0dfa679fe016be26307c3ee698cce171d51 (block_num:50, state:e18c2ce54859d1e9a6e4fb949f8d861e483d330b363b4060b069f53d7e6c6380, previous_block_id:e05737151717eb8787a2db46279fedf9d331a501c12cd8059df379996d9a34577cf605e95f531514558b200a386dc73e11de3fa17d6c00882acf6f9d9c387e82) 335 336 Submitting Transactions with sawtooth batch submit 337 -------------------------------------------------- 338 339 In the example above, the ``intkey create_batch`` command created the file 340 ``batches.intkey``. Rather than using ``intkey load`` to submit these 341 transactions, you could use ``sawtooth batch submit`` to submit them. 342 343 #. As before, create a batch of transactions: 344 345 .. code-block:: console 346 347 root@client# intkey create_batch --count 10 --key-count 5 348 Writing to batches.intkey... 349 350 #. Submit the batch file with ``sawtooth batch submit``: 351 352 .. code-block:: console 353 354 root@client# sawtooth batch submit -f batches.intkey --url http://rest-api:8008 355 batches: 11, batch/sec: 216.80369536716367 356 357 Viewing Blockchain and Block Data with sawtooth block 358 ----------------------------------------------------- 359 360 The ``sawtooth block`` command displays information about the blocks stored on 361 the blockchain. 362 363 #. Use ``sawtooth block list`` to display the list of blocks stored in state. 364 365 .. code-block:: console 366 367 root@client# sawtooth block list --url http://rest-api:8008 368 369 The output shows the block number and block ID, as in this example: 370 371 .. code-block:: console 372 373 NUM BLOCK_ID BATS TXNS SIGNER 374 61 9566426220751691b7463e3c1ec1d8c4f158c98e89722672721d457182cb3b3d48e734ddceabf706b41fc3e1f8d739451f7d70bd5a8708bc4085b6fb33b40bef 1 4 020d21... 375 60 309c0707b95609d4ebc2fad0afd590ec40db41680a3edbbeb0875720ed59f4d775e1160a2c6cbe2e9ccb34c4671f4cd7db1e5ed35a2ed9a0f2a2c99aa981f83c 1 5 020d21... 376 59 e0c6c29a9f3d1436e4837c96587ae3fa60274991efa9d0c9000d53694cd2a0841914b2f362aa05c2385126288f060f524bac3a05850edb1ac1c86f0c237afdba 1 3 020d21... 377 58 8c67a1ec68bfdd5b07bb02919019b917ed26dbc6ec0fc3de15d539538bd30f8a1aa58795578970d2e607cd63cf1f5ef921476cbc0564cbe37469e5e50b72ecf2 1 3 020d21... 378 57 879c6cb43e244fb7c1676cf5d9e51ace25ad8e670f37e81b81e5d9e133aebba80282913677821c14fe2ccb2aae631229bdd044222e6a8927f4f5dabb6d62c409 1 4 020d21... 379 ... 380 5 dce0921531472a8f9840e256c585917dfc22b78c5045a3416ed76faf57232b065b8be5a34023e8a8cdab74ab24cf029a5c1051f742b9b5280b8edab5a80d805d 2 4 020d21... 381 4 0007380e98fc6d63de1d47261b83186bce9722023f2e6ab6849916766e9be29f4903d76a642dfc27579b8a8bf9adba5f077c1f1457b2cad8f52a28d7079333a6 1 8 020d21... 382 3 515c827b9e84c22c24838130d4e0f6af07ab271c138a61c555a830c4118a75815f54340ef3f04de009c94c3531f3202690708cf16fcfee04303972cb91e3b87a 1 10 020d21... 383 2 9067bcb093bb095ca436d8868914ecf2630215d36bfd78b0b167554c544b9842193dd309f135e6959a664fe34b06b4f16a297528249550821cda9273291ebe70 1 5 020d21... 384 1 3ab950b2cd370f26e188d95ee97268965732768080ca1adb71759e3c1f22d1ea19945b48fc81f5f821387fde355349f87096da00a4e356408b630ab80576d3ae 1 5 020d21... 385 0 51a704e1a83086372a3c0823533881ffac9479995289902a311fd5d99ff6a32216cd1fb9883a421449c943cad8604ce1447b0f6080c8892e334b14dc082f91d3 1 1 020d21... 386 387 #. From the output generated by ``sawtooth block list``, copy the ID of a block 388 you want to view, then paste it in place of ``{BLOCK_ID}`` in the following 389 command: 390 391 .. code-block:: console 392 393 root@client# sawtooth block show --url http://rest-api:8008 {BLOCK_ID} 394 395 The output of this command can be quite long, because it includes all data 396 stored under that block. This is a truncated example: 397 398 .. code-block:: console 399 400 batches: 401 - header: 402 signer_public_key: 0276023d4f7323103db8d8683a4b7bc1eae1f66fbbf79c20a51185f589e2d304ce 403 transaction_ids: 404 - 24b168aaf5ea4a76a6c316924a1c26df0878908682ea5740dd70814e7c400d56354dee788191be8e28393c70398906fb467fac8db6279e90e4e61619589d42bf 405 header_signature: a93731646a8fd2bce03b3a17bc2cb3192d8597da93ce735950dccbf0e3cf0b005468fadb94732e013be0bc2afb320be159b452cf835b35870db5fa953220fb35 406 transactions: 407 - header: 408 batcher_public_key: 0276023d4f7323103db8d8683a4b7bc1eae1f66fbbf79c20a51185f589e2d304ce 409 dependencies: [] 410 family_name: sawtooth_settings 411 family_version: '1.0' 412 ... 413 header: 414 batch_ids: 415 - a93731646a8fd2bce03b3a17bc2cb3192d8597da93ce735950dccbf0e3cf0b005468fadb94732e013be0bc2afb320be159b452cf835b35870db5fa953220fb35 416 block_num: 3 417 consensus: RGV2bW9kZQ== 418 previous_block_id: 042f08e1ff49bbf16914a53dc9056fb6e522ca0e2cff872547eac9555c1de2a6200e67fb9daae6dfb90f02bef6a9088e94e5bdece04f622bce67ccecd678d56e 419 signer_public_key: 033fbed13b51eafaca8d1a27abc0d4daf14aab8c0cbc1bb4735c01ff80d6581c52 420 state_root_hash: 5d5ea37cbbf8fe793b6ea4c1ba6738f5eee8fc4c73cdca797736f5afeb41fbef 421 header_signature: ff4f6705bf57e2a1498dc1b649cc9b6a4da2cc8367f1b70c02bc6e7f648a28b53b5f6ad7c2aa639673d873959f5d3fcc11129858ecfcb4d22c79b6845f96c5e3 422 423 Viewing State Data with sawtooth state 424 -------------------------------------- 425 426 The ``sawtooth state`` command lets you display state data. Sawtooth stores 427 state data in a :term:`Merkle-Radix tree`; for more information, see 428 :doc:`../architecture/global_state`. 429 430 #. Use ``sawtooth state list`` to list the nodes (addresses) in state: 431 432 .. code-block:: console 433 434 root@client# sawtooth state list --url http://rest-api:8008 435 436 The output will be similar to this truncated example: 437 438 .. code-block:: console 439 440 ADDRESS SIZE DATA 441 1cf126ddb507c936e4ee2ed07aa253c2f4e7487af3a0425f0dc7321f94be02950a081ab7058bf046c788dbaf0f10a980763e023cde0ee282585b9855e6e5f3715bf1fe 11 b'\xa1fcCTdcH\x... 442 1cf1260cd1c2492b6e700d5ef65f136051251502e5d4579827dc303f7ed76ddb7185a19be0c6443503594c3734141d2bdcf5748a2d8c75541a8e568bae063983ea27b9 11 b'\xa1frdLONu\x... 443 1cf126ed7d0ac4f755be5dd040e2dfcd71c616e697943f542682a2feb14d5f146538c643b19bcfc8c4554c9012e56209f94efe580b6a94fb326be9bf5bc9e177d6af52 11 b'\xa1fAUZZqk\x... 444 1cf126c46ff13fcd55713bcfcf7b66eba515a51965e9afa8b4ff3743dc6713f4c40b4254df1a2265d64d58afa14a0051d3e38999704f6e25c80bed29ef9b80aee15c65 11 b'\xa1fLvUYLk\x... 445 1cf126c4b1b09ebf28775b4923e5273c4c01ba89b961e6a9984632612ec9b5af82a0f7c8fc1a44b9ae33bb88f4ed39b590d4774dc43c04c9a9bd89654bbee68c8166f0 13 b'\xa1fXHonWY\x... 446 1cf126e924a506fb2c4bb8d167d20f07d653de2447df2754de9eb61826176c7896205a17e363e457c36ccd2b7c124516a9b573d9a6142f031499b18c127df47798131a 13 b'\xa1foWZXEz\x... 447 1cf126c295a476acf935cd65909ed5ead2ec0168f3ee761dc6f37ea9558fc4e32b71504bf0ad56342a6671db82cb8682d64689838731da34c157fa045c236c97f1dd80 13 b'\xa1fadKGve\x... 448 449 #. Use ``sawtooth state show`` to view state data at a specific address (a node 450 in the Merkle-Radix database). Copy the address from the output of 451 ``sawtooth state list``, then paste it in place of ``{STATE_ADDRESS}`` in 452 the following command: 453 454 .. code-block:: console 455 456 root@client# sawtooth state show --url http://rest-api:8008 {STATE_ADDRESS} 457 458 The output shows the bytes stored at that address and the block ID of the 459 "chain head" that the current state is tied to, as in this example: 460 461 .. code-block:: console 462 463 DATA: "b'\xa1fcCTdcH\x192B'" 464 HEAD: "0c4364c6d5181282a1c7653038ec9515cb0530c6bfcb46f16e79b77cb524491676638339e8ff8e3cc57155c6d920e6a4d1f53947a31dc02908bcf68a91315ad5" 465 466 .. _container-names-label: 467 468 Step 7: Connect to Each Container (Optional) 469 ============================================ 470 471 Use this information when you need to connect to any container in the Sawtooth 472 application development environment. For example, you can examine the log files 473 or check the status of Sawtooth components in any container. 474 475 #. Use the following ``docker`` command to list all running Docker containers 476 477 .. code-block:: console 478 479 user@host$ docker ps 480 481 The output should resemble the following example: 482 483 .. code-block:: console 484 485 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 486 76f6731c43a9 hyperledger/sawtooth-all:1.0 "bash -c 'sawtooth k" 7 minutes ago Up 7 minutes 4004/tcp, 8008/tcp sawtooth-shell-default 487 9844faed9e9d hyperledger/sawtooth-intkey-tp-python:1.0 "intkey-tp-python -v" 7 minutes ago Up 7 minutes 4004/tcp sawtooth-intkey-tp-python-default 488 44db125c2dca hyperledger/sawtooth-settings-tp:1.0 "settings-tp -vv -C " 7 minutes ago Up 7 minutes 4004/tcp sawtooth-settings-tp-default 489 875df9d022d6 hyperledger/sawtooth-xo-tp-python:1.0 "xo-tp-python -vv -C" 7 minutes ago Up 7 minutes 4004/tcp sawtooth-xo-tp-python-default 490 93d048c01d30 hyperledger/sawtooth-rest-api:1.0 "sawtooth-rest-api -" 7 minutes ago Up 7 minutes 4004/tcp, 0.0.0.0:8008->8008/tcp sawtooth-rest-api-default 491 6bbcda66a5aa hyperledger/sawtooth-validator:1.0 "bash -c 'sawadm key" 7 minutes ago Up 7 minutes 0.0.0.0:4004->4004/tcp sawtooth-validator-default 492 493 The Docker Compose file defines the name of each container. It also 494 specifies the TCP port and host name, if applicable. The following table 495 shows the values in the example Compose file, ``sawtooth-default.yaml``. 496 497 +---------------+---------------------------------------+----------+----------------------+ 498 | **Component** | **Container Name** | **Port** | **Host Name** | 499 +===============+=======================================+==========+======================+ 500 | Validator | ``sawtooth-validator-default`` | 4004 | ``validator`` | 501 +---------------+---------------------------------------+----------+----------------------+ 502 | REST API | ``sawtooth-rest-api-default`` | 8008 | ``rest-api`` | 503 +---------------+---------------------------------------+----------+----------------------+ 504 | Settings TP | ``sawtooth-settings-tp-default`` | | ``settings-tp`` | 505 +---------------+---------------------------------------+----------+----------------------+ 506 | IntegerKey TP | ``sawtooth-intkey-tp-python-default`` | | ``intkey-tp-python`` | 507 +---------------+---------------------------------------+----------+----------------------+ 508 | XO TP | ``sawtooth-xo-tp-python-default`` | | ``xo-tp-python`` | 509 +---------------+---------------------------------------+----------+----------------------+ 510 | Shell | ``sawtooth-shell-default`` | | | 511 +---------------+---------------------------------------+----------+----------------------+ 512 513 Note that the validator and REST API ports are exposed to other containers 514 and forwarded (published) for external connections, such as from your host 515 system. 516 517 #. Use the following ``docker exec`` command from your host system to connect 518 to a Sawtooth Docker container. 519 520 .. code-block:: console 521 522 user@host$ docker exec -it {ContainerName} bash 523 524 For example, you can use the following command from your host system to 525 connect to the validator container: 526 527 .. code-block:: console 528 529 user@host$ docker exec -it sawtooth-validator-default bash 530 531 #. After connecting to the container, you can use ``ps`` to verify that the 532 Sawtooth component is running. 533 534 .. code-block:: console 535 536 # ps --pid 1 fw 537 538 In the validator container, the output resembles the following example: 539 540 .. code-block:: console 541 542 PID TTY STAT TIME COMMAND 543 1 ? Ss 0:00 bash -c sawadm keygen && sawtooth keygen my_key 544 && sawset genesis -k /root/.sawtooth/keys/my_key.priv && sawadm genesis 545 config-genesis.batch && sawtooth-validator -vv --endpoint 546 547 548 .. _examine-logs-docker-label: 549 550 Step 8: Examine Sawtooth Logs 551 ============================= 552 553 As described above, you can display Sawtooth log messages by using the 554 ``docker logs`` command from your host system: 555 556 .. code-block:: console 557 558 user@host$ docker logs {OPTIONS} {ContainerName} 559 560 In each container, the Sawtooth log files for that component are stored in the 561 directory ``/var/log/sawtooth``. Each component (validator, REST API, and 562 transaction processors) has both a debug log and an error log. 563 564 For example, the validator container has these log files: 565 566 .. code-block:: console 567 568 root@validator# ls -1 /var/log/sawtooth 569 validator-debug.log 570 validator-error.log 571 572 The IntegerKey container has these log files: 573 574 .. code-block:: console 575 576 root@intkey-tp# ls -1 /var/log/sawtooth 577 intkey-ae98c3726f9743c4-debug.log 578 intkey-ae98c3726f9743c4-error.log 579 580 .. note:: 581 582 By convention, the transaction processors use a random string to make the log 583 file names unique. The names on your system may be different than these 584 examples. 585 586 For more information on log files, see 587 :doc:`../sysadmin_guide/log_configuration`. 588 589 590 .. _stop-sawtooth-docker-label: 591 592 Step 9: Stop the Sawtooth Environment 593 ===================================== 594 595 Use this procedure if you need to stop or reset the Sawtooth environment for any 596 reason. 597 598 .. important:: 599 600 Any work done in this environment will be lost once the container exits. 601 To keep your work, you would need to take additional steps, such as 602 mounting a host directory into the container. See the `Docker documentation 603 <https://docs.docker.com/>`_ for more information. 604 605 #. Log out of the client container. 606 607 #. Enter CTRL-c from the window where you originally ran ``docker-compose``. The 608 output will resemble this example: 609 610 .. code-block:: console 611 612 ^CGracefully stopping... (press Ctrl+C again to force) 613 Stopping sawtooth-shell-default ... done 614 Stopping sawtooth-rest-api-default ... done 615 Stopping sawtooth-intkey-tp-python-default ... done 616 Stopping sawtooth-xo-tp-python-default ... done 617 Stopping sawtooth-settings-tp-default ... done 618 Stopping sawtooth-validator-default ... done 619 620 #. After all containers have shut down, run this ``docker-compose`` command: 621 622 .. code-block:: console 623 624 user@host$ docker-compose -f sawtooth-default.yaml down 625 Removing sawtooth-shell-default ... done 626 Removing sawtooth-intkey-tp-python-default ... done 627 Removing sawtooth-xo-tp-python-default ... done 628 Removing sawtooth-settings-tp-default ... done 629 Removing sawtooth-rest-api-default ... done 630 Removing sawtooth-validator-default ... done 631 Removing network testsawtooth_default 632 633 634 .. Licensed under Creative Commons Attribution 4.0 International License 635 .. https://creativecommons.org/licenses/by/4.0/