mirror of
https://github.com/ACINQ/eclair.git
synced 2025-03-13 11:35:47 +01:00
Set channel capacity in balance update method
And fix test.
This commit is contained in:
parent
7554711246
commit
8b26e8afce
5 changed files with 36 additions and 28 deletions
5
commit.md
Normal file
5
commit.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
Add more splice RBF reconnection tests
|
||||
|
||||
We add more tests around disconnection in the middle of signing an RBF
|
||||
attempt, and verify more details of the `channel_reestablish` message
|
||||
sent on reconnection.
|
|
@ -805,6 +805,8 @@ case class Commitments(params: ChannelParams,
|
|||
val remoteCommitIndex = active.head.remoteCommit.index
|
||||
val nextRemoteCommitIndex = remoteCommitIndex + 1
|
||||
|
||||
// While we have multiple active commitments, we use the most restrictive one.
|
||||
val capacity = active.map(_.capacity).min
|
||||
lazy val availableBalanceForSend: MilliSatoshi = active.map(_.availableBalanceForSend(params, changes)).min
|
||||
lazy val availableBalanceForReceive: MilliSatoshi = active.map(_.availableBalanceForReceive(params, changes)).min
|
||||
|
||||
|
|
|
@ -420,9 +420,9 @@ object Router {
|
|||
def getBalanceSameSideAs(u: ChannelUpdate): Option[MilliSatoshi] = if (u.channelFlags.isNode1) meta_opt.map(_.balance1) else meta_opt.map(_.balance2)
|
||||
def updateChannelUpdateSameSideAs(u: ChannelUpdate): PublicChannel = if (u.channelFlags.isNode1) copy(update_1_opt = Some(u)) else copy(update_2_opt = Some(u))
|
||||
def updateBalances(commitments: Commitments): PublicChannel = if (commitments.localNodeId == ann.nodeId1) {
|
||||
copy(meta_opt = Some(ChannelMeta(commitments.availableBalanceForSend, commitments.availableBalanceForReceive)))
|
||||
copy(capacity = commitments.capacity, meta_opt = Some(ChannelMeta(commitments.availableBalanceForSend, commitments.availableBalanceForReceive)))
|
||||
} else {
|
||||
copy(meta_opt = Some(ChannelMeta(commitments.availableBalanceForReceive, commitments.availableBalanceForSend)))
|
||||
copy(capacity = commitments.capacity, meta_opt = Some(ChannelMeta(commitments.availableBalanceForReceive, commitments.availableBalanceForSend)))
|
||||
}
|
||||
def applyChannelUpdate(update: Either[LocalChannelUpdate, RemoteChannelUpdate]): PublicChannel = update match {
|
||||
case Left(lcu) => updateChannelUpdateSameSideAs(lcu.channelUpdate).updateBalances(lcu.commitments)
|
||||
|
|
|
@ -626,7 +626,7 @@ object Validation {
|
|||
def handleAvailableBalanceChanged(d: Data, e: AvailableBalanceChanged)(implicit log: LoggingAdapter): Data = {
|
||||
val (publicChannels1, graphWithBalances1) = e.shortIds.real.toOption.flatMap(d.channels.get) match {
|
||||
case Some(pc) =>
|
||||
val pc1 = pc.updateBalances(e.commitments).copy(capacity = e.commitments.latest.capacity)
|
||||
val pc1 = pc.updateBalances(e.commitments)
|
||||
log.debug("public channel balance updated: {}", pc1)
|
||||
val update_opt = if (e.commitments.localNodeId == pc1.ann.nodeId1) pc1.update_1_opt else pc1.update_2_opt
|
||||
val graphWithBalances1 = update_opt.map(u => d.graphWithBalances.addEdge(GraphEdge(u, pc1))).getOrElse(d.graphWithBalances)
|
||||
|
|
|
@ -38,7 +38,7 @@ import fr.acinq.eclair.router.RouteCalculationSpec.{DEFAULT_AMOUNT_MSAT, DEFAULT
|
|||
import fr.acinq.eclair.router.Router._
|
||||
import fr.acinq.eclair.transactions.Scripts
|
||||
import fr.acinq.eclair.wire.protocol._
|
||||
import fr.acinq.eclair.{BlockHeight, CltvExpiryDelta, Features, MilliSatoshi, MilliSatoshiLong, RealShortChannelId, ShortChannelId, TestConstants, TimestampSecond, randomBytes32, randomKey}
|
||||
import fr.acinq.eclair.{BlockHeight, CltvExpiryDelta, Features, MilliSatoshiLong, RealShortChannelId, ShortChannelId, TestConstants, TimestampSecond, randomBytes32, randomKey}
|
||||
import org.scalatest.Inside.inside
|
||||
import scodec.bits._
|
||||
|
||||
|
@ -1007,19 +1007,19 @@ class RouterSpec extends BaseRouterSpec {
|
|||
|
||||
{
|
||||
// When the local channel comes back online, it will send a LocalChannelUpdate to the router.
|
||||
val balances = Set[Option[MilliSatoshi]](Some(10000 msat), Some(15000 msat))
|
||||
val commitments = CommitmentsSpec.makeCommitments(10000 msat, 15000 msat, a, b, announceChannel = true)
|
||||
val commitments = CommitmentsSpec.makeCommitments(channel_ab.capacity - 50_000_000.msat, 50_000_000 msat, a, b, announceChannel = true)
|
||||
val balances = Set(commitments.availableBalanceForSend, commitments.availableBalanceForReceive)
|
||||
sender.send(router, LocalChannelUpdate(sender.ref, null, scids_ab, b, Some(chan_ab), update_ab, commitments))
|
||||
sender.send(router, GetRoutingState)
|
||||
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)
|
||||
val channel_ab1 = sender.expectMsgType[RoutingState].channels.find(_.ann == chan_ab).get
|
||||
assert(Set(channel_ab1.meta_opt.map(_.balance1), channel_ab1.meta_opt.map(_.balance2)).flatten == balances)
|
||||
// And the graph should be updated too.
|
||||
sender.send(router, Router.GetRouterData)
|
||||
val g = sender.expectMsgType[Data].graphWithBalances.graph
|
||||
val edge_ab = g.getEdge(ChannelDesc(scid_ab, a, b)).get
|
||||
val edge_ba = g.getEdge(ChannelDesc(scid_ab, b, a)).get
|
||||
assert(edge_ab.capacity == channel_ab.capacity && edge_ba.capacity == channel_ab.capacity)
|
||||
assert(balances.contains(edge_ab.balance_opt))
|
||||
assert(edge_ab.capacity == channel_ab1.capacity && edge_ba.capacity == channel_ab1.capacity)
|
||||
assert(edge_ab.balance_opt.contains(commitments.availableBalanceForSend))
|
||||
assert(edge_ba.balance_opt.isEmpty)
|
||||
}
|
||||
|
||||
|
@ -1030,53 +1030,54 @@ class RouterSpec extends BaseRouterSpec {
|
|||
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.
|
||||
val balances = Set[Option[MilliSatoshi]](Some(11000 msat), Some(14000 msat))
|
||||
val commitments = CommitmentsSpec.makeCommitments(11000 msat, 14000 msat, a, b, announceChannel = true)
|
||||
val commitments = CommitmentsSpec.makeCommitments(channel_ab.capacity - 40_000_000.msat, 40_000_000 msat, a, b, announceChannel = true)
|
||||
val balances = Set(commitments.availableBalanceForSend, commitments.availableBalanceForReceive)
|
||||
sender.send(router, LocalChannelUpdate(sender.ref, null, scids_ab, b, Some(chan_ab), update_ab, commitments))
|
||||
sender.send(router, GetRoutingState)
|
||||
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)
|
||||
val channel_ab1 = sender.expectMsgType[RoutingState].channels.find(_.ann == chan_ab).get
|
||||
assert(Set(channel_ab1.meta_opt.map(_.balance1), channel_ab1.meta_opt.map(_.balance2)).flatten == balances)
|
||||
// And the graph should be updated too.
|
||||
sender.send(router, Router.GetRouterData)
|
||||
val g = sender.expectMsgType[Data].graphWithBalances.graph
|
||||
val edge_ab = g.getEdge(ChannelDesc(scid_ab, a, b)).get
|
||||
val edge_ba = g.getEdge(ChannelDesc(scid_ab, b, a)).get
|
||||
assert(edge_ab.capacity == channel_ab.capacity && edge_ba.capacity == channel_ab.capacity)
|
||||
assert(balances.contains(edge_ab.balance_opt))
|
||||
assert(edge_ab.capacity == channel_ab1.capacity && edge_ba.capacity == channel_ab1.capacity)
|
||||
assert(edge_ab.balance_opt.contains(commitments.availableBalanceForSend))
|
||||
assert(edge_ba.balance_opt.isEmpty)
|
||||
}
|
||||
|
||||
{
|
||||
// When HTLCs are relayed through the channel, balance changes are sent to the router.
|
||||
val balances = Set[Option[MilliSatoshi]](Some(12000 msat), Some(13000 msat))
|
||||
val commitments = CommitmentsSpec.makeCommitments(12000 msat, 13000 msat, a, b, announceChannel = true)
|
||||
val commitments = CommitmentsSpec.makeCommitments(channel_ab.capacity - 55_000_000.msat, 55_000_000 msat, a, b, announceChannel = true)
|
||||
val balances = Set(commitments.availableBalanceForSend, commitments.availableBalanceForReceive)
|
||||
sender.send(router, AvailableBalanceChanged(sender.ref, null, scids_ab, commitments))
|
||||
sender.send(router, GetRoutingState)
|
||||
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)
|
||||
val channel_ab1 = sender.expectMsgType[RoutingState].channels.find(_.ann == chan_ab).get
|
||||
assert(Set(channel_ab1.meta_opt.map(_.balance1), channel_ab1.meta_opt.map(_.balance2)).flatten == balances)
|
||||
// And the graph should be updated too.
|
||||
sender.send(router, Router.GetRouterData)
|
||||
val g = sender.expectMsgType[Data].graphWithBalances.graph
|
||||
val edge_ab = g.getEdge(ChannelDesc(scid_ab, a, b)).get
|
||||
val edge_ba = g.getEdge(ChannelDesc(scid_ab, b, a)).get
|
||||
assert(edge_ab.capacity == channel_ab.capacity && edge_ba.capacity == channel_ab.capacity)
|
||||
assert(balances.contains(edge_ab.balance_opt))
|
||||
assert(edge_ab.capacity == channel_ab1.capacity && edge_ba.capacity == channel_ab1.capacity)
|
||||
assert(edge_ab.balance_opt.contains(commitments.availableBalanceForSend))
|
||||
assert(edge_ba.balance_opt.isEmpty)
|
||||
}
|
||||
|
||||
{
|
||||
// Private channels should also update the graph when HTLCs are relayed through them.
|
||||
val balances = Set(4620000 msat, 32620000 msat)
|
||||
val commitments = CommitmentsSpec.makeCommitments(33000000 msat, 5000000 msat, a, g, announceChannel = false)
|
||||
sender.send(router, GetRouterData)
|
||||
val channel_ag = sender.expectMsgType[Data].privateChannels(channelId_ag_private)
|
||||
val commitments = CommitmentsSpec.makeCommitments(channel_ag.meta.balance1 + 10_000_000.msat, channel_ag.meta.balance2 - 10_000_000.msat, a, g, announceChannel = false)
|
||||
sender.send(router, AvailableBalanceChanged(sender.ref, channelId_ag_private, scids_ab, commitments))
|
||||
sender.send(router, Router.GetRouterData)
|
||||
val data = sender.expectMsgType[Data]
|
||||
val channel_ag = data.privateChannels(channelId_ag_private)
|
||||
assert(Set(channel_ag.meta.balance1, channel_ag.meta.balance2) == balances)
|
||||
val channel_ag1 = data.privateChannels(channelId_ag_private)
|
||||
assert(Set(channel_ag1.meta.balance1, channel_ag1.meta.balance2) == Set(commitments.availableBalanceForSend, commitments.availableBalanceForReceive))
|
||||
// And the graph should be updated too.
|
||||
val edge_ag = data.graphWithBalances.graph.getEdge(ChannelDesc(alias_ag_private, a, g)).get
|
||||
assert(edge_ag.capacity == channel_ag.capacity)
|
||||
assert(edge_ag.balance_opt.contains(balances.last))
|
||||
assert(edge_ag.capacity == channel_ag1.capacity)
|
||||
assert(edge_ag.balance_opt.contains(commitments.availableBalanceForSend))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue