Skip to content

Commit

Permalink
Routing: don't request their channel ids if we don't want a routing t…
Browse files Browse the repository at this point in the history
…able dump
  • Loading branch information
sstone committed Sep 19, 2018
1 parent 448a1e4 commit 19f0c81
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
11 changes: 8 additions & 3 deletions eclair-core/src/main/scala/fr/acinq/eclair/io/Peer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Peer(nodeParams: NodeParams, remoteNodeId: PublicKey, authenticator: Actor
when(INITIALIZING) {
case Event(remoteInit: wire.Init, InitializingData(address_opt, transport, channels, origin_opt)) =>
transport ! TransportHandler.ReadAck(remoteInit)
val localHasInitialRoutingSync = Features.hasFeature(nodeParams.localFeatures, Features.INITIAL_ROUTING_SYNC_BIT_OPTIONAL)
val remoteHasInitialRoutingSync = Features.hasFeature(remoteInit.localFeatures, Features.INITIAL_ROUTING_SYNC_BIT_OPTIONAL)
val remoteHasChannelRangeQueriesOptional = Features.hasFeature(remoteInit.localFeatures, Features.CHANNEL_RANGE_QUERIES_BIT_OPTIONAL)
val remoteHasChannelRangeQueriesMandatory = Features.hasFeature(remoteInit.localFeatures, Features.CHANNEL_RANGE_QUERIES_BIT_MANDATORY)
Expand All @@ -110,9 +111,13 @@ class Peer(nodeParams: NodeParams, remoteNodeId: PublicKey, authenticator: Actor
router ! GetRoutingState
}
}
if (remoteHasChannelRangeQueriesOptional || remoteHasChannelRangeQueriesMandatory) {
// if they support channel queries, always ask for their filter
router ! SendChannelQuery(remoteNodeId, transport)
if (localHasInitialRoutingSync) {
// if we want a routing table dump and do not support range queries they will send it to us
// but if we do support range queries we have to ask, this mirrors the behaviour above
if (remoteHasChannelRangeQueriesOptional || remoteHasChannelRangeQueriesMandatory) {
// if they support channel queries, ask for their filter
router ! SendChannelQuery(remoteNodeId, transport)
}
}

// let's bring existing/requested channels online
Expand Down
37 changes: 35 additions & 2 deletions eclair-core/src/test/scala/fr/acinq/eclair/io/PeerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import java.net.InetSocketAddress

import akka.actor.ActorRef
import akka.testkit.TestProbe
import fr.acinq.bitcoin.Block
import fr.acinq.bitcoin.{BinaryData, Block}
import fr.acinq.eclair.TestConstants._
import fr.acinq.eclair.blockchain.EclairWallet
import fr.acinq.eclair.crypto.TransportHandler
import fr.acinq.eclair.io.Peer.ResumeAnnouncements
import fr.acinq.eclair.router.RoutingSyncSpec.makeFakeRoutingInfo
import fr.acinq.eclair.router.{ChannelRangeQueries, ChannelRangeQueriesSpec, Rebroadcast, RouteCalculationSpec}
import fr.acinq.eclair.router._
import fr.acinq.eclair.{ShortChannelId, TestkitBaseClass, randomKey, wire}
import org.junit.runner.RunWith
import org.scalatest.Outcome
Expand Down Expand Up @@ -143,4 +143,37 @@ class PeerSpec extends TestkitBaseClass {
}
transport.expectNoMsg(1 second) // peer hasn't acknowledged the messages
}

test("send channel queries if local feature 'initial_routing_sync' is set") { probe =>
val authenticator = TestProbe()
val watcher = TestProbe()
val router = TestProbe()
val relayer = TestProbe()
val connection = TestProbe()
val transport = TestProbe()
val wallet: EclairWallet = null // unused
val remoteNodeId = Bob.nodeParams.nodeId
val peer = system.actorOf(Peer.props(Alice.nodeParams.copy(localFeatures = BinaryData("8a")), remoteNodeId, authenticator.ref, watcher.ref, router.ref, relayer.ref, wallet))
probe.send(peer, Peer.Init(None, Set()))
probe.send(peer, Authenticator.Authenticated(null, transport.ref, remoteNodeId, InetSocketAddress.createUnresolved("localhost", 9735), false, None))
probe.send(peer, wire.Init(BinaryData.empty, BinaryData("8a")))
router.expectMsgType[SendChannelQuery]
}

test("don't send channel queries if local feature 'initial_routing_sync' is not set") { probe =>
val authenticator = TestProbe()
val watcher = TestProbe()
val router = TestProbe()
val relayer = TestProbe()
val connection = TestProbe()
val transport = TestProbe()
val wallet: EclairWallet = null // unused
val remoteNodeId = Bob.nodeParams.nodeId
// 0x82 means that we support channel range queries and data loss protection but do not want a routing table dump
val peer = system.actorOf(Peer.props(Alice.nodeParams.copy(localFeatures = BinaryData("82")), remoteNodeId, authenticator.ref, watcher.ref, router.ref, relayer.ref, wallet))
probe.send(peer, Peer.Init(None, Set()))
probe.send(peer, Authenticator.Authenticated(null, transport.ref, remoteNodeId, InetSocketAddress.createUnresolved("localhost", 9735), false, None))
probe.send(peer, wire.Init(BinaryData.empty, BinaryData("8a")))
router.expectNoMsg(3 second)
}
}

0 comments on commit 19f0c81

Please sign in to comment.