-
Notifications
You must be signed in to change notification settings - Fork 795
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
Web socket subscription for active difficulty #2091
Web socket subscription for active difficulty #2091
Conversation
d2df373
to
b73bf89
Compare
@@ -639,7 +639,12 @@ void nano::active_transactions::update_active_difficulty (std::unique_lock<std:: | |||
auto sum (std::accumulate (multipliers_cb.begin (), multipliers_cb.end (), double(0))); | |||
auto difficulty = nano::difficulty::from_multiplier (sum / multipliers_cb.size (), node.network_params.network.publish_threshold); | |||
assert (difficulty >= node.network_params.network.publish_threshold); | |||
|
|||
bool notify_change = trended_active_difficulty != difficulty; |
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.
Currently implemented to only notify if the active difficulty changes - is this correct or should it notify on every iteration even if active difficulty remains the same?
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.
Only when it changes I think. Thoughts @zhyatt ?
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.
If the call is sufficiently lightweight, I could see value in triggering it every cycle, specifically to ensure consistent data points for any tracking/visualizations, and also as a mechanism that allows watching for that consistency. If gaps are seen, this allows polling for difficulty separately through RPC as fallback or alerting of a possible issue (if these notifications aren't seen for a time period). Any additional thoughts @cryptocode or @guilhermelawless ?
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 think that's a good idea, it's very light data especially considering the ~20 second period.
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.
Sounds good to me if it simplifies clients and is low frequency.
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.
The request_loop
runs faster in testing - will publishing on every iteration have an impact on other tests if running faster?:
request_interval_ms = is_test_network () ? (is_sanitizer_build ? 100 : 20) : 16000;
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.
Not a problem I believe, there is much higher frequency data being passed around. Tests should pass.
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 agree with @guilhermelawless, sending it every cycle should be fine.
Thanks @chrislinegar. Before reviewing this, could you fix the formatting issues reported by CI? There's a |
b73bf89
to
ce5d11f
Compare
9fec66b
to
9ffc0ea
Compare
9ffc0ea
to
30892ad
Compare
thanks, done :) |
This comment has been minimized.
This comment has been minimized.
@@ -639,7 +639,12 @@ void nano::active_transactions::update_active_difficulty (std::unique_lock<std:: | |||
auto sum (std::accumulate (multipliers_cb.begin (), multipliers_cb.end (), double(0))); | |||
auto difficulty = nano::difficulty::from_multiplier (sum / multipliers_cb.size (), node.network_params.network.publish_threshold); | |||
assert (difficulty >= node.network_params.network.publish_threshold); | |||
|
|||
bool notify_change = trended_active_difficulty != difficulty; |
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.
Only when it changes I think. Thoughts @zhyatt ?
Current failure you might be seeing is outlined in #2101 |
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.
LGTM pending formatting issue on CI/2101
Thank you @chrislinegar . Only needs another pass of |
Just to confirm - is there any action needed on this PR for this issue? |
No, it's resolved. |
@chrislinegar Are you considering this PR wrapped up on your end (all comments resolved)? |
* Add active_difficulty topic * Topic to string for active_difficulty * Add difficulty_changed message builder * Add difficulty observer * Notify observer if difficulty changes * Add test for subscribe_active_difficulty * Update comment * Run clang format all * Use boost ptree double get instead of std::stod * Rename test and for std::launch::async policy * Remove difficulty_observer and call node.observers.difficulty directly * Fix formatting issue
This implements #2080 - monitors changes in difficulty and notifies via web socket if the active difficulty changes