Skip to content

Commit

Permalink
Add a case object to get router data (#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
akumaigorodski authored Nov 2, 2020
1 parent 1f90e5b commit 366f9be
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import akka.actor.{Actor, ActorLogging, ActorRef, Props}
import fr.acinq.bitcoin.Crypto.PublicKey
import fr.acinq.eclair.crypto.Sphinx.DecryptedFailurePacket
import fr.acinq.eclair.payment.{PaymentEvent, PaymentFailed, RemoteFailure}
import fr.acinq.eclair.router.Announcements
import fr.acinq.eclair.router.Router.{Data, PublicChannel}
import fr.acinq.eclair.router.{Announcements, Router}
import fr.acinq.eclair.wire.IncorrectOrUnknownPaymentDetails
import fr.acinq.eclair.{LongToBtcAmount, NodeParams, randomBytes32, secureRandom}

Expand All @@ -38,16 +37,16 @@ class Autoprobe(nodeParams: NodeParams, router: ActorRef, paymentInitiator: Acto
import scala.concurrent.ExecutionContext.Implicits.global

// refresh our map of channel_updates regularly from the router
context.system.scheduler.schedule(0 seconds, ROUTING_TABLE_REFRESH_INTERVAL, router, Symbol("data"))
context.system.scheduler.schedule(0 seconds, ROUTING_TABLE_REFRESH_INTERVAL, router, Router.GetRouterData)

override def receive: Receive = {
case routingData: Data =>
case routingData: Router.Data =>
scheduleProbe()
context become main(routingData)
}

def main(routingData: Data): Receive = {
case routingData: Data =>
def main(routingData: Router.Data): Receive = {
case routingData: Router.Data =>
context become main(routingData)

case TickProbe =>
Expand Down Expand Up @@ -87,11 +86,11 @@ object Autoprobe {

object TickProbe

def pickPaymentDestination(nodeId: PublicKey, routingData: Data): Option[PublicKey] = {
def pickPaymentDestination(nodeId: PublicKey, routingData: Router.Data): Option[PublicKey] = {
// we only pick direct peers with enabled public channels
val peers = routingData.channels
.collect {
case (shortChannelId, c@PublicChannel(ann, _, _, Some(u1), _, _))
case (shortChannelId, c@Router.PublicChannel(ann, _, _, Some(u1), _, _))
if c.getNodeIdSameSideAs(u1) == nodeId && Announcements.isEnabled(u1.channelFlags) && routingData.channels.exists(_._1 == shortChannelId) => ann.nodeId2 // we only consider outgoing channels that are enabled and announced
}
if (peers.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Router(val nodeParams: NodeParams, watcher: ActorRef, initialized: Option[
sender ! updates
stay

case Event(Symbol("data"), d) =>
case Event(GetRouterData, d) =>
sender ! d
stay

Expand Down Expand Up @@ -465,6 +465,7 @@ object Router {
case class RoutingState(channels: Iterable[PublicChannel], nodes: Iterable[NodeAnnouncement])
case object GetRoutingStateStreaming
case object RoutingStateStreamingUpToDate
case object GetRouterData
// @formatter:on

// @formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ class RouterSpec extends BaseRouterSpec {
val channel_ab = sender.expectMsgType[RoutingState].channels.find(_.ann == chan_ab).get
assert(Set(channel_ab.meta_opt.map(_.balance1), channel_ab.meta_opt.map(_.balance2)) === balances)
// And the graph should be updated too.
sender.send(router, Symbol("data"))
sender.send(router, Router.GetRouterData)
val g = sender.expectMsgType[Data].graph
val edge_ab = g.getEdge(ChannelDesc(channelId_ab, a, b)).get
val edge_ba = g.getEdge(ChannelDesc(channelId_ab, b, a)).get
Expand All @@ -586,7 +586,7 @@ class RouterSpec extends BaseRouterSpec {
{
// First we make sure we aren't in the "pending rebroadcast" state for this channel update.
sender.send(router, TickBroadcast)
sender.send(router, Symbol("data"))
sender.send(router, Router.GetRouterData)
assert(sender.expectMsgType[Data].rebroadcast.updates.isEmpty)

// Then we update the balance without changing the contents of the channel update; the graph should still be updated.
Expand All @@ -597,7 +597,7 @@ class RouterSpec extends BaseRouterSpec {
val channel_ab = sender.expectMsgType[RoutingState].channels.find(_.ann == chan_ab).get
assert(Set(channel_ab.meta_opt.map(_.balance1), channel_ab.meta_opt.map(_.balance2)) === balances)
// And the graph should be updated too.
sender.send(router, Symbol("data"))
sender.send(router, Router.GetRouterData)
val g = sender.expectMsgType[Data].graph
val edge_ab = g.getEdge(ChannelDesc(channelId_ab, a, b)).get
val edge_ba = g.getEdge(ChannelDesc(channelId_ab, b, a)).get
Expand All @@ -615,7 +615,7 @@ class RouterSpec extends BaseRouterSpec {
val channel_ab = sender.expectMsgType[RoutingState].channels.find(_.ann == chan_ab).get
assert(Set(channel_ab.meta_opt.map(_.balance1), channel_ab.meta_opt.map(_.balance2)) === balances)
// And the graph should be updated too.
sender.send(router, Symbol("data"))
sender.send(router, Router.GetRouterData)
val g = sender.expectMsgType[Data].graph
val edge_ab = g.getEdge(ChannelDesc(channelId_ab, a, b)).get
val edge_ba = g.getEdge(ChannelDesc(channelId_ab, b, a)).get
Expand All @@ -629,7 +629,7 @@ class RouterSpec extends BaseRouterSpec {
val balances = Set(33000000 msat, 5000000 msat)
val commitments = CommitmentsSpec.makeCommitments(33000000 msat, 5000000 msat, a, g, announceChannel = false)
sender.send(router, AvailableBalanceChanged(sender.ref, null, channelId_ag, commitments))
sender.send(router, Symbol("data"))
sender.send(router, Router.GetRouterData)
val data = sender.expectMsgType[Data]
val channel_ag = data.privateChannels(channelId_ag)
assert(Set(channel_ag.meta.balance1, channel_ag.meta.balance2) === balances)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class RoutingSyncSpec extends TestKitBaseClass with AnyFunSuiteLike with Paralle
val qcr = pipe.expectMsgType[QueryChannelRange]
pipe.send(tgt, PeerRoutingMessage(pipe.ref, srcId, qcr))
// this allows us to know when the last reply_channel_range has been set
pipe.send(tgt, 'data)
pipe.send(tgt, Router.GetRouterData)
// tgt answers with reply_channel_ranges
val rcrs = pipe.receiveWhile() {
case rcr: ReplyChannelRange => rcr
Expand Down

0 comments on commit 366f9be

Please sign in to comment.