teku icon indicating copy to clipboard operation
teku copied to clipboard

Compile-time `ChannelInterface` subscription check

Open tbenr opened this issue 2 years ago • 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)

tbenr avatar Apr 16 '24 08:04 tbenr

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

zilm13 avatar Apr 16 '24 15:04 zilm13

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).

zilm13 avatar Apr 16 '24 18:04 zilm13

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.

tbenr avatar Apr 16 '24 19:04 tbenr

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.

zilm13 avatar Apr 16 '24 20:04 zilm13