-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtool_txspam.py
executable file
·84 lines (71 loc) · 2.29 KB
/
tool_txspam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
import argparse
import time
from web3 import Web3, exceptions
from utils import get_profile
from tx import send_transaction
from geth import get_chainid
ap = argparse.ArgumentParser()
ap.add_argument('-p', '--profile', help="Profile to use", default='default')
ap.add_argument(
'-f', '--flood', required=False, action='store_true', default=False,
help="Do NOT wait for tx to be mined",
)
ap.add_argument(
'-e', '--eth', required=False, default=5,
help="ETHs to fund sender account",
)
args = vars(ap.parse_args())
node_url, chain_id, funded_key, bridge_ep, bridge_addr, l1_ep, \
l1_funded_key, _ = \
get_profile(args['profile'])
chain_id = chain_id or get_chainid(node_url)
flood = bool(args['flood'])
sender = Web3().eth.account.create()
sender_addr = sender.address
sender_key = sender.key.hex()
send_transaction(
ep=node_url, sender_key=funded_key, receiver_address=sender_addr,
eth_amount=float(args['eth']), wait='all'
)
receiver_addr = sender_addr
w = Web3(Web3.HTTPProvider(node_url))
pending_nonce = w.eth.get_transaction_count(sender_addr, 'pending')
latest_nonce = w.eth.get_transaction_count(sender_addr, 'latest')
gas_price = w.eth.gas_price
vers = w.client_version
print(
f"Endpoint {node_url} ({vers}) | chaind {chain_id} | "
f"block: {w.eth.block_number}"
)
print(
f"Sender {sender_addr}: pending_nonce={pending_nonce} "
f"latest_nonce={latest_nonce}, Gas_Price={gas_price}")
nonce = pending_nonce
counter = 0
while True:
tx = {
'chainId': chain_id,
'nonce': nonce,
'to': receiver_addr,
'value': w.to_wei(0, 'ether'),
'gas': 21000,
'gasPrice': gas_price,
}
signed_tx = w.eth.account.sign_transaction(tx, sender_key)
tx_hash = w.eth.send_raw_transaction(signed_tx.raw_transaction)
counter += 1
nonce += 1
print(f"tx_count={counter} tx_hash={tx_hash.hex()}")
if flood:
continue
start = time.time()
r = None
while (not r):
try:
r = w.eth.wait_for_transaction_receipt(tx_hash, timeout=5)
except exceptions.TimeExhausted:
elapsed = int(time.time() - start)
print(f"No receipt after {elapsed}s. Retrying...")
elapsed = int(time.time() - start)
print(f"Got confirmation after {elapsed}s")