Skip to content
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

Thor 7/monitor network security #133

Merged
merged 5 commits into from
Jan 12, 2021
Merged

Conversation

DollyVolley
Copy link
Contributor

Description

Add new Job (hourly interval)
trigger notification on network health change

Network health is important in terms of security and efficiency, therefore the user should be notified.

Thor-7 JIRA Task

Fixes (issue)

Monitor Network State

Improvements

Trying to introduce best practices w/ enums and string file instead of hardcoded strings.

How Has This Been Tested?

Changing the health state of the network and checking if the the returned message matches the expected ones.

Checklist:

If you have any comments regarding one of these points just write it down.

  • [x ] My code follows the style guidelines of this project
  • [ x] I have performed a self-review of my own code
  • [ x] I have commented my code, particularly in hard-to-understand areas
  • [ x] I have made corresponding changes to the documentation
  • [ x] My changes generate no new warnings
  • [ x] I have added tests that prove my fix is effective or that my feature works
  • [ x] New and existing unit tests pass locally with my changes

Copy link
Contributor

@mbartn mbartn left a comment

Choose a reason for hiding this comment

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

Dear Contributor,
welcome to the Thronode bot project and thanks for your contribution!
Congratulations for easy and smooth onboarding in the project.
I left some suggestions regarding the style, feel free to open discussion about it.
Hint regarding testing: it's always good to run the bot in DEBUG=True,False on testnet and DEBUG=False on chaosnet to make sure there is no crash or anything.
Thanks for fixing the typos.

Comment on lines 63 to 70


class NetworkHealthStatus(Enum):
INEFFICIENT = "Inefficient"
OVERBONDED = "Overbonded"
OPTIMAL = "Optimal"
UNDBERBONDED = "Underbonded"
INSECURE = "Insecure"
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea with using enum in this case. Maybe constants.messages file would be a more appropriate place for this piece of code?

HEALTH_LEGEND = f'\n*Node health*:\n{HEALTH_EMOJIS[True]} - *healthy*\n{HEALTH_EMOJIS[False]} - *unhealthy*\n' \
f'{HEALTH_EMOJIS[None]} - *unknown*\n'

NETWORK_HEALTH_CURATION = "The network is safe and efficient again! ✅"
Copy link
Contributor

Choose a reason for hiding this comment

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

This name was a little bit mysterious for me at first. Is something like NETWORK_HEALTHY_AGAIN easier to understand?

Comment on lines +10 to +17
def NETWORK_HEALTH_WARNING(network_health_status: NetworkHealthStatus) -> str:
severity = "🤒"
if network_health_status is NetworkHealthStatus.INSECURE:
severity = "💀"
elif network_health_status is NetworkHealthStatus.INEFFICIENT:
severity = "🦥"

return f"Network health is not optimal: {network_health_status.value} {severity}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be simpler to just use a dictionary? See constants/globals.py:30 STATUS_EMOJIS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We came to a consensus and decided no

Comment on lines 367 to 369
"""
Job notifying the user if network security has changed
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

We are trying to move away from commenting stuff too much when the function's operation is clear from the method name, if there are any old unnecessary comments in the code feel free to remove them (@mr-rooftop correct me if I'm wrong)

context.bot_data["network_health_status"] = network_health_status
return None

if network_health_status is not context.bot_data["network_health_status"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure that we should compare here using != because we want to compare the values, not the objects itself

@@ -0,0 +1 @@
2021-01-12 09:56:14+0100 [-] Log opened.
Copy link
Contributor

Choose a reason for hiding this comment

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

😠

@@ -14,6 +14,9 @@ def setup_bot_data(dispatcher):
dispatcher.job_queue.run_repeating(check_other_nodes_syncing_job,
interval=syncing_checks_interval_in_seconds)

dispatcher.job_queue.run_repeating(check_network_security_job,
interval=3600)
Copy link
Contributor

Choose a reason for hiding this comment

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

just for consistency, remove pls syncing_checks_interval_in_seconds or assign seconds in the same way here

@DollyVolley DollyVolley merged commit db843a2 into master Jan 12, 2021
@mr-rooftop mr-rooftop deleted the THOR-7/MonitorNetworkSecurity branch February 24, 2021 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants