From dd57b1c5bbfa097fc016b9288da736effc331b49 Mon Sep 17 00:00:00 2001 From: Neeraj Date: Thu, 22 Aug 2024 14:31:39 +0530 Subject: [PATCH 1/8] Create stack to deploy nitro contracts --- README.md | 3 +- nitro-node-demo.md | 146 ++++++++++++++++++ .../docker-compose-nitro-contracts.yml | 2 - .../config/nitro-contracts/deploy.sh | 28 ---- .../stacks/nitro-contracts/README.md | 1 + .../stacks/nitro-contracts/stack.yml | 9 ++ 6 files changed, 158 insertions(+), 31 deletions(-) create mode 100644 nitro-node-demo.md create mode 100644 stack-orchestrator/stacks/nitro-contracts/README.md create mode 100644 stack-orchestrator/stacks/nitro-contracts/stack.yml diff --git a/README.md b/README.md index c0f50cb..020b41e 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,5 @@ Stacks to run nitro-node and bridge Demo -- [nitro-bridge demo](./nitro-bridge-demo.md) \ No newline at end of file +- [nitro-bridge demo](./nitro-bridge-demo.md) +- [nitro-node demo](./nitro-node-demo.md) diff --git a/nitro-node-demo.md b/nitro-node-demo.md new file mode 100644 index 0000000..8c45c4d --- /dev/null +++ b/nitro-node-demo.md @@ -0,0 +1,146 @@ +# nitro-node demo + +## Setup + +### Fixturenet eth stack + +- Clone the stack repo: + + ```bash + laconic-so fetch-stack git.vdb.to/cerc-io/fixturenet-eth-stacks --pull + ``` + +- Clone required repositories: + + ```bash + laconic-so --stack ~/cerc/fixturenet-eth-stacks/stack-orchestrator/stacks/fixturenet-eth setup-repositories --pull + + # If this throws an error as a result of being already checked out to a branch/tag in a repo, remove all repositories from that stack and re-run the command + # The repositories are located in $HOME/cerc by default + ``` + +- Build the container images: + + ```bash + # Remove any older foundry image with `latest` tag + docker rmi ghcr.io/foundry-rs/foundry:latest + + laconic-so --stack ~/cerc/fixturenet-eth-stacks/stack-orchestrator/stacks/fixturenet-eth build-containers --force-rebuild + + # If errors are thrown during build, old images used by this stack would have to be deleted + ``` + + - NOTE: this will take >10 mins depending on the specs of your machine, and **requires** 16GB of memory or greater. + + - Remove any dangling Docker images (to clear up space): + + ```bash + docker image prune + ``` + +- Create spec files for deployment, which will map the stack's ports and volumes to the host: + + ```bash + laconic-so --stack ~/cerc/fixturenet-eth-stacks/stack-orchestrator/stacks/fixturenet-eth deploy init --output fixturenet-eth-spec.yml + ``` + +- Configure ports: + - `fixturenet-eth-spec.yml` + + ```yml + ... + network: + ports: + fixturenet-eth-bootnode-geth: + - '9898:9898' + - '30303' + fixturenet-eth-geth-1: + - '8545:8545' + - '8546:8546' + - '40000' + - '6060' + fixturenet-eth-lighthouse-1: + - '8001' + ... + ``` +- Create deployments: + Once you've made any needed changes to the spec files, create deployments from them: + + ```bash + laconic-so --stack ~/cerc/fixturenet-eth-stacks/stack-orchestrator/stacks/fixturenet-eth deploy create --spec-file fixturenet-eth-spec.yml --deployment-dir fixturenet-eth-deployment + ``` + +- Env configuration: + + ```bash + cat < fixturenet-eth-deployment/config.env + CERC_ALLOW_UNPROTECTED_TXS=true + EOF + ``` + +### Go-nitro + +- Clone the stack repo: + + ```bash + laconic-so fetch-stack git.vdb.to/cerc-io/nitro-stack --git-ssh --pull + ``` + +- Clone required repositories: + + ```bash + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node setup-repositories --git-ssh --pull + ``` + +- Build the container images: + + ```bash + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node build-containers --force-rebuild + ``` + +## Run + +- Start fixturenet-eth stack: + (run steps in directory where the stack deployments had been created) + + - Start `fixturenet-eth-deployment` deployment: + + ```bash + laconic-so deployment --dir fixturenet-eth-deployment start + ``` + + - Check status of L1 + + - Run status check: + + ```bash + laconic-so deployment --dir fixturenet-eth-deployment exec fixturenet-eth-bootnode-lighthouse "/scripts/status-internal.sh" + ``` + + - Check geth logs to ensure that new blocks are getting created + + ```bash + laconic-so deployment --dir fixturenet-eth-deployment logs -f fixturenet-eth-geth-1 + ``` + +- Deploy nitro contracts + - Create a deployment spec-file for 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,OPTIMISM_URL=http://host.docker.internal:9545,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 logs + laconic-so deployment --dir nitro-contracts-deployment logs nitro-contracts -f + ``` \ No newline at end of file diff --git a/stack-orchestrator/compose/docker-compose-nitro-contracts.yml b/stack-orchestrator/compose/docker-compose-nitro-contracts.yml index 51cf2e7..695b591 100644 --- a/stack-orchestrator/compose/docker-compose-nitro-contracts.yml +++ b/stack-orchestrator/compose/docker-compose-nitro-contracts.yml @@ -8,9 +8,7 @@ services: environment: CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} GETH_URL: ${GETH_URL} - OPTIMISM_URL: ${OPTIMISM_URL} GETH_CHAIN_ID: ${GETH_CHAIN_ID:-1212} - OPTIMISM_CHAIN_ID: ${OPTIMISM_CHAIN_ID:-42069} GETH_DEPLOYER_PK: ${GETH_DEPLOYER_PK} OPTIMISM_DEPLOYER_PK: ${GETH_DEPLOYER_PK} TOKEN_NAME: ${TOKEN_NAME} diff --git a/stack-orchestrator/config/nitro-contracts/deploy.sh b/stack-orchestrator/config/nitro-contracts/deploy.sh index 19f981d..e8524a2 100755 --- a/stack-orchestrator/config/nitro-contracts/deploy.sh +++ b/stack-orchestrator/config/nitro-contracts/deploy.sh @@ -7,15 +7,10 @@ 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 "GETH_URL: ${GETH_URL}" -echo "OPTIMISM_URL: ${OPTIMISM_URL}" echo "GETH_CHAIN_ID: ${GETH_CHAIN_ID}" -echo "OPTIMISM_CHAIN_ID: ${OPTIMISM_CHAIN_ID}" -echo "GETH_DEPLOYER_PK: ${GETH_DEPLOYER_PK}" -echo "OPTIMISM_DEPLOYER_PK: ${OPTIMISM_DEPLOYER_PK}" echo "TOKEN_NAME: ${TOKEN_NAME}" echo "TOKEN_SYMBOL: ${TOKEN_SYMBOL}" echo "INITIAL_TOKEN_SUPPLY: ${INITIAL_TOKEN_SUPPLY}" @@ -34,29 +29,6 @@ else cp ${addresses_deployment_file} ${nitro_addresses_file} fi -# Check if L1 chain id key is present for L1 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 - -L1_ASSET_ADDRESS=$(jq -r ".\"$GETH_CHAIN_ID\"[0].contracts.Token.address" ${nitro_addresses_file}) -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 < "$bridge_assets_map_file" -[[assets]] -l1AssetAddress = "$L1_ASSET_ADDRESS" -l2AssetAddress = "$L2_ASSET_ADDRESS" -EOF - echo "Done" # Keep the container running for future asset transfers diff --git a/stack-orchestrator/stacks/nitro-contracts/README.md b/stack-orchestrator/stacks/nitro-contracts/README.md new file mode 100644 index 0000000..88f85d0 --- /dev/null +++ b/stack-orchestrator/stacks/nitro-contracts/README.md @@ -0,0 +1 @@ +# TODO: Update README \ No newline at end of file diff --git a/stack-orchestrator/stacks/nitro-contracts/stack.yml b/stack-orchestrator/stacks/nitro-contracts/stack.yml new file mode 100644 index 0000000..ece621d --- /dev/null +++ b/stack-orchestrator/stacks/nitro-contracts/stack.yml @@ -0,0 +1,9 @@ +version: "1.0" +name: nitro-contracts +description: "Deploy nitro contracts" +repos: + - github.com/cerc-io/go-nitro +containers: + - cerc/nitro-client +pods: + - nitro-contracts -- 2.45.2 From a5e4d76e554e9d574a31d00e97f8e72855445a4e Mon Sep 17 00:00:00 2001 From: Neeraj Date: Thu, 22 Aug 2024 15:23:31 +0530 Subject: [PATCH 2/8] Add steps to run nitro nodes --- nitro-node-demo.md | 149 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 1 deletion(-) diff --git a/nitro-node-demo.md b/nitro-node-demo.md index 8c45c4d..438fa60 100644 --- a/nitro-node-demo.md +++ b/nitro-node-demo.md @@ -124,10 +124,11 @@ ``` - Deploy nitro contracts + - Create a deployment spec-file for 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,OPTIMISM_URL=http://host.docker.internal:9545,GETH_DEPLOYER_PK=888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218,TOKEN_NAME=LaconicNetworkToken,TOKEN_SYMBOL=LNT,INITIAL_TOKEN_SUPPLY=129600" + 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 @@ -143,4 +144,150 @@ # Check the logs laconic-so deployment --dir nitro-contracts-deployment logs nitro-contracts -f + ``` + + - Get the deployed nitro contract addresses + + ```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 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 deployment for Alice: + - Create a deployment spec-file for Alice node: + + ```bash + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy init --output alice-nitro-spec.yml + ``` + + - Edit `network` in the spec file to map container ports to host ports as required: + + ```bash + # alice-nitro-spec.yml + ... + network: + ports: + nitro-node: + - 3007:3005 + - 4007:4005 + ``` + + - Create a deployment `alice-nitro-deployment` from the spec file + + ```bash + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy create --spec-file alice-nitro-spec.yml --deployment-dir alice-nitro-deployment + ``` + + - Set the env variables for Alice's nitro-node: + + ```bash + cat < alice-nitro-deployment/config.env + NITRO_CHAIN_URL=ws://host.docker.internal:8546 + NITRO_SC_PK=0x9aebbd42f3044295411e3631fcb6aa834ed5373a6d3bf368bfa09e5b74f4f6d1 + NITRO_CHAIN_PK=570b909da9669b2f35a0b1ac70b8358516d55ae1b5b3710e95e9a94395090597 + NA_ADDRESS=$NA_ADDRESS + VPA_ADDRESS=$VPA_ADDRESS + CA_ADDRESS=$CA_ADDRESS + NITRO_EXT_MULTIADDR=/dns4/host.docker.internal/tcp/3007 + EOF + ``` + +- Create deployment for Charlie: + + - Create a deployment spec-file for Charlie node: + + ```bash + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy init --output charlie-nitro-spec.yml + ``` + + - Edit `network` in the spec file to map container ports to host ports as required: + + ```bash + # charlie-nitro-spec.yml + ... + network: + ports: + nitro-node: + - 3008:3005 + - 4008:4005 + ``` + + - Create a deployment `charlie-nitro-deployment` from the spec file + + ```bash + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy create --spec-file charlie-nitro-spec.yml --deployment-dir charlie-nitro-deployment + ``` + + - Set the env variables for Charlie's nitro-node: + + ```bash + cat < charlie-nitro-deployment/config.env + NITRO_CHAIN_URL=ws://host.docker.internal:8546 + NITRO_SC_PK=0x19242258fc60ec7488db0163b20ed1c32f2d27dc49e4d427a461e20a6656de20 + NITRO_CHAIN_PK=111b7500bdce494d6f4bcfe8c2a0dde2ef92f751d9070fac6475dbd6d8021b3f + NA_ADDRESS=$NA_ADDRESS + VPA_ADDRESS=$VPA_ADDRESS + CA_ADDRESS=$CA_ADDRESS + NITRO_BOOTPEERS=/dns4/host.docker.internal/tcp/3007/p2p/16Uiu2HAmVbAtvDW1xrq4gDwRtdTjT1bqVdFJX6eWZbfn174wEENL + NITRO_EXT_MULTIADDR=/dns4/host.docker.internal/tcp/3008 + EOF + ``` + +## Demo + +- Start nitro nodes + + - Start `alice-nitro-deployment` deployment: + ``` + laconic-so deployment --dir alice-nitro-deployment start + + # Check the logs + laconic-so deployment --dir alice-nitro-deployment logs nitro-node -f + ``` + + - Start `charlie-nitro-deployment` deployment: + + ``` + laconic-so deployment --dir charlie-nitro-deployment start + + # Check the logs + laconic-so deployment --dir charlie-nitro-deployment logs nitro-node -f + ``` + +## Cleanup + +- Reset nitro-node deployments: + + - Stop nitro-node deployments and remove volumes: + + ```bash + # Run where deployments are created + laconic-so deployment --dir alice-nitro-deployment stop --delete-volumes + laconic-so deployment --dir charlie-nitro-deployment stop --delete-volumes + ``` + + - Clear nitro-node and bridge deployments: + + ```bash + # Run where deployments are created + sudo rm -rf alice-nitro-deployment + sudo rm -rf charlie-nitro-deployment + ``` + +- Clean up fixturenet-eth deployment: + - Stop deployment and remove volumes: + + ```bash + # Run where deployments are created + laconic-so deployment --dir fixturenet-eth-deployment stop --delete-volumes + ``` + + - Clear deployments: + + ```bash + # Run where deployments are created + sudo rm -rf fixturenet-eth-deployment ``` \ No newline at end of file -- 2.45.2 From 3bee4d1ad912524c0ff44d57117c579ad76f9582 Mon Sep 17 00:00:00 2001 From: Neeraj Date: Thu, 22 Aug 2024 16:38:00 +0530 Subject: [PATCH 3/8] Add steps to make payment and defund the channel --- nitro-node-demo.md | 83 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/nitro-node-demo.md b/nitro-node-demo.md index 438fa60..3fcbba0 100644 --- a/nitro-node-demo.md +++ b/nitro-node-demo.md @@ -153,7 +153,27 @@ 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 ASSET_ADDRESS="$(laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.Token.address' /app/deployment/nitro-addresses.json")" + ``` + +- Send custom tokens to Alice and Charlie + + - Export variables for token address + + ```bash + export 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 C_CHAIN_ADDRESS="0xf1ac8Dd1f6D6F5c0dA99097c57ebF50CD99Ce293" + ``` + + - Send tokens to Alice and Charlie + + ```bash + # Send tokens to Alice + laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "cd packages/nitro-protocol && yarn hardhat transfer --contract $ASSET_ADDRESS --to $A_CHAIN_ADDRESS --amount 1000 --network geth" + + #Send tokens to Charlie + laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "cd packages/nitro-protocol && yarn hardhat transfer --contract $ASSET_ADDRESS --to $C_CHAIN_ADDRESS --amount 1000 --network geth" ``` - Create deployment for Alice: @@ -257,6 +277,67 @@ laconic-so deployment --dir charlie-nitro-deployment logs nitro-node -f ``` +- Create ledger channels + + - Set address of custom token in the current terminal + + ```bash + export 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 Alice and Charlie with custom token + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client direct-fund 0x03Eb7a84E286c671836b9897AaE24b31D36f9cA8 --assetAddress $ASSET_ADDRESS --alphaAmount 1000000 --betaAmount 1000000 -p 4005 -h nitro-node" + + LEDGER_CHANNEL_ID= + ``` + + - Check status of ledger channel between Alice and Charlie + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-ledger-channel $LEDGER_CHANNEL_ID -p 4005 -h nitro-node" + ``` + +- Create virtual channel from Alice to Charlie + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client virtual-fund 0x03Eb7a84E286c671836b9897AaE24b31D36f9cA8 --amount 1000 -p 4005 -h nitro-node" + + # Set the payment channel id in a variable + PAYMENT_CHANNEL_ID= + ``` + +- Check payment channel between Alice and Charlie + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-payment-channel $PAYMENT_CHANNEL_ID -p 4005 -h nitro-node" + ``` + +- After virtual fund objective is complete, make payments + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client pay $PAYMENT_CHANNEL_ID 200 -p 4005 -h nitro-node" + ``` + +- Close payment channel after payments + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client virtual-defund $PAYMENT_CHANNEL_ID -p 4005 -h nitro-node" + ``` + +- Close ledger channel between Alice and Charlie + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client direct-defund $LEDGER_CHANNEL_ID -p 4005 -h nitro-node" + ``` + +- Check status of ledger channel between Alice and Charlie + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-ledger-channel $LEDGER_CHANNEL_ID -p 4005 -h nitro-node" + ``` + ## Cleanup - Reset nitro-node deployments: -- 2.45.2 From 428e40a39c77fd02370fd288a72ccb7e53dd5353 Mon Sep 17 00:00:00 2001 From: Neeraj Date: Thu, 22 Aug 2024 19:20:16 +0530 Subject: [PATCH 4/8] Create seperate service to deploy l2 nitro contract --- nitro-bridge-demo.md | 55 ++++++++++++++++--- nitro-node-demo.md | 2 + .../compose/docker-compose-nitro-bridge.yml | 30 +++++++++- .../docker-compose-nitro-contracts.yml | 4 +- .../config/go-nitro/run-bridge.sh | 11 ++-- .../{deploy.sh => deploy-l1-contracts.sh} | 0 .../nitro-contracts/deploy-l2-contracts.sh | 50 +++++++++++++++++ stack-orchestrator/stacks/bridge/stack.yml | 1 - 8 files changed, 136 insertions(+), 17 deletions(-) rename stack-orchestrator/config/nitro-contracts/{deploy.sh => deploy-l1-contracts.sh} (100%) create mode 100755 stack-orchestrator/config/nitro-contracts/deploy-l2-contracts.sh diff --git a/nitro-bridge-demo.md b/nitro-bridge-demo.md index 35dd506..d5aaea2 100644 --- a/nitro-bridge-demo.md +++ b/nitro-bridge-demo.md @@ -296,11 +296,45 @@ # 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: + + - 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: ```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: @@ -314,6 +348,9 @@ ```bash 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 laconic-so deployment --dir bridge-deployment logs nitro-bridge -f ``` @@ -323,7 +360,7 @@ - Export variables for L1 token address ```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 C_CHAIN_ADDRESS="0xf1ac8Dd1f6D6F5c0dA99097c57ebF50CD99Ce293" @@ -333,10 +370,10 @@ ```bash # 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 - 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 @@ -344,9 +381,9 @@ ```bash # 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 CA_ADDRESS=$(laconic-so deployment --dir bridge-deployment exec nitro-bridge "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 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") # 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") @@ -498,7 +535,7 @@ ```bash 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 @@ -703,6 +740,7 @@ laconic-so deployment --dir l2alice-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 nitro-contracts-deployment stop --delete-volumes ``` - Clear nitro-node and bridge deployments: @@ -714,6 +752,7 @@ sudo rm -rf l2alice-nitro-deployment sudo rm -rf l2charlie-nitro-deployment sudo rm -rf bridge-deployment + sudo rm -rf nitro-contracts-deployment ``` - Clean up L1 and L2 deployments: diff --git a/nitro-node-demo.md b/nitro-node-demo.md index 3fcbba0..46f3f79 100644 --- a/nitro-node-demo.md +++ b/nitro-node-demo.md @@ -348,6 +348,7 @@ # Run where deployments are created laconic-so deployment --dir alice-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: @@ -356,6 +357,7 @@ # Run where deployments are created sudo rm -rf alice-nitro-deployment sudo rm -rf charlie-nitro-deployment + sudo rm -rf nitro-contracts-deployment ``` - Clean up fixturenet-eth deployment: diff --git a/stack-orchestrator/compose/docker-compose-nitro-bridge.yml b/stack-orchestrator/compose/docker-compose-nitro-bridge.yml index db66e24..6f846ee 100644 --- a/stack-orchestrator/compose/docker-compose-nitro-bridge.yml +++ b/stack-orchestrator/compose/docker-compose-nitro-bridge.yml @@ -1,13 +1,36 @@ name: nitro-bridge 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: image: cerc/go-nitro:local hostname: nitro-bridge restart: unless-stopped depends_on: - nitro-contracts: - condition: service_started + l2-nitro-contracts: + condition: service_started environment: CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} GETH_CHAIN_ID: ${GETH_CHAIN_ID:-1212} @@ -23,6 +46,9 @@ services: NITRO_L1_EXT_MULTIADDR: ${NITRO_L1_EXT_MULTIADDR} NITRO_L2_EXT_MULTIADDR: ${NITRO_L2_EXT_MULTIADDR} 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"] volumes: - nitro_bridge_data:/app/data diff --git a/stack-orchestrator/compose/docker-compose-nitro-contracts.yml b/stack-orchestrator/compose/docker-compose-nitro-contracts.yml index 695b591..b2bd236 100644 --- a/stack-orchestrator/compose/docker-compose-nitro-contracts.yml +++ b/stack-orchestrator/compose/docker-compose-nitro-contracts.yml @@ -17,8 +17,8 @@ services: DISABLE_DETERMINISTIC_DEPLOYMENT: ${DISABLE_DETERMINISTIC_DEPLOYMENT:-true} volumes: - nitro_deployment:/app/deployment - - ../config/nitro-contracts/deploy.sh:/app/deploy.sh - command: ["bash", "-c", "/app/deploy.sh"] + - ../config/nitro-contracts/deploy-l1-contracts.sh:/app/deploy-l1-contracts.sh + command: ["bash", "-c", "/app/deploy-l1-contracts.sh"] extra_hosts: - "host.docker.internal:host-gateway" diff --git a/stack-orchestrator/config/go-nitro/run-bridge.sh b/stack-orchestrator/config/go-nitro/run-bridge.sh index 906d84a..5069233 100755 --- a/stack-orchestrator/config/go-nitro/run-bridge.sh +++ b/stack-orchestrator/config/go-nitro/run-bridge.sh @@ -20,6 +20,9 @@ echo "NITRO_RPC_PORT: ${NITRO_RPC_PORT}" echo "NITRO_PUBLIC_P2P_HOST: ${NITRO_PUBLIC_P2P_HOST}" echo "NITRO_L1_EXT_MULTIADDR: ${NITRO_L1_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" @@ -45,12 +48,12 @@ bridgepublicip = "$NITRO_PUBLIC_P2P_HOST" nodel1ExtMultiAddr = "$NITRO_L1_EXT_MULTIADDR" nodel2ExtMultiAddr = "$NITRO_L2_EXT_MULTIADDR" assetmapfilepath = "$bridge_assets_map_file" +naaddress = "${NA_ADDRESS}" +vpaaddress = "${VPA_ADDRESS}" +caaddress = "${CA_ADDRESS}" EOF -# Export contract addresses -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 export BRIDGE_ADDRESS=$(jq -r ".\"$OPTIMISM_CHAIN_ID\"[0].contracts.Bridge.address" ${nitro_addresses_file}) # Start bridge diff --git a/stack-orchestrator/config/nitro-contracts/deploy.sh b/stack-orchestrator/config/nitro-contracts/deploy-l1-contracts.sh similarity index 100% rename from stack-orchestrator/config/nitro-contracts/deploy.sh rename to stack-orchestrator/config/nitro-contracts/deploy-l1-contracts.sh diff --git a/stack-orchestrator/config/nitro-contracts/deploy-l2-contracts.sh b/stack-orchestrator/config/nitro-contracts/deploy-l2-contracts.sh new file mode 100755 index 0000000..39f2b13 --- /dev/null +++ b/stack-orchestrator/config/nitro-contracts/deploy-l2-contracts.sh @@ -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 < "$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 diff --git a/stack-orchestrator/stacks/bridge/stack.yml b/stack-orchestrator/stacks/bridge/stack.yml index 63be604..a162378 100644 --- a/stack-orchestrator/stacks/bridge/stack.yml +++ b/stack-orchestrator/stacks/bridge/stack.yml @@ -7,6 +7,5 @@ containers: - cerc/nitro-client - cerc/go-nitro pods: - - nitro-contracts - nitro-bridge - nitro-rpc-client -- 2.45.2 From 5610385b143156718f807a9d6d8f53f69d8f52bf Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 23 Aug 2024 10:29:10 +0530 Subject: [PATCH 5/8] Add expected output for commands in nitro-node readme --- nitro-node-demo.md | 105 +++++++++++++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 27 deletions(-) diff --git a/nitro-node-demo.md b/nitro-node-demo.md index 46f3f79..b545a72 100644 --- a/nitro-node-demo.md +++ b/nitro-node-demo.md @@ -132,7 +132,7 @@ ``` - 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 ``` @@ -141,11 +141,11 @@ ``` laconic-so deployment --dir nitro-contracts-deployment start - + # Check the logs laconic-so deployment --dir nitro-contracts-deployment logs nitro-contracts -f ``` - + - Get the deployed nitro contract addresses ```bash @@ -153,28 +153,28 @@ 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") - ``` + ``` - Send custom tokens to Alice and Charlie - Export variables for token address - + ```bash export 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 C_CHAIN_ADDRESS="0xf1ac8Dd1f6D6F5c0dA99097c57ebF50CD99Ce293" ``` - + - Send tokens to Alice and Charlie - + ```bash # Send tokens to Alice laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "cd packages/nitro-protocol && yarn hardhat transfer --contract $ASSET_ADDRESS --to $A_CHAIN_ADDRESS --amount 1000 --network geth" - + #Send tokens to Charlie laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "cd packages/nitro-protocol && yarn hardhat transfer --contract $ASSET_ADDRESS --to $C_CHAIN_ADDRESS --amount 1000 --network geth" - ``` + ``` - Create deployment for Alice: - Create a deployment spec-file for Alice node: @@ -196,11 +196,11 @@ ``` - Create a deployment `alice-nitro-deployment` from the spec file - + ```bash laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy create --spec-file alice-nitro-spec.yml --deployment-dir alice-nitro-deployment ``` - + - Set the env variables for Alice's nitro-node: ```bash @@ -213,7 +213,7 @@ CA_ADDRESS=$CA_ADDRESS NITRO_EXT_MULTIADDR=/dns4/host.docker.internal/tcp/3007 EOF - ``` + ``` - Create deployment for Charlie: @@ -222,7 +222,7 @@ ```bash laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy init --output charlie-nitro-spec.yml ``` - + - Edit `network` in the spec file to map container ports to host ports as required: ```bash @@ -236,11 +236,11 @@ ``` - Create a deployment `charlie-nitro-deployment` from the spec file - + ```bash laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy create --spec-file charlie-nitro-spec.yml --deployment-dir charlie-nitro-deployment ``` - + - Set the env variables for Charlie's nitro-node: ```bash @@ -254,7 +254,7 @@ NITRO_BOOTPEERS=/dns4/host.docker.internal/tcp/3007/p2p/16Uiu2HAmVbAtvDW1xrq4gDwRtdTjT1bqVdFJX6eWZbfn174wEENL NITRO_EXT_MULTIADDR=/dns4/host.docker.internal/tcp/3008 EOF - ``` + ``` ## Demo @@ -267,36 +267,50 @@ # Check the logs laconic-so deployment --dir alice-nitro-deployment logs nitro-node -f ``` - + - Start `charlie-nitro-deployment` deployment: ``` laconic-so deployment --dir charlie-nitro-deployment start - + # Check the logs laconic-so deployment --dir charlie-nitro-deployment logs nitro-node -f ``` -- Create ledger channels +- Create ledger channels - Set address of custom token in the current terminal - + ```bash export 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 Alice and Charlie with custom token - + ```bash laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client direct-fund 0x03Eb7a84E286c671836b9897AaE24b31D36f9cA8 --assetAddress $ASSET_ADDRESS --alphaAmount 1000000 --betaAmount 1000000 -p 4005 -h nitro-node" - LEDGER_CHANNEL_ID= - ``` - + LEDGER_CHANNEL_ID= + ``` + - Check status of ledger channel between Alice and Charlie ```bash laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-ledger-channel $LEDGER_CHANNEL_ID -p 4005 -h nitro-node" + + # Expected output: + # { + # ID: '0x72e631943d8b89d9c70af7d3daa75a169fc84c84034ab77c850ceaf4a530a650', + # Status: 'Open', + # Balance: { + # AssetAddress: '0x2b79f4a92c177b4e61f5c4ac37b1b8a623c665a4', + # Me: '0x4b64e26da8279ab12bcd4ca9974ec2b4741e175e', + # Them: '0x03eb7a84e286c671836b9897aae24b31d36f9ca8', + # MyBalance: 1000000n, + # TheirBalance: 1000000n + # }, + # ChannelMode: 'Open' + # } ``` - Create virtual channel from Alice to Charlie @@ -304,7 +318,23 @@ ```bash laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client virtual-fund 0x03Eb7a84E286c671836b9897AaE24b31D36f9cA8 --amount 1000 -p 4005 -h nitro-node" - # Set the payment channel id in a variable + # Expected output: + # { + # ID: '0xf982de03e17fd8ff30b138f142bc17c3deb24a48ec38b41c13e621fa65172f3c', + # Status: 'Open', + # Balance: { + # AssetAddress: '0x0000000000000000000000000000000000000000', + # Payee: '0x03eb7a84e286c671836b9897aae24b31d36f9ca8', + # Payer: '0x4b64e26da8279ab12bcd4ca9974ec2b4741e175e', + # PaidSoFar: 0n, + # RemainingFunds: 1000n + # } + # } + ``` + +- Set the payment channel id in a variable + + ```bash PAYMENT_CHANNEL_ID= ``` @@ -317,7 +347,13 @@ - After virtual fund objective is complete, make payments ```bash - laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client pay $PAYMENT_CHANNEL_ID 200 -p 4005 -h nitro-node" + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client pay $PAYMENT_CHANNEL_ID 200 -p 4005 -h nitro-node" + + # Expected output: + # { + # Amount: 200, + # Channel: '0xf982de03e17fd8ff30b138f142bc17c3deb24a48ec38b41c13e621fa65172f3c' + # } ``` - Close payment channel after payments @@ -336,6 +372,21 @@ ```bash laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-ledger-channel $LEDGER_CHANNEL_ID -p 4005 -h nitro-node" + + # Expected output: + # { + # ID: '0x72e631943d8b89d9c70af7d3daa75a169fc84c84034ab77c850ceaf4a530a650', + # Status: 'Complete', + # Balance: { + # AssetAddress: '0x2b79f4a92c177b4e61f5c4ac37b1b8a623c665a4', + # Me: '0x4b64e26da8279ab12bcd4ca9974ec2b4741e175e', + # Them: '0x03eb7a84e286c671836b9897aae24b31d36f9ca8', + # MyBalance: 999800n, + # TheirBalance: 1000200n + # }, + # ChannelMode: 'Open' + # } + ``` ## Cleanup -- 2.45.2 From a60850aa36bb0d1c277ba34fd71c842c664fdf96 Mon Sep 17 00:00:00 2001 From: Neeraj Date: Fri, 23 Aug 2024 11:11:17 +0530 Subject: [PATCH 6/8] Check payment channel after making payment --- nitro-bridge-demo.md | 4 ++-- nitro-node-demo.md | 51 ++++++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/nitro-bridge-demo.md b/nitro-bridge-demo.md index d5aaea2..4e09343 100644 --- a/nitro-bridge-demo.md +++ b/nitro-bridge-demo.md @@ -731,7 +731,7 @@ - Reset nitro-node deployments: - - Stop nitro-node deployments and remove volumes: + - Stop nitro-node, bridge, nitro-contracts deployments and remove volumes: ```bash # Run where deployments are created @@ -743,7 +743,7 @@ laconic-so deployment --dir nitro-contracts-deployment stop --delete-volumes ``` - - Clear nitro-node and bridge deployments: + - Clear nitro-node, nitro-contracts and bridge deployments: ```bash # Run where deployments are created diff --git a/nitro-node-demo.md b/nitro-node-demo.md index b545a72..bc8e6f2 100644 --- a/nitro-node-demo.md +++ b/nitro-node-demo.md @@ -316,7 +316,19 @@ - Create virtual channel from Alice to Charlie ```bash - laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client virtual-fund 0x03Eb7a84E286c671836b9897AaE24b31D36f9cA8 --amount 1000 -p 4005 -h nitro-node" + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client virtual-fund 0x03Eb7a84E286c671836b9897AaE24b31D36f9cA8 --amount 1000 -p 4005 -h nitro-node" + ``` + +- Set the payment channel id in a variable + + ```bash + PAYMENT_CHANNEL_ID= + ``` + +- Check payment channel between Alice and Charlie + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-payment-channel $PAYMENT_CHANNEL_ID -p 4005 -h nitro-node" # Expected output: # { @@ -332,18 +344,6 @@ # } ``` -- Set the payment channel id in a variable - - ```bash - PAYMENT_CHANNEL_ID= - ``` - -- Check payment channel between Alice and Charlie - - ```bash - laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-payment-channel $PAYMENT_CHANNEL_ID -p 4005 -h nitro-node" - ``` - - After virtual fund objective is complete, make payments ```bash @@ -356,7 +356,26 @@ # } ``` -- Close payment channel after payments +- Check payment channel between Alice and Charlie after payment + + ```bash + laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-payment-channel $PAYMENT_CHANNEL_ID -p 4005 -h nitro-node" + + # Expected output: + # { + # ID: '0xf982de03e17fd8ff30b138f142bc17c3deb24a48ec38b41c13e621fa65172f3c', + # Status: 'Open', + # Balance: { + # AssetAddress: '0x0000000000000000000000000000000000000000', + # Payee: '0x03eb7a84e286c671836b9897aae24b31d36f9ca8', + # Payer: '0x4b64e26da8279ab12bcd4ca9974ec2b4741e175e', + # PaidSoFar: 200n, + # RemainingFunds: 800n + # } + # } + ``` + +- Close payment channel ```bash laconic-so deployment --dir alice-nitro-deployment exec nitro-rpc-client "nitro-rpc-client virtual-defund $PAYMENT_CHANNEL_ID -p 4005 -h nitro-node" @@ -393,7 +412,7 @@ - Reset nitro-node deployments: - - Stop nitro-node deployments and remove volumes: + - Stop nitro-node, nitro-contracts deployments and remove volumes: ```bash # Run where deployments are created @@ -402,7 +421,7 @@ laconic-so deployment --dir nitro-contracts-deployment stop --delete-volumes ``` - - Clear nitro-node and bridge deployments: + - Clear nitro-node and nitro-contracts deployments: ```bash # Run where deployments are created -- 2.45.2 From 0e02a5731aee8f0cfe3f8242f8e6dc229cf4f4f0 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 23 Aug 2024 11:42:06 +0530 Subject: [PATCH 7/8] Add stack instructions for nitro-contracts --- .../stacks/nitro-contracts/README.md | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/stack-orchestrator/stacks/nitro-contracts/README.md b/stack-orchestrator/stacks/nitro-contracts/README.md index 88f85d0..9672d92 100644 --- a/stack-orchestrator/stacks/nitro-contracts/README.md +++ b/stack-orchestrator/stacks/nitro-contracts/README.md @@ -1 +1,59 @@ -# TODO: Update README \ No newline at end of file +# nitro-contracts + +## Setup + +- Clone the stack repo: + + ```bash + laconic-so fetch-stack git.vdb.to/cerc-io/nitro-stack + ``` + +- Clone required repositories: + + ```bash + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-contracts setup-repositories + ``` + +- Build container images: + + ```bash + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-contracts build-containers + ``` + +## Create a deployment + +- Create a spec file + + ```bash + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-contracts deploy init --output nitro-contracts-spec.yml + ``` + +- Create deployment + + ```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 + ``` + +## Configuration + +- Inside the `nitro-contracts-deployment` deployment directory, open `config.env` file and set following env variables: + + ```bash + # URL endpoint of the L1 chain (Example: http://host.docker.internal:8545) + GETH_URL= + + # Private key of the account on chain that is used for deploying L1 contracts + GETH_DEPLOYER_PK= + + TOKEN_NAME=LaconicNetworkToken + + TOKEN_SYMBOL=LNT + + INITIAL_TOKEN_SUPPLY=129600 + ``` + +## Start the deployment + +```bash +laconic-so deployment --dir nitro-contracts-deployment start +``` -- 2.45.2 From cc663baa313994a89479c5163a3c25b9d17fc8d2 Mon Sep 17 00:00:00 2001 From: Neeraj Date: Mon, 26 Aug 2024 16:43:39 +0530 Subject: [PATCH 8/8] Refactor demo clean up for re-run --- nitro-bridge-demo.md | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/nitro-bridge-demo.md b/nitro-bridge-demo.md index 4e09343..9f31522 100644 --- a/nitro-bridge-demo.md +++ b/nitro-bridge-demo.md @@ -375,7 +375,6 @@ #Send tokens to Charlie 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 - Get the deployed nitro contract addresses (run in the directory where the deployments were created): @@ -524,6 +523,8 @@ laconic-so deployment --dir l2charlie-nitro-deployment logs nitro-node -f ``` +## Demo + - Create ledger channels on L1 and mirrored channels on L2 - Open new terminal, check that no channels exist on L2 @@ -711,21 +712,33 @@ laconic-so deployment --dir l1charlie-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 bridge-deployment stop --delete-volumes ``` - - Clear nitro-node deployments: + - Clear nitro-nodes durable store: ```bash # Run where deployments are created - sudo rm -rf l1alice-nitro-deployment - sudo rm -rf l1charlie-nitro-deployment - sudo rm -rf l2alice-nitro-deployment - sudo rm -rf l2charlie-nitro-deployment + sudo rm -rf l1alice-nitro-deployment/data/nitro_node_data/nitro-store + sudo rm -rf l1charlie-nitro-deployment/data/nitro_node_data/nitro-store + sudo rm -rf l2alice-nitro-deployment/data/nitro_node_data/nitro-store + sudo rm -rf l2charlie-nitro-deployment/data/nitro_node_data/nitro-store + sudo rm -rf bridge-deployment/data/nitro_bridge_data/bridge-store ``` ## Re-run -- After running demo cleanup, follow the steps from [Demo](#demo) to re-run the demo +- After running demo cleanup, start the deployments + + ```bash + laconic-so deployment --dir l1alice-nitro-deployment start + laconic-so deployment --dir l1charlie-nitro-deployment start + laconic-so deployment --dir l2alice-nitro-deployment start + laconic-so deployment --dir l2charlie-nitro-deployment start + laconic-so deployment --dir bridge-deployment start + ``` + +- Follow the steps from [Demo](#demo) to re-run the demo ## Cleanup -- 2.45.2