Add demo steps for running nitro nodes with payment and defund #5

Merged
nabarun merged 8 commits from demo-steps-without-bridge into main 2024-08-26 14:00:03 +00:00
8 changed files with 136 additions and 17 deletions
Showing only changes of commit 428e40a39c - Show all commits

View File

@ -296,11 +296,45 @@
# 100000000000000000 # 100000000000000000
``` ```
- Deploy L1 nitro contracts
- Create a deployment spec-file for L1 nitro contract:
```bash
laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-contracts deploy init --output nitro-contracts-spec.yml --config "GETH_URL=http://host.docker.internal:8545,GETH_DEPLOYER_PK=888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218,TOKEN_NAME=LaconicNetworkToken,TOKEN_SYMBOL=LNT,INITIAL_TOKEN_SUPPLY=129600"
```
- Create a deployment `nitro-contracts` from the spec file
```bash
laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-contracts deploy create --spec-file nitro-contracts-spec.yml --deployment-dir nitro-contracts-deployment
```
- Start `nitro-contracts` deployment:
```
laconic-so deployment --dir nitro-contracts-deployment start
# Check the l1 nitro contract deployments
laconic-so deployment --dir nitro-contracts-deployment logs nitro-contracts -f
```
- Run the bridge: - Run the bridge:
- Get the deployed nitro contract addresses (run in the directory where the deployments were created):
```bash
# Nitro contract addresses
export NA_ADDRESS=$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.NitroAdjudicator.address' /app/deployment/nitro-addresses.json")
export CA_ADDRESS=$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.ConsensusApp.address' /app/deployment/nitro-addresses.json")
export VPA_ADDRESS=$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.VirtualPaymentApp.address' /app/deployment/nitro-addresses.json")
export L1_ASSET_ADDRESS="$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.Token.address' /app/deployment/nitro-addresses.json")"
```
- Create a spec-file for the deployment, map container ports to host ports and set env variables: - Create a spec-file for the deployment, map container ports to host ports and set env variables:
```bash ```bash
laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/bridge deploy init --map-ports-to-host any-same --output bridge-nitro-spec.yml --config "NITRO_L1_CHAIN_URL=ws://host.docker.internal:8546,NITRO_L2_CHAIN_URL=ws://host.docker.internal:9546,NITRO_CHAIN_PK=888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218,NITRO_SC_PK=0279651921cd800ac560c21ceea27aab0107b67daf436cdd25ce84cad30159b4,GETH_URL=http://host.docker.internal:8545,OPTIMISM_URL=http://host.docker.internal:9545,GETH_DEPLOYER_PK=$ACCOUNT_PK,OPTIMISM_DEPLOYER_PK=$ACCOUNT_PK,TOKEN_NAME=LaconicNetworkToken,TOKEN_SYMBOL=LNT,INITIAL_TOKEN_SUPPLY=129600" laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/bridge deploy init --map-ports-to-host any-same --output bridge-nitro-spec.yml --config "NITRO_L1_CHAIN_URL=ws://host.docker.internal:8546,NITRO_L2_CHAIN_URL=ws://host.docker.internal:9546,NITRO_CHAIN_PK=888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218,NITRO_SC_PK=0279651921cd800ac560c21ceea27aab0107b67daf436cdd25ce84cad30159b4,GETH_URL=http://host.docker.internal:8545,OPTIMISM_URL=http://host.docker.internal:9545,GETH_DEPLOYER_PK=$ACCOUNT_PK,OPTIMISM_DEPLOYER_PK=$ACCOUNT_PK,TOKEN_NAME=LaconicNetworkToken,TOKEN_SYMBOL=LNT,INITIAL_TOKEN_SUPPLY=129600,NA_ADDRESS=$NA_ADDRESS,VPA_ADDRESS=$VPA_ADDRESS,CA_ADDRESS=$CA_ADDRESS,L1_ASSET_ADDRESS=$L1_ASSET_ADDRESS"
``` ```
- Create a deployment from the spec file: - Create a deployment from the spec file:
@ -314,6 +348,9 @@
```bash ```bash
laconic-so deployment --dir bridge-deployment start laconic-so deployment --dir bridge-deployment start
# Check the l2 nitro contract deployments
laconic-so deployment --dir bridge-deployment logs l2-nitro-contracts -f
# Check the logs, ensure that the node is running # Check the logs, ensure that the node is running
laconic-so deployment --dir bridge-deployment logs nitro-bridge -f laconic-so deployment --dir bridge-deployment logs nitro-bridge -f
``` ```
@ -323,7 +360,7 @@
- Export variables for L1 token address - Export variables for L1 token address
```bash ```bash
export L1_ASSET_ADDRESS="$(laconic-so deployment --dir bridge-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.Token.address' /app/deployment/nitro-addresses.json")" export L1_ASSET_ADDRESS="$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.Token.address' /app/deployment/nitro-addresses.json")"
export A_CHAIN_ADDRESS="0xe22AD83A0dE117bA0d03d5E94Eb4E0d80a69C62a" export A_CHAIN_ADDRESS="0xe22AD83A0dE117bA0d03d5E94Eb4E0d80a69C62a"
export C_CHAIN_ADDRESS="0xf1ac8Dd1f6D6F5c0dA99097c57ebF50CD99Ce293" export C_CHAIN_ADDRESS="0xf1ac8Dd1f6D6F5c0dA99097c57ebF50CD99Ce293"
@ -333,10 +370,10 @@
```bash ```bash
# Send tokens to Alice # Send tokens to Alice
laconic-so deployment --dir bridge-deployment exec nitro-contracts "cd packages/nitro-protocol && yarn hardhat transfer --contract $L1_ASSET_ADDRESS --to $A_CHAIN_ADDRESS --amount 1000 --network geth" laconic-so deployment --dir bridge-deployment exec l2-nitro-contracts "cd packages/nitro-protocol && yarn hardhat transfer --contract $L1_ASSET_ADDRESS --to $A_CHAIN_ADDRESS --amount 1000 --network geth"
#Send tokens to Charlie #Send tokens to Charlie
laconic-so deployment --dir bridge-deployment exec nitro-contracts "cd packages/nitro-protocol && yarn hardhat transfer --contract $L1_ASSET_ADDRESS --to $C_CHAIN_ADDRESS --amount 1000 --network geth" laconic-so deployment --dir bridge-deployment exec l2-nitro-contracts "cd packages/nitro-protocol && yarn hardhat transfer --contract $L1_ASSET_ADDRESS --to $C_CHAIN_ADDRESS --amount 1000 --network geth"
``` ```
## Demo ## Demo
@ -344,9 +381,9 @@
```bash ```bash
# Nitro contract addresses # Nitro contract addresses
export NA_ADDRESS=$(laconic-so deployment --dir bridge-deployment exec nitro-bridge "jq -r '.\"1212\"[0].contracts.NitroAdjudicator.address' /app/deployment/nitro-addresses.json") export NA_ADDRESS=$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.NitroAdjudicator.address' /app/deployment/nitro-addresses.json")
export CA_ADDRESS=$(laconic-so deployment --dir bridge-deployment exec nitro-bridge "jq -r '.\"1212\"[0].contracts.ConsensusApp.address' /app/deployment/nitro-addresses.json") export CA_ADDRESS=$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.ConsensusApp.address' /app/deployment/nitro-addresses.json")
export VPA_ADDRESS=$(laconic-so deployment --dir bridge-deployment exec nitro-bridge "jq -r '.\"1212\"[0].contracts.VirtualPaymentApp.address' /app/deployment/nitro-addresses.json") export VPA_ADDRESS=$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.VirtualPaymentApp.address' /app/deployment/nitro-addresses.json")
# Contract address of bridge # Contract address of bridge
export BRIDGE_ADDRESS=$(laconic-so deployment --dir bridge-deployment exec nitro-bridge "jq -r '.\"42069\"[0].contracts.Bridge.address' /app/deployment/nitro-addresses.json") export BRIDGE_ADDRESS=$(laconic-so deployment --dir bridge-deployment exec nitro-bridge "jq -r '.\"42069\"[0].contracts.Bridge.address' /app/deployment/nitro-addresses.json")
@ -498,7 +535,7 @@
```bash ```bash
export BRIDGE_NITRO_ADDRESS=0xBBB676f9cFF8D242e9eaC39D063848807d3D1D94 export BRIDGE_NITRO_ADDRESS=0xBBB676f9cFF8D242e9eaC39D063848807d3D1D94
export L1_ASSET_ADDRESS="$(laconic-so deployment --dir bridge-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.Token.address' /app/deployment/nitro-addresses.json")" export L1_ASSET_ADDRESS="$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.Token.address' /app/deployment/nitro-addresses.json")"
``` ```
- Create ledger channel between A and Bridge with custom token - Create ledger channel between A and Bridge with custom token
@ -703,6 +740,7 @@
laconic-so deployment --dir l2alice-nitro-deployment stop --delete-volumes laconic-so deployment --dir l2alice-nitro-deployment stop --delete-volumes
laconic-so deployment --dir l2charlie-nitro-deployment stop --delete-volumes laconic-so deployment --dir l2charlie-nitro-deployment stop --delete-volumes
laconic-so deployment --dir bridge-deployment stop --delete-volumes laconic-so deployment --dir bridge-deployment stop --delete-volumes
laconic-so deployment --dir nitro-contracts-deployment stop --delete-volumes
``` ```
- Clear nitro-node and bridge deployments: - Clear nitro-node and bridge deployments:
@ -714,6 +752,7 @@
sudo rm -rf l2alice-nitro-deployment sudo rm -rf l2alice-nitro-deployment
sudo rm -rf l2charlie-nitro-deployment sudo rm -rf l2charlie-nitro-deployment
sudo rm -rf bridge-deployment sudo rm -rf bridge-deployment
sudo rm -rf nitro-contracts-deployment
``` ```
- Clean up L1 and L2 deployments: - Clean up L1 and L2 deployments:

View File

@ -348,6 +348,7 @@
# Run where deployments are created # Run where deployments are created
laconic-so deployment --dir alice-nitro-deployment stop --delete-volumes laconic-so deployment --dir alice-nitro-deployment stop --delete-volumes
laconic-so deployment --dir charlie-nitro-deployment stop --delete-volumes laconic-so deployment --dir charlie-nitro-deployment stop --delete-volumes
laconic-so deployment --dir nitro-contracts-deployment stop --delete-volumes
``` ```
- Clear nitro-node and bridge deployments: - Clear nitro-node and bridge deployments:
@ -356,6 +357,7 @@
# Run where deployments are created # Run where deployments are created
sudo rm -rf alice-nitro-deployment sudo rm -rf alice-nitro-deployment
sudo rm -rf charlie-nitro-deployment sudo rm -rf charlie-nitro-deployment
sudo rm -rf nitro-contracts-deployment
``` ```
- Clean up fixturenet-eth deployment: - Clean up fixturenet-eth deployment:

View File

@ -1,12 +1,35 @@
name: nitro-bridge name: nitro-bridge
services: services:
l2-nitro-contracts:
image: cerc/nitro-client:local
restart: on-failure
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
GETH_URL: ${GETH_URL}
OPTIMISM_DEPLOYER_PK: ${OPTIMISM_DEPLOYER_PK}
OPTIMISM_CHAIN_ID: ${OPTIMISM_CHAIN_ID:-42069}
GETH_CHAIN_ID: ${GETH_CHAIN_ID:-1212}
GETH_DEPLOYER_PK: ${OPTIMISM_DEPLOYER_PK}
OPTIMISM_URL: ${OPTIMISM_URL}
TOKEN_NAME: ${TOKEN_NAME}
TOKEN_SYMBOL: ${TOKEN_SYMBOL}
INITIAL_TOKEN_SUPPLY: ${INITIAL_TOKEN_SUPPLY}
DISABLE_DETERMINISTIC_DEPLOYMENT: ${DISABLE_DETERMINISTIC_DEPLOYMENT:-true}
L1_ASSET_ADDRESS: ${L1_ASSET_ADDRESS}
volumes:
- nitro_deployment:/app/deployment
- ../config/nitro-contracts/deploy-l2-contracts.sh:/app/deploy-l2-contracts.sh
command: ["bash", "-c", "/app/deploy-l2-contracts.sh"]
extra_hosts:
- "host.docker.internal:host-gateway"
nitro-bridge: nitro-bridge:
image: cerc/go-nitro:local image: cerc/go-nitro:local
hostname: nitro-bridge hostname: nitro-bridge
restart: unless-stopped restart: unless-stopped
depends_on: depends_on:
nitro-contracts: l2-nitro-contracts:
condition: service_started condition: service_started
environment: environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
@ -23,6 +46,9 @@ services:
NITRO_L1_EXT_MULTIADDR: ${NITRO_L1_EXT_MULTIADDR} NITRO_L1_EXT_MULTIADDR: ${NITRO_L1_EXT_MULTIADDR}
NITRO_L2_EXT_MULTIADDR: ${NITRO_L2_EXT_MULTIADDR} NITRO_L2_EXT_MULTIADDR: ${NITRO_L2_EXT_MULTIADDR}
NITRO_PUBLIC_RPC_HOST: nitro-bridge NITRO_PUBLIC_RPC_HOST: nitro-bridge
NA_ADDRESS: ${NA_ADDRESS}
CA_ADDRESS: ${CA_ADDRESS}
VPA_ADDRESS: ${VPA_ADDRESS}
entrypoint: ["bash", "-c", "/app/run-bridge.sh"] entrypoint: ["bash", "-c", "/app/run-bridge.sh"]
volumes: volumes:
- nitro_bridge_data:/app/data - nitro_bridge_data:/app/data

