Skip to content

Commit

Permalink
Add a fixturenet-payments stack (#540)
Browse files Browse the repository at this point in the history
* Add a fixturenet-payments stack

* Export the WebSocket port in fixturenet-eth-geth service

* Add container to run a go-nitro node

* Add container to deploy Nitro contracts

* Read contract addresses from a volume when running the Nitro node

* Add a service for Nitro reverse payment proxy

* Expose payment proxy endpoint to be accessible from host

* Map nitro node messaging and payment proxy ports to host

* Use container to deploy Nitro contracts in mobymask-v3 stack

* Use a common contract deployment script from mobymask-v3 stack

* Add MobyMask contract deployment and watcher services

* Fixes for contract deployment and watcher scripts

* Add a container and service for mobymask-snap

* Add MobyMask app service

* Add container and service for a ponder app

* Fix ponder setup and update instructions

* Handle review comments

* Use enablepaidrpcmethods flag in reverse payment proxy server

* Update go-nitro branch

* Fixes for mobymask-v3 stack

---------

Co-authored-by: Nabarun <[email protected]>
  • Loading branch information
prathamesh0 and nikugogoi authored Oct 3, 2023
1 parent b485a3b commit cf039d9
Show file tree
Hide file tree
Showing 36 changed files with 836 additions and 212 deletions.
1 change: 1 addition & 0 deletions app/data/compose/docker-compose-fixturenet-eth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ services:
- fixturenet-eth-bootnode-geth
ports:
- "8545"
- "8546"
- "40000"
- "6060"

Expand Down
39 changes: 39 additions & 0 deletions app/data/compose/docker-compose-go-nitro.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3.7'

services:
go-nitro:
image: cerc/go-nitro:local
hostname: go-nitro
restart: on-failure
depends_on:
# Wait for Nitro contracts to be deployed
nitro-contracts:
condition: service_completed_successfully
environment:
NITRO_CHAIN_URL: ${NITRO_CHAIN_URL:-ws://fixturenet-eth-geth-1:8546}
NITRO_PK: ${NITRO_PK:-2d999770f7b5d49b694080f987b82bbc9fc9ac2b4dcc10b0f8aba7d700f69c6d}
NITRO_CHAIN_PK: ${NITRO_CHAIN_PK:-570b909da9669b2f35a0b1ac70b8358516d55ae1b5b3710e95e9a94395090597}
NITRO_USE_DURABLE_STORE: ${NITRO_USE_DURABLE_STORE:-true}
NITRO_DURABLE_STORE_FOLDER: ${NITRO_DURABLE_STORE_FOLDER:-/app/data/nitro-store}
CERC_NA_ADDRESS: ${CERC_NA_ADDRESS}
CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS}
CERC_CA_ADDRESS: ${CERC_CA_ADDRESS}
entrypoint: ["bash", "-c", "/app/run-nitro-node.sh"]
volumes:
- go_nitro_data:/app/data
- nitro_deployment:/app/deployment
- ../config/go-nitro/run-nitro-node.sh:/app/run-nitro-node.sh
healthcheck:
test: ["CMD", "nc", "-vz", "localhost", "4005"]
interval: 10s
timeout: 5s
retries: 10
start_period: 10s
ports:
- "3005"
- "4005"
- "5005:5005"

volumes:
go_nitro_data:
nitro_deployment:
16 changes: 11 additions & 5 deletions app/data/compose/docker-compose-mobymask-app-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ services:
CERC_DENY_MULTIADDRS: ${CERC_DENY_MULTIADDRS}
CERC_PUBSUB: ${CERC_PUBSUB}
CERC_GOSSIPSUB_DIRECT_PEERS: ${CERC_GOSSIPSUB_DIRECT_PEERS}
CERC_RELEASE: "laconic-v3"
CERC_NA_ADDRESS: ${CERC_NA_ADDRESS}
CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS}
CERC_CA_ADDRESS: ${CERC_CA_ADDRESS}
CERC_APP_WATCHER_URL: ${CERC_APP_WATCHER_URL}
CERC_PAYMENT_NITRO_ADDRESS: ${CERC_PAYMENT_NITRO_ADDRESS}
CERC_PAYMENT_NITRO_ADDRESS: ${CERC_PAYMENT_NITRO_ADDRESS:-0xBBB676f9cFF8D242e9eaC39D063848807d3D1D94}
CERC_SNAP_URL: ${CERC_SNAP_URL}
working_dir: /scripts
command: ["sh", "mobymask-app-start.sh"]
working_dir: /app
command: ["bash", "/scripts/mobymask-app-start.sh"]
volumes:
- ../config/watcher-mobymask-v3/mobymask-app-start.sh:/scripts/mobymask-app-start.sh
- ../config/watcher-mobymask-v2/mobymask-app-config.json:/app/src/mobymask-app-config.json
- peers_ids:/peers
- mobymask_deployment:/server
- nitro_deployment:/nitro
ports:
- "127.0.0.1:3004:80"
healthcheck:
Expand All @@ -37,3 +38,8 @@ services:
start_period: 10s
extra_hosts:
- "host.docker.internal:host-gateway"

