diff --git a/.gitignore b/.gitignore index bee8a64..b0f2192 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__ +.venv \ No newline at end of file diff --git a/erc20_account_addresses b/erc20_account_addresses deleted file mode 100644 index e359c24..0000000 --- a/erc20_account_addresses +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:fe9926980633e889850051421de6fb72876177e63cd615e1084f4f64080f45e3 -size 93894269 diff --git a/erc20_token_addresses b/erc20_token_addresses deleted file mode 100644 index 3a425c0..0000000 --- a/erc20_token_addresses +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:42eb883695b6d955fd40177bcf57d3f96f865deb33812a737e5f4487c0a97300 -size 3627609 diff --git a/locust-test.py b/locust-test.py deleted file mode 100644 index 41df82e..0000000 --- a/locust-test.py +++ /dev/null @@ -1,150 +0,0 @@ -from locust import HttpLocust, TaskSet, task -import requests -import json -import random -import argparse -import sys -import os -import time - -headers = { - 'Content-Type': 'application/json', -} -data={"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1} -response = requests.post(os.environ.get("BASE_RPC_SERVER", "https://eth.rpc.rivet.cloud/10f2a3dbcaa44fd998184ffbb8336f43"), headers=headers, json=data) - -print(response.content) -latestBlock=int(response.json().get('result'),16) -account_addresses = open("erc20_account_addresses").readlines() -token_addresses = open("erc20_token_addresses").readlines() - -if os.environ.get("BASE_RPC_SERVER"): - def run_request(l, data, name): - baseserv=os.environ.get("BASE_RPC_SERVER") - # data["id"] = random.randint(0, sys.maxsize) - result = l.client.post("", name=name, json=data, catch_response=True) - base_res=requests.post(os.environ.get("BASE_RPC_SERVER"), json=data) - try: - response = json.loads(result.content) - base_response = json.loads(base_res.content) - - except json.decoder.JSONDecodeError: - print(data) - result.failure("Invalid JSON") - if response != base_response: - if name != "eth_blockNumber": - result.failure("Nonmatched Response:\nGot: %s \nexpected: %s" % (response,base_response)) - else: - result.failure("DifferenceResponse: %d" % (int(response['result'], 16) - int(base_response['result'], 16))) - else: result.success() - - if name != "eth_blockNumber": - old_result = requests.post(os.environ.get("BASE_RPC_SERVER"), json=data) - for x in range(1,5): - try: - old_response = json.loads(old_result.content) - except: - print("breaking try 1") - old_result = requests.post(os.environ.get("BASE_RPC_SERVER"), json=data) - break - try: - result=l.client.post("", name="%s_consistency" % name, json=data, catch_response=True) - response = json.loads(result.content) - except: - print("breaking try2") - result.failure("Invalid JSON") - break - if response != old_response: - result.failure("DifferenceResponse: %d" % (int(response['result'], 16) - int(base_response['result'], 16))) - else: result.success() - - return result -else: - def run_request(l, data, name): - data["id"] = random.randint(0, sys.maxsize) - result = l.client.post("", name=name, json=data, catch_response=True) - try: - response = json.loads(result.content) - except json.decoder.JSONDecodeError: - print(data) - result.failure("Invalid JSON") - else: - if response.get("error", False): - # print(data) - result.failure("Payload error: %s" % response.get("error")) - elif response.get("id") != data["id"]: - # print(data) - # print(response) - # print(response.get("id"),data["id"]) - # print(type(response.get("id")),type(data["id"])) - result.failure("Mismatched IDs") - else: result.success() - return result -def rand_block(): - return random.randint(1024,latestBlock) -@task(200) -def get_block(l): - run_request(l, {"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}, name="eth_blockNumber") - -@task(1) -def mempool_test(l): - result = l.client.post("", json={"jsonrpc":"2.0","method":"eth_newPendingTransactionFilter","params":[],"id":73}) - subscriptionId = result.json()["result"] - for i in range(10): - changes = l.client.post("", json={"jsonrpc":"2.0","method":"eth_getFilterChanges","params":[subscriptionId],"id":73}) - if changes.json().get("result"): - l.client.post("", json={"jsonrpc":"2.0","method":"eth_uninstallFilter","params":[subscriptionId],"id":73}) - txHash = random.choice(changes.json()["result"]) - hashData = l.client.post("", json={"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":[txHash],"id":73},name="eth_getTransactionByHash", catch_response=True) - if hashData.json().get("result", {}).get("hash") == txHash: - hashData.success() - else: - hashData.failure("Hash mismatch: %s" % hashData.content) - else: - time.sleep(.2) - - -@task(1) -def heavy_request(l): - account_address1=random.choice(account_addresses) - account_address2=random.choice(account_addresses) - token_address=random.choice(token_addresses) - block_num=rand_block() - block_hex=hex(block_num) - data = {"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":[block_hex, True],"id":1} - response = run_request(l, data, name="eth_getBlockByNumber") - block_hash=response.json().get('result')['hash'] - data = {"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params":[block_hash, "0x0"],"id":1} - response = run_request(l, data, name="eth_getTransactionByBlockHashAndIndex") - data = {"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":[block_hex, True],"id":1} - run_request(l, data, name="eth_getBlockByNumber") - data = {"jsonrpc":"2.0","method":"eth_getBlockByHash","params":[block_hash, False],"id":1} - run_request(l, data, name="eth_getBlockByHash") - data = {"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByHash","params":[block_hash],"id":1} - run_request(l, data, name="eth_getBlockTransactionCountByHash") - data = {"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params":[block_hash, "0x0"],"id":1} - run_request(l, data, name="eth_getTransactionByBlockHashAndIndex") - data = {"jsonrpc":"2.0","method":"eth_call","params":[{"to": token_address.strip(), "data": f"0x70a08231000000000000000000000000{account_address1.strip()[2:]}"}, "latest"],"id":1} - run_request(l, data, name="eth_call1") - data = {"jsonrpc":"2.0","method":"eth_call","params":[{"to": token_address.strip(), "data": "0x18160ddd"}, "latest"],"id":1} - run_request(l, data, name="eth_call2") - data = {"jsonrpc":"2.0","method":"eth_call","params":[{"to": token_address.strip(), "data": f"0xdd62ed3e000000000000000000000000{account_address1.strip()[2:]}000000000000000000000000{account_address2.strip()[2:]}"}, "latest"],"id":1} - run_request(l, data, name="eth_call3") - data = {"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"to": token_address.strip(), "data": f"0x70a08231000000000000000000000000{account_address1.strip()[2:]}"}],"id":1} - run_request(l, data, name="eth_estimateGas1") - data = {"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"to": token_address.strip(), "data": "0x18160ddd"}],"id":1} - run_request(l, data, name="eth_estimateGas2") - data = {"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"to": token_address.strip(), "data": f"0xdd62ed3e000000000000000000000000{account_address1.strip()[2:]}000000000000000000000000{account_address2.strip()[2:]}"}],"id":1} - run_request(l, data, name="eth_estimateGas3") - data = {"jsonrpc":"2.0","method":"eth_getBalance","params":['0x'+account_address1.strip()[-40:], "latest"],"id":1} - run_request(l, data, name="eth_getBalance") - data = {"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1} - run_request(l, data, name="eth_gasPrice") - data = {"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByNumber","params":[block_hex],"id":1} - run_request(l, data, name="eth_getBlockTransactionCountByNumber") -class RunTest(TaskSet): - tasks = {get_block: 200, heavy_request: 1, mempool_test: 1} -class WebsiteUser(HttpLocust): - task_set = RunTest - min_wait = 50 - max_wait = 100 diff --git a/mainnet-flume-archive.py b/mainnet-flume-archive.py index 8e36316..5e19919 100644 --- a/mainnet-flume-archive.py +++ b/mainnet-flume-archive.py @@ -2,7 +2,8 @@ import requests import json import random -import sys +import sys, os, shutil +import argparse from weights import * headers = { @@ -13,6 +14,17 @@ block_number = response.json().get('result')['number'] block_hash = response.json().get('result')['hash'] +parser = argparse.ArgumentParser() +parser.add_argument("--blocknumber", type=int, required=True, help="separates light and heavy ranges") +args, unknown = parser.parse_known_args() +sys.argv = [sys.argv[0]] + unknown + +cutoff_block = args.blocknumber + +if os.path.exists("results"): + shutil.rmtree("results") +os.makedirs("results") + # print(response.content) latestBlock=int(block_number,16) @@ -43,17 +55,12 @@ def rand_light_block(): return random.randint((latestBlock - 1024),latestBlock) def rand_heavy_block(): - return random.randint(1000000, latestBlock) - -def rand_archive_block(): - return random.randint(0, 1000000) - + return random.randint(cutoff_block, latestBlock) weight_object = get_weight_object() light_coefficient = 9 heavy_coefficient = 1 -archive_coefficient = 1 class WebsiteUser(HttpUser): def __init__(self, *args, **kwargs): @@ -73,14 +80,6 @@ def __init__(self, *args, **kwargs): self.heavy_block_hash = block_hash self.heavy_64block_hash = "" - self.archive_session_tx_hashes = [*tx_hashes] - self.archive_session_senders = [] - self.archive_session_recipients = [] - self.archive_block_num = latestBlock - self.archive_block_hex = block_number - self.archive_block_hash = block_hash - self.archive_64block_hash = "" - super(WebsiteUser, self).__init__(*args, **kwargs) ## flume standard eth methods @@ -246,90 +245,6 @@ def light_transactionReceiptsByBlockHash(self): data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_block_hash], "id":random.randint(0, 9999)} response = run_request(self, data, name=f"light_{method}") - # # Polygon bor namespace methods - - # # @task(weight=weight_object["bor_getSnapshot"] * light_coefficient) - # @task(weight=2000) - # def light_snapshot(self): - # method = "bor_getSnapshot" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_block_hex], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method} block") - - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method} hash") - - # # @task(weight=weight_object["bor_getAuthor"] * light_coefficient) - # @task(weight=2000) - # def light_author(self): - # method = "bor_getAuthor" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_block_hex], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method}") - - # # @task(weight=weight_object["bor_getRootHash"] * light_coefficient) - # @task(weight=2000) - # def light_rootHash(self): - # method = "bor_getRootHash" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","params":[(self.light_block_num - random.randint(0, 1000)), self.light_block_num], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method}") - - # @task(weight=weight_object["bor_getSignersAtHash"] * light_coefficient) - # @task(weight=2000) - # def light_signersAtHash(self): - # method = "bor_getSignersAtHash" - # print(method) - - # if len(self.light_64block_hash) > 0: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_64block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method}") - # else: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method} error") - - # # @task(weight=weight_object["bor_getCurrentValidators"] * light_coefficient) - # @task(weight=2000) - # def light_currentValidators(self): - # method = "bor_getCurrentValidators" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method}") - - # # @task(weight=weight_object["bor_getCurrentProposer"] * light_coefficient) - # @task(weight=2000) - # def light_currentProposer(self): - # method = "bor_getCurrentProposer" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method}") - - # # # Polygon eth namespace methods - - # # @task(weight=weight_object["eth_getBorBlockReceipt"] * light_coefficient) - # @task(weight=2000) - # def light_borBlockReceipt(self): - # method = "eth_getBorBlockReceipt" - # print(method) - # if len(self.light_64block_hash) > 0: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_64block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method}") - # else: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method} error") - - # # @task(weight=weight_object["eth_getTransactionReceiptsByBlock"] * light_coefficient) - # @task(weight=2000) - # def light_transactionReceiptsByBlock(self): - # method = "eth_getTransactionReceiptsByBlock" - # print(method) - - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_block_hex], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method} block") - - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.light_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"light_{method} hash") - # Heavy calls @task(weight=weight_object["eth_getBlockByNumber"] * heavy_coefficient) @@ -534,380 +449,4 @@ def heavy_eRC20Holders(self): method = "flume_erc20Holders" print(method) data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(account_addresses)], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"heavy_{method}") - - # # # Polygon bor namespace methods - - # # @task(weight=weight_object["bor_getSnapshot"] * heavy_coefficient) - # @task(weight=2000) - # def heavy_snapshot(self): - # method = "bor_getSnapshot" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.heavy_block_hex], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method} block") - - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.heavy_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method} hash") - - # # @task(weight=weight_object["bor_getAuthor"] * heavy_coefficient) - # @task(weight=2000) - # def heavy_author(self): - # method = "bor_getAuthor" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.heavy_block_hex], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method}") - - # # @task(weight=weight_object["bor_getRootHash"] * heavy_coefficient) - # @task(weight=2000) - # def heavy_rootHash(self): - # method = "bor_getRootHash" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","params":[(self.heavy_block_num - random.randint(0, 1000)), self.heavy_block_num], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method}") - - # @task(weight=weight_object["bor_getSignersAtHash"] * heavy_coefficient) - # @task(weight=2000) - # def heavy_getSignersAtHash(self): - # method = "bor_getSignersAtHash" - # print(method) - - # if len(self.heavy_64block_hash) > 0: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.heavy_64block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method}") - # else: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.heavy_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method} error") - - # # @task(weight=weight_object["bor_getCurrentValidators"] * heavy_coefficient) - # @task(weight=2000) - # def heavy_currentValidators(self): - # method = "bor_getCurrentValidators" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method}") - - # # @task(weight=weight_object["bor_getCurrentProposer"] * heavy_coefficient) - # @task(weight=2000) - # def heavy_currentProposer(self): - # method = "bor_getCurrentProposer" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method}") - - # # # Polygon eth namespace methods - - # # @task(weight=weight_object["eth_getBorBlockReceipt"] * heavy_coefficient) - # @task(weight=2000) - # def heavy_borBlockReceipt(self): - # method = "eth_getBorBlockReceipt" - # print(method) - - # if len(self.heavy_64block_hash) > 0: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.heavy_64block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method}") - # else: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.heavy_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method} error") - - # # @task(weight=weight_object["eth_getTransactionReceiptsByBlock"] * heavy_coefficient) - # @task(weight=2000) - # def heavy_transactionReceiptsByBlock(self): - # method = "eth_getTransactionReceiptsByBlock" - # print(method) - - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.heavy_block_hex], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method} block") - - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.heavy_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"heavy_{method} hash") - -# archive calls - - @task(weight=weight_object["eth_getBlockByNumber"] * archive_coefficient) - @task(1000) - def archive_blockByNumber(self): - method = "eth_getBlockByNumber" - print(method) - self.archive_block_num=rand_archive_block() - self.archive_block_hex=hex(self.archive_block_num) - data = {"jsonrpc":"2.0","method":f"{method}","params":[self.archive_block_hex, True],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - if self.archive_block_num % 64 == 0: - self.archive_65block_hash = response.json().get('result')['hash'] - else: - self.archive_block_hash = response.json().get('result')['hash'] - self.archive_block_hash = response.json().get('result')['hash'] - transaction_hashes = [tx['hash'] for tx in response.json().get('result')['transactions']] - recepients = [tx['to'] for tx in response.json().get('result')['transactions']] - senders = [tx['from'] for tx in response.json().get('result')['transactions']] - self.archive_session_tx_hashes.extend(transaction_hashes) - self.archive_session_recipients.extend(recepients) - self.archive_session_senders.extend(senders) - - @task(weight=weight_object["eth_getBlockByHash"] * archive_coefficient) - def archive_blockByHash(self): - method = "eth_getBlockByHash" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hash, True],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["eth_getLogs"] * archive_coefficient) - def archive_getLogs(self): - method = "eth_getLogs" - print(method + "heavy var 1") - data = {"jsonrpc":"2.0", "method": "eth_getLogs", "params": [{"fromBlock": hex(self.archive_block_num - random.randint(0, 3)), "toBlock": hex(self.archive_block_num), "address": random.choice(token_addresses), "topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method} v1") - - @task(weight=weight_object["eth_getLogs"] * archive_coefficient) - def light_getLogs(self): - method = "eth_getLogs" - print(method + "heavy var 2") - data = {"jsonrpc":"2.0", "method": "eth_getLogs", "params": [{"fromBlock": hex(self.archive_block_num), "toBlock": hex(self.archive_block_num)}],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method} v2") - - @task(weight=weight_object["eth_getLogs"] * archive_coefficient) - def light_getLogs(self): - method = "eth_getLogs" - print(method + "heavy var 3") - data = {"jsonrpc":"2.0", "method": "eth_getLogs", "params": [{"fromBlock": hex(self.archive_block_num), "toBlock": hex(self.archive_block_num + 1)}],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method} v3") - - @task(weight=weight_object["eth_getTransactionByHash"] * archive_coefficient) - def archive_transactionByHash(self): - method = "eth_getTransactionByHash" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(self.archive_session_tx_hashes)],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - data = {"jsonrpc":"2.0", "method": "eth_getTransactionByHash", "params": [random.choice(tx_hash_misses)]} - response = run_request(self, data, name="light_eth_getTransactionByHash (miss)") - - @task(weight=weight_object["eth_getBlockTransactionCountByNumber"] * archive_coefficient) - def archive_blockTransactionCountByNumber(self): - print(len(self.archive_transaction_hashes)) - method = "eth_getBlockTransactionCountByNumber" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hex],"id":random.randint(0, 9999)} - print(self.archive_block_hex) - response = run_request(self, data, name=f"archive_{method}") - self.archive_txcount_and_number = (self.archive_block_hex, int(response.json().get("result", "0x0"), 16)) - - @task(weight=weight_object["eth_getBlockTransactionCountByHash"] * archive_coefficient) - def archive_blockTransactionCountByHash(self): - print(len(self.archive_transaction_hashes)) - method = "eth_getBlockTransactionCountByHash" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hash],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - self.archive_txcount_and_hash = (self.archive_block_hash, int(response.json().get("result", "0x0"), 16)) - - @task(weight=weight_object["eth_getTransactionReceipt"] * archive_coefficient) - def archive_transactionReceipt(self): - method = "eth_getTransactionReceipt" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(self.archive_session_tx_hashes)],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - data = {"jsonrpc":"2.0", "method": "eth_getTransactionReceipt", "params": [random.choice(tx_hash_misses)]} - response = run_request(self, data, name="light_eth_getTransactionReceipt (miss)") - - @task(weight=weight_object["eth_getTransactionCount"] * archive_coefficient) - def archive_transactionCount(self): - method = "eth_getTransactionCount" - if self.archive_session_recipients + self.archive_session_senders: - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(self.archive_session_recipients + self.archive_session_senders), self.archive_block_hex],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["eth_getUncleCountByBlockNumber"] * archive_coefficient) - def archive_uncleCountByBlockNumber(self): - method = "eth_getUncleCountByBlockNumber" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hex],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["eth_getUncleCountByBlockHash"] * archive_coefficient) - def archive_uncleCountByBlockHash(self): - method = "eth_getUncleCountByBlockHash" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hash],"id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["eth_gasPrice"] * archive_coefficient) - def archive_gasPrice(self): - method = "eth_gasPrice" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["eth_maxPriorityFeePerGas"] * archive_coefficient) - def archive_maxPriorityFeePerGas(self): - method = "eth_maxPriorityFeePerGas" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["eth_feeHistory"] * archive_coefficient) - def archive_feeHistory(self): - method = "eth_feeHistory" - print(method) ## TODO float params - data = {"jsonrpc":"2.0","method": f"{method}","params":[hex(random.randint(0, 10)), self.archive_block_hex, sorted([random.random(), random.random(), random.random()])], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - ## flume name space methods - - @task(weight=weight_object["flume_getTransactionsBySender"] * archive_coefficient) ## default heavy - def archive_transactionsBySender(self): - method = "flume_getTransactionsBySender" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(self.archive_session_senders)], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["flume_getTransactionsByRecipient"] * archive_coefficient) ## default heavy - def archive_transactionsByRecipient(self): - method = "flume_getTransactionsByRecipient" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(self.archive_session_recipients)], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["flume_getTransactionsByParticipant"] * archive_coefficient) ## default heavy - def archive_transactionsByParticipant(self): - method = "flume_getTransactionsByParticipant" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(account_addresses)], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["flume_getTransactionReceiptsBySender"] * archive_coefficient) ## default heavy - def archive_transactionReceiptsBySender(self): - method = "flume_getTransactionReceiptsBySender" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(self.archive_session_senders)], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["flume_getTransactionReceiptsByRecipient"] * archive_coefficient) ## default heavy - def archive_transactionReceiptsByRecipient(self): - method = "flume_getTransactionReceiptsByRecipient" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(self.archive_session_recipients)], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["flume_getTransactionReceiptsByParticipant"] * archive_coefficient) ## default heavy - def archive_transactionReceiptsByParticipant(self): - method = "flume_getTransactionReceiptsByParticipant" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(account_addresses)], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - - @task(weight=weight_object["flume_getTransactionReceiptsByBlockNumber"] * archive_coefficient) - def archive_transactionReceiptsByBlockNumber(self): - method = "flume_getTransactionReceiptsByBlockNumber" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hex], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["flume_getTransactionReceiptsByBlockHash"] * archive_coefficient) - def archive_transactionReceiptsByBlockHash(self): - method = "flume_getTransactionReceiptsByBlockHash" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hash], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["flume_erc20ByAccount"] * archive_coefficient) ## default heavy - def archive_eRC20ByAccount(self): - method = "flume_erc20ByAccount" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(account_addresses)], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - @task(weight=weight_object["flume_erc20Holders"] * archive_coefficient) ## default heavy - def archive_eRC20Holders(self): - method = "flume_erc20Holders" - print(method) - data = {"jsonrpc":"2.0","method": f"{method}","params":[random.choice(account_addresses)], "id":random.randint(0, 9999)} - response = run_request(self, data, name=f"archive_{method}") - - # # # Polygon bor namespace methods - - # # @task(weight=weight_object["bor_getSnapshot"] * archive_coefficient) - # @task(weight=2000) - # def archive_snapshot(self): - # method = "bor_getSnapshot" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hex], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method} block") - - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method} hash") - - # # @task(weight=weight_object["bor_getAuthor"] * archive_coefficient) - # @task(weight=2000) - # def archive_author(self): - # method = "bor_getAuthor" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hex], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method}") - - # # @task(weight=weight_object["bor_getRootHash"] * archive_coefficient) - # @task(weight=2000) - # def archive_rootHash(self): - # method = "bor_getRootHash" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","params":[(self.archive_block_num - random.randint(0, 1000)), self.archive_block_num], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method}") - - # @task(weight=weight_object["bor_getSignersAtHash"] * archive_coefficient) - # @task(weight=2000) - # def archive_getSignersAtHash(self): - # method = "bor_getSignersAtHash" - # print(method) - - # if len(self.archive_64block_hash) > 0: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_64block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method}") - # else: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method} error") - - # # @task(weight=weight_object["bor_getCurrentValidators"] * archive_coefficient) - # @task(weight=2000) - # def archive_currentValidators(self): - # method = "bor_getCurrentValidators" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method}") - - # # @task(weight=weight_object["bor_getCurrentProposer"] * archive_coefficient) - # @task(weight=2000) - # def archive_currentProposer(self): - # method = "bor_getCurrentProposer" - # print(method) - # data = {"jsonrpc":"2.0","method": f"{method}","id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method}") - - # # # Polygon eth namespace methods - - # # @task(weight=weight_object["eth_getBorBlockReceipt"] * archive_coefficient) - # @task(weight=2000) - # def archive_borBlockReceipt(self): - # method = "eth_getBorBlockReceipt" - # print(method) - - # if len(self.archive_64block_hash) > 0: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_64block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method}") - # else: - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method} error") - - # # @task(weight=weight_object["eth_getTransactionReceiptsByBlock"] * archive_coefficient) - # @task(weight=2000) - # def archive_transactionReceiptsByBlock(self): - # method = "eth_getTransactionReceiptsByBlock" - # print(method) - - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hex], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method} block") - - # data = {"jsonrpc":"2.0","method": f"{method}","params":[self.archive_block_hash], "id":random.randint(0, 9999)} - # response = run_request(self, data, name=f"archive_{method} hash") + response = run_request(self, data, name=f"heavy_{method}") \ No newline at end of file diff --git a/original.sh b/original.sh deleted file mode 100644 index d50fc5d..0000000 --- a/original.sh +++ /dev/null @@ -1,54 +0,0 @@ -#Do a ton of this -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":64}' - -#ER20 balanceOf - We'll need to mix this up -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to": "0xdde19c145c1ee51b48f7a28e8df125da0cc440be", "data": "0x70a08231000000000000000000000000aa934f0f7dc2f6b1a081839ab8a3b929d092356c"}, "latest"],"id":64}' https://mainnet.ethercattle.openrelay.xyz - -#ERC20 totalSupply - We'll want to vary target ERC20 address -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to": "0xdde19c145c1ee51b48f7a28e8df125da0cc440be", "data": "0x18160ddd"}, "latest"],"id":64}' https://mainnet.ethercattle.openrelay.xyz - -#ERC20 allowance(owner, spender) - We'll need to mix this up -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to": "0xdde19c145c1ee51b48f7a28e8df125da0cc440be", "data": "0xdd62ed3e000000000000000000000000aa934f0f7dc2f6b1a081839ab8a3b929d092356c000000000000000000000000258dd1b12d0e6f3e4010a1c6a80ff231536b1005"}, "latest"],"id":64}' https://mainnet.ethercattle.openrelay.xyz - -#ER20 balanceOf - We'll need to mix this up -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"to": "0xdde19c145c1ee51b48f7a28e8df125da0cc440be", "data": "0x70a08231000000000000000000000000aa934f0f7dc2f6b1a081839ab8a3b929d092356c"}],"id":64}' https://mainnet.ethercattle.openrelay.xyz - -#ERC20 totalSupply - We'll want to vary target ERC20 address -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"to": "0xdde19c145c1ee51b48f7a28e8df125da0cc440be", "data": "0x18160ddd"}],"id":64}' https://mainnet.ethercattle.openrelay.xyz - -#ERC20 allowance(owner, spender) - We'll need to mix this up -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"to": "0xdde19c145c1ee51b48f7a28e8df125da0cc440be", "data": "0xdd62ed3e000000000000000000000000aa934f0f7dc2f6b1a081839ab8a3b929d092356c000000000000000000000000258dd1b12d0e6f3e4010a1c6a80ff231536b1005"}],"id":64}' https://mainnet.ethercattle.openrelay.xyz - -#I'll provide a huge list of addresses to vary the address -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xD224cA0c819e8E97ba0136B3b95ceFf503B79f53", "latest"],"id":64}' https://goerli-rpc.openrelay.xyz -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":64}' https://goerli-rpc.openrelay.xyz - -#We'll need to vary the block number -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x1b4", true],"id":64}' https://goerli-rpc.openrelay.xyz - -#We'll need to vary the block number -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0xb0550d9b3033c5bc04407af24af13f943d5636e3674e1e93855219a6fe2ed885", false],"id":64}' https://goerli-rpc.openrelay.xyz - -#We'll need to vary the block hash, maybe following the previous request -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByHash","params":["0xb0550d9b3033c5bc04407af24af13f943d5636e3674e1e93855219a6fe2ed885"],"id":64}' https://goerli-rpc.openrelay.xyz - -#Vary block number -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByNumber","params":["0x25a99"],"id":64}' https://goerli-rpc.openrelay.xyz - -#Change block ranges, get a list of topics -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"], "fromBlock": "latest", "toBlock":"latest"}],"id":74}' https://mainnet.ethercattle.openrelay.xyz - -#Change block ranges, get a list of topics NOT PROVIDED -# curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorage","params":["0xdde19c145c1eE51B48f7a28e8dF125da0Cc440be", "0x0"],"id":74}' https://mainnet.ethercattle.openrelay.xyz - -#Vary block hash and index number -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params":["0x324e6083db2899e9a55c77e519a89c76a86ed4edcdf79517c8bf4d1e58793c77", "0x0"],"id":64}' https://goerli-rpc.openrelay.xyz - -#Maybe use tx hash from previous request -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x723e3c355d6c3a3f2eb36f47df6a1a31b724fb0ca5ce9abc8a584c457554f15b"],"id":64}' https://goerli-rpc.openrelay.xyz - -#Maybe use tx hash from previous request -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0x723e3c355d6c3a3f2eb36f47df6a1a31b724fb0ca5ce9abc8a584c457554f15b"],"id":64}' https://goerli-rpc.openrelay.xyz - -#Maybe use tx hash from previous request -curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["0x2b371c0262CEAb27fAcE32FBB5270dDc6Aa01ba4","latest"],"id":64}' https://goerli-rpc.openrelay.xyz diff --git a/results/result_exceptions.csv b/results/result_exceptions.csv new file mode 100644 index 0000000..5e0e870 --- /dev/null +++ b/results/result_exceptions.csv @@ -0,0 +1 @@ +Count,Message,Traceback,Nodes diff --git a/results/result_failures.csv b/results/result_failures.csv new file mode 100644 index 0000000..f87ff75 --- /dev/null +++ b/results/result_failures.csv @@ -0,0 +1 @@ +Method,Name,Error,Occurrences diff --git a/results/result_stats.csv b/results/result_stats.csv new file mode 100644 index 0000000..a5347c9 --- /dev/null +++ b/results/result_stats.csv @@ -0,0 +1,18 @@ +Type,Name,Request Count,Failure Count,Median Response Time,Average Response Time,Min Response Time,Max Response Time,Average Content Size,Requests/s,Failures/s,50%,66%,75%,80%,90%,95%,98%,99%,99.9%,99.99%,100% +POST,heavy_eth_gasPrice,1,0,333.3564589265734,333.3564589265734,333.3564589265734,333.3564589265734,64.0,0.11096465931225893,0.0,330,330,330,330,330,330,330,330,330,330,330 +POST,heavy_eth_getBlockByHash,1,0,898.1200420530513,898.1200420530513,898.1200420530513,898.1200420530513,412059.0,0.11096465931225893,0.0,900,900,900,900,900,900,900,900,900,900,900 +POST,heavy_eth_getBlockByNumber,2,0,550.0,1169.3195420084521,547.1160840243101,1791.5229999925941,166534.0,0.22192931862451787,0.0,1800,1800,1800,1800,1800,1800,1800,1800,1800,1800,1800 +POST,heavy_eth_getLogs v3,2,0,894.0710840979591,895.6745835603215,894.0710840979591,897.2780830226839,871107.0,0.22192931862451787,0.0,900,900,900,900,900,900,900,900,900,900,900 +POST,heavy_eth_getTransactionByHash,10,0,280.0,285.87862089043483,259.07583301886916,316.8717089574784,56.7,1.1096465931225894,0.0,280,290,310,310,320,320,320,320,320,320,320 +POST,heavy_eth_getTransactionReceipt,2,0,270.0,269.89164599217474,267.82599999569356,271.9572919886559,57.0,0.22192931862451787,0.0,270,270,270,270,270,270,270,270,270,270,270 +POST,light_eth_blockNumber,7,0,310.0,312.3900297131123,272.14995794929564,347.52449998632073,62.857142857142854,0.7767526151858125,0.0,310,340,340,340,350,350,350,350,350,350,350 +POST,light_eth_chainId,28,0,280.0,321.6994642778965,260.07025002036244,1215.5159579124302,62.785714285714285,3.10701046074325,0.0,280,300,310,310,330,330,1200,1200,1200,1200,1200 +POST,light_eth_gasPrice,2,0,300.5647499812767,334.7827914985828,300.5647499812767,369.00083301588893,64.0,0.22192931862451787,0.0,370,370,370,370,370,370,370,370,370,370,370 +POST,light_eth_getBlockByHash,4,0,330.0,531.3142294762656,308.83745895698667,909.9725419655442,456869.5,0.44385863724903574,0.0,580,580,910,910,910,910,910,910,910,910,910 +POST,light_eth_getBlockByNumber,2,0,310.0,592.7154369419441,306.7217079224065,878.7091659614816,665125.0,0.22192931862451787,0.0,880,880,880,880,880,880,880,880,880,880,880 +POST,light_eth_getTransactionByHash,73,0,280.0,359.2352443294957,252.82558402977884,1189.648124971427,56.945205479452056,8.100420129794902,0.0,280,300,310,310,320,1200,1200,1200,1200,1200,1200 +POST,light_eth_getTransactionByHash (miss),79,0,280.0,286.6122626192585,254.7728749923408,354.62108300998807,56.88607594936709,8.766208085668456,0.0,280,290,290,300,310,330,350,350,350,350,350 +POST,light_eth_getTransactionReceipt,24,0,270.0,356.7971405524683,256.2187919393182,1218.4438749682158,148.45833333333334,2.663151823494214,0.0,270,290,290,300,330,1200,1200,1200,1200,1200,1200 +POST,light_eth_getTransactionReceipt (miss),26,0,270.0,278.20776766972045,245.04283303394914,308.90070903114974,56.92307692307692,2.8850811421187323,0.0,280,290,290,290,300,300,310,310,310,310,310 +POST,light_eth_getUncleCountByBlockHash,1,0,285.6450410326943,285.6450410326943,285.6450410326943,285.6450410326943,58.0,0.11096465931225893,0.0,290,290,290,290,290,290,290,290,290,290,290 +,Aggregated,264,0,280.0,336.6792530009248,245.04283303394914,1791.5229999925941,21446.560606060608,29.294670058436356,0.0,290,290,300,310,330,890,1200,1200,1800,1800,1800 diff --git a/results/result_stats_history.csv b/results/result_stats_history.csv new file mode 100644 index 0000000..76c9ac7 --- /dev/null +++ b/results/result_stats_history.csv @@ -0,0 +1,7 @@ +Timestamp,User Count,Type,Name,Requests/s,Failures/s,50%,66%,75%,80%,90%,95%,98%,99%,99.9%,99.99%,100%,Total Request Count,Total Failure Count,Total Median Response Time,Total Average Response Time,Total Min Response Time,Total Max Response Time,Total Average Content Size +1749224183,0,,Aggregated,0.000000,0.000000,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,0,0,0,0.0,0,0,0 +1749224184,10,,Aggregated,0.000000,0.000000,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,0,0,0,0.0,0,0,0 +1749224185,10,,Aggregated,0.000000,0.000000,280,310,1200,1200,1200,1200,1800,1800,1800,1800,1800,32,0,280.0,581.3894179227646,254.7728749923408,1791.5229999925941,5050.875 +1749224186,10,,Aggregated,0.000000,0.000000,280,290,310,330,1200,1200,1200,1800,1800,1800,1800,65,0,280.0,445.10393525617053,254.7728749923408,1791.5229999925941,15192.984615384616 +1749224187,10,,Aggregated,4.500000,0.000000,280,290,290,300,1200,1200,1200,1800,1800,1800,1800,98,0,280.0,392.35182099723806,254.7728749923408,1791.5229999925941,11863.489795918367 +1749224188,10,,Aggregated,15.000000,0.000000,290,300,310,320,580,1200,1200,1200,1800,1800,1800,127,0,290.0,378.3162270395789,254.7728749923408,1791.5229999925941,12411.944881889764 diff --git a/ws-locust-test.py b/ws-locust-test.py deleted file mode 100644 index 5bdb1a1..0000000 --- a/ws-locust-test.py +++ /dev/null @@ -1,98 +0,0 @@ -from locust import HttpLocust, TaskSet, task -from locust.events import request_success, request_failure - -import json -import uuid -import time -import gevent -import logging -import random -import websocket -import six -import sys - -# account_addresses = open("erc20_account_addresses").readlines() -token_addresses = open("erc20_token_addresses").readlines() - -logging.basicConfig(level=logging.INFO,) - -log = logging.getLogger(__name__) -websocket.setdefaulttimeout(120) -class EchoTaskSet(TaskSet): - def on_start(self): - ws = websocket.create_connection('ADDRESS', timeout=120) - self.ws = ws - output = random.randint(1,5000) >= 4999 - - def _receive(): - sub_mapping = {} - while True: - start_time = time.time() - try: - res = ws.recv() - except: - log.exception("Error receiving message") - break - message = json.loads(res) - try: - sub_id = message["id"] - except KeyError: - pass - else: - try: - sub_mapping[message["result"]] = sub_id - continue - except KeyError: - pass - end_time = time.time() - if output: - print(message) - try: - message["params"]["subscription"] = sub_mapping[message["params"]["subscription"]] - except KeyError: - log.warning("Mapping missing for %s", message["params"]["subscription"]) - end_at = time.time() - response_time = int(round((end_time - start_time) * 1000)) - request_failure.fire( - request_type='WebSocket Recv', - name='gotsomething', - response_time=1, - response_length=len(res), - exception="Mapping missing for %s" % message["params"]["subscription"] - ) - - end_at = time.time() - response_time = int(round((end_time - start_time) * 1000)) - request_success.fire( - request_type='WebSocket Recv', - name='gotsomething', - response_time=response_time, - response_length=len(res), - ) - - sends = [] - subscription=[ - {"jsonrpc":"2.0", "method": "eth_subscribe", "params": ["newHeads"]} - # {"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}, - ] - for sub in subscription: - sub['id'] = random.randint(0,sys.maxsize) - sends.append(self.ws.send(json.dumps(sub))) - gevent.spawn(_receive) - - - def on_quit(self): - self.ws.close() - - @task - def wait(self): - while True: - time.sleep(random.randint(5,125)) - - - - -class EchoLocust(HttpLocust): - task_set = EchoTaskSet - min_wait = 0 - max_wait = 100 diff --git a/ws-locust-test0.py b/ws-locust-test0.py deleted file mode 100644 index 4c3d636..0000000 --- a/ws-locust-test0.py +++ /dev/null @@ -1,142 +0,0 @@ -from locust import HttpLocust, TaskSet, task -from locust.events import request_success, request_failure - -import json -import uuid -import time -import gevent -import logging -import random -import websocket -import six -import sys - -# account_addresses = open("erc20_account_addresses").readlines() -token_addresses = open("erc20_token_addresses").readlines() - -logging.basicConfig(level=logging.INFO,) - -log = logging.getLogger(__name__) -websocket.setdefaulttimeout(120) - - -class EchoTaskSet(TaskSet): - def on_start(self): - sends = [] - self.sends = sends - ws = websocket.create_connection('ADDERSS', timeout=120) - self.ws = ws - ws2 = websocket.create_connection('ADDERSS', timeout=120) - self.ws2 = ws2 - output = random.randint(1,5000) >= 4999 - - def _receive(): - sub_mapping = {} - while True: - start_time = time.time() - try: - res = ws.recv() - except: - log.exception("Error receiving message") - break - message = json.loads(res) - try: - sub_id = message["id"] - except KeyError: - pass - else: - try: - sub_mapping[message["result"]] = sub_id - continue - except KeyError: - pass - # except TypeError: - # print(sub_mapping) - # print(message) - # print(sub_id) - - end_time = time.time() - # if output: - # print(message) - try: - message["params"]["subscription"] = sub_mapping[message["params"]["subscription"]] - except KeyError: - log.warning("Mapping missing for %s", message["params"]["subscription"]) - end_at = time.time() - response_time = int(round((end_time - start_time) * 1000)) - num=len(self.sends)//10 - request_failure.fire( - request_type='WebSocket Recv', - name=f'gotsomething{num}', - response_time=1, - response_length=len(res), - exception="Mapping missing for %s" % message["params"]["subscription"] - ) - - end_at = time.time() - num=len(self.sends)//10 - # print("recv") - # print(message) - # if num == 0: - # print(len(self.sends)) - # print(self.sends) - response_time = int(round((end_time - start_time) * 1000)) - request_success.fire( - request_type='WebSocket Recv', - name=f'gotsomething{num}', - response_time=response_time, - response_length=len(res), - ) - - def _receive2(): - while True: - try: - res = ws2.recv() - except: - log.exception("Error receiving message") - break - - end_time = time.time() - response_time = int(round((end_time - self.check_start_time) * 1000)) - request_success.fire( - request_type='WebSocket Recv', - name=f'eth_blockNumberRPC', - response_time=response_time, - response_length=len(res), - ) - - gevent.spawn(_receive2) - gevent.spawn(_receive) - subscription=[ - {"jsonrpc":"2.0", "method": "eth_subscribe", "params": ["newHeads"]}, - #{"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]} - ] - for sub in subscription: - sub['id'] = random.randint(0,sys.maxsize) - self.sends.append(self.ws.send(json.dumps(sub))) - - def on_quit(self): - self.ws.close() - self.ws2.close() - - @task - def wait(self): - time.sleep(10) - # print("RUnninTAsk") - if len(self.sends) < 50: - resp=self.ws.send(json.dumps({"jsonrpc":"2.0", "id": random.randint(0,sys.maxsize), "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"], "address": random.choice(token_addresses).strip()}]})) - self.sends.append(resp) - # print(resp) - # print(self.sends) - - @task - def query(self): - time.sleep(random.randint(5,20)) - # print("RUnninTAsk2") - self.check_start_time = time.time() - data={"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":000000000000000000000000} - self.ws2.send(json.dumps(data)) -class EchoLocust(HttpLocust): - task_set = EchoTaskSet - min_wait = 1000 - max_wait = 5000 diff --git a/ws-locust-test00.py b/ws-locust-test00.py deleted file mode 100644 index 4ba2552..0000000 --- a/ws-locust-test00.py +++ /dev/null @@ -1,143 +0,0 @@ -from locust import HttpLocust, TaskSet, task -from locust.events import request_success, request_failure - -import json -import uuid -import time -import gevent -import logging -import random -import websocket -import six -import sys - -# account_addresses = open("erc20_account_addresses").readlines() -token_addresses = open("erc20_token_addresses").readlines() - -logging.basicConfig(level=logging.INFO,) - -log = logging.getLogger(__name__) -websocket.setdefaulttimeout(120) - - -class EchoTaskSet(TaskSet): - def on_start(self): - sends = [] - self.sends = sends - # ws = create_connection('ADDRESS') - ws = websocket.create_connection('ADDRESS', timeout=120) - self.ws = ws - ws2 = websocket.create_connection('ADDRESS', timeout=120) - self.ws2 = ws2 - output = random.randint(1,5000) >= 4999 - - def _receive(): - sub_mapping = {} - while True: - start_time = time.time() - try: - res = ws.recv() - except: - log.exception("Error receiving message") - break - message = json.loads(res) - try: - sub_id = message["id"] - except KeyError: - pass - else: - try: - sub_mapping[message["result"]] = sub_id - continue - except KeyError: - pass - # except TypeError: - # print(sub_mapping) - # print(message) - # print(sub_id) - - end_time = time.time() - # if output: - # print(message) - try: - message["params"]["subscription"] = sub_mapping[message["params"]["subscription"]] - except KeyError: - log.warning("Mapping missing for %s", message["params"]["subscription"]) - # end_at = time.time() - # response_time = int(round((end_time - start_time) * 1000)) - # num=len(self.sends)//10 - # request_failure.fire( - # request_type='WebSocket Recv', - # name=f'gotsomething{num}', - # response_time=1, - # response_length=len(res), - # exception="Mapping missing for %s" % message["params"]["subscription"] - # ) - - end_at = time.time() - num=len(self.sends)//10 - # print("recv") - # print(message) - # if num == 0: - # print(len(self.sends)) - # print(self.sends) - # response_time = int(round((end_time - start_time) * 1000)) - # request_success.fire( - # request_type='WebSocket Recv', - # name=f'gotsomething{num}', - # response_time=response_time, - # response_length=len(res), - # ) - - def _receive2(): - while True: - try: - res = ws2.recv() - except: - log.exception("Error receiving message") - break - - end_time = time.time() - response_time = int(round((end_time - self.check_start_time) * 1000)) - request_success.fire( - request_type='WebSocket Recv', - name=f'eth_blockNumberRPC', - response_time=response_time, - response_length=len(res), - ) - - gevent.spawn(_receive2) - gevent.spawn(_receive) - subscription=[ - {"jsonrpc":"2.0", "method": "eth_subscribe", "params": ["newHeads"]}, - {"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]} - ] - for sub in subscription: - sub['id'] = random.randint(0,sys.maxsize) - self.sends.append(self.ws.send(json.dumps(sub))) - - def on_quit(self): - self.ws.close() - self.ws2.close() - - @task - def wait(self): - time.sleep(10) - # print("RUnninTAsk") - if len(sends) < 50: - resp=self.ws.send(json.dumps({"jsonrpc":"2.0", "id": random.randint(0,sys.maxsize), "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"], "address": random.choice(token_addresses).strip()}]})) - self.sends.append(resp) - # print(resp) - # print(self.sends) - - @task - def query(self): - time.sleep(random.randint(5,20)) - # print("RUnninTAsk2") - self.check_start_time = time.time() - data={"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":000000000000000000000000} - self.ws2.send(json.dumps(data)) -class EchoLocust(HttpLocust): - task_set = EchoTaskSet - min_wait = 1000 - max_wait = 5000 diff --git a/ws-requirements.txt b/ws-requirements.txt deleted file mode 100644 index 420104b..0000000 --- a/ws-requirements.txt +++ /dev/null @@ -1 +0,0 @@ -websockets==8.0.2 diff --git a/ws-test.py b/ws-test.py deleted file mode 100644 index a8805d8..0000000 --- a/ws-test.py +++ /dev/null @@ -1,123 +0,0 @@ -import asyncio -import json -from collections import Counter - -import websockets -import logging - -logging.basicConfig(level=logging.INFO,) -# logger = logging.getLogger('websockets') -# logger.setLevel(logging.DEBUG) -# logger.addHandler(logging.StreamHandler()) -log = logging.getLogger(__name__) - - -async def watch_primary(primary, collectables, subscriptions): - async with websockets.connect(primary) as websocket: - sends = [] - for i, sub in enumerate(subscriptions): - sends.append(websocket.send(json.dumps( - {"jsonrpc":"2.0", "id": i, "method": "eth_subscribe", "params": sub} - ))) - await asyncio.wait(sends) - log.info("Primary initialized") - sub_mapping = {} - while True: - message = json.loads(await websocket.recv()) - try: - sub_id = message["id"] - except KeyError: - pass - else: - if sub_id < len(subscriptions): - try: - sub_mapping[message["result"]] = sub_id - continue - except KeyError: - pass - try: - message["params"]["subscription"] = sub_mapping[message["params"]["subscription"]] - except KeyError: - log.warning("Mapping missing for %s", message["params"]["subscription"]) - message_string = json.dumps(message, sort_keys=True) - for collectable in collectables: - collectable[message_string] += 1 - -async def watch_secondary(secondary, collectable, subscriptions): - log.info("Initializing secondary %s", secondary) - async with websockets.connect(secondary) as websocket: - log.info("Connected %s", secondary) - # log.info("%s", list(enumerate(subscriptions))) - sends = [] - for i, sub in enumerate(subscriptions): - sends.append(websocket.send(json.dumps( - {"jsonrpc":"2.0", "id": i, "method": "eth_subscribe", "params": sub} - ))) - await asyncio.wait(sends) - log.info("Secondary initialized") - sub_mapping = {} - while True: - # log.info("Getting message on %s", secondary) - try: - raw_message = await websocket.recv() - except: - log.exception("Error receiving message") - break - # log.info("Parsing message on %s", secondary) - message = json.loads(raw_message) - log.info("Got message on %s", secondary) - try: - sub_id = message["id"] - except KeyError: - pass - else: - if sub_id < len(subscriptions): - try: - sub_mapping[message["result"]] = sub_id - continue - except KeyError: - pass - try: - message["params"]["subscription"] = sub_mapping[message["params"]["subscription"]] - except KeyError: - log.warning("Mapping missing for %s", message["params"]["subscription"]) - message_string = json.dumps(message, sort_keys=True) - collectable[message_string] -= 1 - log.info("Done with loop %s", secondary) - -async def report(collectables): - while True: - print("Report: %s" % max(len(c) for c in collectables)) - for i, c in enumerate(collectables): - counter = 0 - for k, v in c.items(): - if v: - counter += 1 - # print("\t", i, v, k) - if counter > 0: - print("\t", i, counter) - await asyncio.sleep(30) - -async def run_test(): - import argparse - parser = argparse.ArgumentParser() - parser.add_argument("primary") - parser.add_argument("secondary", nargs="+") - parser.add_argument("--subscriptions") - args = parser.parse_args() - subscriptions = [ - ["logs", {}], - # ["newHeads"], - # ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}], - ] - if args.subscriptions: - with open(args.subscription) as fd: - subscriptions = json.load(fd) - collectables = [Counter() for _ in args.secondary] - actions = [watch_primary(args.primary, collectables, subscriptions), report(collectables)] - for secondary, collectable in zip(args.secondary, collectables): - actions.append(watch_secondary(secondary, collectable, subscriptions)) - await asyncio.wait(actions) - - -asyncio.get_event_loop().run_until_complete(run_test())