Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# IDEs
.vscode
.env.secrets
.claude
.env.secrets

# Local config files
config/local/
67 changes: 67 additions & 0 deletions config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Config Directory

Management of configuration files for the local-network Docker Compose stack.

## Structure

```
config/
├── templates/ # Template files (committed to git)
│ ├── horizon.json
│ ├── subgraph-service.json
│ └── tap-contracts.json
├── local/ # Working copies (gitignored, auto-generated)
│ ├── horizon.json
│ ├── subgraph-service.json
│ └── tap-contracts.json
├── create-local-config-files.sh
└── README.md
```

## How It Works

### 1. Initialization (`init-config` service)
- Runs **first** before all other services
- Executes `create-local-config-files.sh`
- Copies `templates/*.json` → `local/*.json` (only when target files do not exist)
- Ensures config files are ready before other containers start

### 2. File Generation (`graph-contracts` service)
- Deploys smart contracts using Hardhat
- Writes contract addresses to mounted `local/horizon.json` and `local/subgraph-service.json`
- Adds legacy contract entries (`LegacyDisputeManager`, `LegacyServiceRegistry`) to `local/subgraph-service.json`

### 3. TAP Contracts (`tap-contracts` service)
- Deploys TAP (Timeline Aggregation Protocol) contracts
- Writes addresses to mounted `local/tap-contracts.json`

## Files

### `horizon.json`
- **Generated by:** `graph-contracts` (Hardhat deployment)
- **Contains:** Horizon protocol contract addresses
- **Mounted in:** Multiple services as `/opt/horizon.json:ro` (read-only)

### `subgraph-service.json`
- **Generated by:** `graph-contracts` (Hardhat deployment + jq patch for legacy contracts)
- **Contains:** Subgraph service contract addresses
- **Mounted in:** Multiple services as `/opt/subgraph-service.json:ro` (read-only)

### `tap-contracts.json`
- **Generated by:** `tap-contracts` (TAP deployment)
- **Contains:** TAP v1 contract addresses (legacy payment system)
- **Mounted in:** Multiple services as `/opt/tap-contracts.json:ro` (read-only)

## Cleaning

To remove generated config files and reset the environment:

```bash
./scripts/clean.sh
```

This will:
1. Stop and remove all containers
2. Optionally remove Docker volumes (postgres data, etc.)
3. **Remove all files in `config/local/`**
4. Optionally remove Docker images
19 changes: 19 additions & 0 deletions config/create-local-config-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
set -e

# Get the directory where this script is located
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)

# Create the local directory if it doesn't exist
mkdir -p "$SCRIPT_DIR/local"

