Skip to content

Commit 4ff8b3d

Browse files
committed
Add non_initiator_pays_commit_fees channel flag
We add a non-standard channel flag to `open_channel2` to allow wallets to ask their peer to pay the commit tx fees, even when they're not the channel opener. This is necessary for on-the-fly funding, until we can move to 0-fee commit txs which will make it obsolete.
1 parent a97dd41 commit 4ff8b3d

11 files changed

Lines changed: 28 additions & 10 deletions

File tree

eclair-core/src/main/scala/fr/acinq/eclair/channel/ChannelData.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,16 @@ case class RemoteParams(nodeId: PublicKey,
666666
initFeatures: Features[InitFeature],
667667
upfrontShutdownScript_opt: Option[ByteVector])
668668

669-
case class ChannelFlags(announceChannel: Boolean) {
670-
override def toString: String = s"ChannelFlags(announceChannel=$announceChannel)"
669+
/**
670+
* The [[nonInitiatorPaysCommitFees]] parameter is set to true when the sender wants the receiver to pay the commitment transaction fees.
671+
* This is not part of the BOLTs and won't be needed anymore once commitment transactions don't pay any on-chain fees.
672+
*/
673+
case class ChannelFlags(nonInitiatorPaysCommitFees: Boolean, announceChannel: Boolean) {
674+
override def toString: String = s"ChannelFlags(announceChannel=$announceChannel, nonInitiatorPaysCommitFees=$nonInitiatorPaysCommitFees)"
675+
}
676+
677+
object ChannelFlags {
678+
def apply(announceChannel: Boolean): ChannelFlags = ChannelFlags(nonInitiatorPaysCommitFees = false, announceChannel = announceChannel)
671679
}
672680

673681
/** Information about what triggered the opening of the channel */

eclair-core/src/main/scala/fr/acinq/eclair/wire/protocol/CommonCodecs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ object CommonCodecs {
119119

120120
val listofsignatures: Codec[List[ByteVector64]] = listOfN(uint16, bytes64)
121121

122-
val channelflags: Codec[ChannelFlags] = (ignore(7) :: bool).as[ChannelFlags]
122+
val channelflags: Codec[ChannelFlags] = (ignore(6) :: bool :: bool).as[ChannelFlags]
123123

124124
val ipv4address: Codec[Inet4Address] = bytes(4).xmap(b => InetAddress.getByAddress(b.toArray).asInstanceOf[Inet4Address], a => ByteVector(a.getAddress))
125125

eclair-core/src/test/resources/nonreg/codecs/000003-DATA_NORMAL/fundee-announced/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
}
4848
},
4949
"channelFlags" : {
50+
"nonInitiatorPaysCommitFees" : false,
5051
"announceChannel" : true
5152
}
5253
},

eclair-core/src/test/resources/nonreg/codecs/000003-DATA_NORMAL/funder/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
}
4848
},
4949
"channelFlags" : {
50+
"nonInitiatorPaysCommitFees" : false,
5051
"announceChannel" : true
5152
}
5253
},

eclair-core/src/test/resources/nonreg/codecs/020002-DATA_NORMAL/funder-announced/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
}
6262
},
6363
"channelFlags" : {
64+
"nonInitiatorPaysCommitFees" : false,
6465
"announceChannel" : true
6566
}
6667
},

eclair-core/src/test/resources/nonreg/codecs/030000-DATA_WAIT_FOR_FUNDING_CONFIRMED/funder/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
}
5555
},
5656
"channelFlags" : {
57+
"nonInitiatorPaysCommitFees" : false,
5758
"announceChannel" : false
5859
}
5960
},

eclair-core/src/test/resources/nonreg/codecs/03000a-DATA_WAIT_FOR_CHANNEL_READY/funder/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
}
5757
},
5858
"channelFlags" : {
59+
"nonInitiatorPaysCommitFees" : false,
5960
"announceChannel" : false
6061
}
6162
},

eclair-core/src/test/resources/nonreg/codecs/03000c-DATA_WAIT_FOR_DUAL_FUNDING_READY/funder/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
}
6363
},
6464
"channelFlags" : {
65+
"nonInitiatorPaysCommitFees" : false,
6566
"announceChannel" : false
6667
}
6768
},

eclair-core/src/test/scala/fr/acinq/eclair/json/JsonSerializersSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class JsonSerializersSpec extends TestKitBaseClass with AnyFunSuiteLike with Mat
185185
| "initFeatures": { "activated": {}, "unknown": [] }
186186
| },
187187
| "channelFlags": {
188+
| "nonInitiatorPaysCommitFees": false,
188189
| "announceChannel": true
189190
| }
190191
| },

eclair-core/src/test/scala/fr/acinq/eclair/wire/protocol/CommonCodecsSpec.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,20 @@ class CommonCodecsSpec extends AnyFunSuite {
140140

141141
test("encode/decode channel flags") {
142142
val testCases = Map(
143-
bin"00000000" -> ChannelFlags(announceChannel = false),
144-
bin"00000001" -> ChannelFlags(announceChannel = true),
143+
bin"00000000" -> ChannelFlags(nonInitiatorPaysCommitFees = false, announceChannel = false),
144+
bin"00000001" -> ChannelFlags(nonInitiatorPaysCommitFees = false, announceChannel = true),
145+
bin"00000010" -> ChannelFlags(nonInitiatorPaysCommitFees = true, announceChannel = false),
146+
bin"00000011" -> ChannelFlags(nonInitiatorPaysCommitFees = true, announceChannel = true),
145147
)
146148
testCases.foreach { case (bin, obj) =>
147149
assert(channelflags.decode(bin).require == DecodeResult(obj, BitVector.empty))
148150
assert(channelflags.encode(obj).require == bin)
149151
}
150152

151153
// BOLT 2: The receiving node MUST [...] ignore undefined bits in channel_flags.
152-
assert(channelflags.decode(bin"11111111").require == DecodeResult(ChannelFlags(announceChannel = true), BitVector.empty))
153-
assert(channelflags.decode(bin"11111110").require == DecodeResult(ChannelFlags(announceChannel = false), BitVector.empty))
154+
assert(channelflags.decode(bin"11111111").require == DecodeResult(ChannelFlags(nonInitiatorPaysCommitFees = true, announceChannel = true), BitVector.empty))
155+
assert(channelflags.decode(bin"11111110").require == DecodeResult(ChannelFlags(nonInitiatorPaysCommitFees = true, announceChannel = false), BitVector.empty))
156+
assert(channelflags.decode(bin"11111100").require == DecodeResult(ChannelFlags(nonInitiatorPaysCommitFees = false, announceChannel = false), BitVector.empty))
154157
}
155158

156159
test("encode/decode with rgb codec") {

0 commit comments

Comments
 (0)