Skip to content
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

fixup! Split the Peer in two (#1347) #1357

Merged
merged 10 commits into from
Mar 30, 2020
Merged

fixup! Split the Peer in two (#1347) #1357

merged 10 commits into from
Mar 30, 2020

Conversation

pm47
Copy link
Member

@pm47 pm47 commented Mar 25, 2020

No description provided.

@pm47 pm47 requested a review from t-bast March 25, 2020 20:20
@codecov-io
Copy link

codecov-io commented Mar 25, 2020

Codecov Report

Merging #1357 into master will increase coverage by 0.06%.
The diff coverage is 83.87%.

@@            Coverage Diff             @@
##           master    #1357      +/-   ##
==========================================
+ Coverage   86.29%   86.36%   +0.06%     
==========================================
  Files         119      119              
  Lines        9201     9225      +24     
  Branches      396      402       +6     
==========================================
+ Hits         7940     7967      +27     
+ Misses       1261     1258       -3     
Impacted Files Coverage Δ
...ore/src/main/scala/fr/acinq/eclair/io/Server.scala 89.47% <ø> (-0.53%) ⬇️
...-core/src/main/scala/fr/acinq/eclair/io/Peer.scala 83.70% <76.19%> (-0.51%) ⬇️
...air-core/src/main/scala/fr/acinq/eclair/Logs.scala 91.48% <100.00%> (+3.73%) ⬆️
...src/main/scala/fr/acinq/eclair/io/Monitoring.scala 100.00% <100.00%> (ø)
...main/scala/fr/acinq/eclair/io/PeerConnection.scala 85.23% <100.00%> (+0.14%) ⬆️
...in/scala/fr/acinq/eclair/io/ReconnectionTask.scala 91.83% <100.00%> (+0.17%) ⬆️
...rc/main/scala/fr/acinq/eclair/io/Switchboard.scala 82.35% <100.00%> (+1.10%) ⬆️
...src/main/scala/fr/acinq/eclair/router/Router.scala 92.65% <100.00%> (ø)
...ore/src/main/scala/fr/acinq/eclair/io/Client.scala 63.63% <0.00%> (-0.65%) ⬇️
...clair/payment/send/MultiPartPaymentLifecycle.scala 97.70% <0.00%> (-0.58%) ⬇️
... and 4 more

@@ -21,8 +21,10 @@ import kamon.Kamon
object Monitoring {

object Metrics {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably also instrument the reconnection tasks? Maybe a counter for successful/failed reconnections?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah

@@ -456,7 +467,7 @@ object PeerConnection {
sealed trait Data
sealed trait HasTransport extends Data { def transport: ActorRef }
case object Nothing extends Data
case class AuthenticatingData(pendingAuth: PendingAuth, transport: ActorRef) extends Data
case class AuthenticatingData(pendingAuth: PendingAuth, transport: ActorRef) extends Data with HasTransport
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: HasTransport already extends Data, so you don't need extends Data with HasTransport (and same below).

Copy link
Member Author

@pm47 pm47 Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, that's because I have used the cake pattern too much. Actually that's a perfect fit for the cake pattern and I could have defined HasTransport that way:

sealed trait HasTransport { this: Data => def transport: ActorRef }

wdyt @sstone?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with df54c28

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does that cake pattern bring here (apart from being less explicit than sealed trait HasTransport extends Data)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much: it conveys the idea that HasTransport is just a behavior and not a definition, which is closer to how I see it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I'm not very familiar with that pattern

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words you have to use Data with HasTransport, you can't use HasTransport by itself.

@pm47
Copy link
Member Author

pm47 commented Mar 27, 2020

What do you guys think of removing the Authenticated/InitializeConnection dance between the PeerConnection and the Switchboard?

Meaning going from:

 PeerConnection        Switchboard              Peer
       |                    |                    |
       |   Authenticated    |                    |
       |------------------->|                    |
       |                    |                    |
       |   InitializeConn   |                    |
       |<-------------------|                    |
       |                    |                    |
       |                                         |
       |           ConnectionReady               |
       |---------------------------------------->|
       |                                         |
       |           LightningMessage              |
       |---------------------------------------->|
       |---------------------------------------->|
       |---------------------------------------->|
       |                                         |
       |                                         |

to:

 PeerConnection        Switchboard              Peer
       |                    |                    |
       |  ConnectionReady   |                    |
       |------------------->|  ConnectionReady   |
       |                    |------------------->|
       |  LightningMessage  |                    |
       |------------------->|  LightningMessage  |
       |                    |------------------->|
       |  LightningMessage  |                    |
       |------------------->|  LightningMessage  |
       |                    |------------------->|

Tradeoff being that the flow is simpler, but all messages have to go through the Switchboard, meaning that they also need to be encapsulated in an envelope message containing the remoteNodeId.

@t-bast
Copy link
Member

t-bast commented Mar 27, 2020

I prefer how it is now. It's really not much code and avoids too much forwarding and encapsulating.
The switchboard acts as a manager during the authentication and then gets out of the way, I think this is its job.

@t-bast
Copy link
Member

t-bast commented Mar 27, 2020

Apart from that, I'm in favor on merging this PR once the HasTransport thing is settled to get this fixup in eclair-0.3.4!

@pm47
Copy link
Member Author

pm47 commented Mar 27, 2020

I prefer how it is now. It's really not much code and avoid too much forwarding and encapsulating.
The switchboard acts as a manager during the authentication and then gets out of the way, I think this is its job.

Gave it a try with 27c7e68.

peer forward p

case p: Peer.PeerMessage =>
// we create a peer if it doesn't exist
Copy link
Member

@t-bast t-bast Mar 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never have to create one here, right?
Are there unwanted side-effects if we do (some assumption each of the FSMs make about the other FSMs)?
Shouldn't we reject those messages if we don't have a peer actor to handle it?

It feels to me that the peer FSMs already have to know about the other FSMs and assume some of their behavior, and this change is making it slightly worse...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never have to create one here, right?

Correct, this is only needed in the handler for PeerConnection.ConnectionReady.

It feels to me that the peer FSMs already have to know about the other FSMs and assume some of their behavior, and this change is making it slightly worse...

There has to be an interface contract, even if it less explicit with (untyped) actors. If anything the interface is a bit simpler now. But let's revert this and we can revisit later.

@pm47 pm47 merged commit 90b7fed into master Mar 30, 2020
@pm47 pm47 deleted the fix-peer branch March 30, 2020 09:05
pm47 added a commit that referenced this pull request Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants