livepeer / livepeer-monorepo

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

subgraph: TranscoderDeactivated followed by TranscoderActivated in same round results in inactive transcoder in next round #1027

Closed yondonfu closed 3 years ago

yondonfu commented 3 years ago

The newRound handler processes pending activations from the previous round and then pending deactivations from the previous round. If a TranscoderDeactivated event is emitted in the previous round and then a TranscoderActivated event is emitted in the previous round for the same transcoder address then the pending activation will be processed before the pending deactivation resulting in the active field of the transcoder being set to false. In this case, the active field of the transcoder should be set to true, because the TranscoderDeactivated event was emitted before the TranscoderActivated even in the previous round.

For an example of this bug in the wild, run the following query at https://thegraph.com/hosted-service/subgraph/livepeer/livepeer

{
  transcoders(where:{ id:"0xda43d85b8d419a9c51bbf0089c9bd5169c23f2f9" }) {
    active
    activationRound
    deactivationRound
  }
  transcoderActivatedEvents(where: { delegate: "0xda43d85b8d419a9c51bbf0089c9bd5169c23f2f9" }) {id
    transaction {
      blockNumber
    }
    activationRound
    round {
      id
    }
  }
  transcoderDeactivatedEvents(where: { delegate: "0xda43d85b8d419a9c51bbf0089c9bd5169c23f2f9" }) {
    round {
      id
    }
    transaction {
      blockNumber
    }
    deactivationRound
  }
}

Notice that the active field for the transcoder is set to false when it should be set to true.

The sequence of events that results in the data returned from the above query:

compscidr commented 3 years ago

I believe I may be affected by the same bug - this is a similar query to the one above if it's of any help to reproduce.

{
  transcoders(where:{ id:"0x74ba897f65f04008d8eff364efcc54b0a20e17eb" }) {
    active
    activationRound
    deactivationRound
  }
  transcoderActivatedEvents(where: { delegate: "0x74ba897f65f04008d8eff364efcc54b0a20e17eb" }) {id
    transaction {
      blockNumber
    }
    activationRound
    round {
      id
    }
  }
  transcoderDeactivatedEvents(where: { delegate: "0x74ba897f65f04008d8eff364efcc54b0a20e17eb" }) {
    round {
      id
    }
    transaction {
      blockNumber
    }
    deactivationRound
  }
}
yondonfu commented 3 years ago

@compscidr A fix for this bug has been deployed to the Livepeer subgraph.

compscidr commented 3 years ago

@compscidr A fix for this bug has been deployed to the Livepeer subgraph.

Yes thank you it's been working since the fix was deployed. 🚀