Skip to content

Commit

Permalink
ci: devnet setup with curio (#4760)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmih authored Sep 18, 2024
1 parent fa6afe4 commit c1623d2
Show file tree
Hide file tree
Showing 12 changed files with 657 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scripts/devnet-curio/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CURIO_IMAGE=curio/curio-dev:dev
LOTUS_IMAGE=ghcr.io/chainsafe/lotus-devnet:2024-07-03-1f030c2
FOREST_DATA_DIR=/forest_data
LOTUS_DATA_DIR=/lotus_data
CURIO_REPO_PATH=/var/lib/curio
FIL_PROOFS_PARAMETER_CACHE=/var/tmp/filecoin-proof-parameters
MINER_ACTOR_ADDRESS=t01000
LOTUS_RPC_PORT=1234
LOTUS_P2P_PORT=1235
MINER_RPC_PORT=2345
FOREST_RPC_PORT=3456
FOREST_OFFLINE_RPC_PORT=3457
F3_RPC_PORT=23456
F3_FINALITY=10
GENESIS_NETWORK_VERSION=23
SHARK_HEIGHT=-10
HYGGE_HEIGHT=-9
LIGHTNING_HEIGHT=-8
THUNDER_HEIGHT=-7
WATERMELON_HEIGHT=-6
DRAGON_HEIGHT=-5
WAFFLE_HEIGHT=-4
DRAND_QUICKNET_HEIGHT=-3
TARGET_HEIGHT=24
81 changes: 81 additions & 0 deletions scripts/devnet-curio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Local devnet setup

The devnet consists of a:

- Lotus miner,
- Lotus node,
- Forest node.
- Curio node.
- YugabyteDB.

It's packed in a docker compose setup for convenience and ease of usage. By
default, running it will expose relevant RPC and P2P ports to the host:

- 1234 - Lotus RPC,
- 9090 - Lotus P2P port,
- 2345 - Miner RPC,
- 3456 - Forest RPC.
- 12300 - Curio API.
- 4701 - Curio UI.
- 32100 - Curio Market.

## Running the devnet

Prerequisites:

- Fetch the Curio repository
(`git clone https://github.com/filecoin-project/curio`) and run:
- `make docker/curio-all-in-one`
- `make docker/curio`

Run it with:

```shell
docker compose up --build
```

This will build the local Forest (using the Dockerfile in the project's root)
image, tagged Lotus and setup the devnet. Initial setup may be slow due to
fetching params and setting everyting up. Consecutive starts will be quick.

Stop the devnet with:

```shell
docker compose down
```

Remove the devnet:

```shell
docker compose rm
```

## Interacting with the devnet via CLI

Exec into the `forest` container:

```shell
docker exec -it forest /bin/bash
```

and setup credentials. Then run any command:

```shell
export TOKEN=$(cat /forest_data/token.jwt)
export FULLNODE_API_INFO=$TOKEN:/dns/forest/tcp/1234/http

forest-cli net peers
```

## Known problems

- YugabyteDB sometimes fails to start. If this happens, restart the devnet.
- As of writing, using Forest with Curio doesn't work. Forest fails to find a
miner actor.

## Local devnet development

If you prefer to have Forest running directly on the host, you can comment it
out and draw inspiration from the `docker-compose.yml` on how to connect it to
Lotus. In short, you will need to obtain the peer id, network name and the
genesis file.
62 changes: 62 additions & 0 deletions scripts/devnet-curio/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
# This script is used to check the correctness
# of the local devnet in the CI.

set -eux

# Path to the directory containing this script.
PARENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
pushd "${PARENT_PATH}"
source .env

# Forest check - assert that we sync past the genesis block.
# Allow for 300 seconds of sync time.
function get_sync_height {
local port=$1
curl --silent -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","id":2,"method":"Filecoin.ChainHead","param":"null"}' \
"http://127.0.0.1:${port}/rpc/v0" | jq '.result.Height'
}

function get_f3_latest_cert_instance {
local port=$1
curl --silent -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","id":2,"method":"Filecoin.F3GetLatestCertificate","param":"null"}' \
"http://127.0.0.1:${port}/rpc/v1" | jq '.result.GPBFTInstance'
}

start_time=$(date +%s)
timeout=$((start_time + 300)) # Set timeout to 10 minutes

# Target height set so that all migrations are applied.
target_height=$TARGET_HEIGHT

while true; do
height=$(get_sync_height ${FOREST_RPC_PORT})
if [ "$height" -gt "$target_height" ]; then
echo "Height is larger than $target_height: $height"
break
fi

current_time=$(date +%s)
if [ "$current_time" -gt "$timeout" ]; then
echo "Timeout reached, height is still not larger than $target_height: $height"
exit 1
fi

sleep 1
done

# Check the offline RPC, which should be initialized at that point. It should be at the genesis height, so 0.
height=$(get_sync_height ${FOREST_OFFLINE_RPC_PORT})
if [ "$height" -ne 0 ]; then
echo "Offline RPC height is not zero: $height"
exit 1
fi

# Check the F3 RPC
height=$(get_f3_latest_cert_instance ${FOREST_RPC_PORT})
if [ "$height" -lt 1 ]; then
echo "latest cert instance should be greater than zero: $height"
exit 1
fi
6 changes: 6 additions & 0 deletions scripts/devnet-curio/curio.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LOTUS_PATH=/lotus_data/lotus-local-net
LOTUS_MINER_PATH=/lotus_data/lotus-miner-local-net
LOTUS_SKIP_GENESIS_CHECK=_yes_
LOTUS_API_LISTENADDRESS=/dns/lotus-miner/tcp/2345/http
CURIO_REPO_PATH=/var/lib/curio
CURIO_HARMONYDB_HOSTS=yugabyte
Loading

0 comments on commit c1623d2

Please sign in to comment.