HeaderSyncService#Start Overly Complex
Finding 005 - HeaderSyncService#Start Overly Complex
ID
005
Finding
HeaderSyncService#Start Overly Complex
Severity
2 - Informational
Description
The HeaderSyncService#Start method is rather complex and large. It is responsible for many tasks such as starting and subscribing to a subscriber, starting the header store, P2P logic, creating a syncer and evaluating P2P responses. In addition, the method is not very well documented.In the case this method is bug-prone or problematic or even needs to be updated in the future, it might be difficult for developers to truly understand and debug root causes.
Recommendation
We recommend splitting up the method into simpler, more testable methods, each that are clearly documented and well tested.In addition, Start should take a Context in order for the caller to manage the lifecycle of the call in a predictable manner.
Code References
https://github.com/rollkit/rollkit/blob/eccdd0f1793a5ac532011ef4d896de9e0d8bcb9d/block/header_sync.go#L121