Skip to content

Commit 5201059

Browse files
committed
fix issues
1 parent 3f092f1 commit 5201059

File tree

5 files changed

+67
-65
lines changed

5 files changed

+67
-65
lines changed

chainbench/profile/ethereum/subscriptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from chainbench.user import EvmUser, WssJrpcUser
1+
from chainbench.user import WssJrpcUser
22
from chainbench.user.protocol.ethereum import EthSubscribe
33

44

5-
class EthSubscriptions(WssJrpcUser, EvmUser):
5+
class EthSubscriptions(WssJrpcUser):
66
subscriptions = [
77
EthSubscribe(["newHeads"]),
88
# logs subscription for approve method signature

chainbench/user/jsonrpc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,14 @@ def make_rpc_call(
9898
path: str = "",
9999
) -> None:
100100
"""Make a JSON-RPC call."""
101-
if rpc_call is None and method is not None:
102-
rpc_call = RpcCall(method, params)
101+
if rpc_call is None:
102+
if method is None:
103+
raise ValueError("Either rpc_call or method must be provided")
104+
else:
105+
rpc_call = RpcCall(method, params)
106+
name = method
103107
else:
104-
raise ValueError("Either rpc_call or method must be provided")
105-
106-
if name == "" and method is not None:
107-
name = method
108+
name = rpc_call.method
108109

109110
with self.client.request(
110111
"POST", self.rpc_path + path, json=rpc_call.request_body(), name=name, catch_response=True

chainbench/user/wss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def receive_loop(self):
165165
try:
166166
while self._running:
167167
message = self._ws.recv()
168-
self.logger.debug(f"WSResp: {message}")
168+
self.logger.debug(f"WSResp: {message.strip()}")
169169
self.on_message(message)
170170
else:
171171
self._ws.close()

chainbench/util/event.py

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -179,65 +179,66 @@ def on_init(environment: Environment, **_kwargs):
179179
test_data: dict[str, t.Any] = {}
180180
for user in environment.runner.user_classes:
181181
if not hasattr(user, "test_data"):
182-
raise AttributeError(f"{user} class does not have 'test_data' attribute")
183-
user_test_data: TestData = getattr(user, "test_data")
184-
test_data_class_name: str = type(user_test_data).__name__
185-
if test_data_class_name in test_data:
186-
continue
187-
logger.info(f"Initializing test data for {test_data_class_name}")
188-
print(f"Initializing test data for {test_data_class_name}")
189-
if environment.host:
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}
197-
if environment.parsed_options:
198-
user_test_data.init_data(environment.parsed_options)
199-
test_data[test_data_class_name] = user_test_data.data.to_json()
200-
send_msg_to_workers(environment.runner, "test_data", test_data)
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:
182+
logger.warning(f"{user} class does not have 'test_data' attribute")
183+
else:
184+
user_test_data: TestData = getattr(user, "test_data")
185+
test_data_class_name: str = type(user_test_data).__name__
186+
if test_data_class_name in test_data:
187+
continue
188+
logger.info(f"Initializing test data for {test_data_class_name}")
189+
print(f"Initializing test data for {test_data_class_name}")
190+
if environment.host:
191+
user_test_data.init_http_client(environment.host)
192+
if isinstance(user_test_data, EvmTestData):
193+
chain_id: ChainId = user_test_data.fetch_chain_id()
194+
user_test_data.init_network(chain_id)
195+
logger.info(f"Target endpoint network is {user_test_data.network.name}")
196+
print(f"Target endpoint network is {user_test_data.network.name}")
197+
test_data["chain_id"] = {test_data_class_name: chain_id}
198+
if environment.parsed_options:
199+
user_test_data.init_data(environment.parsed_options)
200+
test_data[test_data_class_name] = user_test_data.data.to_json()
201+
send_msg_to_workers(environment.runner, "test_data", test_data)
202+
print("Fetching blocks...")
203+
if environment.parsed_options.use_latest_blocks:
204+
print(f"Using latest {user_test_data.data.size.blocks_len} blocks as test data")
205+
logger.info(f"Using latest {user_test_data.data.size.blocks_len} blocks as test data")
206+
for block_number in range(
207+
user_test_data.data.block_range.start, user_test_data.data.block_range.end + 1
208+
):
209+
block = None
214210
try:
215-
block = user_test_data.fetch_latest_block()
211+
block = user_test_data.fetch_block(block_number)
216212
except (BlockNotFoundError, InvalidBlockError):
217213
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")
214+
while block is None:
215+
try:
216+
block = user_test_data.fetch_latest_block()
217+
except (BlockNotFoundError, InvalidBlockError):
218+
pass
219+
user_test_data.data.push_block(block)
220+
block_data = {test_data_class_name: block.to_json()}
221+
send_msg_to_workers(environment.runner, "block_data", block_data)
222+
print(user_test_data.data.stats(), end="\r")
223+
else:
224+
print(user_test_data.data.stats(), end="\r")
225+
print("\n") # new line after progress display upon exiting loop
222226
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
238-
logger.info("Test data is ready")
239-
send_msg_to_workers(environment.runner, "release_lock", {})
240-
user_test_data.release_lock()
227+
while user_test_data.data.size.blocks_len > len(user_test_data.data.blocks):
228+
try:
229+
block = user_test_data.fetch_random_block(user_test_data.data.block_numbers)
230+
except (BlockNotFoundError, InvalidBlockError):
231+
continue
232+
user_test_data.data.push_block(block)
233+
block_data = {test_data_class_name: block.to_json()}
234+
send_msg_to_workers(environment.runner, "block_data", block_data)
235+
print(user_test_data.data.stats(), end="\r")
236+
else:
237+
print(user_test_data.data.stats(), end="\r")
238+
print("\n") # new line after progress display upon exiting loop
239+
logger.info("Test data is ready")
240+
send_msg_to_workers(environment.runner, "release_lock", {})
241+
user_test_data.release_lock()
241242
except Exception as e:
242243
logger.error(f"Failed to init test data: {e.__class__.__name__}: {e}. Exiting...")
243244
print(f"Failed to init test data:\n {e.__class__.__name__}: {e}. Exiting...")

chainbench/util/jsonrpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def request_body(self, request_id: int | None = None) -> dict:
3131
"jsonrpc": "2.0",
3232
"method": self.method,
3333
"params": self.params,
34-
"id": self._request_id,
34+
"id": self.request_id,
3535
}
3636

3737

0 commit comments

Comments
 (0)