Add support for inspecting a range of blocks
This commit is contained in:
parent
c5dc3aa0f9
commit
6c727fb1f6
@ -41,6 +41,7 @@ build = 'scripts.poetry.docker:build'
|
|||||||
attach = 'scripts.poetry.docker:attach'
|
attach = 'scripts.poetry.docker:attach'
|
||||||
exec = 'scripts.poetry.docker:exec'
|
exec = 'scripts.poetry.docker:exec'
|
||||||
inspect = 'scripts.poetry.inspect:inspect'
|
inspect = 'scripts.poetry.inspect:inspect'
|
||||||
|
inspect-many = 'scripts.poetry.inspect:inspect_many'
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
exclude = '''
|
exclude = '''
|
||||||
|
@ -20,13 +20,51 @@ from mev_inspect.arbitrages import get_arbitrages
|
|||||||
from mev_inspect.swaps import get_swaps
|
from mev_inspect.swaps import get_swaps
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.group()
|
||||||
|
def cli():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
@click.argument("block_number", type=int)
|
@click.argument("block_number", type=int)
|
||||||
@click.argument("rpc")
|
@click.argument("rpc")
|
||||||
def inspect_block(block_number: int, rpc: str):
|
def inspect_block(block_number: int, rpc: str):
|
||||||
base_provider = Web3.HTTPProvider(rpc)
|
base_provider = Web3.HTTPProvider(rpc)
|
||||||
|
_inspect_block(base_provider, block_number)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.argument("after_block", type=int)
|
||||||
|
@click.argument("before_block", type=int)
|
||||||
|
@click.argument("rpc")
|
||||||
|
def inspect_many_blocks(after_block: int, before_block: int, rpc: str):
|
||||||
|
base_provider = Web3.HTTPProvider(rpc)
|
||||||
|
for block_number in range(after_block + 1, before_block):
|
||||||
|
_inspect_block(
|
||||||
|
base_provider,
|
||||||
|
block_number,
|
||||||
|
should_print_stats=False,
|
||||||
|
should_write_classified_traces=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _inspect_block(
|
||||||
|
base_provider,
|
||||||
|
block_number: int,
|
||||||
|
should_print_stats: bool = True,
|
||||||
|
should_write_classified_traces: bool = True,
|
||||||
|
should_write_swaps: bool = True,
|
||||||
|
should_write_arbitrages: bool = True,
|
||||||
|
):
|
||||||
|
|
||||||
|
block_message = f"Running for {block_number}"
|
||||||
|
dashes = "-" * len(block_message)
|
||||||
|
click.echo(dashes)
|
||||||
|
click.echo(block_message)
|
||||||
|
click.echo(dashes)
|
||||||
|
|
||||||
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)}")
|
click.echo(f"Total traces: {len(block_data.traces)}")
|
||||||
|
|
||||||
total_transactions = len(
|
total_transactions = len(
|
||||||
set(
|
set(
|
||||||
@ -35,33 +73,35 @@ def inspect_block(block_number: int, rpc: str):
|
|||||||
if t.transaction_hash is not None
|
if t.transaction_hash is not None
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
print(f"Total transactions: {total_transactions}")
|
click.echo(f"Total transactions: {total_transactions}")
|
||||||
|
|
||||||
trace_clasifier = TraceClassifier(CLASSIFIER_SPECS)
|
trace_clasifier = TraceClassifier(CLASSIFIER_SPECS)
|
||||||
classified_traces = trace_clasifier.classify(block_data.traces)
|
classified_traces = trace_clasifier.classify(block_data.traces)
|
||||||
print(f"Returned {len(classified_traces)} classified traces")
|
click.echo(f"Returned {len(classified_traces)} classified traces")
|
||||||
|
|
||||||
db_session = get_session()
|
db_session = get_session()
|
||||||
|
|
||||||
delete_classified_traces_for_block(db_session, block_number)
|
if should_write_classified_traces:
|
||||||
write_classified_traces(db_session, classified_traces)
|
delete_classified_traces_for_block(db_session, block_number)
|
||||||
|
write_classified_traces(db_session, classified_traces)
|
||||||
|
|
||||||
swaps = get_swaps(classified_traces)
|
swaps = get_swaps(classified_traces)
|
||||||
print(f"Found {len(swaps)} swaps")
|
click.echo(f"Found {len(swaps)} swaps")
|
||||||
|
|
||||||
delete_swaps_for_block(db_session, block_number)
|
if should_write_swaps:
|
||||||
write_swaps(db_session, swaps)
|
delete_swaps_for_block(db_session, block_number)
|
||||||
|
write_swaps(db_session, swaps)
|
||||||
|
|
||||||
arbitrages = get_arbitrages(swaps)
|
arbitrages = get_arbitrages(swaps)
|
||||||
print(f"Found {len(arbitrages)} arbitrages")
|
click.echo(f"Found {len(arbitrages)} arbitrages")
|
||||||
|
|
||||||
delete_arbitrages_for_block(db_session, block_number)
|
if should_write_arbitrages:
|
||||||
write_arbitrages(db_session, arbitrages)
|
delete_arbitrages_for_block(db_session, block_number)
|
||||||
|
write_arbitrages(db_session, arbitrages)
|
||||||
|
|
||||||
db_session.close()
|
if should_print_stats:
|
||||||
|
stats = get_stats(classified_traces)
|
||||||
stats = get_stats(classified_traces)
|
click.echo(json.dumps(stats, indent=4))
|
||||||
print(json.dumps(stats, indent=4))
|
|
||||||
|
|
||||||
|
|
||||||
def get_stats(classified_traces) -> dict:
|
def get_stats(classified_traces) -> dict:
|
||||||
@ -83,4 +123,4 @@ def get_stats(classified_traces) -> dict:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
inspect_block()
|
cli()
|
||||||
|
@ -19,7 +19,31 @@ def inspect(block_number: str, rpc: str):
|
|||||||
"mev-inspect",
|
"mev-inspect",
|
||||||
"python",
|
"python",
|
||||||
"./scripts/inspect_block.py",
|
"./scripts/inspect_block.py",
|
||||||
|
"inspect-block",
|
||||||
block_number,
|
block_number,
|
||||||
rpc,
|
rpc,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.option("--after-block", type=str, help="look at blocks after this number")
|
||||||
|
@click.option("--before-block", type=str, help="look at blocks before this number")
|
||||||
|
@click.option(
|
||||||
|
"-r", "--rpc", help="rpc endpoint, this needs to have parity style traces"
|
||||||
|
)
|
||||||
|
def inspect_many(after_block: str, before_block: str, rpc: str):
|
||||||
|
check_call(
|
||||||
|
[
|
||||||
|
"docker",
|
||||||
|
"compose",
|
||||||
|
"exec",
|
||||||
|
"mev-inspect",
|
||||||
|
"python",
|
||||||
|
"./scripts/inspect_block.py",
|
||||||
|
"inspect-many-blocks",
|
||||||
|
after_block,
|
||||||
|
before_block,
|
||||||
|
rpc,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user