Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Add Dockerfile, environment, and PBFT client
Browse files Browse the repository at this point in the history
Signed-off-by: Bridger Herman <bridger@bitwise.io>
  • Loading branch information
Bridger Herman committed Jul 23, 2018
1 parent 078257f commit 7005eac
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

/target
**/*.rs.bk
*.swp
/src/protos
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ISOLATION_ID=latest
INSTALL_TYPE=local
SAWTOOTH_CORE=/Users/bridger/sawtooth/sawtooth-core
SAWTOOTH_PBFT=/Users/bridger/sawtooth/sawtooth-pbft
SAWTOOTH_RAFT=/Users/bridger/sawtooth/sawtooth-raft-1
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------

FROM ubuntu:xenial

RUN apt-get update \
&& apt-get install -y -q --allow-downgrades \
build-essential \
curl \
libssl-dev \
gcc \
git \
libzmq3-dev \
openssl \
pkg-config \
unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \
&& unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \
&& rm protoc-3.5.1-linux-x86_64.zip

RUN curl https://sh.rustup.rs -sSf > /usr/bin/rustup-init \
&& chmod +x /usr/bin/rustup-init \
&& rustup-init -y

ENV PATH=$PATH:/protoc3/bin:/project/sawtooth-core/bin:/root/.cargo/bin \
CARGO_INCREMENTAL=0

WORKDIR /project/sawtooth-pbft

CMD cargo build
4 changes: 1 addition & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ fn main() {
// Run protoc
protoc_rust::run(protoc_rust::Args {
out_dir: "src/protos",
input: &[
"protos/pbft_message.proto",
],
input: &["protos/pbft_message.proto"],
includes: &["protos"],
customize: Customize {
..Default::default()
Expand Down
15 changes: 7 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,19 @@ fn main() {
.get_matches();

let log_level = match matches.occurrences_of("verbose") {
0 => log::Level::Warn,
1 => log::Level::Info,
2 => log::Level::Debug,
3 | _ => log::Level::Trace,
0 => log::Level::Warn,
1 => log::Level::Info,
2 => log::Level::Debug,
3 | _ => log::Level::Trace,
};

let endpoint = String::from(
matches
.value_of("connect")
.unwrap_or("tcp://localhost:5050")
.value_of("connect")
.unwrap_or("tcp://localhost:5050"),
);

let id = value_t!(matches.value_of("ID"), u64)
.unwrap_or_else(|e| e.exit());
let id = value_t!(matches.value_of("ID"), u64).unwrap_or_else(|e| e.exit());

simple_logger::init_with_level(log_level).unwrap();

Expand Down
4 changes: 4 additions & 0 deletions tests/pbft.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

docker-compose -f tests/pbft_client.yaml up;
docker-compose -f tests/pbft_client.yaml down
291 changes: 291 additions & 0 deletions tests/pbft_client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
# Copyright 2018 Bitwise IO, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------

version: "2.1"

volumes:
keys:

services:
validator-0:
image: sawtooth-validator:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
- keys:/shared_keys
expose:
- 4004
- 8800
- 5005
working_dir: /root
command: "bash -c \"\
sawadm keygen validator-1 && \
sawadm keygen validator-2 && \
sawadm keygen validator-3 && \
sawadm keygen && \
sawset genesis \
-k /etc/sawtooth/keys/validator.priv \
-o config-genesis.batch && \
sawset proposal create \
-k /etc/sawtooth/keys/validator.priv \
sawtooth.consensus.algorithm=None \
sawtooth.consensus.pbft.peers=\\{'\\\"'$$(cat /etc/sawtooth/keys/validator.pub)'\\\"':0,'\\\"'$$(cat /etc/sawtooth/keys/validator-1.pub)'\\\"':1,'\\\"'$$(cat /etc/sawtooth/keys/validator-2.pub)'\\\"':2,'\\\"'$$(cat /etc/sawtooth/keys/validator-3.pub)'\\\"':3\\} \
sawtooth.consensus.pbft.block_duration=2000 \
sawtooth.consensus.pbft.checkpoint_period=10 \
sawtooth.consensus.pbft.view_change_timeout=4000 \
sawtooth.consensus.pbft.message_timeout=10 \
sawtooth.consensus.pbft.max_log_size=1000 \
-o config.batch && \
sawadm genesis \
config-genesis.batch config.batch && \
mv /etc/sawtooth/keys/validator-* /shared_keys && \
echo $$(cat /etc/sawtooth/keys/validator.pub); \
sawtooth-validator -v \
--endpoint tcp://validator-0:8800 \
--bind component:tcp://eth0:4004 \
--bind network:tcp://eth0:8800 \
--bind consensus:tcp://eth0:5050 \
--peering static \
--peers tcp://validator-1:8800,tcp://validator-2:8800,tcp://validator-3:8800
--scheduler parallel \
\""
stop_signal: SIGKILL

validator-1:
image: sawtooth-validator:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
- keys:/shared_keys
expose:
- 4004
- 8800
command: "bash -c \"\
while true; do if [ -e /shared_keys/validator-1.pub ]; then mv /shared_keys/validator-1.priv /etc/sawtooth/keys/validator.priv && mv /shared_keys/validator-1.pub /etc/sawtooth/keys/validator.pub; break; fi; sleep 0.5; done; \
echo $$(cat /etc/sawtooth/keys/validator.pub); \
sawtooth-validator \
--endpoint tcp://validator-1:8800 \
--bind component:tcp://eth0:4004 \
--bind network:tcp://eth0:8800 \
--bind consensus:tcp://eth0:5050 \
--peering static \
--peers tcp://validator-0:8800,tcp://validator-2:8800,tcp://validator-3:8800
--scheduler parallel \
\""
stop_signal: SIGKILL

validator-2:
image: sawtooth-validator:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
- keys:/shared_keys
expose:
- 4004
- 8800
command: "bash -c \"\
while true; do if [ -e /shared_keys/validator-2.pub ]; then mv /shared_keys/validator-2.priv /etc/sawtooth/keys/validator.priv && mv /shared_keys/validator-2.pub /etc/sawtooth/keys/validator.pub; break; fi; sleep 0.5; done; \
echo $$(cat /etc/sawtooth/keys/validator.pub); \
sawtooth-validator \
--endpoint tcp://validator-2:8800 \
--bind component:tcp://eth0:4004 \
--bind network:tcp://eth0:8800 \
--bind consensus:tcp://eth0:5050 \
--peering static \
--peers tcp://validator-0:8800,tcp://validator-1:8800,tcp://validator-3:8800
--scheduler parallel \
\""
stop_signal: SIGKILL

validator-3:
image: sawtooth-validator:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
- keys:/shared_keys
expose:
- 4004
- 8800
command: "bash -c \"\
while true; do if [ -e /shared_keys/validator-3.pub ]; then mv /shared_keys/validator-3.priv /etc/sawtooth/keys/validator.priv && mv /shared_keys/validator-3.pub /etc/sawtooth/keys/validator.pub; break; fi; sleep 0.5; done; \
echo $$(cat /etc/sawtooth/keys/validator.pub); \
sawtooth-validator \
--endpoint tcp://validator-3:8800 \
--bind component:tcp://eth0:4004 \
--bind network:tcp://eth0:8800 \
--bind consensus:tcp://eth0:5050 \
--peering static \
--peers tcp://validator-0:8800,tcp://validator-1:8800,tcp://validator-2:8800
--scheduler parallel \
\""
stop_signal: SIGKILL

pbft-0:
image: sawtooth-dev-pbft:$ISOLATION_ID
volumes:
- $SAWTOOTH_PBFT:/project/sawtooth-pbft
working_dir: /project/sawtooth-pbft/
command: ./target/debug/sawtooth-pbft --connect tcp://validator-0:5050 0 -d 15 -vv
stop_signal: SIGKILL

pbft-1:
image: sawtooth-dev-pbft:$ISOLATION_ID
volumes:
- $SAWTOOTH_PBFT:/project/sawtooth-pbft
working_dir: /project/sawtooth-pbft/
command: ./target/debug/sawtooth-pbft --connect tcp://validator-1:5050 1 -vv
stop_signal: SIGKILL

pbft-2:
image: sawtooth-dev-pbft:$ISOLATION_ID
volumes:
- $SAWTOOTH_PBFT:/project/sawtooth-pbft
working_dir: /project/sawtooth-pbft/
command: ./target/debug/sawtooth-pbft --connect tcp://validator-2:5050 2
stop_signal: SIGKILL

pbft-3:
image: sawtooth-dev-pbft:$ISOLATION_ID
volumes:
- $SAWTOOTH_PBFT:/project/sawtooth-pbft
working_dir: /project/sawtooth-pbft/
command: ./target/debug/sawtooth-pbft --connect tcp://validator-3:5050 3
stop_signal: SIGKILL

rest-api-0:
image: sawtooth-rest-api:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
- 8008
command: sawtooth-rest-api --connect tcp://validator-0:4004 --bind rest-api-0:8008
stop_signal: SIGKILL

rest-api-1:
image: sawtooth-rest-api:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
- 8008
command: sawtooth-rest-api --connect tcp://validator-1:4004 --bind rest-api-1:8008
stop_signal: SIGKILL

rest-api-2:
image: sawtooth-rest-api:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
- 8008
command: sawtooth-rest-api --connect tcp://validator-2:4004 --bind rest-api-2:8008
stop_signal: SIGKILL

rest-api-3:
image: sawtooth-rest-api:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
- 8008
command: sawtooth-rest-api --connect tcp://validator-3:4004 --bind rest-api-3:8008
stop_signal: SIGKILL

xo-tp-0:
image: sawtooth-xo-tp-python:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
command: xo-tp-python -C tcp://validator-0:4004
stop_signal: SIGKILL

xo-tp-1:
image: sawtooth-xo-tp-python:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
command: xo-tp-python -C tcp://validator-1:4004
stop_signal: SIGKILL

xo-tp-2:
image: sawtooth-xo-tp-python:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
command: xo-tp-python -C tcp://validator-2:4004
stop_signal: SIGKILL

xo-tp-3:
image: sawtooth-xo-tp-python:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
command: xo-tp-python -C tcp://validator-3:4004
stop_signal: SIGKILL

settings-tp-0:
image: sawtooth-settings-tp:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
command: settings-tp -C tcp://validator-0:4004
stop_signal: SIGKILL

settings-tp-1:
image: sawtooth-settings-tp:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
command: settings-tp -C tcp://validator-1:4004
stop_signal: SIGKILL

settings-tp-2:
image: sawtooth-settings-tp:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
command: settings-tp -C tcp://validator-2:4004
stop_signal: SIGKILL

settings-tp-3:
image: sawtooth-settings-tp:$ISOLATION_ID
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
expose:
- 4004
command: settings-tp -C tcp://validator-3:4004
stop_signal: SIGKILL

client:
image: sawtooth-dev-python:latest
volumes:
- $SAWTOOTH_CORE:/project/sawtooth-core
- $SAWTOOTH_PBFT:/project/sawtooth-pbft
working_dir: /project/sawtooth-pbft
environment:
PATH: "$PATH:/project/sawtooth-core/bin"
depends_on:
- rest-api-0
- rest-api-1
- rest-api-2
- rest-api-3
entrypoint: "bash -c \"\
sawtooth keygen && \
tail -f /dev/null \
\""

0 comments on commit 7005eac

Please sign in to comment.