-
Notifications
You must be signed in to change notification settings - Fork 268
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
Move router handlers to separate files #1352
Conversation
2fada2b
to
7327b97
Compare
eclair-core/src/main/scala/fr/acinq/eclair/router/RouteCalculationHandlers.scala
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #1352 +/- ##
==========================================
+ Coverage 86.40% 86.64% +0.23%
==========================================
Files 119 123 +4
Lines 9306 9364 +58
Branches 390 384 -6
==========================================
+ Hits 8041 8113 +72
+ Misses 1265 1251 -14
|
eclair-core/src/main/scala/fr/acinq/eclair/router/RouteCalculationHandlers.scala
Outdated
Show resolved
Hide resolved
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.
This is a great clean-up!
I think we can go further, but if we do can you make sure you don't rebase so that we can keep the history of what we've already reviewed (these refactorings take time to properly review, so better to do them only once!).
Or we can choose to do follow-up PRs for some of my comments.
eclair-core/src/test/scala/fr/acinq/eclair/router/BaseRouterSpec.scala
Outdated
Show resolved
Hide resolved
@@ -351,6 +352,7 @@ class PeerConnection(nodeParams: NodeParams, switchboard: ActorRef, router: Acto | |||
setTimer(ResumeAnnouncements.toString, ResumeAnnouncements, IGNORE_NETWORK_ANNOUNCEMENTS_PERIOD, repeat = false) | |||
d.behavior.copy(fundingTxAlreadySpentCount = d.behavior.fundingTxAlreadySpentCount + 1, ignoreNetworkAnnouncement = true) | |||
} | |||
case _ => d.behavior // other rejections are not considered punishable offenses |
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.
Maybe it's worth defining a trait next to GossipDecision
to flag which cases should lead to a connection close?
This way we'll make sure anytime we update the list of potential gossip decisions in router, we correctly flag the new ones?
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.
But we're not doing the exact same action. Another way would be to just replace the case _ =>
catch-all by more precise matchers. Compiler would warn us if we're missing a new type.
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.
But couldn't this catch-all be expressed by a specific trait defined in the router?
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.
Only if the trait meant "should not lead to a connection close".
eclair-core/src/main/scala/fr/acinq/eclair/router/RouteCalculationHandlers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/router/RouteCalculationHandlers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/router/RouteCalculationHandlers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/router/SyncHandlers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/router/SyncHandlers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/router/SyncHandlers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/router/ValidationHandlers.scala
Outdated
Show resolved
Hide resolved
I've moved all static methods to respective handlers file, and also took the opportunity to move router-related types to the As this touches a lot of files and may generate conflicts, I suggest we merge this rather sooner than later. |
eclair-core/src/main/scala/fr/acinq/eclair/router/ValidationHandlers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/router/Monitoring.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/router/RouteCalculationSpec.scala
Outdated
Show resolved
Hide resolved
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.
LGTM, thanks for this!
Also, acknowledge all gossip with a `GossipDecision`.
Also, send Gossip.Decision for discarded stashed updates/nodes on channel validation failure.
Rebased, waiting for review from @sstone. |
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.
At first I did not like passing an akka context to most helper methods, which means they are not "pure", but this makes Router much more readable and it is still possible to tests all side effects cleanly.
A "pure" way of doing this would be to have methods that return the new state and all side effects but we would need to model them all (ack message, reply to sender, publish event, send message to self, send message to another actor...) and it's probably overkill for now but I'll open an issue to keep that in mind.
I completely agree with @sstone, that was exactly my reaction too :) |
This build on #1347.
The goal is to simplify the router by moving handlers to dedicated stateless functions in separated files, for syncing, announcement validation, route calculation, etc. That's quite a big change, but it's very repetitive.
Also, all gossip messages are now acknowledged by the router with a
GossipDecision
reply.