Skip to content

feat(tooling): log RLP errors to file + shorten RLP errors in console #1810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pytest-execute-hive.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ addopts =
-p pytest_plugins.solc.solc
-p pytest_plugins.execute.rpc.hive
-p pytest_plugins.execute.execute
-p pytest_plugins.logging.logging
-p pytest_plugins.shared.execute_fill
-p pytest_plugins.forks.forks
-p pytest_plugins.pytest_hive.pytest_hive
Expand Down
1 change: 1 addition & 0 deletions pytest-execute.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ addopts =
-p pytest_plugins.execute.pre_alloc
-p pytest_plugins.solc.solc
-p pytest_plugins.execute.execute
-p pytest_plugins.logging.logging
-p pytest_plugins.shared.execute_fill
-p pytest_plugins.execute.rpc.remote_seed_sender
-p pytest_plugins.execute.rpc.remote
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ addopts =
-p pytest_plugins.filler.filler
-p pytest_plugins.filler.static_filler
-p pytest_plugins.filler.ported_tests
-p pytest_plugins.logging.logging
-p pytest_plugins.shared.execute_fill
-p pytest_plugins.forks.forks
-p pytest_plugins.eels_resolver
Expand Down
27 changes: 26 additions & 1 deletion src/ethereum_test_rpc/rpc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""JSON-RPC methods and helper functions for EEST consume based hive simulators."""

import logging
import time
from itertools import count
from pathlib import Path
from pprint import pprint
from typing import Any, ClassVar, Dict, List, Literal, Union

Expand All @@ -11,6 +13,7 @@

from ethereum_test_base_types import Address, Bytes, Hash, to_json
from ethereum_test_types import Transaction
from pytest_plugins.logging import get_logger

from .types import (
ForkchoiceState,
Expand All @@ -24,6 +27,7 @@
)

BlockNumberType = Union[int, Literal["latest", "earliest", "pending"]]
logger = get_logger(__name__)


class SendTransactionExceptionError(Exception):
Expand All @@ -43,7 +47,28 @@ def __str__(self):
if self.tx is not None:
f"{super().__str__()} Transaction={self.tx.model_dump_json()}"
elif self.tx_rlp is not None:
return f"{super().__str__()} Transaction RLP={self.tx_rlp.hex()}"
tx_rlp_hex_full = self.tx_rlp.hex()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should constrain this to only run when debugging is enabled. This would be an overhead that's dumping information to file system without the user having an option to disable it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but with Dan's custom logger I do not know how to retrieve the user-provided eest-log-level at runtime.

# always log shortened errors to console (even when debugging read full from log file)
tx_rlp_hex = tx_rlp_hex_full[:50]

# create ./logs/rlp folder if it does not exist already
rlp_logs_folder = Path(".") / "logs" / "rlp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have AppConfig().DEFAULT_EVM_LOGS_DIR instead of Path(".") but I'm not sure if that's the correct source for this location, so I'll defer to @danceratopz who is more familiar with the consume command logging.

rlp_logs_folder.mkdir(parents=True, exist_ok=True)

# create and config a temporary logger that logs to file
timestamp = time.time_ns()
file_name = rlp_logs_folder / f"{timestamp}_rlp_data.log"
temp_logger = logging.getLogger(f"rlp_{timestamp}")
temp_logger.propagate = False
file_handler = logging.FileHandler(file_name)
temp_logger.addHandler(file_handler)
# log rlp to file
temp_logger.error(tx_rlp_hex_full)
# cleanup
temp_logger.removeHandler(file_handler)
file_handler.close()

return f"{super().__str__()} Transaction RLP={tx_rlp_hex}"
return super().__str__()


Expand Down
Loading