Skip to content

Instantly share code, notes, and snippets.

@nginnever
Created February 10, 2020 20:50
Show Gist options
  • Save nginnever/8fc85ce381a4f87beea775b2aeaa043e to your computer and use it in GitHub Desktop.
Save nginnever/8fc85ce381a4f87beea775b2aeaa043e to your computer and use it in GitHub Desktop.
This file has been truncated, but you can view the full file.
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..53f7426
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1 @@
+**/target/
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index b6e8700..f07a38a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@
# These are backup files generated by rustfmt
**/*.rs.bk
+
+.idea
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..83bac8f
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,54 @@
+# Request an environment that provides sudo (that goes with larger containers)
+# and a minimal language environment.
+sudo: true
+language: rust
+
+services:
+ - docker
+
+before_cache:
+ # Travis can't cache files that are not readable by "others"
+ - chmod -R a+r $HOME/.cargo
+
+cache: cargo
+
+branches:
+ only:
+ - master
+
+env:
+ global:
+ - RUST_BACKTRACE=1
+ - secure: "gV/Zl5ihkZTB3S8ezmpTD7gvAzI2+tOSEQhZr91XoLptLt/w0y69q9ggOUiC457tD+77nb5SgqfRNI1PC+57xWpky1SowKJLzzmEbSdGdv+D35WcJVED4sasyEVPKolO3uOdW6h6vCOpRkyEOqHI4q/x7TUZu1ZiqrXHaU3U7s8MRceRCdzFRyC9l6RF9ovyIz/4aagfIvMPq5KB7WfmoJmkj/MDtNoUwuF8pry1HIbvPkx1Us7iYxVuzzUpuZOyp2dm1/7ERgTxURI9JwokvRxHW4EyBH3QWoKpMRIQZNQbjfluviSBKGpqXkBrsnwagDuVyC1tlUR2ZJOaJtAJcSlKaljLlj3pfPHYCORAFSKFyi3BKSNBf9kzVNcYVuZgosiXSaCzD1QYBlfBRcuDVgVPaxViMRmHAVZmYZBKOUO6YLasZIIkHzERAuhLF/vpetDIR/2A3cWbwknz55NXvvo5rY28a5YYEuactaJrTPbOP4y6WW22E2XkcuWcRN+TPN1bhoUctqT2DXxvlqqPTIILae/WV9hKFvB3bfnQVyB8BHldSmjLsLwQC4TzAJEIgegfC431bZGFn2pRTwJDtpiocThmzkWn8UOf9jCFTin4VZcQxEr6vZusKY77PObTEMQTJpiz6LSYDsTTMgTc5lmi8zJ0E/JlkL94vbL0SsM="
+ - secure: "p1XKGf0G74t6shD456Bbc89K83lLx8M5JZpik/7gIBwnninm5FVE+8Zm9+88gjIBSlcx9Rlp2P01va6fiTGDPTk3hDmioCJIifQSrCakd6/hiANu8IVZqj9ud83lBYuWYOY2kjTtFKV4e2JO80lny2+w6+cs3vGbltTxDwF0nAJV7T1kb2RMZOzUXd1/I0mAU68hg4EZ/tLV6H5g2I+Au1k0iST3EXxYaykGXntmDR7xv6QZboFT97ZUyb2gnqqM1MRui0aVft+XaFIy2/TQah2uwZy7cM+zzhBcVUSttiQqsNN8m789fo1xgZDFUR5tPNBBiztmRnk5/DvmESyGO8yFsy4mNFVplugyNpTq+7UBBxv2yf6CU1/TEtGNvbciTKt8celZajsm+o7Z+4kxUMOCLn1sS1wcoq3cnGHItSSHM72/ph3voJpe/4UxDMcnsWfQINLm13Q0ttNmx5hqwB9KinYor76UKE3LnfdT53G3x8/pdjkdQUURNB37A6S6UWWu7zZIJ1BgxQmQPBmIhlG98zVwqFtbuqMLX29rAUGR3Zu9YGmPcmFkoL9R2vfflUrUmdG4p5S/p9+F33PFpmSzb40I0ewlvgWyOddX/jo9/WRf0N943OxWjr7OEyIwC56t/q9zpwPo14qeu75S7L8DXNPyFONHiYddO+HhzBc="
+
+before_install:
+ # Check how much space we've got on this machine.
+ - df -h
+
+jobs:
+ include:
+ - stage: "Test and build"
+ name: "Run runtime tests"
+ script: RUST_TOOLCHAIN=nightly-2019-10-13 TARGET=runtime-test travis_wait 180 ./ci/script.sh
+ - # stage name not required, will continue last one
+ name: "Build (WASM and native)"
+ script: RUST_TOOLCHAIN=nightly-2019-10-13 TARGET=build-client travis_wait 180 ./ci/script.sh
+ - stage: "Build and push Docker image"
+ if: (NOT type IN (pull_request)) AND (branch = master)
+ script: travis_wait 180 ./ci/docker.sh
+
+addons:
+ apt:
+ packages:
+ - libcurl4-openssl-dev
+ - libelf-dev
+ - libdw-dev
+ - cmake
+ - gcc
+ - binutils-dev
+ - libiberty-dev
+
+after_script:
+ # Check how much free disk space left after the build
+ - df -h
diff --git a/Cargo.toml b/Cargo.toml
index b576af1..809faf0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,83 +1,146 @@
-[dependencies]
-error-chain = '0.12'
-exit-future = '0.1'
-futures = '0.1'
-hex-literal = '0.1'
-log = '0.4'
-parity-codec = '3.2'
-parking_lot = '0.7.1'
-tokio = '0.1'
-trie-root = '0.12.0'
-
-[dependencies.basic-authorship]
-git = 'https://github.com/paritytech/substrate.git'
-package = 'substrate-basic-authorship'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
-
-[dependencies.consensus]
-git = 'https://github.com/paritytech/substrate.git'
-package = 'substrate-consensus-aura'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
-
-[dependencies.ctrlc]
-features = ['termination']
-version = '3.0'
-
-[dependencies.inherents]
-git = 'https://github.com/paritytech/substrate.git'
-package = 'substrate-inherents'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
-
-[dependencies.network]
-git = 'https://github.com/paritytech/substrate.git'
-package = 'substrate-network'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
-
-[dependencies.centrifuge-chain-runtime]
-path = 'runtime'
-
-[dependencies.primitives]
-git = 'https://github.com/paritytech/substrate.git'
-package = 'substrate-primitives'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
-
-[dependencies.sr-io]
-git = 'https://github.com/paritytech/substrate.git'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
-
-[dependencies.substrate-cli]
-git = 'https://github.com/paritytech/substrate.git'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
-
-[dependencies.substrate-client]
-git = 'https://github.com/paritytech/substrate.git'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
-
-[dependencies.substrate-executor]
-git = 'https://github.com/paritytech/substrate.git'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
-
-[dependencies.substrate-service]
-git = 'https://github.com/paritytech/substrate.git'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
+[package]
+name = "centrifuge-chain"
+version = "2.0.0"
+authors = ["philip@centrifuge.io", "vimukthi@centrifuge.io"]
+build = "build.rs"
+edition = "2018"
+default-run = "centrifuge-chain"
-[dependencies.transaction-pool]
-git = 'https://github.com/paritytech/substrate.git'
-package = 'substrate-transaction-pool'
-rev = '2e30b7321df0cc4dba525cfcf18df8438e12b830'
+[[bin]]
+name = "centrifuge-chain"
+path = "src/main.rs"
+required-features = ["cli"]
-[package]
-authors = ['Parity Technologies <admin@parity.io>']
-build = 'build.rs'
-edition = '2018'
-name = 'centrifuge-chain'
-version = '1.0.0'
+[dependencies]
+# third-party dependencies
+codec = { package = "parity-scale-codec", version = "1.0.6" }
+serde = { version = "1.0.102", features = ["derive"] }
+futures01 = { package = "futures", version = "0.1.29" }
+futures = { version = "0.3.1", features = ["compat"] }
+hex-literal = "0.2.1"
+jsonrpc-core = "14.0.3"
+jsonrpc-core-client = "14.0.3"
+jsonrpc-derive = "14.0.3"
+log = "0.4.8"
+rand = "0.7.2"
+structopt = "=0.3.7"
+serde_json = "1.0.41"
+
+# primitives
+sp-authority-discovery = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32"}
+sp-consensus-babe = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+grandpa-primitives = { package = "sp-finality-grandpa", git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sp-core = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sp-runtime = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sp-timestamp = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", default-features = false }
+sp-finality-tracker = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", default-features = false }
+sp-inherents = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sp-keyring = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sp-io = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sp-consensus = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+
+# client dependencies
+sc-client-api = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-client = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32"}
+sc-chain-spec = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-transaction-pool = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-network = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-consensus-babe = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+grandpa = { package = "sc-finality-grandpa", git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-client-db = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", default-features = false }
+sc-offchain = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-rpc = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-basic-authority = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-service = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", default-features = false }
+sc-telemetry = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-authority-discovery = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-executor = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+
+# frame dependencies
+pallet-indices = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", default-features = false }
+frame-system = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+pallet-balances = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+pallet-transaction-payment = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+frame-support = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", default-features = false }
+pallet-im-online = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", default-features = false }
+pallet-authority-discovery = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+
+# node-specific dependencies
+node-runtime = { package = "centrifuge-chain-runtime", path = "runtime" }
+# node-rpc = { path = "../rpc" }
+node-primitives = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+
+# CLI-specific dependencies
+tokio = { version = "0.1.22", optional = true }
+sc-cli = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", optional = true }
+ctrlc = { version = "3.1.3", features = ["termination"], optional = true }
+node-transaction-factory = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", optional = true }
+
+# WASM-specific dependencies
+libp2p = { version = "0.13.2", default-features = false, optional = true }
+clear_on_drop = { version = "0.2.3", features = ["no_cc"], optional = true } # Imported just for the `no_cc` feature
+console_error_panic_hook = { version = "0.1.1", optional = true }
+console_log = { version = "0.1.2", optional = true }
+js-sys = { version = "0.3.22", optional = true }
+wasm-bindgen = { version = "0.2.45", optional = true }
+wasm-bindgen-futures = { version = "0.3.22", optional = true }
+kvdb-memorydb = { version = "0.2.0", optional = true }
+rand6 = { package = "rand", version = "0.6", features = ["wasm-bindgen"], optional = true } # Imported just for the `wasm-bindgen` feature
+
+[dev-dependencies]
+sc-keystore = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+sc-consensus-babe = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32", features = ["test-helpers"] }
+sc-service-test = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+futures = "0.3.1"
+tempfile = "3.1.0"
[build-dependencies]
-vergen = '3'
-[profile.release]
-panic = 'unwind'
+sc-cli = { git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+build-script-utils = { package = "substrate-build-script-utils", git = "https://github.com/paritytech/substrate.git", rev = "ddb309ae7c70e5e51a60879af18819cf28be4a32" }
+structopt = "=0.3.7"
+vergen = "3.0.4"
+
+[features]
+default = ["cli"]
+browser = [
+ "clear_on_drop",
+ "console_error_panic_hook",
+ "console_log",
+ "js-sys",
+ "libp2p",
+ "wasm-bindgen",
+ "wasm-bindgen-futures",
+ "kvdb-memorydb",
+ "rand/wasm-bindgen",
+ "rand6"
+]
+cli = [
+ "sc-cli",
+ "node-transaction-factory",
+ "tokio",
+ "ctrlc",
+ "sc-service/rocksdb",
+ "sc-executor/wasmi-errno",
+]
+wasmtime = [
+ "cli",
+ "sc-executor/wasmtime",
+ "sc-cli/wasmtime",
+ "sc-service/wasmtime",
+]
+
+[workspace]
+members = [
+ "runtime",
+]
+
+[badges]
+maintenance = { status = "actively-developed" }
-[[bin]]
-name = 'centrifuge-chain'
-path = 'src/main.rs'
+[profile.release]
+# Runtime requires unwinding.
+panic = "unwind"
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..a45bbd4
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,59 @@
+# Note: We don't use Alpine and its packaged Rust/Cargo because they're too often out of date,
+# preventing them from being used to build Substrate/Polkadot.
+
+FROM phusion/baseimage:0.10.2 as builder
+LABEL maintainer="philip@centrifuge.io"
+LABEL description="This is the build stage for the Centrifuge Chain client. Here the binary is created."
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+ARG PROFILE=release
+WORKDIR /centrifuge-chain
+
+COPY . /centrifuge-chain
+
+RUN apt-get update && \
+ apt-get dist-upgrade -y -o Dpkg::Options::="--force-confold" && \
+ apt-get install -y cmake pkg-config libssl-dev git clang
+
+RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
+ export PATH="$PATH:$HOME/.cargo/bin" && \
+ rustup toolchain install nightly && \
+ rustup target add wasm32-unknown-unknown --toolchain nightly && \
+ rustup default nightly && \
+ rustup default stable && \
+ cargo build "--$PROFILE"
+
+# ===== SECOND STAGE ======
+
+FROM phusion/baseimage:0.10.2
+LABEL maintainer="philip@centrifuge.io"
+LABEL description="This is the 2nd stage: a very small image that contains the centrifuge-chain binary and will be used by users."
+ARG PROFILE=release
+
+RUN mv /usr/share/ca* /tmp && \
+ rm -rf /usr/share/* && \
+ mv /tmp/ca-certificates /usr/share/ && \
+ mkdir -p /root/.local/share/centrifuge-chain && \
+ ln -s /root/.local/share/centrifuge-chain /data
+ # && \
+ # useradd -m -u 1000 -U -s /bin/sh -d /centrifuge-chain centrifuge-chain # commented out since users do not seem to work with PVCs we currently use: https://stackoverflow.com/questions/46873796/allowing-access-to-a-persistentvolumeclaim-to-non-root-user/46907452
+
+COPY --from=builder /centrifuge-chain/target/$PROFILE/centrifuge-chain /usr/local/bin
+
+# checks
+RUN ldd /usr/local/bin/centrifuge-chain && \
+ /usr/local/bin/centrifuge-chain --version
+
+# Shrinking
+RUN rm -rf /usr/lib/python* && \
+ rm -rf /usr/bin /usr/sbin /usr/share/man
+
+# Add chain resources to image
+COPY res /resources/
+
+# USER centrifuge-chain # see above
+EXPOSE 30333 9933 9944
+VOLUME ["/data"]
+
+CMD ["/usr/local/bin/centrifuge-chain"]
diff --git a/LICENSE b/LICENSE
index cf1ab25..e554c4c 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,24 +1,165 @@
-This is free and unencumbered software released into the public domain.
-
-Anyone is free to copy, modify, publish, use, compile, sell, or
-distribute this software, either in source code form or as a compiled
-binary, for any purpose, commercial or non-commercial, and by any
-means.
-
-In jurisdictions that recognize copyright laws, the author or authors
-of this software dedicate any and all copyright interest in the
-software to the public domain. We make this dedication for the benefit
-of the public at large and to the detriment of our heirs and
-successors. We intend this dedication to be an overt act of
-relinquishment in perpetuity of all present and future rights to this
-software under copyright law.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-For more information, please refer to <http://unlicense.org>
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2019 Centrifuge GmbH <https://centrifuge.io/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/README.md b/README.md
index 250ebbe..d3c2030 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,11 @@
# centrifuge-chain
-A new SRML-based Substrate node, ready for hacking.
+[![Build Status](https://travis-ci.com/centrifuge/centrifuge-chain.svg?branch=master)](https://travis-ci.com/centrifuge/centrifuge-chain)
+[![codecov](https://codecov.io/gh/centrifuge/centrifuge-chain/branch/master/graph/badge.svg)](https://codecov.io/gh/centrifuge/centrifuge-chain)
-# Building
+Centrifuge Chain is [Centrifuge](https://centrifuge.io)'s [substrate](https://github.com/paritytech/substrate) based chain.
+
+## Build
Install Rust:
@@ -10,59 +13,108 @@ Install Rust:
curl https://sh.rustup.rs -sSf | sh
```
-Install required tools:
+Initialize your Wasm Build environment:
```bash
./scripts/init.sh
```
-Build the WebAssembly binary:
+Build Wasm and native code:
```bash
-./scripts/build.sh
+cargo build --release
```
-Build all native code:
+## Run
+
+### Testnets
+
+Centrifuge has multiple testnets online.
+
+1. Fulvous is an ephemeral testnet for internal dev purposes, and testing internal integrations with all the centrifuge components. Not recommended for external usage due to its nature and purpose.
+2. Flint is for breaking changes and testing the integration with other parts of the Centrifuge ecosystem. Think of Flint as a way to test previews, alpha releases.
+3. Amber is for audits and testing of the stability of release candidates. Think of Amber as a way to test beta releases.
+
+#### 1. Fulvous
+
+To run a node:
```bash
-cargo build
+./target/release/centrifuge-chain \
+ --chain=fulvous \
+ --name "My node name" \
+ --bootnodes /ip4/35.246.140.178/tcp/30333/p2p/QmRg2bEPTHCt8u3a1LeZA8dJTd8mgMccsAcoHXTjQUpcZj \
+ --bootnodes /ip4/35.198.166.26/tcp/30333/p2p/QmNpeu3bJhESzriWMLRcxRgSCYDGQ6GdBHnJAf8bJexAd5
```
-# Run
+#### 2. Flint
-You can start a development chain with:
+To run a node:
```bash
-cargo run -- --dev
+./target/release/centrifuge-chain \
+ --chain=flint \
+ --name "My node name" \
+ --bootnodes=/ip4/34.89.190.227/tcp/30333/p2p/QmdMJoLc6yduqfrJtMAB6xHegydr3YXzfDCZWEYsaCJaRZ \
+ --bootnodes=/ip4/35.234.68.18/tcp/30333/p2p/Qma5M7P5qym3Gfgp1wu6yk1QyMv2RzFV9GztP9AxHoK8PK \
+ --bootnodes=/ip4/35.246.244.114/tcp/30333/p2p/QmdjEGZ9ZNVv4aTGGV46AkBqgCdWTHrh9wr9itYhs61gJA \
+ --bootnodes=/ip4/34.89.148.219/tcp/30333/p2p/QmNd8inSbEvFuwbRToj5VQBNReqtb414oWGyDjF7tQ1qfX
```
-Detailed logs may be shown by running the node with the following environment variables set: `RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- --dev`.
+To receive tokens, use our faucet: https://faucets.blockxlabs.com/
-If you want to see the multi-node consensus algorithm in action locally, then you can create a local testnet with two validator nodes for Alice and Bob, who are the initial authorities of the genesis chain that have been endowed with testnet units. Give each node a name and expose them so they are listed on the Polkadot [telemetry site](https://telemetry.polkadot.io/#/Local%20Testnet). You'll need two terminal windows open.
+To run a validator: https://centrifuge.hackmd.io/@pstehlik/rJ4ldDdiH
-We'll start Alice's substrate node first on default TCP port 30333 with her chain database stored locally at `/tmp/alice`. The bootnode ID of her node is `QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN`, which is generated from the `--node-key` value that we specify below:
+#### 2. Amber
+
+tbd
+
+### Single node development chain
+
+Purge any existing developer chain state:
```bash
-cargo run -- \
+cargo run --release -- purge-chain --dev
+```
+
+Start a development chain with:
+
+```bash
+cargo run --release -- --dev
+```
+
+Detailed logs may be shown by running the node with the following environment variables set: `RUST_LOG=debug RUST_BACKTRACE=1 cargo run --release -- --dev`.
+
+### Multi-node local testnet
+
+If you want to see the multi-node consensus algorithm in action locally, then you can create a local testnet with two validator nodes for Alice and Bob, who are the initial authorities that have been endowed with testnet tokens.
+
+You'll need two terminal windows open.
+
+We'll start Alice's node first on default TCP port 30333 with her chain database stored locally at `/tmp/alice`. The identity of her node is `QmPf2cdiE6Sp2Njxzy6cz8vHA7ii86mMFF61e6NMGRtFbr`:
+
+```bash
+./target/release/centrifuge-chain \
--base-path /tmp/alice \
--chain=local \
- --alice \
- --node-key 0000000000000000000000000000000000000000000000000000000000000001 \
- --telemetry-url ws://telemetry.polkadot.io:1024 \
- --validator
+ --alice
```
-In the second terminal, we'll start Bob's substrate node on a different TCP port of 30334, and with his chain database stored locally at `/tmp/bob`. We'll specify a value for the `--bootnodes` option that will connect his node to Alice's bootnode ID on TCP port 30333:
+In the second terminal, we'll start Bob's node on TCP port 30334, and with his chain database stored locally at `/tmp/bob`. We'll specify a value for the `--bootnodes` option that will connect his node to Alice's bootnode ID on TCP port 30333:
```bash
-cargo run -- \
+./target/release/centrifuge-chain \
--base-path /tmp/bob \
- --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN \
+ --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/QmPf2cdiE6Sp2Njxzy6cz8vHA7ii86mMFF61e6NMGRtFbr \
--chain=local \
--bob \
- --port 30334 \
- --telemetry-url ws://telemetry.polkadot.io:1024 \
- --validator
+ --port 30334
```
-Additional CLI usage options are available and may be shown by running `cargo run -- --help`.
+Additional CLI usage options are available and may be shown by running `./target/release/centrifuge-chain --help`.
+
+### Generating a new genesis file
+
+1. Be sure to change the `id` and `protocol_id` in `src/chain_spec.rs`
+2. Run `cargo run --release build-spec --disable-default-bootnode --chain flint > res/[name]-spec.json` to export the chain spec
+3. Commit
\ No newline at end of file
diff --git a/build.rs b/build.rs
index afc39d3..b84597f 100644
--- a/build.rs
+++ b/build.rs
@@ -1,8 +1,36 @@
+use std::{fs, env, path::Path};
+use structopt::{StructOpt, clap::Shell};
+use sc_cli::{NoCustom, CoreParams};
use vergen::{ConstantsFlags, generate_cargo_keys};
-const ERROR_MSG: &str = "Failed to generate metadata files";
-
fn main() {
- generate_cargo_keys(ConstantsFlags::all()).expect(ERROR_MSG);
- println!("cargo:rerun-if-changed=.git/HEAD");
+ build_shell_completion();
+ generate_cargo_keys(ConstantsFlags::all()).expect("Failed to generate metadata files");
+
+ build_script_utils::rerun_if_git_head_changed();
+}
+
+/// Build shell completion scripts for all known shells
+/// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123
+fn build_shell_completion() {
+ for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] {
+ build_completion(shell);
+ }
+}
+
+/// Build the shell auto-completion for a given Shell
+fn build_completion(shell: &Shell) {
+ let outdir = match env::var_os("OUT_DIR") {
+ None => return,
+ Some(dir) => dir,
+ };
+ let path = Path::new(&outdir)
+ .parent().unwrap()
+ .parent().unwrap()
+ .parent().unwrap()
+ .join("completion-scripts");
+
+ fs::create_dir(&path).ok();
+
+ CoreParams::<NoCustom, NoCustom>::clap().gen_completions("substrate-node", *shell, &path);
}
diff --git a/ci/docker.sh b/ci/docker.sh
new file mode 100755
index 0000000..fc7bccc
--- /dev/null
+++ b/ci/docker.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+GIT_SHORT_COMMIT=`git rev-parse --short HEAD`
+TIMESTAMP=`date -u +%Y%m%d%H%M%S`
+IMAGE_NAME="centrifugeio/centrifuge-chain"
+TAG="${TIMESTAMP}-${GIT_SHORT_COMMIT}"
+
+docker build $BUILD_ARGS -t ${IMAGE_NAME}:${TAG} .
+docker tag "${IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:latest"
+echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
+docker push ${IMAGE_NAME}:latest
+docker push ${IMAGE_NAME}:${TAG}
diff --git a/ci/script.sh b/ci/script.sh
new file mode 100755
index 0000000..a820305
--- /dev/null
+++ b/ci/script.sh
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+set -eux
+
+# Enable warnings about unused extern crates
+export RUSTFLAGS=" -W unused-extern-crates"
+
+# Install rustup and the specified rust toolchain.
+curl https://sh.rustup.rs -sSf | sh -s -- -y
+
+# Load cargo environment. Specifically, put cargo into PATH.
+source ~/.cargo/env
+
+rustup toolchain install $RUST_TOOLCHAIN
+rustup default $RUST_TOOLCHAIN
+
+rustc --version
+rustup --version
+cargo --version
+
+sudo apt-get -y update
+sudo apt-get install -y cmake pkg-config libssl-dev
+
+./scripts/init.sh
+
+rustup target add wasm32-unknown-unknown --toolchain $RUST_TOOLCHAIN
+
+case $TARGET in
+ "build-client")
+ cargo build --release --locked "$@"
+ ;;
+
+ "runtime-test")
+ cargo test -p centrifuge-chain-runtime
+ wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
+ tar xzf master.tar.gz &&
+ cd kcov-master &&
+ mkdir build &&
+ cd build &&
+ cmake .. &&
+ make &&
+ make install DESTDIR=../../kcov-build &&
+ cd ../.. &&
+ rm -rf kcov-master &&
+ for file in target/debug/centrifuge_chain*; do [ -x "${file}" ] || continue; mkdir -p "target/cov/$(basename $file)"; kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done &&
+ bash <(curl -s https://codecov.io/bash) &&
+ echo "Uploaded code coverage"
+ ;;
+esac
diff --git a/cloudbuild.yaml b/cloudbuild.yaml
new file mode 100644
index 0000000..fd64082
--- /dev/null
+++ b/cloudbuild.yaml
@@ -0,0 +1,11 @@
+steps:
+- name: 'gcr.io/cloud-builders/docker'
+ args: [
+ 'build',
+ '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$REVISION_ID',
+ '--cache-from', 'gcr.io/$PROJECT_ID/$REPO_NAME',
+ '.'
+ ]
+timeout: 10800s
+images:
+- 'gcr.io/$PROJECT_ID/$REPO_NAME:$REVISION_ID'
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..358bc78
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,74 @@
+version: "3.7"
+services:
+ validator-alice:
+ image: centrifugeio/centrifuge-chain:latest
+ ports:
+ - 9933:9933
+ - 9944:9944
+ - 30333:30333
+ networks:
+ - internet
+ volumes:
+ - "~/tmp/centrifuge-chain/alice/:/data"
+ entrypoint:
+ - centrifuge-chain
+ # Local node id: QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR
+ - --node-key=0000000000000000000000000000000000000000000000000000000000000001
+ - --chain=local
+ - --alice
+ - --bootnodes=/dns4/validator-bob/tcp/30333/p2p/QmSVnNf9HwVMT1Y4cK1P6aoJcEZjmoTXpjKBmAABLMnZEk
+ - --bootnodes=/dns4/validator-charlie/tcp/30333/p2p/QmV7EhW6J6KgmNdr558RH1mPx2xGGznW7At4BhXzntRFsi
+ - --ws-external
+ - --rpc-external
+ - --no-telemetry
+ - --rpc-cors=all
+ validator-bob:
+ image: centrifugeio/centrifuge-chain:latest
+ ports:
+ - 9934:9933
+ - 9945:9944
+ - 30334:30333
+ networks:
+ - internet
+ volumes:
+ - "~/tmp/centrifuge-chain/bob/:/data"
+ entrypoint:
+ - centrifuge-chain
+ # Local node id: QmSVnNf9HwVMT1Y4cK1P6aoJcEZjmoTXpjKBmAABLMnZEk
+ - --node-key=0000000000000000000000000000000000000000000000000000000000000002
+ - --chain=local
+ - --bob
+ - --bootnodes=/dns4/validator-alice/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR
+ - --bootnodes=/dns4/validator-charlie/tcp/30333/p2p/QmV7EhW6J6KgmNdr558RH1mPx2xGGznW7At4BhXzntRFsi
+ - --ws-external
+ - --rpc-external
+ - --no-telemetry
+ - --rpc-cors=all
+ validator-charlie:
+ image: centrifugeio/centrifuge-chain:latest
+ ports:
+ - 9935:9933
+ - 9946:9944
+ - 30335:30333
+ networks:
+ - internet
+ volumes:
+ - "~/tmp/centrifuge-chain/charlie/:/data"
+ entrypoint:
+ - centrifuge-chain
+ # Local node id: QmV7EhW6J6KgmNdr558RH1mPx2xGGznW7At4BhXzntRFsi
+ - --node-key=0000000000000000000000000000000000000000000000000000000000000003
+ - --chain=local
+ - --charlie
+ - --bootnodes=/dns4/validator-alice/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR
+ - --bootnodes=/dns4/validator-bob/tcp/30333/p2p/QmSVnNf9HwVMT1Y4cK1P6aoJcEZjmoTXpjKBmAABLMnZEk
+ - --ws-external
+ - --rpc-external
+ - --no-telemetry
+ - --rpc-cors=all
+ # ui:
+ # image: polkadot-js/apps
+ # ports:
+ # - "3000:80"
+networks:
+ internet:
diff --git a/res/amber-spec.json b/res/amber-spec.json
new file mode 100644
index 0000000..23305ed
--- /dev/null
+++ b/res/amber-spec.json
@@ -0,0 +1,169 @@
+{
+ "name": "Centrifuge Testnet Amber",
+ "id": "amber",
+ "bootNodes": [],
+ "telemetryEndpoints": [
+ [
+ "wss://telemetry.polkadot.io/submit/",
+ 0
+ ]
+ ],
+ "protocolId": "amber",
+ "properties": {
+ "tokenDecimals": 18,
+ "tokenSymbol": "ARAD"
+ },
+ "forkBlocks": null,
+ "badBlocks": null,
+ "consensusEngine": null,
+ "genesis": {
+ "runtime": {
+ "frameSystem": {
+ "changesTrieConfig": null,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment