Lesson 2. Deploying a Hyperledger Sawtooth Network on the Docker environment

Tram Ho

In a Sawtooth Network, each host system (be it physical computer, virtual machine, Docker Containers, or a Kubernetes Pod) is a Sawtooth node on which it runs a validator , a REST API option, a consensus. engine , a set of transaction processors .

There will be a node that will first create the genesis block, which will determine the initial on-chain settings for the network.

A Sawtooth Network has the following requirements:

  • Each node must run the same consensus engine . The steps in this article will show you how to configure PBFT and PoET consensus .
  • Each node must run the same set of transaction processors with all the other nodes in the network.
  • Each node must have an address. This is provided by Docker and Kubernetes providing preconfigured settings. As for the ubuntu environment, you must configure the network settings before starting validator .
  • The type of authorization must be the same for all nodes: either trust or challenge .
  • The first node on the network must create the genensis block, the genesis block will contain the on-chain installation configuration, the nodes that later join the network will use this available configuration.

Use Docker for Sawtooth Network

This procedure describes using Docker to create a network of 5 nodes running an application development environment. Each node is a set of Docker Containers running a validator and other related components.

  • Download Sawtooth Docker Compose file.
  • Starting Sawtooth Network with docker-compose .
  • Check process status.
  • Configure the types of transactions allowed.
  • Connect to Sawtoot Shell Container and confirm network functionality .
  • Stopping Sawtooth and Reset docker environment.

1. About the Docker Sawtooth Network environment.

A test environment consisting of 5 Sawtooth nodes.

For each node as follows:

Each node in this Sawtooth network runs a validator , a REST API , a consensus engine , and the following transaction processors :

  • Settings ( settings-tp ): Handle Sawtooth’s on-chain configuration settings. Settings transactions processor is required on all Sawtooth Network.
  • IntegerKey ( intkey-tp-python ): intkey-tp-python basic functions of Sawtooth. intkey client consists of shell commands to perform integer-based transactions.
  • XO ( sawtooth-xo-tp-python ): Simple tic-tac-toe play application on the blockchain. xo client provides shell commands to define the player and how to play the game.
  • (PoET only) PoET Validator Registry ( poet-validator-rigistry ): Configure PoET consensus and handle a multi-node network.

NOTE: The nodes in Sawtooth Network must run in the same transaction processor.

The Dock Sawtooth Network environment uses transaction processing in parallel and you can choose one of the following two consensus:

  • PBFT consensus : provides a votting-based consensus algorithm that is tolerant to Byzantine errors.
  • PoET consensus : provides leader-election consensus algorithm, also known as PoET CFT.

2. Required before practice

This application development environment requires Docker Engine and Docker Compose.

3. Practice

Step 1. Download Docker Compose File

Download Docker Compse file for multiple-node network:

Step 2. Start Network

NOTE: The Docker Compose File allows Sawtooth to handle environment settings such as generating keys and creating genesis blocks.

  1. Open a terminal window.
  2. Navigate to the directory where you have just downloaded the docker compose file.
  3. Start network:
    • For PBFT:

    • For PoET:

  4. The above Compose files will create 5 nodes named validator-0 , validator-1 , validator-2 , validator-3 , validator-4 . Note that each node validator will have the following components, for example:
    validator-0 will have:

    • sawtooth-validator-default-0
    • sawtooth-rest-api-default-0
    • sawtooth-pbft-engine-default-0 or sawtooth-poet-engine-0
    • sawtooth-settings-tp-default-0
    • sawtooth-intkey-tp-python-default-0
    • sawtooth-xo-tp-python-default-0
    • (PoET only) sawtooth-poet-validator-registry-tp-0
  5. Note that we only have one shell container for this Docker environment:
Step 3. Check the REST API process.
  1. Connect to the REST API container on a node, such as sawtooth-poet-sawtooht-rest-api-default-0 :
  2. Use the following command to make sure this component is running:
Step 4. Confirm the Network functions
  1. Connect to shell container
  2. To check whether peer-to-peer data exchange exists on the network, execute a query to the REST API on the first node. This command needs to specify the container API port and port name of the first node:

    If the result is 503 Error, then the nodes are not connected to the network yet. Repeat the query until the results return as follows:
  3. (Optional) You can run the following commands to view other nodes in the network.

    a. Run the sawtooth peer list to see peers of a specific node. For example, the following statement specifies the REST API on the first node, which returns the peers of the first node.

    b. Run the sawnet peer list command to display all peers of the network.

  4. Submit a transaction to the REST API of the first node. The following example sets a key named myKey equal to 999:

    The output of the transaction must look like the following:

  5. Review myKey value on another node. The following command retrieves myKey values ​​on the second node:
    You can always run this command on the shell container of the first node, but change --url the URL of the second node:

    The result returns the name of the key and its current value:

Step 5. Configure allowed transactions

By default, a validator accepts all transactions from any transaction processor . However, Sawtooth allows you to limit the type of transactions that are allowed to be submitted.

In this step, you will configure the Sawtooth network to accept transactions only from transactions processors running in the docker environment we are running. The configuration to restrict transaction type is an on-chain setting, so we only need to configure it on one node, it will be applied to all the other nodes.

You will use the saw set command to create and submit a batch of transactions that contain configuration changes.

NOTE: This must be done on the first validator container, because according to the Docker compose file, the key of the first validator is used to create and sign the genesis block, meaning that only the key will be used to create the new genesis block. Can change the on-chain changes.

  1. Connect to the first validator container ( sawtooth-validator-default-0 ).
  2. Run the following command in the first validator container to specify which transactions families are allowed to submit:
    • For PBFT:
    • For PoET:

      The above statement sets a sawtooth.validator.transaction_families variable that is an array of JSON that assigns family name and version for each transaction processor.
  3. After running the above command, a message TP_PROCESS_REQUEST is returned:
  4. Run the following command to check the shell container for any validator container settings changes. You can specify any REST API available on the network.

    The result is similar to the following:
Step 6. Stop network.

Use this step to stop or reset the environment.

  1. Exit all containers.
  2. Ctrl C at the window where you run the docker-compose up command.
  3. Delete all containers and data:
    • For PBFT:
    • For PoET:

Reference links


Share the news now

Source : Viblo