Update README for Kube

This commit is contained in:
Luke Van Seters 2021-09-20 12:54:08 -04:00
parent 5682c2ce4e
commit be9ae86d5c

200
README.md
View File

@ -1,104 +1,122 @@
# mev-inspect # mev-inspect-py
A [WIP] Ethereum MEV Inspector in Python managed by Poetry > illuminating the dark forest 🌲🔦
## Containers **mev-inspect-py** is an MEV inspector for Ethereum
mev-inspect's local setup is built on [Docker Compose](https://docs.docker.com/compose/)
By default it starts up: Given a block, mev-inspect finds:
- `mev-inspect` - a container with the code in this repo used for running scripts - miner payments (gas + coinbase)
- `db` - a postgres database instance - tokens transfers and profit
- `pgadmin` - a postgres DB UI for querying and more (avaiable at localhost:5050) - swaps and [arbitrages](https://twitter.com/bertcmiller/status/142763202826305946://twitter.com/bertcmiller/status/1427632028263059462)
- ...and more
Data is stored in Postgres for analysis
## Running locally ## Running locally
Setup [Docker](https://www.docker.com/products/docker-desktop) mev-inspect-py is built to run on kubernetes locally and in production
Setup [Poetry](https://python-poetry.org/docs/#osx--linux--bashonwindows-install-instructions)
Install dependencies through poetry ### Install dependencies
Setup a local kubernetes deployment (we use [kind](https://kind.sigs.k8s.io/docs/user/quick-start))
Setup [Tilt](https://docs.tilt.dev/install.html) which manages the local deployment
### Start up
Set an environment variable `RPC_URL` to an RPC for fetching blocks
Example:
```
export RPC_URL="http://111.111.111.111:8546"
```
Note: mev-inspect-py currently requires and RPC with support for parity traces
Next, start all servcies with:
```
tilt up
```
Press "space" to see a browser of the services starting up
On first startup, you'll need to apply database migrations. Apply with:
```
kubectl exec deploy/mev-inspect-deployment -- alembic upgrade head
```
## Inspecting
### Inspect a single block
Inspecting block 12345
```
kubectl exec deploy/mev-inspect-deployment -- poetry run inspect-block 12345
```
### Inspect many blocks
Inspecting blocks 12345 to 13345
```
kubectl exec deploy/mev-inspect-deployment -- poetry run inspect-many-blocks 12345 13345
```
### Inspect all incoming blocks
Start a block listener with
```
kubectl exec deploy/mev-inspect-deployment -- /app/listener start
```
By default, it will pick up wherever you left off.
If running for the first time, listener starts at the latest block
See logs for the listener with
```
kubectl exec deploy/mev-inspect-deployment -- tail -f listener.log
```
And stop the listener with
```
kubectl exec deploy/mev-inspect-deployment -- /app/listener stop
```
## Contributing
### Guide
Coming soon
### Pre-commit
We use pre-commit to maintain a consistent style, prevent errors, and ensure test coverage.
To set up, install dependencies through poetry
``` ```
poetry install poetry install
``` ```
Start the services (optionally as daemon) Then install pre-commit hooks with
```
poetry run start [-d]
```
Apply the latest migrations against the local DB:
```
poetry run exec alembic upgrade head
```
Run inspect on a block
```
poetry run inspect -b/--block-number 11931270 -r/--rpc 'http://111.11.11.111:8545/'
```
To stop the services (if running in the background, otherwise just ctrl+c)
```
poetry run stop
```
MEV container can be attached via
```
poetry run attach
```
Running additional compose commands are possible through standard `docker
compose ...` calls. Check `docker compose help` for more tools available
## Executing scripts
Any script can be run from the mev-inspect container like
```
poetry run exec <your command here>
```
For example
```
poetry run exec python examples/uniswap_inspect.py -block_number=123 -rpc='111.111.111'
```
### Poetry Scripts
```bash
# code check
poetry run lint # linting via Pylint
poetry run test # testing and code coverage with Pytest
poetry run isort # fixing imports
poetry run mypy # type checking
poetry run black # style guide
poetry run pre-commit run --all-files # runs Black, PyLint and MyPy
# docker management
poetry run start [-d] # starts all services, optionally as a daemon
poetry run stop # shutsdown all services or just ctrl + c if foreground
poetry run build # rebuilds containers
poetry run attach # enters the mev-inspect container in interactive mode
# launches inspection script
poetry run inspect -b/--block-number 11931270 -r/--rpc 'http://111.11.11.111:8545/'
```
## Rebuilding containers
After changes to the app's Dockerfile, rebuild with
```
poetry run build
```
## Using PGAdmin
1. Go to [localhost:5050](localhost:5050)
2. Login with the PGAdmin username and password in `.env`
3. Add a new engine for mev_inspect with
- host: db
- user / password: see `.env`
## Contributing
Pre-commit is used to maintain a consistent style, prevent errors and ensure test coverage.
Install pre-commit with:
``` ```
poetry run pre-commit install poetry run pre-commit install
``` ```
Update README if needed
## FAQ
### How do I delete / reset my local postgres data?
Stop the system if running
```
tilt down
```
Then delete with
```
kubectl delete pvc data-postgresql-postgresql-0
```
### I was using the docker-compose setup and want to switch to kube, now what?
Make sure the docker-compose resources are down
```
docker compose down
```
Then go through the steps in the current README for kube setup