Skip to content

Commit

Permalink
Run multiple Ponder indexers in payment stack (#588)
Browse files Browse the repository at this point in the history
* Separate ponder indexer and ponder watcher and add second ponder indexer

* Handle review changes

* Update config to point ponder watcher to indexer 2 to indexer 1

* Update Ponder demo

* Use deployed ERC20 contract in second Ponder indexer

* Add order by timestamp in Ponder watcher app entities query

* Upgrade go-nitro version to v0.1.2-ts-port-0.1.9

* Decrease Ponder start block to process contract transfer event at deployment

---------

Co-authored-by: Shreerang Kale <[email protected]>
  • Loading branch information
nikugogoi and shreerang6921 authored Oct 19, 2023
1 parent 2402220 commit 4a90ced
Show file tree
Hide file tree
Showing 11 changed files with 326 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ services:
extra_hosts:
- "host.docker.internal:host-gateway"

ponder-app-indexer:
hostname: ponder-app-indexer
ponder-app-indexer-1:
hostname: ponder-app-indexer-1
restart: unless-stopped
image: cerc/ponder:local
working_dir: /app/examples/token-erc20
environment:
CERC_PONDER_CHAIN_ID: ${PONDER_CHAIN_ID:-99}
CERC_PONDER_RPC_URL_1: ${PONDER_RPC_URL_1:-http://ipld-eth-server-2:8081}
CERC_PONDER_NITRO_PK: ${CERC_PONDER_INDEXER_NITRO_PK:-58368d20ff12f17669c06158c21d885897aa56f9be430edc789614bf9851d53f}
CERC_PONDER_NITRO_CHAIN_PK: ${CERC_PONDER_INDEXER_NITRO_CHAIN_PK:-fb1e9af328c283ca3e2486e7c24d13582b7912057d8b9542ff41503c85bc05c0}
CERC_PONDER_NITRO_PK: ${CERC_PONDER_INDEXER_NITRO_PK_1:-58368d20ff12f17669c06158c21d885897aa56f9be430edc789614bf9851d53f}
CERC_PONDER_NITRO_CHAIN_PK: ${CERC_PONDER_INDEXER_NITRO_CHAIN_PK_1:-fb1e9af328c283ca3e2486e7c24d13582b7912057d8b9542ff41503c85bc05c0}
CERC_PONDER_NITRO_CHAIN_URL: ${CERC_PONDER_NITRO_CHAIN_URL:-http://fixturenet-eth-geth-1:8546}
CERC_RELAY_MULTIADDR: ${CERC_RELAY_MULTIADDR}
CERC_UPSTREAM_NITRO_ADDRESS: ${CERC_UPSTREAM_NITRO_ADDRESS:-0x660a4bEF3fbC863Fcd8D3CDB39242aE513d7D92e}
Expand All @@ -33,50 +33,48 @@ services:
command: ["bash", "./ponder-start.sh"]
volumes:
- ../config/ponder/ponder-start.sh:/app/examples/token-erc20/ponder-start.sh
- ../config/ponder/ponder.indexer.config.ts:/app/examples/token-erc20/ponder.config.ts
- ../config/ponder/ponder.indexer-1.config.ts:/app/examples/token-erc20/ponder.config.ts
- ../config/ponder/base-rates-config.json:/app/examples/token-erc20/base-rates-config.json
- peers_ids:/peers
- nitro_deployment:/nitro
- erc20_deployment:/erc20
- ponder_indexer_nitro_data:/app/examples/token-erc20/.ponder/nitro-db
- ponder_indexer_1_nitro_data:/app/examples/token-erc20/.ponder/nitro-db
ports:
- "42070"
- "127.0.0.1:42070:42070"
extra_hosts:
- "host.docker.internal:host-gateway"

ponder-app-watcher:
hostname: ponder-app-watcher
depends_on:
- ponder-app-indexer
ponder-app-indexer-2:
hostname: ponder-app-indexer-2
restart: unless-stopped
image: cerc/ponder:local
working_dir: /app/examples/token-erc20
environment:
CERC_PONDER_CHAIN_ID: ${PONDER_CHAIN_ID:-99}
CERC_PONDER_NITRO_PK: ${CERC_PONDER_WATCHER_NITRO_PK:-febb3b74b0b52d0976f6571d555f4ac8b91c308dfa25c7b58d1e6a7c3f50c781}
CERC_PONDER_NITRO_CHAIN_PK: ${CERC_PONDER_WATCHER_NITRO_CHAIN_PK:-be4aa664815ea3bc3d63118649a733f6c96b243744310806ecb6d96359ab62cf}
CERC_INDEXER_GQL_ENDPOINT: ${CERC_INDEXER_GQL_ENDPOINT:-http://ponder-app-indexer-1:42070/graphql}
CERC_PONDER_NITRO_PK: ${CERC_PONDER_INDEXER_NITRO_PK_2:-0aca28ba64679f63d71e671ab4dbb32aaa212d4789988e6ca47da47601c18fe2}
CERC_PONDER_NITRO_CHAIN_PK: ${CERC_PONDER_INDEXER_NITRO_CHAIN_PK_2:-6177345b77c4069ac4d553f8b43cf68a799ca4bb63eac93d6cf796d63694ebf0}
CERC_PONDER_NITRO_CHAIN_URL: ${CERC_PONDER_NITRO_CHAIN_URL:-http://fixturenet-eth-geth-1:8546}
CERC_RELAY_MULTIADDR: ${CERC_RELAY_MULTIADDR}
CERC_INDEXER_GQL_ENDPOINT: ${CERC_INDEXER_GQL_ENDPOINT:-http://ponder-app-indexer:42070/graphql}
CERC_INDEXER_NITRO_ADDRESS: ${CERC_INDEXER_NITRO_ADDRESS:-0x67D5b55604d1aF90074FcB69b8C51838FFF84f8d}
CERC_INDEXER_NITRO_PAY_AMOUNT: ${CERC_INDEXER_NITRO_PAY_AMOUNT:-50}
CERC_UPSTREAM_NITRO_PAY_AMOUNT: ${CERC_UPSTREAM_NITRO_PAY_AMOUNT:-100}
command: ["bash", "./ponder-start.sh"]
volumes:
- ../config/ponder/ponder-start.sh:/app/examples/token-erc20/ponder-start.sh
- ../config/ponder/ponder.watcher.config.ts:/app/examples/token-erc20/ponder.config.ts
- ../config/ponder/ponder.indexer-2.config.ts:/app/examples/token-erc20/ponder.config.ts
- ../config/ponder/base-rates-config.json:/app/examples/token-erc20/base-rates-config.json
- peers_ids:/peers
- nitro_deployment:/nitro
- erc20_deployment:/erc20
- ponder_watcher_nitro_data:/app/examples/token-erc20/.ponder/nitro-db
- ponder_indexer_2_nitro_data:/app/examples/token-erc20/.ponder/nitro-db
ports:
- "42069"
- "127.0.0.1:42071:42070"
extra_hosts:
- "host.docker.internal:host-gateway"

volumes:
peers_ids:
nitro_deployment:
erc20_deployment:
ponder_indexer_nitro_data:
ponder_watcher_nitro_data:
ponder_indexer_1_nitro_data:
ponder_indexer_2_nitro_data:
39 changes: 39 additions & 0 deletions app/data/compose/docker-compose-ponder-watcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

version: '3.7'

services:
ponder-app-watcher:
hostname: ponder-app-watcher
depends_on:
- ponder-app-indexer-1
restart: unless-stopped
image: cerc/ponder:local
working_dir: /app/examples/token-erc20
environment:
CERC_PONDER_CHAIN_ID: ${PONDER_CHAIN_ID:-99}
CERC_PONDER_NITRO_PK: ${CERC_PONDER_WATCHER_NITRO_PK:-febb3b74b0b52d0976f6571d555f4ac8b91c308dfa25c7b58d1e6a7c3f50c781}
CERC_PONDER_NITRO_CHAIN_PK: ${CERC_PONDER_WATCHER_NITRO_CHAIN_PK:-be4aa664815ea3bc3d63118649a733f6c96b243744310806ecb6d96359ab62cf}
CERC_PONDER_NITRO_CHAIN_URL: ${CERC_PONDER_NITRO_CHAIN_URL:-http://fixturenet-eth-geth-1:8546}
CERC_RELAY_MULTIADDR: ${CERC_RELAY_MULTIADDR}
CERC_INDEXER_GQL_ENDPOINT: ${CERC_INDEXER_GQL_ENDPOINT:-http://ponder-app-indexer-2:42070/graphql}
CERC_INDEXER_NITRO_ADDRESS: ${CERC_INDEXER_NITRO_ADDRESS:-0xB2B22ec3889d11f2ddb1A1Db11e80D20EF367c01}
CERC_INDEXER_NITRO_PAY_AMOUNT: ${CERC_INDEXER_NITRO_PAY_AMOUNT:-50}
command: ["bash", "./ponder-start.sh"]
volumes:
- ../config/ponder/ponder-start.sh:/app/examples/token-erc20/ponder-start.sh
- ../config/ponder/ponder.watcher.config.ts:/app/examples/token-erc20/ponder.config.ts
- ../config/ponder/base-rates-config.json:/app/examples/token-erc20/base-rates-config.json
- peers_ids:/peers
- nitro_deployment:/nitro
- erc20_deployment:/erc20
- ponder_watcher_nitro_data:/app/examples/token-erc20/.ponder/nitro-db
ports:
- "127.0.0.1:42069:42069"
extra_hosts:
- "host.docker.internal:host-gateway"

volumes:
peers_ids:
nitro_deployment:
erc20_deployment:
ponder_watcher_nitro_data:
4 changes: 3 additions & 1 deletion app/data/config/ponder/base-rates-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"freeQueriesLimit": 10,
"freeQueriesList": [],
"queries": {
"getLogEvents": "50"
"getLogEvents": "50",
"getEthLogs": "50",
"getEthBlock": "50"
},
"mutations": {}
}
11 changes: 7 additions & 4 deletions app/data/config/ponder/deploy-erc20-contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ fi

erc20_address_file="/app/deployment/erc20-address.json"

# Check and exit if a deployment already exists (on restarts)
echo ETH_RPC_URL=${CERC_ETH_RPC_ENDPOINT} > .env
echo ACCOUNT_PRIVATE_KEY=${CERC_PRIVATE_KEY_DEPLOYER} >> .env

# Check and keep container running if a deployment already exists (on restarts)
if [ -f ${erc20_address_file} ]; then
echo "${erc20_address_file} already exists, skipping ERC20 contract deployment"
cat ${erc20_address_file}
exit

# Keep the container running
tail -f
fi

wait_for_chain_endpoint() {
Expand Down Expand Up @@ -46,8 +51,6 @@ wait_for_chain_endpoint

echo "Using CERC_PRIVATE_KEY_DEPLOYER from env"

echo ETH_RPC_URL=${CERC_ETH_RPC_ENDPOINT} > .env
echo ACCOUNT_PRIVATE_KEY=${CERC_PRIVATE_KEY_DEPLOYER} >> .env
yarn token:deploy:docker --file ${erc20_address_file}

# Keep the container running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const config: Config = {
network: "fixturenet",
abi: "./abis/AdventureGold.json",
address: process.env.ERC20_CONTRACT,
startBlock: 5,
startBlock: 1,
maxBlockRange: 100,
},
],
Expand Down
64 changes: 64 additions & 0 deletions app/data/config/ponder/ponder.indexer-2.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { type Config, AppMode } from "@ponder/core";

import contractAddresses from "./nitro-addresses.json" assert { type: "json" };

export const config: Config = {
networks: [
{
name: "fixturenet",
chainId: Number(process.env.PONDER_CHAIN_ID),
indexerUrl: process.env.INDEXER_GQL_ENDPOINT,
maxRpcRequestConcurrency: 1,
pollingInterval: 5000,
payments: {
nitro: {
address: process.env.INDEXER_NITRO_ADDRESS!,
fundingAmounts: {
// TODO: Pass amounts from env
directFund: "1000000000000",
virtualFund: "1000000000",
},
},
paidRPCMethods: [
"eth_getLogs",
"eth_getBlockByNumber",
"eth_getBlockByHash",
],
amount: process.env.UPSTREAM_NITRO_PAY_AMOUNT!,
},
},
],
contracts: [
{
name: "AdventureGold",
network: "fixturenet",
abi: "./abis/AdventureGold.json",
address: process.env.ERC20_CONTRACT,
startBlock: 1,
maxBlockRange: 100,
},
],
options: {
mode: AppMode.Indexer,
},
nitro: {
privateKey: process.env.PONDER_NITRO_PK!,
chainPrivateKey: process.env.PONDER_NITRO_CHAIN_PK!,
chainUrl: process.env.PONDER_NITRO_CHAIN_URL!,
contractAddresses,
relayMultiAddr: process.env.RELAY_MULTIADDR!,
store: "./.ponder/nitro-db",
payments: {
cache: {
maxAccounts: 1000,
accountTTLInSecs: 1800,
maxVouchersPerAccount: 1000,
voucherTTLInSecs: 300,
maxPaymentChannels: 10000,
paymentChannelTTLInSecs: 1800,
},
ratesFile: "./base-rates-config.json",
requestTimeoutInSecs: 10,
},
},
};
2 changes: 1 addition & 1 deletion app/data/config/ponder/ponder.watcher.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const config: Config = {
network: "fixturenet",
abi: "./abis/AdventureGold.json",
address: process.env.ERC20_CONTRACT,
startBlock: 5,
startBlock: 1,
maxBlockRange: 100,
},
],
Expand Down
9 changes: 6 additions & 3 deletions app/data/stacks/fixturenet-payments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ laconic-so --stack fixturenet-payments deploy --cluster payments up
# 32***: geth in statediffing mode and ipld-eth-server(s)
# 4005: in-process go-nitro node's RPC endpoint
# 3005: in-process go-nitro node's p2p TCP endpoint
# 5005: in-process go-nitro node's p2p WS endpoin
# 5005: in-process go-nitro node's p2p WS endpoint
# 4006: out-of-process go-nitro node's RPC endpoint
# 3006: out-of-process go-nitro node's p2p TCP endpoint
# 5006: out-of-process go-nitro node's p2p WS endpoint
Expand All @@ -38,7 +38,9 @@ laconic-so --stack fixturenet-payments deploy --cluster payments up
# 9090: MobyMask v3 watcher relay node endpoint
# 8080: MobyMask snap
# 3004: MobyMask v3 app
# 32***: geth with statediffing
# 42070: Ponder indexer-1
# 42071: Ponder indexer-2
# 42069: Ponder watcher
```

If running in the cloud, ensure all the of the above ports are open. The geth port can be retrieved with:
Expand All @@ -60,7 +62,8 @@ This will allow you to access the entirety of the app as if it were running loca

## Demo

Follow the [demo](./demo.md) to try out end-to-end payments.
- Follow the [mobymask-demo](./mobymask-demo.md) to try out MobyMask end-to-end payments.
- Follow the [ponder-demo](./ponder-demo.md) to try out Ponder end-to-end payments.

## Clean up

Expand Down
Loading

0 comments on commit 4a90ced

Please sign in to comment.