# Copy all template files to local if they don't exist
for file in "$SCRIPT_DIR/templates"/*; do
filename=$(basename "$file")
if [ ! -f "$SCRIPT_DIR/local/$filename" ]; then
echo "Copying $SCRIPT_DIR/templates/$filename to $SCRIPT_DIR/local/$filename"
cp "$file" "$SCRIPT_DIR/local/$filename"
fi
done

echo "Config files initialized successfully"
1 change: 1 addition & 0 deletions config/templates/horizon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions config/templates/subgraph-service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions config/templates/tap-contracts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
83 changes: 48 additions & 35 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
services:
init-config:
container_name: init-config
image: node:23.11-bookworm-slim
user: "1000"
command: sh config/create-local-config-files.sh
volumes:
- ./config:/work/config
working_dir: /work

chain:
container_name: chain
build: { context: chain }
build: { context: chain }
ports: ["${CHAIN_RPC}:8545"]
command: ["anvil --host=0.0.0.0 --chain-id=1337 --base-fee=0"]
healthcheck: { interval: 1s, retries: 10, test: cast block }
Expand All @@ -10,22 +19,18 @@ services:

block-explorer:
container_name: block-explorer
build: {
context: block-explorer,
args: { RPC_URL: http://localhost:8545 }
}
build: { context: block-explorer, args: { RPC_URL: http://localhost:8545 } }
depends_on:
chain: { condition: service_healthy }
ports: ["${BLOCK_EXPLORER}:3000"]

ipfs:
container_name: ipfs
image: ipfs/kubo:v0.34.1
image: ipfs/kubo:v0.38.2
ports: ["${IPFS_RPC}:5001"]
environment:
IPFS_PROFILE: server
healthcheck:
{ interval: 1s, retries: 50, test: ipfs id }
healthcheck: { interval: 1s, retries: 50, test: ipfs id }

postgres:
container_name: postgres
Expand All @@ -38,8 +43,7 @@ services:
POSTGRES_INITDB_ARGS: "--encoding UTF8 --locale=C"
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_USER: postgres
healthcheck:
{ interval: 1s, retries: 20, test: pg_isready -U postgres }
healthcheck: { interval: 1s, retries: 20, test: pg_isready -U postgres }

graph-node:
container_name: graph-node
Expand Down Expand Up @@ -70,11 +74,12 @@ services:
CONTRACTS_COMMIT: ${CONTRACTS_COMMIT}
NETWORK_SUBGRAPH_COMMIT: ${NETWORK_SUBGRAPH_COMMIT}
depends_on:
init-config: { condition: service_completed_successfully }
graph-node: { condition: service_healthy }
volumes:
- ./.env:/opt/.env:ro
- ./horizon.json:/opt/contracts/packages/horizon/addresses-local-network.json
- ./subgraph-service.json:/opt/contracts/packages/subgraph-service/addresses-local-network.json
- ./config/local/horizon.json:/opt/contracts/packages/horizon/addresses-local-network.json
- ./config/local/subgraph-service.json:/opt/contracts/packages/subgraph-service/addresses-local-network.json
environment:
- FORK_RPC_URL=${FORK_RPC_URL:-}

Expand All @@ -90,8 +95,8 @@ services:
graph-contracts: { condition: service_completed_successfully }
volumes:
- ./.env:/opt/.env:ro
- ./horizon.json:/opt/horizon.json:ro
- ./tap-contracts.json:/opt/tap-contracts.json
- ./config/local/horizon.json:/opt/horizon.json:ro
- ./config/local/tap-contracts.json:/opt/tap-contracts.json

block-oracle:
container_name: block-oracle
Expand All @@ -104,11 +109,15 @@ services:
stop_signal: SIGKILL
volumes:
- ./.env:/opt/.env:ro
- ./horizon.json:/opt/horizon.json:ro
- ./config/local/horizon.json:/opt/horizon.json:ro
environment:
RUST_BACKTRACE: full
healthcheck:
{ interval: 1s, retries: 600, test: curl -f http://127.0.0.1:9090/metrics }
{
interval: 1s,
retries: 600,
test: curl -f http://127.0.0.1:9090/metrics,
}

indexer-agent:
container_name: indexer-agent
Expand All @@ -123,9 +132,9 @@ services:
stop_signal: SIGKILL
volumes:
- ./.env:/opt/.env:ro
- ./horizon.json:/opt/horizon.json:ro
- ./subgraph-service.json:/opt/subgraph-service.json:ro
- ./tap-contracts.json:/opt/tap-contracts.json:ro
- ./config/local/horizon.json:/opt/horizon.json:ro
- ./config/local/subgraph-service.json:/opt/subgraph-service.json:ro
- ./config/local/tap-contracts.json:/opt/tap-contracts.json:ro
healthcheck:
{ interval: 10s, retries: 600, test: curl -f http://127.0.0.1:7600/ }

Expand All @@ -139,7 +148,7 @@ services:
chain: { condition: service_healthy }
volumes:
- ./.env:/opt/.env:ro
- ./subgraph-service.json:/opt/subgraph-service.json:ro
- ./config/local/subgraph-service.json:/opt/subgraph-service.json:ro

redpanda:
container_name: redpanda
Expand All @@ -161,7 +170,11 @@ services:
- --pandaproxy-addr 0.0.0.0:8082
- --schema-registry-addr 0.0.0.0:8081
healthcheck:
{ interval: 1s, retries: 600, test: rpk topic list --brokers="localhost:9092" }
{
interval: 1s,
retries: 600,
test: rpk topic list --brokers="localhost:9092",
}

tap-aggregator:
container_name: tap-aggregator
Expand All @@ -175,8 +188,8 @@ services:
stop_signal: SIGKILL
volumes:
- ./.env:/opt/.env:ro
- ./horizon.json:/opt/horizon.json:ro
- ./tap-contracts.json:/opt/tap-contracts.json:ro
- ./config/local/horizon.json:/opt/horizon.json:ro
- ./config/local/tap-contracts.json:/opt/tap-contracts.json:ro
environment:
RUST_LOG: info,tap_aggregator=trace
RUST_BACKTRACE: 1
Expand All @@ -193,7 +206,7 @@ services:
stop_signal: SIGKILL
volumes:
- ./.env:/opt/.env:ro
- ./horizon.json:/opt/horizon.json:ro
- ./config/local/horizon.json:/opt/horizon.json:ro
environment:
RUST_LOG: info,tap_escrow_manager=trace
RUST_BACKTRACE: 1
Expand All @@ -213,8 +226,8 @@ services:
stop_signal: SIGKILL
volumes:
- ./.env:/opt/.env:ro
- ./horizon.json:/opt/horizon.json:ro
- ./subgraph-service.json:/opt/subgraph-service.json:ro
- ./config/local/horizon.json:/opt/horizon.json:ro
- ./config/local/subgraph-service.json:/opt/subgraph-service.json:ro
environment:
RUST_LOG: info,graph_gateway=trace
RUST_BACKTRACE: 1
Expand All @@ -233,14 +246,14 @@ services:
indexer-agent: { condition: service_healthy }
ipfs: { condition: service_healthy }
tap-escrow-manager: { condition: service_started }
ports:
ports:
- "${INDEXER_SERVICE}:7601"
stop_signal: SIGKILL
volumes:
- ./.env:/opt/.env:ro
- ./horizon.json:/opt/horizon.json:ro
- ./subgraph-service.json:/opt/subgraph-service.json:ro
- ./tap-contracts.json:/opt/tap-contracts.json:ro
- ./config/local/horizon.json:/opt/horizon.json:ro
- ./config/local/subgraph-service.json:/opt/subgraph-service.json:ro
- ./config/local/tap-contracts.json:/opt/tap-contracts.json:ro
environment:
RUST_LOG: info,indexer_service_rs=trace
RUST_BACKTRACE: 1
Expand All @@ -259,9 +272,9 @@ services:
stop_signal: SIGKILL
volumes:
- ./.env:/opt/.env:ro
- ./horizon.json:/opt/horizon.json:ro
- ./subgraph-service.json:/opt/subgraph-service.json:ro
- ./tap-contracts.json:/opt/tap-contracts.json:ro
- ./config/local/horizon.json:/opt/horizon.json:ro
- ./config/local/subgraph-service.json:/opt/subgraph-service.json:ro
- ./config/local/tap-contracts.json:/opt/tap-contracts.json:ro
environment:
RUST_LOG: info,indexer_tap_agent=trace
RUST_BACKTRACE: 1
RUST_BACKTRACE: 1
16 changes: 7 additions & 9 deletions graph-contracts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ ARG CONTRACTS_COMMIT
ARG NETWORK_SUBGRAPH_COMMIT

RUN apt-get update \
&& apt-get install -y curl git jq nodejs npm \
&& rm -rf /var/lib/apt/lists/*
&& apt-get install -y curl git jq nodejs npm \
&& rm -rf /var/lib/apt/lists/*
RUN npm install -g corepack \
&& corepack enable \
&& corepack prepare [email protected] --activate \
&& corepack prepare [email protected] --activate

&& corepack enable \
&& corepack prepare [email protected] --activate \
&& corepack prepare [email protected] --activate

# Install Foundry
COPY --from=ghcr.io/foundry-rs/foundry:v1.0.0 \
Expand All @@ -18,13 +17,12 @@ COPY --from=ghcr.io/foundry-rs/foundry:v1.0.0 \
WORKDIR /opt

RUN git clone https://github.com/graphprotocol/contracts && \
cd contracts && git checkout ${CONTRACTS_COMMIT} && \
pnpm install --ignore-scripts && pnpm build
cd contracts && git checkout ${CONTRACTS_COMMIT} && \
pnpm install --ignore-scripts && pnpm build

RUN git clone https://github.com/graphprotocol/graph-network-subgraph && \
cd graph-network-subgraph && git checkout ${NETWORK_SUBGRAPH_COMMIT} && \
pnpm install && pnpm add -D ts-node

COPY ./run.sh /opt/run.sh
ENTRYPOINT bash -cl /opt/run.sh

22 changes: 10 additions & 12 deletions graph-contracts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,25 @@ then
fi
fi

# Initialize address books
cd /opt/contracts/packages
cd horizon && echo "{}" > addresses-local-network.json && cd ..
cd subgraph-service && echo "{}" > addresses-local-network.json && cd ..

# == DEPLOY PROTOCOL WITH SUBGRAPH SERVICE ==
echo "No FORK_RPC_URL detected, deploying new version of the protocol"
cd /opt/contracts/packages/subgraph-service
npx hardhat deploy:protocol --network localNetwork --subgraph-service-config localNetwork

# Add legacy contracts to the deployed addresses (mounted file at addresses-local-network.json)
# The hardhat deployment doesn't include these, but the gateway needs them
# Use a temp variable to avoid breaking the Docker volume mount (mv creates a new inode)
TEMP_JSON=$(jq '.["1337"] += {
"LegacyServiceRegistry": {"address": "0x0000000000000000000000000000000000000000"},
"LegacyDisputeManager": {"address": "0x0000000000000000000000000000000000000000"}
}' addresses-local-network.json)
printf '%s\n' "$TEMP_JSON" > addresses-local-network.json

# == DEPLOY NETWORK SUBGRAPH ==
cp /opt/contracts/packages/horizon/addresses-local-network.json /opt/horizon.json
cp /opt/contracts/packages/subgraph-service/addresses-local-network.json /opt/subgraph-service.json
cd /opt/graph-network-subgraph

# Patch subgraph service address book, add "legacy" contracts to avoid network subgraph from crashing
jq '.["1337"] += {
"LegacyServiceRegistry": { "address": "0x0000000000000000000000000000000000000000" },
"LegacyDisputeManager": { "address": "0x0000000000000000000000000000000000000000" }
}' /opt/subgraph-service.json > /opt/tmp.json && mv /opt/tmp.json /opt/subgraph-service.json

# Build and deploy the subgraph
npx ts-node config/localNetworkAddressScript.ts
npx mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts
Expand All @@ -61,4 +59,4 @@ npx graph deploy graph-network --node="http://graph-node:${GRAPH_NODE_ADMIN}" --
# Keep the container running - for development purposes
if [ -n "${KEEP_CONTAINER_RUNNING:-}" ]; then
tail -f /dev/null
fi
fi
Loading