Add instructions for payments on L2 channel

This commit is contained in:
Prathamesh Musale 2024-09-17 18:34:07 +05:30
parent 789c51e574
commit a04da54129

View File

@ -176,7 +176,7 @@ Nitro nodes can be run using Ansible either locally or on a remote machine; foll
Create a ledger channel with the bridge on L1 which is mirrored on L2 Create a ledger channel with the bridge on L1 which is mirrored on L2
* Run the following commands deployment machine: * Run the following commands deployment machine
* Set required variables: * Set required variables:
@ -273,6 +273,146 @@ Create a ledger channel with the bridge on L1 which is mirrored on L2
# ] # ]
``` ```
## Payments On L2 Channel
Perform payments using a virtual payment channel created with another Nitro node over the mirrored L2 channel with bridge as an intermediary
* Run the following commands deployment machine
* Check status of the mirrored channel on L2:
```bash
laconic-so deployment --dir l2-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-all-ledger-channels -p 4005 -h nitro-node"
# Expected output:
# [
# {
# "ID": "0x6a9f5ccf1fa802525d794f4a899897f947615f6acc7141e61e056a8bfca29179",
# "Status": "Open",
# "Balance": {
# "AssetAddress": "<l2-asset-address>",
# "Me": "<your-nitro-address>",
# "Them": "<bridge-nitro-address>",
# "MyBalance": Xn,
# "TheirBalance": Yn
# },
# "ChannelMode": "Open"
# }
# ]
```
* Set required variables:
```bash
DEPLOYMENTS_DIR=<path-to-deployments-dir>
cd $DEPLOYMENTS_DIR/nitro-node
export BRIDGE_NITRO_ADDRESS=$(yq eval '.bridge_nitro_address' nitro-node-config.yml)
# Counterparty to create the payment channel with
export COUNTER_PARTY_ADDRESS=<counterparty-nitro-address>
# Mirrored channel on L2
export L2_CHANNEL_ID=<l2-channel-id>
# Amount to create the payment channel with
export PAYMENT_CHANNEL_AMOUNT=10000
```
* Check for existing payment channels for the L2 channel:
```bash
laconic-so deployment --dir l2-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-payment-channels-by-ledger $L2_CHANNEL_ID -p 4005 -h nitro-node"
```
* Create a virtual payment channel:
```bash
laconic-so deployment --dir l2-nitro-deployment exec nitro-rpc-client "nitro-rpc-client virtual-fund $COUNTER_PARTY_ADDRESS $BRIDGE_NITRO_ADDRESS --amount $PAYMENT_CHANNEL_AMOUNT -p 4005 -h nitro-node"
# Follow your L2 Nitro node logs for progress
# Expected Output:
# Objective started VirtualFund-0x43db45a101658387263b36d613322cc952d8ce5b70de51e3a495513c256bef4d
# Channel Open 0x43db45a101658387263b36d613322cc952d8ce5b70de51e3a495513c256bef4d
# Set the resulting payment channel id in a variable
PAYMENT_CHANNEL_ID=<payment-channel-id>
```
Multiple virtual payment channels can be created at once
* Check the payment channel's status:
```bash
laconic-so deployment --dir l2-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-payment-channel $PAYMENT_CHANNEL_ID -p 4005 -h nitro-node"
# Expected output:
# {
# ID: '0xb29aeb32c9495a793ebf7bd116232075d1e7bfe89fc82281c7d498e3ffd3e3bf',
# Status: 'Open',
# Balance: {
# AssetAddress: '0x0000000000000000000000000000000000000000',
# Payee: '<your-nitro-address>',
# Payer: '<counterparty-nitro-address>',
# PaidSoFar: 0n,
# RemainingFunds: <payment-channel-amount>n
# }
# }
```
* Send payments using the virtual payment channel:
```bash
export PAY_AMOUNT=200
laconic-so deployment --dir l2-nitro-deployment exec nitro-rpc-client "nitro-rpc-client pay $PAYMENT_CHANNEL_ID $PAY_AMOUNT -p 4005 -h nitro-node"
# Expected output
# {
# Amount: <pay-amount>,
# Channel: '<payment-channel-id>'
# }
# This can be done multiple times until the payment channel balance is exhausted
```
* Check payment channel's status again to view updated channel state
* Close the payment channel to settle on the L2 mirrored channel:
```bash
laconic-so deployment --dir l2-nitro-deployment exec nitro-rpc-client "nitro-rpc-client virtual-defund $PAYMENT_CHANNEL_ID -p 4005 -h nitro-node"
# Expected output:
# Objective started VirtualDefund-0x43db45a101658387263b36d613322cc952d8ce5b70de51e3a495513c256bef4d
# Channel complete 0x43db45a101658387263b36d613322cc952d8ce5b70de51e3a495513c256bef4d
```
* Check L2 mirrored channel's status after the virtual payment channel is closed:
```bash
laconic-so deployment --dir l2-nitro-deployment exec nitro-rpc-client "nitro-rpc-client get-all-ledger-channels -p 4005 -h nitro-node"
# Expected output:
# [
# {
# "ID": "0x6a9f5ccf1fa802525d794f4a899897f947615f6acc7141e61e056a8bfca29179",
# "Status": "Open",
# "Balance": {
# "AssetAddress": "<l2-asset-address>",
# "Me": "<your-nitro-address>",
# "Them": "<bridge-nitro-address>",
# "MyBalance": <your-updated-balance>n,
# "TheirBalance": <bridge-updated-balance>n
# },
# "ChannelMode": "Open"
# }
# ]
```
Your balance on the L2 channel should be reduced by total payments done on the virtual payment channel
## Clean up ## Clean up
* Switch to deployments dir: * Switch to deployments dir: