Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add demo instructions to fixturenet-payments stack #556

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/data/compose/docker-compose-go-nitro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:
start_period: 10s
ports:
- "3005"
- "4005"
- "4005:4005"
- "5005:5005"

volumes:
Expand Down
12 changes: 6 additions & 6 deletions app/data/repository-list.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/cerc-io/ipld-eth-db
github.com/cerc-io/go-ethereum
github.com/cerc-io/ipld-eth-server
github.com/cerc-io/eth-statediff-service
git.vdb.to/cerc-io/ipld-eth-db
git.vdb.to/cerc-io/go-ethereum
git.vdb.to/cerc-io/ipld-eth-server
git.vdb.to/cerc-io/eth-statediff-service
github.com/cerc-io/eth-statediff-fill-service
github.com/cerc-io/ipld-eth-db-validator
github.com/cerc-io/ipld-eth-beacon-indexer
Expand All @@ -18,7 +18,7 @@ github.com/vulcanize/uniswap-watcher-ts
github.com/vulcanize/uniswap-v3-info
github.com/vulcanize/assemblyscript
github.com/cerc-io/eth-probe
github.com/cerc-io/tx-spammer
git.vdb.to/cerc-io/tx-spammer
github.com/dboreham/foundry
github.com/lirewine/gem
github.com/lirewine/debug
Expand All @@ -30,7 +30,7 @@ github.com/ethereum-optimism/optimism
github.com/pokt-network/pocket-core
github.com/pokt-network/pocket-core-deployments
github.com/cerc-io/azimuth-watcher-ts
github.com/cerc-io/ipld-eth-state-snapshot
git.vdb.to/cerc-io/ipld-eth-state-snapshot
github.com/cerc-io/gelato-watcher-ts
github.com/filecoin-project/lotus
git.vdb.to/cerc-io/test-project
Expand Down
2 changes: 1 addition & 1 deletion app/data/stacks/fixturenet-eth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ It is not necessary to use them all at once, but a complete example follows:

```
# Setup
$ laconic-so setup-repositories --include github.com/cerc-io/go-ethereum,github.com/cerc-io/ipld-eth-db,github.com/cerc-io/ipld-eth-server,github.com/cerc-io/ipld-eth-beacon-db,github.com/cerc-io/ipld-eth-beacon-indexer,github.com/cerc-io/eth-probe,github.com/cerc-io/tx-spammer
$ laconic-so setup-repositories --include git.vdb.to/cerc-io/go-ethereum,git.vdb.to/cerc-io/ipld-eth-db,git.vdb.to/cerc-io/ipld-eth-server,github.com/cerc-io/ipld-eth-beacon-db,github.com/cerc-io/ipld-eth-beacon-indexer,github.com/cerc-io/eth-probe,git.vdb.to/cerc-io/tx-spammer

# Build
$ laconic-so build-containers --include cerc/go-ethereum,cerc/lighthouse,cerc/fixturenet-eth-geth,cerc/fixturenet-eth-lighthouse,cerc/ipld-eth-db,cerc/ipld-eth-server,cerc/ipld-eth-beacon-db,cerc/ipld-eth-beacon-indexer,cerc/eth-probe,cerc/keycloak,cerc/tx-spammer
Expand Down
2 changes: 1 addition & 1 deletion app/data/stacks/fixturenet-optimism/l2-only.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Prerequisite: An L1 Ethereum RPC endpoint
Clone required repositories:

```bash
laconic-so --stack fixturenet-optimism setup-repositories --exclude github.com/cerc-io/go-ethereum
laconic-so --stack fixturenet-optimism setup-repositories --exclude git.vdb.to/cerc-io/go-ethereum

# If this throws an error as a result of being already checked out to a branch/tag in a repo, remove the repositories mentioned below and re-run the command
```
Expand Down
25 changes: 0 additions & 25 deletions app/data/stacks/fixturenet-payments/.env.fixturenet

This file was deleted.

23 changes: 4 additions & 19 deletions app/data/stacks/fixturenet-payments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ laconic-so --stack fixturenet-payments build-containers

## Deploy

### Configuration

Deploy the stack:

```bash
laconic-so --stack fixturenet-payments deploy --cluster payments up

# Exposed on host ports:
# 5005: go-nitro node's p2p msg port
# 4005: go-nitro node's RPC endpoint
# 5005: go-nitro node's p2p endpoint
# 8081: reverse payment proxy's RPC endpoint
# 15432: MobyMask v3 watcher's db endpoint
# 3001: MobyMask v3 watcher endpoint
Expand All @@ -33,23 +32,9 @@ laconic-so --stack fixturenet-payments deploy --cluster payments up
# 3004: MobyMask v3 app
```

Check the logs of the MobyMask contract deployment container to get the deployed contract's address and generated root invite link:

```bash
docker logs -f $(docker ps -aq --filter name="mobymask-1")
```

Check the reverse payment proxy container logs:
## Demo

```bash
docker logs -f $(docker ps -aq --filter name="nitro-reverse-payment-proxy")
```

Run the ponder app:

```bash
docker exec -it payments-ponder-app-1 bash -c "pnpm start"
```
Follow the [demo](./demo.md) to try out end-to-end payments

## Clean up

Expand Down
216 changes: 216 additions & 0 deletions app/data/stacks/fixturenet-payments/demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# Demo

## MobyMask Watcher

* Check watcher logs and wait for the payment channel to be created with upstream go-nitro node:

```bash
docker logs -f $(docker ps -aq --filter name="mobymask-watcher-server")

# Expected output:
# vulcanize:server Using rpcProviderEndpoint as chain URL for Nitro node +0ms
# ...
# ts-nitro:util:nitro Ledger channel created with id 0x65703ccdfacab09ac35367bdbe6c5a337e7a6651aad526807607b1c59b28bc1e
# ...
# ts-nitro:util:nitro Virtual payment channel created with id 0x29ff1335d73391a50e8fde3e9b34f00c3d81c39ddc7f89187f44dd51df96140e
```

* Export the payment channel id to a variable:

```bash
export WATCHER_UPSTREAM_PAYMENT_CHANNEL=<PAYMENT_CHANNEL_ID>
```

* Generate an auth token required to query the go-nitro node's RPC endpoint:

```bash
export AUTH_TOKEN=$(curl -s -X POST -H "Content-Type: application/json" --data '{
"jsonrpc": "2.0", "id": 1,
"method": "get_auth_token",
"params": {}
}' http://127.0.0.1:4005/api/v1 | jq -r '.result')
```

* Check the payment channel status:

```bash
curl -X POST -H "Content-Type: application/json" --data "{
\"jsonrpc\": \"2.0\", \"id\": 1,
\"method\": \"get_payment_channel\",
\"params\": { \"authtoken\": \"$AUTH_TOKEN\", \"payload\": { \"Id\": \"$WATCHER_UPSTREAM_PAYMENT_CHANNEL\" } }
}" http://127.0.0.1:4005/api/v1 | jq

# Expected output:
# {
# "jsonrpc": "2.0",
# "id": 1,
# "result": {
# "ID": "0xfe1231722d6c2cd7af8606afe039582ebc438ee5ca2b956f8284cb497597583f",
# "Status": "Open",
# "Balance": {
# "AssetAddress": "0x0000000000000000000000000000000000000000",
# "Payee": "0xaaa6628ec44a8a742987ef3a114ddfe2d4f7adce",
# "Payer": "0xbbb676f9cff8d242e9eac39d063848807d3d1d94",
# "PaidSoFar": "0x0",
# "RemainingFunds": "0x3b9aca00"
# }
# }
# }
```

## MobyMask App

* Track the reverse payment proxy container logs in a terminal:

```bash
docker logs -f $(docker ps -aq --filter name="nitro-reverse-payment-proxy")
```

* Get the geth node’s port mapped to host:

```bash
docker port payments-fixturenet-eth-geth-1-1 8545
```

* In MetaMask Flask, add a custom network with the following settings:

```bash
# New RPC URL
http://127.0.0.1:<GETH_PORT>

# Chain ID
1212

# Currency symbol
ETH
```

* Import the faucet account in MetaMask and fund an additional account for usage in the app:

```bash
# Faucet PK
# 0x570b909da9669b2f35a0b1ac70b8358516d55ae1b5b3710e95e9a94395090597

# Clear activity tab for the accounts on chain restart
```

* Get the generated root invite link for the app from MobyMask contract deployment container logs:

```bash
docker logs -f $(docker ps -aq --filter name="mobymask-1")

# Expected output:
# ...
# "key": "0x60e706fda4639fe0a8eb102cb0ce81231cf6e819f41cb4eadf72d865ea4c11ad"
# }
# http://127.0.0.1:3004/#/members?invitation=<INVITATION>
```

* Open app in a browser using the invite link

* Run the following in the browser console to enable logs:

```bash
localStorage.debug = 'ts-nitro:*'
# Refresh the tab for taking effect
```

* In the app’s debug panel, check that the peer gets connected to relay node and watcher peer

* Open the `NITRO` tab in debug panel
* Click on `Connect Wallet` to connect to MetaMask (make sure that the newly funded account is active)
* Click on `Connect Snap` to install/connect snap

* Perform `DIRECT FUND` with the preset amount

* Perform `VIRTUAL FUND` with amount set to `10000`

* Perform phisher status check queries now that a payment channel is created:
* Check the watcher logs for received payments
* Check the payment proxy server logs for charged RPC requests (`eth_getBlockByHash`, `eth_getStorageAt`) made from watcher to upstream ETH server

* Change the amount besides `PAY` button to `>=100` for phisher reports next

* Perform a phisher report and check the watcher logs for received payments; the RPC mutation request is sent to geth node and is not charged

* Check the watcher - eth-server payment channel status after a few requests:

```bash
curl -X POST -H "Content-Type: application/json" --data "{
\"jsonrpc\": \"2.0\", \"id\": 1,
\"method\": \"get_payment_channel\",
\"params\": { \"authtoken\": \"$AUTH_TOKEN\", \"payload\": { \"Id\": \"$WATCHER_UPSTREAM_PAYMENT_CHANNEL\" } }
}" http://127.0.0.1:4005/api/v1 | jq

