Skip to content

Commit

Permalink
Merge pull request #343 from carver/logging-cleanups
Browse files Browse the repository at this point in the history
Logging cleanups
  • Loading branch information
carver committed May 12, 2021
2 parents 1d3b554 + 6cd91f1 commit 82b0e5d
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
7 changes: 3 additions & 4 deletions ddht/canary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging

from async_service import Service
from eth_utils import get_extended_debug_logger
import trio

WAKEUP_INTERVAL = 2
Expand All @@ -9,15 +8,15 @@


class Canary(Service):
logger = logging.getLogger("ddht.Canary")
logger = get_extended_debug_logger("ddht.Canary")

async def run(self) -> None:
while True:
start_at = trio.current_time()
await trio.sleep(WAKEUP_INTERVAL)
elapsed = trio.current_time() - start_at
delay = elapsed - WAKEUP_INTERVAL
self.logger.debug("Loop monitoring task called; delay=%.3fs", delay)
self.logger.debug2("Loop monitoring task called; delay=%.3fs", delay)

if delay < DELAY_DEBUG:
continue
Expand Down
5 changes: 2 additions & 3 deletions ddht/tools/w3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from eth_typing import HexStr, NodeID
from mypy_extensions import VarArg
from web3.method import Method
from web3.module import ModuleV2
from web3.module import Module
from web3.types import RPCEndpoint

from ddht.rpc_handlers import BucketInfo as BucketInfoDict
Expand Down Expand Up @@ -313,8 +313,7 @@ def find_nodes_response_formatter(enr_reprs: Sequence[str]) -> Tuple[ENRAPI, ...
return tuple(ENR.from_repr(enr_repr) for enr_repr in enr_reprs)


# TODO: why does mypy think ModuleV2 is of `Any` type?
class DiscoveryV5Module(ModuleV2): # type: ignore
class DiscoveryV5Module(Module):
"""
A web3.py module that exposes high level APIs for interacting with the
discovery v5 network.
Expand Down
4 changes: 2 additions & 2 deletions ddht/tools/w3_alexandria.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from eth_typing import HexStr
from web3.method import Method
from web3.module import ModuleV2
from web3.module import Module
from web3.types import RPCEndpoint

from ddht.v5_1.alexandria.typing import ContentKey
Expand Down Expand Up @@ -50,7 +50,7 @@ def content_key_and_content_munger(
)


class AlexandriaModule(ModuleV2): # type: ignore
class AlexandriaModule(Module):
"""
A web3.py module that exposes high level APIs for interacting with the
discovery v5 network.
Expand Down
6 changes: 4 additions & 2 deletions ddht/v5_1/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ async def run(self) -> None:
listen_on_ip_address: AnyIPAddress
if self._boot_info.listen_on is None:
listen_on_ip_address = DEFAULT_LISTEN
if IP_V4_ADDRESS_ENR_KEY not in enr_manager.enr:
enr_manager.update((IP_V4_ADDRESS_ENR_KEY, listen_on_ip_address.packed))
else:
listen_on_ip_address = self._boot_info.listen_on
# Update the ENR if an explicit listening address was provided
Expand Down Expand Up @@ -135,8 +137,8 @@ async def run(self) -> None:
self.logger.info("Listening on : %s", listen_on)
self.logger.info("Local Node ID : %s", encode_hex(enr_manager.enr.node_id))
self.logger.info(
"Local ENR : seq=%d enr=%r",
enr_manager.enr.sequence_number,
"Local ENR : encoded=%r, decoded=%s",
enr_manager.enr,
enr_manager.enr,
)

Expand Down
7 changes: 1 addition & 6 deletions ddht/v5_1/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
)


DEFAULT_BOOTNODES: Tuple[str, ...] = (
# 94.63.192.187:30303
# "enr:-IS4QMKRqKacvGacwsChKkhY9OWyRAJvCkUG3mTlM-9DOtqcS7Zr7vVkf6s20ju6wCMNFE_ivWwYYp1CqA_ybJ9R_O8DgmlkgnY0gmlwhF4_wLuJc2VjcDI1NmsxoQLhZcNMi9TtZ9RxmjGNVG83YFyWQnyVdKr74_qXl7mbb4N1ZHCCdl8", # noqa: E501
# 192.168.1.112:30303
"enr:-IS4QAVuwe64nAc-Lki-UHRUdpHzAB5xX_Uff0aQDBjIXgMlS7U7WjJ0h0Gja3-YTTTMTt6S5GG0doViOVYPMpYb2goDgmlkgnY0gmlwhMCoAXCJc2VjcDI1NmsxoQLhZcNMi9TtZ9RxmjGNVG83YFyWQnyVdKr74_qXl7mbb4N1ZHCCdl8", # noqa: E501
)
DEFAULT_BOOTNODES: Tuple[str, ...] = ()


PACKET_VERSION_1 = b"\x00\x01"
Expand Down
1 change: 1 addition & 0 deletions newsfragments/343.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Configure local ENR properly when using the default IP address.
1 change: 1 addition & 0 deletions newsfragments/343.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move noisy log "Loop monitoring task called" into debug2. Log out ENR items along with encoded ENR.
2 changes: 2 additions & 0 deletions newsfragments/343.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Install web3 for lint tests, so that mypy notices problems. Upgrade coincurve. Upgrade web3 to
5.19+ and handle the ModuleV2 rename.
1 change: 1 addition & 0 deletions newsfragments/343.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove all bootnodes for now.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"twine",
"ipython",
],
"web3": ["web3>=5.13.1,<6"],
"web3": ["web3>=5.19.0,<6"],
"alexandria": [
"pyethash>=0.1.27,<1.0.0",
"ssz>=0.2.4,<0.3",
Expand Down Expand Up @@ -70,7 +70,7 @@
install_requires=[
"async-service>=0.1.0a9,<0.2",
"cached-property>=1.5.1,<2",
"coincurve>=10.0.0,<11.0.0",
"coincurve>=15.0.0,<16.0.0",
"cryptography>=3.0,<3.2",
"eth-enr>=0.4.1,<0.5",
"eth-hash[pycryptodome]>=0.1.4,<1",
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ whitelist_externals=make

[testenv:lint]
basepython=python
extras=lint
extras=
lint
web3
commands=
mypy -p {toxinidir}/ddht --config-file {toxinidir}/mypy.ini
flake8 {toxinidir}/ddht {toxinidir}/tests
Expand Down

0 comments on commit 82b0e5d

Please sign in to comment.