Sign inSign up

provable/ptokens-eth-syncer

By provable

•Updated over 2 years ago

Image
0

6.4K

provable/ptokens-eth-syncer repository overview

⁠:arrows_clockwise: pBTC ETH Syncer

The Provable pBTC Token ETH syncing tool, designed to keep up a feed of ETH blocks to the enclave.

 


 

⁠Build with docker
./build-image ptokens-eth-syncer:latest-vanilla vanilla ghp_... -f Dockerfile.dev

 

⁠:point_right: Usage:

First install dependencies:

❍ npm i

Then run the tool via:

❍ node eth-syncer.js

For more information:

❍ node eth-syncer.js --help


❍ ETH Syncer:

  Copyright Provable Things 2020
  Questions: [email protected]

❍ Info:

  A tool to watch for new ETH blocks & feed them to a pToken enclave.

❍ Usage:
  eth-syncer.js
  eth-syncer.js --help
  eth-syncer.js --version
  eth-syncer.js getInitBlock [--file=<path>]
  eth-syncer.js getSubmissionMaterial <blockNum> [--file=<path>]

❍ Commands:

  <no-command>          ❍ Start the ETH syncer.
  getSubmissionMaterial ❍ Get the submission material for a given block number.
  getInitBlock          ❍ Get a block that can be used to initialize the ETH side of a pToken enclave.

❍ Options:
    --help              ❍ Show this message.
    --version           ❍ Show version information.
    <blockNum>          ❍ The number of the bitcoin block in question.
    --file=<path>       ❍ Path to write the output to.

 


 

⁠:page_with_curl: Notes:

This tool polls the ETH blockchain for new blocks and upon finding one, assembles that block, all of it's transactions into a JSON, which it then submits to the pBTC enclave.

 


 

⁠:wrench: Configurables:

A guide to the various configurable fields in the config.js file in the crate root:

  • ENCLAVE_BINARY_NAME Name of the enclave binary.

  • MAX_ENCLAVE_RETRIES Max number of times to try and communicate with the enclave binary.

  • ENCLAVE_QUERY_MAX_TIME Max amount of time (in milliseconds) to wait for an enclave query to execute.

  • DB_LOCK_SLEEP_TIME: The amount of time in milliseconds the tool will sleep when encountering a database lock in the enclave before trying its previous action once more.

  • SLEEP_TIME: The amout of time in milliseconds the tool will sleep between successfully finding and submitting a BTC block.

  • MONGO_DATABASE_NAME: The name of the Mongo database accessible via the mongod daemon.

  • ETH_ENDPOINT: An endpoint for a full ethereum node on the desired ethereum network.

  • MONGO_COLLECTION_NAME: The name of the collection in the aforementioned database.

  • MONGO_DB_URL: The URL to access the above defined database.

  • RELATIVE_PATH_TO_ENCLAVE: Per title: a path to the enclave binary, relative to this configuration file.

  • GET_TX_RECEIPTS_CALL_TYPE: Depending on the endpoint in use, you can select 4 different RPC calls methods:

    • parity: perform parity_getBlockReceipts to download tx receipts

    • erigon: perform eth_getBlockReceipts to download tx receipts

    • single: (a.k.a. batch JSON RPC call) perform a single JSON RPC call to download all the block receipts

    • multiple: (a.k.a. non-batch json RPC call) performs a call for each tx receipt inside the block

    • auto: use parity if available otherwise use multiple

 


 

⁠:guardsman: Tests

To run the tests simply run:

❍ npx mocha

 


 

⁠:black_nib: To Do:
  • Make PATH_TO_ENCLAVE configurable!
  • More Tests!
  • Factor out bit of maybeGetNextBlock... fxn.
  • Catch ctrl-c & exit gracefully! (& in this case we can NOT delete the temp file EXCEPT when we catch a sigint)
  • Some form of clean up in above case.
  • Put main mongo db in state and close the connection if we hit the main catch
  • Handle block already in db error by incrementing num in state and continuing!
  • Handle receipts root error by decrementing block num and continuing (then, with above, it should solve orphans, bad blocks etc)
  • Handle NO_RESPONSE_FROM_NODE_ERR better by counting the retries or something before giving up. Then somehow send an alert that the node is down.
  • Implement queueing system for getting blocks so we can submit them faster to the enclave.

Tag summary

Content type

Image

Digest

sha256:81b5715b3…

Size

210 MB

Last updated

over 2 years ago

docker pull provable/ptokens-eth-syncer:3.12.0-strongbox