diff --git a/Dockerfile b/Dockerfile index 66790a326..393888f54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM ubuntu:xenial +FROM ubuntu:xenial as builder -WORKDIR /substrate +WORKDIR /build # install tools and dependencies RUN apt -y update && \ @@ -9,10 +9,6 @@ RUN apt -y update && \ make cmake ca-certificates g++ zip dpkg-dev python rhash rpm openssl gettext\ build-essential pkg-config libssl-dev libudev-dev ruby-dev time -#install nodejs -RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - && \ - apt-get install -y nodejs - # install rustup RUN curl https://sh.rustup.rs -sSf | sh -s -- -y @@ -48,14 +44,40 @@ ENV CXX g++ ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 -COPY . /substrate +COPY . /build RUN /bin/bash build.sh RUN cargo build && cargo test -EXPOSE 30333 9933 9944 +FROM ubuntu:xenial + +WORKDIR /runtime + +RUN apt -y update && \ + apt install -y --no-install-recommends \ + openssl \ + curl \ + libssl-dev dnsutils + +RUN mkdir -p /runtime/target/debug/ +COPY --from=builder /build/target/debug/node ./target/debug/node +COPY --from=builder /build/start-node.sh ./start-node.sh + +RUN chmod a+x *.sh RUN ls -la . -CMD ["cargo", "run", "--", "dev"] \ No newline at end of file +# expose node ports +EXPOSE 30333 9933 9944 + +# +# Pass the node start command to the docker run command +# +# To start Alice boot node: +# ./start-node --account-name Alice --telemetry +# +# To start a node that connects to Alice: +# ./start-node.sh --account-name Charly --connect-to Alice -t +# +CMD ["echo","\"Please provide a startup command.\""] diff --git a/README.md b/README.md index cb97047d3..47a99274a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,45 @@ -# substrate-poc -A new SRML-based Substrate node, ready for hacking +# prototype-chain -## Run inside docker container +Substrate node implementation for the KILT prototype + +## Running a local node that connects to KILT prototype testnet in AWS + +There are master boot nodes running in the KILT testnet: + +* Alice (bootnode-alice.kilt-prototype.tk) +* Bob (bootnode-bob.kilt-prototype.tk) + +To start a node and connect to Alice you can use the shell script `start-node.sh`: + +``` +./start-node.sh --account-name Charly --connect-to Alice +``` + +You can use any of the accounts declared in the chain spec to connect (Alice, Bob, Charly, Dave, Eve, Ferdie). + +Run `./start-node.sh --help` for more information. + +### Running a node inside a docker container + +Make sure to have the `awscli` installed. Otherwise Install it via `brew install awscli` (Mac). +You also need to have your docker daemon system running (on mac, just download and install the docker application). + +Login to Amazon ECR + +``` + $(aws ecr get-login --no-include-email --region eu-central-1) +``` + +Pull the latest image from Amazon ECR ``` -docker build -t substrate-poc . -docker run -p 9933:9933 -p 9944:9944 -p 30333:30333 --publish-all=true -it substrate-poc +docker pull 348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/prototype-chain:latest ``` + +Run the image and pass the command to start a node + +``` +docker run 348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/prototype-chain ./start-node.sh --account-name Charly --connect-to Alice +``` + +The node should be connected to the KILT testnet. \ No newline at end of file diff --git a/build.sh b/build.sh index 55b53039a..f19200850 100755 --- a/build.sh +++ b/build.sh @@ -8,16 +8,13 @@ PROJECT_ROOT=`pwd` export CARGO_INCREMENTAL=0 -bold=$(tput bold) -normal=$(tput sgr0) - # Save current directory. pushd . >/dev/null for SRC in runtime/wasm do echo "$PROJECT_ROOT/$SRC" - echo "${bold}Building webassembly binary in $SRC...${normal}" + echo "Building webassembly binary in $SRC..." cd "$PROJECT_ROOT/$SRC" chmod a+x build.sh diff --git a/buildspec.yml b/buildspec.yml index 3eb09d556..9e52eba21 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -6,7 +6,7 @@ phases: - echo Logging in to Amazon ECR... - aws --version - $(aws ecr get-login --region eu-central-1 --no-include-email) - - REPOSITORY_URI=348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/substrate-poc + - REPOSITORY_URI=348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/prototype-chain - 'IMAGE_TAG=$(sed -n ''s/version = "\(.*\)"$/\1/p'' Cargo.toml)' - docker pull $REPOSITORY_URI:latest || true build: @@ -22,6 +22,6 @@ phases: - docker push $REPOSITORY_URI:latest - docker push $REPOSITORY_URI:$IMAGE_TAG - echo Writing image definitions file... - - printf '[{"name":"substrate-poc","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json + - printf '[{"name":"prototype-bootnode","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json artifacts: files: imagedefinitions.json diff --git a/src/chain_spec.rs b/src/chain_spec.rs index 2e6815c0b..fe6c7bf3a 100644 --- a/src/chain_spec.rs +++ b/src/chain_spec.rs @@ -16,7 +16,7 @@ pub enum Alternative { /// Whatever the current runtime is, with just Alice as an auth. Development, /// Whatever the current runtime is, with simple Alice/Bob auths. - LocalTestnet, + KiltTestnet, } impl Alternative { @@ -39,9 +39,9 @@ impl Alternative { None, None ), - Alternative::LocalTestnet => ChainSpec::from_genesis( - "Local Testnet", - "local_testnet", + Alternative::KiltTestnet => ChainSpec::from_genesis( + "KILT Testnet", + "kilt_testnet", || testnet_genesis(vec![ ed25519::Pair::from_seed(b"Alice ").public().into(), ed25519::Pair::from_seed(b"Bob ").public().into(), @@ -67,7 +67,7 @@ impl Alternative { pub(crate) fn from(s: &str) -> Option { match s { "dev" => Some(Alternative::Development), - "local" => Some(Alternative::LocalTestnet), + "kilt-testnet" => Some(Alternative::KiltTestnet), _ => None, } } diff --git a/start-node.sh b/start-node.sh new file mode 100755 index 000000000..edd509ba2 --- /dev/null +++ b/start-node.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +# start-node.sh - A script to start a node within the KILT test network + +##### Constants + +CHAIN_NAME="kilt-testnet" +ALICE_BOOT_NODE_KEY=0000000000000000000000000000000000000000000000000000000000000001 +ALICE_BOOT_NODE_KEY_HASH=QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN +BOB_BOOT_NODE_KEY=0000000000000000000000000000000000000000000000000000000000000002 +BOB_BOOT_NODE_KEY_HASH=QmXiB3jqqn2rpiKU7k1h7NJYeBg8WNSx9DiTRKz9ti2KSK +TELEMETRY_URL=ws://telemetry-backend.kilt-prototype.tk:1024 + +##### Functions + +lookup_boot_node() { + boot_node_domain="bootnode-${bootnode}.kilt-prototype.tk" + echo "Performing lookup for boot node ${boot_node_domain}" + if [[ "$bootnode" = "Alice" ]]; then + alice_boot_node_ip=`dig ${boot_node_domain} A +short` + boot_node_ipfs=/ip4/${alice_boot_node_ip}/tcp/30333/p2p/${ALICE_BOOT_NODE_KEY_HASH} + elif [[ "$bootnode" = "Bob" ]]; then + bob_boot_node_ip=`dig ${boot_node_domain} A +short` + boot_node_ipfs=/ip4/${bob_boot_node_ip}/tcp/30333/p2p/${BOB_BOOT_NODE_KEY_HASH} + fi +} + + + +usage() +{ +cat < [...] + + If you want to start a boot node, just use "Alice" or "Bob" as account name. + + -a, --account-name ACCOUNT_NAME The name of the account to start the node with (Alice | Bob | Charly | Dave | Eve | Ferdie). + -n, --node-name NODE_NAME The arbitrary name of the node (e.g. "charly-node-1234") + -c, --connect-to BOOT_NODE_NAME The name of the boot node to connect to ("alice" | "bob") + -d, --dry-run Flag indicating to only show the resulting command instead of executing it + -t, --telemetry Flag indicating whether or not to send data to the telemetry server + + Examples: + + Start Alice (boot node): + ./start-node.sh -a Alice + + Start Bob (boot node) that connects to Alice: + ./start-node.sh -a Bob -c Alice + + Start Charly (normal node) that connects to Alice: + ./start-node.sh -a Charly -c Alice -n charly-node-123 +HELP_USAGE +} + +##### Main + + +bootnode= +node_name= +account_name= +telemetry=0 +dry_run=0 + +while [[ "$1" != "" ]]; do + case $1 in + -a | --account-name ) shift + account_name=$1 + ;; + -n | --node-name ) shift + node_name=$1 + ;; + -c | --connect-to ) shift + bootnode=$1 + ;; + -t | --telemetry ) telemetry=1 + ;; + -d | --dry-run ) dry_run=1 + ;; + -h | --help ) usage + exit + ;; + * ) usage + exit 1 + esac + shift +done + + +arg_boot_node_connect= +arg_node_key= +arg_node_name= +arg_telemetry= +arg_account_name= + +if [[ -z "$account_name" ]]; then + usage + exit 1 +fi + +if [[ "$account_name" = "Alice" ]]; then + arg_node_key=" --node-key ${ALICE_BOOT_NODE_KEY}" +elif [[ "$account_name" = "Bob" ]]; then + arg_node_key=" --node-key ${BOB_BOOT_NODE_KEY}" +fi +arg_account_name=" --key ${account_name}" + +echo "Starting KILT node with account '${account_name}'" +if [[ ! -z "$bootnode" ]]; then + echo "Trying to connect to boot node '$bootnode'..." + lookup_boot_node + if [[ -z "$boot_node_ipfs" ]]; then + echo "Boot node address lookup failed for boot node named '$bootnode'" + exit 1 + else + echo "Boot-node IPFS location: $boot_node_ipfs" + arg_boot_node_connect=" --bootnodes ${boot_node_ipfs}" + fi +fi + +if [[ ! -z "$node_name" ]]; then + random_suffix=`cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 5` + node_name="${node_name}-${random_suffix}" + arg_node_name=" --name ${node_name}" +fi + +if [[ "$telemetry" = "1" ]]; then + arg_telemetry=" --telemetry-url ${TELEMETRY_URL}" +fi + +command="./target/debug/node --chain ${CHAIN_NAME} --validator --port 30333 --ws-port 9944 --ws-external --rpc-external${arg_account_name}${arg_node_key}${arg_boot_node_connect}${arg_node_name}${arg_telemetry}" + +if [[ "$dry_run" = "1" ]]; then + echo "Dry run." + echo "Command: $command" + exit 0 +fi + +echo "Running: $command" +`${command}` \ No newline at end of file