disable unused rocksdb zlib feature that is not working with address sanitizer
cleanup run.sh script, add new node-saddr which runs node with address sanitizer enabled
include docker environment for address sanitizer
include address sanitizer tests in github workflow
MODIFY
.github/workflows/build.yml
.github/workflows/build.yml
@@ -13,6 +13,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
+ sanitizer: [none, address]
steps:
- uses: actions/checkout@v2
- name: Setup Rust
@@ -20,6 +21,12 @@ jobs:
with:
toolchain: nightly-2020-12-31
default: true
+ - name: Settings for cargo in Linux
+ if: matrix.os == 'ubuntu-latest' && matrix.sanitizer == 'address'
+ run: |
+ echo '[build]' >> ~/.cargo/config
+ echo 'rustflags = ["-Z", "sanitizer=address"]' >> ~/.cargo/config
+ echo 'rustdocflags = ["-Z", "sanitizer=address"]' >> ~/.cargo/config
- name: Settings for cargo in OSX
if: runner.os == 'macOS'
run: |
@@ -40,7 +47,15 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: check
+ - name: cargo test SADDR
+ if: matrix.sanitizer == 'address'
+ uses: actions-rs/cargo@v1
+ with:
+ command: test
- name: cargo test
+ if: matrix.sanitizer == 'none'
uses: actions-rs/cargo@v1
with:
command: test
+
+

MODIFY
Cargo.lock
Cargo.lock
@@ -2012,8 +2012,7 @@ checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397"
[[package]]
name = "ocaml-interop"
version = "0.4.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "73f6eb1378c49deceaf7fec407633c1f9ca8317ec58992da8a91e2c2164cc628"
+source = "git+https://github.com/simplestaking/ocaml-interop?branch=v0.4.4_saddr_fix#511d74095c4ba95408707e4ed4db7d0be8a73ab4"
dependencies = [
"ocaml-sys",
]

ADD
docker/sanitizer/Dockerfile
+FROM simplestakingcom/tezos-opam-builder:debian10 as build-env
+
+# Checkout and compile tezedge source code
+USER root
+
+ARG tezedge_git="https://github.com/simplestaking/tezedge.git"
+ARG rust_toolchain="nightly-2020-12-31"
+ENV RUSTUP_HOME=/opt/rustup
+ENV CARGO_HOME=/opt/cargo
+RUN mkdir $RUSTUP_HOME
+RUN mkdir $CARGO_HOME
+RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain ${rust_toolchain} -y
+ENV PATH=$CARGO_HOME/bin:$PATH
+ENV RUST_BACKTRACE=1
+ENV SODIUM_USE_PKG_CONFIG=1
+ENV OCAML_BUILD_CHAIN=remote
+
+#USER root
+RUN apt-get update && apt-get install clang libclang-dev libssl-dev -y
+RUN apt-get update && apt-get install gosu -y
+RUN echo "interceptor_via_lib:protocol-runner" > /asan.supp
+
+RUN rustup component add rust-src
+RUN chmod -R 777 /opt/cargo
+COPY docker-entrypoint.sh /entry.sh
+CMD ["/entry.sh"]

ADD
docker/sanitizer/docker-entrypoint.sh
+#!/bin/bash -e
+REPO_ROOT=/home/dev/repo
+USER="dev"
+GROUP="dev"
+
+USERID="$(stat -c '%u' "$REPO_ROOT")"
+GROUPID="$(stat -c '%g' "$REPO_ROOT")"
+
+
+groupadd -g $GROUPID $GROUP || :
+
+useradd -o --uid $USERID --gid $GROUPID $USER
+cd /home/$USER/repo
+exec /usr/sbin/gosu "$USER" /bin/bash

ADD
docker/sanitizer/enter.sh
+#!/bin/bash
+
+REPO_ROOT=$(readlink -f $(dirname $(readlink -f $0))/../../)
+#echo $REPO_ROOT
+
+docker build $REPO_ROOT/docker/sanitizer -t tezedge-sanitizer && docker run -v $REPO_ROOT:/home/dev/repo -it tezedge-sanitizer

MODIFY
light_node/Cargo.toml
light_node/Cargo.toml
@@ -12,7 +12,7 @@ futures = "0.3"
riker = "0.4"
rlimit = "0.5"
serde_json = "1.0"
-rocksdb = "0.15"
+rocksdb = {version = "0.15", features = ["snappy", "lz4", "zstd", "zlib"], default-features = false }
slog = { version = "2.7", features = ["max_level_trace"] }
slog-async = "2.6"
slog-json = "2.3"

MODIFY
run.sh
run.sh
# Copyright (c) SimpleStaking and Tezedge Contributors
# SPDX-License-Identifier: MIT
+# stop on first error
+set -e
+
warn_if_not_using_recommended_rust() {
RUSTC_TOOLCHAIN_VERSION="2020-12-31"
@@ -28,26 +31,51 @@ help() {
echo " # $0 docker --help"
}
-build_all() {
- # cargo build profile commandline argument
+configure_env_variables() {
+ options=$(getopt --longoptions debug,release,addrsanitizer --options "" --name $0 -- "$@")
+ eval set -- "$options"
+ while true ; do
case $1 in
- debug)
- # nothing to do here
+ --debug)
+ export PROFILE="debug"
shift
;;
- release)
- CARGO_PROFILE_ARG="--release"
+ --release)
+ export PROFILE="release"
+ shift
+ ;;
+ --addrsanitizer)
+ export RUSTFLAGS="-Z sanitizer=address"
+ export CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu"
+ shift
+ ;;
+ --)
shift
+ break
;;
*)
echo "Invalid function argument"
exit 1
;;
esac
+ done
+}
+
+print_configuration() {
+ echo -ne "\033[1;37mRunning Tezedge node in ${PROFILE^^} mode"
+ if [ -n "$CARGO_BUILD_TARGET" ]; then
+ echo -ne "($CARGO_BUILD_TARGET)"
+ fi
+
+ if [ -n "$RUSTFLAGS" ]; then
+ echo -ne " extra compilation flags : '$RUSTFLAGS'"
+ fi
+ echo -ne "\e[0m\n"
+}
- # this is required for the most linux distributions
+build_all() {
export SODIUM_USE_PKG_CONFIG=1
- cargo build $CARGO_PROFILE_ARG || exit 1
+ cargo build
}
run_node() {
@@ -67,25 +95,6 @@ run_node() {
# rest of the commandline arguments will end up here
args=()
-
- # set compilation profile and cargo commandline argument
- PROFILE=""
- case $1 in
- debug)
- PROFILE="debug"
- shift
- ;;
- release)
- CARGO_PROFILE_ARG="--release"
- PROFILE="release"
- shift
- ;;
- *)
- echo "Invalid function argument"
- exit 1
- ;;
- esac
-
shift # shift past <MODE>
# The following loop is used to replace default light-node commandline parameters.
@@ -139,20 +148,26 @@ run_node() {
# cleanup data directory
if [ -z "$KEEP_DATA" ]; then
- rm -rf "$BOOTSTRAP_DIR" && mkdir "$BOOTSTRAP_DIR"
- rm -rf "$TEZOS_DIR" && mkdir "$TEZOS_DIR"
+ rm -rf $TEZOS_DIR $BOOTSTRAP_DIR || true
+ mkdir -p $TEZOS_DIR $BOOTSTRAP_DIR
fi
# protocol_runner needs 'libtezos.so' to run
export LD_LIBRARY_PATH="${BASH_SOURCE%/*}/tezos/interop/lib_tezos/artifacts:${BASH_SOURCE%/*}/target/$PROFILE"
# start node
- cargo run $CARGO_PROFILE_ARG --bin light-node -- \
+ if [ -z "$CARGO_BUILD_TARGET" ]; then
+ PROTOCOL_RUNNER_BINARY=./target/$PROFILE/protocol-runner
+ else
+ PROTOCOL_RUNNER_BINARY=./target/$CARGO_BUILD_TARGET/$PROFILE/protocol-runner
+ fi
+
+ cargo run --bin light-node -- \
--config-file "$CONFIG_FILE" \
--tezos-data-dir "$TEZOS_DIR" \
--identity-file "$IDENTITY_FILE" \
--bootstrap-db-path "$BOOTSTRAP_DIR" \
--network "$NETWORK" \
- --protocol-runner "./target/$PROFILE/protocol-runner" "${args[@]}"
+ --protocol-runner $PROTOCOL_RUNNER_BINARY "${args[@]}"
}
run_docker() {
@@ -174,32 +189,12 @@ run_sandbox() {
# -n | --network
NETWORK=sandbox
- # set compilation profile and cargo commandline argument
- PROFILE=""
- case $1 in
- debug)
- PROFILE="debug"
- shift
- ;;
- release)
- CARGO_PROFILE_ARG="--release"
- PROFILE="release"
- shift
- ;;
- *)
- echo "Invalid function argument"
- exit 1
- ;;
- esac
-
- shift # shift past <MODE>
-
# protocol_runner needs 'libtezos.so' to run
export LD_LIBRARY_PATH="${BASH_SOURCE%/*}/tezos/interop/lib_tezos/artifacts:${BASH_SOURCE%/*}/target/$PROFILE"
export TEZOS_CLIENT_UNSAFE_DISABLE_DISCLAIMER="Y"
- cargo run $CARGO_PROFILE_ARG --bin sandbox -- \
+ cargo run --bin sandbox -- \
--log-level "info" \
--sandbox-rpc-port "3030" \
--light-node-path "./target/$PROFILE/light-node" \
@@ -211,27 +206,38 @@ case $1 in
node)
warn_if_not_using_recommended_rust
- printf "\033[1;37mRunning Tezedge node in DEBUG mode\e[0m\n"
- build_all "debug"
- run_node "debug" "$@"
+ configure_env_variables --debug
+ print_configuration
+ build_all
+ run_node "$@"
+ ;;
+
+ node-saddr)
+ warn_if_not_using_recommended_rust
+ configure_env_variables --debug --addrsanitizer
+ print_configuration
+ build_all
+ run_node "$@"
;;
release)
warn_if_not_using_recommended_rust
- printf "\033[1;37mRunning Tezedge node in RELEASE mode\e[0m\n"
- build_all "release"
- run_node "release" "$@"
+ configure_env_variables --release
+ print_configuration
+ build_all
+ run_node "$@"
;;
sandbox)
warn_if_not_using_recommended_rust
- printf "\033[1;37mRunning Tezedge node in RELEASE mode\e[0m\n"
- build_all "release"
- run_sandbox "release" "$@"
+ configure_env_variables --release
+ print_configuration
+ build_all
+ run_sandbox "$@"
;;
docker)
- printf "\033[1;37mRunning Tezedge node in docker\e[0m\n"
+ echo -ne "\033[1;37mRunning Tezedge node in docker\e[0m\n"
run_docker "$@"
;;