View File

@ -17,8 +17,8 @@ services:
DISABLE_DETERMINISTIC_DEPLOYMENT: ${DISABLE_DETERMINISTIC_DEPLOYMENT:-true} DISABLE_DETERMINISTIC_DEPLOYMENT: ${DISABLE_DETERMINISTIC_DEPLOYMENT:-true}
volumes: volumes:
- nitro_deployment:/app/deployment - nitro_deployment:/app/deployment
- ../config/nitro-contracts/deploy.sh:/app/deploy.sh - ../config/nitro-contracts/deploy-l1-contracts.sh:/app/deploy-l1-contracts.sh
command: ["bash", "-c", "/app/deploy.sh"] command: ["bash", "-c", "/app/deploy-l1-contracts.sh"]
extra_hosts: extra_hosts:
- "host.docker.internal:host-gateway" - "host.docker.internal:host-gateway"

View File

@ -20,6 +20,9 @@ echo "NITRO_RPC_PORT: ${NITRO_RPC_PORT}"
echo "NITRO_PUBLIC_P2P_HOST: ${NITRO_PUBLIC_P2P_HOST}" echo "NITRO_PUBLIC_P2P_HOST: ${NITRO_PUBLIC_P2P_HOST}"
echo "NITRO_L1_EXT_MULTIADDR: ${NITRO_L1_EXT_MULTIADDR}" echo "NITRO_L1_EXT_MULTIADDR: ${NITRO_L1_EXT_MULTIADDR}"
echo "NITRO_L2_EXT_MULTIADDR: ${NITRO_L2_EXT_MULTIADDR}" echo "NITRO_L2_EXT_MULTIADDR: ${NITRO_L2_EXT_MULTIADDR}"
echo "NA_ADDRESS: ${NA_ADDRESS}"
echo "CA_ADDRESS: ${CA_ADDRESS}"
echo "VPA_ADDRESS: ${VPA_ADDRESS}"
echo "Waiting for $bridge_assets_map_file to be ready" echo "Waiting for $bridge_assets_map_file to be ready"
@ -45,12 +48,12 @@ bridgepublicip = "$NITRO_PUBLIC_P2P_HOST"
nodel1ExtMultiAddr = "$NITRO_L1_EXT_MULTIADDR" nodel1ExtMultiAddr = "$NITRO_L1_EXT_MULTIADDR"
nodel2ExtMultiAddr = "$NITRO_L2_EXT_MULTIADDR" nodel2ExtMultiAddr = "$NITRO_L2_EXT_MULTIADDR"
assetmapfilepath = "$bridge_assets_map_file" assetmapfilepath = "$bridge_assets_map_file"
naaddress = "${NA_ADDRESS}"
vpaaddress = "${VPA_ADDRESS}"
caaddress = "${CA_ADDRESS}"
EOF EOF
# Export contract addresses # Export bridge address
export NA_ADDRESS=$(jq -r ".\"$GETH_CHAIN_ID\"[0].contracts.NitroAdjudicator.address" ${nitro_addresses_file})
export CA_ADDRESS=$(jq -r ".\"$GETH_CHAIN_ID\"[0].contracts.ConsensusApp.address" ${nitro_addresses_file})
export VPA_ADDRESS=$(jq -r ".\"$GETH_CHAIN_ID\"[0].contracts.VirtualPaymentApp.address" ${nitro_addresses_file})
export BRIDGE_ADDRESS=$(jq -r ".\"$OPTIMISM_CHAIN_ID\"[0].contracts.Bridge.address" ${nitro_addresses_file}) export BRIDGE_ADDRESS=$(jq -r ".\"$OPTIMISM_CHAIN_ID\"[0].contracts.Bridge.address" ${nitro_addresses_file})
# Start bridge # Start bridge

