Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geth additions2 #298

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
75ac0ea
geth additions
Oct 25, 2021
2f1d826
Readme updates
Oct 25, 2021
c841313
fixed lint issue
Oct 27, 2021
54bd2e6
Merge branch 'geth_additions' into main-gethmerge
supragya Nov 23, 2021
3fa8655
Merge pull request #1 from marlinprotocol/main-gethmerge
supragya Nov 23, 2021
8504ac5
updates for latest master
Nov 25, 2021
0895a0f
await getblock
Nov 25, 2021
d1a1a53
async middleware - geth poa
Dec 2, 2021
f705bb9
async middleware - geth poa
Dec 2, 2021
b31f5d7
added RPCType, fixes
Dec 9, 2021
6b6dd45
Merge branch 'main' into geth_additions
supragya Dec 9, 2021
935d0c9
added translation for create2, README updates, shell script updates
Dec 9, 2021
22d98af
Merge branch 'geth_additions' of https://github.com/marlinprotocol/me…
ZigaMr May 7, 2022
1873712
Geth additions
ZigaMr May 7, 2022
11ebac2
Testing workflow
ZigaMr May 7, 2022
b21ca9f
Fixed params order
ZigaMr May 7, 2022
253c8be
Changed await call for web3 get_block method
ZigaMr May 7, 2022
86b5fbb
Cleaned unused variables
ZigaMr May 7, 2022
a6b3919
Fixed parameters, added create2 Tracetype, miner address for geth
ZigaMr May 8, 2022
f18444e
Deleted import that was causing problems with logging
ZigaMr May 9, 2022
4b660e9
Used isort
ZigaMr May 9, 2022
19c80bd
Used black and pylint to reformat
ZigaMr May 9, 2022
4253928
Removed type parameter, now infers through trace_block call
ZigaMr May 22, 2022
011cb36
Removed additional unused type parameters
ZigaMr May 22, 2022
f1431ce
Removed unused import
ZigaMr May 22, 2022
ce047e1
Used black
ZigaMr May 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Example:
export RPC_URL="http://111.111.111.111:8546"
```

**Note**: mev-inspect-py currently requires an RPC of a full archive node with support for Erigon traces and receipts. Geth additions have been added to translate geth traces and receipts to Erigon ones and can be accessed using `--geth` flag.

Next, start all services with:

Expand All @@ -71,17 +72,19 @@ And load prices data
### Inspect a single block

Inspecting block [12914944](https://twitter.com/mevalphaleak/status/1420416437575901185):
**Note**: Add `geth` at the end instead of `parity` if RPC_URL points to a geth / geth like node.

```
./mev inspect 12914944
./mev inspect 12914944 parity
```

### Inspect many blocks

Inspecting blocks 12914944 to 12914954:
**Note**: Add `geth` at the end instead of `parity` if RPC_URL points to a geth / geth like node.

```
./mev inspect-many 12914944 12914954
./mev inspect-many 12914944 12914954 parity
```

### Inspect all incoming blocks
Expand Down
14 changes: 8 additions & 6 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ k8s_yaml(secret_from_dict("mev-inspect-db-credentials", inputs = {
"password": "password",
"host": "postgresql",
}))

# if using https://github.com/taarushv/trace-db
# k8s_yaml(secret_from_dict("trace-db-credentials", inputs = {
# "username" : "username",
Expand Down Expand Up @@ -79,6 +79,8 @@ k8s_resource(
resource_deps=["postgresql", "redis-master"],
)

# k8s_resource(workload='mev-inspect', port_forwards='8101')

k8s_resource(
workload="mev-inspect-workers",
resource_deps=["postgresql", "redis-master"],
Expand All @@ -102,17 +104,17 @@ local_resource(
# "export-aws-secret-access-key": "foobar",
#}))

#helm_remote(
# helm_remote(
# "localstack",
# repo_name="localstack-charts",
# repo_url="https://localstack.github.io/helm-charts",
#)
#
#local_resource(
# )

# local_resource(
# 'localstack-port-forward',
# serve_cmd='kubectl port-forward --namespace default svc/localstack 4566:4566',
# resource_deps=["localstack"]
#)
# )
#
#k8s_yaml(configmap_from_dict("mev-inspect-export", inputs = {
# "services": "s3",
Expand Down
33 changes: 27 additions & 6 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
inspect_many_blocks_task,
)
from mev_inspect.s3_export import export_block
from mev_inspect.utils import RPCType

RPC_URL_ENV = "RPC_URL"

Expand All @@ -35,12 +36,18 @@ def cli():
@cli.command()
@click.argument("block_number", type=int)
@click.option("--rpc", default=lambda: os.environ.get(RPC_URL_ENV, ""))
@click.option(
"--type",
type=click.Choice(list(map(lambda x: x.name, RPCType)), case_sensitive=False),
default=RPCType.parity.name,
)
@coro
async def inspect_block_command(block_number: int, rpc: str):
async def inspect_block_command(block_number: int, rpc: str, type: str):
type_e = convert_str_to_enum(type)
inspect_db_session = get_inspect_session()
trace_db_session = get_trace_session()

inspector = MEVInspector(rpc)
inspector = MEVInspector(rpc, type_e)

await inspector.inspect_single_block(
inspect_db_session=inspect_db_session,
Expand All @@ -49,26 +56,38 @@ async def inspect_block_command(block_number: int, rpc: str):
)


def convert_str_to_enum(type: str) -> RPCType:
if type == "parity":
return RPCType.parity
elif type == "geth":
return RPCType.geth
raise ValueError


@cli.command()
@click.argument("block_number", type=int)
@click.option("--rpc", default=lambda: os.environ.get(RPC_URL_ENV, ""))
@coro
async def fetch_block_command(block_number: int, rpc: str):
trace_db_session = get_trace_session()

inspector = MEVInspector(rpc)
inspector = MEVInspector(rpc, RPCType.parity)
block = await inspector.create_from_block(
block_number=block_number,
trace_db_session=trace_db_session,
)

print(block.json())


@cli.command()
@click.argument("after_block", type=int)
@click.argument("before_block", type=int)
@click.option("--rpc", default=lambda: os.environ.get(RPC_URL_ENV, ""))
@click.option(
"--type",
type=click.Choice(list(map(lambda x: x.name, RPCType)), case_sensitive=False),
default=RPCType.parity.name,
)
@click.option(
"--max-concurrency",
type=int,
Expand All @@ -85,12 +104,14 @@ async def inspect_many_blocks_command(
rpc: str,
max_concurrency: int,
request_timeout: int,
type: str,
):
type_e = convert_str_to_enum(type)
inspect_db_session = get_inspect_session()
trace_db_session = get_trace_session()

inspector = MEVInspector(
rpc,
rpc=rpc,
type=type_e,
max_concurrency=max_concurrency,
request_timeout=request_timeout,
)
Expand Down
25 changes: 23 additions & 2 deletions listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import dramatiq
from aiohttp_retry import ExponentialRetry, RetryClient
from web3 import HTTPProvider, Web3

from mev_inspect.block import get_latest_block_number
from mev_inspect.concurrency import coro
Expand All @@ -21,6 +22,7 @@
realtime_export_task,
)
from mev_inspect.signal_handler import GracefulKiller
from mev_inspect.utils import RPCType

logging.basicConfig(filename="listener.log", filemode="a", level=logging.INFO)
logger = logging.getLogger(__name__)
Expand All @@ -29,6 +31,14 @@
BLOCK_NUMBER_LAG = 5


def convert_str_to_enum(type: str) -> RPCType:
if type == "parity":
return RPCType.parity
elif type == "geth":
return RPCType.geth
raise ValueError


@coro
async def run():
rpc = os.getenv("RPC_URL")
Expand All @@ -52,8 +62,19 @@ async def run():
priority=HIGH_PRIORITY,
)

inspector = MEVInspector(rpc)
base_provider = get_base_provider(rpc)
w3 = Web3(HTTPProvider(rpc))
res = w3.provider.make_request("trace_block", ["earliest"])
if (
"error" in res
and res["error"]["message"]
== "the method trace_block does not exist/is not available"
):
type_e = RPCType.geth
else:
type_e = RPCType.parity
base_provider = get_base_provider(rpc, type=type_e)
# type_e = convert_str_to_enum(sys.argv[1])
inspector = MEVInspector(rpc, type_e)

while not killer.kill_now:
await inspect_next_block(
Expand Down
12 changes: 7 additions & 5 deletions mev
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ case "$1" in
;;
inspect)
block_number=$2
rpc_type=$3
echo "Inspecting block $block_number"
kubectl exec -ti deploy/mev-inspect -- poetry run inspect-block $block_number
kubectl exec -ti deploy/mev-inspect -- poetry run inspect-block $block_number --type $rpc_type
;;
inspect-many)
after_block_number=$2
before_block_number=$3
echo "Inspecting from block $after_block_number to $before_block_number"
start_block_number=$2
end_block_number=$3
rpc_type=$4
echo "Inspecting from block $start_block_number to $end_block_number"
kubectl exec -ti deploy/mev-inspect -- \
poetry run inspect-many-blocks $after_block_number $before_block_number
poetry run inspect-many-blocks $start_block_number $end_block_number --type $rpc_type
;;
test)
shift
Expand Down
Loading