MODIFY
storage/Cargo.toml
storage/Cargo.toml
@@ -14,7 +14,7 @@ getset = "0.1"
hex = "0.4"
itertools = "0.10"
num_cpus = "1.13"
-rocksdb = "0.15"
+rocksdb = {version = "0.15", features = ["snappy", "lz4", "zstd", "zlib"], default-features = false }
serde = { version = "1.0", features = ["derive", "rc"] }
slog = "2.7"
# local dependencies

MODIFY
tezos/api/Cargo.toml
tezos/api/Cargo.toml
@@ -10,7 +10,9 @@ enum-iterator = "0.6"
failure = "0.1"
chrono = { version = "0.4", features = ["serde"] }
lazy_static = "1.4"
-ocaml-interop = { version = "0.4.4", features = ["docs-rs"] }
+# patched version of v.0.4.4 - once new version of ocaml interop
+# is integrated git reference should be no longer used
+ocaml-interop = { git="https://github.com/simplestaking/ocaml-interop", branch="v0.4.4_saddr_fix"}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
# local dependencies

MODIFY
tezos/interop/Cargo.toml
tezos/interop/Cargo.toml
@@ -9,7 +9,11 @@ failure = "0.1"
futures = { version = "0.3", features = ["thread-pool"] }
hex = "0.4"
lazy_static = "1.4"
-ocaml-interop = { version = "0.4.4", features = ["docs-rs"] }
+
+# patched version of v.0.4.4 - once new version of ocaml interop
+# is integrated git reference should be no longer used
+ocaml-interop = { git="https://github.com/simplestaking/ocaml-interop", branch="v0.4.4_saddr_fix"}
+
serde_json = "1.0"
# local dependencies
tezos_api = { path = "../api" }

MODIFY
tezos/interop_callback/Cargo.toml
tezos/interop_callback/Cargo.toml
@@ -8,6 +8,8 @@ edition = "2018"
crate-type = ["dylib", "rlib"]
[dependencies]
-ocaml-interop = { version = "0.4.4", features = ["docs-rs"] }
+# patched version of v.0.4.4 - once new version of ocaml interop
+# is integrated git reference should be no longer used
+ocaml-interop = { git="https://github.com/simplestaking/ocaml-interop/", branch="v0.4.4_saddr_fix"}
# local dependencies
tezos_context = { path = "../context" }

disable unused rocksdb zlib feature that is not working with address sanitizer
cleanup run.sh script, add new node-saddr which runs node with address sanitizer enabled
include docker environment for address sanitizer
include address sanitizer tests in github workflow