-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added a reliable flooder (#186)
- Loading branch information
Showing
5 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 &"]) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters