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

CI: test infra scripts. #368

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
25714c6
improve localnet.md
raulk Oct 24, 2023
7fd2c43
add Foundry as a prerequisite.
raulk Oct 24, 2023
38c5361
add `pkg-config` dependency
raulk Oct 24, 2023
aae1179
`libssl-dev` package
raulk Oct 24, 2023
a10dd44
add more system packages.
raulk Oct 24, 2023
a632095
localnet scripts: use Docker image to prepare genesis.
raulk Oct 24, 2023
f43177b
create eth account; print report.
raulk Oct 25, 2023
1d46594
correct typo.
raulk Oct 25, 2023
8594b38
drop 'script'.
raulk Oct 25, 2023
7000ce1
fixes; increase wait time.
raulk Oct 26, 2023
5ddd1cb
improve testnode report.
raulk Oct 26, 2023
80e0e44
drop 'script'.
raulk Oct 25, 2023
5a8aabb
infra: make testnet targets use Docker images.
raulk Oct 26, 2023
6d5ae1d
Merge branch 'main' into raulk/fix-localnet-script
raulk Oct 26, 2023
baee141
rework subnet commands; fix merge snafu.
raulk Oct 26, 2023
9f18241
Merge branch 'main' into raulk/fix-localnet-script
raulk Oct 26, 2023
dec0f5d
Merge branch 'main' into raulk/fix-localnet-script
raulk Oct 26, 2023
ebbb93b
slashes break things.
raulk Oct 26, 2023
1dfbb2d
add network type.
raulk Oct 27, 2023
9823566
Merge branch 'main' into raulk/fix-localnet-script
raulk Oct 27, 2023
53a3c56
fixes.
raulk Oct 27, 2023
5e87eab
fix env var NETWORK_TYPE => FM_NETWORK.
raulk Oct 27, 2023
3267d1b
improve localnet.md.
raulk Oct 30, 2023
321534c
pull fendermint image from remote.
raulk Oct 30, 2023
51d2edc
fix substitution.
raulk Oct 30, 2023
03f27af
FM_PULL_SKIP to skip pulling Fendermint image.
raulk Oct 30, 2023
b3fb164
move build prerequisites to new 'Build from source' section.
raulk Oct 30, 2023
747b89d
Merge branch 'main' into raulk/fix-localnet-script
adlrocha Oct 30, 2023
d9ccb50
FIX: remove duplicate --network flag
adlrocha Oct 30, 2023
cd91a38
FIX: add cargo-make as a dependency for localnet
adlrocha Oct 30, 2023
cbbb9b0
small edits.
raulk Oct 30, 2023
46b4240
infra: subnet validator now loads private key correctly.
raulk Oct 30, 2023
9bce2c5
extract bootstrap infra scripts.
raulk Oct 30, 2023
a0f7158
normalize .ipc directory structure to <network_name>/<node_name>.
raulk Oct 30, 2023
daed22c
rework subnet infra scripts.
raulk Oct 30, 2023
867fad2
CI: test infra scripts.
raulk Oct 30, 2023
9bef0fc
alias remotely pulled image.
raulk Oct 30, 2023
a82a2a0
Merge branch 'raulk/fix-localnet-script' into raulk/ci-infra
raulk Oct 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/infra-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Infra test

on:
workflow_call:

## TMP TODO REMOVE Only for testing
pull_request:
branches:
- '**'
# To add ready_for_review as a trigger we need to list all the defaults.
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
test:
name: Test infra scripts
runs-on: ubuntu-latest
steps:
- name: Check out the project
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt
- name: Install cargo-make
run: |
cargo install --force cargo-make
- name: Run testnode
run: |
cargo make --makefile ./infra/Makefile.toml testnode
## TODO run a smoke test
cargo make --makefile ./infra/Makefile.toml testnode-down
- name: Run testnet
run: |
cargo make --makefile ./infra/Makefile.toml testnet
## TODO run a smoke test
cargo make --makefile ./infra/Makefile.toml testnet-down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@
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

Please have a look in the [docs](./docs/README.md) to see an overview of the project, how to run the components, and previous demos.

## IPC

