1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-20 02:27:32 +01:00

fixup! Use sender instead of providing actor refs (#1379) (#1386)

When switching to a new connection while already connected, peer
immediately kills the current connection and sends back the
`PeerConnection.ConnectionReady` to itself. Since #1379, the sender of
this message is assumed to be the `PeerConnection` actor. If peer
doesn't preserve the sender by using a `forward` instead of a `tell`, it
will assume that itself is the `PeerConnection`, which will break
everything.
This commit is contained in:
Pierre-Marie Padiou 2020-04-21 16:12:07 +02:00 committed by GitHub
parent e32d9ed99f
commit bff833b1b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -216,7 +216,7 @@ class Peer(val nodeParams: NodeParams, remoteNodeId: PublicKey, switchboard: Act
context unwatch d.peerConnection
d.peerConnection ! PoisonPill
d.channels.values.toSet[ActorRef].foreach(_ ! INPUT_DISCONNECTED) // we deduplicate with toSet because there might be two entries per channel (tmp id and final id)
self ! connectionReady
self forward connectionReady // we preserve the origin
goto(DISCONNECTED) using DisconnectedData(d.channels.collect { case (k: FinalChannelId, v) => (k, v) })
case Event(unhandledMsg: LightningMessage, _) =>

View File

@ -18,7 +18,6 @@ package fr.acinq.eclair.io
import java.net.{InetAddress, ServerSocket}
import akka.actor.FSM.{CurrentState, SubscribeTransitionCallBack, Transition}
import akka.actor.Status.Failure
import akka.testkit.{TestFSMRef, TestProbe}
import com.google.common.net.HostAndPort
@ -38,7 +37,7 @@ import scala.concurrent.duration._
class PeerSpec extends TestkitBaseClass with StateTestsHelperMethods {
val fakeIPAddress = NodeAddress.fromParts("1.2.3.4", 42000).get
val fakeIPAddress: NodeAddress = NodeAddress.fromParts("1.2.3.4", 42000).get
case class FixtureParam(nodeParams: NodeParams, remoteNodeId: PublicKey, switchboard: TestProbe, router: TestProbe, watcher: TestProbe, relayer: TestProbe, peer: TestFSMRef[Peer.State, Peer.Data, Peer], peerConnection: TestProbe)
@ -137,6 +136,33 @@ class PeerSpec extends TestkitBaseClass with StateTestsHelperMethods {
probe.expectMsg("disconnecting")
}
test("handle new connection in state CONNECTED") { f =>
import f._
connect(remoteNodeId, switchboard, peer, peerConnection, channels = Set(ChannelCodecsSpec.normal))
// this is just to extract inits
val Peer.ConnectedData(_, _, localInit, remoteInit, _) = peer.stateData
val peerConnection1 = peerConnection
val peerConnection2 = TestProbe()
val peerConnection3 = TestProbe()
val deathWatch = TestProbe()
deathWatch.watch(peerConnection1.ref)
deathWatch.watch(peerConnection2.ref)
deathWatch.watch(peerConnection3.ref)
peerConnection2.send(peer, PeerConnection.ConnectionReady(remoteNodeId, fakeIPAddress.socketAddress, outgoing = false, localInit, remoteInit))
// peer should kill previous connection
deathWatch.expectTerminated(peerConnection1.ref)
awaitCond(peer.stateData.asInstanceOf[Peer.ConnectedData].peerConnection === peerConnection2.ref)
peerConnection3.send(peer, PeerConnection.ConnectionReady(remoteNodeId, fakeIPAddress.socketAddress, outgoing = false, localInit, remoteInit))
// peer should kill previous connection
deathWatch.expectTerminated(peerConnection2.ref)
awaitCond(peer.stateData.asInstanceOf[Peer.ConnectedData].peerConnection === peerConnection3.ref)
}
test("don't spawn a wumbo channel if wumbo feature isn't enabled") { f =>
import f._