# Expected output ('PaidSoFar' should be non zero):
# {
# "jsonrpc": "2.0",
# "id": 1,
# "result": {
# "ID": "0xfe1231722d6c2cd7af8606afe039582ebc438ee5ca2b956f8284cb497597583f",
# "Status": "Open",
# "Balance": {
# "AssetAddress": "0x0000000000000000000000000000000000000000",
# "Payee": "0xaaa6628ec44a8a742987ef3a114ddfe2d4f7adce",
# "Payer": "0xbbb676f9cff8d242e9eac39d063848807d3d1d94",
# "PaidSoFar": "0x2710",
# "RemainingFunds": "0x3b9aa2f0"
# }
# }
# }
```

## Ponder App

* Run the ponder app in it's container:

```bash
docker exec -it payments-ponder-app-1 bash -c "pnpm start"

# Expected output:
# 09:58:54.288 INFO payment Creating ledger channel with nitro node 0xAAA6628Ec44A8a742987EF3A114dDFE2D4F7aDCE
# ...
# 09:59:14.230 INFO payment Creating payment channel with nitro node 0xAAA6628Ec44A8a742987EF3A114dDFE2D4F7aDCE
# ...
# 09:59:14.329 INFO payment Using payment channel 0x10f049519bc3f862e2b26e974be8666886228f30ea54aab06e2f23718afffab0
```

* Export the payment channel id to a variable:

```bash
export PONDER_UPSTREAM_PAYMENT_CHANNEL=<PAYMENT_CHANNEL_ID>
```

* Check the ponder - eth-server payment channel status:

```bash
curl -X POST -H "Content-Type: application/json" --data "{
\"jsonrpc\": \"2.0\", \"id\": 1,
\"method\": \"get_payment_channel\",
\"params\": { \"authtoken\": \"$AUTH_TOKEN\", \"payload\": { \"Id\": \"$PONDER_UPSTREAM_PAYMENT_CHANNEL\" } }
}" http://127.0.0.1:4005/api/v1 | jq

# Expected output:
# TODO
```

* Check reverse payment proxy server logs for charged RPC requests made from ponder app to upstream ETH server:

```bash
# Expected output:
# ...
# {"time":"2023-09-28T09:59:14.499841999Z","level":"DEBUG","msg":"Request cost","cost-per-byte":1,"response-length":61,"cost":61}
# {"time":"2023-09-28T09:59:14.500060006Z","level":"DEBUG","msg":"sent message","address":"0xAAA6628Ec44A8a742987EF3A114dDFE2D4F7aDCE","method":"receive_voucher"}
# {"time":"2023-09-28T09:59:14.501221898Z","level":"DEBUG","msg":"Received voucher","delta":5000}
# {"time":"2023-09-28T09:59:14.501245984Z","level":"DEBUG","msg":"Destination request","url":"http://ipld-eth-server:8081/?method=eth_getLogs"}
```

## Clean Up

* In the MobyMask app, perform `VIRTUAL DEFUND` and `DIRECT DEFUND` (in this order) for closing the payment channel created with watcher

* Run the following in the browser console to delete the Nitro node's data:

```bash
await clearNodeStorage()
```
8 changes: 4 additions & 4 deletions app/data/stacks/fixturenet-payments/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: fixturenet-payments
description: "Stack to demonstrate payments between various services"
repos:
# fixturenet repos
- github.com/cerc-io/go-ethereum
- github.com/cerc-io/lighthouse
- github.com/cerc-io/ipld-eth-db
- github.com/cerc-io/ipld-eth-server
- git.vdb.to/cerc-io/go-ethereum@v1.11.6-statediff-v5
- git.vdb.to/cerc-io/lighthouse
- git.vdb.to/cerc-io/ipld-eth-db@v5
- git.vdb.to/cerc-io/ipld-eth-server@v1.11.6-statediff-v5
# nitro repos
- github.com/cerc-io/ts-nitro@v0.1.12
- github.com/cerc-io/go-nitro@v0.1.0-ts-port-0.1.4 # TODO: Update after fixes
Expand Down