Skip to content

Commit

Permalink
Ignore disabled edges for routing messages
Browse files Browse the repository at this point in the history
Other implementations and Eclair (#2703) disable channels only when the other peer is offline.
So disabled channels should no be used for routing messages.

This PR removes `ActiveEdge` that was introduced in #2656
  • Loading branch information
thomash-acinq committed Oct 2, 2023
1 parent 9ca9227 commit 2d33c9b
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 222 deletions.
2 changes: 0 additions & 2 deletions eclair-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ eclair {
base = 0.6 // when computing the weight for a channel, proportion that stays the same for all channels
channel-age = 0.1 // when computing the weight for a channel, consider its AGE in this proportion
channel-capacity = 0.3 // when computing the weight for a channel, consider its CAPACITY in this proportion

disabled-multiplier = 2.5 // How much we prefer relaying a message along an active channel instead of a disabled one.
}
}

Expand Down
3 changes: 1 addition & 2 deletions eclair-core/src/main/scala/fr/acinq/eclair/NodeParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ object NodeParams extends Logging {
val ratioBase = config.getDouble("ratios.base")
val ratioAge = config.getDouble("ratios.channel-age")
val ratioCapacity = config.getDouble("ratios.channel-capacity")
val disabledMultiplier = config.getDouble("ratios.disabled-multiplier")
MessageRouteParams(maxRouteLength, Graph.MessagePath.WeightRatios(ratioBase, ratioAge, ratioCapacity, disabledMultiplier))
MessageRouteParams(maxRouteLength, Graph.MessagePath.WeightRatios(ratioBase, ratioAge, ratioCapacity))
}

val unhandledExceptionStrategy = config.getString("channel.unhandled-exception-strategy") match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ object EclairInternalsSerializer {
("maxRouteLength" | int32) ::
(("baseFactor" | double) ::
("ageFactor" | double) ::
("capacityFactor" | double) ::
("disabledMultiplier" | double)).as[Graph.MessagePath.WeightRatios]).as[MessageRouteParams]
("capacityFactor" | double)).as[Graph.MessagePath.WeightRatios]).as[MessageRouteParams]

val routerConfCodec: Codec[RouterConf] = (
("watchSpentWindow" | finiteDurationCodec) ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package fr.acinq.eclair.router

import fr.acinq.bitcoin.scalacompat.Crypto.PublicKey
import fr.acinq.bitcoin.scalacompat.{Satoshi, SatoshiLong}
import fr.acinq.eclair.router.Graph.GraphStructure.{DirectedGraph, ActiveEdge}
import fr.acinq.eclair.router.Graph.GraphStructure.{DirectedGraph, GraphEdge}
import fr.acinq.eclair.router.Router.{ChannelDesc, ChannelHop, Route}
import fr.acinq.eclair.wire.protocol.NodeAnnouncement
import fr.acinq.eclair.{MilliSatoshi, MilliSatoshiLong, ShortChannelId, TimestampSecond, TimestampSecondLong, ToMilliSatoshiConversion}
Expand Down Expand Up @@ -179,7 +179,7 @@ case class BalanceEstimate private(low: MilliSatoshi,
def didReceive(amount: MilliSatoshi, timestamp: TimestampSecond): BalanceEstimate =
otherSide.didSend(amount, timestamp).otherSide

def addEdge(edge: ActiveEdge): BalanceEstimate = copy(
def addEdge(edge: GraphEdge): BalanceEstimate = copy(
high = high.max(edge.capacity.toMilliSatoshi),
capacities = capacities.updated(edge.desc.shortChannelId, edge.capacity)
)
Expand Down Expand Up @@ -235,7 +235,7 @@ object BalanceEstimate {
case class BalancesEstimates(balances: Map[(PublicKey, PublicKey), BalanceEstimate], defaultHalfLife: FiniteDuration) {
private def get(a: PublicKey, b: PublicKey): Option[BalanceEstimate] = balances.get((a, b))

def addEdge(edge: ActiveEdge): BalancesEstimates = BalancesEstimates(
def addEdge(edge: GraphEdge): BalancesEstimates = BalancesEstimates(
balances.updatedWith((edge.desc.a, edge.desc.b))(balance =>
Some(balance.getOrElse(BalanceEstimate.empty(defaultHalfLife)).addEdge(edge))
),
Expand Down Expand Up @@ -287,7 +287,7 @@ case class BalancesEstimates(balances: Map[(PublicKey, PublicKey), BalanceEstima
case class GraphWithBalanceEstimates(graph: DirectedGraph, private val balances: BalancesEstimates) {
def addOrUpdateVertex(ann: NodeAnnouncement): GraphWithBalanceEstimates = GraphWithBalanceEstimates(graph.addOrUpdateVertex(ann), balances)

def addEdge(edge: ActiveEdge): GraphWithBalanceEstimates = GraphWithBalanceEstimates(graph.addEdge(edge), balances.addEdge(edge))
def addEdge(edge: GraphEdge): GraphWithBalanceEstimates = GraphWithBalanceEstimates(graph.addEdge(edge), balances.addEdge(edge))

def disableEdge(desc: ChannelDesc): GraphWithBalanceEstimates = GraphWithBalanceEstimates(graph.disableEdge(desc), balances.removeEdge(desc))

Expand Down Expand Up @@ -318,7 +318,7 @@ case class GraphWithBalanceEstimates(graph: DirectedGraph, private val balances:
GraphWithBalanceEstimates(graph, balances.channelCouldNotSend(hop, amount))
}

def canSend(amount: MilliSatoshi, edge: ActiveEdge): Double = {
def canSend(amount: MilliSatoshi, edge: GraphEdge): Double = {
balances.balances.get((edge.desc.a, edge.desc.b)) match {
case Some(estimate) => estimate.canSend(amount)
case None => BalanceEstimate.empty(1 hour).addEdge(edge).canSend(amount)
Expand Down
Loading

0 comments on commit 2d33c9b

Please sign in to comment.