nearcore
nearcore copied to clipboard
Make EpochManager::get_validator_info run fast even when node is syncing
EpochManager::get_validator_info call querying information by block hash turns out to be quite expensive while node is synchronising.
My current understanding is that when node is syncing EpochManager does not maintain aggregator which normally stores data up to the latest final block. As a result, get_epoch_info_aggregator_upto_last calls cannot leverage the aggregated data and instead have to aggregate all the statistics from given block up to epoch’s start.
This is prohibitively expensive. Especially as we’re calling the get_validator_info method every ten seconds when we’re outputting stats to the log. (The statistics are used to update validators blocks/chunks produced/expected Prometheus metrics).
We might want to change the code such that the method are fast (at least in amortised sense) or we error out when computation is too expensive. Whether returning an error is possible in every situation should be checked first though.
I’m actually not sure if I’m gonna have time to work on this anytime soon. Let’s leave it unassigned for now. The PR I’ve sent was just a quick fix for an issue the described behaviour is causing.