374 lines
12 KiB
Markdown
374 lines
12 KiB
Markdown
# 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 <<EOF > 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,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
|
|
```
|
|
|
|
- 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")
|
|
```
|
|
|
|
- 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:
|
|
|
|
```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 <<EOF > 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 <<EOF > 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
|
|
```
|
|
|
|
- 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"
|
|
```
|
|
|
|
- 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=<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:
|
|
|
|
- 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
|
|
``` |