Skip to content

Commit

Permalink
build(repo): Automate running fuel-core-nats locally (#20)
Browse files Browse the repository at this point in the history
* build(repo): allow starting & stopping nats server locally

* build(repo): start nats with jetstream always

* fix(fuel-core-nats): remove trailing '.' in 'assets' subject

* build(fuel-core-nats): automate running fuel-core-nats locally

* refactor(fuel-core-nats): re-introduce command as dev/run-node

* refactor(fuel-core-nats): improve fuel core nats dev script

This change allows creating a .env file matching the templated environment variables from
.env.sample to start the fuel-core-nats service locally.
  • Loading branch information
Jurshsmith authored and pedronauck committed Aug 16, 2024
1 parent 08b6ccf commit 5519c83
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
KEYPAIR=generated-p2p-secret
RELAYER=https://sepolia.infura.io/v3/infura-api-key
RELAYER_V2_LISTENING_CONTRACTS=0x768f9459E3339A1F7d59CcF24C80Eb4A711a01FB
RELAYER_DA_DEPLOY_HEIGHT=5791365
RELAYER_LOG_PAGE_SIZE=2000
SYNC_HEADER_BATCH_SIZE=100
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ check-commands:
done

setup: COMMANDS=rustup pre-commit
setup: check-commands
setup: check-commands
./scripts/setup.sh

# ------------------------------------------------------------
# Development
# ------------------------------------------------------------

dev:
cargo run
# Starts fuel-core-nats service
start.fuel-core-nats:
./scripts/start-fuel-core-nats.sh

dev-watch:
cargo watch -- cargo run
Expand All @@ -45,7 +45,7 @@ start-nats: CMDS=docker-compose
start-nats: check-commands
docker-compose -f docker/docker-compose.yml up

stop-nats:
stop-nats:
docker-compose -f docker/docker-compose.yml down

run:
Expand Down
49 changes: 49 additions & 0 deletions scripts/start-fuel-core-nats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Load environment variables from .env file
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
else
echo ".env file not found. Please create a .env file using the '.env.sample' template and try again."
exit 1
fi

# Function to check if environment variables are set
check_env_vars() {
local missing_vars=0

while IFS= read -r line; do
# Skip empty lines and comments
[[ -z "$line" || "$line" == \#* ]] && continue

# Extract the key
key=$(echo "$line" | cut -d '=' -f 1)

# Check if the key is set in the environment
if [ -z "${!key}" ]; then
echo "Environment variable $key is not set."
missing_vars=$((missing_vars + 1))
fi
done < ".env.sample"

return $missing_vars
}

check_env_vars

cargo run -p fuel-core-nats -- \
--service-name "NATS Publisher Node" \
--ip 0.0.0.0 \
--port 4000 \
--peering-port 30333 \
--db-path tmp/fuel-core-db \
--utxo-validation \
--poa-instant false \
--enable-p2p \
--keypair $KEYPAIR \
--sync-header-batch-size $SYNC_HEADER_BATCH_SIZE \
--enable-relayer \
--relayer $RELAYER \
--relayer-v2-listening-contracts $RELAYER_V2_LISTENING_CONTRACTS \
--relayer-da-deploy-height $RELAYER_DA_DEPLOY_HEIGHT \
--relayer-log-page-size $RELAYER_LOG_PAGE_SIZE \

0 comments on commit 5519c83

Please sign in to comment.