From 06040d14e21b228178070d16ea704dd3ccf2fb69 Mon Sep 17 00:00:00 2001 From: Alfonso de la Rocha Date: Mon, 28 Aug 2023 10:55:43 +0200 Subject: [PATCH 01/40] wip: first few strokes --- fendermint/infra/Cargo.toml | 11 ++ fendermint/infra/Makefile.toml | 263 +++++++++++++++++++++++++++++++ fendermint/infra/scripts/init.sh | 70 ++++++++ fendermint/infra/src/lib.rs | 12 ++ 4 files changed, 356 insertions(+) create mode 100644 fendermint/infra/Cargo.toml create mode 100644 fendermint/infra/Makefile.toml create mode 100755 fendermint/infra/scripts/init.sh create mode 100644 fendermint/infra/src/lib.rs diff --git a/fendermint/infra/Cargo.toml b/fendermint/infra/Cargo.toml new file mode 100644 index 00000000..5f80a05d --- /dev/null +++ b/fendermint/infra/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "fendermint_infra" +description = "Workflows for the deployment of Fendermint infrastructure" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/fendermint/infra/Makefile.toml b/fendermint/infra/Makefile.toml new file mode 100644 index 00000000..acede2c1 --- /dev/null +++ b/fendermint/infra/Makefile.toml @@ -0,0 +1,263 @@ +[env] +NETWORK_NAME = "smoke" +CMT_CONTAINER_NAME = "smoke-cometbft" +FM_CONTAINER_NAME = "smoke-fendermint" +ETHAPI_CONTAINER_NAME = "smoke-ethapi" +CMT_DOCKER_IMAGE = "cometbft/cometbft:v0.37.x" +FM_DOCKER_IMAGE = "fendermint:latest" +TEST_DATA_DIR = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/fendermint/testing/smoke-test/test-data" +TEST_SCRIPTS_DIR = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/fendermint/testing/smoke-test/scripts" +ACTORS_BUNDLE = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/../builtin-actors/output/bundle.car" +CMT_HOST_PORT = 26657 +ETHAPI_HOST_PORT = 8545 +# If this wasn't present, any wait task is skipped. +CARGO_MAKE_WAIT_MILLISECONDS = 5000 +# This wait time seems to work locally. +CMT_WAIT_MILLIS = 10000 +# Keep example logs to a minimum. +VERBOSITY = "" + +[env.ci] +CMT_WAIT_MILLIS = 20000 +# Help debug any issues with simplecoin by logging requests and responses. +VERBOSITY = "--verbose" + +# infrastructure workflows: +# cargo install cargo-make +# +# cd fendermint/testing/smoke-test +# - then - +# cargo make --profile ci +# - or - +# cargo make setup +# cargo make test +# docker logs smoke-ethapi +# cargo make teardown + +[tasks.default] +clear = true +run_task = { name = [ + "setup", + "test", +], fork = true, cleanup_task = "teardown" } + +# Waiting before starting the Eth API for the CometBFT websocket to start listening. +[tasks.setup] +dependencies = [ + "test-data-dir", + "network-create", + "cometbft-init", + "fendermint-deps", + "fendermint-init", + "fendermint-start", + "cometbft-start", + "cometbft-wait", + "ethapi-start", + "fendermint-logs", + "cometbft-logs", + "ethapi-logs", +] + +[tasks.test] +clear = true +dependencies = ["simplecoin-example", "ethapi-example"] + +[tasks.teardown] +# `dependencies` doesn't seem to work with `cleanup_task`. +run_task = { name = [ + "cometbft-stop", + "cometbft-rm", + "fendermint-stop", + "fendermint-rm", + "ethapi-stop", + "ethapi-rm", + "network-rm", + "test-data-dir-rm", +] } + + +[tasks.simplecoin-example] +# Using --release in the hope that it can reuse artifacts compiled earlier for the docker build. +script = """ +cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} +cargo run -p fendermint_rpc --release --example simplecoin -- \ + --secret-key fendermint/testing/smoke-test/test-data/fendermint/keys/alice.sk \ + ${VERBOSITY} +""" + + +[tasks.ethapi-example] +script = """ +cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} +cargo run -p fendermint_eth_api --release --example ethers -- \ + --secret-key-from fendermint/testing/smoke-test/test-data/fendermint/keys/emily.sk \ + --secret-key-to fendermint/testing/smoke-test/test-data/fendermint/keys/eric.sk +""" + + +[tasks.test-data-dir] +script = """ +mkdir -p ${TEST_DATA_DIR}/fendermint; +mkdir -p ${TEST_DATA_DIR}/cometbft; +""" + +[tasks.test-data-dir-rm] +script = """ +rm -rf ${TEST_DATA_DIR} +""" + + +[tasks.cometbft-pull] +command = "docker" +args = ["pull", "${CMT_DOCKER_IMAGE}"] + +[tasks.cometbft-init] +extend = "cometbft-run" +env = { "CMD" = "init", "FLAGS" = "-a STDOUT -a STDERR --rm" } + +[tasks.cometbft-start] +extend = "cometbft-run" +env = { "CMD" = "start", "FLAGS" = "-d" } + +[tasks.cometbft-wait] +extend = "wait" +env = { "CARGO_MAKE_WAIT_MILLISECONDS" = "${CMT_WAIT_MILLIS}" } + +[tasks.cometbft-run] +script = """ +docker run \ + ${FLAGS} \ + --name ${CMT_CONTAINER_NAME} \ + --user $(id -u) \ + --network ${NETWORK_NAME} \ + --publish 26657:${CMT_HOST_PORT} \ + --volume ${TEST_DATA_DIR}/cometbft:/cometbft \ + --env CMT_PROXY_APP=tcp://${FM_CONTAINER_NAME}:26658 \ + --env CMT_PEX=false \ + ${CMT_DOCKER_IMAGE} \ + ${CMD} +""" +dependencies = ["cometbft-pull", "test-data-dir", "network-create"] + +[tasks.fendermint-deps] +script = """ +# Check if the image exists +# TODO: Check the version or use a flag to always re-build? +if docker images | awk '{print $1":"$2}' | grep fendermint; then + echo fendermint image already exists + docker images | grep fendermint +else + cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} + make docker-build +fi +""" + +[tasks.fendermint-init] +extend = "fendermint-run" +env = { "ENTRY" = "/scripts/init.sh", "FLAGS" = "-a STDOUT -a STDERR --rm" } + +[tasks.fendermint-start] +extend = "fendermint-run" +env = { "ENTRY" = "fendermint", "CMD" = "run", "FLAGS" = "-d" } + +[tasks.fendermint-run] +script = """ +docker run \ + ${FLAGS} \ + --name ${FM_CONTAINER_NAME} \ + --init \ + --user $(id -u) \ + --network ${NETWORK_NAME} \ + --volume ${TEST_DATA_DIR}:/data \ + --volume ${TEST_SCRIPTS_DIR}:/scripts \ + --env FM_DATA_DIR=/data/fendermint/data \ + --env FM_CHAIN_NAME=${NETWORK_NAME} \ + --env LOG_LEVEL=info \ + --entrypoint ${ENTRY} \ + ${FM_DOCKER_IMAGE} \ + ${CMD} +""" +dependencies = ["test-data-dir", "network-create", "fendermint-deps"] + +[tasks.ethapi-start] +extend = "ethapi-run" +env = { "CMD" = "eth run", "FLAGS" = "-d" } + + +[tasks.ethapi-run] +script = """ +docker run \ + ${FLAGS} \ + --name ${ETHAPI_CONTAINER_NAME} \ + --init \ + --user $(id -u) \ + --network ${NETWORK_NAME} \ + --publish 8545:${ETHAPI_HOST_PORT} \ + --env TENDERMINT_WS_URL=ws://${CMT_CONTAINER_NAME}:26657/websocket \ + --env LOG_LEVEL=debug \ + --env RUST_BACKTRACE=1 \ + ${FM_DOCKER_IMAGE} \ + ${CMD} +""" +dependencies = ["network-create"] + +[tasks.network-create] +command = "docker" +args = ["network", "create", "${NETWORK_NAME}"] +ignore_errors = true + +[tasks.network-rm] +command = "docker" +args = ["network", "rm", "${NETWORK_NAME}"] +ignore_errors = true + +[tasks.cometbft-rm] +extend = "docker-rm" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.cometbft-stop] +extend = "docker-stop" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.fendermint-rm] +extend = "docker-rm" +env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } + +[tasks.fendermint-stop] +extend = "docker-stop" +env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } + +[tasks.ethapi-rm] +extend = "docker-rm" +env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } + +[tasks.ethapi-stop] +extend = "docker-stop" +env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } + +[tasks.ethapi-logs] +extend = "docker-logs" +env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } + +[tasks.fendermint-logs] +extend = "docker-logs" +env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } + +[tasks.cometbft-logs] +extend = "docker-logs" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.docker-stop] +command = "docker" +args = ["stop", "${CONTAINER_NAME}"] +ignore_errors = true + +[tasks.docker-rm] +command = "docker" +args = ["rm", "--force", "${CONTAINER_NAME}"] +ignore_errors = true + +[tasks.docker-logs] +command = "docker" +args = ["logs", "${CONTAINER_NAME}"] +ignore_errors = true diff --git a/fendermint/infra/scripts/init.sh b/fendermint/infra/scripts/init.sh new file mode 100755 index 00000000..584541a6 --- /dev/null +++ b/fendermint/infra/scripts/init.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +set -e + +# Create test artifacts, which is basically the Tendermint genesis file. + +CMT_DIR=/data/cometbft +FM_DIR=/data/fendermint + +KEYS_DIR=$FM_DIR/keys +GENESIS_FILE=$FM_DIR/genesis.json + +# Create a genesis file +fendermint genesis --genesis-file $GENESIS_FILE new --chain-name $FM_CHAIN_NAME --base-fee 1000 --timestamp 1680101412 + +# Create test keys +mkdir -p $KEYS_DIR +for NAME in alice bob charlie dave; do + fendermint key gen --out-dir $KEYS_DIR --name $NAME; +done + +# Create an account +fendermint \ + genesis --genesis-file $GENESIS_FILE \ + add-account --public-key $KEYS_DIR/alice.pk \ + --balance 1000 + +# Create a multisig account +fendermint \ + genesis --genesis-file $GENESIS_FILE \ + add-multisig --public-key $KEYS_DIR/bob.pk \ + --public-key $KEYS_DIR/charlie.pk \ + --public-key $KEYS_DIR/dave.pk \ + --threshold 2 --vesting-start 0 --vesting-duration 1000000 \ + --balance 3000 + +# Create some Ethereum accounts +for NAME in emily eric; do + fendermint key gen --out-dir $KEYS_DIR --name $NAME; + fendermint \ + genesis --genesis-file $GENESIS_FILE \ + add-account --public-key $KEYS_DIR/$NAME.pk \ + --balance 1000 \ + --kind ethereum +done + +# Add a validator +fendermint \ + genesis --genesis-file $GENESIS_FILE \ + add-validator --public-key $KEYS_DIR/bob.pk --power 1 + +# Enable IPC with some dummy values to test contract deployment. +fendermint \ + genesis --genesis-file $GENESIS_FILE \ + ipc gateway \ + --subnet-id /r0 \ + --top-down-check-period 10 \ + --bottom-up-check-period 10 \ + --msg-fee 10 \ + --majority-percentage 66 + +# Convert FM genesis to CMT +fendermint \ + genesis --genesis-file $GENESIS_FILE \ + into-tendermint --out $CMT_DIR/config/genesis.json + +# Convert FM validator key to CMT +fendermint \ + key into-tendermint --secret-key $KEYS_DIR/bob.sk \ + --out $CMT_DIR/config/priv_validator_key.json diff --git a/fendermint/infra/src/lib.rs b/fendermint/infra/src/lib.rs new file mode 100644 index 00000000..655b20f7 --- /dev/null +++ b/fendermint/infra/src/lib.rs @@ -0,0 +1,12 @@ +// Copyright 2022-2023 Protocol Labs +// SPDX-License-Identifier: Apache-2.0, MIT +//! Run some tests against a pair of Fendermint and Tendermint docker containers running locally. +//! +//! Example: +//! +//! ```text +//! cd fendermint/testing/smoke-test +//! cargo make +//! ``` +//! +//! Make sure you installed cargo-make by running `cargo install cargo-make` first. From 44d0db1d472fe8b42d9e7307d2dc4f82d734d031 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Mon, 4 Sep 2023 16:18:09 +0200 Subject: [PATCH 02/40] Update makefile --- fendermint/infra/Makefile.toml | 197 +++++++++++++++++++++++++++------ 1 file changed, 164 insertions(+), 33 deletions(-) diff --git a/fendermint/infra/Makefile.toml b/fendermint/infra/Makefile.toml index acede2c1..a62a2d9b 100644 --- a/fendermint/infra/Makefile.toml +++ b/fendermint/infra/Makefile.toml @@ -1,8 +1,24 @@ [env] -NETWORK_NAME = "smoke" -CMT_CONTAINER_NAME = "smoke-cometbft" -FM_CONTAINER_NAME = "smoke-fendermint" -ETHAPI_CONTAINER_NAME = "smoke-ethapi" +CHAIN_NAME = { value = "root", condition = { env_not_set = ["CHAIN_NAME"] }} +BALANCE = { value = "1000", condition = { env_not_set = ["BALANCE"] }} +BASE_FEE = { value = "1000", condition = { env_not_set = ["BASE_FEE"] }} +TIMESTAMP = { value = "1680101412", condition = { env_not_set = ["TIMESTAMP"] }} + +BASE_DIR="${HOME}" +FM_DIR="${BASE_DIR}/.fendermint" +CMT_DIR="${BASE_DIR}/.cometbft" + +GENESIS_FILE="${FM_DIR}/genesis.json" +KEYS_DIR="${FM_DIR}/keys" +KEY_NAME="validator_key" +PUB_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.pk" +PRIV_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.sk" + +NETWORK_NAME = "${CHAIN_NAME}-network" +CMT_CONTAINER_NAME = "${CHAIN_NAME}-cometbft" +FM_CONTAINER_NAME = "${CHAIN_NAME}-fendermint" +ETHAPI_CONTAINER_NAME = "${CHAIN_NAME}-ethapi" + CMT_DOCKER_IMAGE = "cometbft/cometbft:v0.37.x" FM_DOCKER_IMAGE = "fendermint:latest" TEST_DATA_DIR = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/fendermint/testing/smoke-test/test-data" @@ -34,15 +50,137 @@ VERBOSITY = "--verbose" # docker logs smoke-ethapi # cargo make teardown +[tasks.info] +script=""" +echo +echo Chain: +echo - Chain: ${CHAIN_NAME} +echo - Balance: ${BALANCE} +echo - Base Fee: ${BASE_FEE} +echo - Timestamp: ${TIMESTAMP} +echo +echo Directories and files: +echo - Home directory: ${BASE_DIR} +echo - Keys directory: ${KEYS_DIR} +echo - Genesis file: ${GENESIS_FILE} +echo - CometBFT directory: ${CMT_DIR} +echo - Fendermint directory: ${FM_DIR} +echo +echo Docker: +echo - Network: ${NETWORK_NAME} +echo - CometBFT container: ${CMT_CONTAINER_NAME} +echo - Fendermint container: ${FM_CONTAINER_NAME} +echo +""" + +[tasks.init] +dependencies = [ + "clear", + "createbasedir", + "newgenesis", + "newkey", + "newaccount", + "newgateway" +] + +[tasks.clear] +script=""" +echo clearing all data in: $FM_DIR $CMT_DIR +rm -rf ${FM_DIR} +rm -rf ${CMT_DIR} +""" + +[tasks.createbasedir] +script=""" +echo creating directories: $FM_DIR $CMT_DIR +mkdir -p $FM_DIR +mkdir -p $CMT_DIR +mkdir -p $CMT_DIR/data +mkdir -p $CMT_DIR/config +""" + +[tasks.newkey] +cwd = "./target/release" +script=""" +mkdir -p $KEYS_DIR +./fendermint key gen --out-dir $KEYS_DIR --name $KEY_NAME; +chmod 600 ${PRIV_KEY_PATH} +""" + +[tasks.newaccount] +cwd = "./target/release" +script=""" +./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} +""" + +[tasks.newgenesis] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} +""" +dependencies = [ + "createbasedir", +] + +[tasks.newgateway] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} add-validator --public-key ${PUB_KEY_PATH} --power 1 + +./fendermint genesis --genesis-file ${GENESIS_FILE} ipc gateway --subnet-id /r0 \ + --top-down-check-period 10 \ + --bottom-up-check-period 10 \ + --msg-fee 10 \ + --majority-percentage 66 + +./fendermint genesis --genesis-file ${GENESIS_FILE} into-tendermint --out ${CMT_DIR}/config/genesis.json + +./fendermint key into-tendermint --secret-key ${PRIV_KEY_PATH} --out ${CMT_DIR}/data/priv_validator_key.json + +chmod 600 ${CMT_DIR}/data/priv_validator_key.json +""" + [tasks.default] clear = true -run_task = { name = [ - "setup", - "test", -], fork = true, cleanup_task = "teardown" } +script_runner = "@duckscript" +script = [''' + echo + echo Main tasks: + echo - clear: Clear all information: private keys, cache, database, etc. + echo - init: Initialize the system + echo - info: Print the setup information + echo - start: Starts Fendermint/CometBFT docker containers with the genesis + echo - teardown: Stops the system and clears all data + echo - run: Inits and then starts the system + echo + echo Most tasks use these environment variables: + echo - CHAIN_NAME (default '${CHAIN_NAME}'): the target IPC subnet + echo + echo Run 'cargo make -e CHAIN_NAME=chain -e BALANCE=100 -e BASE_FEE=200 ... COMMAND' to populate the variables from CLI or + echo Run 'cargo make --env-file=/PATH/.env COMMAND' to populate the variables from the file before running the command. + echo + echo Run 'cargo make --list-all-steps' for a complete list of available tasks. + echo +'''] + # Waiting before starting the Eth API for the CometBFT websocket to start listening. -[tasks.setup] +[tasks.start] +dependencies = [ + "network-create", + "cometbft-init", + "fendermint-deps", + "fendermint-start", + "cometbft-start", +] + +[tasks.run] +dependencies = [ + "init", + "start", +] + +[tasks.setupold] dependencies = [ "test-data-dir", "network-create", @@ -72,7 +210,7 @@ run_task = { name = [ "ethapi-stop", "ethapi-rm", "network-rm", - "test-data-dir-rm", + "clear", ] } @@ -95,12 +233,6 @@ cargo run -p fendermint_eth_api --release --example ethers -- \ """ -[tasks.test-data-dir] -script = """ -mkdir -p ${TEST_DATA_DIR}/fendermint; -mkdir -p ${TEST_DATA_DIR}/cometbft; -""" - [tasks.test-data-dir-rm] script = """ rm -rf ${TEST_DATA_DIR} @@ -131,13 +263,25 @@ docker run \ --user $(id -u) \ --network ${NETWORK_NAME} \ --publish 26657:${CMT_HOST_PORT} \ - --volume ${TEST_DATA_DIR}/cometbft:/cometbft \ + --volume ${CMT_DIR}:/cometbft \ --env CMT_PROXY_APP=tcp://${FM_CONTAINER_NAME}:26658 \ --env CMT_PEX=false \ ${CMT_DOCKER_IMAGE} \ ${CMD} """ -dependencies = ["cometbft-pull", "test-data-dir", "network-create"] +dependencies = ["cometbft-pull", "createbasedir", "network-create"] + +[tasks.cometbft-rm] +extend = "docker-rm" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.cometbft-stop] +extend = "docker-stop" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.cometbft-logs] +extend = "docker-logs" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } [tasks.fendermint-deps] script = """ @@ -168,8 +312,7 @@ docker run \ --init \ --user $(id -u) \ --network ${NETWORK_NAME} \ - --volume ${TEST_DATA_DIR}:/data \ - --volume ${TEST_SCRIPTS_DIR}:/scripts \ + --volume ${FM_DIR}/data:/data \ --env FM_DATA_DIR=/data/fendermint/data \ --env FM_CHAIN_NAME=${NETWORK_NAME} \ --env LOG_LEVEL=info \ @@ -177,7 +320,7 @@ docker run \ ${FM_DOCKER_IMAGE} \ ${CMD} """ -dependencies = ["test-data-dir", "network-create", "fendermint-deps"] +dependencies = ["createbasedir", "network-create", "fendermint-deps"] [tasks.ethapi-start] extend = "ethapi-run" @@ -211,14 +354,6 @@ command = "docker" args = ["network", "rm", "${NETWORK_NAME}"] ignore_errors = true -[tasks.cometbft-rm] -extend = "docker-rm" -env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } - -[tasks.cometbft-stop] -extend = "docker-stop" -env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } - [tasks.fendermint-rm] extend = "docker-rm" env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } @@ -243,10 +378,6 @@ env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } extend = "docker-logs" env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } -[tasks.cometbft-logs] -extend = "docker-logs" -env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } - [tasks.docker-stop] command = "docker" args = ["stop", "${CONTAINER_NAME}"] From 67f74ea8cf378224e98386af656d8c5639e5b8cc Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Mon, 4 Sep 2023 16:42:22 +0200 Subject: [PATCH 03/40] update --- fendermint/infra/Makefile.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fendermint/infra/Makefile.toml b/fendermint/infra/Makefile.toml index a62a2d9b..70504061 100644 --- a/fendermint/infra/Makefile.toml +++ b/fendermint/infra/Makefile.toml @@ -5,8 +5,8 @@ BASE_FEE = { value = "1000", condition = { env_not_set = ["BASE_FEE"] }} TIMESTAMP = { value = "1680101412", condition = { env_not_set = ["TIMESTAMP"] }} BASE_DIR="${HOME}" -FM_DIR="${BASE_DIR}/.fendermint" -CMT_DIR="${BASE_DIR}/.cometbft" +FM_DIR="${BASE_DIR}/.fendermint/${CHAIN_NAME}" +CMT_DIR="${BASE_DIR}/.cometbft/${CHAIN_NAME}" GENESIS_FILE="${FM_DIR}/genesis.json" KEYS_DIR="${FM_DIR}/keys" @@ -65,6 +65,7 @@ echo - Keys directory: ${KEYS_DIR} echo - Genesis file: ${GENESIS_FILE} echo - CometBFT directory: ${CMT_DIR} echo - Fendermint directory: ${FM_DIR} +echo - Private key: ${PRIV_KEY_PATH} echo echo Docker: echo - Network: ${NETWORK_NAME} @@ -94,6 +95,7 @@ rm -rf ${CMT_DIR} script=""" echo creating directories: $FM_DIR $CMT_DIR mkdir -p $FM_DIR + mkdir -p $CMT_DIR mkdir -p $CMT_DIR/data mkdir -p $CMT_DIR/config From a0cad1c95f34f7d4e8d3655f0a40f0b582739267 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Mon, 4 Sep 2023 21:59:00 +0200 Subject: [PATCH 04/40] fix misprints --- fendermint/infra/Makefile.toml | 158 ++++++++++++++------------------- 1 file changed, 69 insertions(+), 89 deletions(-) diff --git a/fendermint/infra/Makefile.toml b/fendermint/infra/Makefile.toml index 70504061..32dc3657 100644 --- a/fendermint/infra/Makefile.toml +++ b/fendermint/infra/Makefile.toml @@ -4,9 +4,9 @@ BALANCE = { value = "1000", condition = { env_not_set = ["BALANCE"] }} BASE_FEE = { value = "1000", condition = { env_not_set = ["BASE_FEE"] }} TIMESTAMP = { value = "1680101412", condition = { env_not_set = ["TIMESTAMP"] }} -BASE_DIR="${HOME}" -FM_DIR="${BASE_DIR}/.fendermint/${CHAIN_NAME}" -CMT_DIR="${BASE_DIR}/.cometbft/${CHAIN_NAME}" +BASE_DIR="${HOME}/.ipc/${CHAIN_NAME}" +FM_DIR="${BASE_DIR}/fendermint" +CMT_DIR="${BASE_DIR}/cometbft" GENESIS_FILE="${FM_DIR}/genesis.json" KEYS_DIR="${FM_DIR}/keys" @@ -14,10 +14,10 @@ KEY_NAME="validator_key" PUB_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.pk" PRIV_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.sk" -NETWORK_NAME = "${CHAIN_NAME}-network" -CMT_CONTAINER_NAME = "${CHAIN_NAME}-cometbft" -FM_CONTAINER_NAME = "${CHAIN_NAME}-fendermint" -ETHAPI_CONTAINER_NAME = "${CHAIN_NAME}-ethapi" +NETWORK_NAME = "${CHAIN_NAME}net" +CMT_CONTAINER_NAME = "${NETWORK_NAME}-cometbft" +FM_CONTAINER_NAME = "${NETWORK_NAME}-fendermint" +ETHAPI_CONTAINER_NAME = "${NETWORK_NAME}-ethapi" CMT_DOCKER_IMAGE = "cometbft/cometbft:v0.37.x" FM_DOCKER_IMAGE = "fendermint:latest" @@ -53,21 +53,21 @@ VERBOSITY = "--verbose" [tasks.info] script=""" echo -echo Chain: +echo Chain info: echo - Chain: ${CHAIN_NAME} echo - Balance: ${BALANCE} echo - Base Fee: ${BASE_FEE} echo - Timestamp: ${TIMESTAMP} echo echo Directories and files: -echo - Home directory: ${BASE_DIR} -echo - Keys directory: ${KEYS_DIR} -echo - Genesis file: ${GENESIS_FILE} +echo - IPC directory: ${BASE_DIR} echo - CometBFT directory: ${CMT_DIR} echo - Fendermint directory: ${FM_DIR} +echo - Keys directory: ${KEYS_DIR} +echo - Genesis file: ${GENESIS_FILE} echo - Private key: ${PRIV_KEY_PATH} echo -echo Docker: +echo Docker info: echo - Network: ${NETWORK_NAME} echo - CometBFT container: ${CMT_CONTAINER_NAME} echo - Fendermint container: ${FM_CONTAINER_NAME} @@ -78,68 +78,21 @@ echo dependencies = [ "clear", "createbasedir", - "newgenesis", - "newkey", - "newaccount", - "newgateway" ] [tasks.clear] script=""" -echo clearing all data in: $FM_DIR $CMT_DIR -rm -rf ${FM_DIR} -rm -rf ${CMT_DIR} +echo clearing all IPC data +rm -rf ${BASE_DIR} """ [tasks.createbasedir] script=""" -echo creating directories: $FM_DIR $CMT_DIR +echo creating directories: $BASE_DIR $FM_DIR $CMT_DIR +mkdir -p $BASE_DIR mkdir -p $FM_DIR mkdir -p $CMT_DIR -mkdir -p $CMT_DIR/data -mkdir -p $CMT_DIR/config -""" - -[tasks.newkey] -cwd = "./target/release" -script=""" -mkdir -p $KEYS_DIR -./fendermint key gen --out-dir $KEYS_DIR --name $KEY_NAME; -chmod 600 ${PRIV_KEY_PATH} -""" - -[tasks.newaccount] -cwd = "./target/release" -script=""" -./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} -""" - -[tasks.newgenesis] -cwd = "./target/release" -script = """ -./fendermint genesis --genesis-file ${GENESIS_FILE} new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} -""" -dependencies = [ - "createbasedir", -] - -[tasks.newgateway] -cwd = "./target/release" -script = """ -./fendermint genesis --genesis-file ${GENESIS_FILE} add-validator --public-key ${PUB_KEY_PATH} --power 1 - -./fendermint genesis --genesis-file ${GENESIS_FILE} ipc gateway --subnet-id /r0 \ - --top-down-check-period 10 \ - --bottom-up-check-period 10 \ - --msg-fee 10 \ - --majority-percentage 66 - -./fendermint genesis --genesis-file ${GENESIS_FILE} into-tendermint --out ${CMT_DIR}/config/genesis.json - -./fendermint key into-tendermint --secret-key ${PRIV_KEY_PATH} --out ${CMT_DIR}/data/priv_validator_key.json - -chmod 600 ${CMT_DIR}/data/priv_validator_key.json """ [tasks.default] @@ -151,9 +104,9 @@ script = [''' echo - clear: Clear all information: private keys, cache, database, etc. echo - init: Initialize the system echo - info: Print the setup information - echo - start: Starts Fendermint/CometBFT docker containers with the genesis - echo - teardown: Stops the system and clears all data - echo - run: Inits and then starts the system + echo - start: Start Fendermint/CometBFT docker containers with the genesis + echo - teardown: Stop the system and clears all data + echo - run: Init and then start the system echo echo Most tasks use these environment variables: echo - CHAIN_NAME (default '${CHAIN_NAME}'): the target IPC subnet @@ -168,23 +121,8 @@ script = [''' # Waiting before starting the Eth API for the CometBFT websocket to start listening. [tasks.start] -dependencies = [ - "network-create", - "cometbft-init", - "fendermint-deps", - "fendermint-start", - "cometbft-start", -] - -[tasks.run] dependencies = [ "init", - "start", -] - -[tasks.setupold] -dependencies = [ - "test-data-dir", "network-create", "cometbft-init", "fendermint-deps", @@ -192,10 +130,7 @@ dependencies = [ "fendermint-start", "cometbft-start", "cometbft-wait", - "ethapi-start", - "fendermint-logs", - "cometbft-logs", - "ethapi-logs", + "ethapi-start" ] [tasks.test] @@ -299,8 +234,53 @@ fi """ [tasks.fendermint-init] -extend = "fendermint-run" -env = { "ENTRY" = "/scripts/init.sh", "FLAGS" = "-a STDOUT -a STDERR --rm" } +dependencies = [ + "fendermint-newgenesis", + "fendermint-newkey", + "fendermint-newaccount", + "fendermint-newgateway" +] + +[tasks.fendermint-newkey] +cwd = "./target/release" +script=""" +mkdir -p $KEYS_DIR + +./fendermint key gen --out-dir $KEYS_DIR --name $KEY_NAME; +chmod 600 ${PRIV_KEY_PATH} +""" + +[tasks.fendermint-newaccount] +cwd = "./target/release" +script=""" +./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} +""" + +[tasks.fendermint-newgenesis] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} +""" +dependencies = [ + "createbasedir", +] + +[tasks.fendermint-newgateway] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} add-validator --public-key ${PUB_KEY_PATH} --power 1 + +./fendermint genesis --genesis-file ${GENESIS_FILE} ipc gateway --subnet-id /r0 \ + --top-down-check-period 10 \ + --bottom-up-check-period 10 \ + --msg-fee 10 \ + --majority-percentage 66 + +./fendermint genesis --genesis-file ${GENESIS_FILE} into-tendermint --out ${CMT_DIR}/config/genesis.json + +./fendermint key into-tendermint --secret-key ${PRIV_KEY_PATH} --out ${CMT_DIR}/config/priv_validator_key.json +chmod 600 ${CMT_DIR}/config/priv_validator_key.json +""" [tasks.fendermint-start] extend = "fendermint-run" @@ -314,7 +294,7 @@ docker run \ --init \ --user $(id -u) \ --network ${NETWORK_NAME} \ - --volume ${FM_DIR}/data:/data \ + --volume ${BASE_DIR}:/data \ --env FM_DATA_DIR=/data/fendermint/data \ --env FM_CHAIN_NAME=${NETWORK_NAME} \ --env LOG_LEVEL=info \ @@ -349,7 +329,7 @@ dependencies = ["network-create"] [tasks.network-create] command = "docker" args = ["network", "create", "${NETWORK_NAME}"] -ignore_errors = true +ignore_errors = false [tasks.network-rm] command = "docker" From d81a940ce2f232192fae1a7048917347ee497f1c Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 5 Sep 2023 14:14:57 +0200 Subject: [PATCH 05/40] start working on testnet config --- fendermint/infra/Makefile.toml | 163 +++++++++++++++++++++++++++- fendermint/infra/docker-compose.yml | 134 +++++++++++++++++++++++ 2 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 fendermint/infra/docker-compose.yml diff --git a/fendermint/infra/Makefile.toml b/fendermint/infra/Makefile.toml index 32dc3657..fb05decc 100644 --- a/fendermint/infra/Makefile.toml +++ b/fendermint/infra/Makefile.toml @@ -5,6 +5,8 @@ BASE_FEE = { value = "1000", condition = { env_not_set = ["BASE_FEE"] }} TIMESTAMP = { value = "1680101412", condition = { env_not_set = ["TIMESTAMP"] }} BASE_DIR="${HOME}/.ipc/${CHAIN_NAME}" +BASE_TESTNET_DIR="${HOME}/.ipc-testnet" + FM_DIR="${BASE_DIR}/fendermint" CMT_DIR="${BASE_DIR}/cometbft" @@ -118,7 +120,6 @@ script = [''' echo '''] - # Waiting before starting the Eth API for the CometBFT websocket to start listening. [tasks.start] dependencies = [ @@ -150,6 +151,69 @@ run_task = { name = [ "clear", ] } +[tasks.testnet-clear] +script=""" +echo clearing all IPC data +rm -rf ${BASE_TESTNET_DIR} +""" + +[tasks.testnet-mkdir] +script=""" +echo creating directories: $BASE_DIR $FM_DIR $CMT_DIR +mkdir -p $BASE_TESTNET_DIR +mkdir -p $BASE_TESTNET_DIR/out + +mkdir -p $BASE_TESTNET_DIR/node0 +mkdir -p $BASE_TESTNET_DIR/node1 +mkdir -p $BASE_TESTNET_DIR/node2 +mkdir -p $BASE_TESTNET_DIR/node3 + +mkdir -p $BASE_TESTNET_DIR/node0/fendermint +mkdir -p $BASE_TESTNET_DIR/node1/fendermint +mkdir -p $BASE_TESTNET_DIR/node2/fendermint +mkdir -p $BASE_TESTNET_DIR/node3/fendermint + +mkdir -p $BASE_TESTNET_DIR/node0/cometbft +mkdir -p $BASE_TESTNET_DIR/node1/cometbft +mkdir -p $BASE_TESTNET_DIR/node2/cometbft +mkdir -p $BASE_TESTNET_DIR/node3/cometbft + +mkdir -p $BASE_TESTNET_DIR/node0/cometbft/config +mkdir -p $BASE_TESTNET_DIR/node1/cometbft/config +mkdir -p $BASE_TESTNET_DIR/node2/cometbft/config +mkdir -p $BASE_TESTNET_DIR/node3/cometbft/config + +mkdir -p $BASE_TESTNET_DIR/node0/cometbft/data +mkdir -p $BASE_TESTNET_DIR/node1/cometbft/data +mkdir -p $BASE_TESTNET_DIR/node2/cometbft/data +mkdir -p $BASE_TESTNET_DIR/node3/cometbft/data + +""" + +[tasks.testnet-createbasedir] +dependencies = [ + "testnet-clear", + "testnet-mkdir", +] + +[tasks.testnet-up] +script = """ +docker compose -f ./fendermint/infra/docker-compose.yml up -d +""" + +[tasks.testnet-down] +script = """ +docker compose -f ./fendermint/infra/docker-compose.yml down +""" + +[tasks.testnet] +dependencies = [ + "testnet-down", + "testnet-createbasedir", + "testnet-init", + "fendermint-deps", + "testnet-up" +] [tasks.simplecoin-example] # Using --release in the hope that it can reuse artifacts compiled earlier for the docker build. @@ -233,14 +297,45 @@ else fi """ +[tasks.testnet-init] +dependencies = [ + "testnet-newgenesis", + "testnet-newkey", + "testnet-newaccount", + "testnet-newgateway", + "testnet-share-genesis" +] + [tasks.fendermint-init] dependencies = [ "fendermint-newgenesis", "fendermint-newkey", "fendermint-newaccount", - "fendermint-newgateway" + "fendermint-newgateway", ] +[tasks.testnet-newkey] +cwd = "./target/release" +script=""" +mkdir -p $BASE_TESTNET_DIR/node0/fendermint/keys +mkdir -p $BASE_TESTNET_DIR/node1/fendermint/keys +mkdir -p $BASE_TESTNET_DIR/node2/fendermint/keys +mkdir -p $BASE_TESTNET_DIR/node3/fendermint/keys + +./fendermint key gen --out-dir $BASE_TESTNET_DIR/node0/fendermint/keys --name validator0_key +./fendermint key gen --out-dir $BASE_TESTNET_DIR/node1/fendermint/keys --name validator1_key +./fendermint key gen --out-dir $BASE_TESTNET_DIR/node2/fendermint/keys --name validator2_key +./fendermint key gen --out-dir $BASE_TESTNET_DIR/node3/fendermint/keys --name validator3_key + +""" + +[tasks.testnet-newgenesis] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json \ + new --chain-name testnet --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} +""" + [tasks.fendermint-newkey] cwd = "./target/release" script=""" @@ -250,12 +345,75 @@ mkdir -p $KEYS_DIR chmod 600 ${PRIV_KEY_PATH} """ +[tasks.testnet-newaccount] +cwd = "./target/release" +script=""" +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.pk --balance ${BALANCE} + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.pk --balance ${BALANCE} + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.pk --balance ${BALANCE} + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.pk --balance ${BALANCE} +""" + +[tasks.testnet-newgateway] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ + --public-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.pk --power 1 + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ + --public-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.pk --power 1 + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ + --public-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.pk --power 1 + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ + --public-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.pk --power 1 + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json ipc gateway --subnet-id /r0 \ + --top-down-check-period 10 \ + --bottom-up-check-period 10 \ + --msg-fee 10 \ + --majority-percentage 66 + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json into-tendermint --out $BASE_TESTNET_DIR/out/genesis.json + +./fendermint key into-tendermint --secret-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.sk \ + --out $BASE_TESTNET_DIR/node0/cometbft/config/priv_validator_key.json + +./fendermint key into-tendermint --secret-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.sk \ + --out $BASE_TESTNET_DIR/node1/cometbft/config/priv_validator_key.json + +./fendermint key into-tendermint --secret-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.sk \ + --out $BASE_TESTNET_DIR/node2/cometbft/config/priv_validator_key.json + +./fendermint key into-tendermint --secret-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.sk \ + --out $BASE_TESTNET_DIR/node3/cometbft/config/priv_validator_key.json + +""" + +[tasks.testnet-share-genesis] +cwd = "./target/release" +script = """ +cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node0/cometbft/config/genesis.json +cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node1/cometbft/config/genesis.json +cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node2/cometbft/config/genesis.json +cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node3/cometbft/config/genesis.json +""" + [tasks.fendermint-newaccount] cwd = "./target/release" script=""" ./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} """ + [tasks.fendermint-newgenesis] cwd = "./target/release" script = """ @@ -265,6 +423,7 @@ dependencies = [ "createbasedir", ] + [tasks.fendermint-newgateway] cwd = "./target/release" script = """ diff --git a/fendermint/infra/docker-compose.yml b/fendermint/infra/docker-compose.yml new file mode 100644 index 00000000..de367c4d --- /dev/null +++ b/fendermint/infra/docker-compose.yml @@ -0,0 +1,134 @@ +version: '3' + +services: + cometbft-node0: + container_name: cometbft-node0 + image: "cometbft/cometbft:v0.37.x" + ports: + - "26656-26657:26656-26657" + environment: + - ID=0 + - LOG=${LOG:-cometbft-node0.log} + - CMT_PEX=false + - CMT_PROXY_APP=tcp://fendermint-node0:26658 + volumes: + - ${HOME}/.ipc-testnet/node0/cometbft:/cometbft + networks: + localnet: + ipv4_address: 192.167.10.2 + + cometbft-node1: + container_name: cometbft-node1 + image: "cometbft/cometbft:v0.37.x" + ports: + - "26659-26660:26656-26657" + environment: + - ID=1 + - LOG=${LOG:-cometbft-node1.log} + - CMT_PEX=false + - CMT_PROXY_APP=tcp://fendermint-node1:26658 + volumes: + - ${HOME}/.ipc-testnet/node1/cometbft:/cometbft + networks: + localnet: + ipv4_address: 192.167.10.3 + + cometbft-node2: + container_name: cometbft-node2 + image: "cometbft/cometbft:v0.37.x" + environment: + - ID=2 + - LOG=${LOG:-cometbft-node2.log} + - CMT_PEX=false + - CMT_PROXY_APP=tcp://fendermint-node2:26658 + ports: + - "26661-26662:26656-26657" + volumes: + - ${HOME}/.ipc-testnet/node2/cometbft:/cometbft + networks: + localnet: + ipv4_address: 192.167.10.4 + + cometbft-node3: + container_name: cometbft-node3 + image: "cometbft/cometbft:v0.37.x" + environment: + - ID=3 + - LOG=${LOG:-cometbft-node3.log} + - CMT_PEX=false + - CMT_PROXY_APP=tcp://fendermint-node3:26658 + ports: + - "26663-26664:26656-26657" + volumes: + - ${HOME}/.ipc-testnet/node3/cometbft:/cometbft + networks: + localnet: + ipv4_address: 192.167.10.5 + + fendermint-node0: + container_name: fendermint-node0 + image: "fendermint:latest" + build: + context: . + environment: + - FM_DATA_DIR=/data/fendermint/data + - FM_CHAIN_NAME=root + - LOG_LEVEL=info + volumes: + - ${HOME}/.ipc-testnet/node0:/data + networks: + localnet: + ipv4_address: 192.167.10.6 + + fendermint-node1: + container_name: fendermint-node1 + image: "fendermint:latest" + build: + context: . + environment: + - FM_DATA_DIR=/data/fendermint/data + - FM_CHAIN_NAME=root + - LOG_LEVEL=info + volumes: + - ${HOME}/.ipc-testnet/node1:/data + networks: + localnet: + ipv4_address: 192.167.10.7 + + fendermint-node2: + container_name: fendermint-node2 + image: "fendermint:latest" + build: + context: . + environment: + - FM_DATA_DIR=/data/fendermint/data + - FM_CHAIN_NAME=root + - LOG_LEVEL=info + volumes: + - ${HOME}/.ipc-testnet/node2:/data + networks: + localnet: + ipv4_address: 192.167.10.8 + + fendermint-node3: + container_name: fendermint-node3 + image: "fendermint:latest" + build: + context: . + environment: + - FM_DATA_DIR=/data/fendermint/data + - FM_CHAIN_NAME=root + - LOG_LEVEL=info + volumes: + - ${HOME}/.ipc-testnet/node3:/data + networks: + localnet: + ipv4_address: 192.167.10.9 + +networks: + localnet: + driver: bridge + ipam: + driver: default + config: + - subnet: 192.167.10.0/16 \ No newline at end of file From d5948064c7dce3f26c55552f9949f7c0b4617421 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Wed, 6 Sep 2023 17:19:57 +0200 Subject: [PATCH 06/40] add persistent peers --- Cargo.lock | 86 ++++++++++++--- Cargo.toml | 2 + fendermint/app/Cargo.toml | 1 + fendermint/app/src/cmd/key.rs | 29 ++++- fendermint/app/src/options/key.rs | 15 +++ fendermint/infra/Makefile.toml | 160 +++++++++++++++++++--------- fendermint/infra/docker-compose.yml | 114 +++++++++++++++++++- 7 files changed, 337 insertions(+), 70 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1af92bf8..e154b87c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2725,7 +2725,7 @@ dependencies = [ "futures", "im", "structopt", - "tendermint", + "tendermint 0.31.1", "tokio", "tower", "tower-abci", @@ -2774,8 +2774,9 @@ dependencies = [ "serde_json", "serde_with", "tempfile", - "tendermint", - "tendermint-proto", + "tendermint 0.31.1", + "tendermint-config 0.33.1", + "tendermint-proto 0.31.1", "tendermint-rpc", "tokio", "tower-abci", @@ -2812,7 +2813,7 @@ dependencies = [ "rand 0.8.5", "serde", "serde_json", - "tendermint", + "tendermint 0.31.1", "tendermint-rpc", "thiserror", "tokio", @@ -2869,8 +2870,8 @@ dependencies = [ "libsecp256k1", "prost", "serde", - "tendermint", - "tendermint-proto", + "tendermint 0.31.1", + "tendermint-proto 0.31.1", "tendermint-rpc", "tokio", "tracing", @@ -8147,7 +8148,36 @@ dependencies = [ "signature 2.1.0", "subtle", "subtle-encoding", - "tendermint-proto", + "tendermint-proto 0.31.1", + "time", + "zeroize", +] + +[[package]] +name = "tendermint" +version = "0.33.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c293cdbb6e13bad728bce26584a3a89d7cb5ea0b4b9db796fded10bae4a0b06b" +dependencies = [ + "bytes", + "digest 0.10.7", + "ed25519 2.2.2", + "ed25519-consensus", + "flex-error", + "futures", + "num-traits", + "once_cell", + "prost", + "prost-types", + "serde", + "serde_bytes", + "serde_json", + "serde_repr", + "sha2 0.10.7", + "signature 2.1.0", + "subtle", + "subtle-encoding", + "tendermint-proto 0.33.1", "time", "zeroize", ] @@ -8161,7 +8191,21 @@ dependencies = [ "flex-error", "serde", "serde_json", - "tendermint", + "tendermint 0.31.1", + "toml 0.5.11", + "url", +] + +[[package]] +name = "tendermint-config" +version = "0.33.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007da10d992c93039bde6a962ec0ab12e3520695cebb9542d5c9011de29341e3" +dependencies = [ + "flex-error", + "serde", + "serde_json", + "tendermint 0.33.1", "toml 0.5.11", "url", ] @@ -8184,6 +8228,24 @@ dependencies = [ "time", ] +[[package]] +name = "tendermint-proto" +version = "0.33.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03dcd29922e5670af2307f3d8e58c9720ec94b15b92ef85fe9ed0f4b25fbde44" +dependencies = [ + "bytes", + "flex-error", + "num-derive", + "num-traits", + "prost", + "prost-types", + "serde", + "serde_bytes", + "subtle-encoding", + "time", +] + [[package]] name = "tendermint-rpc" version = "0.31.1" @@ -8208,8 +8270,8 @@ dependencies = [ "serde_json", "subtle", "subtle-encoding", - "tendermint", - "tendermint-config", + "tendermint 0.31.1", + "tendermint-config 0.31.1", "thiserror", "time", "tokio", @@ -8543,8 +8605,8 @@ dependencies = [ "futures", "pin-project", "prost", - "tendermint", - "tendermint-proto", + "tendermint 0.31.1", + "tendermint-proto 0.31.1", "tokio", "tokio-stream", "tokio-util 0.6.10", diff --git a/Cargo.toml b/Cargo.toml index db78d650..483691fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,8 @@ im = "15.1.0" jsonrpc-v2 = { version = "0.11", default-features = false, features = ["bytes-v10"] } k256 = "0.11" # Same as tendermint-rs lazy_static = "1.4" +ed25519-consensus = { version = "2", default-features = false } +tendermint-config = "0.33.0" libsecp256k1 = "0.7" lru_time_cache = "0.11" multihash = { version = "0.16.1", default-features = false } diff --git a/fendermint/app/Cargo.toml b/fendermint/app/Cargo.toml index 4c28d9ee..d83f9cc4 100644 --- a/fendermint/app/Cargo.toml +++ b/fendermint/app/Cargo.toml @@ -16,6 +16,7 @@ config = { workspace = true } dirs = { workspace = true } hex = { workspace = true } k256 = { workspace = true } +tendermint-config = { workspace = true } libsecp256k1 = { workspace = true } num-traits = { workspace = true } prost = { workspace = true } diff --git a/fendermint/app/src/cmd/key.rs b/fendermint/app/src/cmd/key.rs index 8072a384..654ce136 100644 --- a/fendermint/app/src/cmd/key.rs +++ b/fendermint/app/src/cmd/key.rs @@ -6,12 +6,17 @@ use fvm_shared::address::Address; use libsecp256k1::{PublicKey, SecretKey}; use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng}; use serde_json::json; +use std::any::Any; use std::path::{Path, PathBuf}; +use tendermint_config::NodeKey; +use tendermint_proto::Protobuf; use super::{from_b64, to_b64}; use crate::{ cmd, - options::key::{KeyAddressArgs, KeyArgs, KeyCommands, KeyGenArgs, KeyIntoTendermintArgs}, + options::key::{ + AddPeer, KeyAddressArgs, KeyArgs, KeyCommands, KeyGenArgs, KeyIntoTendermintArgs, + }, }; cmd! { @@ -19,6 +24,7 @@ cmd! { match &self.command { KeyCommands::Gen(args) => args.exec(()).await, KeyCommands::IntoTendermint(args) => args.exec(()).await, + KeyCommands::AddPeer(args) => args.exec(()).await, KeyCommands::Address(args) => args.exec(()).await, } } @@ -66,6 +72,27 @@ cmd! { } } +cmd! { + AddPeer(self) { + let node_key = NodeKey::load_json_file(&self.node_key_file).unwrap(); + let peer_id : String = node_key.node_id().to_owned().to_string()+"@"+self.network_addr.as_str(); + let peers_result = std::fs::read_to_string(&self.local_peers_file).context("failed to read peer file"); + match peers { + Ok(mut v) => { + if v.is_empty() { + std::fs::write(&self.local_peers_file, peer_id)?; + } else { + v = v.to_owned().to_string()+ "," + peer_id.as_str(); + std::fs::write(&self.local_peers_file, v)?; + } + } + Err(_) => { + std::fs::write(&self.local_peers_file, peer_id)?;} + } + Ok(()) + } +} + cmd! { KeyAddressArgs(self) { let pk = read_public_key(&self.public_key)?; diff --git a/fendermint/app/src/options/key.rs b/fendermint/app/src/options/key.rs index 9f6aed12..dc7df3f4 100644 --- a/fendermint/app/src/options/key.rs +++ b/fendermint/app/src/options/key.rs @@ -13,6 +13,8 @@ pub enum KeyCommands { IntoTendermint(KeyIntoTendermintArgs), /// Convert a public key file from base64 into an f1 Address format an print it to STDOUT. Address(KeyAddressArgs), + /// TBD + AddPeer(AddPeer) } #[derive(Args, Debug)] @@ -21,6 +23,19 @@ pub struct KeyArgs { pub command: KeyCommands, } +#[derive(Args, Debug)] +pub struct AddPeer { + /// The path to node key file. + #[arg(long, short)] + pub node_key_file: PathBuf, + /// The path to a local file with persistent peers. + #[arg(long, short)] + pub local_peers_file: PathBuf, + /// The path to a local file with persistent peers. + #[arg(long, short)] + pub network_addr: String +} + #[derive(Args, Debug)] pub struct KeyGenArgs { /// Name used to distinguish the files from other exported keys. diff --git a/fendermint/infra/Makefile.toml b/fendermint/infra/Makefile.toml index fb05decc..ba3685c7 100644 --- a/fendermint/infra/Makefile.toml +++ b/fendermint/infra/Makefile.toml @@ -16,7 +16,7 @@ KEY_NAME="validator_key" PUB_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.pk" PRIV_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.sk" -NETWORK_NAME = "${CHAIN_NAME}net" +NETWORK_NAME = "${CHAIN_NAME}testnet" CMT_CONTAINER_NAME = "${NETWORK_NAME}-cometbft" FM_CONTAINER_NAME = "${NETWORK_NAME}-fendermint" ETHAPI_CONTAINER_NAME = "${NETWORK_NAME}-ethapi" @@ -123,6 +123,7 @@ script = [''' # Waiting before starting the Eth API for the CometBFT websocket to start listening. [tasks.start] dependencies = [ + "teardown", "init", "network-create", "cometbft-init", @@ -178,16 +179,6 @@ mkdir -p $BASE_TESTNET_DIR/node1/cometbft mkdir -p $BASE_TESTNET_DIR/node2/cometbft mkdir -p $BASE_TESTNET_DIR/node3/cometbft -mkdir -p $BASE_TESTNET_DIR/node0/cometbft/config -mkdir -p $BASE_TESTNET_DIR/node1/cometbft/config -mkdir -p $BASE_TESTNET_DIR/node2/cometbft/config -mkdir -p $BASE_TESTNET_DIR/node3/cometbft/config - -mkdir -p $BASE_TESTNET_DIR/node0/cometbft/data -mkdir -p $BASE_TESTNET_DIR/node1/cometbft/data -mkdir -p $BASE_TESTNET_DIR/node2/cometbft/data -mkdir -p $BASE_TESTNET_DIR/node3/cometbft/data - """ [tasks.testnet-createbasedir] @@ -198,6 +189,7 @@ dependencies = [ [tasks.testnet-up] script = """ +export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` docker compose -f ./fendermint/infra/docker-compose.yml up -d """ @@ -209,7 +201,10 @@ docker compose -f ./fendermint/infra/docker-compose.yml down [tasks.testnet] dependencies = [ "testnet-down", + "network-create", + "cometbft-pull", "testnet-createbasedir", + "testnet-cometbft-init", "testnet-init", "fendermint-deps", "testnet-up" @@ -248,6 +243,26 @@ args = ["pull", "${CMT_DOCKER_IMAGE}"] extend = "cometbft-run" env = { "CMD" = "init", "FLAGS" = "-a STDOUT -a STDERR --rm" } +[tasks.testnet-cometbft-init] +env = { "CMD" = "init", "FLAGS" = "-a STDOUT -a STDERR --rm" } +dependencies = ["testnet-cometbft-init-node0", "testnet-cometbft-init-node1", "testnet-cometbft-init-node2", "testnet-cometbft-init-node3"] + +[tasks.testnet-cometbft-init-node0] +extend = "testnet-cometbft-init-run" +env = { "CMT_DIR" = "${BASE_TESTNET_DIR}/node0/cometbft", "CMT_CONTAINER_NAME" = "node0", "FLAGS" = "-a STDOUT -a STDERR --rm"} + +[tasks.testnet-cometbft-init-node1] +extend = "testnet-cometbft-init-run" +env = { "CMT_DIR" = "${BASE_TESTNET_DIR}/node1/cometbft", "CMT_CONTAINER_NAME" = "node1", "FLAGS" = "-a STDOUT -a STDERR --rm" } + +[tasks.testnet-cometbft-init-node2] +extend = "testnet-cometbft-init-run" +env = { "CMT_DIR" = "${BASE_TESTNET_DIR}/node2/cometbft", "CMT_CONTAINER_NAME" = "node2", "FLAGS" = "-a STDOUT -a STDERR --rm" } + +[tasks.testnet-cometbft-init-node3] +extend = "testnet-cometbft-init-run" +env = { "CMT_DIR" = "${BASE_TESTNET_DIR}/node3/cometbft", "CMT_CONTAINER_NAME" = "node3", "FLAGS" = "-a STDOUT -a STDERR --rm" } + [tasks.cometbft-start] extend = "cometbft-run" env = { "CMD" = "start", "FLAGS" = "-d" } @@ -256,6 +271,21 @@ env = { "CMD" = "start", "FLAGS" = "-d" } extend = "wait" env = { "CARGO_MAKE_WAIT_MILLISECONDS" = "${CMT_WAIT_MILLIS}" } +[tasks.testnet-cometbft-init-run] +script = """ +docker run \ + ${FLAGS} \ + --name ${CMT_CONTAINER_NAME} \ + --user $(id -u) \ + --network ${NETWORK_NAME} \ + --publish 26657:${CMT_HOST_PORT} \ + --volume ${CMT_DIR}:/cometbft \ + --env CMT_PROXY_APP=tcp://${FM_CONTAINER_NAME}:26658 \ + --env CMT_PEX=false \ + ${CMT_DOCKER_IMAGE} \ + init +""" + [tasks.cometbft-run] script = """ docker run \ @@ -300,19 +330,21 @@ fi [tasks.testnet-init] dependencies = [ "testnet-newgenesis", + "testnet_peers", "testnet-newkey", "testnet-newaccount", "testnet-newgateway", "testnet-share-genesis" ] -[tasks.fendermint-init] -dependencies = [ - "fendermint-newgenesis", - "fendermint-newkey", - "fendermint-newaccount", - "fendermint-newgateway", -] +[tasks.testnet-newgenesis] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json \ + new --chain-name testnet --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} + +cat $BASE_TESTNET_DIR/genesis.json +""" [tasks.testnet-newkey] cwd = "./target/release" @@ -329,36 +361,22 @@ mkdir -p $BASE_TESTNET_DIR/node3/fendermint/keys """ -[tasks.testnet-newgenesis] -cwd = "./target/release" -script = """ -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json \ - new --chain-name testnet --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} -""" - -[tasks.fendermint-newkey] +[tasks.testnet_peers] cwd = "./target/release" script=""" -mkdir -p $KEYS_DIR - -./fendermint key gen --out-dir $KEYS_DIR --name $KEY_NAME; -chmod 600 ${PRIV_KEY_PATH} -""" - -[tasks.testnet-newaccount] -cwd = "./target/release" -script=""" -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.pk --balance ${BALANCE} - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.pk --balance ${BALANCE} - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.pk --balance ${BALANCE} - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.pk --balance ${BALANCE} +./fendermint key add-peer --node-key-file $BASE_TESTNET_DIR/node0/cometbft/config/node_key.json --network-addr 192.167.10.2:26656 --local-peers-file $BASE_TESTNET_DIR/peers +./fendermint key add-peer --node-key-file $BASE_TESTNET_DIR/node1/cometbft/config/node_key.json --network-addr 192.167.10.3:26656 --local-peers-file $BASE_TESTNET_DIR/peers +./fendermint key add-peer --node-key-file $BASE_TESTNET_DIR/node2/cometbft/config/node_key.json --network-addr 192.167.10.4:26656 --local-peers-file $BASE_TESTNET_DIR/peers +./fendermint key add-peer --node-key-file $BASE_TESTNET_DIR/node3/cometbft/config/node_key.json --network-addr 192.167.10.5:26656 --local-peers-file $BASE_TESTNET_DIR/peers + +unset CMT_PERSISTENT_PEERS +export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` +echo Persistent peers: $CMT_PERSISTENT_PEERS + +sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node0/cometbft/config/config.toml +sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node1/cometbft/config/config.toml +sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node2/cometbft/config/config.toml +sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node3/cometbft/config/config.toml """ [tasks.testnet-newgateway] @@ -396,6 +414,8 @@ script = """ ./fendermint key into-tendermint --secret-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.sk \ --out $BASE_TESTNET_DIR/node3/cometbft/config/priv_validator_key.json +cat $BASE_TESTNET_DIR/genesis.json + """ [tasks.testnet-share-genesis] @@ -407,12 +427,13 @@ cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node2/cometbft/config/ge cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node3/cometbft/config/genesis.json """ -[tasks.fendermint-newaccount] -cwd = "./target/release" -script=""" -./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} -""" - +[tasks.fendermint-init] +dependencies = [ + "fendermint-newgenesis", + "fendermint-newkey", + "fendermint-newaccount", + "fendermint-newgateway", +] [tasks.fendermint-newgenesis] cwd = "./target/release" @@ -423,6 +444,39 @@ dependencies = [ "createbasedir", ] +[tasks.fendermint-newkey] +cwd = "./target/release" +script=""" +mkdir -p $KEYS_DIR + +./fendermint key gen --out-dir $KEYS_DIR --name $KEY_NAME; +chmod 600 ${PRIV_KEY_PATH} +""" + +[tasks.testnet-newaccount] +cwd = "./target/release" +script=""" +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.pk --balance ${BALANCE} + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.pk --balance ${BALANCE} + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.pk --balance ${BALANCE} + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.pk --balance ${BALANCE} + +cat $BASE_TESTNET_DIR/genesis.json +""" + +[tasks.fendermint-newaccount] +cwd = "./target/release" +script=""" +./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} +""" + [tasks.fendermint-newgateway] cwd = "./target/release" @@ -488,7 +542,7 @@ dependencies = ["network-create"] [tasks.network-create] command = "docker" args = ["network", "create", "${NETWORK_NAME}"] -ignore_errors = false +ignore_errors = true [tasks.network-rm] command = "docker" diff --git a/fendermint/infra/docker-compose.yml b/fendermint/infra/docker-compose.yml index de367c4d..a7ffad16 100644 --- a/fendermint/infra/docker-compose.yml +++ b/fendermint/infra/docker-compose.yml @@ -9,10 +9,16 @@ services: environment: - ID=0 - LOG=${LOG:-cometbft-node0.log} - - CMT_PEX=false + - CMT_PEX=true - CMT_PROXY_APP=tcp://fendermint-node0:26658 + - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" volumes: - ${HOME}/.ipc-testnet/node0/cometbft:/cometbft + healthcheck: + test: curl --fail http://localhost:26657 || exit 1 + interval: 8s + timeout: 10s + retries: 20 networks: localnet: ipv4_address: 192.167.10.2 @@ -25,10 +31,16 @@ services: environment: - ID=1 - LOG=${LOG:-cometbft-node1.log} - - CMT_PEX=false + - CMT_PEX=true + - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" - CMT_PROXY_APP=tcp://fendermint-node1:26658 volumes: - ${HOME}/.ipc-testnet/node1/cometbft:/cometbft + healthcheck: + test: curl --fail http://localhost:26657 || exit 1 + interval: 8s + timeout: 10s + retries: 20 networks: localnet: ipv4_address: 192.167.10.3 @@ -39,12 +51,18 @@ services: environment: - ID=2 - LOG=${LOG:-cometbft-node2.log} - - CMT_PEX=false + - CMT_PEX=true + - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" - CMT_PROXY_APP=tcp://fendermint-node2:26658 ports: - "26661-26662:26656-26657" volumes: - ${HOME}/.ipc-testnet/node2/cometbft:/cometbft + healthcheck: + test: curl --fail http://localhost:26657 || exit 1 + interval: 8s + timeout: 10s + retries: 20 networks: localnet: ipv4_address: 192.167.10.4 @@ -55,12 +73,16 @@ services: environment: - ID=3 - LOG=${LOG:-cometbft-node3.log} - - CMT_PEX=false - CMT_PROXY_APP=tcp://fendermint-node3:26658 ports: - "26663-26664:26656-26657" volumes: - ${HOME}/.ipc-testnet/node3/cometbft:/cometbft + healthcheck: + test: curl --fail http://localhost:26657 || exit 1 + interval: 8s + timeout: 10s + retries: 20 networks: localnet: ipv4_address: 192.167.10.5 @@ -125,6 +147,90 @@ services: localnet: ipv4_address: 192.167.10.9 + ethapi-node0: + container_name: ethapi-node0 + image: "fendermint:latest" + command: "eth run" + build: + context: . + environment: + - TENDERMINT_WS_URL=ws://cometbft-node0:26657/websocket + - LOG_LEVEL=debug + - RUST_BACKTRACE=1 + ports: + - 8545:8545 + volumes: + - ${HOME}/.ipc-testnet/node0:/data + depends_on: + cometbft-node0: + condition: service_healthy + networks: + localnet: + ipv4_address: 192.167.10.10 + + ethapi-node1: + container_name: ethapi-node1 + image: "fendermint:latest" + command: "eth run" + build: + context: . + environment: + - TENDERMINT_WS_URL=ws://cometbft-node1:26657/websocket + - LOG_LEVEL=debug + - RUST_BACKTRACE=1 + ports: + - 8546:8545 + volumes: + - ${HOME}/.ipc-testnet/node1:/data + depends_on: + cometbft-node1: + condition: service_healthy + networks: + localnet: + ipv4_address: 192.167.10.11 + + ethapi-node2: + container_name: ethapi-node2 + image: "fendermint:latest" + command: "eth run" + build: + context: . + environment: + - TENDERMINT_WS_URL=ws://cometbft-node2:26657/websocket + - LOG_LEVEL=debug + - RUST_BACKTRACE=1 + ports: + - 8547:8545 + volumes: + - ${HOME}/.ipc-testnet/node2:/data + depends_on: + cometbft-node2: + condition: service_healthy + networks: + localnet: + ipv4_address: 192.167.10.12 + + ethapi-node3: + container_name: ethapi-node3 + image: "fendermint:latest" + command: "eth run" + build: + context: . + environment: + - TENDERMINT_WS_URL=ws://cometbft-node3:26657/websocket + - LOG_LEVEL=debug + - RUST_BACKTRACE=1 + ports: + - 8548:8545 + volumes: + - ${HOME}/.ipc-testnet/node3:/data + depends_on: + cometbft-node2: + condition: service_healthy + networks: + localnet: + ipv4_address: 192.167.10.13 + networks: localnet: driver: bridge From 14dbaba3f25b71ba372f198ffa354d1bc6f24b80 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Wed, 6 Sep 2023 17:22:49 +0200 Subject: [PATCH 07/40] fmt --- fendermint/app/src/options/key.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fendermint/app/src/options/key.rs b/fendermint/app/src/options/key.rs index dc7df3f4..11087972 100644 --- a/fendermint/app/src/options/key.rs +++ b/fendermint/app/src/options/key.rs @@ -14,7 +14,7 @@ pub enum KeyCommands { /// Convert a public key file from base64 into an f1 Address format an print it to STDOUT. Address(KeyAddressArgs), /// TBD - AddPeer(AddPeer) + AddPeer(AddPeer), } #[derive(Args, Debug)] @@ -33,7 +33,7 @@ pub struct AddPeer { pub local_peers_file: PathBuf, /// The path to a local file with persistent peers. #[arg(long, short)] - pub network_addr: String + pub network_addr: String, } #[derive(Args, Debug)] From 2f56b5174309e71f6b8ce239b8d4c75e0d189e5a Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Thu, 7 Sep 2023 14:48:53 +0200 Subject: [PATCH 08/40] Add docs and polish --- README.md | 2 + docs/localnet.md | 49 +++ fendermint/infra/Makefile.toml | 500 ++++++++++++++-------------- fendermint/infra/docker-compose.yml | 1 + 4 files changed, 306 insertions(+), 246 deletions(-) create mode 100644 docs/localnet.md diff --git a/README.md b/README.md index d6e7960d..35b3263f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Fendermint is an effort to implement [IPC with Tendermint Core](https://docs.google.com/document/d/1cFoTdoRuYgxmWJia6K-b5vmEj-4MvyHCNvShZpyconU/edit#). There is a preliminary [roadmap](https://docs.google.com/spreadsheets/d/1eVwkHEPGNg0js8DKRDIX7sugf5JqbI9zRBddIqzJFfI/edit#gid=0) that lays out the tasks towards implementing subnets that run IPLD and FVM under the Filecoin rootnet, sharing components with the Lotus/Eudico based implementation. +## Quick Start +- [Local testnets](./docs/localnet.md) ## Docs diff --git a/docs/localnet.md b/docs/localnet.md new file mode 100644 index 00000000..076689cc --- /dev/null +++ b/docs/localnet.md @@ -0,0 +1,49 @@ +# Local Testnets + +## Single node deployment + +To run IPC in a rootnet just perform the following : +```bash +cargo make --makefile ./fendermint/infra/Makefile.toml node + +``` + +It will create three docker containers (cometbft, fendermint, and eth-api). + +To stop run the following: +```bash +cargo make --makefile ./fendermint/infra/Makefile.toml node-down +``` + +## Local 4-nodes deployment +To run IPC in a rootnet with 4 nodes perform the following command : +```bash +cargo make --makefile ./fendermint/infra/Makefile.toml testnet + +``` + +To stop the network: +```bash +cargo make --makefile ./fendermint/infra/Makefile.toml testnet-down +``` + +The testnet contains four logical nodes. Each node consists of cometbft, fendermint, and ethapi containers. +The testnet network is `192.167.10.0/24`. + +ETH-API is accessible on the following interfaces: +- `192.167.10.10:8545` +- `192.167.10.11:8546` +- `192.167.10.12:8547` +- `192.167.10.13:8548` + +## Development + +The deployment process is as follows: +- Remove all docker containers, files, networks, etc. from the previous deployment +- Create all necessary directories +- Initialize CometBFT testnet by creating `config` and `data` directories using `cometbft` tools +- Read cometbft nodes private keys,derive node IDs and store in `config.toml` for each node +- Create the `genesis` file for Fendermint +- Share the genesis among all Fendermint nodes +- Run Fendermint application in 4 containers +- Run Eth API in 4 containers \ No newline at end of file diff --git a/fendermint/infra/Makefile.toml b/fendermint/infra/Makefile.toml index ba3685c7..cb0b8082 100644 --- a/fendermint/infra/Makefile.toml +++ b/fendermint/infra/Makefile.toml @@ -1,3 +1,6 @@ +[config] +default_to_workspace = false + [env] CHAIN_NAME = { value = "root", condition = { env_not_set = ["CHAIN_NAME"] }} BALANCE = { value = "1000", condition = { env_not_set = ["BALANCE"] }} @@ -5,6 +8,7 @@ BASE_FEE = { value = "1000", condition = { env_not_set = ["BASE_FEE"] }} TIMESTAMP = { value = "1680101412", condition = { env_not_set = ["TIMESTAMP"] }} BASE_DIR="${HOME}/.ipc/${CHAIN_NAME}" + BASE_TESTNET_DIR="${HOME}/.ipc-testnet" FM_DIR="${BASE_DIR}/fendermint" @@ -16,7 +20,9 @@ KEY_NAME="validator_key" PUB_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.pk" PRIV_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.sk" -NETWORK_NAME = "${CHAIN_NAME}testnet" +NETWORK_NAME = "${CHAIN_NAME}" + + CMT_CONTAINER_NAME = "${NETWORK_NAME}-cometbft" FM_CONTAINER_NAME = "${NETWORK_NAME}-fendermint" ETHAPI_CONTAINER_NAME = "${NETWORK_NAME}-ethapi" @@ -61,40 +67,23 @@ echo - Balance: ${BALANCE} echo - Base Fee: ${BASE_FEE} echo - Timestamp: ${TIMESTAMP} echo -echo Directories and files: +echo Single node testnet layout: echo - IPC directory: ${BASE_DIR} +echo - IPC Testnet directory: ${BASE_TESTNET_DIR} echo - CometBFT directory: ${CMT_DIR} echo - Fendermint directory: ${FM_DIR} echo - Keys directory: ${KEYS_DIR} echo - Genesis file: ${GENESIS_FILE} echo - Private key: ${PRIV_KEY_PATH} -echo -echo Docker info: echo - Network: ${NETWORK_NAME} echo - CometBFT container: ${CMT_CONTAINER_NAME} echo - Fendermint container: ${FM_CONTAINER_NAME} echo -""" - -[tasks.init] -dependencies = [ - "clear", - "createbasedir", -] - -[tasks.clear] -script=""" -echo clearing all IPC data -rm -rf ${BASE_DIR} -""" - -[tasks.createbasedir] -script=""" -echo creating directories: $BASE_DIR $FM_DIR $CMT_DIR -mkdir -p $BASE_DIR -mkdir -p $FM_DIR - -mkdir -p $CMT_DIR +echo +echo 4 nodes testnet layout: +echo - IPC directory: ${BASE_TESTNET_DIR} +echo - Genesis file: ${GENESIS_FILE} +echo """ [tasks.default] @@ -120,26 +109,51 @@ script = [''' echo '''] -# Waiting before starting the Eth API for the CometBFT websocket to start listening. -[tasks.start] +######################################################################################################################## +# Single node +######################################################################################################################## +[tasks.node] +workspace = false dependencies = [ - "teardown", - "init", - "network-create", + "node-down", + "node-init", + "node-network-create", "cometbft-init", "fendermint-deps", - "fendermint-init", + "node-config", "fendermint-start", "cometbft-start", "cometbft-wait", "ethapi-start" ] -[tasks.test] -clear = true -dependencies = ["simplecoin-example", "ethapi-example"] +[tasks.node-network-create] +env = { "NETWORK_NAME"="${NETWORK_NAME}"} +extend = "network-create" -[tasks.teardown] + +[tasks.node-init] +dependencies = [ + "node-clear", + "node-mkdir", +] + +[tasks.node-clear] +script=""" +echo clearing all IPC data +rm -rf ${BASE_DIR} +""" + +[tasks.node-mkdir] +script=""" +echo creating directories: $BASE_DIR $FM_DIR $CMT_DIR +mkdir -p $BASE_DIR +mkdir -p $FM_DIR + +mkdir -p $CMT_DIR +""" + +[tasks.node-down] # `dependencies` doesn't seem to work with `cleanup_task`. run_task = { name = [ "cometbft-stop", @@ -149,195 +163,179 @@ run_task = { name = [ "ethapi-stop", "ethapi-rm", "network-rm", - "clear", -] } +]} -[tasks.testnet-clear] +[tasks.node-config] +dependencies = [ + "fendermint-newgenesis", + "fendermint-newkey", + "fendermint-newaccount", + "fendermint-newgateway", +] + +[tasks.fendermint-newgenesis] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} +""" + +[tasks.fendermint-newkey] +cwd = "./target/release" script=""" -echo clearing all IPC data -rm -rf ${BASE_TESTNET_DIR} +mkdir -p $KEYS_DIR + +./fendermint key gen --out-dir $KEYS_DIR --name $KEY_NAME; +chmod 600 ${PRIV_KEY_PATH} """ -[tasks.testnet-mkdir] +[tasks.fendermint-newaccount] +cwd = "./target/release" script=""" -echo creating directories: $BASE_DIR $FM_DIR $CMT_DIR -mkdir -p $BASE_TESTNET_DIR -mkdir -p $BASE_TESTNET_DIR/out +./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} +""" -mkdir -p $BASE_TESTNET_DIR/node0 -mkdir -p $BASE_TESTNET_DIR/node1 -mkdir -p $BASE_TESTNET_DIR/node2 -mkdir -p $BASE_TESTNET_DIR/node3 -mkdir -p $BASE_TESTNET_DIR/node0/fendermint -mkdir -p $BASE_TESTNET_DIR/node1/fendermint -mkdir -p $BASE_TESTNET_DIR/node2/fendermint -mkdir -p $BASE_TESTNET_DIR/node3/fendermint +[tasks.fendermint-newgateway] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} add-validator --public-key ${PUB_KEY_PATH} --power 1 -mkdir -p $BASE_TESTNET_DIR/node0/cometbft -mkdir -p $BASE_TESTNET_DIR/node1/cometbft -mkdir -p $BASE_TESTNET_DIR/node2/cometbft -mkdir -p $BASE_TESTNET_DIR/node3/cometbft +./fendermint genesis --genesis-file ${GENESIS_FILE} ipc gateway --subnet-id /r0 \ + --top-down-check-period 10 \ + --bottom-up-check-period 10 \ + --msg-fee 10 \ + --majority-percentage 66 + +./fendermint genesis --genesis-file ${GENESIS_FILE} into-tendermint --out ${CMT_DIR}/config/genesis.json +./fendermint key into-tendermint --secret-key ${PRIV_KEY_PATH} --out ${CMT_DIR}/config/priv_validator_key.json +chmod 600 ${CMT_DIR}/config/priv_validator_key.json """ -[tasks.testnet-createbasedir] -dependencies = [ - "testnet-clear", - "testnet-mkdir", -] +[tasks.fendermint-start] +extend = "fendermint-run" +env = { "ENTRY" = "fendermint", "CMD" = "run", "FLAGS" = "-d" } -[tasks.testnet-up] +[tasks.fendermint-run] script = """ -export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` -docker compose -f ./fendermint/infra/docker-compose.yml up -d +docker run \ + ${FLAGS} \ + --name ${FM_CONTAINER_NAME} \ + --init \ + --user $(id -u) \ + --network ${NETWORK_NAME} \ + --volume ${BASE_DIR}:/data \ + --env FM_DATA_DIR=/data/fendermint/data \ + --env FM_CHAIN_NAME=${NETWORK_NAME} \ + --env LOG_LEVEL=info \ + --entrypoint ${ENTRY} \ + ${FM_DOCKER_IMAGE} \ + ${CMD} """ +dependencies = ["network-create", "fendermint-deps"] -[tasks.testnet-down] -script = """ -docker compose -f ./fendermint/infra/docker-compose.yml down -""" +######################################################################################################################## +# Testnet node +######################################################################################################################## [tasks.testnet] dependencies = [ "testnet-down", - "network-create", - "cometbft-pull", - "testnet-createbasedir", - "testnet-cometbft-init", "testnet-init", "fendermint-deps", + "testnet-fendermint-config", "testnet-up" ] -[tasks.simplecoin-example] -# Using --release in the hope that it can reuse artifacts compiled earlier for the docker build. +[tasks.testnet-up] script = """ -cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} -cargo run -p fendermint_rpc --release --example simplecoin -- \ - --secret-key fendermint/testing/smoke-test/test-data/fendermint/keys/alice.sk \ - ${VERBOSITY} +export =`cat $BASE_TESTNET_DIR/peers` +docker compose -f ./fendermint/infra/docker-compose.yml up -d """ +[tasks.testnet-down] +dependencies = [ + "testnet-docker-compose-down", + "network-rm" +] -[tasks.ethapi-example] +[tasks.testnet-docker-compose-down] script = """ -cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} -cargo run -p fendermint_eth_api --release --example ethers -- \ - --secret-key-from fendermint/testing/smoke-test/test-data/fendermint/keys/emily.sk \ - --secret-key-to fendermint/testing/smoke-test/test-data/fendermint/keys/eric.sk +docker compose -f ./fendermint/infra/docker-compose.yml down """ +[tasks.testnet-init] +dependencies = [ + "testnet-clear", + "testnet-network-create", + "cometbft-pull", + "testnet-mkdir", + "testnet-cometbft-init", + "testnet-mkdir", +] + +[tasks.testnet-network-create] +env = { "NETWORK_NAME"="${NETWORK_NAME}"} +extend = "network-create" -[tasks.test-data-dir-rm] -script = """ -rm -rf ${TEST_DATA_DIR} +[tasks.testnet-clear] +script=""" +echo clearing all IPC data +rm -rf ${BASE_TESTNET_DIR} """ +[tasks.testnet-mkdir] +script=""" +echo creating directories: $BASE_DIR $FM_DIR $CMT_DIR +mkdir -p $BASE_TESTNET_DIR +mkdir -p $BASE_TESTNET_DIR/out -[tasks.cometbft-pull] -command = "docker" -args = ["pull", "${CMT_DOCKER_IMAGE}"] +mkdir -p $BASE_TESTNET_DIR/node0 +mkdir -p $BASE_TESTNET_DIR/node1 +mkdir -p $BASE_TESTNET_DIR/node2 +mkdir -p $BASE_TESTNET_DIR/node3 -[tasks.cometbft-init] -extend = "cometbft-run" -env = { "CMD" = "init", "FLAGS" = "-a STDOUT -a STDERR --rm" } +mkdir -p $BASE_TESTNET_DIR/node0/fendermint +mkdir -p $BASE_TESTNET_DIR/node1/fendermint +mkdir -p $BASE_TESTNET_DIR/node2/fendermint +mkdir -p $BASE_TESTNET_DIR/node3/fendermint + +mkdir -p $BASE_TESTNET_DIR/node0/cometbft +mkdir -p $BASE_TESTNET_DIR/node1/cometbft +mkdir -p $BASE_TESTNET_DIR/node2/cometbft +mkdir -p $BASE_TESTNET_DIR/node3/cometbft +""" [tasks.testnet-cometbft-init] -env = { "CMD" = "init", "FLAGS" = "-a STDOUT -a STDERR --rm" } dependencies = ["testnet-cometbft-init-node0", "testnet-cometbft-init-node1", "testnet-cometbft-init-node2", "testnet-cometbft-init-node3"] [tasks.testnet-cometbft-init-node0] -extend = "testnet-cometbft-init-run" -env = { "CMT_DIR" = "${BASE_TESTNET_DIR}/node0/cometbft", "CMT_CONTAINER_NAME" = "node0", "FLAGS" = "-a STDOUT -a STDERR --rm"} +extend = "cometbft-init" +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node0/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node0", "FLAGS" = "-a STDOUT -a STDERR --rm"} [tasks.testnet-cometbft-init-node1] -extend = "testnet-cometbft-init-run" -env = { "CMT_DIR" = "${BASE_TESTNET_DIR}/node1/cometbft", "CMT_CONTAINER_NAME" = "node1", "FLAGS" = "-a STDOUT -a STDERR --rm" } +extend = "cometbft-init" +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node1/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node1", "FLAGS" = "-a STDOUT -a STDERR --rm" } [tasks.testnet-cometbft-init-node2] -extend = "testnet-cometbft-init-run" -env = { "CMT_DIR" = "${BASE_TESTNET_DIR}/node2/cometbft", "CMT_CONTAINER_NAME" = "node2", "FLAGS" = "-a STDOUT -a STDERR --rm" } +extend = "cometbft-init" +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node2/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node2", "FLAGS" = "-a STDOUT -a STDERR --rm" } [tasks.testnet-cometbft-init-node3] -extend = "testnet-cometbft-init-run" -env = { "CMT_DIR" = "${BASE_TESTNET_DIR}/node3/cometbft", "CMT_CONTAINER_NAME" = "node3", "FLAGS" = "-a STDOUT -a STDERR --rm" } - -[tasks.cometbft-start] -extend = "cometbft-run" -env = { "CMD" = "start", "FLAGS" = "-d" } - -[tasks.cometbft-wait] -extend = "wait" -env = { "CARGO_MAKE_WAIT_MILLISECONDS" = "${CMT_WAIT_MILLIS}" } - -[tasks.testnet-cometbft-init-run] -script = """ -docker run \ - ${FLAGS} \ - --name ${CMT_CONTAINER_NAME} \ - --user $(id -u) \ - --network ${NETWORK_NAME} \ - --publish 26657:${CMT_HOST_PORT} \ - --volume ${CMT_DIR}:/cometbft \ - --env CMT_PROXY_APP=tcp://${FM_CONTAINER_NAME}:26658 \ - --env CMT_PEX=false \ - ${CMT_DOCKER_IMAGE} \ - init -""" +extend = "cometbft-init" +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node3/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node3", "FLAGS" = "-a STDOUT -a STDERR --rm" } -[tasks.cometbft-run] -script = """ -docker run \ - ${FLAGS} \ - --name ${CMT_CONTAINER_NAME} \ - --user $(id -u) \ - --network ${NETWORK_NAME} \ - --publish 26657:${CMT_HOST_PORT} \ - --volume ${CMT_DIR}:/cometbft \ - --env CMT_PROXY_APP=tcp://${FM_CONTAINER_NAME}:26658 \ - --env CMT_PEX=false \ - ${CMT_DOCKER_IMAGE} \ - ${CMD} -""" -dependencies = ["cometbft-pull", "createbasedir", "network-create"] - -[tasks.cometbft-rm] -extend = "docker-rm" -env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } - -[tasks.cometbft-stop] -extend = "docker-stop" -env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } - -[tasks.cometbft-logs] -extend = "docker-logs" -env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } - -[tasks.fendermint-deps] -script = """ -# Check if the image exists -# TODO: Check the version or use a flag to always re-build? -if docker images | awk '{print $1":"$2}' | grep fendermint; then - echo fendermint image already exists - docker images | grep fendermint -else - cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} - make docker-build -fi -""" - -[tasks.testnet-init] +[tasks.testnet-fendermint-config] dependencies = [ - "testnet-newgenesis", - "testnet_peers", - "testnet-newkey", - "testnet-newaccount", - "testnet-newgateway", + "testnet-config-newgenesis", + "testnet-config-peers", + "testnet-config-newkey", + "testnet-config-newaccount", + "testnet-config-newgateway", "testnet-share-genesis" ] -[tasks.testnet-newgenesis] +[tasks.testnet-config-newgenesis] cwd = "./target/release" script = """ ./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json \ @@ -346,7 +344,7 @@ script = """ cat $BASE_TESTNET_DIR/genesis.json """ -[tasks.testnet-newkey] +[tasks.testnet-config-newkey] cwd = "./target/release" script=""" mkdir -p $BASE_TESTNET_DIR/node0/fendermint/keys @@ -361,7 +359,25 @@ mkdir -p $BASE_TESTNET_DIR/node3/fendermint/keys """ -[tasks.testnet_peers] +[tasks.testnet-config-newaccount] +cwd = "./target/release" +script=""" +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.pk --balance ${BALANCE} + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.pk --balance ${BALANCE} + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.pk --balance ${BALANCE} + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.pk --balance ${BALANCE} + +cat $BASE_TESTNET_DIR/genesis.json +""" + +[tasks.testnet-config-peers] cwd = "./target/release" script=""" ./fendermint key add-peer --node-key-file $BASE_TESTNET_DIR/node0/cometbft/config/node_key.json --network-addr 192.167.10.2:26656 --local-peers-file $BASE_TESTNET_DIR/peers @@ -379,7 +395,7 @@ sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_P sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node3/cometbft/config/config.toml """ -[tasks.testnet-newgateway] +[tasks.testnet-config-newgateway] cwd = "./target/release" script = """ ./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ @@ -427,95 +443,87 @@ cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node2/cometbft/config/ge cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node3/cometbft/config/genesis.json """ -[tasks.fendermint-init] -dependencies = [ - "fendermint-newgenesis", - "fendermint-newkey", - "fendermint-newaccount", - "fendermint-newgateway", -] +######################################################################################################################## +# Apps +######################################################################################################################## -[tasks.fendermint-newgenesis] -cwd = "./target/release" +[tasks.simplecoin-example] +# Using --release in the hope that it can reuse artifacts compiled earlier for the docker build. script = """ -./fendermint genesis --genesis-file ${GENESIS_FILE} new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} -""" -dependencies = [ - "createbasedir", -] - -[tasks.fendermint-newkey] -cwd = "./target/release" -script=""" -mkdir -p $KEYS_DIR - -./fendermint key gen --out-dir $KEYS_DIR --name $KEY_NAME; -chmod 600 ${PRIV_KEY_PATH} -""" - -[tasks.testnet-newaccount] -cwd = "./target/release" -script=""" -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.pk --balance ${BALANCE} - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.pk --balance ${BALANCE} - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.pk --balance ${BALANCE} - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.pk --balance ${BALANCE} - -cat $BASE_TESTNET_DIR/genesis.json +cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} +cargo run -p fendermint_rpc --release --example simplecoin -- \ + --secret-key fendermint/testing/smoke-test/test-data/fendermint/keys/alice.sk \ + ${VERBOSITY} """ -[tasks.fendermint-newaccount] -cwd = "./target/release" -script=""" -./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} +[tasks.ethapi-example] +script = """ +cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} +cargo run -p fendermint_eth_api --release --example ethers -- \ + --secret-key-from fendermint/testing/smoke-test/test-data/fendermint/keys/emily.sk \ + --secret-key-to fendermint/testing/smoke-test/test-data/fendermint/keys/eric.sk """ +######################################################################################################################## +# Primitives +######################################################################################################################## -[tasks.fendermint-newgateway] -cwd = "./target/release" -script = """ -./fendermint genesis --genesis-file ${GENESIS_FILE} add-validator --public-key ${PUB_KEY_PATH} --power 1 - -./fendermint genesis --genesis-file ${GENESIS_FILE} ipc gateway --subnet-id /r0 \ - --top-down-check-period 10 \ - --bottom-up-check-period 10 \ - --msg-fee 10 \ - --majority-percentage 66 +[tasks.cometbft-pull] +command = "docker" +args = ["pull", "${CMT_DOCKER_IMAGE}"] -./fendermint genesis --genesis-file ${GENESIS_FILE} into-tendermint --out ${CMT_DIR}/config/genesis.json +[tasks.cometbft-init] +extend = "cometbft-run" +env = { "CMD" = "init", "FLAGS" = "-a STDOUT -a STDERR --rm" } -./fendermint key into-tendermint --secret-key ${PRIV_KEY_PATH} --out ${CMT_DIR}/config/priv_validator_key.json -chmod 600 ${CMT_DIR}/config/priv_validator_key.json -""" +[tasks.cometbft-start] +extend = "cometbft-run" +env = { "CMD" = "start", "FLAGS" = "-d" } -[tasks.fendermint-start] -extend = "fendermint-run" -env = { "ENTRY" = "fendermint", "CMD" = "run", "FLAGS" = "-d" } +[tasks.cometbft-wait] +extend = "wait" +env = { "CARGO_MAKE_WAIT_MILLISECONDS" = "${CMT_WAIT_MILLIS}" } -[tasks.fendermint-run] +[tasks.cometbft-run] script = """ docker run \ ${FLAGS} \ - --name ${FM_CONTAINER_NAME} \ - --init \ + --name ${CMT_CONTAINER_NAME} \ --user $(id -u) \ --network ${NETWORK_NAME} \ - --volume ${BASE_DIR}:/data \ - --env FM_DATA_DIR=/data/fendermint/data \ - --env FM_CHAIN_NAME=${NETWORK_NAME} \ - --env LOG_LEVEL=info \ - --entrypoint ${ENTRY} \ - ${FM_DOCKER_IMAGE} \ + --publish 26657:${CMT_HOST_PORT} \ + --volume ${CMT_DIR}:/cometbft \ + --env CMT_PROXY_APP=tcp://${FM_CONTAINER_NAME}:26658 \ + --env CMT_PEX=false \ + ${CMT_DOCKER_IMAGE} \ ${CMD} """ -dependencies = ["createbasedir", "network-create", "fendermint-deps"] +dependencies = ["cometbft-pull", "network-create"] + +[tasks.cometbft-rm] +extend = "docker-rm" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.cometbft-stop] +extend = "docker-stop" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.cometbft-logs] +extend = "docker-logs" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.fendermint-deps] +script = """ +# Check if the image exists +# TODO: Check the version or use a flag to always re-build? +if docker images | awk '{print $1":"$2}' | grep fendermint; then + echo fendermint image already exists + docker images | grep fendermint +else + cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} + make docker-build +fi +""" [tasks.ethapi-start] extend = "ethapi-run" diff --git a/fendermint/infra/docker-compose.yml b/fendermint/infra/docker-compose.yml index a7ffad16..3a1c2983 100644 --- a/fendermint/infra/docker-compose.yml +++ b/fendermint/infra/docker-compose.yml @@ -73,6 +73,7 @@ services: environment: - ID=3 - LOG=${LOG:-cometbft-node3.log} + - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" - CMT_PROXY_APP=tcp://fendermint-node3:26658 ports: - "26663-26664:26656-26657" From 88d1e51ef47b637ee8720bfee2739df35500f2be Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Thu, 7 Sep 2023 15:09:55 +0200 Subject: [PATCH 09/40] Fix misprint in key.rs --- fendermint/app/src/cmd/key.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fendermint/app/src/cmd/key.rs b/fendermint/app/src/cmd/key.rs index 654ce136..68447761 100644 --- a/fendermint/app/src/cmd/key.rs +++ b/fendermint/app/src/cmd/key.rs @@ -76,7 +76,7 @@ cmd! { AddPeer(self) { let node_key = NodeKey::load_json_file(&self.node_key_file).unwrap(); let peer_id : String = node_key.node_id().to_owned().to_string()+"@"+self.network_addr.as_str(); - let peers_result = std::fs::read_to_string(&self.local_peers_file).context("failed to read peer file"); + let peers = std::fs::read_to_string(&self.local_peers_file).context("failed to read peer file"); match peers { Ok(mut v) => { if v.is_empty() { From 2b9d62618d5e1dc01fb7bc6dbb335323cf3a85d1 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Thu, 7 Sep 2023 15:27:50 +0200 Subject: [PATCH 10/40] Remove unused imports key.rs --- fendermint/app/src/cmd/key.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/fendermint/app/src/cmd/key.rs b/fendermint/app/src/cmd/key.rs index 68447761..2d2db580 100644 --- a/fendermint/app/src/cmd/key.rs +++ b/fendermint/app/src/cmd/key.rs @@ -6,10 +6,8 @@ use fvm_shared::address::Address; use libsecp256k1::{PublicKey, SecretKey}; use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng}; use serde_json::json; -use std::any::Any; use std::path::{Path, PathBuf}; use tendermint_config::NodeKey; -use tendermint_proto::Protobuf; use super::{from_b64, to_b64}; use crate::{ From 60ac4f47331f5c95a38b00e2d0aecace0a903caf Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Thu, 7 Sep 2023 15:44:14 +0200 Subject: [PATCH 11/40] move infra --- docs/localnet.md | 17 +++-- fendermint/infra/scripts/init.sh | 70 ------------------- fendermint/infra/src/lib.rs | 12 ---- {fendermint/infra => infra}/Cargo.toml | 0 {fendermint/infra => infra}/Makefile.toml | 0 .../infra => infra}/docker-compose.yml | 0 6 files changed, 11 insertions(+), 88 deletions(-) delete mode 100755 fendermint/infra/scripts/init.sh delete mode 100644 fendermint/infra/src/lib.rs rename {fendermint/infra => infra}/Cargo.toml (100%) rename {fendermint/infra => infra}/Makefile.toml (100%) rename {fendermint/infra => infra}/docker-compose.yml (100%) diff --git a/docs/localnet.md b/docs/localnet.md index 076689cc..4a8b0bf6 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -1,10 +1,15 @@ # Local Testnets +Prerequisites: +```bash +make build +``` + ## Single node deployment -To run IPC in a rootnet just perform the following : +To run IPC in the local rootnet just perform the following : ```bash -cargo make --makefile ./fendermint/infra/Makefile.toml node +cargo make --makefile ./infra/Makefile.toml node ``` @@ -12,19 +17,19 @@ It will create three docker containers (cometbft, fendermint, and eth-api). To stop run the following: ```bash -cargo make --makefile ./fendermint/infra/Makefile.toml node-down +cargo make --makefile ./infra/Makefile.toml node-down ``` ## Local 4-nodes deployment -To run IPC in a rootnet with 4 nodes perform the following command : +To run IPC in the local rootnet with 4 nodes perform the following command : ```bash -cargo make --makefile ./fendermint/infra/Makefile.toml testnet +cargo make --makefile ./infra/Makefile.toml testnet ``` To stop the network: ```bash -cargo make --makefile ./fendermint/infra/Makefile.toml testnet-down +cargo make --makefile ./infra/Makefile.toml testnet-down ``` The testnet contains four logical nodes. Each node consists of cometbft, fendermint, and ethapi containers. diff --git a/fendermint/infra/scripts/init.sh b/fendermint/infra/scripts/init.sh deleted file mode 100755 index 584541a6..00000000 --- a/fendermint/infra/scripts/init.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# Create test artifacts, which is basically the Tendermint genesis file. - -CMT_DIR=/data/cometbft -FM_DIR=/data/fendermint - -KEYS_DIR=$FM_DIR/keys -GENESIS_FILE=$FM_DIR/genesis.json - -# Create a genesis file -fendermint genesis --genesis-file $GENESIS_FILE new --chain-name $FM_CHAIN_NAME --base-fee 1000 --timestamp 1680101412 - -# Create test keys -mkdir -p $KEYS_DIR -for NAME in alice bob charlie dave; do - fendermint key gen --out-dir $KEYS_DIR --name $NAME; -done - -# Create an account -fendermint \ - genesis --genesis-file $GENESIS_FILE \ - add-account --public-key $KEYS_DIR/alice.pk \ - --balance 1000 - -# Create a multisig account -fendermint \ - genesis --genesis-file $GENESIS_FILE \ - add-multisig --public-key $KEYS_DIR/bob.pk \ - --public-key $KEYS_DIR/charlie.pk \ - --public-key $KEYS_DIR/dave.pk \ - --threshold 2 --vesting-start 0 --vesting-duration 1000000 \ - --balance 3000 - -# Create some Ethereum accounts -for NAME in emily eric; do - fendermint key gen --out-dir $KEYS_DIR --name $NAME; - fendermint \ - genesis --genesis-file $GENESIS_FILE \ - add-account --public-key $KEYS_DIR/$NAME.pk \ - --balance 1000 \ - --kind ethereum -done - -# Add a validator -fendermint \ - genesis --genesis-file $GENESIS_FILE \ - add-validator --public-key $KEYS_DIR/bob.pk --power 1 - -# Enable IPC with some dummy values to test contract deployment. -fendermint \ - genesis --genesis-file $GENESIS_FILE \ - ipc gateway \ - --subnet-id /r0 \ - --top-down-check-period 10 \ - --bottom-up-check-period 10 \ - --msg-fee 10 \ - --majority-percentage 66 - -# Convert FM genesis to CMT -fendermint \ - genesis --genesis-file $GENESIS_FILE \ - into-tendermint --out $CMT_DIR/config/genesis.json - -# Convert FM validator key to CMT -fendermint \ - key into-tendermint --secret-key $KEYS_DIR/bob.sk \ - --out $CMT_DIR/config/priv_validator_key.json diff --git a/fendermint/infra/src/lib.rs b/fendermint/infra/src/lib.rs deleted file mode 100644 index 655b20f7..00000000 --- a/fendermint/infra/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2022-2023 Protocol Labs -// SPDX-License-Identifier: Apache-2.0, MIT -//! Run some tests against a pair of Fendermint and Tendermint docker containers running locally. -//! -//! Example: -//! -//! ```text -//! cd fendermint/testing/smoke-test -//! cargo make -//! ``` -//! -//! Make sure you installed cargo-make by running `cargo install cargo-make` first. diff --git a/fendermint/infra/Cargo.toml b/infra/Cargo.toml similarity index 100% rename from fendermint/infra/Cargo.toml rename to infra/Cargo.toml diff --git a/fendermint/infra/Makefile.toml b/infra/Makefile.toml similarity index 100% rename from fendermint/infra/Makefile.toml rename to infra/Makefile.toml diff --git a/fendermint/infra/docker-compose.yml b/infra/docker-compose.yml similarity index 100% rename from fendermint/infra/docker-compose.yml rename to infra/docker-compose.yml From 2a45713cbf7a9c46f6593347177119bd42d9df8f Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 12:46:57 +0200 Subject: [PATCH 12/40] Update docs/localnet.md Co-authored-by: Akosh Farkash --- docs/localnet.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/localnet.md b/docs/localnet.md index 4a8b0bf6..6ffd40f6 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -2,7 +2,7 @@ Prerequisites: ```bash -make build +make build docker-build ``` ## Single node deployment From d4f8e007a80102296a7749145af5643ba233135d Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 12:54:02 +0200 Subject: [PATCH 13/40] fix ports in docs --- docs/localnet.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/localnet.md b/docs/localnet.md index 6ffd40f6..f9a61b5f 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -37,9 +37,9 @@ The testnet network is `192.167.10.0/24`. ETH-API is accessible on the following interfaces: - `192.167.10.10:8545` -- `192.167.10.11:8546` -- `192.167.10.12:8547` -- `192.167.10.13:8548` +- `192.167.10.11:8545` +- `192.167.10.12:8545` +- `192.167.10.13:8545` ## Development From 5d84019a071ef2d42990cd8a70aa86824c6cc08d Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 12:54:34 +0200 Subject: [PATCH 14/40] Update docs/localnet.md Co-authored-by: Akosh Farkash --- docs/localnet.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/localnet.md b/docs/localnet.md index f9a61b5f..957e0201 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -51,4 +51,5 @@ The deployment process is as follows: - Create the `genesis` file for Fendermint - Share the genesis among all Fendermint nodes - Run Fendermint application in 4 containers +- Run CometBFT in 4 containers - Run Eth API in 4 containers \ No newline at end of file From d0f08c88edd421bdbb043cf9b49780b70b8afe31 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 12:56:18 +0200 Subject: [PATCH 15/40] use deployment --- docs/localnet.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/localnet.md b/docs/localnet.md index 957e0201..ec4db922 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -41,7 +41,7 @@ ETH-API is accessible on the following interfaces: - `192.167.10.12:8545` - `192.167.10.13:8545` -## Development +## Deployment process The deployment process is as follows: - Remove all docker containers, files, networks, etc. from the previous deployment From d1d5ba859faf1ddf66d4b86b1b1d9277bd6c5465 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 13:04:13 +0200 Subject: [PATCH 16/40] Update fendermint/app/src/cmd/key.rs Co-authored-by: Akosh Farkash --- fendermint/app/src/cmd/key.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fendermint/app/src/cmd/key.rs b/fendermint/app/src/cmd/key.rs index 2d2db580..90e36fbc 100644 --- a/fendermint/app/src/cmd/key.rs +++ b/fendermint/app/src/cmd/key.rs @@ -73,7 +73,7 @@ cmd! { cmd! { AddPeer(self) { let node_key = NodeKey::load_json_file(&self.node_key_file).unwrap(); - let peer_id : String = node_key.node_id().to_owned().to_string()+"@"+self.network_addr.as_str(); + let peer_id = format!("{}@{}", node_key.node_id(), self.network_addr); let peers = std::fs::read_to_string(&self.local_peers_file).context("failed to read peer file"); match peers { Ok(mut v) => { From 49eb9f4bdffa974a2bad3b2a4033a6ae6430bc9c Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 13:04:25 +0200 Subject: [PATCH 17/40] Update fendermint/app/src/cmd/key.rs Co-authored-by: Akosh Farkash --- fendermint/app/src/cmd/key.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fendermint/app/src/cmd/key.rs b/fendermint/app/src/cmd/key.rs index 90e36fbc..7414ce43 100644 --- a/fendermint/app/src/cmd/key.rs +++ b/fendermint/app/src/cmd/key.rs @@ -80,7 +80,7 @@ cmd! { if v.is_empty() { std::fs::write(&self.local_peers_file, peer_id)?; } else { - v = v.to_owned().to_string()+ "," + peer_id.as_str(); + v.push("," + peer_id.as_str()); std::fs::write(&self.local_peers_file, v)?; } } From 03b1ac5b2099276974c0294ab75197c03d0d9465 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 13:04:41 +0200 Subject: [PATCH 18/40] Update fendermint/app/src/options/key.rs Co-authored-by: Akosh Farkash --- fendermint/app/src/options/key.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fendermint/app/src/options/key.rs b/fendermint/app/src/options/key.rs index 11087972..eb83ead2 100644 --- a/fendermint/app/src/options/key.rs +++ b/fendermint/app/src/options/key.rs @@ -25,7 +25,7 @@ pub struct KeyArgs { #[derive(Args, Debug)] pub struct AddPeer { - /// The path to node key file. + /// The path to a CometBFT node key file. #[arg(long, short)] pub node_key_file: PathBuf, /// The path to a local file with persistent peers. From e7a124ede748991f9692c34db176834a0f8107ea Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 13:14:56 +0200 Subject: [PATCH 19/40] fix comments --- fendermint/app/src/cmd/key.rs | 5 +++-- fendermint/app/src/options/key.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fendermint/app/src/cmd/key.rs b/fendermint/app/src/cmd/key.rs index 7414ce43..d3be6ff7 100644 --- a/fendermint/app/src/cmd/key.rs +++ b/fendermint/app/src/cmd/key.rs @@ -72,7 +72,7 @@ cmd! { cmd! { AddPeer(self) { - let node_key = NodeKey::load_json_file(&self.node_key_file).unwrap(); + let node_key = NodeKey::load_json_file(&self.node_key_file).context("failed to read node key file")?; let peer_id = format!("{}@{}", node_key.node_id(), self.network_addr); let peers = std::fs::read_to_string(&self.local_peers_file).context("failed to read peer file"); match peers { @@ -85,7 +85,8 @@ cmd! { } } Err(_) => { - std::fs::write(&self.local_peers_file, peer_id)?;} + std::fs::write(&self.local_peers_file, peer_id)?; + } } Ok(()) } diff --git a/fendermint/app/src/options/key.rs b/fendermint/app/src/options/key.rs index eb83ead2..114ff44b 100644 --- a/fendermint/app/src/options/key.rs +++ b/fendermint/app/src/options/key.rs @@ -13,7 +13,7 @@ pub enum KeyCommands { IntoTendermint(KeyIntoTendermintArgs), /// Convert a public key file from base64 into an f1 Address format an print it to STDOUT. Address(KeyAddressArgs), - /// TBD + /// Get the peer ID corresponding to a node ID and its network address and print it to a local file. AddPeer(AddPeer), } From 7de41ad5914b2dc856a900925c71e3a9677e90cc Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 13:25:22 +0200 Subject: [PATCH 20/40] fix push --- fendermint/app/src/cmd/key.rs | 55 ++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/fendermint/app/src/cmd/key.rs b/fendermint/app/src/cmd/key.rs index d3be6ff7..92098f4a 100644 --- a/fendermint/app/src/cmd/key.rs +++ b/fendermint/app/src/cmd/key.rs @@ -18,14 +18,14 @@ use crate::{ }; cmd! { - KeyArgs(self) { - match &self.command { - KeyCommands::Gen(args) => args.exec(()).await, - KeyCommands::IntoTendermint(args) => args.exec(()).await, - KeyCommands::AddPeer(args) => args.exec(()).await, - KeyCommands::Address(args) => args.exec(()).await, + KeyArgs(self) { + match &self.command { + KeyCommands::Gen(args) => args.exec(()).await, + KeyCommands::IntoTendermint(args) => args.exec(()).await, + KeyCommands::AddPeer(args) => args.exec(()).await, + KeyCommands::Address(args) => args.exec(()).await, + } } - } } cmd! { @@ -71,34 +71,35 @@ cmd! { } cmd! { - AddPeer(self) { - let node_key = NodeKey::load_json_file(&self.node_key_file).context("failed to read node key file")?; - let peer_id = format!("{}@{}", node_key.node_id(), self.network_addr); - let peers = std::fs::read_to_string(&self.local_peers_file).context("failed to read peer file"); - match peers { - Ok(mut v) => { - if v.is_empty() { - std::fs::write(&self.local_peers_file, peer_id)?; - } else { - v.push("," + peer_id.as_str()); - std::fs::write(&self.local_peers_file, v)?; + AddPeer(self) { + let node_key = NodeKey::load_json_file(&self.node_key_file).context("failed to read node key file")?; + let peer_id = format!("{}@{}", node_key.node_id(), self.network_addr); + let peers = std::fs::read_to_string(&self.local_peers_file).context("failed to read peer file"); + match peers { + Ok(mut v) => { + if v.is_empty() { + std::fs::write(&self.local_peers_file, peer_id)?; + } else { + v.push_str(","); + v.push_str(peer_id.as_str()); + std::fs::write(&self.local_peers_file, v)?; + } } - } - Err(_) => { + Err(_) => { std::fs::write(&self.local_peers_file, peer_id)?; } } - Ok(()) + Ok(()) } } cmd! { - KeyAddressArgs(self) { - let pk = read_public_key(&self.public_key)?; - let addr = Address::new_secp256k1(&pk.serialize())?; - println!("{}", addr); - Ok(()) - } + KeyAddressArgs(self) { + let pk = read_public_key(&self.public_key)?; + let addr = Address::new_secp256k1(&pk.serialize())?; + println!("{}", addr); + Ok(()) + } } fn secret_to_b64(sk: &SecretKey) -> String { From ee33f10de572c970b1a4ae1a90f19d6f513c5175 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 14:22:17 +0200 Subject: [PATCH 21/40] fix comments --- fendermint/app/src/cmd/key.rs | 23 +++++++++-------------- fendermint/app/src/options/key.rs | 8 +++++--- infra/Makefile.toml | 6 +++--- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/fendermint/app/src/cmd/key.rs b/fendermint/app/src/cmd/key.rs index 92098f4a..91c041dc 100644 --- a/fendermint/app/src/cmd/key.rs +++ b/fendermint/app/src/cmd/key.rs @@ -74,21 +74,16 @@ cmd! { AddPeer(self) { let node_key = NodeKey::load_json_file(&self.node_key_file).context("failed to read node key file")?; let peer_id = format!("{}@{}", node_key.node_id(), self.network_addr); - let peers = std::fs::read_to_string(&self.local_peers_file).context("failed to read peer file"); - match peers { - Ok(mut v) => { - if v.is_empty() { - std::fs::write(&self.local_peers_file, peer_id)?; - } else { - v.push_str(","); - v.push_str(peer_id.as_str()); - std::fs::write(&self.local_peers_file, v)?; - } - } - Err(_) => { - std::fs::write(&self.local_peers_file, peer_id)?; - } + let mut peers = std::fs::read_to_string(&self.local_peers_file).unwrap_or_default(); + + if peers.is_empty() { + peers.push_str(&peer_id); + } else { + peers.push_str(","); + peers.push_str(peer_id.as_str()); } + + std::fs::write(&self.local_peers_file, peers).context("failed to write to the peers file")?; Ok(()) } } diff --git a/fendermint/app/src/options/key.rs b/fendermint/app/src/options/key.rs index 114ff44b..b399249d 100644 --- a/fendermint/app/src/options/key.rs +++ b/fendermint/app/src/options/key.rs @@ -26,12 +26,14 @@ pub struct KeyArgs { #[derive(Args, Debug)] pub struct AddPeer { /// The path to a CometBFT node key file. - #[arg(long, short)] + #[arg(long, short = 'n')] pub node_key_file: PathBuf, - /// The path to a local file with persistent peers. + /// The path to a temporal local file where the peer IDs will be added. + /// The file will be created if it doesn't exist. #[arg(long, short)] pub local_peers_file: PathBuf, - /// The path to a local file with persistent peers. + /// The target CometBFT node network interface in the following format `IP:Port`. + /// For example: `192.168.10.7:26656`. #[arg(long, short)] pub network_addr: String, } diff --git a/infra/Makefile.toml b/infra/Makefile.toml index cb0b8082..e2812a55 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -249,8 +249,8 @@ dependencies = [ [tasks.testnet-up] script = """ -export =`cat $BASE_TESTNET_DIR/peers` -docker compose -f ./fendermint/infra/docker-compose.yml up -d +export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` +docker compose -f ./infra/docker-compose.yml up -d """ [tasks.testnet-down] @@ -261,7 +261,7 @@ dependencies = [ [tasks.testnet-docker-compose-down] script = """ -docker compose -f ./fendermint/infra/docker-compose.yml down +docker compose -f ./infra/docker-compose.yml down """ [tasks.testnet-init] From 3cbb4dad3117331fe1aac4b61e2dfa95e8b31dff Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 14:33:58 +0200 Subject: [PATCH 22/40] fix push --- fendermint/app/src/cmd/key.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fendermint/app/src/cmd/key.rs b/fendermint/app/src/cmd/key.rs index 91c041dc..6715279b 100644 --- a/fendermint/app/src/cmd/key.rs +++ b/fendermint/app/src/cmd/key.rs @@ -79,7 +79,7 @@ cmd! { if peers.is_empty() { peers.push_str(&peer_id); } else { - peers.push_str(","); + peers.push(','); peers.push_str(peer_id.as_str()); } From 9794e8c0f3bc38b701eb63fd086442056e6c0b06 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 17:04:41 +0200 Subject: [PATCH 23/40] fix env --- infra/Makefile.toml | 1 + infra/docker-compose.yml | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/infra/Makefile.toml b/infra/Makefile.toml index e2812a55..2a9c48f6 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -250,6 +250,7 @@ dependencies = [ [tasks.testnet-up] script = """ export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` +export CHAIN_NAME=$CHAIN_NAME docker compose -f ./infra/docker-compose.yml up -d """ diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index 3a1c2983..08c168af 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -95,7 +95,7 @@ services: context: . environment: - FM_DATA_DIR=/data/fendermint/data - - FM_CHAIN_NAME=root + - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - ${HOME}/.ipc-testnet/node0:/data @@ -110,7 +110,7 @@ services: context: . environment: - FM_DATA_DIR=/data/fendermint/data - - FM_CHAIN_NAME=root + - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - ${HOME}/.ipc-testnet/node1:/data @@ -125,7 +125,7 @@ services: context: . environment: - FM_DATA_DIR=/data/fendermint/data - - FM_CHAIN_NAME=root + - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - ${HOME}/.ipc-testnet/node2:/data @@ -140,7 +140,7 @@ services: context: . environment: - FM_DATA_DIR=/data/fendermint/data - - FM_CHAIN_NAME=root + - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - ${HOME}/.ipc-testnet/node3:/data From 4f201bbc6e943df8c51c0e1bd3efdecd26d36960 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 17:11:52 +0200 Subject: [PATCH 24/40] Fix comments --- infra/Makefile.toml | 1 + infra/docker-compose.yml | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/infra/Makefile.toml b/infra/Makefile.toml index 2a9c48f6..4c9391ab 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -251,6 +251,7 @@ dependencies = [ script = """ export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` export CHAIN_NAME=$CHAIN_NAME +export BASE_TESTNET_DIR=$BASE_TESTNET_DIR docker compose -f ./infra/docker-compose.yml up -d """ diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index 08c168af..adcf2216 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -13,7 +13,7 @@ services: - CMT_PROXY_APP=tcp://fendermint-node0:26658 - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" volumes: - - ${HOME}/.ipc-testnet/node0/cometbft:/cometbft + - $BASE_TESTNET_DIR/node0/cometbft:/cometbft healthcheck: test: curl --fail http://localhost:26657 || exit 1 interval: 8s @@ -35,7 +35,7 @@ services: - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" - CMT_PROXY_APP=tcp://fendermint-node1:26658 volumes: - - ${HOME}/.ipc-testnet/node1/cometbft:/cometbft + - $BASE_TESTNET_DIR/node1/cometbft:/cometbft healthcheck: test: curl --fail http://localhost:26657 || exit 1 interval: 8s @@ -57,7 +57,7 @@ services: ports: - "26661-26662:26656-26657" volumes: - - ${HOME}/.ipc-testnet/node2/cometbft:/cometbft + - $BASE_TESTNET_DIR/node2/cometbft:/cometbft healthcheck: test: curl --fail http://localhost:26657 || exit 1 interval: 8s @@ -78,7 +78,7 @@ services: ports: - "26663-26664:26656-26657" volumes: - - ${HOME}/.ipc-testnet/node3/cometbft:/cometbft + - $BASE_TESTNET_DIR/node3/cometbft:/cometbft healthcheck: test: curl --fail http://localhost:26657 || exit 1 interval: 8s @@ -98,7 +98,7 @@ services: - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - - ${HOME}/.ipc-testnet/node0:/data + - $BASE_TESTNET_DIR/node0:/data networks: localnet: ipv4_address: 192.167.10.6 @@ -113,7 +113,7 @@ services: - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - - ${HOME}/.ipc-testnet/node1:/data + - $BASE_TESTNET_DIR/node1:/data networks: localnet: ipv4_address: 192.167.10.7 @@ -128,7 +128,7 @@ services: - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - - ${HOME}/.ipc-testnet/node2:/data + - $BASE_TESTNET_DIR/node2:/data networks: localnet: ipv4_address: 192.167.10.8 @@ -143,7 +143,7 @@ services: - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - - ${HOME}/.ipc-testnet/node3:/data + - $BASE_TESTNET_DIR/node3:/data networks: localnet: ipv4_address: 192.167.10.9 @@ -161,7 +161,7 @@ services: ports: - 8545:8545 volumes: - - ${HOME}/.ipc-testnet/node0:/data + - $BASE_TESTNET_DIR/node0:/data depends_on: cometbft-node0: condition: service_healthy @@ -182,7 +182,7 @@ services: ports: - 8546:8545 volumes: - - ${HOME}/.ipc-testnet/node1:/data + - $BASE_TESTNET_DIR/node1:/data depends_on: cometbft-node1: condition: service_healthy @@ -203,7 +203,7 @@ services: ports: - 8547:8545 volumes: - - ${HOME}/.ipc-testnet/node2:/data + - $BASE_TESTNET_DIR/node2:/data depends_on: cometbft-node2: condition: service_healthy @@ -224,7 +224,7 @@ services: ports: - 8548:8545 volumes: - - ${HOME}/.ipc-testnet/node3:/data + - $BASE_TESTNET_DIR/node3:/data depends_on: cometbft-node2: condition: service_healthy From bd884f894d34bcd646f9aeb1133859684eea504f Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 12 Sep 2023 20:09:16 +0200 Subject: [PATCH 25/40] Fix comments --- infra/.env | 1 + infra/Makefile.toml | 116 ++++++++++++++------------------------- infra/docker-compose.yml | 24 ++------ 3 files changed, 47 insertions(+), 94 deletions(-) create mode 100644 infra/.env diff --git a/infra/.env b/infra/.env new file mode 100644 index 00000000..6093e7d7 --- /dev/null +++ b/infra/.env @@ -0,0 +1 @@ +COMETBFT_VERSION=v0.37.x \ No newline at end of file diff --git a/infra/Makefile.toml b/infra/Makefile.toml index 4c9391ab..240b9ff4 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -83,6 +83,7 @@ echo echo 4 nodes testnet layout: echo - IPC directory: ${BASE_TESTNET_DIR} echo - Genesis file: ${GENESIS_FILE} +echo - Network: ${NETWORK_NAME} echo """ @@ -263,6 +264,7 @@ dependencies = [ [tasks.testnet-docker-compose-down] script = """ +export CMT_PERSISTENT_PEERS="UNDEFINED" docker compose -f ./infra/docker-compose.yml down """ @@ -288,24 +290,14 @@ rm -rf ${BASE_TESTNET_DIR} [tasks.testnet-mkdir] script=""" -echo creating directories: $BASE_DIR $FM_DIR $CMT_DIR mkdir -p $BASE_TESTNET_DIR mkdir -p $BASE_TESTNET_DIR/out -mkdir -p $BASE_TESTNET_DIR/node0 -mkdir -p $BASE_TESTNET_DIR/node1 -mkdir -p $BASE_TESTNET_DIR/node2 -mkdir -p $BASE_TESTNET_DIR/node3 - -mkdir -p $BASE_TESTNET_DIR/node0/fendermint -mkdir -p $BASE_TESTNET_DIR/node1/fendermint -mkdir -p $BASE_TESTNET_DIR/node2/fendermint -mkdir -p $BASE_TESTNET_DIR/node3/fendermint - -mkdir -p $BASE_TESTNET_DIR/node0/cometbft -mkdir -p $BASE_TESTNET_DIR/node1/cometbft -mkdir -p $BASE_TESTNET_DIR/node2/cometbft -mkdir -p $BASE_TESTNET_DIR/node3/cometbft +for i in $(seq 0 3); do + mkdir -p $BASE_TESTNET_DIR/node${i} + mkdir -p $BASE_TESTNET_DIR/node${i}/fendermint + mkdir -p $BASE_TESTNET_DIR/node${i}/cometbft +done """ [tasks.testnet-cometbft-init] @@ -341,7 +333,7 @@ dependencies = [ cwd = "./target/release" script = """ ./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json \ - new --chain-name testnet --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} + new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} cat $BASE_TESTNET_DIR/genesis.json """ @@ -349,68 +341,49 @@ cat $BASE_TESTNET_DIR/genesis.json [tasks.testnet-config-newkey] cwd = "./target/release" script=""" -mkdir -p $BASE_TESTNET_DIR/node0/fendermint/keys -mkdir -p $BASE_TESTNET_DIR/node1/fendermint/keys -mkdir -p $BASE_TESTNET_DIR/node2/fendermint/keys -mkdir -p $BASE_TESTNET_DIR/node3/fendermint/keys - -./fendermint key gen --out-dir $BASE_TESTNET_DIR/node0/fendermint/keys --name validator0_key -./fendermint key gen --out-dir $BASE_TESTNET_DIR/node1/fendermint/keys --name validator1_key -./fendermint key gen --out-dir $BASE_TESTNET_DIR/node2/fendermint/keys --name validator2_key -./fendermint key gen --out-dir $BASE_TESTNET_DIR/node3/fendermint/keys --name validator3_key - +for i in $(seq 0 3); do + mkdir -p $BASE_TESTNET_DIR/node${i}/fendermint/keys + ./fendermint key gen --out-dir $BASE_TESTNET_DIR/node${i}/fendermint/keys --name validator${i}_key +done """ [tasks.testnet-config-newaccount] cwd = "./target/release" script=""" +for i in $(seq 0 3); do ./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.pk --balance ${BALANCE} - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.pk --balance ${BALANCE} - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.pk --balance ${BALANCE} - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.pk --balance ${BALANCE} - -cat $BASE_TESTNET_DIR/genesis.json + --public-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.pk --balance ${BALANCE} +done """ [tasks.testnet-config-peers] cwd = "./target/release" script=""" -./fendermint key add-peer --node-key-file $BASE_TESTNET_DIR/node0/cometbft/config/node_key.json --network-addr 192.167.10.2:26656 --local-peers-file $BASE_TESTNET_DIR/peers -./fendermint key add-peer --node-key-file $BASE_TESTNET_DIR/node1/cometbft/config/node_key.json --network-addr 192.167.10.3:26656 --local-peers-file $BASE_TESTNET_DIR/peers -./fendermint key add-peer --node-key-file $BASE_TESTNET_DIR/node2/cometbft/config/node_key.json --network-addr 192.167.10.4:26656 --local-peers-file $BASE_TESTNET_DIR/peers -./fendermint key add-peer --node-key-file $BASE_TESTNET_DIR/node3/cometbft/config/node_key.json --network-addr 192.167.10.5:26656 --local-peers-file $BASE_TESTNET_DIR/peers +for i in $(seq 0 3); do + ./fendermint key add-peer \ + --node-key-file $BASE_TESTNET_DIR/node${i}/cometbft/config/node_key.json \ + --network-addr 192.167.10.$((${i}+2)):26656 \ + --local-peers-file $BASE_TESTNET_DIR/peers +done unset CMT_PERSISTENT_PEERS export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` echo Persistent peers: $CMT_PERSISTENT_PEERS -sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node0/cometbft/config/config.toml -sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node1/cometbft/config/config.toml -sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node2/cometbft/config/config.toml -sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node3/cometbft/config/config.toml +for i in $(seq 0 3); do + sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node${i}/cometbft/config/config.toml +done """ [tasks.testnet-config-newgateway] cwd = "./target/release" script = """ -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ - --public-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.pk --power 1 - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ - --public-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.pk --power 1 - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ - --public-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.pk --power 1 - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ - --public-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.pk --power 1 +for i in $(seq 0 3); do + ./fendermint genesis \ + --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ + --public-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.pk \ + --power 1 +done ./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json ipc gateway --subnet-id /r0 \ --top-down-check-period 10 \ @@ -418,31 +391,26 @@ script = """ --msg-fee 10 \ --majority-percentage 66 -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json into-tendermint --out $BASE_TESTNET_DIR/out/genesis.json - -./fendermint key into-tendermint --secret-key $BASE_TESTNET_DIR/node0/fendermint/keys/validator0_key.sk \ - --out $BASE_TESTNET_DIR/node0/cometbft/config/priv_validator_key.json - -./fendermint key into-tendermint --secret-key $BASE_TESTNET_DIR/node1/fendermint/keys/validator1_key.sk \ - --out $BASE_TESTNET_DIR/node1/cometbft/config/priv_validator_key.json +./fendermint genesis \ + --genesis-file $BASE_TESTNET_DIR/genesis.json into-tendermint \ + --out $BASE_TESTNET_DIR/out/genesis.json -./fendermint key into-tendermint --secret-key $BASE_TESTNET_DIR/node2/fendermint/keys/validator2_key.sk \ - --out $BASE_TESTNET_DIR/node2/cometbft/config/priv_validator_key.json - -./fendermint key into-tendermint --secret-key $BASE_TESTNET_DIR/node3/fendermint/keys/validator3_key.sk \ - --out $BASE_TESTNET_DIR/node3/cometbft/config/priv_validator_key.json +for i in $(seq 0 3); do + ./fendermint key into-tendermint \ + --secret-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.sk \ + --out $BASE_TESTNET_DIR/node${i}/cometbft/config/priv_validator_key.json +done +echo "GENESIS:" cat $BASE_TESTNET_DIR/genesis.json - """ [tasks.testnet-share-genesis] cwd = "./target/release" script = """ -cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node0/cometbft/config/genesis.json -cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node1/cometbft/config/genesis.json -cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node2/cometbft/config/genesis.json -cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node3/cometbft/config/genesis.json +for i in $(seq 0 3); do + cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node${i}/cometbft/config/genesis.json +done """ ######################################################################################################################## diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index adcf2216..5ad30ade 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -3,7 +3,7 @@ version: '3' services: cometbft-node0: container_name: cometbft-node0 - image: "cometbft/cometbft:v0.37.x" + image: "cometbft/cometbft:${COMETBFT_VERSION}" ports: - "26656-26657:26656-26657" environment: @@ -25,7 +25,7 @@ services: cometbft-node1: container_name: cometbft-node1 - image: "cometbft/cometbft:v0.37.x" + image: "cometbft/cometbft:${COMETBFT_VERSION}" ports: - "26659-26660:26656-26657" environment: @@ -47,7 +47,7 @@ services: cometbft-node2: container_name: cometbft-node2 - image: "cometbft/cometbft:v0.37.x" + image: "cometbft/cometbft:${COMETBFT_VERSION}" environment: - ID=2 - LOG=${LOG:-cometbft-node2.log} @@ -69,7 +69,7 @@ services: cometbft-node3: container_name: cometbft-node3 - image: "cometbft/cometbft:v0.37.x" + image: "cometbft/cometbft:${COMETBFT_VERSION}" environment: - ID=3 - LOG=${LOG:-cometbft-node3.log} @@ -91,8 +91,6 @@ services: fendermint-node0: container_name: fendermint-node0 image: "fendermint:latest" - build: - context: . environment: - FM_DATA_DIR=/data/fendermint/data - FM_CHAIN_NAME=$CHAIN_NAME @@ -106,8 +104,6 @@ services: fendermint-node1: container_name: fendermint-node1 image: "fendermint:latest" - build: - context: . environment: - FM_DATA_DIR=/data/fendermint/data - FM_CHAIN_NAME=$CHAIN_NAME @@ -121,8 +117,6 @@ services: fendermint-node2: container_name: fendermint-node2 image: "fendermint:latest" - build: - context: . environment: - FM_DATA_DIR=/data/fendermint/data - FM_CHAIN_NAME=$CHAIN_NAME @@ -136,8 +130,6 @@ services: fendermint-node3: container_name: fendermint-node3 image: "fendermint:latest" - build: - context: . environment: - FM_DATA_DIR=/data/fendermint/data - FM_CHAIN_NAME=$CHAIN_NAME @@ -152,8 +144,6 @@ services: container_name: ethapi-node0 image: "fendermint:latest" command: "eth run" - build: - context: . environment: - TENDERMINT_WS_URL=ws://cometbft-node0:26657/websocket - LOG_LEVEL=debug @@ -173,8 +163,6 @@ services: container_name: ethapi-node1 image: "fendermint:latest" command: "eth run" - build: - context: . environment: - TENDERMINT_WS_URL=ws://cometbft-node1:26657/websocket - LOG_LEVEL=debug @@ -194,8 +182,6 @@ services: container_name: ethapi-node2 image: "fendermint:latest" command: "eth run" - build: - context: . environment: - TENDERMINT_WS_URL=ws://cometbft-node2:26657/websocket - LOG_LEVEL=debug @@ -215,8 +201,6 @@ services: container_name: ethapi-node3 image: "fendermint:latest" command: "eth run" - build: - context: . environment: - TENDERMINT_WS_URL=ws://cometbft-node3:26657/websocket - LOG_LEVEL=debug From 51fee11629f2f88473c6eafa824e83d325ef4a94 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Wed, 13 Sep 2023 17:05:52 +0200 Subject: [PATCH 26/40] fix comments --- docs/localnet.md | 2 +- infra/Makefile.toml | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/localnet.md b/docs/localnet.md index ec4db922..3ce2c30d 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -33,7 +33,7 @@ cargo make --makefile ./infra/Makefile.toml testnet-down ``` The testnet contains four logical nodes. Each node consists of cometbft, fendermint, and ethapi containers. -The testnet network is `192.167.10.0/24`. +The testnet internal network is `192.167.10.0/24`. ETH-API is accessible on the following interfaces: - `192.167.10.10:8545` diff --git a/infra/Makefile.toml b/infra/Makefile.toml index 240b9ff4..b312db70 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -166,21 +166,25 @@ run_task = { name = [ "network-rm", ]} +# This task create all necessary data structures to run Fendermint: +# the genesis file with necessary entities and cryptographic keys. [tasks.node-config] dependencies = [ - "fendermint-newgenesis", - "fendermint-newkey", - "fendermint-newaccount", - "fendermint-newgateway", + "fendermint-new-genesis", + "fendermint-new-key", + "fendermint-new-account", + "fendermint-add-validator", + "fendermint-new-gateway", + "fendermint-export-keys" ] -[tasks.fendermint-newgenesis] +[tasks.fendermint-new-genesis] cwd = "./target/release" script = """ ./fendermint genesis --genesis-file ${GENESIS_FILE} new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} """ -[tasks.fendermint-newkey] +[tasks.fendermint-new-key] cwd = "./target/release" script=""" mkdir -p $KEYS_DIR @@ -189,24 +193,32 @@ mkdir -p $KEYS_DIR chmod 600 ${PRIV_KEY_PATH} """ -[tasks.fendermint-newaccount] +[tasks.fendermint-new-account] cwd = "./target/release" script=""" ./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} """ -[tasks.fendermint-newgateway] +[tasks.fendermint-add-validator] cwd = "./target/release" script = """ ./fendermint genesis --genesis-file ${GENESIS_FILE} add-validator --public-key ${PUB_KEY_PATH} --power 1 +""" +[tasks.fendermint-new-gateway] +cwd = "./target/release" +script = """ ./fendermint genesis --genesis-file ${GENESIS_FILE} ipc gateway --subnet-id /r0 \ --top-down-check-period 10 \ --bottom-up-check-period 10 \ --msg-fee 10 \ --majority-percentage 66 +""" +[tasks.fendermint-export-keys] +cwd = "./target/release" +script = """ ./fendermint genesis --genesis-file ${GENESIS_FILE} into-tendermint --out ${CMT_DIR}/config/genesis.json ./fendermint key into-tendermint --secret-key ${PRIV_KEY_PATH} --out ${CMT_DIR}/config/priv_validator_key.json From 075e26feace7ce2a208697a4778c7307fa261626 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Wed, 13 Sep 2023 18:12:55 +0200 Subject: [PATCH 27/40] fox comments --- docs/localnet.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/localnet.md b/docs/localnet.md index 3ce2c30d..2e9b0a87 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -33,14 +33,20 @@ cargo make --makefile ./infra/Makefile.toml testnet-down ``` The testnet contains four logical nodes. Each node consists of cometbft, fendermint, and ethapi containers. -The testnet internal network is `192.167.10.0/24`. +The Docker internal network is `192.167.10.0/24`. -ETH-API is accessible on the following interfaces: +ETH-API is accessible on the following interfaces on the Docker internal network: - `192.167.10.10:8545` - `192.167.10.11:8545` - `192.167.10.12:8545` - `192.167.10.13:8545` +and on the following interfaces from the host machine: +- `127.0.0.1:8545` +- `127.0.0.1:8546` +- `127.0.0.1:8547` +- `127.0.0.1:8548` + ## Deployment process The deployment process is as follows: From 1e9e9c2f6e75680c7c94de8a412f2c5a0e8ee996 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Thu, 14 Sep 2023 18:53:52 +0200 Subject: [PATCH 28/40] fix docs --- docs/localnet.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/localnet.md b/docs/localnet.md index 2e9b0a87..bb4f7770 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -36,10 +36,10 @@ The testnet contains four logical nodes. Each node consists of cometbft, fenderm The Docker internal network is `192.167.10.0/24`. ETH-API is accessible on the following interfaces on the Docker internal network: -- `192.167.10.10:8545` -- `192.167.10.11:8545` -- `192.167.10.12:8545` -- `192.167.10.13:8545` +- `192.167.10.10:8545` or `ethapi-node0:8545` +- `192.167.10.11:8545` or `ethapi-node1:8545` +- `192.167.10.12:8545` or `ethapi-node2:8545` +- `192.167.10.13:8545` or `ethapi-node3:8545` and on the following interfaces from the host machine: - `127.0.0.1:8545` From d0d0eb36e1ac2ae0f00a7c394fb5d7670d8eee7c Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Mon, 18 Sep 2023 21:30:34 +0200 Subject: [PATCH 29/40] add user --- infra/docker-compose.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index 5ad30ade..4a022368 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -3,6 +3,7 @@ version: '3' services: cometbft-node0: container_name: cometbft-node0 + user: ${UID}:${GID} image: "cometbft/cometbft:${COMETBFT_VERSION}" ports: - "26656-26657:26656-26657" @@ -25,6 +26,7 @@ services: cometbft-node1: container_name: cometbft-node1 + user: ${UID}:${GID} image: "cometbft/cometbft:${COMETBFT_VERSION}" ports: - "26659-26660:26656-26657" @@ -47,6 +49,7 @@ services: cometbft-node2: container_name: cometbft-node2 + user: ${UID}:${GID} image: "cometbft/cometbft:${COMETBFT_VERSION}" environment: - ID=2 @@ -69,6 +72,7 @@ services: cometbft-node3: container_name: cometbft-node3 + user: ${UID}:${GID} image: "cometbft/cometbft:${COMETBFT_VERSION}" environment: - ID=3 @@ -90,6 +94,7 @@ services: fendermint-node0: container_name: fendermint-node0 + user: ${UID}:${GID} image: "fendermint:latest" environment: - FM_DATA_DIR=/data/fendermint/data @@ -103,6 +108,7 @@ services: fendermint-node1: container_name: fendermint-node1 + user: ${UID}:${GID} image: "fendermint:latest" environment: - FM_DATA_DIR=/data/fendermint/data @@ -116,6 +122,7 @@ services: fendermint-node2: container_name: fendermint-node2 + user: ${UID}:${GID} image: "fendermint:latest" environment: - FM_DATA_DIR=/data/fendermint/data @@ -129,6 +136,7 @@ services: fendermint-node3: container_name: fendermint-node3 + user: ${UID}:${GID} image: "fendermint:latest" environment: - FM_DATA_DIR=/data/fendermint/data @@ -142,6 +150,7 @@ services: ethapi-node0: container_name: ethapi-node0 + user: ${UID}:${GID} image: "fendermint:latest" command: "eth run" environment: @@ -161,6 +170,7 @@ services: ethapi-node1: container_name: ethapi-node1 + user: ${UID}:${GID} image: "fendermint:latest" command: "eth run" environment: @@ -180,6 +190,7 @@ services: ethapi-node2: container_name: ethapi-node2 + user: ${UID}:${GID} image: "fendermint:latest" command: "eth run" environment: @@ -199,6 +210,7 @@ services: ethapi-node3: container_name: ethapi-node3 + user: ${UID}:${GID} image: "fendermint:latest" command: "eth run" environment: From b69fcccc4366d06470f7e42a92c12e95d447adb0 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Mon, 18 Sep 2023 21:49:59 +0200 Subject: [PATCH 30/40] add UID GID --- infra/Makefile.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/infra/Makefile.toml b/infra/Makefile.toml index b312db70..635d1168 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -163,7 +163,7 @@ run_task = { name = [ "fendermint-rm", "ethapi-stop", "ethapi-rm", - "network-rm", + "network-rm" ]} # This task create all necessary data structures to run Fendermint: @@ -262,6 +262,8 @@ dependencies = [ [tasks.testnet-up] script = """ +if [ -z $GID ]; then export GID=$(id -g); fi +if [ -z $UID ]; then export UID=$(id -u); fi export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` export CHAIN_NAME=$CHAIN_NAME export BASE_TESTNET_DIR=$BASE_TESTNET_DIR @@ -271,7 +273,7 @@ docker compose -f ./infra/docker-compose.yml up -d [tasks.testnet-down] dependencies = [ "testnet-docker-compose-down", - "network-rm" + "network-rm", ] [tasks.testnet-docker-compose-down] From 26ae8676a28742dd6f292fe56ccbd18160edc986 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Mon, 18 Sep 2023 21:55:47 +0200 Subject: [PATCH 31/40] add UID GID --- infra/Makefile.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infra/Makefile.toml b/infra/Makefile.toml index 635d1168..16eeb60a 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -279,6 +279,8 @@ dependencies = [ [tasks.testnet-docker-compose-down] script = """ export CMT_PERSISTENT_PEERS="UNDEFINED" +if [ -z $GID ]; then export GID=$(id -g); fi +if [ -z $UID ]; then export UID=$(id -u); fi docker compose -f ./infra/docker-compose.yml down """ From 809f2592a541bb56fa47554641d71877928f726b Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 19 Sep 2023 18:58:58 +0200 Subject: [PATCH 32/40] use extend --- infra/Makefile.toml | 483 +--------------------------------- infra/scripts/cometbft.toml | 43 +++ infra/scripts/docker.toml | 24 ++ infra/scripts/ethapi.toml | 32 +++ infra/scripts/examples.toml | 16 ++ infra/scripts/fendermint.toml | 24 ++ infra/scripts/node.toml | 136 ++++++++++ infra/scripts/testnet.toml | 180 +++++++++++++ 8 files changed, 465 insertions(+), 473 deletions(-) create mode 100644 infra/scripts/cometbft.toml create mode 100644 infra/scripts/docker.toml create mode 100644 infra/scripts/ethapi.toml create mode 100644 infra/scripts/examples.toml create mode 100644 infra/scripts/fendermint.toml create mode 100644 infra/scripts/node.toml create mode 100644 infra/scripts/testnet.toml diff --git a/infra/Makefile.toml b/infra/Makefile.toml index 16eeb60a..1f2e0cf5 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -1,3 +1,13 @@ +extend = [ + { path = "scripts/docker.toml" }, + { path = "scripts/cometbft.toml" }, + { path = "scripts/fendermint.toml" }, + { path = "scripts/ethapi.toml" }, + { path = "scripts/node.toml" }, + { path = "scripts/testnet.toml" }, + { path = "scripts/examples.toml" }, +] + [config] default_to_workspace = false @@ -22,7 +32,6 @@ PRIV_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.sk" NETWORK_NAME = "${CHAIN_NAME}" - CMT_CONTAINER_NAME = "${NETWORK_NAME}-cometbft" FM_CONTAINER_NAME = "${NETWORK_NAME}-fendermint" ETHAPI_CONTAINER_NAME = "${NETWORK_NAME}-ethapi" @@ -109,475 +118,3 @@ script = [''' echo Run 'cargo make --list-all-steps' for a complete list of available tasks. echo '''] - -######################################################################################################################## -# Single node -######################################################################################################################## -[tasks.node] -workspace = false -dependencies = [ - "node-down", - "node-init", - "node-network-create", - "cometbft-init", - "fendermint-deps", - "node-config", - "fendermint-start", - "cometbft-start", - "cometbft-wait", - "ethapi-start" -] - -[tasks.node-network-create] -env = { "NETWORK_NAME"="${NETWORK_NAME}"} -extend = "network-create" - - -[tasks.node-init] -dependencies = [ - "node-clear", - "node-mkdir", -] - -[tasks.node-clear] -script=""" -echo clearing all IPC data -rm -rf ${BASE_DIR} -""" - -[tasks.node-mkdir] -script=""" -echo creating directories: $BASE_DIR $FM_DIR $CMT_DIR -mkdir -p $BASE_DIR -mkdir -p $FM_DIR - -mkdir -p $CMT_DIR -""" - -[tasks.node-down] -# `dependencies` doesn't seem to work with `cleanup_task`. -run_task = { name = [ - "cometbft-stop", - "cometbft-rm", - "fendermint-stop", - "fendermint-rm", - "ethapi-stop", - "ethapi-rm", - "network-rm" -]} - -# This task create all necessary data structures to run Fendermint: -# the genesis file with necessary entities and cryptographic keys. -[tasks.node-config] -dependencies = [ - "fendermint-new-genesis", - "fendermint-new-key", - "fendermint-new-account", - "fendermint-add-validator", - "fendermint-new-gateway", - "fendermint-export-keys" -] - -[tasks.fendermint-new-genesis] -cwd = "./target/release" -script = """ -./fendermint genesis --genesis-file ${GENESIS_FILE} new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} -""" - -[tasks.fendermint-new-key] -cwd = "./target/release" -script=""" -mkdir -p $KEYS_DIR - -./fendermint key gen --out-dir $KEYS_DIR --name $KEY_NAME; -chmod 600 ${PRIV_KEY_PATH} -""" - -[tasks.fendermint-new-account] -cwd = "./target/release" -script=""" -./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} -""" - - -[tasks.fendermint-add-validator] -cwd = "./target/release" -script = """ -./fendermint genesis --genesis-file ${GENESIS_FILE} add-validator --public-key ${PUB_KEY_PATH} --power 1 -""" - -[tasks.fendermint-new-gateway] -cwd = "./target/release" -script = """ -./fendermint genesis --genesis-file ${GENESIS_FILE} ipc gateway --subnet-id /r0 \ - --top-down-check-period 10 \ - --bottom-up-check-period 10 \ - --msg-fee 10 \ - --majority-percentage 66 -""" - -[tasks.fendermint-export-keys] -cwd = "./target/release" -script = """ -./fendermint genesis --genesis-file ${GENESIS_FILE} into-tendermint --out ${CMT_DIR}/config/genesis.json - -./fendermint key into-tendermint --secret-key ${PRIV_KEY_PATH} --out ${CMT_DIR}/config/priv_validator_key.json -chmod 600 ${CMT_DIR}/config/priv_validator_key.json -""" - -[tasks.fendermint-start] -extend = "fendermint-run" -env = { "ENTRY" = "fendermint", "CMD" = "run", "FLAGS" = "-d" } - -[tasks.fendermint-run] -script = """ -docker run \ - ${FLAGS} \ - --name ${FM_CONTAINER_NAME} \ - --init \ - --user $(id -u) \ - --network ${NETWORK_NAME} \ - --volume ${BASE_DIR}:/data \ - --env FM_DATA_DIR=/data/fendermint/data \ - --env FM_CHAIN_NAME=${NETWORK_NAME} \ - --env LOG_LEVEL=info \ - --entrypoint ${ENTRY} \ - ${FM_DOCKER_IMAGE} \ - ${CMD} -""" -dependencies = ["network-create", "fendermint-deps"] - -######################################################################################################################## -# Testnet node -######################################################################################################################## - -[tasks.testnet] -dependencies = [ - "testnet-down", - "testnet-init", - "fendermint-deps", - "testnet-fendermint-config", - "testnet-up" -] - -[tasks.testnet-up] -script = """ -if [ -z $GID ]; then export GID=$(id -g); fi -if [ -z $UID ]; then export UID=$(id -u); fi -export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` -export CHAIN_NAME=$CHAIN_NAME -export BASE_TESTNET_DIR=$BASE_TESTNET_DIR -docker compose -f ./infra/docker-compose.yml up -d -""" - -[tasks.testnet-down] -dependencies = [ - "testnet-docker-compose-down", - "network-rm", -] - -[tasks.testnet-docker-compose-down] -script = """ -export CMT_PERSISTENT_PEERS="UNDEFINED" -if [ -z $GID ]; then export GID=$(id -g); fi -if [ -z $UID ]; then export UID=$(id -u); fi -docker compose -f ./infra/docker-compose.yml down -""" - -[tasks.testnet-init] -dependencies = [ - "testnet-clear", - "testnet-network-create", - "cometbft-pull", - "testnet-mkdir", - "testnet-cometbft-init", - "testnet-mkdir", -] - -[tasks.testnet-network-create] -env = { "NETWORK_NAME"="${NETWORK_NAME}"} -extend = "network-create" - -[tasks.testnet-clear] -script=""" -echo clearing all IPC data -rm -rf ${BASE_TESTNET_DIR} -""" - -[tasks.testnet-mkdir] -script=""" -mkdir -p $BASE_TESTNET_DIR -mkdir -p $BASE_TESTNET_DIR/out - -for i in $(seq 0 3); do - mkdir -p $BASE_TESTNET_DIR/node${i} - mkdir -p $BASE_TESTNET_DIR/node${i}/fendermint - mkdir -p $BASE_TESTNET_DIR/node${i}/cometbft -done -""" - -[tasks.testnet-cometbft-init] -dependencies = ["testnet-cometbft-init-node0", "testnet-cometbft-init-node1", "testnet-cometbft-init-node2", "testnet-cometbft-init-node3"] - -[tasks.testnet-cometbft-init-node0] -extend = "cometbft-init" -env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node0/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node0", "FLAGS" = "-a STDOUT -a STDERR --rm"} - -[tasks.testnet-cometbft-init-node1] -extend = "cometbft-init" -env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node1/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node1", "FLAGS" = "-a STDOUT -a STDERR --rm" } - -[tasks.testnet-cometbft-init-node2] -extend = "cometbft-init" -env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node2/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node2", "FLAGS" = "-a STDOUT -a STDERR --rm" } - -[tasks.testnet-cometbft-init-node3] -extend = "cometbft-init" -env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node3/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node3", "FLAGS" = "-a STDOUT -a STDERR --rm" } - -[tasks.testnet-fendermint-config] -dependencies = [ - "testnet-config-newgenesis", - "testnet-config-peers", - "testnet-config-newkey", - "testnet-config-newaccount", - "testnet-config-newgateway", - "testnet-share-genesis" -] - -[tasks.testnet-config-newgenesis] -cwd = "./target/release" -script = """ -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json \ - new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} - -cat $BASE_TESTNET_DIR/genesis.json -""" - -[tasks.testnet-config-newkey] -cwd = "./target/release" -script=""" -for i in $(seq 0 3); do - mkdir -p $BASE_TESTNET_DIR/node${i}/fendermint/keys - ./fendermint key gen --out-dir $BASE_TESTNET_DIR/node${i}/fendermint/keys --name validator${i}_key -done -""" - -[tasks.testnet-config-newaccount] -cwd = "./target/release" -script=""" -for i in $(seq 0 3); do -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.pk --balance ${BALANCE} -done -""" - -[tasks.testnet-config-peers] -cwd = "./target/release" -script=""" -for i in $(seq 0 3); do - ./fendermint key add-peer \ - --node-key-file $BASE_TESTNET_DIR/node${i}/cometbft/config/node_key.json \ - --network-addr 192.167.10.$((${i}+2)):26656 \ - --local-peers-file $BASE_TESTNET_DIR/peers -done - -unset CMT_PERSISTENT_PEERS -export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` -echo Persistent peers: $CMT_PERSISTENT_PEERS - -for i in $(seq 0 3); do - sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node${i}/cometbft/config/config.toml -done -""" - -[tasks.testnet-config-newgateway] -cwd = "./target/release" -script = """ -for i in $(seq 0 3); do - ./fendermint genesis \ - --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ - --public-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.pk \ - --power 1 -done - -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json ipc gateway --subnet-id /r0 \ - --top-down-check-period 10 \ - --bottom-up-check-period 10 \ - --msg-fee 10 \ - --majority-percentage 66 - -./fendermint genesis \ - --genesis-file $BASE_TESTNET_DIR/genesis.json into-tendermint \ - --out $BASE_TESTNET_DIR/out/genesis.json - -for i in $(seq 0 3); do - ./fendermint key into-tendermint \ - --secret-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.sk \ - --out $BASE_TESTNET_DIR/node${i}/cometbft/config/priv_validator_key.json -done - -echo "GENESIS:" -cat $BASE_TESTNET_DIR/genesis.json -""" - -[tasks.testnet-share-genesis] -cwd = "./target/release" -script = """ -for i in $(seq 0 3); do - cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node${i}/cometbft/config/genesis.json -done -""" - -######################################################################################################################## -# Apps -######################################################################################################################## - -[tasks.simplecoin-example] -# Using --release in the hope that it can reuse artifacts compiled earlier for the docker build. -script = """ -cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} -cargo run -p fendermint_rpc --release --example simplecoin -- \ - --secret-key fendermint/testing/smoke-test/test-data/fendermint/keys/alice.sk \ - ${VERBOSITY} -""" - -[tasks.ethapi-example] -script = """ -cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} -cargo run -p fendermint_eth_api --release --example ethers -- \ - --secret-key-from fendermint/testing/smoke-test/test-data/fendermint/keys/emily.sk \ - --secret-key-to fendermint/testing/smoke-test/test-data/fendermint/keys/eric.sk -""" - -######################################################################################################################## -# Primitives -######################################################################################################################## - -[tasks.cometbft-pull] -command = "docker" -args = ["pull", "${CMT_DOCKER_IMAGE}"] - -[tasks.cometbft-init] -extend = "cometbft-run" -env = { "CMD" = "init", "FLAGS" = "-a STDOUT -a STDERR --rm" } - -[tasks.cometbft-start] -extend = "cometbft-run" -env = { "CMD" = "start", "FLAGS" = "-d" } - -[tasks.cometbft-wait] -extend = "wait" -env = { "CARGO_MAKE_WAIT_MILLISECONDS" = "${CMT_WAIT_MILLIS}" } - -[tasks.cometbft-run] -script = """ -docker run \ - ${FLAGS} \ - --name ${CMT_CONTAINER_NAME} \ - --user $(id -u) \ - --network ${NETWORK_NAME} \ - --publish 26657:${CMT_HOST_PORT} \ - --volume ${CMT_DIR}:/cometbft \ - --env CMT_PROXY_APP=tcp://${FM_CONTAINER_NAME}:26658 \ - --env CMT_PEX=false \ - ${CMT_DOCKER_IMAGE} \ - ${CMD} -""" -dependencies = ["cometbft-pull", "network-create"] - -[tasks.cometbft-rm] -extend = "docker-rm" -env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } - -[tasks.cometbft-stop] -extend = "docker-stop" -env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } - -[tasks.cometbft-logs] -extend = "docker-logs" -env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } - -[tasks.fendermint-deps] -script = """ -# Check if the image exists -# TODO: Check the version or use a flag to always re-build? -if docker images | awk '{print $1":"$2}' | grep fendermint; then - echo fendermint image already exists - docker images | grep fendermint -else - cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} - make docker-build -fi -""" - -[tasks.ethapi-start] -extend = "ethapi-run" -env = { "CMD" = "eth run", "FLAGS" = "-d" } - - -[tasks.ethapi-run] -script = """ -docker run \ - ${FLAGS} \ - --name ${ETHAPI_CONTAINER_NAME} \ - --init \ - --user $(id -u) \ - --network ${NETWORK_NAME} \ - --publish 8545:${ETHAPI_HOST_PORT} \ - --env TENDERMINT_WS_URL=ws://${CMT_CONTAINER_NAME}:26657/websocket \ - --env LOG_LEVEL=debug \ - --env RUST_BACKTRACE=1 \ - ${FM_DOCKER_IMAGE} \ - ${CMD} -""" -dependencies = ["network-create"] - -[tasks.network-create] -command = "docker" -args = ["network", "create", "${NETWORK_NAME}"] -ignore_errors = true - -[tasks.network-rm] -command = "docker" -args = ["network", "rm", "${NETWORK_NAME}"] -ignore_errors = true - -[tasks.fendermint-rm] -extend = "docker-rm" -env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } - -[tasks.fendermint-stop] -extend = "docker-stop" -env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } - -[tasks.ethapi-rm] -extend = "docker-rm" -env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } - -[tasks.ethapi-stop] -extend = "docker-stop" -env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } - -[tasks.ethapi-logs] -extend = "docker-logs" -env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } - -[tasks.fendermint-logs] -extend = "docker-logs" -env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } - -[tasks.docker-stop] -command = "docker" -args = ["stop", "${CONTAINER_NAME}"] -ignore_errors = true - -[tasks.docker-rm] -command = "docker" -args = ["rm", "--force", "${CONTAINER_NAME}"] -ignore_errors = true - -[tasks.docker-logs] -command = "docker" -args = ["logs", "${CONTAINER_NAME}"] -ignore_errors = true diff --git a/infra/scripts/cometbft.toml b/infra/scripts/cometbft.toml new file mode 100644 index 00000000..987a40ca --- /dev/null +++ b/infra/scripts/cometbft.toml @@ -0,0 +1,43 @@ +[tasks.cometbft-pull] +command = "docker" +args = ["pull", "${CMT_DOCKER_IMAGE}"] + +[tasks.cometbft-init] +extend = "cometbft-run" +env = { "CMD" = "init", "FLAGS" = "-a STDOUT -a STDERR --rm" } + +[tasks.cometbft-start] +extend = "cometbft-run" +env = { "CMD" = "start", "FLAGS" = "-d" } + +[tasks.cometbft-wait] +extend = "wait" +env = { "CARGO_MAKE_WAIT_MILLISECONDS" = "${CMT_WAIT_MILLIS}" } + +[tasks.cometbft-run] +script = """ +docker run \ + ${FLAGS} \ + --name ${CMT_CONTAINER_NAME} \ + --user $(id -u) \ + --network ${NETWORK_NAME} \ + --publish 26657:${CMT_HOST_PORT} \ + --volume ${CMT_DIR}:/cometbft \ + --env CMT_PROXY_APP=tcp://${FM_CONTAINER_NAME}:26658 \ + --env CMT_PEX=false \ + ${CMT_DOCKER_IMAGE} \ + ${CMD} +""" +dependencies = ["cometbft-pull", "docker-network-create"] + +[tasks.cometbft-rm] +extend = "docker-rm" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.cometbft-stop] +extend = "docker-stop" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } + +[tasks.cometbft-logs] +extend = "docker-logs" +env = { "CONTAINER_NAME" = "${CMT_CONTAINER_NAME}" } \ No newline at end of file diff --git a/infra/scripts/docker.toml b/infra/scripts/docker.toml new file mode 100644 index 00000000..7c8cc75c --- /dev/null +++ b/infra/scripts/docker.toml @@ -0,0 +1,24 @@ +[tasks.docker-network-create] +command = "docker" +args = ["network", "create", "${NETWORK_NAME}"] +ignore_errors = true + +[tasks.docker-network-rm] +command = "docker" +args = ["network", "rm", "${NETWORK_NAME}"] +ignore_errors = true + +[tasks.docker-stop] +command = "docker" +args = ["stop", "${CONTAINER_NAME}"] +ignore_errors = true + +[tasks.docker-rm] +command = "docker" +args = ["rm", "--force", "${CONTAINER_NAME}"] +ignore_errors = true + +[tasks.docker-logs] +command = "docker" +args = ["logs", "${CONTAINER_NAME}"] +ignore_errors = true diff --git a/infra/scripts/ethapi.toml b/infra/scripts/ethapi.toml new file mode 100644 index 00000000..29ab0d96 --- /dev/null +++ b/infra/scripts/ethapi.toml @@ -0,0 +1,32 @@ +[tasks.ethapi-run] +script = """ +docker run \ + ${FLAGS} \ + --name ${ETHAPI_CONTAINER_NAME} \ + --init \ + --user $(id -u) \ + --network ${NETWORK_NAME} \ + --publish 8545:${ETHAPI_HOST_PORT} \ + --env TENDERMINT_WS_URL=ws://${CMT_CONTAINER_NAME}:26657/websocket \ + --env LOG_LEVEL=debug \ + --env RUST_BACKTRACE=1 \ + ${FM_DOCKER_IMAGE} \ + ${CMD} +""" +dependencies = ["docker-network-create"] + +[tasks.ethapi-start] +extend = "ethapi-run" +env = { "CMD" = "eth run", "FLAGS" = "-d" } + +[tasks.ethapi-rm] +extend = "docker-rm" +env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } + +[tasks.ethapi-stop] +extend = "docker-stop" +env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } + +[tasks.ethapi-logs] +extend = "docker-logs" +env = { "CONTAINER_NAME" = "${ETHAPI_CONTAINER_NAME}" } \ No newline at end of file diff --git a/infra/scripts/examples.toml b/infra/scripts/examples.toml new file mode 100644 index 00000000..07b09fdc --- /dev/null +++ b/infra/scripts/examples.toml @@ -0,0 +1,16 @@ +[tasks.simplecoin-example] +# Using --release in the hope that it can reuse artifacts compiled earlier for the docker build. +script = """ +cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} +cargo run -p fendermint_rpc --release --example simplecoin -- \ + --secret-key fendermint/testing/smoke-test/test-data/fendermint/keys/alice.sk \ + ${VERBOSITY} +""" + +[tasks.ethapi-example] +script = """ +cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} +cargo run -p fendermint_eth_api --release --example ethers -- \ + --secret-key-from fendermint/testing/smoke-test/test-data/fendermint/keys/emily.sk \ + --secret-key-to fendermint/testing/smoke-test/test-data/fendermint/keys/eric.sk +""" \ No newline at end of file diff --git a/infra/scripts/fendermint.toml b/infra/scripts/fendermint.toml new file mode 100644 index 00000000..53154e18 --- /dev/null +++ b/infra/scripts/fendermint.toml @@ -0,0 +1,24 @@ +[tasks.fendermint-deps] +script = """ +# Check if the image exists +# TODO: Check the version or use a flag to always re-build? +if docker images | awk '{print $1":"$2}' | grep fendermint; then + echo fendermint image already exists + docker images | grep fendermint +else + cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} + make docker-build +fi +""" + +[tasks.fendermint-rm] +extend = "docker-rm" +env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } + +[tasks.fendermint-stop] +extend = "docker-stop" +env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } + +[tasks.fendermint-logs] +extend = "docker-logs" +env = { "CONTAINER_NAME" = "${FM_CONTAINER_NAME}" } \ No newline at end of file diff --git a/infra/scripts/node.toml b/infra/scripts/node.toml new file mode 100644 index 00000000..3d77cd72 --- /dev/null +++ b/infra/scripts/node.toml @@ -0,0 +1,136 @@ +######################################################################################################################## +# Single node +######################################################################################################################## +[tasks.node] +workspace = false +dependencies = [ + "node-down", + "node-init", + "node-network-create", + "cometbft-init", + "fendermint-deps", + "node-config", + "fendermint-start", + "cometbft-start", + "cometbft-wait", + "ethapi-start" +] + +[tasks.node-network-create] +env = { "NETWORK_NAME"="${NETWORK_NAME}"} +extend = "docker-network-create" + + +[tasks.node-init] +dependencies = [ + "node-clear", + "node-mkdir", +] + +[tasks.node-clear] +script=""" +echo clearing all IPC data +rm -rf ${BASE_DIR} +""" + +[tasks.node-mkdir] +script=""" +echo creating directories: $BASE_DIR $FM_DIR $CMT_DIR +mkdir -p $BASE_DIR +mkdir -p $FM_DIR + +mkdir -p $CMT_DIR +""" + +[tasks.node-down] +# `dependencies` doesn't seem to work with `cleanup_task`. +run_task = { name = [ + "cometbft-stop", + "cometbft-rm", + "fendermint-stop", + "fendermint-rm", + "ethapi-stop", + "ethapi-rm", + "docker-network-rm" +]} + +# This task create all necessary data structures to run Fendermint: +# the genesis file with necessary entities and cryptographic keys. +[tasks.node-config] +dependencies = [ + "fendermint-new-genesis", + "fendermint-new-key", + "fendermint-new-account", + "fendermint-add-validator", + "fendermint-new-gateway", + "fendermint-export-keys" +] + +[tasks.fendermint-new-genesis] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} +""" + +[tasks.fendermint-new-key] +cwd = "./target/release" +script=""" +mkdir -p $KEYS_DIR + +./fendermint key gen --out-dir $KEYS_DIR --name $KEY_NAME; +chmod 600 ${PRIV_KEY_PATH} +""" + +[tasks.fendermint-new-account] +cwd = "./target/release" +script=""" +./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} +""" + + +[tasks.fendermint-add-validator] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} add-validator --public-key ${PUB_KEY_PATH} --power 1 +""" + +[tasks.fendermint-new-gateway] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} ipc gateway --subnet-id /r0 \ + --top-down-check-period 10 \ + --bottom-up-check-period 10 \ + --msg-fee 10 \ + --majority-percentage 66 +""" + +[tasks.fendermint-export-keys] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file ${GENESIS_FILE} into-tendermint --out ${CMT_DIR}/config/genesis.json + +./fendermint key into-tendermint --secret-key ${PRIV_KEY_PATH} --out ${CMT_DIR}/config/priv_validator_key.json +chmod 600 ${CMT_DIR}/config/priv_validator_key.json +""" + +[tasks.fendermint-start] +extend = "fendermint-run" +env = { "ENTRY" = "fendermint", "CMD" = "run", "FLAGS" = "-d" } + +[tasks.fendermint-run] +script = """ +docker run \ + ${FLAGS} \ + --name ${FM_CONTAINER_NAME} \ + --init \ + --user $(id -u) \ + --network ${NETWORK_NAME} \ + --volume ${BASE_DIR}:/data \ + --env FM_DATA_DIR=/data/fendermint/data \ + --env FM_CHAIN_NAME=${NETWORK_NAME} \ + --env LOG_LEVEL=info \ + --entrypoint ${ENTRY} \ + ${FM_DOCKER_IMAGE} \ + ${CMD} +""" +dependencies = ["docker-network-create", "fendermint-deps"] \ No newline at end of file diff --git a/infra/scripts/testnet.toml b/infra/scripts/testnet.toml new file mode 100644 index 00000000..46511f9c --- /dev/null +++ b/infra/scripts/testnet.toml @@ -0,0 +1,180 @@ +######################################################################################################################## +# Testnet node +######################################################################################################################## +[tasks.testnet] +dependencies = [ + "testnet-down", + "testnet-init", + "fendermint-deps", + "testnet-fendermint-config", + "testnet-up" +] + +[tasks.testnet-up] +script = """ +if [ -z $GID ]; then export GID=$(id -g); fi +if [ -z $UID ]; then export UID=$(id -u); fi +export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` +export CHAIN_NAME=$CHAIN_NAME +export BASE_TESTNET_DIR=$BASE_TESTNET_DIR +docker compose -f ./infra/docker-compose.yml up -d +""" + +[tasks.testnet-down] +dependencies = [ + "testnet-docker-compose-down", + "docker-network-rm", +] + +[tasks.testnet-docker-compose-down] +script = """ +export CMT_PERSISTENT_PEERS="UNDEFINED" +if [ -z $GID ]; then export GID=$(id -g); fi +if [ -z $UID ]; then export UID=$(id -u); fi +docker compose -f ./infra/docker-compose.yml down +""" + +[tasks.testnet-init] +dependencies = [ + "testnet-clear", + "testnet-network-create", + "cometbft-pull", + "testnet-mkdir", + "testnet-cometbft-init", + "testnet-mkdir", +] + +[tasks.testnet-network-create] +env = { "NETWORK_NAME"="${NETWORK_NAME}"} +extend = "docker-network-create" + +[tasks.testnet-clear] +script=""" +echo clearing all IPC data +rm -rf ${BASE_TESTNET_DIR} +""" + +[tasks.testnet-mkdir] +script=""" +mkdir -p $BASE_TESTNET_DIR +mkdir -p $BASE_TESTNET_DIR/out + +for i in $(seq 0 3); do + mkdir -p $BASE_TESTNET_DIR/node${i} + mkdir -p $BASE_TESTNET_DIR/node${i}/fendermint + mkdir -p $BASE_TESTNET_DIR/node${i}/cometbft +done +""" + +[tasks.testnet-cometbft-init] +dependencies = ["testnet-cometbft-init-node0", "testnet-cometbft-init-node1", "testnet-cometbft-init-node2", "testnet-cometbft-init-node3"] + +[tasks.testnet-cometbft-init-node0] +extend = "cometbft-init" +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node0/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node0", "FLAGS" = "-a STDOUT -a STDERR --rm"} + +[tasks.testnet-cometbft-init-node1] +extend = "cometbft-init" +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node1/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node1", "FLAGS" = "-a STDOUT -a STDERR --rm" } + +[tasks.testnet-cometbft-init-node2] +extend = "cometbft-init" +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node2/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node2", "FLAGS" = "-a STDOUT -a STDERR --rm" } + +[tasks.testnet-cometbft-init-node3] +extend = "cometbft-init" +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node3/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node3", "FLAGS" = "-a STDOUT -a STDERR --rm" } + +[tasks.testnet-fendermint-config] +dependencies = [ + "testnet-config-newgenesis", + "testnet-config-peers", + "testnet-config-newkey", + "testnet-config-newaccount", + "testnet-config-newgateway", + "testnet-share-genesis" +] + +[tasks.testnet-config-newgenesis] +cwd = "./target/release" +script = """ +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json \ + new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} + +cat $BASE_TESTNET_DIR/genesis.json +""" + +[tasks.testnet-config-newkey] +cwd = "./target/release" +script=""" +for i in $(seq 0 3); do + mkdir -p $BASE_TESTNET_DIR/node${i}/fendermint/keys + ./fendermint key gen --out-dir $BASE_TESTNET_DIR/node${i}/fendermint/keys --name validator${i}_key +done +""" + +[tasks.testnet-config-newaccount] +cwd = "./target/release" +script=""" +for i in $(seq 0 3); do +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ + --public-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.pk --balance ${BALANCE} +done +""" + +[tasks.testnet-config-peers] +cwd = "./target/release" +script=""" +for i in $(seq 0 3); do + ./fendermint key add-peer \ + --node-key-file $BASE_TESTNET_DIR/node${i}/cometbft/config/node_key.json \ + --network-addr 192.167.10.$((${i}+2)):26656 \ + --local-peers-file $BASE_TESTNET_DIR/peers +done + +unset CMT_PERSISTENT_PEERS +export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` +echo Persistent peers: $CMT_PERSISTENT_PEERS + +for i in $(seq 0 3); do + sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node${i}/cometbft/config/config.toml +done +""" + +[tasks.testnet-config-newgateway] +cwd = "./target/release" +script = """ +for i in $(seq 0 3); do + ./fendermint genesis \ + --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ + --public-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.pk \ + --power 1 +done + +./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json ipc gateway --subnet-id /r0 \ + --top-down-check-period 10 \ + --bottom-up-check-period 10 \ + --msg-fee 10 \ + --majority-percentage 66 + +./fendermint genesis \ + --genesis-file $BASE_TESTNET_DIR/genesis.json into-tendermint \ + --out $BASE_TESTNET_DIR/out/genesis.json + +for i in $(seq 0 3); do + ./fendermint key into-tendermint \ + --secret-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.sk \ + --out $BASE_TESTNET_DIR/node${i}/cometbft/config/priv_validator_key.json +done + +echo "GENESIS:" +cat $BASE_TESTNET_DIR/genesis.json +""" + +[tasks.testnet-share-genesis] +cwd = "./target/release" +script = """ +for i in $(seq 0 3); do + cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node${i}/cometbft/config/genesis.json +done +""" From 02ed819e381bcc335e08655e1d41ab33c17843e9 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 19 Sep 2023 19:14:30 +0200 Subject: [PATCH 33/40] update --- docs/localnet.md | 8 ++--- infra/Makefile.toml | 23 +++--------- infra/docker-compose.yml | 24 ++++++------- infra/scripts/testnet.toml | 74 ++++++++++++++++++++------------------ 4 files changed, 59 insertions(+), 70 deletions(-) diff --git a/docs/localnet.md b/docs/localnet.md index bb4f7770..471812d0 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -9,7 +9,7 @@ make build docker-build To run IPC in the local rootnet just perform the following : ```bash -cargo make --makefile ./infra/Makefile.toml node +cargo make --makefile ./infra/Makefile.toml --profile node node ``` @@ -17,19 +17,19 @@ It will create three docker containers (cometbft, fendermint, and eth-api). To stop run the following: ```bash -cargo make --makefile ./infra/Makefile.toml node-down +cargo make --makefile ./infra/Makefile.toml --profile node node-down ``` ## Local 4-nodes deployment To run IPC in the local rootnet with 4 nodes perform the following command : ```bash -cargo make --makefile ./infra/Makefile.toml testnet +cargo make --makefile ./infra/Makefile.toml --profile testnet testnet ``` To stop the network: ```bash -cargo make --makefile ./infra/Makefile.toml testnet-down +cargo make --makefile ./infra/Makefile.toml --profile testnet testnet-down ``` The testnet contains four logical nodes. Each node consists of cometbft, fendermint, and ethapi containers. diff --git a/infra/Makefile.toml b/infra/Makefile.toml index 1f2e0cf5..cd9975b2 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -17,10 +17,6 @@ BALANCE = { value = "1000", condition = { env_not_set = ["BALANCE"] }} BASE_FEE = { value = "1000", condition = { env_not_set = ["BASE_FEE"] }} TIMESTAMP = { value = "1680101412", condition = { env_not_set = ["TIMESTAMP"] }} -BASE_DIR="${HOME}/.ipc/${CHAIN_NAME}" - -BASE_TESTNET_DIR="${HOME}/.ipc-testnet" - FM_DIR="${BASE_DIR}/fendermint" CMT_DIR="${BASE_DIR}/cometbft" @@ -50,22 +46,11 @@ CMT_WAIT_MILLIS = 10000 # Keep example logs to a minimum. VERBOSITY = "" -[env.ci] -CMT_WAIT_MILLIS = 20000 -# Help debug any issues with simplecoin by logging requests and responses. -VERBOSITY = "--verbose" +[env.node] +BASE_DIR="${HOME}/.ipc/${CHAIN_NAME}" -# infrastructure workflows: -# cargo install cargo-make -# -# cd fendermint/testing/smoke-test -# - then - -# cargo make --profile ci -# - or - -# cargo make setup -# cargo make test -# docker logs smoke-ethapi -# cargo make teardown +[env.testnet] +BASE_DIR="${HOME}/.ipc-testnet" [tasks.info] script=""" diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index 4a022368..d24b24a5 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -14,7 +14,7 @@ services: - CMT_PROXY_APP=tcp://fendermint-node0:26658 - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" volumes: - - $BASE_TESTNET_DIR/node0/cometbft:/cometbft + - $BASE_DIR/node0/cometbft:/cometbft healthcheck: test: curl --fail http://localhost:26657 || exit 1 interval: 8s @@ -37,7 +37,7 @@ services: - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" - CMT_PROXY_APP=tcp://fendermint-node1:26658 volumes: - - $BASE_TESTNET_DIR/node1/cometbft:/cometbft + - $BASE_DIR/node1/cometbft:/cometbft healthcheck: test: curl --fail http://localhost:26657 || exit 1 interval: 8s @@ -60,7 +60,7 @@ services: ports: - "26661-26662:26656-26657" volumes: - - $BASE_TESTNET_DIR/node2/cometbft:/cometbft + - $BASE_DIR/node2/cometbft:/cometbft healthcheck: test: curl --fail http://localhost:26657 || exit 1 interval: 8s @@ -82,7 +82,7 @@ services: ports: - "26663-26664:26656-26657" volumes: - - $BASE_TESTNET_DIR/node3/cometbft:/cometbft + - $BASE_DIR/node3/cometbft:/cometbft healthcheck: test: curl --fail http://localhost:26657 || exit 1 interval: 8s @@ -101,7 +101,7 @@ services: - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - - $BASE_TESTNET_DIR/node0:/data + - $BASE_DIR/node0:/data networks: localnet: ipv4_address: 192.167.10.6 @@ -115,7 +115,7 @@ services: - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - - $BASE_TESTNET_DIR/node1:/data + - $BASE_DIR/node1:/data networks: localnet: ipv4_address: 192.167.10.7 @@ -129,7 +129,7 @@ services: - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - - $BASE_TESTNET_DIR/node2:/data + - $BASE_DIR/node2:/data networks: localnet: ipv4_address: 192.167.10.8 @@ -143,7 +143,7 @@ services: - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - - $BASE_TESTNET_DIR/node3:/data + - $BASE_DIR/node3:/data networks: localnet: ipv4_address: 192.167.10.9 @@ -160,7 +160,7 @@ services: ports: - 8545:8545 volumes: - - $BASE_TESTNET_DIR/node0:/data + - $BASE_DIR/node0:/data depends_on: cometbft-node0: condition: service_healthy @@ -180,7 +180,7 @@ services: ports: - 8546:8545 volumes: - - $BASE_TESTNET_DIR/node1:/data + - $BASE_DIR/node1:/data depends_on: cometbft-node1: condition: service_healthy @@ -200,7 +200,7 @@ services: ports: - 8547:8545 volumes: - - $BASE_TESTNET_DIR/node2:/data + - $BASE_DIR/node2:/data depends_on: cometbft-node2: condition: service_healthy @@ -220,7 +220,7 @@ services: ports: - 8548:8545 volumes: - - $BASE_TESTNET_DIR/node3:/data + - $BASE_DIR/node3:/data depends_on: cometbft-node2: condition: service_healthy diff --git a/infra/scripts/testnet.toml b/infra/scripts/testnet.toml index 46511f9c..3c055f75 100644 --- a/infra/scripts/testnet.toml +++ b/infra/scripts/testnet.toml @@ -12,11 +12,13 @@ dependencies = [ [tasks.testnet-up] script = """ -if [ -z $GID ]; then export GID=$(id -g); fi -if [ -z $UID ]; then export UID=$(id -u); fi -export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` +if [ -z $GID ]; then GID=$(id -g); fi +if [ -z $UID ]; then UID=$(id -u); fi +export UID +export GID +export CMT_PERSISTENT_PEERS=`cat $BASE_DIR/peers` export CHAIN_NAME=$CHAIN_NAME -export BASE_TESTNET_DIR=$BASE_TESTNET_DIR +export BASE_DIR=$BASE_DIR docker compose -f ./infra/docker-compose.yml up -d """ @@ -29,8 +31,10 @@ dependencies = [ [tasks.testnet-docker-compose-down] script = """ export CMT_PERSISTENT_PEERS="UNDEFINED" -if [ -z $GID ]; then export GID=$(id -g); fi -if [ -z $UID ]; then export UID=$(id -u); fi +if [ -z $GID ]; then GID=$(id -g); fi +if [ -z $UID ]; then UID=$(id -u); fi +export UID +export GID docker compose -f ./infra/docker-compose.yml down """ @@ -51,18 +55,18 @@ extend = "docker-network-create" [tasks.testnet-clear] script=""" echo clearing all IPC data -rm -rf ${BASE_TESTNET_DIR} +rm -rf ${BASE_DIR} """ [tasks.testnet-mkdir] script=""" -mkdir -p $BASE_TESTNET_DIR -mkdir -p $BASE_TESTNET_DIR/out +mkdir -p $BASE_DIR +mkdir -p $BASE_DIR/out for i in $(seq 0 3); do - mkdir -p $BASE_TESTNET_DIR/node${i} - mkdir -p $BASE_TESTNET_DIR/node${i}/fendermint - mkdir -p $BASE_TESTNET_DIR/node${i}/cometbft + mkdir -p $BASE_DIR/node${i} + mkdir -p $BASE_DIR/node${i}/fendermint + mkdir -p $BASE_DIR/node${i}/cometbft done """ @@ -71,19 +75,19 @@ dependencies = ["testnet-cometbft-init-node0", "testnet-cometbft-init-node1", "t [tasks.testnet-cometbft-init-node0] extend = "cometbft-init" -env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node0/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node0", "FLAGS" = "-a STDOUT -a STDERR --rm"} +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_DIR}/node0/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node0", "FLAGS" = "-a STDOUT -a STDERR --rm"} [tasks.testnet-cometbft-init-node1] extend = "cometbft-init" -env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node1/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node1", "FLAGS" = "-a STDOUT -a STDERR --rm" } +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_DIR}/node1/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node1", "FLAGS" = "-a STDOUT -a STDERR --rm" } [tasks.testnet-cometbft-init-node2] extend = "cometbft-init" -env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node2/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node2", "FLAGS" = "-a STDOUT -a STDERR --rm" } +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_DIR}/node2/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node2", "FLAGS" = "-a STDOUT -a STDERR --rm" } [tasks.testnet-cometbft-init-node3] extend = "cometbft-init" -env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_TESTNET_DIR}/node3/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node3", "FLAGS" = "-a STDOUT -a STDERR --rm" } +env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_DIR}/node3/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node3", "FLAGS" = "-a STDOUT -a STDERR --rm" } [tasks.testnet-fendermint-config] dependencies = [ @@ -98,18 +102,18 @@ dependencies = [ [tasks.testnet-config-newgenesis] cwd = "./target/release" script = """ -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json \ +./fendermint genesis --genesis-file $BASE_DIR/genesis.json \ new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} -cat $BASE_TESTNET_DIR/genesis.json +cat $BASE_DIR/genesis.json """ [tasks.testnet-config-newkey] cwd = "./target/release" script=""" for i in $(seq 0 3); do - mkdir -p $BASE_TESTNET_DIR/node${i}/fendermint/keys - ./fendermint key gen --out-dir $BASE_TESTNET_DIR/node${i}/fendermint/keys --name validator${i}_key + mkdir -p $BASE_DIR/node${i}/fendermint/keys + ./fendermint key gen --out-dir $BASE_DIR/node${i}/fendermint/keys --name validator${i}_key done """ @@ -117,8 +121,8 @@ done cwd = "./target/release" script=""" for i in $(seq 0 3); do -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json add-account \ - --public-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.pk --balance ${BALANCE} +./fendermint genesis --genesis-file $BASE_DIR/genesis.json add-account \ + --public-key $BASE_DIR/node${i}/fendermint/keys/validator${i}_key.pk --balance ${BALANCE} done """ @@ -127,17 +131,17 @@ cwd = "./target/release" script=""" for i in $(seq 0 3); do ./fendermint key add-peer \ - --node-key-file $BASE_TESTNET_DIR/node${i}/cometbft/config/node_key.json \ + --node-key-file $BASE_DIR/node${i}/cometbft/config/node_key.json \ --network-addr 192.167.10.$((${i}+2)):26656 \ - --local-peers-file $BASE_TESTNET_DIR/peers + --local-peers-file $BASE_DIR/peers done unset CMT_PERSISTENT_PEERS -export CMT_PERSISTENT_PEERS=`cat $BASE_TESTNET_DIR/peers` +export CMT_PERSISTENT_PEERS=`cat $BASE_DIR/peers` echo Persistent peers: $CMT_PERSISTENT_PEERS for i in $(seq 0 3); do - sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_TESTNET_DIR/node${i}/cometbft/config/config.toml + sed -i'bak' "s/persistent_peers = \\"\\"/persistent_peers = \\"$CMT_PERSISTENT_PEERS\\"/" $BASE_DIR/node${i}/cometbft/config/config.toml done """ @@ -146,35 +150,35 @@ cwd = "./target/release" script = """ for i in $(seq 0 3); do ./fendermint genesis \ - --genesis-file $BASE_TESTNET_DIR/genesis.json add-validator \ - --public-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.pk \ + --genesis-file $BASE_DIR/genesis.json add-validator \ + --public-key $BASE_DIR/node${i}/fendermint/keys/validator${i}_key.pk \ --power 1 done -./fendermint genesis --genesis-file $BASE_TESTNET_DIR/genesis.json ipc gateway --subnet-id /r0 \ +./fendermint genesis --genesis-file $BASE_DIR/genesis.json ipc gateway --subnet-id /r0 \ --top-down-check-period 10 \ --bottom-up-check-period 10 \ --msg-fee 10 \ --majority-percentage 66 ./fendermint genesis \ - --genesis-file $BASE_TESTNET_DIR/genesis.json into-tendermint \ - --out $BASE_TESTNET_DIR/out/genesis.json + --genesis-file $BASE_DIR/genesis.json into-tendermint \ + --out $BASE_DIR/out/genesis.json for i in $(seq 0 3); do ./fendermint key into-tendermint \ - --secret-key $BASE_TESTNET_DIR/node${i}/fendermint/keys/validator${i}_key.sk \ - --out $BASE_TESTNET_DIR/node${i}/cometbft/config/priv_validator_key.json + --secret-key $BASE_DIR/node${i}/fendermint/keys/validator${i}_key.sk \ + --out $BASE_DIR/node${i}/cometbft/config/priv_validator_key.json done echo "GENESIS:" -cat $BASE_TESTNET_DIR/genesis.json +cat $BASE_DIR/genesis.json """ [tasks.testnet-share-genesis] cwd = "./target/release" script = """ for i in $(seq 0 3); do - cp $BASE_TESTNET_DIR/out/genesis.json $BASE_TESTNET_DIR/node${i}/cometbft/config/genesis.json + cp $BASE_DIR/out/genesis.json $BASE_DIR/node${i}/cometbft/config/genesis.json done """ From b1e701eccaf1a38532d716cb592a3f51388d048f Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 19 Sep 2023 19:37:11 +0200 Subject: [PATCH 34/40] test new impl --- docs/localnet.md | 8 +++--- infra/Makefile.toml | 8 +----- infra/scripts/fendermint.toml | 22 +++++++++++++++ infra/scripts/node.toml | 51 +++++++++-------------------------- infra/scripts/testnet.toml | 28 +++++++++---------- 5 files changed, 54 insertions(+), 63 deletions(-) diff --git a/docs/localnet.md b/docs/localnet.md index 471812d0..bb4f7770 100644 --- a/docs/localnet.md +++ b/docs/localnet.md @@ -9,7 +9,7 @@ make build docker-build To run IPC in the local rootnet just perform the following : ```bash -cargo make --makefile ./infra/Makefile.toml --profile node node +cargo make --makefile ./infra/Makefile.toml node ``` @@ -17,19 +17,19 @@ It will create three docker containers (cometbft, fendermint, and eth-api). To stop run the following: ```bash -cargo make --makefile ./infra/Makefile.toml --profile node node-down +cargo make --makefile ./infra/Makefile.toml node-down ``` ## Local 4-nodes deployment To run IPC in the local rootnet with 4 nodes perform the following command : ```bash -cargo make --makefile ./infra/Makefile.toml --profile testnet testnet +cargo make --makefile ./infra/Makefile.toml testnet ``` To stop the network: ```bash -cargo make --makefile ./infra/Makefile.toml --profile testnet testnet-down +cargo make --makefile ./infra/Makefile.toml testnet-down ``` The testnet contains four logical nodes. Each node consists of cometbft, fendermint, and ethapi containers. diff --git a/infra/Makefile.toml b/infra/Makefile.toml index cd9975b2..ba8a472c 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -16,7 +16,7 @@ CHAIN_NAME = { value = "root", condition = { env_not_set = ["CHAIN_NAME"] }} BALANCE = { value = "1000", condition = { env_not_set = ["BALANCE"] }} BASE_FEE = { value = "1000", condition = { env_not_set = ["BASE_FEE"] }} TIMESTAMP = { value = "1680101412", condition = { env_not_set = ["TIMESTAMP"] }} - +BASE_DIR="${HOME}/.ipc/${CHAIN_NAME}" FM_DIR="${BASE_DIR}/fendermint" CMT_DIR="${BASE_DIR}/cometbft" @@ -46,12 +46,6 @@ CMT_WAIT_MILLIS = 10000 # Keep example logs to a minimum. VERBOSITY = "" -[env.node] -BASE_DIR="${HOME}/.ipc/${CHAIN_NAME}" - -[env.testnet] -BASE_DIR="${HOME}/.ipc-testnet" - [tasks.info] script=""" echo diff --git a/infra/scripts/fendermint.toml b/infra/scripts/fendermint.toml index 53154e18..966c5af5 100644 --- a/infra/scripts/fendermint.toml +++ b/infra/scripts/fendermint.toml @@ -1,3 +1,25 @@ +[tasks.fendermint-start] +extend = "fendermint-run" +env = { "ENTRY" = "fendermint", "CMD" = "run", "FLAGS" = "-d" } + +[tasks.fendermint-run] +script = """ +docker run \ + ${FLAGS} \ + --name ${FM_CONTAINER_NAME} \ + --init \ + --user $(id -u) \ + --network ${NETWORK_NAME} \ + --volume ${BASE_DIR}:/data \ + --env FM_DATA_DIR=/data/fendermint/data \ + --env FM_CHAIN_NAME=${NETWORK_NAME} \ + --env LOG_LEVEL=info \ + --entrypoint ${ENTRY} \ + ${FM_DOCKER_IMAGE} \ + ${CMD} +""" +dependencies = ["docker-network-create", "fendermint-deps"] + [tasks.fendermint-deps] script = """ # Check if the image exists diff --git a/infra/scripts/node.toml b/infra/scripts/node.toml index 3d77cd72..49f45ae3 100644 --- a/infra/scripts/node.toml +++ b/infra/scripts/node.toml @@ -1,6 +1,3 @@ -######################################################################################################################## -# Single node -######################################################################################################################## [tasks.node] workspace = false dependencies = [ @@ -58,21 +55,21 @@ run_task = { name = [ # the genesis file with necessary entities and cryptographic keys. [tasks.node-config] dependencies = [ - "fendermint-new-genesis", - "fendermint-new-key", - "fendermint-new-account", - "fendermint-add-validator", - "fendermint-new-gateway", - "fendermint-export-keys" + "node-script-new-genesis", + "node-script-new-key", + "node-script-new-account", + "node-script-add-validator", + "node-script-new-gateway", + "node-script-export-keys" ] -[tasks.fendermint-new-genesis] +[tasks.node-script-new-genesis] cwd = "./target/release" script = """ ./fendermint genesis --genesis-file ${GENESIS_FILE} new --chain-name ${CHAIN_NAME} --base-fee ${BASE_FEE} --timestamp ${TIMESTAMP} """ -[tasks.fendermint-new-key] +[tasks.node-script-new-key] cwd = "./target/release" script=""" mkdir -p $KEYS_DIR @@ -81,20 +78,20 @@ mkdir -p $KEYS_DIR chmod 600 ${PRIV_KEY_PATH} """ -[tasks.fendermint-new-account] +[tasks.node-script-new-account] cwd = "./target/release" script=""" ./fendermint genesis --genesis-file ${GENESIS_FILE} add-account --public-key ${PUB_KEY_PATH} --balance ${BALANCE} """ -[tasks.fendermint-add-validator] +[tasks.node-script-add-validator] cwd = "./target/release" script = """ ./fendermint genesis --genesis-file ${GENESIS_FILE} add-validator --public-key ${PUB_KEY_PATH} --power 1 """ -[tasks.fendermint-new-gateway] +[tasks.node-script-new-gateway] cwd = "./target/release" script = """ ./fendermint genesis --genesis-file ${GENESIS_FILE} ipc gateway --subnet-id /r0 \ @@ -104,33 +101,11 @@ script = """ --majority-percentage 66 """ -[tasks.fendermint-export-keys] +[tasks.node-script-export-keys] cwd = "./target/release" script = """ ./fendermint genesis --genesis-file ${GENESIS_FILE} into-tendermint --out ${CMT_DIR}/config/genesis.json ./fendermint key into-tendermint --secret-key ${PRIV_KEY_PATH} --out ${CMT_DIR}/config/priv_validator_key.json chmod 600 ${CMT_DIR}/config/priv_validator_key.json -""" - -[tasks.fendermint-start] -extend = "fendermint-run" -env = { "ENTRY" = "fendermint", "CMD" = "run", "FLAGS" = "-d" } - -[tasks.fendermint-run] -script = """ -docker run \ - ${FLAGS} \ - --name ${FM_CONTAINER_NAME} \ - --init \ - --user $(id -u) \ - --network ${NETWORK_NAME} \ - --volume ${BASE_DIR}:/data \ - --env FM_DATA_DIR=/data/fendermint/data \ - --env FM_CHAIN_NAME=${NETWORK_NAME} \ - --env LOG_LEVEL=info \ - --entrypoint ${ENTRY} \ - ${FM_DOCKER_IMAGE} \ - ${CMD} -""" -dependencies = ["docker-network-create", "fendermint-deps"] \ No newline at end of file +""" \ No newline at end of file diff --git a/infra/scripts/testnet.toml b/infra/scripts/testnet.toml index 3c055f75..15860023 100644 --- a/infra/scripts/testnet.toml +++ b/infra/scripts/testnet.toml @@ -6,7 +6,7 @@ dependencies = [ "testnet-down", "testnet-init", "fendermint-deps", - "testnet-fendermint-config", + "testnet-config", "testnet-up" ] @@ -89,17 +89,17 @@ env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_DI extend = "cometbft-init" env = { "CMD" = "init", "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_DIR}/node3/cometbft", "CMT_CONTAINER_NAME" = "cometbft-node3", "FLAGS" = "-a STDOUT -a STDERR --rm" } -[tasks.testnet-fendermint-config] +[tasks.testnet-config] dependencies = [ - "testnet-config-newgenesis", - "testnet-config-peers", - "testnet-config-newkey", - "testnet-config-newaccount", - "testnet-config-newgateway", - "testnet-share-genesis" + "testnet-script-new-genesis", + "testnet-script-add-peers", + "testnet-script-new-key", + "testnet-script-new-account", + "testnet-script-new-gateway", + "testnet-script-share-genesis" ] -[tasks.testnet-config-newgenesis] +[tasks.testnet-script-new-genesis] cwd = "./target/release" script = """ ./fendermint genesis --genesis-file $BASE_DIR/genesis.json \ @@ -108,7 +108,7 @@ script = """ cat $BASE_DIR/genesis.json """ -[tasks.testnet-config-newkey] +[tasks.testnet-script-new-key] cwd = "./target/release" script=""" for i in $(seq 0 3); do @@ -117,7 +117,7 @@ for i in $(seq 0 3); do done """ -[tasks.testnet-config-newaccount] +[tasks.testnet-script-new-account] cwd = "./target/release" script=""" for i in $(seq 0 3); do @@ -126,7 +126,7 @@ for i in $(seq 0 3); do done """ -[tasks.testnet-config-peers] +[tasks.testnet-script-add-peers] cwd = "./target/release" script=""" for i in $(seq 0 3); do @@ -145,7 +145,7 @@ for i in $(seq 0 3); do done """ -[tasks.testnet-config-newgateway] +[tasks.testnet-script-new-gateway] cwd = "./target/release" script = """ for i in $(seq 0 3); do @@ -175,7 +175,7 @@ echo "GENESIS:" cat $BASE_DIR/genesis.json """ -[tasks.testnet-share-genesis] +[tasks.testnet-script-share-genesis] cwd = "./target/release" script = """ for i in $(seq 0 3); do From a683928625eff61b6a9ec27c0a7b29e098394180 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Thu, 21 Sep 2023 15:50:43 +0200 Subject: [PATCH 35/40] remove unused script --- infra/scripts/examples.toml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 infra/scripts/examples.toml diff --git a/infra/scripts/examples.toml b/infra/scripts/examples.toml deleted file mode 100644 index 07b09fdc..00000000 --- a/infra/scripts/examples.toml +++ /dev/null @@ -1,16 +0,0 @@ -[tasks.simplecoin-example] -# Using --release in the hope that it can reuse artifacts compiled earlier for the docker build. -script = """ -cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} -cargo run -p fendermint_rpc --release --example simplecoin -- \ - --secret-key fendermint/testing/smoke-test/test-data/fendermint/keys/alice.sk \ - ${VERBOSITY} -""" - -[tasks.ethapi-example] -script = """ -cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} -cargo run -p fendermint_eth_api --release --example ethers -- \ - --secret-key-from fendermint/testing/smoke-test/test-data/fendermint/keys/emily.sk \ - --secret-key-to fendermint/testing/smoke-test/test-data/fendermint/keys/eric.sk -""" \ No newline at end of file From c0601633854a93858d67f8fba3bdbc816339b0d8 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Thu, 21 Sep 2023 16:05:05 +0200 Subject: [PATCH 36/40] fix new comments and minor things --- infra/Makefile.toml | 3 +-- infra/scripts/node.toml | 2 +- infra/scripts/testnet.toml | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/infra/Makefile.toml b/infra/Makefile.toml index ba8a472c..1724fed0 100644 --- a/infra/Makefile.toml +++ b/infra/Makefile.toml @@ -4,8 +4,7 @@ extend = [ { path = "scripts/fendermint.toml" }, { path = "scripts/ethapi.toml" }, { path = "scripts/node.toml" }, - { path = "scripts/testnet.toml" }, - { path = "scripts/examples.toml" }, + { path = "scripts/testnet.toml" } ] [config] diff --git a/infra/scripts/node.toml b/infra/scripts/node.toml index 49f45ae3..a697cbee 100644 --- a/infra/scripts/node.toml +++ b/infra/scripts/node.toml @@ -98,7 +98,7 @@ script = """ --top-down-check-period 10 \ --bottom-up-check-period 10 \ --msg-fee 10 \ - --majority-percentage 66 + --majority-percentage 67 """ [tasks.node-script-export-keys] diff --git a/infra/scripts/testnet.toml b/infra/scripts/testnet.toml index 15860023..3f0099f6 100644 --- a/infra/scripts/testnet.toml +++ b/infra/scripts/testnet.toml @@ -45,7 +45,6 @@ dependencies = [ "cometbft-pull", "testnet-mkdir", "testnet-cometbft-init", - "testnet-mkdir", ] [tasks.testnet-network-create] @@ -159,7 +158,7 @@ done --top-down-check-period 10 \ --bottom-up-check-period 10 \ --msg-fee 10 \ - --majority-percentage 66 + --majority-percentage 67 ./fendermint genesis \ --genesis-file $BASE_DIR/genesis.json into-tendermint \ From 97157e2fdd54e47acd291c389dd9b90ec879b7ff Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Mon, 25 Sep 2023 18:49:35 +0000 Subject: [PATCH 37/40] fix compose --- infra/docker-compose.yml | 224 ++++--------------------------------- infra/down.sh | 23 ++++ infra/scripts/testnet.toml | 18 +-- infra/up.sh | 23 ++++ 4 files changed, 80 insertions(+), 208 deletions(-) create mode 100755 infra/down.sh create mode 100755 infra/up.sh diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index d24b24a5..eaab3e3e 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -1,99 +1,29 @@ -version: '3' - services: - cometbft-node0: - container_name: cometbft-node0 + cometbft-node: + container_name: cometbft-node${NODE_ID} user: ${UID}:${GID} image: "cometbft/cometbft:${COMETBFT_VERSION}" ports: - - "26656-26657:26656-26657" + - "${PORT1}-${PORT2}:26656-26657" environment: - - ID=0 - - LOG=${LOG:-cometbft-node0.log} + - ID=${NODE_ID} + - LOG=${LOG:-cometbft-node${NODE_ID}.log} - CMT_PEX=true - - CMT_PROXY_APP=tcp://fendermint-node0:26658 + - CMT_PROXY_APP=tcp://fendermint-node${NODE_ID}:26658 - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" volumes: - - $BASE_DIR/node0/cometbft:/cometbft + - $BASE_DIR/node${NODE_ID}/cometbft:/cometbft healthcheck: test: curl --fail http://localhost:26657 || exit 1 interval: 8s timeout: 10s retries: 20 networks: - localnet: - ipv4_address: 192.167.10.2 + testnet: + ipv4_address: ${CMT_NODE_ADDR} - cometbft-node1: - container_name: cometbft-node1 - user: ${UID}:${GID} - image: "cometbft/cometbft:${COMETBFT_VERSION}" - ports: - - "26659-26660:26656-26657" - environment: - - ID=1 - - LOG=${LOG:-cometbft-node1.log} - - CMT_PEX=true - - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" - - CMT_PROXY_APP=tcp://fendermint-node1:26658 - volumes: - - $BASE_DIR/node1/cometbft:/cometbft - healthcheck: - test: curl --fail http://localhost:26657 || exit 1 - interval: 8s - timeout: 10s - retries: 20 - networks: - localnet: - ipv4_address: 192.167.10.3 - - cometbft-node2: - container_name: cometbft-node2 - user: ${UID}:${GID} - image: "cometbft/cometbft:${COMETBFT_VERSION}" - environment: - - ID=2 - - LOG=${LOG:-cometbft-node2.log} - - CMT_PEX=true - - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" - - CMT_PROXY_APP=tcp://fendermint-node2:26658 - ports: - - "26661-26662:26656-26657" - volumes: - - $BASE_DIR/node2/cometbft:/cometbft - healthcheck: - test: curl --fail http://localhost:26657 || exit 1 - interval: 8s - timeout: 10s - retries: 20 - networks: - localnet: - ipv4_address: 192.167.10.4 - - cometbft-node3: - container_name: cometbft-node3 - user: ${UID}:${GID} - image: "cometbft/cometbft:${COMETBFT_VERSION}" - environment: - - ID=3 - - LOG=${LOG:-cometbft-node3.log} - - CMT_PERSISTENT_PEERS="${CMT_PERSISTENT_PEERS}" - - CMT_PROXY_APP=tcp://fendermint-node3:26658 - ports: - - "26663-26664:26656-26657" - volumes: - - $BASE_DIR/node3/cometbft:/cometbft - healthcheck: - test: curl --fail http://localhost:26657 || exit 1 - interval: 8s - timeout: 10s - retries: 20 - networks: - localnet: - ipv4_address: 192.167.10.5 - - fendermint-node0: - container_name: fendermint-node0 + fendermint-node: + container_name: fendermint-node${NODE_ID} user: ${UID}:${GID} image: "fendermint:latest" environment: @@ -101,137 +31,31 @@ services: - FM_CHAIN_NAME=$CHAIN_NAME - LOG_LEVEL=info volumes: - - $BASE_DIR/node0:/data - networks: - localnet: - ipv4_address: 192.167.10.6 - - fendermint-node1: - container_name: fendermint-node1 - user: ${UID}:${GID} - image: "fendermint:latest" - environment: - - FM_DATA_DIR=/data/fendermint/data - - FM_CHAIN_NAME=$CHAIN_NAME - - LOG_LEVEL=info - volumes: - - $BASE_DIR/node1:/data - networks: - localnet: - ipv4_address: 192.167.10.7 - - fendermint-node2: - container_name: fendermint-node2 - user: ${UID}:${GID} - image: "fendermint:latest" - environment: - - FM_DATA_DIR=/data/fendermint/data - - FM_CHAIN_NAME=$CHAIN_NAME - - LOG_LEVEL=info - volumes: - - $BASE_DIR/node2:/data - networks: - localnet: - ipv4_address: 192.167.10.8 - - fendermint-node3: - container_name: fendermint-node3 - user: ${UID}:${GID} - image: "fendermint:latest" - environment: - - FM_DATA_DIR=/data/fendermint/data - - FM_CHAIN_NAME=$CHAIN_NAME - - LOG_LEVEL=info - volumes: - - $BASE_DIR/node3:/data - networks: - localnet: - ipv4_address: 192.167.10.9 - - ethapi-node0: - container_name: ethapi-node0 - user: ${UID}:${GID} - image: "fendermint:latest" - command: "eth run" - environment: - - TENDERMINT_WS_URL=ws://cometbft-node0:26657/websocket - - LOG_LEVEL=debug - - RUST_BACKTRACE=1 - ports: - - 8545:8545 - volumes: - - $BASE_DIR/node0:/data - depends_on: - cometbft-node0: - condition: service_healthy - networks: - localnet: - ipv4_address: 192.167.10.10 - - ethapi-node1: - container_name: ethapi-node1 - user: ${UID}:${GID} - image: "fendermint:latest" - command: "eth run" - environment: - - TENDERMINT_WS_URL=ws://cometbft-node1:26657/websocket - - LOG_LEVEL=debug - - RUST_BACKTRACE=1 - ports: - - 8546:8545 - volumes: - - $BASE_DIR/node1:/data - depends_on: - cometbft-node1: - condition: service_healthy - networks: - localnet: - ipv4_address: 192.167.10.11 - - ethapi-node2: - container_name: ethapi-node2 - user: ${UID}:${GID} - image: "fendermint:latest" - command: "eth run" - environment: - - TENDERMINT_WS_URL=ws://cometbft-node2:26657/websocket - - LOG_LEVEL=debug - - RUST_BACKTRACE=1 - ports: - - 8547:8545 - volumes: - - $BASE_DIR/node2:/data - depends_on: - cometbft-node2: - condition: service_healthy + - $BASE_DIR/node${NODE_ID}:/data networks: - localnet: - ipv4_address: 192.167.10.12 + testnet: + ipv4_address: ${FMT_NODE_ADDR} - ethapi-node3: - container_name: ethapi-node3 + ethapi-node: + container_name: ethapi-node${NODE_ID} user: ${UID}:${GID} image: "fendermint:latest" command: "eth run" environment: - - TENDERMINT_WS_URL=ws://cometbft-node3:26657/websocket + - TENDERMINT_WS_URL=ws://cometbft-node${NODE_ID}:26657/websocket - LOG_LEVEL=debug - RUST_BACKTRACE=1 ports: - - 8548:8545 + - ${PORT3}:8545 volumes: - - $BASE_DIR/node3:/data + - $BASE_DIR/node${NODE_ID}:/data depends_on: - cometbft-node2: + cometbft-node: condition: service_healthy networks: - localnet: - ipv4_address: 192.167.10.13 + testnet: + ipv4_address: ${ETHAPI_NODE_ADDR} networks: - localnet: - driver: bridge - ipam: - driver: default - config: - - subnet: 192.167.10.0/16 \ No newline at end of file + testnet: + external: true \ No newline at end of file diff --git a/infra/down.sh b/infra/down.sh new file mode 100755 index 00000000..2d88b807 --- /dev/null +++ b/infra/down.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +PORT1=26656 +PORT2=26657 +PORT3=8545 + +for i in $(seq 0 3); do + export NODE_ID=${i} + export PORT1 + export PORT2 + export PORT3 + export CMT_NODE_ADDR=192.167.10.$((${i}+2)) + export FMT_NODE_ADDR=192.167.10.$((${i}+6)) + export ETHAPI_NODE_ADDR=192.167.10.$((${i}+10)) + docker compose -f ./infra/docker-compose.yml -p testnet_node_${i} down & + PORT1=$((PORT1+3)) + PORT2=$((PORT2+3)) + PORT3=$((PORT3+1)) +done + +wait $(jobs -p) + +docker network rm -f testnet \ No newline at end of file diff --git a/infra/scripts/testnet.toml b/infra/scripts/testnet.toml index 3f0099f6..9ad2cb00 100644 --- a/infra/scripts/testnet.toml +++ b/infra/scripts/testnet.toml @@ -19,7 +19,7 @@ export GID export CMT_PERSISTENT_PEERS=`cat $BASE_DIR/peers` export CHAIN_NAME=$CHAIN_NAME export BASE_DIR=$BASE_DIR -docker compose -f ./infra/docker-compose.yml up -d +./infra/up.sh """ [tasks.testnet-down] @@ -35,7 +35,7 @@ if [ -z $GID ]; then GID=$(id -g); fi if [ -z $UID ]; then UID=$(id -u); fi export UID export GID -docker compose -f ./infra/docker-compose.yml down +./infra/down.sh """ [tasks.testnet-init] @@ -151,18 +151,20 @@ for i in $(seq 0 3); do ./fendermint genesis \ --genesis-file $BASE_DIR/genesis.json add-validator \ --public-key $BASE_DIR/node${i}/fendermint/keys/validator${i}_key.pk \ - --power 1 + --power 1 \ done -./fendermint genesis --genesis-file $BASE_DIR/genesis.json ipc gateway --subnet-id /r0 \ +./fendermint genesis --genesis-file $BASE_DIR/genesis.json ipc gateway \ + --subnet-id /r0 \ --top-down-check-period 10 \ --bottom-up-check-period 10 \ --msg-fee 10 \ - --majority-percentage 67 + --majority-percentage 67 \ + --min-collateral 1 -./fendermint genesis \ - --genesis-file $BASE_DIR/genesis.json into-tendermint \ - --out $BASE_DIR/out/genesis.json +./fendermint \ + genesis --genesis-file $BASE_DIR/genesis.json \ + into-tendermint --out $BASE_DIR/out/genesis.json for i in $(seq 0 3); do ./fendermint key into-tendermint \ diff --git a/infra/up.sh b/infra/up.sh new file mode 100755 index 00000000..ac72933a --- /dev/null +++ b/infra/up.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +docker network create testnet + +PORT1=26656 +PORT2=26657 +PORT3=8545 + +for i in $(seq 0 3); do + export NODE_ID=${i} + export PORT1 + export PORT2 + export PORT3 + export CMT_NODE_ADDR=192.167.10.$((${i}+2)) + export FMT_NODE_ADDR=192.167.10.$((${i}+6)) + export ETHAPI_NODE_ADDR=192.167.10.$((${i}+10)) + docker compose -f ./infra/docker-compose.yml -p testnet_node_${i} up -d & + PORT1=$((PORT1+3)) + PORT2=$((PORT2+3)) + PORT3=$((PORT3+1)) +done + +wait $(jobs -p) \ No newline at end of file From 7f77aaf5619d889c580517718f3230ea79744ed4 Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Mon, 25 Sep 2023 19:14:56 +0000 Subject: [PATCH 38/40] fix scripts --- infra/down.sh | 23 ----------------------- infra/{up.sh => run.sh} | 28 +++++++++++++++++++++++++--- infra/scripts/testnet.toml | 6 +++--- 3 files changed, 28 insertions(+), 29 deletions(-) delete mode 100755 infra/down.sh rename infra/{up.sh => run.sh} (51%) diff --git a/infra/down.sh b/infra/down.sh deleted file mode 100755 index 2d88b807..00000000 --- a/infra/down.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env sh - -PORT1=26656 -PORT2=26657 -PORT3=8545 - -for i in $(seq 0 3); do - export NODE_ID=${i} - export PORT1 - export PORT2 - export PORT3 - export CMT_NODE_ADDR=192.167.10.$((${i}+2)) - export FMT_NODE_ADDR=192.167.10.$((${i}+6)) - export ETHAPI_NODE_ADDR=192.167.10.$((${i}+10)) - docker compose -f ./infra/docker-compose.yml -p testnet_node_${i} down & - PORT1=$((PORT1+3)) - PORT2=$((PORT2+3)) - PORT3=$((PORT3+1)) -done - -wait $(jobs -p) - -docker network rm -f testnet \ No newline at end of file diff --git a/infra/up.sh b/infra/run.sh similarity index 51% rename from infra/up.sh rename to infra/run.sh index ac72933a..3923d137 100755 --- a/infra/up.sh +++ b/infra/run.sh @@ -1,11 +1,29 @@ #!/usr/bin/env sh -docker network create testnet +if [ $# -ne 1 ]; then + echo "usage: $0 (start|stop)" + exit 1 +fi PORT1=26656 PORT2=26657 PORT3=8545 +ACTION= + +case $1 in + start) ACTION="up -d" ;; + stop) ACTION="down" ;; + *) + echo "usage: $0 (start|stop)" + exit 1 + ;; +esac + +if [ "$1" == "start" ]; then + docker network create --subnet 192.167.10.0/16 testnet +fi + for i in $(seq 0 3); do export NODE_ID=${i} export PORT1 @@ -14,10 +32,14 @@ for i in $(seq 0 3); do export CMT_NODE_ADDR=192.167.10.$((${i}+2)) export FMT_NODE_ADDR=192.167.10.$((${i}+6)) export ETHAPI_NODE_ADDR=192.167.10.$((${i}+10)) - docker compose -f ./infra/docker-compose.yml -p testnet_node_${i} up -d & + docker compose -f ./infra/docker-compose.yml -p testnet_node_${i} $ACTION & PORT1=$((PORT1+3)) PORT2=$((PORT2+3)) PORT3=$((PORT3+1)) done -wait $(jobs -p) \ No newline at end of file +wait $(jobs -p) + +if [ "$1" == "stop" ]; then + docker network rm -f testnet +fi \ No newline at end of file diff --git a/infra/scripts/testnet.toml b/infra/scripts/testnet.toml index 9ad2cb00..8cba2259 100644 --- a/infra/scripts/testnet.toml +++ b/infra/scripts/testnet.toml @@ -19,7 +19,7 @@ export GID export CMT_PERSISTENT_PEERS=`cat $BASE_DIR/peers` export CHAIN_NAME=$CHAIN_NAME export BASE_DIR=$BASE_DIR -./infra/up.sh +./infra/run.sh start """ [tasks.testnet-down] @@ -35,7 +35,7 @@ if [ -z $GID ]; then GID=$(id -g); fi if [ -z $UID ]; then UID=$(id -u); fi export UID export GID -./infra/down.sh +./infra/run.sh stop """ [tasks.testnet-init] @@ -151,7 +151,7 @@ for i in $(seq 0 3); do ./fendermint genesis \ --genesis-file $BASE_DIR/genesis.json add-validator \ --public-key $BASE_DIR/node${i}/fendermint/keys/validator${i}_key.pk \ - --power 1 \ + --power 1 done ./fendermint genesis --genesis-file $BASE_DIR/genesis.json ipc gateway \ From f6425072b0114460a1841fe436aa57419c2c588d Mon Sep 17 00:00:00 2001 From: Denis Kolegov Date: Tue, 26 Sep 2023 18:10:41 +0000 Subject: [PATCH 39/40] remove net --- infra/docker-compose.yml | 1 + infra/run.sh | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index eaab3e3e..01bce9ea 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -58,4 +58,5 @@ services: networks: testnet: + name: ${NETWORK_NAME} external: true \ No newline at end of file diff --git a/infra/run.sh b/infra/run.sh index 3923d137..059010e4 100755 --- a/infra/run.sh +++ b/infra/run.sh @@ -21,9 +21,14 @@ case $1 in esac if [ "$1" == "start" ]; then - docker network create --subnet 192.167.10.0/16 testnet + # we need to remove the network with the same name + # because that network might me created without subnet with necessary IP address space + docker network rm -f ${NETWORK_NAME} + docker network create --subnet 192.167.10.0/16 ${NETWORK_NAME} fi +export NETWORK_NAME=${NETWORK_NAME} + for i in $(seq 0 3); do export NODE_ID=${i} export PORT1 @@ -41,5 +46,5 @@ done wait $(jobs -p) if [ "$1" == "stop" ]; then - docker network rm -f testnet + docker network rm -f ${NETWORK_NAME} fi \ No newline at end of file From 8aad8ea7a23c1dff03e1a87513af79844bd93e15 Mon Sep 17 00:00:00 2001 From: Alfonso de la Rocha Date: Tue, 26 Sep 2023 20:16:12 +0200 Subject: [PATCH 40/40] fm-150: fix infra/run.sh --- infra/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/run.sh b/infra/run.sh index 059010e4..c244a7d3 100755 --- a/infra/run.sh +++ b/infra/run.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash if [ $# -ne 1 ]; then echo "usage: $0 (start|stop)" @@ -47,4 +47,4 @@ wait $(jobs -p) if [ "$1" == "stop" ]; then docker network rm -f ${NETWORK_NAME} -fi \ No newline at end of file +fi