volumes:
peers_ids:
mobymask_deployment:
nitro_deployment:
14 changes: 14 additions & 0 deletions app/data/compose/docker-compose-mobymask-snap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.7'

services:
mobymask-snap:
restart: unless-stopped
image: cerc/mobymask-snap:local
ports:
- "127.0.0.1:8080:8080"
healthcheck:
test: ["CMD", "nc", "-vz", "localhost", "8080"]
interval: 10s
timeout: 5s
retries: 10
start_period: 10s
23 changes: 23 additions & 0 deletions app/data/compose/docker-compose-nitro-contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.7'

services:
# Optionally deploys the Nitro contracts
nitro-contracts:
image: cerc/nitro-contracts:local
restart: on-failure
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
CERC_ETH_RPC_ENDPOINT: ${CERC_ETH_RPC_ENDPOINT:-http://fixturenet-eth-geth-1:8545}
CERC_PRIVATE_KEY_DEPLOYER: ${CERC_PRIVATE_KEY_DEPLOYER:-0x888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218}
CERC_NA_ADDRESS: ${CERC_NA_ADDRESS}
CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS}
CERC_CA_ADDRESS: ${CERC_CA_ADDRESS}
volumes:
- ../config/nitro-contracts/deploy.sh:/app/deploy.sh
- nitro_deployment:/app/deployment
command: ["bash", "-c", "/app/deploy.sh"]
extra_hosts:
- "host.docker.internal:host-gateway"

volumes:
nitro_deployment:
27 changes: 27 additions & 0 deletions app/data/compose/docker-compose-nitro-reverse-payment-proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.7'

