Separate out watcher and web-apps in mobymask-v2 stack (#287)
* Separate out watcher and web-apps in mobymask stack * Take L2 RPC endpoint from the env file * Changes to run watcher and mobymask web-app separately * Support running watcher without contract deployment and L2 txs * Remove duplicate mobymask params env * Add code comments * Add instructions for running web-apps separately * Self review fixes * Fix timeout for mobymask-app on watcher server --------- Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com> Former-commit-id: 6f781ae303915d7612fbc670b4f5f9b521b48121
This commit is contained in:
@@ -4,6 +4,8 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
echo "Using L2 RPC endpoint ${L2_GETH_RPC}"
|
||||
|
||||
if [ -f /geth-accounts/accounts.csv ]; then
|
||||
echo "Using L1 private key from the mounted volume"
|
||||
# Read the private key of L1 account to deploy contract
|
||||
@@ -16,10 +18,16 @@ fi
|
||||
jq --arg privateKey "$PRIVATE_KEY_DEPLOYER" '.privateKey = $privateKey' secrets-template.json > secrets.json
|
||||
|
||||
# Set the RPC URL
|
||||
export L2_GETH_URL="http://${L2_GETH_HOST}:${L2_GETH_PORT}"
|
||||
jq --arg rpcUrl "$L2_GETH_URL" '.rpcUrl = $rpcUrl' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json
|
||||
jq --arg rpcUrl "$L2_GETH_RPC" '.rpcUrl = $rpcUrl' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json
|
||||
|
||||
export RPC_URL="${L2_GETH_URL}"
|
||||
export RPC_URL="${L2_GETH_RPC}"
|
||||
|
||||
# Check if DEPLOYED_CONTRACT environment variable set to skip contract deployment
|
||||
if [[ -n "$DEPLOYED_CONTRACT" ]]; then
|
||||
echo "DEPLOYED_CONTRACT is set to '$DEPLOYED_CONTRACT'"
|
||||
echo "Exiting without deploying contract"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check and exit if a deployment already exists (on restarts)
|
||||
if [ -f ./config.json ]; then
|
||||
@@ -39,10 +47,10 @@ if [ -f ./config.json ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Wait until balance for deployer account is reflected
|
||||
# Wait until balance for deployer account is updated
|
||||
cd ../hardhat
|
||||
while true; do
|
||||
ACCOUNT_BALANCE=$(yarn balance --network optimism $PRIVATE_KEY_DEPLOYER | grep ETH)
|
||||
ACCOUNT_BALANCE=$(yarn balance --network optimism "$PRIVATE_KEY_DEPLOYER" | grep ETH)
|
||||
|
||||
if [ "$ACCOUNT_BALANCE" != "0.0 ETH" ]; then
|
||||
echo "Account balance updated: $ACCOUNT_BALANCE"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"name": "MobyMask",
|
||||
"relayNodes": [
|
||||
"/ip4/127.0.0.1/tcp/9090/ws/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t"
|
||||
],
|
||||
|
||||
@@ -4,9 +4,22 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# Merging config files to get deployed contract address
|
||||
jq -s '.[0] * .[1]' /app/src/mobymask-app-config.json /server/config.json > /app/src/config.json
|
||||
# Use config from mounted volume if available (when running web-app along with watcher stack)
|
||||
if [ -f /server/config.json ]; then
|
||||
echo "Merging config for deployed contract from mounted volume"
|
||||
# Merging config files to get deployed contract address
|
||||
jq -s '.[0] * .[1]' /app/src/mobymask-app-config.json /server/config.json > /app/src/config.json
|
||||
else
|
||||
echo "Setting deployed contract details from env"
|
||||
|
||||
npm run build
|
||||
# Set config values from environment variables
|
||||
jq --arg address "$DEPLOYED_CONTRACT" \
|
||||
--argjson chainId $CHAIN_ID \
|
||||
--argjson relayNodes "$RELAY_NODES" \
|
||||
'.address = $address | .chainId = $chainId | .relayNodes = $relayNodes' \
|
||||
/app/src/mobymask-app-config.json > /app/src/config.json
|
||||
fi
|
||||
|
||||
REACT_APP_WATCHER_URI="$APP_WATCHER_URL/graphql" npm run build
|
||||
|
||||
serve -s build
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
REACT_APP_WATCHER_URI=http://localhost:3001/graphql
|
||||
@@ -0,0 +1,14 @@
|
||||
# Change if pointing web app to external watcher endpoint
|
||||
WATCHER_HOST="mobymask-watcher-server"
|
||||
WATCHER_PORT=3001
|
||||
APP_WATCHER_URL="http://localhost:3001"
|
||||
|
||||
# Set deployed MobyMask contract address to avoid deploying contract in stack
|
||||
# mobymask-app will use this contract address in config if run separately
|
||||
DEPLOYED_CONTRACT=
|
||||
|
||||
# Chain ID is used by mobymask web-app for txs
|
||||
CHAIN_ID=42069
|
||||
|
||||
# Set relay nodes to be used by web-apps
|
||||
RELAY_NODES=["/ip4/127.0.0.1/tcp/9090/ws/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t"]
|
||||
@@ -1,9 +1,10 @@
|
||||
# Change if pointing to an external optimism geth endpoint
|
||||
|
||||
# L2 endpoints
|
||||
# TODO: Add another env for complete URL to handle https
|
||||
L2_GETH_RPC="http://op-geth:8545"
|
||||
L2_GETH_HOST="op-geth"
|
||||
L2_GETH_PORT=8545
|
||||
|
||||
L2_NODE_HOST="op-node"
|
||||
L2_NODE_PORT=8547
|
||||
|
||||
|
||||
@@ -4,8 +4,15 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# Assign deployed contract address from server config
|
||||
CONTRACT_ADDRESS=$(jq -r '.address' /server/config.json | tr -d '"')
|
||||
echo "Using L2 RPC endpoint ${L2_GETH_RPC}"
|
||||
|
||||
# Use contract address from environment variable or set from config.json in mounted volume
|
||||
if [ -n "$DEPLOYED_CONTRACT" ]; then
|
||||
CONTRACT_ADDRESS="${DEPLOYED_CONTRACT}"
|
||||
else
|
||||
# Assign deployed contract address from server config (created by mobymask container after deploying contract)
|
||||
CONTRACT_ADDRESS=$(jq -r '.address' /server/config.json | tr -d '"')
|
||||
fi
|
||||
|
||||
if [ -f /geth-accounts/accounts.csv ]; then
|
||||
echo "Using L1 private key from the mounted volume"
|
||||
@@ -15,11 +22,20 @@ else
|
||||
echo "Using PRIVATE_KEY_PEER from env"
|
||||
fi
|
||||
|
||||
sed "s/REPLACE_WITH_PRIVATE_KEY/${PRIVATE_KEY_PEER}/" environments/watcher-config-template.toml > environments/local.toml
|
||||
sed -i "s/REPLACE_WITH_CONTRACT_ADDRESS/${CONTRACT_ADDRESS}/" environments/local.toml
|
||||
# Set private key and contract address for watcher peer txs to L2 only if PRIVATE_KEY_PEER variable is set
|
||||
if [ -n "$PRIVATE_KEY_PEER" ]; then
|
||||
# Read in config template TOML file and modify it
|
||||
CONTENT=$(cat environments/watcher-config-template.toml)
|
||||
NEW_CONTENT=$(echo "$CONTENT" | sed -E "/\[metrics\]/i \\\n\n [server.p2p.peer.l2TxConfig]\n privateKey = \"${PRIVATE_KEY_PEER}\"\n contractAddress = \"${CONTRACT_ADDRESS}\"\n")
|
||||
|
||||
export L2_GETH_URL="http://${L2_GETH_HOST}:${L2_GETH_PORT}"
|
||||
sed -i 's|REPLACE_WITH_L2_GETH_URL|'"${L2_GETH_URL}"'|' environments/local.toml
|
||||
# Write the modified content to a watcher config file
|
||||
echo "$NEW_CONTENT" > environments/local.toml
|
||||
|
||||
sed -i 's|REPLACE_WITH_L2_GETH_RPC_ENDPOINT|'"${L2_GETH_RPC}"'|' environments/local.toml
|
||||
else
|
||||
# Copy template config to watcher config without setting params for peer L2 txs
|
||||
cp environments/watcher-config-template.toml environments/local.toml
|
||||
fi
|
||||
|
||||
echo 'yarn server'
|
||||
yarn server
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# Set relay nodes in config from RELAY_NODES environment variable
|
||||
jq --argjson relayNodes "$RELAY_NODES" \
|
||||
'.relayNodes = $relayNodes' \
|
||||
./src/test-app-config.json > ./src/config.json
|
||||
|
||||
yarn build
|
||||
|
||||
serve -s build
|
||||
@@ -36,10 +36,6 @@
|
||||
peerIdFile = './peer-id.json'
|
||||
enableDebugInfo = true
|
||||
|
||||
[server.p2p.peer.l2TxConfig]
|
||||
privateKey = 'REPLACE_WITH_PRIVATE_KEY'
|
||||
contractAddress = 'REPLACE_WITH_CONTRACT_ADDRESS'
|
||||
|
||||
[metrics]
|
||||
host = "0.0.0.0"
|
||||
port = 9000
|
||||
@@ -59,7 +55,7 @@
|
||||
[upstream]
|
||||
[upstream.ethServer]
|
||||
gqlApiEndpoint = "http://ipld-eth-server:8083/graphql"
|
||||
rpcProviderEndpoint = "REPLACE_WITH_L2_GETH_URL"
|
||||
rpcProviderEndpoint = "REPLACE_WITH_L2_GETH_RPC_ENDPOINT"
|
||||
blockDelayInMilliSecs = 60000
|
||||
|
||||
[upstream.cache]
|
||||
|
||||
Reference in New Issue
Block a user