Skip to content

Commit

Permalink
Rename requestedChannelReserve_opt
Browse files Browse the repository at this point in the history
This field only applies to the first funding index, so we rename it to
make that explicit. Once a splice has happened, it will be ignored.
  • Loading branch information
t-bast committed Sep 11, 2023
1 parent 177c801 commit e1f9447
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ case class LocalParams(nodeId: PublicKey,
fundingKeyPath: DeterministicWallet.KeyPath,
dustLimit: Satoshi,
maxHtlcValueInFlightMsat: MilliSatoshi,
requestedChannelReserve_opt: Option[Satoshi],
initialRequestedChannelReserve_opt: Option[Satoshi],
htlcMinimum: MilliSatoshi,
toSelfDelay: CltvExpiryDelta,
maxAcceptedHtlcs: Int,
Expand All @@ -634,7 +634,7 @@ case class LocalParams(nodeId: PublicKey,
case class RemoteParams(nodeId: PublicKey,
dustLimit: Satoshi,
maxHtlcValueInFlightMsat: UInt64, // this is not MilliSatoshi because it can exceed the total amount of MilliSatoshi
requestedChannelReserve_opt: Option[Satoshi],
initialRequestedChannelReserve_opt: Option[Satoshi],
htlcMinimum: MilliSatoshi,
toSelfDelay: CltvExpiryDelta,
maxAcceptedHtlcs: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ case class ChannelParams(channelId: ByteVector32,
channelFlags: ChannelFlags) {

require(channelFeatures.paysDirectlyToWallet == localParams.walletStaticPaymentBasepoint.isDefined, s"localParams.walletStaticPaymentBasepoint must be defined only for commitments that pay directly to our wallet (channel features: $channelFeatures")
require(channelFeatures.hasFeature(Features.DualFunding) == localParams.requestedChannelReserve_opt.isEmpty, "custom local channel reserve is incompatible with dual-funded channels")
require(channelFeatures.hasFeature(Features.DualFunding) == remoteParams.requestedChannelReserve_opt.isEmpty, "custom remote channel reserve is incompatible with dual-funded channels")
require(channelFeatures.hasFeature(Features.DualFunding) == localParams.initialRequestedChannelReserve_opt.isEmpty, "custom local channel reserve is incompatible with dual-funded channels")
require(channelFeatures.hasFeature(Features.DualFunding) == remoteParams.initialRequestedChannelReserve_opt.isEmpty, "custom remote channel reserve is incompatible with dual-funded channels")

val commitmentFormat: CommitmentFormat = channelFeatures.commitmentFormat
val channelType: SupportedChannelType = channelFeatures.channelType
Expand Down Expand Up @@ -106,14 +106,14 @@ case class ChannelParams(channelId: ByteVector32,
def localChannelReserveForCapacity(capacity: Satoshi, isSplice: Boolean): Satoshi = if (channelFeatures.hasFeature(Features.DualFunding) || isSplice) {
(capacity / 100).max(remoteParams.dustLimit)
} else {
remoteParams.requestedChannelReserve_opt.get // this is guarded by a require() in Params
remoteParams.initialRequestedChannelReserve_opt.get // this is guarded by a require() in Params
}

/** Channel reserve that applies to our peer's funds. */
def remoteChannelReserveForCapacity(capacity: Satoshi, isSplice: Boolean): Satoshi = if (channelFeatures.hasFeature(Features.DualFunding) || isSplice) {
(capacity / 100).max(localParams.dustLimit)
} else {
localParams.requestedChannelReserve_opt.get // this is guarded by a require() in Params
localParams.initialRequestedChannelReserve_opt.get // this is guarded by a require() in Params
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ trait ChannelOpenDualFunded extends DualFundingHandlers with ErrorHandlers {
nodeId = remoteNodeId,
dustLimit = open.dustLimit,
maxHtlcValueInFlightMsat = open.maxHtlcValueInFlightMsat,
requestedChannelReserve_opt = None, // channel reserve will be computed based on channel capacity
initialRequestedChannelReserve_opt = None, // channel reserve will be computed based on channel capacity
htlcMinimum = open.htlcMinimum,
toSelfDelay = open.toSelfDelay,
maxAcceptedHtlcs = open.maxAcceptedHtlcs,
Expand Down Expand Up @@ -247,7 +247,7 @@ trait ChannelOpenDualFunded extends DualFundingHandlers with ErrorHandlers {
nodeId = remoteNodeId,
dustLimit = accept.dustLimit,
maxHtlcValueInFlightMsat = accept.maxHtlcValueInFlightMsat,
requestedChannelReserve_opt = None, // channel reserve will be computed based on channel capacity
initialRequestedChannelReserve_opt = None, // channel reserve will be computed based on channel capacity
htlcMinimum = accept.htlcMinimum,
toSelfDelay = accept.toSelfDelay,
maxAcceptedHtlcs = accept.maxAcceptedHtlcs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ trait ChannelOpenSingleFunded extends SingleFundingHandlers with ErrorHandlers {
pushMsat = input.pushAmount_opt.getOrElse(0 msat),
dustLimitSatoshis = input.localParams.dustLimit,
maxHtlcValueInFlightMsat = UInt64(input.localParams.maxHtlcValueInFlightMsat.toLong),
channelReserveSatoshis = input.localParams.requestedChannelReserve_opt.get,
channelReserveSatoshis = input.localParams.initialRequestedChannelReserve_opt.get,
htlcMinimumMsat = input.localParams.htlcMinimum,
feeratePerKw = input.commitTxFeerate,
toSelfDelay = input.localParams.toSelfDelay,
Expand Down Expand Up @@ -114,7 +114,7 @@ trait ChannelOpenSingleFunded extends SingleFundingHandlers with ErrorHandlers {
nodeId = remoteNodeId,
dustLimit = open.dustLimitSatoshis,
maxHtlcValueInFlightMsat = open.maxHtlcValueInFlightMsat,
requestedChannelReserve_opt = Some(open.channelReserveSatoshis), // our peer requires us to always have at least that much satoshis in our balance
initialRequestedChannelReserve_opt = Some(open.channelReserveSatoshis), // our peer requires us to always have at least that much satoshis in our balance
htlcMinimum = open.htlcMinimumMsat,
toSelfDelay = open.toSelfDelay,
maxAcceptedHtlcs = open.maxAcceptedHtlcs,
Expand All @@ -136,7 +136,7 @@ trait ChannelOpenSingleFunded extends SingleFundingHandlers with ErrorHandlers {
val accept = AcceptChannel(temporaryChannelId = open.temporaryChannelId,
dustLimitSatoshis = d.initFundee.localParams.dustLimit,
maxHtlcValueInFlightMsat = UInt64(d.initFundee.localParams.maxHtlcValueInFlightMsat.toLong),
channelReserveSatoshis = d.initFundee.localParams.requestedChannelReserve_opt.get,
channelReserveSatoshis = d.initFundee.localParams.initialRequestedChannelReserve_opt.get,
minimumDepth = minimumDepth.getOrElse(0),
htlcMinimumMsat = d.initFundee.localParams.htlcMinimum,
toSelfDelay = d.initFundee.localParams.toSelfDelay,
Expand Down Expand Up @@ -172,7 +172,7 @@ trait ChannelOpenSingleFunded extends SingleFundingHandlers with ErrorHandlers {
nodeId = remoteNodeId,
dustLimit = accept.dustLimitSatoshis,
maxHtlcValueInFlightMsat = accept.maxHtlcValueInFlightMsat,
requestedChannelReserve_opt = Some(accept.channelReserveSatoshis), // our peer requires us to always have at least that much satoshis in our balance
initialRequestedChannelReserve_opt = Some(accept.channelReserveSatoshis), // our peer requires us to always have at least that much satoshis in our balance
htlcMinimum = accept.htlcMinimumMsat,
toSelfDelay = accept.toSelfDelay,
maxAcceptedHtlcs = accept.maxAcceptedHtlcs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ object OpenChannelInterceptor {
nodeParams.channelKeyManager.newFundingKeyPath(isInitiator), // we make sure that initiator and non-initiator key paths end differently
dustLimit = nodeParams.channelConf.dustLimit,
maxHtlcValueInFlightMsat = maxHtlcValueInFlightMsat,
requestedChannelReserve_opt = if (dualFunded) None else Some((fundingAmount * nodeParams.channelConf.reserveToFundingRatio).max(nodeParams.channelConf.dustLimit)), // BOLT #2: make sure that our reserve is above our dust limit
initialRequestedChannelReserve_opt = if (dualFunded) None else Some((fundingAmount * nodeParams.channelConf.reserveToFundingRatio).max(nodeParams.channelConf.dustLimit)), // BOLT #2: make sure that our reserve is above our dust limit
htlcMinimum = nodeParams.channelConf.htlcMinimum,
toSelfDelay = nodeParams.channelConf.toRemoteDelay, // we choose their delay
maxAcceptedHtlcs = nodeParams.channelConf.maxAcceptedHtlcs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private[channel] object ChannelTypes0 {
nodeId = nodeId,
dustLimit = dustLimit,
maxHtlcValueInFlightMsat = maxHtlcValueInFlightMsat,
requestedChannelReserve_opt = requestedChannelReserve_opt,
initialRequestedChannelReserve_opt = requestedChannelReserve_opt,
htlcMinimum = htlcMinimum,
toSelfDelay = toSelfDelay,
maxAcceptedHtlcs = maxAcceptedHtlcs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package fr.acinq.eclair.wire.internal.channel.version4
import fr.acinq.bitcoin.scalacompat.Crypto.PublicKey
import fr.acinq.bitcoin.scalacompat.DeterministicWallet.KeyPath
import fr.acinq.bitcoin.scalacompat.{OutPoint, ScriptWitness, Transaction, TxOut}
import fr.acinq.eclair.blockchain.fee
import fr.acinq.eclair.blockchain.fee.{ConfirmationPriority, ConfirmationTarget}
import fr.acinq.eclair.channel.LocalFundingStatus._
import fr.acinq.eclair.channel._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"fundingKeyPath" : [ 1457788542, 1007597768, 1455922339, 479707306 ],
"dustLimit" : 546,
"maxHtlcValueInFlightMsat" : 5000000000,
"requestedChannelReserve_opt" : 167772,
"initialRequestedChannelReserve_opt" : 167772,
"htlcMinimum" : 1,
"toSelfDelay" : 720,
"maxAcceptedHtlcs" : 30,
Expand All @@ -29,7 +29,7 @@
"nodeId" : "034fe52e98a0e9d3c21b767e1b371881265d8c7578c21f5afd6d6438da10348b36",
"dustLimit" : 573,
"maxHtlcValueInFlightMsat" : 16609443000,
"requestedChannelReserve_opt" : 167772,
"initialRequestedChannelReserve_opt" : 167772,
"htlcMinimum" : 1000,
"toSelfDelay" : 2016,
"maxAcceptedHtlcs" : 483,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"fundingKeyPath" : [ 3561221353, 3653515793, 2711311691, 2863050005 ],
"dustLimit" : 546,
"maxHtlcValueInFlightMsat" : 1000000000,
"requestedChannelReserve_opt" : 150000,
"initialRequestedChannelReserve_opt" : 150000,
"htlcMinimum" : 1,
"toSelfDelay" : 144,
"maxAcceptedHtlcs" : 30,
Expand All @@ -29,7 +29,7 @@
"nodeId" : "0269a94e8b32c005e4336bfb743c08a6e9beb13d940d57c479d95c8e687ccbdb9f",
"dustLimit" : 573,
"maxHtlcValueInFlightMsat" : 14850000000,
"requestedChannelReserve_opt" : 150000,
"initialRequestedChannelReserve_opt" : 150000,
"htlcMinimum" : 1000,
"toSelfDelay" : 1802,
"maxAcceptedHtlcs" : 483,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"fundingKeyPath" : [ 2353764507, 3184449568, 2809819526, 3258060413, 392846475, 1545000620, 720603293, 1808318336, 2147483649 ],
"dustLimit" : 546,
"maxHtlcValueInFlightMsat" : 20000000000,
"requestedChannelReserve_opt" : 150000,
"initialRequestedChannelReserve_opt" : 150000,
"htlcMinimum" : 1,
"toSelfDelay" : 720,
"maxAcceptedHtlcs" : 30,
Expand All @@ -36,7 +36,7 @@
"nodeId" : "027455aef8453d92f4706b560b61527cc217ddf14da41770e8ed6607190a1851b8",
"dustLimit" : 573,
"maxHtlcValueInFlightMsat" : 14850000000,
"requestedChannelReserve_opt" : 150000,
"initialRequestedChannelReserve_opt" : 150000,
"htlcMinimum" : 1,
"toSelfDelay" : 1802,
"maxAcceptedHtlcs" : 483,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"fundingKeyPath" : [ 4092535092, 4227137620, 3959690417, 2298849496, 2106263857, 1090614243, 1495530077, 1280982866, 2147483649 ],
"dustLimit" : 1100,
"maxHtlcValueInFlightMsat" : 500000000,
"requestedChannelReserve_opt" : 10000,
"initialRequestedChannelReserve_opt" : 10000,
"htlcMinimum" : 0,
"toSelfDelay" : 144,
"maxAcceptedHtlcs" : 100,
Expand All @@ -32,7 +32,7 @@
"nodeId" : "02bbbb671d15145722fb8c28d732cddb249bcc6652ed2b297ff1f77a18371b1e63",
"dustLimit" : 1000,
"maxHtlcValueInFlightMsat" : 18446744073709551615,
"requestedChannelReserve_opt" : 20000,
"initialRequestedChannelReserve_opt" : 20000,
"htlcMinimum" : 1000,
"toSelfDelay" : 144,
"maxAcceptedHtlcs" : 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"fundingKeyPath" : [ 303987973, 3198768511, 3783619274, 2277156978, 1699864653, 63358126, 3265052696, 516813756, 2147483649 ],
"dustLimit" : 1100,
"maxHtlcValueInFlightMsat" : 500000000,
"requestedChannelReserve_opt" : 10000,
"initialRequestedChannelReserve_opt" : 10000,
"htlcMinimum" : 0,
"toSelfDelay" : 144,
"maxAcceptedHtlcs" : 100,
Expand All @@ -33,7 +33,7 @@
"nodeId" : "02bbbb671d15145722fb8c28d732cddb249bcc6652ed2b297ff1f77a18371b1e63",
"dustLimit" : 1000,
"maxHtlcValueInFlightMsat" : 1000000000,
"requestedChannelReserve_opt" : 20000,
"initialRequestedChannelReserve_opt" : 20000,
"htlcMinimum" : 1000,
"toSelfDelay" : 144,
"maxAcceptedHtlcs" : 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ object TestConstants {
fundingSatoshis,
unlimitedMaxHtlcValueInFlight = false,
).copy(
requestedChannelReserve_opt = Some(10_000 sat) // Bob will need to keep that much satoshis in his balance
initialRequestedChannelReserve_opt = Some(10_000 sat) // Bob will need to keep that much satoshis in his balance
)
}

Expand Down Expand Up @@ -392,7 +392,7 @@ object TestConstants {
fundingSatoshis,
unlimitedMaxHtlcValueInFlight = false,
).copy(
requestedChannelReserve_opt = Some(20_000 sat) // Alice will need to keep that much satoshis in her balance
initialRequestedChannelReserve_opt = Some(20_000 sat) // Alice will need to keep that much satoshis in her balance
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ trait ChannelStateTestsBase extends Assertions with Eventually {
.modify(_.maxHtlcValueInFlightMsat).setToIf(tags.contains(ChannelStateTestsTags.AliceLowMaxHtlcValueInFlight))(150_000_000 msat)
.modify(_.dustLimit).setToIf(tags.contains(ChannelStateTestsTags.HighDustLimitDifferenceAliceBob))(5000 sat)
.modify(_.dustLimit).setToIf(tags.contains(ChannelStateTestsTags.HighDustLimitDifferenceBobAlice))(1000 sat)
.modify(_.requestedChannelReserve_opt).setToIf(tags.contains(ChannelStateTestsTags.DualFunding))(None)
.modify(_.initialRequestedChannelReserve_opt).setToIf(tags.contains(ChannelStateTestsTags.DualFunding))(None)
.modify(_.upfrontShutdownScript_opt).setToIf(tags.contains(ChannelStateTestsTags.UpfrontShutdownScript))(Some(Script.write(Script.pay2wpkh(Await.result(wallet.getP2wpkhPubkey(), 10 seconds)))))
val bobParams = Bob.channelParams
.modify(_.initFeatures).setTo(bobInitFeatures)
.modify(_.walletStaticPaymentBasepoint).setToIf(channelType.paysDirectlyToWallet)(Some(Await.result(wallet.getP2wpkhPubkey(), 10 seconds)))
.modify(_.maxHtlcValueInFlightMsat).setToIf(tags.contains(ChannelStateTestsTags.NoMaxHtlcValueInFlight))(Long.MaxValue.msat)
.modify(_.dustLimit).setToIf(tags.contains(ChannelStateTestsTags.HighDustLimitDifferenceAliceBob))(1000 sat)
.modify(_.dustLimit).setToIf(tags.contains(ChannelStateTestsTags.HighDustLimitDifferenceBobAlice))(5000 sat)
.modify(_.requestedChannelReserve_opt).setToIf(tags.contains(ChannelStateTestsTags.DualFunding))(None)
.modify(_.initialRequestedChannelReserve_opt).setToIf(tags.contains(ChannelStateTestsTags.DualFunding))(None)
.modify(_.upfrontShutdownScript_opt).setToIf(tags.contains(ChannelStateTestsTags.UpfrontShutdownScript))(Some(Script.write(Script.pay2wpkh(Await.result(wallet.getP2wpkhPubkey(), 10 seconds)))))

(aliceParams, bobParams, channelType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class JsonSerializersSpec extends TestKitBaseClass with AnyFunSuiteLike with Mat
| "fundingKeyPath": [42],
| "dustLimit": 546,
| "maxHtlcValueInFlightMsat": 9223372036854775807,
| "requestedChannelReserve_opt": 1000,
| "initialRequestedChannelReserve_opt": 1000,
| "htlcMinimum": 1,
| "toSelfDelay": 144,
| "maxAcceptedHtlcs": 50,
Expand All @@ -173,7 +173,7 @@ class JsonSerializersSpec extends TestKitBaseClass with AnyFunSuiteLike with Mat
| "nodeId": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
| "dustLimit": 546,
| "maxHtlcValueInFlightMsat": 18446744073709551615,
| "requestedChannelReserve_opt": 1000,
| "initialRequestedChannelReserve_opt": 1000,
| "htlcMinimum": 1,
| "toSelfDelay": 144,
| "maxAcceptedHtlcs": 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ object ChannelCodecsSpec {
fundingKeyPath = DeterministicWallet.KeyPath(Seq(42L)),
dustLimit = Satoshi(546),
maxHtlcValueInFlightMsat = 50_000_000 msat,
requestedChannelReserve_opt = Some(10000 sat),
initialRequestedChannelReserve_opt = Some(10000 sat),
htlcMinimum = 10000 msat,
toSelfDelay = CltvExpiryDelta(144),
maxAcceptedHtlcs = 50,
Expand All @@ -270,7 +270,7 @@ object ChannelCodecsSpec {
nodeId = randomKey().publicKey,
dustLimit = 546 sat,
maxHtlcValueInFlightMsat = UInt64(5000000),
requestedChannelReserve_opt = Some(10000 sat),
initialRequestedChannelReserve_opt = Some(10000 sat),
htlcMinimum = 5000 msat,
toSelfDelay = CltvExpiryDelta(144),
maxAcceptedHtlcs = 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class ChannelCodecs4Spec extends AnyFunSuite {
val remoteCodec = remoteParamsCodec(ChannelFeatures(Features.DualFunding))
val decodedLocalParams = localCodec.decode(localCodec.encode(localParams).require).require.value
val decodedRemoteParams = remoteCodec.decode(remoteCodec.encode(remoteParams).require).require.value
assert(decodedLocalParams == localParams.copy(requestedChannelReserve_opt = None))
assert(decodedRemoteParams == remoteParams.copy(requestedChannelReserve_opt = None))
assert(decodedLocalParams == localParams.copy(initialRequestedChannelReserve_opt = None))
assert(decodedRemoteParams == remoteParams.copy(initialRequestedChannelReserve_opt = None))
}
}

Expand Down

0 comments on commit e1f9447

Please sign in to comment.