View File

@ -0,0 +1,50 @@
#!/bin/bash
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
addresses_deployment_file="packages/nitro-protocol/addresses.json"
nitro_addresses_file="/app/deployment/nitro-addresses.json"
bridge_assets_map_file="/app/deployment/bridge-assets-map.toml"
echo "Using the following environment variables:"
echo "OPTIMISM_URL: ${OPTIMISM_URL}"
echo "OPTIMISM_CHAIN_ID: ${OPTIMISM_CHAIN_ID}"
echo "OPTIMISM_DEPLOYER_PK: ${OPTIMISM_DEPLOYER_PK}"
echo "GETH_URL: ${GETH_URL}"
echo "GETH_CHAIN_ID: ${GETH_CHAIN_ID}"
echo "GETH_DEPLOYER_PK: ${GETH_DEPLOYER_PK}"
echo "TOKEN_NAME: ${TOKEN_NAME}"
echo "TOKEN_SYMBOL: ${TOKEN_SYMBOL}"
echo "INITIAL_TOKEN_SUPPLY: ${INITIAL_TOKEN_SUPPLY}"
echo "DISABLE_DETERMINISTIC_DEPLOYMENT: ${DISABLE_DETERMINISTIC_DEPLOYMENT}"
echo "L1_ASSET_ADDRESS: ${L1_ASSET_ADDRESS}"
# Check if L2 chain id key is present for L2 deployment
if [ -f "$nitro_addresses_file" ] && jq -e "has(\"$OPTIMISM_CHAIN_ID\")" ${nitro_addresses_file} > /dev/null; then
echo "L2 addresses found in ${nitro_addresses_file}, skipping deployment"
else
# Deploy Nitro contracts
yarn contracts:deploy-optimism
# Deploy custom token
yarn contracts:deploy-token-optimism
cp ${addresses_deployment_file} ${nitro_addresses_file}
fi
L2_ASSET_ADDRESS=$(jq -r ".\"$OPTIMISM_CHAIN_ID\"[0].contracts.Token.address" ${nitro_addresses_file})
# Deploy custom tokens and create bridge-assets-map.toml
cat <<EOF > "$bridge_assets_map_file"
[[assets]]
l1AssetAddress = "$L1_ASSET_ADDRESS"
l2AssetAddress = "$L2_ASSET_ADDRESS"
EOF
echo "Done"
# Keep the container running for future asset transfers
tail -f /dev/null

View File

@ -7,6 +7,5 @@ containers:
- cerc/nitro-client - cerc/nitro-client
- cerc/go-nitro - cerc/go-nitro
pods: pods:
- nitro-contracts
- nitro-bridge - nitro-bridge
- nitro-rpc-client - nitro-rpc-client