Consensys/teku

Compile-time `ChannelInterface` subscription check

Opened this issue · 4 comments

When we introduce classes implementing a channel (ie SlotEventsChannel), we could forget to subscribe it during initialization (ie #8128)
So we end up implementing and passing all the unit tests (ie onSlot) but at runtime the class will never receive the events.

We should make sure (via an errorprone plugin or something) that the class instance get subscribed in production code (most of the time happens in BeaconChainController but is not always the case)

Maybe some reflection stuff like we have for checking that channels have methods returning only void/Safefuture

Another option could be

  • adding trace logging in EventChannels
  • get the list of all channels (from reflection?)
  • make an acceptance test on proposing node log that all getPublisher classes have subscribers (will need to enable few options or ignore few channels)

It could also check the order of subscriptions being before getPublisher (which is not true at the moment, but it would be good).

WRT the order, I think it might be a nice to have but the design of it explicitly allow late subscription (It is a feature, 'cose you may want to have different services in different modules initializing independently and async).
But in place where order can be followed, agree that it's a good thing to avoid missing events at initialization time.

Yeah, I understand that part of init is async, some things could be subscribed later etc, but for core startup subscriptions wrong order could lead to miss of events. Just thinking aloud as hit it today.