Skip to content

Commit

Permalink
Merge pull request #478 from hoprnet/jean/more_logs
Browse files Browse the repository at this point in the history
More logs
  • Loading branch information
jeandemeusy authored Mar 1, 2024
2 parents 7eeb2bb + 0f6d04e commit b706553
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ct-app/core/components/baseclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

logging.basicConfig()
logging.getLogger("asyncio").setLevel(logging.WARNING)
formatter = logging.Formatter("%(message)s")
formatter = logging.Formatter("%(asctime)s %(levelname)s:%(message)s")


class Base:
Expand All @@ -25,7 +25,7 @@ def class_prefix(cls) -> str:
return f"{cls.__name__.upper()}_"

def __format(self, message: str, color: str = "\033[0m"):
return f"{color}{self.print_prefix}\033[0m | {message}"
return f"{self.print_prefix} | {message}"

def _print(self, message: str, color: str = "\033[0m"):
print(self.__format(message, color))
Expand Down
3 changes: 3 additions & 0 deletions ct-app/core/components/hoprd_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def print_prefix(self) -> str:
def __call_api(
self, obj: Callable[..., object], method: str, *args, **kwargs
) -> tuple[bool, Optional[object]]:
self.debug(
f"Calling {obj.__name__}.{method} with kwargs: {kwargs}, args: {args}"
)
try:
with ApiClient(self.configuration) as client:
api_callback = getattr(obj(client), method)
Expand Down
3 changes: 2 additions & 1 deletion ct-app/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ async def get_subgraph_data(self):
self.debug(f"Fetched subgraph data ({len(results)} entries).")

@flagguard
@connectguard
@formalin("Getting topology data")
@connectguard
async def get_topology_data(self):
"""
Gets a dictionary containing all unique source_peerId-source_address links
Expand Down Expand Up @@ -346,6 +346,7 @@ async def distribute_rewards(self):

@flagguard
@formalin("Getting funding data")
@connectguard
async def get_fundings(self):
from_address = self.params.subgraph.from_address
ct_safe_addresses = {
Expand Down
18 changes: 17 additions & 1 deletion ct-app/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ async def healthcheck(self):
if address := self.address:
self.debug(f"Connection state: {await self.connected.get()}")
HEALTH.labels(address.id).set(int(await self.connected.get()))
else:
self.warning("No address found")

@flagguard
@formalin("Retrieving balances")
Expand Down Expand Up @@ -132,13 +134,16 @@ async def open_channels(self):
self.debug(f"Addresses without channels: {len(addresses_without_channels)}")

for address in addresses_without_channels:
self.debug(f"Opening channel to {address}")
ok = await self.api.open_channel(
address,
f"{int(self.params.channel.funding_amount*1e18):d}",
)
if ok:
self.debug(f"Opened channel to {address}")
CHANNELS_OPENED.labels(self.address.id).inc()
else:
self.warning(f"Failed to open channel to {address}")
OPEN_CHANNELS_CALLS.labels(self.address.id).inc()

ADDRESSES_WOUT_CHANNELS.labels(self.address.id).set(
Expand All @@ -158,10 +163,13 @@ async def close_incoming_channels(self):
]

for channel in in_opens:
self.debug(f"Closing incoming channel {channel.channel_id}")
ok = await self.api.close_channel(channel.channel_id)
if ok:
self.debug(f"Closed channel {channel.channel_id}")
INCOMING_CHANNELS_CLOSED.labels(self.address.id).inc()
else:
self.warning(f"Failed to close channel {channel.channel_id}")
CLOSE_INCOMING_CHANNELS_CALLS.labels(self.address.id).inc()

@flagguard
Expand All @@ -179,10 +187,13 @@ async def close_pending_channels(self):
self.debug(f"Pending channels: {len(out_pendings)}")

for channel in out_pendings:
self.debug(f"Closing pending channel {channel.channel_id}")
ok = await self.api.close_channel(channel.channel_id)
if ok:
self.debug(f"Closed pending channel {channel.channel_id}")
PENDING_CHANNELS_CLOSED.labels(self.address.id).inc()
else:
self.warning(f"Failed to close pending channel {channel.channel_id}")
CLOSE_PENDING_CHANNELS_CALLS.labels(self.address.id).inc()

@flagguard
Expand Down Expand Up @@ -222,13 +233,14 @@ async def close_old_channels(self):

self.info(f"Closing {len(channels_to_close)} old channels")
for channel in channels_to_close:
self.debug(f"Closing channel {channel}")
ok = await self.api.close_channel(channel)

if ok:
self.debug(f"Channel {channel} closed")
OLD_CHANNELS_CLOSED.labels(self.address.id).inc()
else:
self.debug(f"Failed to close channel {channel_id}")
self.warning(f"Failed to close channel {channel_id}")

CLOSE_OLD_CHANNELS_CALLS.labels(self.address.id).inc()

Expand Down Expand Up @@ -256,12 +268,15 @@ async def fund_channels(self):

for channel in low_balances:
if channel.destination_peer_id in peer_ids:
self.debug(f"Funding channel {channel.channel_id}")
ok = await self.api.fund_channel(
channel.channel_id, self.params.channel.funding_amount * 1e18
)
if ok:
self.debug(f"Funded channel {channel.channel_id}")
FUNDED_CHANNELS.labels(self.address.id).inc()
else:
self.warning(f"Failed to fund channel {channel.channel_id}")
FUND_CHANNELS_CALLS.labels(self.address.id).inc()

@flagguard
Expand Down Expand Up @@ -340,6 +355,7 @@ async def get_total_channel_funds(self):
results = await Utils.aggregatePeerBalanceInChannels(channels)

if self.address.id not in results:
self.warning("Funding info not found")
return

entry = TopologyEntry.fromDict(self.address.id, results[self.address.id])
Expand Down

0 comments on commit b706553

Please sign in to comment.