Add inspect command

This commit is contained in:
Luke Van Seters 2021-07-27 18:56:52 -04:00
parent d7f2d120dd
commit e38f1384ef
4 changed files with 35 additions and 21 deletions

View File

@ -28,6 +28,11 @@ Apply the latest migrations against the local DB:
poetry run exec alembic upgrade head poetry run exec alembic upgrade head
``` ```
Run inspect on a block
```
poetry run inspect --block-number 11931270 --rpc 'http://111.11.11.111:8545/'
```
To stop the services (if running in the background, otherwise just ctrl+c) To stop the services (if running in the background, otherwise just ctrl+c)
``` ```
poetry run stop poetry run stop
@ -67,7 +72,7 @@ poetry run stop # shutsdown all services or just ctrl + c if foreground
poetry run build # rebuilds containers poetry run build # rebuilds containers
poetry run attach # enters the mev-inspect container in interactive mode poetry run attach # enters the mev-inspect container in interactive mode
# launches inspection script # launches inspection script
poetry run inspect -script ... -block_number ... -rpc ... poetry run inspect --block-number 11931270 --rpc 'http://111.11.11.111:8545/'
``` ```

View File

@ -1,6 +1,6 @@
import argparse
import json import json
import click
from web3 import Web3 from web3 import Web3
from mev_inspect import block from mev_inspect import block
@ -10,7 +10,11 @@ from mev_inspect.classifier_specs import CLASSIFIER_SPECS
from mev_inspect.trace_classifier import TraceClassifier from mev_inspect.trace_classifier import TraceClassifier
def inspect_block(base_provider, block_number): @click.command()
@click.argument("block_number", type=int)
@click.argument("rpc")
def inspect_block(block_number: int, rpc: str):
base_provider = Web3.HTTPProvider(rpc)
block_data = block.create_from_block_number(block_number, base_provider) block_data = block.create_from_block_number(block_number, base_provider)
print(f"Total traces: {len(block_data.traces)}") print(f"Total traces: {len(block_data.traces)}")
@ -54,21 +58,4 @@ def get_stats(classified_traces) -> dict:
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Inspect some blocks.") inspect_block()
parser.add_argument(
"-block_number",
metavar="b",
type=int,
nargs="+",
help="the block number you are targetting, eventually this will need to be changed",
)
parser.add_argument(
"-rpc", metavar="r", help="rpc endpoint, this needs to have parity style traces"
)
args = parser.parse_args()
w3_base_provider = Web3.HTTPProvider(args.rpc)
inspect_block(w3_base_provider, args.block_number[0])

View File

@ -40,6 +40,7 @@ stop = 'scripts.docker:stop'
build = 'scripts.docker:build' build = 'scripts.docker:build'
attach = 'scripts.docker:attach' attach = 'scripts.docker:attach'
exec = 'scripts.docker:exec' exec = 'scripts.docker:exec'
inspect = 'scripts.inspect:inspect'
[tool.black] [tool.black]
exclude = ''' exclude = '''

21
scripts/inspect.py Normal file
View File

@ -0,0 +1,21 @@
from subprocess import check_call
import click
@click.command()
@click.option("--block-number", type=int, help="the block number you are targetting")
@click.option("--rpc", help="rpc endpoint, this needs to have parity style traces")
def inspect(block_number: int, rpc: str):
check_call(
[
"docker",
"compose",
"exec",
"mev-inspect",
"python",
"inspect_block.py",
str(block_number),
rpc,
]
)