services:
nitro-reverse-payment-proxy:
image: cerc/go-nitro:local
hostname: nitro-reverse-payment-proxy
restart: on-failure
depends_on:
# Wait for the go-nitro node to start
go-nitro:
condition: service_healthy
environment:
PROXY_ADDRESS: 0.0.0.0:8081
PROXY_NITRO_ENDPOINT: ${PROXY_NITRO_ENDPOINT:-go-nitro:4005/api/v1}
PROXY_DESTINATION_URL: ${PROXY_DESTINATION_URL:-http://ipld-eth-server:8081}
PROXY_COST_PER_BYTE: ${PROXY_COST_PER_BYTE:-1}
entrypoint: ["bash", "-c", "/app/run-reverse-payment-proxy.sh"]
volumes:
- ../config/go-nitro/run-reverse-payment-proxy.sh:/app/run-reverse-payment-proxy.sh
healthcheck:
test: ["CMD", "nc", "-vz", "localhost", "8081"]
interval: 10s
timeout: 5s
retries: 10
start_period: 10s
ports:
- "8081:8081"
31 changes: 31 additions & 0 deletions app/data/compose/docker-compose-ponder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '3.7'

services:
ponder-app:
restart: unless-stopped
image: cerc/ponder:local
working_dir: /app/examples/token-erc20
environment:
PONDER_CHAIN_ID: ${PONDER_CHAIN_ID:-99}
PONDER_RPC_URL_1: ${PONDER_RPC_URL_1:-http://nitro-reverse-payment-proxy:8081}
CERC_PONDER_NITRO_PK: ${CERC_PONDER_NITRO_PK:-58368d20ff12f17669c06158c21d885897aa56f9be430edc789614bf9851d53f}
CERC_PONDER_NITRO_CHAIN_PK: ${CERC_PONDER_NITRO_CHAIN_PK:-fb1e9af328c283ca3e2486e7c24d13582b7912057d8b9542ff41503c85bc05c0}
CERC_PONDER_NITRO_CHAIN_URL: ${CERC_PONDER_NITRO_CHAIN_URL:-http://fixturenet-eth-geth-1:8545}
CERC_RELAY_MULTIADDR: ${CERC_RELAY_MULTIADDR}
CERC_UPSTREAM_NITRO_ADDRESS: ${CERC_UPSTREAM_NITRO_ADDRESS:-0xAAA6628Ec44A8a742987EF3A114dDFE2D4F7aDCE}
CERC_UPSTREAM_NITRO_MULTIADDR: ${CERC_UPSTREAM_NITRO_MULTIADDR:-/dns4/go-nitro/tcp/5005/ws/p2p/16Uiu2HAmSjXJqsyBJgcBUU2HQmykxGseafSatbpq5471XmuaUqyv}
CERC_UPSTREAM_NITRO_PAY_AMOUNT: ${CERC_UPSTREAM_NITRO_PAY_AMOUNT:-5000}
command: ["bash", "./ponder-start.sh"]
volumes:
- ../config/ponder/ponder-start.sh:/app/examples/token-erc20/ponder-start.sh
- ../config/ponder/ponder.config.ts:/app/examples/token-erc20/ponder.config.ts
- peers_ids:/peers
- nitro_deployment:/nitro
- ponder_nitro_data:/app/examples/token-erc20/.ponder/nitro-db
extra_hosts:
- "host.docker.internal:host-gateway"

volumes:
peers_ids:
nitro_deployment:
ponder_nitro_data:
44 changes: 19 additions & 25 deletions app/data/compose/docker-compose-watcher-mobymask-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,13 @@ services:
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
ENV: "PROD"
CERC_L2_GETH_RPC: ${CERC_L2_GETH_RPC}
CERC_L1_ACCOUNTS_CSV_URL: ${CERC_L1_ACCOUNTS_CSV_URL}
CERC_PRIVATE_KEY_DEPLOYER: ${CERC_PRIVATE_KEY_DEPLOYER}
CERC_ETH_RPC_ENDPOINT: ${CERC_ETH_RPC_ENDPOINT}
CERC_PRIVATE_KEY_DEPLOYER: ${CERC_PRIVATE_KEY_DEPLOYER:-0x888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218}
CERC_MOBYMASK_APP_BASE_URI: ${CERC_MOBYMASK_APP_BASE_URI}
CERC_DEPLOYED_CONTRACT: ${CERC_DEPLOYED_CONTRACT}
CERC_L2_GETH_HOST: ${CERC_L2_GETH_HOST}
CERC_L2_GETH_PORT: ${CERC_L2_GETH_PORT}
CERC_L2_NODE_HOST: ${CERC_L2_NODE_HOST}
CERC_L2_NODE_PORT: ${CERC_L2_NODE_PORT}
command: ["sh", "deploy-and-generate-invite.sh"]
command: ["bash", "-c", "./deploy-and-generate-invite.sh"]
volumes:
- ../config/network/wait-for-it.sh:/app/packages/server/wait-for-it.sh
- ../config/watcher-mobymask-v2/secrets-template.json:/app/packages/server/secrets-template.json
- ../config/watcher-mobymask-v2/deploy-and-generate-invite.sh:/app/packages/server/deploy-and-generate-invite.sh
- ../config/watcher-mobymask-v3/deploy-and-generate-invite.sh:/app/packages/server/deploy-and-generate-invite.sh
- mobymask_deployment:/app/packages/server
extra_hosts:
- "host.docker.internal:host-gateway"
Expand All @@ -62,7 +55,6 @@ services:
- ../config/watcher-mobymask-v2/generate-peer-ids.sh:/app/packages/peer/generate-peer-ids.sh
- peers_ids:/peer-ids

# Optionally deploys the Nitro contracts; sets them at the required path
# Starts the MobyMask v3 watcher server
mobymask-watcher-server:
image: cerc/watcher-mobymask-v3:local
Expand All @@ -74,13 +66,14 @@ services:
condition: service_completed_successfully
mobymask:
condition: service_completed_successfully
nitro-contracts:
condition: service_completed_successfully
env_file:
- ../config/watcher-mobymask-v3/mobymask-params.env
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
CERC_L2_GETH_RPC: ${CERC_L2_GETH_RPC}
CERC_L1_ACCOUNTS_CSV_URL: ${CERC_L1_ACCOUNTS_CSV_URL}
CERC_PRIVATE_KEY_DEPLOYER: ${CERC_PRIVATE_KEY_DEPLOYER}
CERC_ETH_RPC_QUERY_ENDPOINT: ${CERC_ETH_RPC_QUERY_ENDPOINT}
CERC_ETH_RPC_MUTATION_ENDPOINT: ${CERC_ETH_RPC_MUTATION_ENDPOINT}
CERC_RELAY_PEERS: ${CERC_RELAY_PEERS}
CERC_DENY_MULTIADDRS: ${CERC_DENY_MULTIADDRS}
CERC_PUBSUB: ${CERC_PUBSUB}
Expand All @@ -90,21 +83,22 @@ services:
CERC_NA_ADDRESS: ${CERC_NA_ADDRESS}
CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS}
CERC_CA_ADDRESS: ${CERC_CA_ADDRESS}
CERC_PRIVATE_KEY_PEER: ${CERC_PRIVATE_KEY_PEER}
CERC_PRIVATE_KEY_NITRO: ${CERC_PRIVATE_KEY_NITRO}
CERC_PRIVATE_KEY_PEER: ${CERC_PRIVATE_KEY_PEER:-111b7500bdce494d6f4bcfe8c2a0dde2ef92f751d9070fac6475dbd6d8021b3f}
CERC_WATCHER_NITRO_PK: ${CERC_WATCHER_NITRO_PK:-0279651921cd800ac560c21ceea27aab0107b67daf436cdd25ce84cad30159b4}
CERC_PEER_ID: ${CERC_PEER_ID}
entrypoint: ["bash", "-c"]
command: ["./deploy-nitro-contracts.sh && ./start-server.sh"]
CERC_ENABLE_UPSTREAM_PAYMENTS: ${CERC_ENABLE_UPSTREAM_PAYMENTS}
CERC_UPSTREAM_NITRO_ADDRESS: ${CERC_UPSTREAM_NITRO_ADDRESS:-0xAAA6628Ec44A8a742987EF3A114dDFE2D4F7aDCE}
CERC_UPSTREAM_NITRO_MULTIADDR: ${CERC_UPSTREAM_NITRO_MULTIADDR:-/dns4/go-nitro/tcp/5005/ws/p2p/16Uiu2HAmSjXJqsyBJgcBUU2HQmykxGseafSatbpq5471XmuaUqyv}
CERC_UPSTREAM_NITRO_PAY_AMOUNT: ${CERC_UPSTREAM_NITRO_PAY_AMOUNT:-5000}
command: ["bash", "./start-server.sh"]
volumes:
- ../config/watcher-mobymask-v3/deploy-nitro-contracts.sh:/app/deploy-nitro-contracts.sh
- ../config/watcher-mobymask-v3/deploy-nitro-contracts.ts:/app/deploy-nitro-contracts.ts
- ../config/watcher-mobymask-v3/watcher-config-template.toml:/app/environments/watcher-config-template.toml
- ../config/watcher-mobymask-v3/watcher-config-rates.toml:/app/environments/rates.toml
- ../config/watcher-mobymask-v3/keys:/app/keys
- ../config/watcher-mobymask-v3/start-server.sh:/app/start-server.sh
- nitro_data:/app/out/nitro-db
- watcher_nitro_data:/app/out/nitro-db
- peers_ids:/app/peers
- nitro_addresses:/nitro
- nitro_deployment:/nitro
- mobymask_deployment:/server
# Expose GQL, metrics and relay node ports
ports:
Expand All @@ -124,5 +118,5 @@ volumes:
mobymask_watcher_db_data:
peers_ids:
mobymask_deployment:
nitro_addresses:
nitro_data:
nitro_deployment:
watcher_nitro_data:
35 changes: 35 additions & 0 deletions app/data/config/go-nitro/run-nitro-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi

nitro_addresses_file="/app/deployment/nitro-addresses.json"

# Check if CERC_NA_ADDRESS environment variable is set
if [ -n "$CERC_NA_ADDRESS" ]; then
echo "CERC_NA_ADDRESS is set to '$CERC_NA_ADDRESS'"
echo "CERC_VPA_ADDRESS is set to '$CERC_VPA_ADDRESS'"
echo "CERC_CA_ADDRESS is set to '$CERC_CA_ADDRESS'"
echo "Using the above Nitro addresses"

NA_ADDRESS=${CERC_NA_ADDRESS}
VPA_ADDRESS=${CERC_VPA_ADDRESS}
CA_ADDRESS=${CERC_CA_ADDRESS}
elif [ -f ${nitro_addresses_file} ]; then
echo "Reading Nitro addresses from ${nitro_addresses_file}"

NA_ADDRESS=$(jq -r '.nitroAdjudicatorAddress' ${nitro_addresses_file})
VPA_ADDRESS=$(jq -r '.virtualPaymentAppAddress' ${nitro_addresses_file})
CA_ADDRESS=$(jq -r '.consensusAppAddress' ${nitro_addresses_file})
else
echo "File ${nitro_addresses_file} not found"
exit 1
fi

echo "Running Nitro node"

# TODO Wait for RPC endpoint to come up

./nitro -chainurl ${NITRO_CHAIN_URL} -msgport 3005 -rpcport 4005 -wsmsgport 5005 -pk ${NITRO_PK} -chainpk ${NITRO_CHAIN_PK} -naaddress ${NA_ADDRESS} -vpaaddress ${VPA_ADDRESS} -caaddress ${CA_ADDRESS} -usedurablestore ${NITRO_USE_DURABLE_STORE} -durablestorefolder ${NITRO_DURABLE_STORE_FOLDER}
14 changes: 14 additions & 0 deletions app/data/config/go-nitro/run-reverse-payment-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi

echo "Running Nitro reverse payment proxy"
echo "Using PROXY_ADDRESS ${PROXY_ADDRESS}"
echo "Using PROXY_NITRO_ENDPOINT ${PROXY_NITRO_ENDPOINT}"
echo "Using PROXY_DESTINATION_URL ${PROXY_DESTINATION_URL}"
echo "Using PROXY_COST_PER_BYTE ${PROXY_COST_PER_BYTE}"

./start-reverse-payment-proxy -proxyaddress ${PROXY_ADDRESS} -nitroendpoint=${PROXY_NITRO_ENDPOINT} -destinationurl=${PROXY_DESTINATION_URL} -costperbyte ${PROXY_COST_PER_BYTE} -enablepaidrpcmethods
57 changes: 57 additions & 0 deletions app/data/config/nitro-contracts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi

nitro_addresses_file="/app/deployment/nitro-addresses.json"

# Check if CERC_NA_ADDRESS environment variable set to skip contract deployment
if [ -n "$CERC_NA_ADDRESS" ]; then
echo "CERC_NA_ADDRESS is set to '$CERC_NA_ADDRESS'"
echo "CERC_VPA_ADDRESS is set to '$CERC_VPA_ADDRESS'"
echo "CERC_CA_ADDRESS is set to '$CERC_CA_ADDRESS'"
echo "Skipping Nitro contracts deployment"
exit
fi

# Check and exit if a deployment already exists (on restarts)
if [ -f ${nitro_addresses_file} ]; then
echo "${nitro_addresses_file} already exists, skipping Nitro contracts deployment"
cat ${nitro_addresses_file}
exit
fi

echo "Using ETH RPC endpoint ${CERC_ETH_RPC_ENDPOINT}"

# Wait till ETH RPC endpoint is available with block number > 1
retry_interval=5
while true; do
block_number_hex=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' ${CERC_ETH_RPC_ENDPOINT} | jq -r '.result')

# Check if the request call was successful
if [ $? -ne 0 ]; then
echo "RPC endpoint not yet available, retrying in $retry_interval seconds..."
sleep $retry_interval
continue
fi

# Convert hex to decimal
block_number_dec=$(printf %u ${block_number_hex})

# Check if block number is > 1 to avoid failures in the deployment
if [ "$block_number_dec" -ge 1 ]; then
echo "RPC endpoint is up"
break
else
echo "RPC endpoint not yet available, retrying in $retry_interval seconds..."
sleep $retry_interval
continue
fi
done

echo "Using CERC_PRIVATE_KEY_DEPLOYER from env"

yarn test:deploy-contracts --chainurl ${CERC_ETH_RPC_ENDPOINT} --key ${CERC_PRIVATE_KEY_DEPLOYER} --addressesFilePath ${nitro_addresses_file}
cat ${nitro_addresses_file}
Loading

0 comments on commit cf039d9

Please sign in to comment.