Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix ci and tests #174

Merged
merged 14 commits into from
Dec 16, 2024
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ jobs:
docker compose -f ci/docker-compose.yml logs -f |
awk '/Configuration finished. Running a bridge node/ {print;exit}'

- name: Wait for light node to start
run: |
docker compose -f ci/docker-compose.yml logs -f |
awk '/Configuration finished. Running a light node/ {print;exit}'

- name: Run integration tests
run: cargo test -p prism-tests --lib --release --features mock_prover

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ We are currently experimenting with various proof systems and have handwritten g

### Install Dependencies

We use `just` as a task runner. Once installed, you can install the rest of the dependencies with:
We use [`just`](https://github.com/casey/just?tab=readme-ov-file#packages) as a task runner. Once installed, you can install the rest of the dependencies with:

```bash
just install-deps
Expand Down
2 changes: 1 addition & 1 deletion ci/Dockerfile.bridge
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# A dockerfile for the celestia bridge node in DA layer
# Based on:
# https://github.com/celestiaorg/celestia-node/blob/main/Dockerfile
FROM docker.io/alpine:3.19.1
FROM docker.io/alpine:3.21.0

ENV CELESTIA_HOME=/root

Expand Down
2 changes: 1 addition & 1 deletion ci/Dockerfile.lightnode
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# A dockerfile for the celestia bridge node in DA layer
# Based on:
# https://github.com/celestiaorg/celestia-node/blob/main/Dockerfile
FROM docker.io/alpine:3.19.1
FROM docker.io/alpine:3.21.0

ENV CELESTIA_HOME=/root

Expand Down
2 changes: 1 addition & 1 deletion ci/Dockerfile.validator
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# A dockerfile for the celestia validator in consensus layer
# Based on:
# https://github.com/celestiaorg/celestia-app/blob/main/Dockerfile
FROM docker.io/alpine:3.19.1
FROM docker.io/alpine:3.21.0

ENV CELESTIA_HOME=/root

Expand Down
31 changes: 12 additions & 19 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ services:
# provide an id for the bridge node (default: 0)
# each node should have a next natural number starting from 0
- NODE_ID=0
# setting SKIP_AUTH to true disables the use of JWT for authentication
- SKIP_AUTH=true
# this must match the service name in the docker-compose.yml file
# used for the trusted peers string for the light node
- CONTAINER_NAME=bridge-0
smuu marked this conversation as resolved.
Show resolved Hide resolved
ports:
- 26658:26658
volumes:
Expand All @@ -42,6 +46,9 @@ services:
- NODE_ID=1
# setting SKIP_AUTH to true disables the use of JWT for authentication
- SKIP_AUTH=true
# this must match the service name in the docker-compose.yml file
# used for the trusted peers string for the light node
- CONTAINER_NAME=bridge-1
ports:
- 36658:26658
volumes:
Expand All @@ -55,34 +62,20 @@ services:
context: .
dockerfile: Dockerfile.lightnode
environment:
# provide an id for the bridge node (default: 0)
# provide an id for the light node (default: 0)
# each node should have a next natural number starting from 0
- NODE_ID=0
# setting SKIP_AUTH to true disables the use of JWT for authentication
- SKIP_AUTH=true
# depending on the number of bridge nodes, provide the count
# is used for the trusted peers string for the light node
- BRIDGE_COUNT=2
smuu marked this conversation as resolved.
Show resolved Hide resolved
ports:
- 46658:26658
volumes:
- credentials:/credentials
- genesis:/genesis

# Uncomment for another bridge node
# remember to adjust services.validator.command
# bridge-1:
# image: bridge
# platform: "linux/amd64"
# build:
# context: .
# dockerfile: Dockerfile.bridge
# environment:
# # provide an id for the bridge node (default: 0)
# # each node should have a next natural number starting from 0
# - NODE_ID=1
# ports:
# - 36658:26658
# volumes:
# - credentials:/credentials
# - genesis:/genesis

volumes:
# local volume where node's credentials can persist
credentials:
Expand Down
50 changes: 50 additions & 0 deletions ci/run-bridge.sh
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -euo pipefail
# Name for this node or `bridge-0` if not provided
NODE_ID="${NODE_ID:-0}"
SKIP_AUTH="${SKIP_AUTH:-false}"
CONTAINER_NAME="${CONTAINER_NAME:-bridge-$NODE_ID}"
NODE_NAME="bridge-$NODE_ID"
# a private local network
P2P_NETWORK="private"
Expand All @@ -19,6 +20,7 @@ NODE_JWT_FILE="$CREDENTIALS_DIR/$NODE_NAME.jwt"
# directory where validator will write the genesis hash
GENESIS_DIR="/genesis"
GENESIS_HASH_FILE="$GENESIS_DIR/genesis_hash"
TRUSTED_PEERS_FILE="$GENESIS_DIR/trusted_peers"

# Wait for the validator to set up and provision us via shared dir
wait_for_provision() {
Expand Down Expand Up @@ -53,6 +55,52 @@ write_jwt_token() {
celestia bridge auth admin --p2p.network "$P2P_NETWORK" > "$NODE_JWT_FILE"
}

append_trusted_peers() {
peer_id=""
start_time=$(date +%s)
timeout=30

while [[ -z "$peer_id" ]]; do
peer_id=$(celestia p2p info | jq -r '.result.id' || echo "")
if [[ -z "$peer_id" ]]; then
echo "Node is not running yet. Retrying..."
sleep 1
fi

current_time=$(date +%s)
elapsed=$((current_time - start_time))
if [[ $elapsed -ge $timeout ]]; then
echo "Failed to retrieve Peer ID after $timeout seconds. Exiting."
exit 1
fi
done

#multiaddr: /dns/$CONTAINER_NAME/tcp/$RPC_PORT/p2p/$peer_id
multiaddr="/dns/$CONTAINER_NAME/tcp/2121/p2p/$peer_id"
echo "Appending trusted peer: $multiaddr"

# Lock the file to prevent race conditions
exec 9>"$TRUSTED_PEERS_FILE.lock"
flock -x 9

# Read existing peers into a variable
existing_peers=""
if [[ -s "$TRUSTED_PEERS_FILE" ]]; then
existing_peers=$(cat "$TRUSTED_PEERS_FILE")
fi

# Append the new multiaddr to the existing peers
if [[ -n "$existing_peers" ]]; then
echo "$existing_peers,$multiaddr" > "$TRUSTED_PEERS_FILE"
else
echo "$multiaddr" > "$TRUSTED_PEERS_FILE"
fi
smuu marked this conversation as resolved.
Show resolved Hide resolved

# Unlock the file
flock -u 9
exec 9>&-
}
smuu marked this conversation as resolved.
Show resolved Hide resolved

main() {
# Initialize the bridge node
celestia bridge init --p2p.network "$P2P_NETWORK"
Expand All @@ -64,6 +112,8 @@ main() {
add_trusted_genesis
# Update the JWT token
write_jwt_token
# Append the peer multiaddr to the trusted peers (run in background, as the node needs to be running)
append_trusted_peers &
smuu marked this conversation as resolved.
Show resolved Hide resolved
# give validator some time to set up
sleep 4
# Start the bridge node
Expand Down
41 changes: 40 additions & 1 deletion ci/run-lightnode.sh
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -euo pipefail
# Name for this node or `light-0` if not provided
NODE_ID="${NODE_ID:-0}"
SKIP_AUTH="${SKIP_AUTH:-false}"
BRIDGE_COUNT="${BRIDGE_COUNT}"
smuu marked this conversation as resolved.
Show resolved Hide resolved
NODE_NAME="light-$NODE_ID"
# a private local network
P2P_NETWORK="private"
Expand All @@ -19,15 +20,43 @@ NODE_JWT_FILE="$CREDENTIALS_DIR/$NODE_NAME.jwt"
# directory where validator will write the genesis hash
GENESIS_DIR="/genesis"
GENESIS_HASH_FILE="$GENESIS_DIR/genesis_hash"
TRUSTED_PEERS_FILE="$GENESIS_DIR/trusted_peers"

# Wait for the validator to set up and provision us via shared dir
wait_for_provision() {
echo "Waiting for the validator node to start"
while [[ ! ( -e "$GENESIS_HASH_FILE" && -e "$NODE_KEY_FILE" ) ]]; do
sleep 0.1
done

echo "Validator is ready"

echo "Waiting for $BRIDGE_COUNT bridge nodes to start"
start_time=$(date +%s)
timeout=30

while true; do
if [[ -e "$TRUSTED_PEERS_FILE" ]]; then
trusted_peers="$(cat "$TRUSTED_PEERS_FILE")"
comma_count=$(echo "$trusted_peers" | grep -o "," | wc -l)
if [[ $comma_count -eq $((BRIDGE_COUNT - 1)) ]]; then
echo "$BRIDGE_COUNT bridge nodes are ready"
break
else
echo "Trusted peers file does not contain the expected number of commas. Retrying..."
fi
else
echo "Trusted peers file does not exist yet. Retrying..."
fi

current_time=$(date +%s)
elapsed=$((current_time - start_time))
if [[ $elapsed -ge $timeout ]]; then
echo "Timeout reached. Exiting."
exit 1
fi

sleep 1
done
}

# Import the test account key shared by the validator
Expand All @@ -43,11 +72,19 @@ add_trusted_genesis() {

# Read the hash of the genesis block
genesis_hash="$(cat "$GENESIS_HASH_FILE")"
trusted_peers="$(cat "$TRUSTED_PEERS_FILE")"
# and make it trusted in the node's config
echo "Trusting a genesis: $genesis_hash"
sed -i'.bak' "s/TrustedHash = .*/TrustedHash = $genesis_hash/" "$CONFIG_DIR/config.toml"
}

add_trusted_peers() {
local trusted_peers="$(cat "$TRUSTED_PEERS_FILE")"
local formatted_peers=$(echo "$trusted_peers" | sed 's/\([^,]*\)/"\1"/g')
smuu marked this conversation as resolved.
Show resolved Hide resolved
echo "Trusting peers: $formatted_peers"
sed -i'.bak' "s|TrustedPeers = .*|TrustedPeers = [$formatted_peers]|" "$CONFIG_DIR/config.toml"
}

write_jwt_token() {
echo "Saving jwt token to $NODE_JWT_FILE"
celestia light auth admin --p2p.network "$P2P_NETWORK" > "$NODE_JWT_FILE"
Expand All @@ -62,6 +99,8 @@ main() {
import_shared_key
# Trust the private blockchain
add_trusted_genesis
# Trust the bridge nodes
add_trusted_peers
# Update the JWT token
write_jwt_token
# give validator some time to set up
Expand Down
4 changes: 2 additions & 2 deletions crates/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ async fn test_light_client_prover_talking() -> Result<()> {
pretty_env_logger::init();

let bridge_cfg = CelestiaConfig {
connection_string: "ws://0.0.0.0:36658".to_string(),
connection_string: "ws://localhost:36658".to_string(),
..CelestiaConfig::default()
};
let lc_cfg = CelestiaConfig {
connection_string: "ws://0.0.0.0:26658".to_string(),
connection_string: "ws://localhost:46658".to_string(),
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
..CelestiaConfig::default()
};

Expand Down
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
33 changes: 27 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ celestia-up:
echo "Cleaning up any existing Docker resources..."
docker-compose -f {{DOCKER_COMPOSE_FILE}} down -v --remove-orphans

echo "Building Docker images..."
docker-compose -f {{DOCKER_COMPOSE_FILE}} build

distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
echo "Spinning up a fresh Docker Compose stack..."
docker-compose -f {{DOCKER_COMPOSE_FILE}} up -d --force-recreate --renew-anon-volumes

Expand Down Expand Up @@ -65,7 +68,9 @@ integration-test:
just celestia-up

echo "Running integration tests..."
cargo test -p prism-tests --lib --release --features mock_prover
if ! cargo test -p prism-tests --lib --release --features mock_prover; then
echo "Integration tests failed."
fi
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved

just celestia-down

Expand All @@ -86,10 +91,19 @@ unit-test:
cargo test --lib --release --features "mock_prover" -- --skip test_light_client_prover_talking

coverage:
@echo "Generating coverage report..."
cargo llvm-cov nextest --html --output-dir coverage_report --lib --features "mock_prover" --release --workspace --exclude prism-cli --exclude-from-report prism-sp1 --ignore-filename-regex sp1
@echo "Coverage report generated in 'coverage_report' directory"
#!/usr/bin/env bash
set -euo pipefail

just celestia-up

echo "Generating coverage report..."
if ! cargo llvm-cov nextest --html --output-dir coverage_report --lib --features "mock_prover" --release --workspace --exclude prism-cli --exclude-from-report prism-sp1 --ignore-filename-regex sp1; then
echo "Coverage report generation failed."
else
echo "Coverage report generated in 'coverage_report' directory"
fi
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved

just celestia-down

install-deps:
#!/usr/bin/env bash
Expand Down Expand Up @@ -139,13 +153,11 @@ install-deps:
echo "Protobuf is already installed."; \
fi


if ! command -v cargo prove > /dev/null; then \
echo "Installing SP1..."
curl -L https://sp1.succinct.xyz | bash; \
source ~/.bashrc || source ~/.bash_profile || source ~/.zshrc; \


echo "Running sp1up to install SP1 toolchain..."
sp1up

Expand All @@ -159,4 +171,13 @@ install-deps:
echo "SP1 is already installed."; \
fi

for tool in cargo-udeps cargo-llvm-cov cargo-nextest; do \
if ! command -v $tool > /dev/null; then \
echo "Installing $tool..."; \
cargo install $tool; \
else \
echo "$tool is already installed."; \
fi; \
done

distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
echo "All dependencies installed successfully!"
Loading