1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-23 14:40:34 +01:00

Improve error handling when we couldn't find all the channels for a supplied route in /sendtoroute API (#1142)

* Improve error handling when we couldn't find all the channels for a supplied route in /sendtoroute
This commit is contained in:
araspitzu 2019-09-20 16:09:52 +02:00 committed by GitHub
parent 401c996a69
commit b5461b80c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View file

@ -476,10 +476,15 @@ class Router(val nodeParams: NodeParams, watcher: ActorRef, initialized: Option[
stay stay
case Event(FinalizeRoute(partialHops), d) => case Event(FinalizeRoute(partialHops), d) =>
// split into sublists [(a,b),(b,c), ...] then get the edges between each of those pairs, then select the largest edge between them // split into sublists [(a,b),(b,c), ...] then get the edges between each of those pairs
val edges = partialHops.sliding(2).map { case List(v1, v2) => d.graph.getEdgesBetween(v1, v2).maxBy(_.update.htlcMaximumMsat.getOrElse(0 msat)) } partialHops.sliding(2).map { case List(v1, v2) => d.graph.getEdgesBetween(v1, v2) }.toList match {
val hops = edges.map(d => Hop(d.desc.a, d.desc.b, d.update)).toSeq case edges if edges.nonEmpty && edges.forall(_.nonEmpty) =>
sender ! RouteResponse(hops, Set.empty, Set.empty) val selectedEdges = edges.map(_.maxBy(_.update.htlcMaximumMsat.getOrElse(0 msat))) // select the largest edge
val hops = selectedEdges.map(d => Hop(d.desc.a, d.desc.b, d.update))
sender ! RouteResponse(hops, Set.empty, Set.empty)
case _ => // some nodes in the supplied route aren't connected in our graph
sender ! Status.Failure(new IllegalArgumentException("Not all the nodes in the supplied route are connected with public channels"))
}
stay stay
case Event(RouteRequest(start, end, amount, assistedRoutes, ignoreNodes, ignoreChannels, params_opt), d) => case Event(RouteRequest(start, end, amount, assistedRoutes, ignoreNodes, ignoreChannels, params_opt), d) =>

View file

@ -82,6 +82,23 @@ class PaymentLifecycleSpec extends BaseRouterSpec {
awaitCond(paymentDb.getOutgoingPayment(id).exists(_.status.isInstanceOf[OutgoingPaymentStatus.Succeeded])) awaitCond(paymentDb.getOutgoingPayment(id).exists(_.status.isInstanceOf[OutgoingPaymentStatus.Succeeded]))
} }
test("send to route (edges not found in the graph)") { fixture =>
import fixture._
val nodeParams = TestConstants.Alice.nodeParams.copy(keyManager = testKeyManager)
val id = UUID.randomUUID()
val progressHandler = PaymentLifecycle.DefaultPaymentProgressHandler(id, defaultPaymentRequest, nodeParams.db.payments)
val paymentFSM = system.actorOf(PaymentLifecycle.props(nodeParams, progressHandler, router, TestProbe().ref))
val sender = TestProbe()
val eventListener = TestProbe()
system.eventStream.subscribe(eventListener.ref, classOf[PaymentEvent])
val brokenRoute = SendPaymentToRoute(randomBytes32, Seq(randomKey.publicKey, randomKey.publicKey, randomKey.publicKey), FinalLegacyPayload(defaultAmountMsat, defaultExpiryDelta.toCltvExpiry(nodeParams.currentBlockHeight)))
sender.send(paymentFSM, brokenRoute)
val failureMessage = eventListener.expectMsgType[PaymentFailed].failures.head.asInstanceOf[LocalFailure].t.getMessage
assert(failureMessage == "Not all the nodes in the supplied route are connected with public channels")
}
test("payment failed (route not found)") { fixture => test("payment failed (route not found)") { fixture =>
import fixture._ import fixture._
val nodeParams = TestConstants.Alice.nodeParams.copy(keyManager = testKeyManager) val nodeParams = TestConstants.Alice.nodeParams.copy(keyManager = testKeyManager)