livepeer / livepeer-monorepo

JavaScript tools and applications that interact with Livepeer's smart contracts and peer-to-peer network
https://livepeer.org
MIT License
167 stars 71 forks source link

subgraph: active field for Transcoder entity should not be set in TranscoderActivated/Deactivated event handlers #929

Closed yondonfu closed 3 years ago

yondonfu commented 3 years ago

Describe the bug (required) A clear and concise description of what the bug is.

At the moment, for the Transcoder entity, the active field field is set to true when the TranscoderActivated event is emitted and to false when the TranscoderDeactivated event is emitted. However, a transcoder only becomes active in the round after the TranscoderActivated event is emitted and inactive in the round after the TranscoderDeactivated event is emitted (this is a bit confusing...I know :/). As a result, if someone sends a GraphQL query with where: { active: true } expecting to get only active transcoders, they might receive transcoders that are actually still inactive (i.e. pending activation).

I think this could be resolved by setting the active field in the NewRound handler. As the handler loops through the on-chain transcoder pool, it can check if the transcoder's activation round <= currentRound < transcoder's deactivation round and if so set active = true, else set active = false.

adamsoffer commented 3 years ago

ah that's right. I'll submit a PR with a fix. Sounds like a straight forward fix.