github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/docs/source/app_developers_guide/ubuntu.rst (about) 1 ********************************************* 2 Using Ubuntu for Your Development Environment 3 ********************************************* 4 5 This procedure explains how to set up Hyperledger Sawtooth for application 6 development on Ubuntu 16.04. It shows you how to install Sawtooth on Ubuntu, 7 then walks you through the following tasks: 8 9 * Generating a user key 10 * Creating the genesis block 11 * Generating a root key 12 * Starting the components: validator, REST API, and 13 transaction processors 14 * Checking the status of the REST API 15 * Using Sawtooth commands to submit transactions, display block data, and view 16 global state 17 * Examining Sawtooth logs 18 * Stopping Sawtooth and resetting the development environment 19 20 After completing this procedure, you will have the application development 21 environment that is required for the other tutorials in this guide. The next 22 tutorial introduces the XO transaction family by using the ``xo`` client 23 commands to play a game of tic-tac-toe. The final set of tutorials describe how 24 to use an SDK to create a transaction family that implements your application's 25 business logic. 26 27 28 About the Application Development Environment 29 ============================================= 30 31 The Ubuntu application development environment is a single validator node that 32 is running a validator, a REST API, and three transaction processors. This 33 environment uses Developer mode (dev mode) consensus and serial transaction 34 processing. 35 36 .. figure:: ../images/appdev-environment-one-node-3TPs.* 37 :width: 100% 38 :align: center 39 :alt: Ubuntu application development environment for Ubuntu 40 41 This environment introduces basic Sawtooth functionality with the 42 `IntegerKey <../transaction_family_specifications/integerkey_transaction_family>`_ 43 and 44 `Settings <../transaction_family_specifications/settings_transaction_family>`_ 45 transaction processors for the business logic and Sawtooth commands as a client. 46 It also includes the 47 `XO <../transaction_family_specifications/xo_transaction_family>`_ 48 transaction processor, which is used in later tutorials. 49 50 The IntegerKey and XO families are simple examples of a transaction family, but 51 Settings is a reference implementation. In a production environment, you should 52 always run a transaction processor that supports the Settings transaction 53 family. 54 55 In this procedure, you will open six terminal windows on your host system: one 56 for each Sawtooth component and one to use for client commands. 57 58 .. note:: 59 60 This procedure starts the validator first, then the REST API, followed by 61 the transaction processors. However, the start-up order is flexible. For 62 example, you can start the transaction processors before starting the 63 validator. 64 65 66 Prerequisites 67 ============= 68 69 This Sawtooth development environment requires Ubuntu 16.04. 70 71 72 Step 1: Install Sawtooth 73 ======================== 74 75 The Sawtooth package repositories provide two types of Ubuntu packages: 76 stable or nightly. We recommend using the stable repository. 77 78 79 #. Open a terminal window on your host system. 80 From this point on, this procedure refers to this window as the "validator 81 terminal window". 82 In the following examples, the prompt ``user@validator$`` 83 shows the commands that must run in this window. 84 85 #. Choose either the stable repository or the nightly repository. 86 87 * To add the stable repository, run these commands: 88 89 .. code-block:: console 90 91 user@validator$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD 92 user@validator$ sudo add-apt-repository 'deb [arch=amd64] http://repo.sawtooth.me/ubuntu/1.0/stable xenial universe' 93 user@validator$ sudo apt-get update 94 95 * To use the nightly repository, run the following commands: 96 97 .. Caution:: 98 99 Nightly builds have not gone through long-running network testing and 100 could be out of sync with the documentation. We really do recommend the 101 stable repository. 102 103 .. code-block:: console 104 105 user@validator$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA 106 user@validator$ sudo apt-add-repository "deb http://repo.sawtooth.me/ubuntu/nightly xenial universe" 107 user@validator$ sudo apt-get update 108 109 #. Install the Sawtooth packages. Sawtooth consists of several Ubuntu packages 110 that can be installed together using the ``sawtooth`` meta-package. Run the 111 following command: 112 113 .. code-block:: console 114 115 user@validator$ sudo apt-get install -y sawtooth 116 117 #. Any time after installation, you can view the installed Sawtooth packages 118 with the following command: 119 120 .. code-block:: console 121 122 user@validator$ dpkg -l '*sawtooth*' 123 124 125 .. _generate-user-key-ubuntu: 126 127 Step 2: Generate a User Key 128 =========================== 129 130 Generate your user key for Sawtooth, using the same terminal window as the 131 previous step. 132 133 .. code-block:: console 134 135 user@validator$ sawtooth keygen 136 writing file: /home/yourname/.sawtooth/keys/yourname.priv 137 writing file: /home/yourname/.sawtooth/keys/yourname.pub 138 139 140 .. _create-genesis-block-ubuntu-label: 141 142 Step 3: Create the Genesis Block 143 ================================ 144 145 Because this is a new network, you must create a genesis block (the first block 146 on the distributed ledger). This step is done only for the first validator node 147 on the network. Validator nodes that join an existing network do not create 148 a genesis block. 149 150 The genesis block contains initial values that are necessary when a Sawtooth 151 distributed ledger is created and used for the first time, including the keys 152 for users who are authorized to set and change configuration settings. 153 154 Use the same terminal window as the previous step. 155 156 #. Create a settings proposal (as a batch of transactions) that authorizes you 157 to set and change configuration settings. By default (if no options are 158 specified), the ``sawset genesis`` command uses the key of the current user 159 (you). 160 161 .. code-block:: console 162 163 user@validator$ sawset genesis 164 Generated config-genesis.batch 165 166 This settings proposal will change authorized keys in the setting 167 ``sawtooth.settings.vote.authorized_keys``. The change will take effect 168 after the validator and Settings transaction processor have started. 169 170 #. Run the following command: 171 172 .. code-block:: console 173 174 user@validator$ sudo -u sawtooth sawadm genesis config-genesis.batch 175 Processing config-genesis.batch... 176 Generating /var/lib/sawtooth/genesis.batch 177 178 .. note:: 179 180 The ``-u sawtooth`` option refers to the sawtooth user, 181 not the sawtooth command. 182 183 184 .. _generate-root-key-ubuntu: 185 186 Step 4: Generate the Root Key for the Validator 187 =============================================== 188 189 Generate the key for the validator, which runs as root. Use the same terminal 190 window as the previous step. 191 192 .. code-block:: console 193 194 user@validator$ sudo sawadm keygen 195 writing file: /etc/sawtooth/keys/validator.priv 196 writing file: /etc/sawtooth/keys/validator.pub 197 198 199 .. _start-validator-ubuntu-label: 200 201 Step 5: Start the Validator 202 =========================== 203 204 Use the same terminal window as the previous step. 205 206 #. Start a validator that listens locally on the default ports. 207 208 .. code-block:: console 209 210 user@validator$ sudo -u sawtooth sawtooth-validator -vv 211 212 .. note:: 213 214 See :doc:`../cli/sawtooth-validator` in the CLI Command Reference for 215 information on the ``sawtooth-validator`` options. 216 217 The validator terminal window displays verbose log messages. The output will 218 be similar to this truncated example: 219 220 .. code-block:: console 221 222 [2018-03-14 15:53:34.909 INFO cli] sawtooth-validator (Hyperledger Sawtooth) version 1.0.1 223 [2018-03-14 15:53:34.909 INFO path] Skipping path loading from non-existent config file: /etc/sawtooth/path.toml 224 [2018-03-14 15:53:34.910 INFO validator] Skipping validator config loading from non-existent config file: /etc/sawtooth/validator.toml 225 [2018-03-14 15:53:34.911 INFO keys] Loading signing key: /etc/sawtooth/keys/validator.priv 226 [2018-03-14 15:53:34.912 INFO cli] config [path]: config_dir = "/etc/sawtooth"; config [path]: key_dir = "/etc/sawtooth/keys"; config [path]: data_dir = "/var/lib/sawtooth"; config [path]: log_dir = "/var/log/sawtooth"; config [path]: policy_dir = "/etc/sawtooth/policy" 227 [2018-03-14 15:53:34.913 WARNING cli] Network key pair is not configured, Network communications between validators will not be authenticated or encrypted. 228 [2018-03-14 15:53:34.914 DEBUG core] global state database file is /var/lib/sawtooth/merkle-00.lmdb 229 ... 230 [2018-03-14 15:53:34.929 DEBUG genesis] genesis_batch_file: /var/lib/sawtooth/genesis.batch 231 [2018-03-14 15:53:34.930 DEBUG genesis] block_chain_id: not yet specified 232 [2018-03-14 15:53:34.931 INFO genesis] Producing genesis block from /var/lib/sawtooth/genesis.batch 233 [2018-03-14 15:53:34.932 DEBUG genesis] Adding 1 batches 234 [2018-03-14 15:53:34.934 DEBUG executor] no transaction processors registered for processor type sawtooth_settings: 1.0 235 [2018-03-14 15:53:34.936 INFO executor] Waiting for transaction processor (sawtooth_settings, 1.0) 236 237 Note that the validator is waiting for the Settings transaction processor 238 (``sawtooth_settings``) to start. 239 240 The validator terminal window will continue to display log messages as you 241 complete this procedure. 242 243 .. note:: 244 245 If you want to stop the validator, enter CTRL-c in the validator terminal 246 window. For more information, see :ref:`stop-sawtooth-ubuntu-label`. 247 248 249 .. _start-rest-api-label: 250 251 Step 6: Start the REST API 252 ========================== 253 254 The REST API allows you to configure a running validator, submit batches, and 255 query the state of the distributed ledger. 256 257 #. Open a new terminal window (the rest-api terminal window). In this procedure, 258 the prompt ``user@rest-api$`` shows the commands that should be run in this 259 window. 260 261 #. Run the following command to start the REST API and connect to the local 262 validator. 263 264 .. code-block:: console 265 266 user@rest-api$ sudo -u sawtooth sawtooth-rest-api -v 267 268 .. note:: 269 270 See :doc:`../cli/sawtooth-rest-api` in the CLI Command Reference for 271 information on the ``sawtooth-rest-api`` options. 272 273 The output is similar to this example: 274 275 .. code-block:: console 276 277 Connecting to tcp://localhost:4004 278 [2018-03-14 15:55:29.509 INFO rest_api] Creating handlers for validator at tcp://localhost:4004 279 [2018-03-14 15:55:29.511 INFO rest_api] Starting REST API on 127.0.0.1:8008 280 ======== Running on http://127.0.0.1:8008 ======== 281 (Press CTRL+C to quit) 282 283 The rest-api terminal window continues display log messages as you complete this 284 procedure. 285 286 287 .. _start-tps-label: 288 289 Step 7: Start the Transaction Processors 290 ======================================== 291 292 In this step, you will open a new terminal window for each transaction 293 processor. 294 295 1. Start the Settings transaction processor, ``settings-tp``. 296 297 a. Open a new terminal window (the settings terminal window). The prompt 298 ``user@settings-tp$`` shows the commands that should be run in this 299 window. 300 301 #. Run the following command: 302 303 .. code-block:: console 304 305 user@settings$ sudo -u sawtooth settings-tp -v 306 307 .. note:: 308 309 See :doc:`../cli/settings-tp` in the CLI Command Reference for 310 information on the ``settings-tp`` options. 311 312 #. Check the validator terminal window to confirm that the transaction 313 processor has registered with the validator, as shown in this example 314 log message: 315 316 .. code-block:: console 317 318 [2018-03-14 16:00:17.223 INFO processor_handlers] registered transaction processor: connection_id=eca3a9ad0ff1cdbc29e449cc61af4936bfcaf0e064952dd56615bc00bb9df64c4b01209d39ae062c555d3ddc5e3a9903f1a9e2d0fd2cdd47a9559ae3a78936ed, family=sawtooth_settings, version=1.0, namespaces=['000000'] 319 320 #. Open a new terminal window (the client terminal window). In this 321 procedure, the prompt ``user@client$`` shows the commands that should be 322 run in this window. 323 324 #. At this point, you can see the authorized keys setting that was proposed 325 in :ref:`create-genesis-block-ubuntu-label`. 326 Run the following command in the client terminal window: 327 328 .. code-block:: console 329 330 user@client$ sawtooth settings list 331 sawtooth.settings.vote.authorized_keys: 0276023d4f7323103db8d8683a4b7bc1eae1f66fbbf79c20a51185f589e2d304ce 332 333 The ``settings-tp`` transaction processor continues to run and to display log 334 messages in its terminal window. 335 336 #. Start the IntegerKey transaction processor, ``intkey-tp-python``. 337 338 a. Open a new terminal window (the intkey terminal window). The prompt 339 ``user@intkey$`` shows the commands that should be run in this window. 340 341 #. Run the following command: 342 343 .. code-block:: console 344 345 user@intkey$ sudo -u sawtooth intkey-tp-python -v 346 [23:07:57 INFO core] register attempt: OK 347 348 .. note:: 349 350 For information on the ``intkey-tp-python`` options, run the command 351 ``intkey-tp-python --help``. 352 353 #. Check the validator terminal window to confirm that the transaction 354 processor has registered with the validator. A successful registration 355 event produces the following output: 356 357 .. code-block:: console 358 359 [2018-03-14 15:56:35.255 INFO processor_handlers] registered transaction processor: connection_id=94d1aedfc2ba0575a0e4b4f06be7ff7875703f18817027b463b3772ce2b963adb9902f7ed0bafa50201e6845015f65bac814302bdafbcda6e6698fe1733b9411, family=intkey, version=1.0, namespaces=['1cf126'] 360 361 The ``intkey-tp-python`` transaction processor continues to run and to 362 display log messages in its terminal window. 363 364 #. (Optional) Start the XO transaction processor, ``xo-tp-python``. This 365 transaction processor will be used in a later tutorial. 366 367 a. Open a new terminal window (the xo terminal window). The prompt 368 ``user@xo$`` shows the commands that should be run in this window. 369 370 #. Run the following command: 371 372 .. code-block:: console 373 374 user@xo$ sudo -u sawtooth xo-tp-python -v 375 376 .. note:: 377 378 For information on the ``xo-tp-python`` options, run the command 379 ``xo-tp-python --help``. 380 381 #. Check the validator terminal window to confirm that the transaction 382 processor has registered with the validator. 383 384 .. code-block:: console 385 386 [2018-03-14 16:04:18.706 INFO processor_handlers] registered transaction processor: connection_id=c885e99a11724e04e7da4ee426ee00d4af2cb54b67bf2fbd2f57e862bf28fa2c759a0d0978573782369659124797cc6f38d41bfde2469fe69e7e48dc1fadf5a9, family=xo, version=1.0, namespaces=['5b7349'] 387 388 The ``xo-tp-python`` transaction processor continues to run and to display 389 log messages in its terminal window. 390 391 392 .. _confirm-rest-api-ubuntu-label: 393 394 Step 8: Confirm Connectivity to the REST API 395 ============================================ 396 397 #. Run the following command in the client terminal window: 398 399 .. code-block:: console 400 401 user@client$ ps aux | grep [s]awtooth-rest-api 402 sawtooth 2829 0.0 0.3 55756 3980 pts/0 S+ 19:36 0:00 sudo -u sawtooth sawtooth-rest-api -v 403 sawtooth 2830 0.0 3.6 221164 37520 pts/0 Sl+ 19:36 0:00 /usr/bin/python3 /usr/bin/sawtooth-rest-api -v 404 405 #. If necessary, restart the REST API (see :ref:`start-rest-api-label`). 406 407 408 Step 9: Use Sawtooth Commands as a Client 409 ========================================= 410 411 Sawtooth includes commands that act as a client application. This step describes 412 how to use the ``intkey`` and ``sawtooth`` commands to create and submit 413 transactions, display blockchain and block data, and examine global state data. 414 415 .. note:: 416 417 Use the ``--help`` option with any Sawtooth command to display the available 418 options and subcommands. 419 420 Continue to use the client terminal window to run the commands in this step. 421 422 Creating and Submitting Transactions with intkey 423 ------------------------------------------------ 424 425 The ``intkey`` command creates sample IntegerKey transactions for testing 426 purposes. 427 428 #. Use ``intkey create_batch`` to prepare batches of transactions that set 429 a few keys to random values, then randomly increment and decrement those 430 values. These batches are saved locally in the file ``batches.intkey``. 431 432 .. code-block:: console 433 434 user@client$ intkey create_batch --count 10 --key-count 5 435 Writing to batches.intkey... 436 437 #. Use ``intkey load`` to submit the batches to the validator. 438 439 .. code-block:: console 440 441 user@client$ intkey load -f batches.intkey 442 batches: 11 batch/sec: 141.7800162868952 443 444 #. The validator terminal window displays many log messages showing that the 445 validator is handling the submitted transactions and processing blocks, as in 446 this truncated example: 447 448 .. code-block:: console 449 450 ... 451 78c295614594319ece3fac71145c05ca36fadc3bd6e65 (block_num:13, state:addbd88bc80ecb05793750b7c80b91588043a1287cd8d4b6e0b1e6a68a0e4017, previous_block_id:f4323dfc238938db834aa5d40b4e6c2825bf7eae5cdaf73a9da28cb308a765707e85ac06e72b01e3d7d529132329b55b18d0cc71ab026506edd63bc6b718e80a)^[[0m 452 [2018-03-14 16:24:49.621 INFO chain] Starting block validation of : 60c0c348a00cde622a3664d6d4fb949736b78f8bcb6b77bd0300cdc7675ca9d4116ee23ec18c7cfee5978c295614594319ece3fac71145c05ca36fadc3bd6e65 (block_num:13, state:addbd88bc80ecb05793750b7c80b91588043a1287cd8d4b6e0b1e6a68a0e4017, previous_block_id:f4323dfc238938db834aa5d40b4e6c2825bf7eae5cdaf73a9da28cb308a765707e85ac06e72b01e3d7d529132329b55b18d0cc71ab026506edd63bc6b718e80a) 453 [2018-03-14 16:24:49.646 INFO chain] Comparing current chain head 'f4323dfc238938db834aa5d40b4e6c2825bf7eae5cdaf73a9da28cb308a765707e85ac06e72b01e3d7d529132329b55b18d0cc71ab026506edd63bc6b718e80a (block_num:12, state:c30ed78dde19d9ff58587a8bdd4aa435e09212cd1fee3e95d88faafe44f207cc, previous_block_id:dc98ce9029e6e3527bca18060cbb1325b545054b1589f2df7bf200fb0a09d0572491a3837dea1baf2981f5a960bd108f198806c974efcb3b69d2712809cc6065)' against new block '60c0c348a00cde622a3664d6d4fb949736b78f8bcb6b77bd0300cdc7675ca9d4116ee23ec18c7cfee5978c295614594319ece3fac71145c05ca36fadc3bd6e65 (block_num:13, state:addbd88bc80ecb05793750b7c80b91588043a1287cd8d4b6e0b1e6a68a0e4017, previous_block_id:f4323dfc238938db834aa5d40b4e6c2825bf7eae5cdaf73a9da28cb308a765707e85ac06e72b01e3d7d529132329b55b18d0cc71ab026506edd63bc6b718e80a)' 454 [2018-03-14 16:24:49.647 INFO chain] Fork comparison at height 13 is between - and 60c0c348 455 [2018-03-14 16:24:49.647 INFO chain] Chain head updated to: 60c0c348a00cde622a3664d6d4fb949736b78f8bcb6b77bd0300cdc7675ca9d4116ee23ec18c7cfee5978c295614594319ece3fac71145c05ca36fadc3bd6e65 (block_num:13, state:addbd88bc80ecb05793750b7c80b91588043a1287cd8d4b6e0b1e6a68a0e4017, previous_block_id:f4323dfc238938db834aa5d40b4e6c2825bf7eae5cdaf73a9da28cb308a765707e85ac06e72b01e3d7d529132329b55b18d0cc71ab026506edd63bc6b718e80a) 456 [2018-03-14 16:24:49.648 INFO publisher] Now building on top of block: 60c0c348a00cde622a3664d6d4fb949736b78f8bcb6b77bd0300cdc7675ca9d4116ee23ec18c7cfee5978c295614594319ece3fac71145c05ca36fadc3bd6e65 (block_num:13, state:addbd88bc80ecb05793750b7c80b91588043a1287cd8d4b6e0b1e6a68a0e4017, previous_block_id:f4323dfc238938db834aa5d40b4e6c2825bf7eae5cdaf73a9da28cb308a765707e85ac06e72b01e3d7d529132329b55b18d0cc71ab026506edd63bc6b718e80a) 457 [2018-03-14 16:24:49.649 DEBUG chain] Verify descendant blocks: 60c0c348a00cde622a3664d6d4fb949736b78f8bcb6b77bd0300cdc7675ca9d4116ee23ec18c7cfee5978c295614594319ece3fac71145c05ca36fadc3bd6e65 (block_num:13, state:addbd88bc80ecb05793750b7c80b91588043a1287cd8d4b6e0b1e6a68a0e4017, previous_block_id:f4323dfc238938db834aa5d40b4e6c2825bf7eae5cdaf73a9da28cb308a765707e85ac06e72b01e3d7d529132329b55b18d0cc71ab026506edd63bc6b718e80a) ([]) 458 [2018-03-14 16:24:49.651 INFO chain] Finished block validation of: 60c0c348a00cde622a3664d6d4fb949736b78f8bcb6b77bd0300cdc7675ca9d4116ee23ec18c7cfee5978c295614594319ece3fac71145c05ca36fadc3bd6e65 (block_num:13, state:addbd88bc80ecb05793750b7c80b91588043a1287cd8d4b6e0b1e6a68a0e4017, previous_block_id:f4323dfc238938db834aa5d40b4e6c2825bf7eae5cdaf73a9da28cb308a765707e85ac06e72b01e3d7d529132329b55b18d0cc71ab026506edd63bc6b718e80a) 459 460 #. The rest-api terminal window displays a log message as it communicates with 461 the intkey transaction processor. 462 463 .. code-block:: console 464 465 [2018-03-14 16:24:49.587 INFO helpers] POST /batches HTTP/1.1: 202 status, 1639 size, in 0.030922 s 466 467 #. You can also look at the Sawtooth log files to see what happened. Use the 468 following command to display the last 10 entries in the intkey log file, 469 which show that values have been changed. 470 471 .. code-block:: console 472 473 user@client$ sudo bash -c "tail -10 /var/log/sawtooth/intkey-*-debug.log" 474 [2018-03-14 16:24:49.587 [MainThread] core DEBUG] received message of type: TP_PROCESS_REQUEST 475 [2018-03-14 16:24:49.588 [MainThread] handler DEBUG] incrementing "MvRznE" by 1 476 [2018-03-14 16:24:49.624 [MainThread] core DEBUG] received message of type: TP_PROCESS_REQUEST 477 [2018-03-14 16:24:49.625 [MainThread] handler DEBUG] incrementing "iJWCRq" by 5 478 [2018-03-14 16:24:49.629 [MainThread] core DEBUG] received message of type: TP_PROCESS_REQUEST 479 [2018-03-14 16:24:49.630 [MainThread] handler DEBUG] incrementing "vJJL1N" by 8 480 [2018-03-14 16:24:49.634 [MainThread] core DEBUG] received message of type: TP_PROCESS_REQUEST 481 [2018-03-14 16:24:49.636 [MainThread] handler DEBUG] incrementing "vsTbBo" by 4 482 [2018-03-14 16:24:49.639 [MainThread] core DEBUG] received message of type: TP_PROCESS_REQUEST 483 [2018-03-14 16:24:49.641 [MainThread] handler DEBUG] incrementing "MvRznE" by 1 484 485 .. note:: 486 487 The log file names for the transaction processors contain a random 488 string that is unique for each instance of the transaction processor. 489 For more information, see :ref:`examine-logs-ubuntu-label`. 490 491 Submitting Transactions with sawtooth batch submit 492 -------------------------------------------------- 493 494 In the example above, the ``intkey create_batch`` command created the file 495 ``batches.intkey``. Rather than using ``intkey load`` to submit these 496 transactions, you could use ``sawtooth batch submit`` to submit them. 497 498 #. As before, create a batch of transactions. 499 500 .. code-block:: console 501 502 user@client$ intkey create_batch --count 10 --key-count 5 503 Writing to batches.intkey... 504 505 #. Submit the batch file with the following command: 506 507 .. code-block:: console 508 509 user@client$ sawtooth batch submit -f batches.intkey 510 batches: 11, batch/sec: 216.80369536716367 511 512 Viewing Blockchain and Block Data with sawtooth block 513 ----------------------------------------------------- 514 515 The ``sawtooth block`` command displays information about the blocks stored on 516 the blockchain. 517 518 #. Use ``sawtooth block list`` to display the list of blocks stored in state. 519 520 .. code-block:: console 521 522 user@client$ sawtooth block list 523 524 The output includes the block ID, as in this example: 525 526 .. code-block:: console 527 528 NUM BLOCK_ID BATS TXNS SIGNER 529 61 9566426220751691b7463e3c1ec1d8c4f158c98e89722672721d457182cb3b3d48e734ddceabf706b41fc3e1f8d739451f7d70bd5a8708bc4085b6fb33b40bef 1 4 020d21... 530 60 309c0707b95609d4ebc2fad0afd590ec40db41680a3edbbeb0875720ed59f4d775e1160a2c6cbe2e9ccb34c4671f4cd7db1e5ed35a2ed9a0f2a2c99aa981f83c 1 5 020d21... 531 59 e0c6c29a9f3d1436e4837c96587ae3fa60274991efa9d0c9000d53694cd2a0841914b2f362aa05c2385126288f060f524bac3a05850edb1ac1c86f0c237afdba 1 3 020d21... 532 58 8c67a1ec68bfdd5b07bb02919019b917ed26dbc6ec0fc3de15d539538bd30f8a1aa58795578970d2e607cd63cf1f5ef921476cbc0564cbe37469e5e50b72ecf2 1 3 020d21... 533 57 879c6cb43e244fb7c1676cf5d9e51ace25ad8e670f37e81b81e5d9e133aebba80282913677821c14fe2ccb2aae631229bdd044222e6a8927f4f5dabb6d62c409 1 4 020d21... 534 ... 535 5 dce0921531472a8f9840e256c585917dfc22b78c5045a3416ed76faf57232b065b8be5a34023e8a8cdab74ab24cf029a5c1051f742b9b5280b8edab5a80d805d 2 4 020d21... 536 4 0007380e98fc6d63de1d47261b83186bce9722023f2e6ab6849916766e9be29f4903d76a642dfc27579b8a8bf9adba5f077c1f1457b2cad8f52a28d7079333a6 1 8 020d21... 537 3 515c827b9e84c22c24838130d4e0f6af07ab271c138a61c555a830c4118a75815f54340ef3f04de009c94c3531f3202690708cf16fcfee04303972cb91e3b87a 1 10 020d21... 538 2 9067bcb093bb095ca436d8868914ecf2630215d36bfd78b0b167554c544b9842193dd309f135e6959a664fe34b06b4f16a297528249550821cda9273291ebe70 1 5 020d21... 539 1 3ab950b2cd370f26e188d95ee97268965732768080ca1adb71759e3c1f22d1ea19945b48fc81f5f821387fde355349f87096da00a4e356408b630ab80576d3ae 1 5 020d21... 540 0 51a704e1a83086372a3c0823533881ffac9479995289902a311fd5d99ff6a32216cd1fb9883a421449c943cad8604ce1447b0f6080c8892e334b14dc082f91d3 1 1 020d21... 541 542 #. From the output generated by ``sawtooth block list``, copy the ID of a block 543 you want to view, then paste it in place of ``{BLOCK_ID}`` in the following 544 command: 545 546 .. code-block:: console 547 548 user@client$ sawtooth block show {BLOCK_ID} 549 550 The output of this command can be quite long, because it includes all data 551 stored under that block. This is a truncated example: 552 553 .. code-block:: console 554 555 batches: 556 - header: 557 signer_public_key: 0276023d4f7323103db8d8683a4b7bc1eae1f66fbbf79c20a51185f589e2d304ce 558 transaction_ids: 559 - 24b168aaf5ea4a76a6c316924a1c26df0878908682ea5740dd70814e7c400d56354dee788191be8e28393c70398906fb467fac8db6279e90e4e61619589d42bf 560 header_signature: a93731646a8fd2bce03b3a17bc2cb3192d8597da93ce735950dccbf0e3cf0b005468fadb94732e013be0bc2afb320be159b452cf835b35870db5fa953220fb35 561 transactions: 562 - header: 563 batcher_public_key: 0276023d4f7323103db8d8683a4b7bc1eae1f66fbbf79c20a51185f589e2d304ce 564 dependencies: [] 565 family_name: sawtooth_settings 566 family_version: '1.0' 567 ... 568 header: 569 batch_ids: 570 - a93731646a8fd2bce03b3a17bc2cb3192d8597da93ce735950dccbf0e3cf0b005468fadb94732e013be0bc2afb320be159b452cf835b35870db5fa953220fb35 571 block_num: 3 572 consensus: RGV2bW9kZQ== 573 previous_block_id: 042f08e1ff49bbf16914a53dc9056fb6e522ca0e2cff872547eac9555c1de2a6200e67fb9daae6dfb90f02bef6a9088e94e5bdece04f622bce67ccecd678d56e 574 signer_public_key: 033fbed13b51eafaca8d1a27abc0d4daf14aab8c0cbc1bb4735c01ff80d6581c52 575 state_root_hash: 5d5ea37cbbf8fe793b6ea4c1ba6738f5eee8fc4c73cdca797736f5afeb41fbef 576 header_signature: ff4f6705bf57e2a1498dc1b649cc9b6a4da2cc8367f1b70c02bc6e7f648a28b53b5f6ad7c2aa639673d873959f5d3fcc11129858ecfcb4d22c79b6845f96c5e3 577 578 Viewing State Data with sawtooth state 579 -------------------------------------- 580 581 The ``sawtooth state`` command lets you display state data. Sawtooth stores 582 state data in a :term:`Merkle-Radix tree`; for more information, see 583 :doc:`../architecture/global_state`. 584 585 #. Use ``sawtooth state list`` to list the nodes (addresses) in state. 586 587 .. code-block:: console 588 589 user@client$ sawtooth state list 590 591 The output will be similar to this truncated example: 592 593 .. code-block:: console 594 595 ADDRESS SIZE DATA 596 1cf126ddb507c936e4ee2ed07aa253c2f4e7487af3a0425f0dc7321f94be02950a081ab7058bf046c788dbaf0f10a980763e023cde0ee282585b9855e6e5f3715bf1fe 11 b'\xa1fcCTdcH\x... 597 1cf1260cd1c2492b6e700d5ef65f136051251502e5d4579827dc303f7ed76ddb7185a19be0c6443503594c3734141d2bdcf5748a2d8c75541a8e568bae063983ea27b9 11 b'\xa1frdLONu\x... 598 1cf126ed7d0ac4f755be5dd040e2dfcd71c616e697943f542682a2feb14d5f146538c643b19bcfc8c4554c9012e56209f94efe580b6a94fb326be9bf5bc9e177d6af52 11 b'\xa1fAUZZqk\x... 599 1cf126c46ff13fcd55713bcfcf7b66eba515a51965e9afa8b4ff3743dc6713f4c40b4254df1a2265d64d58afa14a0051d3e38999704f6e25c80bed29ef9b80aee15c65 11 b'\xa1fLvUYLk\x... 600 1cf126c4b1b09ebf28775b4923e5273c4c01ba89b961e6a9984632612ec9b5af82a0f7c8fc1a44b9ae33bb88f4ed39b590d4774dc43c04c9a9bd89654bbee68c8166f0 13 b'\xa1fXHonWY\x... 601 1cf126e924a506fb2c4bb8d167d20f07d653de2447df2754de9eb61826176c7896205a17e363e457c36ccd2b7c124516a9b573d9a6142f031499b18c127df47798131a 13 b'\xa1foWZXEz\x... 602 1cf126c295a476acf935cd65909ed5ead2ec0168f3ee761dc6f37ea9558fc4e32b71504bf0ad56342a6671db82cb8682d64689838731da34c157fa045c236c97f1dd80 13 b'\xa1fadKGve\x... 603 604 #. Use ``sawtooth state show`` to view state data at a specific address (a node 605 in the Merkle-Radix database). Copy the address from the output of 606 ``sawtooth state list``, then paste it in place of ``{STATE_ADDRESS}`` in 607 the following command: 608 609 .. code-block:: console 610 611 user@client$ sawtooth state show {STATE_ADDRESS} 612 613 The output shows the bytes stored at that address and the block ID of the 614 "chain head" that the current state is tied to, as in this example: 615 616 .. code-block:: console 617 618 DATA: "b'\xa1fcCTdcH\x192B'" 619 HEAD: "0c4364c6d5181282a1c7653038ec9515cb0530c6bfcb46f16e79b77cb524491676638339e8ff8e3cc57155c6d920e6a4d1f53947a31dc02908bcf68a91315ad5" 620 621 622 .. _examine-logs-ubuntu-label: 623 624 Step 10: Examine Sawtooth Logs 625 ============================== 626 627 By default, Sawtooth logs are stored in the directory ``/var/log/sawtooth``. 628 Each component (validator, REST API, and transaction processors) has both a 629 debug log and an error log. This example shows the log files for this 630 application development environment: 631 632 .. code-block:: console 633 634 user@client$ sudo ls -1 /var/log/sawtooth 635 identity-f5c42a08548c4ffa-debug.log 636 identity-f5c42a08548c4ffa-error.log 637 intkey-ae98c3726f9743c4-debug.log 638 intkey-ae98c3726f9743c4-error.log 639 rest_api-debug.log 640 rest_api-error.log 641 settings-6d591c44915b465c-debug.log 642 settings-6d591c44915b465c-error.log 643 validator-debug.log 644 validator-error.log 645 xo-9b8b55265ca0d546-error.log 646 xo-9b8b55265ca0d546-debug.log 647 648 .. note:: 649 650 For the transaction processors, the log file names contain a random string to 651 make the names unique. This string changes for each instance of a transaction 652 processor. The file names on your system will be different than these 653 examples. 654 655 For more information on log files, see 656 :doc:`../sysadmin_guide/log_configuration`. 657 658 659 .. _stop-sawtooth-ubuntu-label: 660 661 Step 11: Stop Sawtooth Components 662 ================================= 663 664 Use this procedure if you need to stop or reset the Sawtooth environment for any 665 reason. 666 667 .. note:: 668 669 This application development environment is used in later procedures in this 670 guide. Do not stop this environment if you intend to continue with these 671 procedures. 672 673 To stop the Sawtooth components: 674 675 #. Stop the validator by entering CTRL-c in the validator terminal window. 676 677 .. note:: 678 679 A single CTRL-c does a graceful shutdown. If you prefer not to wait, you 680 can enter multiple CTRL-c characters to force the shutdown. 681 682 #. Stop the REST API by entering a single CTRL-c in REST API terminal window. 683 684 #. Stop each transaction processor by entering a single CTRL-c in the 685 appropriate window. 686 687 You can restart the Sawtooth components at a later time and continue working 688 with your application development environment. 689 690 To completely reset the Sawtooth environment and start over from the beginning 691 of this procedure, add these steps: 692 693 * To delete the blockchain data, remove all files from ``/var/lib/sawtooth``. 694 695 * To delete the Sawtooth logs, remove all files from ``/var/log/sawtooth/``. 696 697 * To delete the Sawtooth keys, remove the key files 698 ``/etc/sawtooth/keys/validator.\*`` and 699 ``/home/``\ `yourname`\ ``/.sawtooth/keys/``\ `yourname`\ ``.\*``. 700 701 702 .. Licensed under Creative Commons Attribution 4.0 International License 703 .. https://creativecommons.org/licenses/by/4.0/