-
Notifications
You must be signed in to change notification settings - Fork 167
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
felix314159
wants to merge
1
commit into
ethereum:main
Choose a base branch
from
felix314159:rlp-logging-improvement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
@@ -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, | ||
|
@@ -24,6 +27,7 @@ | |
) | ||
|
||
BlockNumberType = Union[int, Literal["latest", "earliest", "pending"]] | ||
logger = get_logger(__name__) | ||
|
||
|
||
class SendTransactionExceptionError(Exception): | ||
|
@@ -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() | ||
# 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have |
||
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__() | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.