Skip to content

Commit 2d40774

Browse files
committed
fix stuff
1 parent 6fb1c46 commit 2d40774

File tree

4 files changed

+48
-95
lines changed

4 files changed

+48
-95
lines changed

chainbench/user/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from .common import get_subclass_tasks
55
from .http import HttpUser
6+
from .jsonrpc import JsonRpcUser
67
from .wss import WssJrpcUser
78

89
# importing plugins here as all profiles depend on it
@@ -14,6 +15,7 @@
1415
"EthBeaconUser",
1516
"EvmUser",
1617
"HttpUser",
18+
"JsonRpcUser",
1719
"SolanaUser",
1820
"StarkNetUser",
1921
"WssJrpcUser",

chainbench/user/wss.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import time
3-
from socket import socket
43

54
import gevent
65
import orjson as json
@@ -166,7 +165,7 @@ def receive_loop(self):
166165
try:
167166
while self._running:
168167
message = self._ws.recv()
169-
self.logger.debug(f"WSR: {message}")
168+
self.logger.debug(f"WSResp: {message}")
170169
self.on_message(message)
171170
else:
172171
self._ws.close()
@@ -202,5 +201,5 @@ def send(self, rpc_call: RpcCall = None, method: str = None, params: dict | list
202201
{rpc_call.request_id: WSRequest(rpc_call, start_time=time.time_ns(), subscription_index=subscription_index)}
203202
)
204203
json_body = json.dumps(rpc_call.request_body())
205-
self.logger.debug(f"WSS: {json_body}")
204+
self.logger.debug(f"WSReq: {json_body}")
206205
self._ws.send(json_body)

chainbench/util/event.py

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -187,59 +187,54 @@ def on_init(environment: Environment, **_kwargs):
187187
logger.info(f"Initializing test data for {test_data_class_name}")
188188
print(f"Initializing test data for {test_data_class_name}")
189189
if environment.host:
190-
if environment.host.startswith("wss"):
191-
user_test_data.init_http_client(
192-
"https://nd-195-027-150.p2pify.com/681543cc4d120809ae5a1c973ac798e8"
193-
)
194-
else:
195-
user_test_data.init_http_client(environment.host)
196-
# if isinstance(user_test_data, EvmTestData):
197-
# chain_id: ChainId = user_test_data.fetch_chain_id()
198-
# user_test_data.init_network(chain_id)
199-
# logger.info(f"Target endpoint network is {user_test_data.network.name}")
200-
# print(f"Target endpoint network is {user_test_data.network.name}")
201-
# test_data["chain_id"] = {test_data_class_name: chain_id}
190+
user_test_data.init_http_client(environment.host)
191+
if isinstance(user_test_data, EvmTestData):
192+
chain_id: ChainId = user_test_data.fetch_chain_id()
193+
user_test_data.init_network(chain_id)
194+
logger.info(f"Target endpoint network is {user_test_data.network.name}")
195+
print(f"Target endpoint network is {user_test_data.network.name}")
196+
test_data["chain_id"] = {test_data_class_name: chain_id}
202197
if environment.parsed_options:
203198
user_test_data.init_data(environment.parsed_options)
204199
test_data[test_data_class_name] = user_test_data.data.to_json()
205200
send_msg_to_workers(environment.runner, "test_data", test_data)
206-
# print("Fetching blocks...")
207-
# if environment.parsed_options.use_latest_blocks:
208-
# print(f"Using latest {user_test_data.data.size.blocks_len} blocks as test data")
209-
# logger.info(f"Using latest {user_test_data.data.size.blocks_len} blocks as test data")
210-
# for block_number in range(
211-
# user_test_data.data.block_range.start, user_test_data.data.block_range.end + 1
212-
# ):
213-
# block = None
214-
# try:
215-
# block = user_test_data.fetch_block(block_number)
216-
# except (BlockNotFoundError, InvalidBlockError):
217-
# pass
218-
# while block is None:
219-
# try:
220-
# block = user_test_data.fetch_latest_block()
221-
# except (BlockNotFoundError, InvalidBlockError):
222-
# pass
223-
# user_test_data.data.push_block(block)
224-
# block_data = {test_data_class_name: block.to_json()}
225-
# send_msg_to_workers(environment.runner, "block_data", block_data)
226-
# print(user_test_data.data.stats(), end="\r")
227-
# else:
228-
# print(user_test_data.data.stats(), end="\r")
229-
# print("\n") # new line after progress display upon exiting loop
230-
# else:
231-
# while user_test_data.data.size.blocks_len > len(user_test_data.data.blocks):
232-
# try:
233-
# block = user_test_data.fetch_random_block(user_test_data.data.block_numbers)
234-
# except (BlockNotFoundError, InvalidBlockError):
235-
# continue
236-
# user_test_data.data.push_block(block)
237-
# block_data = {test_data_class_name: block.to_json()}
238-
# send_msg_to_workers(environment.runner, "block_data", block_data)
239-
# print(user_test_data.data.stats(), end="\r")
240-
# else:
241-
# print(user_test_data.data.stats(), end="\r")
242-
# print("\n") # new line after progress display upon exiting loop
201+
print("Fetching blocks...")
202+
if environment.parsed_options.use_latest_blocks:
203+
print(f"Using latest {user_test_data.data.size.blocks_len} blocks as test data")
204+
logger.info(f"Using latest {user_test_data.data.size.blocks_len} blocks as test data")
205+
for block_number in range(
206+
user_test_data.data.block_range.start, user_test_data.data.block_range.end + 1
207+
):
208+
block = None
209+
try:
210+
block = user_test_data.fetch_block(block_number)
211+
except (BlockNotFoundError, InvalidBlockError):
212+
pass
213+
while block is None:
214+
try:
215+
block = user_test_data.fetch_latest_block()
216+
except (BlockNotFoundError, InvalidBlockError):
217+
pass
218+
user_test_data.data.push_block(block)
219+
block_data = {test_data_class_name: block.to_json()}
220+
send_msg_to_workers(environment.runner, "block_data", block_data)
221+
print(user_test_data.data.stats(), end="\r")
222+
else:
223+
print(user_test_data.data.stats(), end="\r")
224+
print("\n") # new line after progress display upon exiting loop
225+
else:
226+
while user_test_data.data.size.blocks_len > len(user_test_data.data.blocks):
227+
try:
228+
block = user_test_data.fetch_random_block(user_test_data.data.block_numbers)
229+
except (BlockNotFoundError, InvalidBlockError):
230+
continue
231+
user_test_data.data.push_block(block)
232+
block_data = {test_data_class_name: block.to_json()}
233+
send_msg_to_workers(environment.runner, "block_data", block_data)
234+
print(user_test_data.data.stats(), end="\r")
235+
else:
236+
print(user_test_data.data.stats(), end="\r")
237+
print("\n") # new line after progress display upon exiting loop
243238
logger.info("Test data is ready")
244239
send_msg_to_workers(environment.runner, "release_lock", {})
245240
user_test_data.release_lock()

chainbench/util/ws.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)