EspressoSystems / hotshot-query-service

Generic query service for HotShot applications
https://espressosystems.github.io/hotshot-query-service/
GNU General Public License v3.0
5 stars 1 forks source link

Add endpoint to evaluate leader performance based on onchain data #709

Open jbearer opened 1 month ago

jbearer commented 1 month ago

At the moment, we track performance by looking at view timeout logs (view timed out, $.fields.leader gives the node who should have been driving that view). This information is also inferable from looking at the chain, although there is not a nice collated endpoint right now. But the way we would do it is look at decided leaves (e.g. https://query.decaf.testnet.espresso.network/v0/availability/leaf/100 or https://query.decaf.testnet.espresso.network/v0/availability/stream/leaves), look at $.leaf.view_number to see views which are successful, then figuring out which views we aren't seeing to find unsuccessful views, and finally mapping view number back to leader by taking view number mod 100 (total number of nodes) and indexing into the stake table (https://query.decaf.testnet.espresso.network/v0/config/hotshot, $.config.known_nodes_with_stake)

We can make a better endpoint for pulling this data. Th interface should look like GET /node/leader-performance/:pubkey/:from/:to with :from and :to being unix timestamps specifying the window of interest, and returning a float in [0, 1] indicating the fraction of views in that window where that leader was successful. We can also include for convenience an endpoint GET /node/leader-performance/:pubkey/:from where :from indicates a number of seconds back from the current time.