-
Notifications
You must be signed in to change notification settings - Fork 6
Refactor LongRunningService and use PeriodicPollingService #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # app/src/integrationTest/kotlin/maru/app/MaruPeerScoringTest.kt
19ad0d4 to
1f2484d
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #469 +/- ##
============================================
+ Coverage 83.44% 83.75% +0.30%
- Complexity 1119 1131 +12
============================================
Files 227 227
Lines 8077 8075 -2
Branches 629 621 -8
============================================
+ Hits 6740 6763 +23
+ Misses 1001 989 -12
+ Partials 336 323 -13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
| override val period: Duration, | ||
| override val task: Runnable, | ||
| ) : Timer { | ||
| override val errorHandler: (Throwable) -> Unit = { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestablePeriodicTimer would benefit from having errorHandling lambda in the constructor defaulted to {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handler is never used inside the TestablePeriodicTimer, so it doesn't make sense to have it in the constructor. The timer task is manually invoked in this timer and it is not wrapped in any try-catch with error handling.
jvm-libs/test-utils/src/main/kotlin/testutils/maru/TestablePeriodicTimer.kt
Outdated
Show resolved
Hide resolved
|
|
||
| checkAndHandleForkTransition() | ||
|
|
||
| poller.start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Timer starts uncontrolled, risking system integrity.
The start() method lacks a guard to prevent multiple invocations, allowing the timer to be started repeatedly. The previous implementation checked if poller != null before starting, but this refactoring removed that protection. Multiple calls to start() will now start the same timer multiple times, causing the pollTask() to execute at an incorrect frequency and potentially leading to race conditions in fork transition logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gauravahuja can you please take a look at this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks poitless comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is pointless, start is idempotent
|
|
||
| checkAndHandleForkTransition() | ||
|
|
||
| poller.start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Repeated Starts Lead To Unpredictable Behavior.
The start() method lacks idempotency protection. The old implementation checked if poller was already running before starting, but the refactored version removed this guard. Since start() can be called multiple times (e.g., via the onBeaconSyncComplete callback at line 61), calling poller.start() repeatedly may cause undefined behavior depending on the timer implementation. The method needs to track whether the poller is already started and return early on subsequent calls.
|
|
||
| poller?.cancel() | ||
| poller = null | ||
| poller.stop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Idempotency Failure in pause() Method
The pause() method lacks idempotency protection. The old implementation checked if the poller was null before stopping it, but the refactored version removed this guard. Since pause() can be called multiple times (e.g., via the onClSyncStatusUpdate callback at line 56, or through close() which calls pause()), calling poller.stop() repeatedly may cause undefined behavior depending on the timer implementation. The method needs to track whether the poller is already stopped and return early on subsequent calls.
Note
Switches services to async start/stop and shared timer/polling abstractions, propagating through app, API, consensus/sync, P2P, and tests with optional Vertx timers and updated dependencies.
LongRunningServiceto async (CompletableFuture), typealias to Linea impl; updateNoOpLongRunningService.TimerFactory) andPeriodicPollingServiceacross components.ProtocolStarterto useTimerFactory(fixed-rate poller).ELSyncServiceandPeerChainTrackertoPeriodicPollingServicewith async lifecycle.CLSyncServiceImpllifecycle to async futures.LineaFinalizationProvidertoPeriodicPollingService.P2PNetworkImpl: async stop flow; plumbTimerFactory.MaruDiscoveryService: async lifecycle; replaceTimerwithTimerFactorypoller; add ENR updates.ApiServernow extendsLongRunningService;ApiServerImpl.start/stopreturn futures.MaruApporchestrates services via async start/stop;MaruAppCliawaits.get().MaruAppFactory: wireTimerFactory(VertxTimerFactoryvsJvmTimerFactory) via new configuseVertxTimers; pass through to P2P/Sync/Finalization/Protocol.MaruConfig.useVertxTimersflag..start().get()/.stop().get(); addTestablePeriodicTimerFactory; update helpers and stacks accordingly.build.linea.internal:long-running-serviceacross modules; bump Linea libs version; minor gradle wiring.Written by Cursor Bugbot for commit 16b3ef9. This will update automatically on new commits. Configure here.