Skip to content

Commit

Permalink
Decentralized relayer (#214)
Browse files Browse the repository at this point in the history
* Initial TRON support

* Fix error catching

* Support for TRON address type in /limits endpoint

* Minor refactoring

* Remove mock proof

* Make configurable feeLimit

* Add MPC guard service

* MPC relayer

* Fix guard signatures

* Fix guard signature

* Update launch scripts

* Add debug logs

* Handle trongrid error

* Initial

* Update launch script

* Ingore legacy ts errors

* Fix memo offset

* Fix commitment-watcher

* Fix fetching limits from external accounting contract

* Add /fee and /address endpoints for prover

* Fix job state & RelayPool fetcher

* Add /proverFee endpoint

* Fix fee manager init

* Fix RelayPool validation

* Fix commitment processing condition (#215)

* Add indexer service & make relayer stateless

* Fix build

* Add proxy optimistic state

* Fix indexer sync

* Add TxStore

* Fix build

* Fix indexer offset

* Fix prover sync bug (#216)

* Add direct deposits

* Fix watcher init

* updates job status on queue inclusion (#217)

* updates job status on queue inclusion

* Remove additional logic from getTransactionV2

* Added /proverAddress endpoint

* Propagating job validation error

* Job error description

* Trying to restore balance waiting routine

* Optimistic state for sent transactions

* Updating txHash in cached txs, introducing pendingDeltaIndex field in /info endpoint

* Setting reverted state to failed txs

* Clearing pending cache on tx revert

* Fix minor bugs (#218)

* Fix potential indexer gap

* Fix prover fee

* Don't import FeeOptions

* Use applyDenominator

* Move INDEXER_BLOCK_CONFIRMATIONS to config

* Update zp-relayer/workers/sentTxWorker.ts

Co-authored-by: Alexander Filippov <[email protected]>

* Update zp-relayer/pool/RelayPool.ts

Co-authored-by: Alexander Filippov <[email protected]>

* Update zp-relayer/pool/BasePool.ts

Co-authored-by: Alexander Filippov <[email protected]>

* make jobId mandatory for onFailed callback

---------

Co-authored-by: Alexander Filippov <[email protected]>
Co-authored-by: EvgenKor <[email protected]>

* Fix basic dd logic (#219)

* Add COMMITMENT_WATCHER_DIRECT_DEPOSIT_PARAMS_PATH

* Fix dd indexing logic

* Support both formats

* Mark job as failed if the indexer isn't synced yet

* Remove obsolete job

* Fix sync

* Fix sync

* Attempt to fix dd flow

* Remove unnecessary code

* Refactor code

* remove redundant methods

---------

Co-authored-by: Alexander Filippov <[email protected]>
Co-authored-by: r0wdy1 <[email protected]>
Co-authored-by: EvgenKor <[email protected]>
Co-authored-by: vladimir <[email protected]>
  • Loading branch information
5 people authored Aug 7, 2024
1 parent e603e42 commit 364e1e2
Show file tree
Hide file tree
Showing 115 changed files with 5,729 additions and 3,101 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ zp-relayer/poolTxs.db

*.md
*.yml
**/lib/
**/build/
**/*.json
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"singleQuote": true,
"arrowParens": "avoid",
"bracketSpacing": true,
"quoteProps": "consistent"
"quoteProps": "consistent",
"plugins": ["prettier-plugin-organize-imports"]
}
2 changes: 1 addition & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ These environment variables are required for all services.
| RELAYER_MIN_GAS_PRICE_BUMP_FACTOR | Minimum `gasPrice` bump factor to meet RPC node requirements. Default `0.1`. | float |
| RELAYER_MAX_FEE_PER_GAS_LIMIT | Max limit on `maxFeePerGas` parameter for each transaction in wei | integer |
| RELAYER_MAX_SENT_QUEUE_SIZE | Maximum number of jobs waiting in the `sentTxQueue` at a time. | integer |
| RELAYER_TX_REDUNDANCY | If set to `true`, instructs relayer to send `eth_sendRawTransaction` requests through all available RPC urls defined in `RPC_URL` variables instead of using first available one. Defaults to `false` | boolean |
| TX_REDUNDANCY | If set to `true`, instructs relayer to send `eth_sendRawTransaction` requests through all available RPC urls defined in `RPC_URL` variables instead of using first available one. Defaults to `false` | boolean |
| RELAYER_INSUFFICIENT_BALANCE_CHECK_TIMEOUT | Interval in milliseconds to check for relayer balance update if transaction send failed with insufficient balance error. Default `60000` | integer |
| RELAYER_SENT_TX_DELAY | Delay in milliseconds for sentTxWorker to verify submitted transactions | integer |
| RELAYER_SENT_TX_ERROR_THRESHOLD | Maximum number of re-sends which is considered to be normal. After this threshold each re-send will log a corresponding error (but re-send loop will continue). Defaults to `3`. | integer |
Expand Down
75 changes: 45 additions & 30 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,62 @@
version: '3.8'

services:
ganache:
image: trufflesuite/ganache-cli
command: >
--deterministic
--gasLimit 20000000
--allowUnlimitedContractSize
--networkId 1337
--chainId 1337
ports:
- 8545:8545
contracts:
image: lok52/zp-contracts:latest
verifier:
image: lok52/verifier:latest
build:
context: ./docker
dockerfile: Dockerfile.verifier
redis:
redis_indexer:
command: [redis-server, --appendonly, 'yes']
image: redis:6.2.6
indexer:
image: ghcr.io/zkbob/zkbob-relayer:${RELAYER_VERSION:-latest}
build:
context: .
dockerfile: docker/Dockerfile.relayer
command: yarn run start:indexer:prod
volumes:
- ./zp-relayer/params:/app/zp-relayer/params/
env_file: ./zp-relayer/indexer.env
environment:
- INDEXER_PORT=80
- COMMON_REDIS_URL=redis_indexer:6379
ports:
- 6379:6379
- 8000:80
depends_on:
- redis_indexer
redis_relayer:
command: [redis-server, --appendonly, 'yes']
image: redis:6.2.6
relayer:
image: ghcr.io/zkbob/zkbob-relayer:${RELAYER_VERSION:-latest}
build:
context: .
dockerfile: docker/Dockerfile.relayer
volumes:
- relayer_tree:/app/tree.db
- relayer_txs:/app/txs.db
- $PARAMS_PATH:/app/zp-relayer/params/
env_file: ./zp-relayer/relayer.env
- ./zp-relayer/params:/app/zp-relayer/params/
env_file: ./zp-relayer/relayer-decentralized.env
environment:
- RELAYER_PORT=80
- RELAYER_PROVER_URL=http://commitment_watcher:80
- COMMON_INDEXER_URL=http://indexer:80
- COMMON_REDIS_URL=redis_relayer:6379
ports:
- 8000:8000
watcher:
- 8001:80
depends_on:
- redis_relayer
redis_prover:
command: [redis-server, --appendonly, 'yes']
image: redis:6.2.6
commitment_watcher:
image: ghcr.io/zkbob/zkbob-relayer:${RELAYER_VERSION:-latest}
build:
context: .
dockerfile: docker/Dockerfile.relayer
command: yarn run start:direct-deposit-watcher:prod
env_file: ./zp-relayer/watcher.env
volumes:
relayer_tree:
relayer_txs:
command: yarn run start:commitment-watcher:prod
volumes:
- ./zp-relayer/params:/app/zp-relayer/params/
env_file: ./zp-relayer/commitment-watcher.env
environment:
- COMMITMENT_WATCHER_PORT=80
- COMMON_INDEXER_URL=http://indexer:80
- COMMON_REDIS_URL=redis_prover:6379
ports:
- 8002:80
depends_on:
- redis_prover
6 changes: 3 additions & 3 deletions docker/Dockerfile.relayer
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM rust:1.69.0-slim-buster as base
FROM rust:1.77.0-slim-buster as base

WORKDIR /app

RUN apt-get update && \
apt-get -y install curl && \
curl -sL https://deb.nodesource.com/setup_18.x | bash && \
curl -sL https://deb.nodesource.com/setup_20.x | bash && \
apt-get -y install nodejs libclang-dev clang && \
npm install -g yarn cargo-cp-artifact

Expand All @@ -29,7 +29,7 @@ RUN yarn build:relayer
RUN yarn install --frozen-lockfile --production


FROM node:18
FROM node:20

ARG RELAYER_REF
ARG RELAYER_SHA
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"devDependencies": {
"@types/node": "^18.11.17",
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.2.4",
"ts-loader": "9.4.2",
"tsc-alias": "^1.7.0",
"tsconfig-paths": "^4.1.0",
Expand Down
Loading

0 comments on commit 364e1e2

Please sign in to comment.