Skip to content

Develop

Arthur Greef edited this page Feb 4, 2018 · 16 revisions

Prerequisites

We use docker images for development so the definitions below assume Docker and Docker Compose have been installed.

Clone the sawtooth-core repo and clone this repo to the following folders.

repos/sawtooth-core
repos/sawtooth-eventchain

Build the sawtooth-core python components.

cd ~/sawtooth-core
bin/build_all -l python

Docker for Windows (D4W) and Windows Subsystem for Linux (WSL)

WSL and D4w do not agree on the path structure. WSL ads /mnt to a folder path (e.g. /mnt/c) and D4W only understand folders that start with / e.g. /c. Add the following to your ~/.bashrc file to fix this problem. You do need to provide your password.

export DOCKER_HOST='tcp://0.0.0.0:2375'
export PATH=$PATH:~/bin

# mount /mnt/c to /c if not already done
if [ ! -d "/c" ] || [ ! "$(ls -A /c)" ]; then
  echo "Requiring root password to $(tput setaf 6)mount --bind /mnt/c /c$(tput sgr 0)"
  sudo mkdir -p /c
  sudo mount --bind /mnt/c /c
fi

# Change from /mnt/c/... to /c/...
if [ "$(pwd | cut -c -7)" == "/mnt/c/" ]; then
  cd "$(pwd | cut -c 5-)"
fi

# Provide docker for bash and docker-compose
docker() {
  docker.exe "$@"
}

Build

Run the following build command from the root folder. This will build the sawtooth-dev-python image and the sawtooth-units-tp image. The build will also create a container from the sawtooth-dev-python image and run build_python in the container to generate python protobuf files.

bin/build_all

You many need to clean your docker containers and images to build all. Add the following to your ~/.bash_aliases file and then run the dcclean and the diclean commands aliases.

alias diclean='docker images -a | grep '\'' [months|days|weeks]* ago'\'' | awk  '\''{print $3}'\'' | xargs docker rmi -f'
alias dclean='docker ps -a | grep -v '\''CONTAINER\|_config\|_data\|_run'\'' | cut -c-12 | xargs docker rm'

Composing and running a sawtooth validator and units transaction processor network

The following uses the docker-dev-units.yaml to compose a network of services for units transaction family development. The units-tp image mounts the source code on the host machine and includes the pudb debugger. This allows code inspection and problem solving with any changes to the source are save to the host machine.

;
; To initiate the setup of the units-tp image and bring up the network
;

cd ~/sawtooth-eventchain
docker-compose -f docker/compose/sawtooth-dev-units.yaml up

Subsequent executions will not take as long to initialize unless you change the sawtooth-uom docker configuration.

Any of the running components can be shelled into from additional bash shell windows:

; Shell into the running units transaction processor container and open
; to /project/sawtooth-eventchain

docker exec -it uom-processor bash
root@2fd6faa664fc:/project/sawtooth-eventchain#

; In another bash shell for the uom-shell image, open
; to /project/sawtooth-units

docker exec -it uom-shell bash
root@0be7c748eae3:/devprj/sawtooth-uom#

To stop the processing, exit out of any shelled images, return to the composition window and type Ctrl+C in the shell you started it from. When the shutdown completes clean up the docker-compose artifacts

; To stop the processing type Ctrl+C in the shell you started it from. 
; When the shutdown completes clean up the docker-compose artifacts

docker-compose -f ./docker-dev-compose.yaml down

sawtooth-core repository

The core repo is the source for compiling the SDK. It would seem this step may be optional as the sdk pacages are available from Python package repositories.

  1. Clone the latest sawtooth-core repository
  2. Go to the root directory of the repo cd ~\sawtooth-core
  3. At a minimum do bin\build_all -l python