Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #85 from derekpierre/overloaded
Browse files Browse the repository at this point in the history
Don't overload the monitor trying to project stakers and stake size for a year in the future
  • Loading branch information
derekpierre authored Oct 30, 2020
2 parents ae1f8aa + 4099712 commit 4e73f5b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
12 changes: 7 additions & 5 deletions monitor/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ class Crawler(Learner):
PolicyManagerAgent: ['NodeBrokenState'],
}

STAKER_PAGINATION_SIZE = 200

def __init__(self,
influx_host: str,
influx_port: int,
Expand Down Expand Up @@ -341,13 +343,14 @@ def _measure_future_locked_tokens(self, periods: int = 365):
period_range = range(1, periods + 1)
token_counter = dict()
for day in period_range:
tokens, stakers = self.staking_agent.get_all_active_stakers(periods=day)
tokens, stakers = self.staking_agent.get_all_active_stakers(periods=day,
pagination_size=self.STAKER_PAGINATION_SIZE)
token_counter[day] = (float(NU.from_nunits(tokens).to_tokens()), len(stakers))
return dict(token_counter)

@collector(label="Top Stakes")
def _measure_top_stakers(self) -> dict:
_, stakers = self.staking_agent.get_all_active_stakers(periods=1)
_, stakers = self.staking_agent.get_all_active_stakers(periods=1, pagination_size=self.STAKER_PAGINATION_SIZE)
data = dict(sorted(stakers.items(), key=lambda s: s[1], reverse=True))
return data

Expand Down Expand Up @@ -481,7 +484,7 @@ def _collect_stats(self, threaded: bool = True) -> None:
activity = self._measure_staker_activity()

# Stake
future_locked_tokens = self._measure_future_locked_tokens()
#future_locked_tokens = self._measure_future_locked_tokens()
global_locked_tokens = self.staking_agent.get_global_locked_tokens()
click.secho("✓ ... Global Network Locked Tokens", color='blue')

Expand All @@ -504,7 +507,7 @@ def _collect_stats(self, threaded: bool = True) -> None:
'node_details': known_nodes,

'global_locked_tokens': global_locked_tokens,
'future_locked_tokens': future_locked_tokens,
#'future_locked_tokens': future_locked_tokens,
'top_stakers': top_stakers,
}
done = maya.now()
Expand All @@ -523,7 +526,6 @@ def _collect_events(self, threaded: bool = True):
return reactor.callInThread(self._collect_events, threaded=False)
self.__collecting_events = True


blockchain_client = self.staking_agent.blockchain.client
latest_block_number = blockchain_client.block_number
from_block = self.__events_from_block
Expand Down
26 changes: 13 additions & 13 deletions monitor/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@ def staked_tokens(n, latest_crawler_stats):
staked = NU.from_nunits(data['global_locked_tokens'])
return html.Div([html.H4('Staked Tokens'), html.H5(f"{staked}", id='staked-tokens-value')])

@dash_app.callback(Output('locked-stake-graph', 'children'),
[Input('daily-interval', 'n_intervals')],
[State('cached-crawler-stats', 'children')])
def stake_and_known_nodes_plot(n, latest_crawler_stats):
prior_periods = 30
data = self.verify_cached_stats(latest_crawler_stats)
nodes_history = self.influx_client.get_historical_num_stakers_over_range(prior_periods)
past_stakes = self.influx_client.get_historical_locked_tokens_over_range(prior_periods)
future_stakes = data['future_locked_tokens']
graph = future_locked_tokens_bar_chart(future_locked_tokens=future_stakes,
past_locked_tokens=past_stakes,
node_history=nodes_history)
return graph
# @dash_app.callback(Output('locked-stake-graph', 'children'),
# [Input('daily-interval', 'n_intervals')],
# [State('cached-crawler-stats', 'children')])
# def stake_and_known_nodes_plot(n, latest_crawler_stats):
# prior_periods = 30
# data = self.verify_cached_stats(latest_crawler_stats)
# nodes_history = self.influx_client.get_historical_num_stakers_over_range(prior_periods)
# past_stakes = self.influx_client.get_historical_locked_tokens_over_range(prior_periods)
# future_stakes = data['future_locked_tokens']
# graph = future_locked_tokens_bar_chart(future_locked_tokens=future_stakes,
# past_locked_tokens=past_stakes,
# node_history=nodes_history)
# return graph

@dash_app.callback(Output('nodes-geolocation-graph', 'children'),
[Input('minute-interval', 'n_intervals')],
Expand Down
2 changes: 1 addition & 1 deletion monitor/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
# html.Div(id='prev-work-orders-graph'), # TODO
html.Div(id='nodes-geolocation-graph'),
html.Div(id='top-stakers-graph'),
html.Div(id='locked-stake-graph'),
#html.Div(id='locked-stake-graph'),
html.Div(id='prev-states'),
], id='widgets')

Expand Down

0 comments on commit 4e73f5b

Please sign in to comment.