Smart contract events

Hi, I need a dev to take a look at this problem.
I’ve tried in a couple of ways and I’m starting to think that either I’m misunderstanding something or there is a problem in how you emit events in your smart contract(Matterhorn)

Basically, what I’ve found is that there is a mistmatch in the subgraph depending on which events you watch, specifically in the number of channels opened. I’ve deployed 2 subgraphs to demonstrate the issue, this is your subgraph (from hopr community) thegraph (dot) com/hosted-service/subgraph/eliaxie/hopr-channels (approx 2500 open channels) and this is the one I’ve developed thegraph (dot) com/hosted-service/subgraph/eliaxie/hopr-subgraph-v2 (approx 500 open channels).

So, what’s the code behind them
for the first one, I’ve deployed directly this github(dot)com/hoprnet/hopr-community/tree/main/subgraph-channels
For the second one I’ve got 2 version, 1 that I wrote myself and found the approx 500 entities and then to double check I’ve taken your code (the one for the first subgraph) and split it in ChannelOpened and ChannelClosureInitiated instead of watching channelUpdate, as you can see here github(dot)com/Eliaxie/HoprSubgraph/blob/main/src/mapping.ts
The result is that even with basically the same code from the first subgraph (I’ve just replicated the two parts, removed some parameters in the nodes which was impossible to get from those 2 events, and splitted the logic in the 2 events instead of channelUpdated), we have 500 instead of 2500 open channels on the subgraph. As I’m developing the subgraph to be used inside a bounty, I’m not sure which one to use

Thanks @Eliaxie, it was nice exchanging with you directly on TG. I’m summarising our discussion here for documentation’s purpose.
tl;dr
The discrepancy comes from the definition of “ChannelOpened”. It may seem like ChannelOpened represents the status of a channel is “OPEN”. However, this event only gets triggered when an “open channel” action is called, which corresponds to the case where a channel has been previously opened and gets opened again (i.e. the action that brings channel from “CLOSED” status to “OPEN” status).

The clarity with regard to when ChannelOpened should be emitted is not sufficient in the current smart contract implementation. An issue is created and will be included in the next smart contract upgrade.