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

feat: added a reliable flooder #186

Merged
merged 18 commits into from
Sep 6, 2023
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,21 @@ This package also supports a `"mev_type": "mock"` mode that will only bring up:

For more details, including a guide and architecture of the `mev-boost` infrastructure, go [here](https://docs.kurtosis.com/how-to-full-mev-with-eth2-package).

## Pre-funded accounts at Genesis

This package builds on top of the [`eth-network-package`](https://github.com/kurtosis-tech/eth-network-package) and comes with [seven prefunded keys for testing](https://github.com/kurtosis-tech/eth-network-package/blob/main/src/prelaunch_data_generator/genesis_constants/genesis_constants.star).

Here's a table of where the keys are used

| Account Index| Component Used In | Private Key Used | Public Key Used | Comment |
|----------------|---------------------|------------------|-----------------|----------------------------|
| 0 | transaction_spammer | ✅ | | To spam transactions with |
| 0 | mev_flood | ✅ | | As the admin_key |
| 2 | mev_flood | ✅ | | As the user_key |
| 0 | mev_custom_flood | | ✅ | As the receiver of balance |
| 6 | mev_custom_flood | ✅ | | As the sender of balance |
| 1 | blob_spammer | ✅ | | As the sender of blobs |

## Developing On This Package

First, install prerequisites:
Expand Down
4 changes: 3 additions & 1 deletion main.star
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mev_boost_launcher_module = import_module("github.com/kurtosis-tech/eth2-package
mock_mev_launcher_module = import_module("github.com/kurtosis-tech/eth2-package/src/mock_mev/mock_mev_launcher.star")
mev_relay_launcher_module = import_module("github.com/kurtosis-tech/eth2-package/src/mev_relay/mev_relay_launcher.star")
mev_flood_module = import_module("github.com/kurtosis-tech/eth2-package/src/mev_flood/mev_flood_launcher.star")
mev_custom_flood_module = import_module("github.com/kurtosis-tech/eth2-package/src/mev_custom_flood/mev_custom_flood_launcher.star")

GRAFANA_USER = "admin"
GRAFANA_PASSWORD = "admin"
Expand Down Expand Up @@ -84,9 +85,10 @@ def run(plan, args):
plan.print("epoch 2 reached, can begin mev stuff")
endpoint = mev_relay_launcher_module.launch_mev_relay(plan, mev_params, network_params.network_id, beacon_uris, genesis_validators_root, builder_uri, network_params.seconds_per_slot)
mev_flood_module.spam_in_background(plan, el_uri, mev_params.mev_flood_extra_args, mev_params.mev_flood_seconds_per_bundle, genesis_constants.PRE_FUNDED_ACCOUNTS)
if args_with_right_defaults.mev_params.launch_custom_flood:
mev_custom_flood_module.spam_in_background(plan, genesis_constants.PRE_FUNDED_ACCOUNTS[-1].private_key, genesis_constants.PRE_FUNDED_ACCOUNTS[0].address, el_uri)
mev_endpoints.append(endpoint)


# spin up the mev boost contexts if some endpoints for relays have been passed
all_mevboost_contexts = []
if mev_endpoints:
Expand Down
31 changes: 31 additions & 0 deletions src/mev_custom_flood/mev_custom_flood_launcher.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
PYTHON_IMAGE = "python:3.11-alpine"
CUSTOM_FLOOD_SREVICE_NAME = "mev-custom-flood"

def spam_in_background(plan, sender_key, receiver_key, el_uri):
sender_script = plan.upload_files("github.com/kurtosis-tech/eth2-package/src/mev_custom_flood/sender.py")

plan.add_service(
name = CUSTOM_FLOOD_SREVICE_NAME,
config = ServiceConfig(
image = PYTHON_IMAGE,
files = {
"/tmp": sender_script
},
cmd = ["/bin/sh", "-c", "touch /tmp/sender.log && tail -f /tmp/sender.log"],
env_vars = {
"SENDER_PRIVATE_KEY": sender_key,
"RECEIVER_PUBLIC_KEY": receiver_key,
"EL_RPC_URI": el_uri,
}
)
)

plan.exec(
service_name = CUSTOM_FLOOD_SREVICE_NAME,
recipe = ExecRecipe(["pip", "install", "web3"])
)

plan.exec(
service_name = CUSTOM_FLOOD_SREVICE_NAME,
recipe = ExecRecipe(["/bin/sh", "-c", "nohup python /tmp/sender.py > /dev/null 2>&1 &"])
)
60 changes: 60 additions & 0 deletions src/mev_custom_flood/sender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
this is s a really dumb script that sends tokens to the receiver from the sender every 3 seconds
this is being used as of 2023-09-06 to guarantee that payloads are delivered
"""

from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
import os
import time
import logging

VALUE_TO_SEND = 0x9184

logging.basicConfig(filename="/tmp/sender.log",
filemode='a',
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
datefmt='%H:%M:%S',
level=logging.DEBUG)


def flood():
# this is the last prefunded address
sender = os.getenv("SENDER_PRIVATE_KEY", "17fdf89989597e8bcac6cdfcc001b6241c64cece2c358ffc818b72ca70f5e1ce")
h4ck3rk3y marked this conversation as resolved.
Show resolved Hide resolved
# this is the first prefunded address
receiver = os.getenv("RECEIVER_PUBLIC_KEY", "0x878705ba3f8Bc32FCf7F4CAa1A35E72AF65CF766")
el_uri = os.getenv("EL_RPC_URI", 'http://0.0.0.0:53913')

logging.info(f"Using sender {sender} receiver {receiver} and el_uri {el_uri}")

w3 = Web3(Web3.HTTPProvider(el_uri))

sender_account = w3.eth.account.from_key(sender)

while True:
time.sleep(3)

w3.middleware_onion.add(construct_sign_and_send_raw_middleware(sender_account))

transaction = {
"from": sender_account.address,
"value": VALUE_TO_SEND,
"to": receiver,
"data": "0xabcd",
"gasPrice": w3.eth.gas_price,
}

estimated_gas = w3.eth.estimate_gas(transaction)

transaction["gas"] = estimated_gas

tx_hash = w3.eth.send_transaction(transaction)

tx = w3.eth.get_transaction(tx_hash)
logging.info(tx_hash.hex())
assert tx["from"] == sender_account.address



if __name__ == "__main__":
flood()
5 changes: 4 additions & 1 deletion src/package_io/parse_input.star
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def parse_input(plan, input_args):
mev_builder_extra_args = result["mev_params"]["mev_builder_extra_args"],
mev_flood_image = result["mev_params"]["mev_flood_image"],
mev_flood_extra_args = result["mev_params"]["mev_flood_extra_args"],
mev_flood_seconds_per_bundle = result["mev_params"]["mev_flood_seconds_per_bundle"]
mev_flood_seconds_per_bundle = result["mev_params"]["mev_flood_seconds_per_bundle"],
launch_custom_flood = result["mev_params"]["launch_custom_flood"],
),
launch_additional_services=result["launch_additional_services"],
wait_for_finalization=result["wait_for_finalization"],
Expand Down Expand Up @@ -231,6 +232,8 @@ def get_default_mev_params():
"mev_flood_image": "flashbots/mev-flood",
"mev_flood_extra_args": [],
"mev_flood_seconds_per_bundle": 15,
# this is a simple script that increases the balance of the coinbase address at a cadence
"launch_custom_flood": False
}


Expand Down