Fendermint is built with support for [IPC](https://github.com/consensus-shipyard/ipc) by design. If you are looking to deploy the infrastructure Fendermint-based IPC subnet, refer to the [IPC main repo](https://github.com/consensus-shipyard/ipc), or have a look at the [IPC infrastructure docs](./docs/ipc.md).

## Building from source

**Linux.** Install the following pre-requisites (instructions for Ubuntu):

- Install system packages: `sudo apt install build-essential clang cmake pkg-config libssl-dev protobuf-compiler`.
- Install Rust. See [instructions](https://www.rust-lang.org/tools/install).
- Install cargo-make: `cargo install --force cargo-make`.
- Install Foundry. See [instructions](https://book.getfoundry.sh/getting-started/installation).
- Install Docker (if you intend to build Docker images). See [instructions](https://docs.docker.com/engine/install/ubuntu/).

## Testing

The following command runs unit and integration tests:
Expand All @@ -28,7 +40,6 @@ while the next command builds docker images and runs an end-to-end test using th
make e2e
```


## IPC Solidity Actors

We generate Rust bindings for the Solidity actors we need to invoke from the [ipc-solidity-actors](https://github.com/consensus-shipyard/ipc-solidity-actors) library, some of which are deployed during the genesis process. The bindings live in [ipc_actors](./fendermint/vm/ipc_actors/), and are generated automatically during the build, or with the following command:
Expand All @@ -47,7 +58,6 @@ To test whether the genesis process works, we can run the following unit test:
cargo test --release -p fendermint_vm_interpreter load_genesis
```


## Pre-built Docker Image

The CI build publishes a [Docker image](https://github.com/consensus-shipyard/fendermint/pkgs/container/fendermint) to Github Container Registry upon a successful build on the `main` branch. This is the same image as the one used in the End-to-End tests; it contains the built-in actor bundle and IPC Solidity actors, ready to be deployed during genesis.
Expand Down
68 changes: 46 additions & 22 deletions docs/localnet.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
# Local Testnets

Prerequisites:
```bash
make build docker-build
```
Setting up a Fendermint local testnet is a way to get started quickly with IPC.

This guide offers two flavours:

- A single node deployment: useful for developing smart contracts and testing the APIs.
- A 4 node testnet: useful for testing consensus, checkpointing, and more.

## Prerequisites

On Linux (links and instructions for Ubuntu):

- Install Docker. See [instructions](https://docs.docker.com/engine/install/ubuntu/).
- Install Rust. See [instructions](https://www.rust-lang.org/tools/install).
- Install cargo-make: `cargo install --force cargo-make`.

## Docker images

These commands will pull various Docker images from remote repositories, including `fendermint:latest`, by default.

- To override which Fendermint Docker image to pull, set the `FM_DOCKER_TAG` env variable to the desired tag.
- To use a local Fendermint image, set the `FM_PULL_SKIP` env variable to some value, e.g. `FM_PULL_SKIP=true`.

## Single node deployment

To run IPC in the local rootnet just perform the following :
To run IPC in the local rootnet just perform the following:

```bash
cargo make --makefile ./infra/Makefile.toml testnode

```

It will create three docker containers (cometbft, fendermint, and eth-api).
Expand All @@ -21,41 +38,48 @@ cargo make --makefile ./infra/Makefile.toml testnode-down
```

## Local 4-nodes deployment
To run IPC in the local 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 ./infra/Makefile.toml testnet

```

To stop the network:

```bash
cargo make --makefile ./infra/Makefile.toml testnet-down
```

The testnet contains four logical nodes. Each node consists of cometbft, fendermint, and ethapi containers.
The Docker internal network is `192.167.10.0/24`.

ETH-API is accessible on the following interfaces on the Docker internal network:
The Ethereum API is accessible on the following endpoints on the Docker internal network:

- `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:
And on the following endpoints 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:
- 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 CometBFT in 4 containers
- Run Eth API in 4 containers
## What's happening behind the scenes

> For a 4-node deployment.

The deployment process performs the following steps:

- Remove all Docker containers, files, networks, etc. from any previous deployments.
- 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 them 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 CometBFT in 4 containers.
- Run Eth API in 4 containers.
32 changes: 19 additions & 13 deletions infra/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ extend = [
{ path = "scripts/cometbft.toml" },
{ path = "scripts/fendermint.toml" },
{ path = "scripts/ethapi.toml" },
{ path = "scripts/genesis.toml"},
{ path = "scripts/node.toml" },
{ path = "scripts/testnet.toml" },
{ path = "scripts/testnode.toml" },
{ path = "scripts/subnet.toml" }
{ path = "scripts/subnet.toml" },
{ path = "scripts/bootstrap.toml" },
]

[config]
default_to_workspace = false

[env]
# General network-specific parameters
SUBNET_ID = { value = "/r0", condition = { env_not_set = ["SUBNET_ID"] }}
SUBNET_ID = { value = "/r0", condition = { env_not_set = ["SUBNET_ID"] } }
# The network name is derived from the SUBNET_ID, replacing slashes with dashes, and dropping the first dash if any.
NETWORK_NAME = { script = ["echo $SUBNET_ID | sed -e 's/\\//-/g' -e 's/^-//1'"] }

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"] }}
Expand All @@ -29,31 +34,32 @@ NODE_NAME = { value = "ipc-node", condition = { env_not_set = ["NODE_NAME"] } }
PARENT_ENDPOINT = { value = "https://api.calibration.node.glif.io/rpc/v1", condition = { env_not_set = ["PARENT_ENDPOINT"] } }
PARENT_GATEWAY = { value = "0x56948d2CFaa2EF355B8C08Ac925202db212146D1", condition = { env_not_set = ["PARENT_GATEWAY"] } }
PARENT_REGISTRY = { value = "0x6A4884D2B6A597792dC68014D4B7C117cca5668e", condition = { env_not_set = ["PARENT_REGISTRY"] } }
NETWORK_TYPE = { value = "test", condition = { env_not_set = ["NETWORK_TYPE"] } }
VALIDATOR_PRIV_KEY = { value = "~/.ipc/priv.key", condition = { env_not_set = ["VALIDATOR_PRIV_KEY"] } }
FM_NETWORK = { value = "test", condition = { env_not_set = ["FM_NETWORK"] } }
TOPDOWN_CHAIN_HEAD_DELAY = { value = "10", condition = { env_not_set = ["TOPDOWN_CHAIN_HEAD_DELAY"] } }
# Comma-separated list of bootstrap nodes to be used by the CometBFT node.
BOOTSTRAPS = { value = "", condition = { env_not_set = ["BOOTSTRAPS"] } }

# Deployment-related
BASE_DIR="${HOME}/.ipc/${SUBNET_ID}"
FM_DIR="${BASE_DIR}/fendermint"
CMT_DIR="${BASE_DIR}/cometbft"
BASE_DIR="${HOME}/.ipc/${NETWORK_NAME}"
FM_DIR="${BASE_DIR}/${NODE_NAME}/fendermint"
CMT_DIR="${BASE_DIR}/${NODE_NAME}/cometbft"

GENESIS_FILE="${FM_DIR}/genesis.json"
KEYS_DIR="${FM_DIR}/keys"
GENESIS_FILE="${BASE_DIR}/genesis.json"
KEYS_SUBDIR="keys"
KEY_NAME="validator_key"
PUB_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.pk"
PRIV_KEY_PATH="${KEYS_DIR}/${KEY_NAME}.sk"
PUB_KEY_PATH="${KEYS_SUBDIR}/${KEY_NAME}.pk"
PRIV_KEY_PATH="${KEYS_SUBDIR}/${KEY_NAME}.sk"

NETWORK_NAME = "${SUBNET_ID}"
COMETBFT_SUBDIR = "cometbft"

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"
FM_DOCKER_TAG = "latest"
FM_DOCKER_IMAGE = "fendermint:${FM_DOCKER_TAG}"
FM_REMOTE_DOCKER_IMAGE = "ghcr.io/consensus-shipyard/fendermint:${FM_DOCKER_TAG}"
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"
Expand Down
30 changes: 16 additions & 14 deletions infra/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
services:
fendermint-node:
container_name: fendermint-node${NODE_ID}
user: ${UID}:${GID}
image: "fendermint:latest"
environment:
- FM_DATA_DIR=/data/fendermint/data
- FM_CHAIN_NAME=$NETWORK_NAME
- TENDERMINT_RPC_URL=http://cometbft-node${NODE_ID}:26657
- LOG_LEVEL=info
- FM_NETWORK=$FM_NETWORK
volumes:
- $BASE_DIR/node${NODE_ID}:/data
networks:
testnet:
ipv4_address: ${FMT_NODE_ADDR}

cometbft-node:
container_name: cometbft-node${NODE_ID}
user: ${UID}:${GID}
Expand All @@ -22,20 +38,6 @@ services:
testnet:
ipv4_address: ${CMT_NODE_ADDR}

fendermint-node:
container_name: fendermint-node${NODE_ID}
user: ${UID}:${GID}
image: "fendermint:latest"
environment:
- FM_DATA_DIR=/data/fendermint/data
- FM_CHAIN_NAME=$SUBNET_ID
- LOG_LEVEL=info
volumes:
- $BASE_DIR/node${NODE_ID}:/data
networks:
testnet:
ipv4_address: ${FMT_NODE_ADDR}

ethapi-node:
container_name: ethapi-node${NODE_ID}
user: ${UID}:${GID}
Expand Down
11 changes: 11 additions & 0 deletions infra/scripts/bootstrap.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tasks.bootstrap]
env = { "NETWORK_NAME"="${NETWORK_NAME}", "CMT_DIR" = "${BASE_DIR}/bootstrap/cometbft", "CMT_CONTAINER_NAME" = "cometbft-${NODE_NAME}-bootstrap" }
run_task = "new-node"

[tasks.bootstrap-id]
env = { "CMT_CONTAINER_NAME" = "cometbft-${NODE_NAME}-bootstrap" }
run_task = "cometbft-node-id"

[tasks.bootstrap-down]
env = { "CMT_CONTAINER_NAME" = "cometbft-${NODE_NAME}-bootstrap" }
run_task = "node-down"
34 changes: 30 additions & 4 deletions infra/scripts/fendermint.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
extend = "fendermint-run"
env = { "ENTRY" = "fendermint", "CMD" = "run", "FLAGS" = "-d" }

[tasks.fendermint-run]
[tasks.fendermint-pull]
condition = { env_not_set = ["FM_PULL_SKIP"], fail_message = "Skipped pulling fendermint Docker image." }
script = """
docker pull ghcr.io/consensus-shipyard/fendermint:${FM_DOCKER_TAG}
docker tag ghcr.io/consensus-shipyard/fendermint:${FM_DOCKER_TAG} fendermint:${FM_DOCKER_TAG}
"""

[tasks.fendermint-run]
script.main = """
docker run \
${FLAGS} \
--name ${FM_CONTAINER_NAME} \
Expand All @@ -15,9 +22,11 @@ docker run \
--env FM_CHAIN_NAME=${NETWORK_NAME} \
--env TENDERMINT_RPC_URL=http://${CMT_CONTAINER_NAME}:26657 \
--env LOG_LEVEL=info \
--env RUST_BACKTRACE=1 \
--entrypoint ${ENTRY} \
${FM_DOCKER_IMAGE} \
--network=${NETWORK_TYPE} ${CMD}
--network=${FM_NETWORK} \
${CMD}
"""
dependencies = ["docker-network-create", "fendermint-deps"]

Expand All @@ -36,7 +45,7 @@ docker run \
--volume ${BASE_DIR}:/data \
--env FM_DATA_DIR=/data/fendermint/data \
--env FM_CHAIN_NAME=${NETWORK_NAME} \
--env FM_IPC__SUBNET_ID=${NETWORK_NAME} \
--env FM_IPC__SUBNET_ID=${SUBNET_ID} \
--env FM_IPC__TOPDOWN__CHAIN_HEAD_DELAY=${TOPDOWN_CHAIN_HEAD_DELAY} \
--env FM_IPC__TOPDOWN__PARENT_HTTP_ENDPOINT=${PARENT_ENDPOINT} \
--env FM_IPC__TOPDOWN__PARENT_REGISTRY=${PARENT_REGISTRY} \
Expand All @@ -49,13 +58,30 @@ docker run \
--env FM_TENDERMINT_RPC_URL=http://${CMT_CONTAINER_NAME}:26657 \
--env TENDERMINT_RPC_URL=http://${CMT_CONTAINER_NAME}:26657 \
--env LOG_LEVEL=info \
--env RUST_BACKTRACE=1 \
--entrypoint ${ENTRY} \
${FM_DOCKER_IMAGE} \
--network=${NETWORK_TYPE} \
--network=${FM_NETWORK} \
${CMD}
"""
dependencies = ["docker-network-create", "fendermint-deps"]

[tasks.fendermint-tool]
script.main = """
docker run \
${FLAGS} \
--init \
--user $(id -u) \
--volume ${BASE_DIR}:/data \
--env LOG_LEVEL=info \
--env RUST_BACKTRACE=1 \
--entrypoint ${ENTRY} \
${FM_DOCKER_IMAGE} \
--network=${FM_NETWORK} \
${CMD}
"""
dependencies = ["fendermint-deps"]

[tasks.fendermint-deps]
script = """
# Check if the image exists
Expand Down
Loading