Skip to content

Commit a7e4dad

Browse files
authored
Remove support for push_amount (#697)
With the updated on-the-fly funding protocol, we're using liquidity ads instead of an unofficial `push_amount` TLV. We can thus remove usage of `push_amount`s everywhere, which simplifies the codebase.
1 parent 192f3bf commit a7e4dad

34 files changed

+166
-447
lines changed

src/commonMain/kotlin/fr/acinq/lightning/channel/ChannelCommand.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import fr.acinq.lightning.channel.states.ClosingFeerates
1010
import fr.acinq.lightning.channel.states.PersistedChannelState
1111
import fr.acinq.lightning.crypto.KeyManager
1212
import fr.acinq.lightning.utils.UUID
13-
import fr.acinq.lightning.utils.msat
1413
import fr.acinq.lightning.wire.FailureMessage
1514
import fr.acinq.lightning.wire.LightningMessage
1615
import fr.acinq.lightning.wire.LiquidityAds
@@ -27,7 +26,6 @@ sealed class ChannelCommand {
2726
data class Initiator(
2827
val replyTo: CompletableDeferred<ChannelFundingResponse>,
2928
val fundingAmount: Satoshi,
30-
val pushAmount: MilliSatoshi,
3129
val walletInputs: List<WalletState.Utxo>,
3230
val commitTxFeerate: FeeratePerKw,
3331
val fundingTxFeerate: FeeratePerKw,
@@ -46,7 +44,6 @@ sealed class ChannelCommand {
4644
val replyTo: CompletableDeferred<ChannelFundingResponse>,
4745
val temporaryChannelId: ByteVector32,
4846
val fundingAmount: Satoshi,
49-
val pushAmount: MilliSatoshi,
5047
val walletInputs: List<WalletState.Utxo>,
5148
val localParams: LocalParams,
5249
val channelConfig: ChannelConfig,
@@ -98,11 +95,10 @@ sealed class ChannelCommand {
9895
val feerate: FeeratePerKw,
9996
val origins: List<Origin>
10097
) : Splice() {
101-
val pushAmount: MilliSatoshi = spliceIn?.pushAmount ?: 0.msat
10298
val spliceOutputs: List<TxOut> = spliceOut?.let { listOf(TxOut(it.amount, it.scriptPubKey)) } ?: emptyList()
10399
val liquidityFees: LiquidityAds.Fees? = requestRemoteFunding?.fees(feerate, isChannelCreation = false)
104100

105-
data class SpliceIn(val walletInputs: List<WalletState.Utxo>, val pushAmount: MilliSatoshi = 0.msat)
101+
data class SpliceIn(val walletInputs: List<WalletState.Utxo>)
106102
data class SpliceOut(val amount: Satoshi, val scriptPubKey: ByteVector)
107103
}
108104
}

src/commonMain/kotlin/fr/acinq/lightning/channel/Helpers.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ object Helpers {
7272
return Either.Left(InvalidChainHash(open.temporaryChannelId, local = nodeParams.chainHash, remote = open.chainHash))
7373
}
7474

75-
// BOLT #2: The receiving node MUST fail the channel if: push_msat is greater than funding_satoshis * 1000.
76-
if (open.pushAmount > open.fundingAmount) {
77-
return Either.Left(InvalidPushAmount(open.temporaryChannelId, open.pushAmount, open.fundingAmount.toMilliSatoshi()))
78-
}
79-
8075
// BOLT #2: The receiving node MUST fail the channel if: to_self_delay is unreasonably large.
8176
if (open.toSelfDelay > Channel.MAX_TO_SELF_DELAY || open.toSelfDelay > nodeParams.maxToLocalDelayBlocks) {
8277
return Either.Left(ToSelfDelayTooHigh(open.temporaryChannelId, open.toSelfDelay, nodeParams.maxToLocalDelayBlocks))
@@ -122,10 +117,6 @@ object Helpers {
122117
return Either.Left(InvalidFundingAmount(accept.temporaryChannelId, accept.fundingAmount))
123118
}
124119

125-
if (accept.pushAmount > accept.fundingAmount) {
126-
return Either.Left(InvalidPushAmount(accept.temporaryChannelId, accept.pushAmount, accept.fundingAmount.toMilliSatoshi()))
127-
}
128-
129120
if (accept.maxAcceptedHtlcs > Channel.MAX_ACCEPTED_HTLCS) {
130121
return Either.Left(InvalidMaxAcceptedHtlcs(accept.temporaryChannelId, accept.maxAcceptedHtlcs, Channel.MAX_ACCEPTED_HTLCS))
131122
}

src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,9 @@ data class FundingContributions(val inputs: List<InteractiveTxInput.Outgoing>, v
270270
swapInKeys: KeyManager.SwapInOnChainKeys,
271271
params: InteractiveTxParams,
272272
walletInputs: List<WalletState.Utxo>,
273-
localPushAmount: MilliSatoshi,
274-
remotePushAmount: MilliSatoshi,
275273
liquidityPurchase: LiquidityAds.Purchase?
276274
): Either<FundingContributionFailure, FundingContributions> {
277-
return create(channelKeys, swapInKeys, params, null, walletInputs, listOf(), localPushAmount, remotePushAmount, liquidityPurchase)
275+
return create(channelKeys, swapInKeys, params, null, walletInputs, listOf(), liquidityPurchase)
278276
}
279277

280278
/**
@@ -290,8 +288,6 @@ data class FundingContributions(val inputs: List<InteractiveTxInput.Outgoing>, v
290288
sharedUtxo: Pair<SharedFundingInput, SharedFundingInputBalances>?,
291289
walletInputs: List<WalletState.Utxo>,
292290
localOutputs: List<TxOut>,
293-
localPushAmount: MilliSatoshi,
294-
remotePushAmount: MilliSatoshi,
295291
liquidityPurchase: LiquidityAds.Purchase?,
296292
changePubKey: PublicKey? = null
297293
): Either<FundingContributionFailure, FundingContributions> {
@@ -310,9 +306,9 @@ data class FundingContributions(val inputs: List<InteractiveTxInput.Outgoing>, v
310306

311307
val liquidityFees = params.liquidityFees(liquidityPurchase)
312308
val nextLocalBalanceBeforePush = (sharedUtxo?.second?.toLocal ?: 0.msat) + params.localContribution.toMilliSatoshi()
313-
val nextLocalBalanceAfterPush = (sharedUtxo?.second?.toLocal ?: 0.msat) + params.localContribution.toMilliSatoshi() - localPushAmount + remotePushAmount - liquidityFees
309+
val nextLocalBalanceAfterPush = (sharedUtxo?.second?.toLocal ?: 0.msat) + params.localContribution.toMilliSatoshi() - liquidityFees
314310
val nextRemoteBalanceBeforePush = (sharedUtxo?.second?.toRemote ?: 0.msat) + params.remoteContribution.toMilliSatoshi()
315-
val nextRemoteBalanceAfterPush = (sharedUtxo?.second?.toRemote ?: 0.msat) + params.remoteContribution.toMilliSatoshi() + localPushAmount - remotePushAmount + liquidityFees
311+
val nextRemoteBalanceAfterPush = (sharedUtxo?.second?.toRemote ?: 0.msat) + params.remoteContribution.toMilliSatoshi() + liquidityFees
316312
if (nextLocalBalanceAfterPush < 0.msat || nextRemoteBalanceAfterPush < 0.msat) {
317313
return Either.Left(FundingContributionFailure.InvalidFundingBalances(params.fundingAmount, nextLocalBalanceAfterPush, nextRemoteBalanceAfterPush))
318314
}
@@ -1091,8 +1087,6 @@ data class InteractiveTxSigningSession(
10911087
fundingParams: InteractiveTxParams,
10921088
fundingTxIndex: Long,
10931089
sharedTx: SharedTransaction,
1094-
localPushAmount: MilliSatoshi,
1095-
remotePushAmount: MilliSatoshi,
10961090
liquidityPurchase: LiquidityAds.Purchase?,
10971091
localCommitmentIndex: Long,
10981092
remoteCommitmentIndex: Long,
@@ -1109,8 +1103,8 @@ data class InteractiveTxSigningSession(
11091103
channelParams.channelId,
11101104
channelParams.localParams, channelParams.remoteParams,
11111105
fundingAmount = sharedTx.sharedOutput.amount,
1112-
toLocal = sharedTx.sharedOutput.localAmount - localPushAmount + remotePushAmount - liquidityFees,
1113-
toRemote = sharedTx.sharedOutput.remoteAmount - remotePushAmount + localPushAmount + liquidityFees,
1106+
toLocal = sharedTx.sharedOutput.localAmount - liquidityFees,
1107+
toRemote = sharedTx.sharedOutput.remoteAmount + liquidityFees,
11141108
localHtlcs = localHtlcs,
11151109
localCommitmentIndex = localCommitmentIndex,
11161110
remoteCommitmentIndex = remoteCommitmentIndex,
@@ -1203,8 +1197,6 @@ sealed class SpliceStatus {
12031197
data class InProgress(
12041198
val replyTo: CompletableDeferred<ChannelFundingResponse>?,
12051199
val spliceSession: InteractiveTxSession,
1206-
val localPushAmount: MilliSatoshi,
1207-
val remotePushAmount: MilliSatoshi,
12081200
val liquidityPurchase: LiquidityAds.Purchase?,
12091201
val origins: List<Origin>
12101202
) : QuiescentSpliceStatus()

src/commonMain/kotlin/fr/acinq/lightning/channel/states/Normal.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,9 @@ data class Normal(
419419
lockTime = currentBlockHeight.toLong(),
420420
feerate = spliceStatus.command.feerate,
421421
fundingPubkey = channelKeys().fundingPubKey(parentCommitment.fundingTxIndex + 1),
422-
pushAmount = spliceStatus.command.pushAmount,
423422
requestFunding = spliceStatus.command.requestRemoteFunding,
424423
)
425-
logger.info { "initiating splice with local.amount=${spliceInit.fundingContribution} local.push=${spliceInit.pushAmount}" }
424+
logger.info { "initiating splice with local.amount=${spliceInit.fundingContribution}" }
426425
Pair(this@Normal.copy(spliceStatus = SpliceStatus.Requested(spliceStatus.command, spliceInit)), listOf(ChannelAction.Message.Send(spliceInit)))
427426
}
428427
} else {
@@ -453,12 +452,11 @@ data class Normal(
453452
}
454453
is SpliceStatus.NonInitiatorQuiescent ->
455454
if (commitments.isQuiescent()) {
456-
logger.info { "accepting splice with remote.amount=${cmd.message.fundingContribution} remote.push=${cmd.message.pushAmount}" }
455+
logger.info { "accepting splice with remote.amount=${cmd.message.fundingContribution}" }
457456
val parentCommitment = commitments.active.first()
458457
val spliceAck = SpliceAck(
459458
channelId,
460459
fundingContribution = 0.sat, // only remote contributes to the splice
461-
pushAmount = 0.msat,
462460
fundingPubkey = channelKeys().fundingPubKey(parentCommitment.fundingTxIndex + 1),
463461
willFund = null,
464462
)
@@ -489,8 +487,6 @@ data class Normal(
489487
spliceStatus = SpliceStatus.InProgress(
490488
replyTo = null,
491489
session,
492-
localPushAmount = 0.msat,
493-
remotePushAmount = cmd.message.pushAmount,
494490
liquidityPurchase = null,
495491
origins = listOf()
496492
)
@@ -511,7 +507,7 @@ data class Normal(
511507
}
512508
is SpliceAck -> when (spliceStatus) {
513509
is SpliceStatus.Requested -> {
514-
logger.info { "our peer accepted our splice request with remote.amount=${cmd.message.fundingContribution} remote.push=${cmd.message.pushAmount} liquidityFees=${spliceStatus.command.liquidityFees}" }
510+
logger.info { "our peer accepted our splice request with remote.amount=${cmd.message.fundingContribution} liquidityFees=${spliceStatus.command.liquidityFees}" }
515511
when (val liquidityPurchase = LiquidityAds.validateRemoteFunding(
516512
spliceStatus.command.requestRemoteFunding,
517513
remoteNodeId,
@@ -550,8 +546,6 @@ data class Normal(
550546
sharedUtxo = Pair(sharedInput, SharedFundingInputBalances(toLocal = parentCommitment.localCommit.spec.toLocal, toRemote = parentCommitment.localCommit.spec.toRemote, toHtlcs = parentCommitment.localCommit.spec.htlcs.map { it.add.amountMsat }.sum())),
551547
walletInputs = spliceStatus.command.spliceIn?.walletInputs ?: emptyList(),
552548
localOutputs = spliceStatus.command.spliceOutputs,
553-
localPushAmount = spliceStatus.spliceInit.pushAmount,
554-
remotePushAmount = cmd.message.pushAmount,
555549
liquidityPurchase = liquidityPurchase.value,
556550
changePubKey = null // we don't want a change output: we're spending every funds available
557551
)) {
@@ -579,8 +573,6 @@ data class Normal(
579573
spliceStatus = SpliceStatus.InProgress(
580574
replyTo = spliceStatus.command.replyTo,
581575
interactiveTxSession,
582-
localPushAmount = spliceStatus.spliceInit.pushAmount,
583-
remotePushAmount = cmd.message.pushAmount,
584576
liquidityPurchase = liquidityPurchase.value,
585577
origins = spliceStatus.command.origins,
586578
)
@@ -617,8 +609,6 @@ data class Normal(
617609
spliceStatus.spliceSession.fundingParams,
618610
fundingTxIndex = parentCommitment.fundingTxIndex + 1,
619611
interactiveTxAction.sharedTx,
620-
localPushAmount = spliceStatus.localPushAmount,
621-
remotePushAmount = spliceStatus.remotePushAmount,
622612
liquidityPurchase = spliceStatus.liquidityPurchase,
623613
localCommitmentIndex = parentCommitment.localCommit.index,
624614
remoteCommitmentIndex = parentCommitment.remoteCommit.index,

src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForAcceptChannel.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ data class WaitForAcceptChannel(
7272
keyManager.swapInOnChainWallet,
7373
fundingParams,
7474
init.walletInputs,
75-
lastSent.pushAmount,
76-
accept.pushAmount,
7775
liquidityPurchase.value
7876
)) {
7977
is Either.Left -> {
@@ -100,8 +98,6 @@ data class WaitForAcceptChannel(
10098
init.localParams,
10199
remoteParams,
102100
interactiveTxSession,
103-
lastSent.pushAmount,
104-
accept.pushAmount,
105101
lastSent.commitmentFeerate,
106102
accept.firstPerCommitmentPoint,
107103
accept.secondPerCommitmentPoint,

src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForFundingConfirmed.kt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@ package fr.acinq.lightning.channel.states
22

33
import fr.acinq.bitcoin.TxId
44
import fr.acinq.bitcoin.utils.Either
5-
import fr.acinq.lightning.MilliSatoshi
65
import fr.acinq.lightning.ShortChannelId
76
import fr.acinq.lightning.blockchain.BITCOIN_FUNDING_DEPTHOK
87
import fr.acinq.lightning.blockchain.WatchConfirmed
98
import fr.acinq.lightning.blockchain.WatchEventConfirmed
109
import fr.acinq.lightning.channel.*
1110
import fr.acinq.lightning.utils.msat
12-
import fr.acinq.lightning.utils.toMilliSatoshi
1311
import fr.acinq.lightning.wire.*
1412

1513
/** We wait for the channel funding transaction to confirm. */
1614
data class WaitForFundingConfirmed(
1715
override val commitments: Commitments,
18-
val localPushAmount: MilliSatoshi,
19-
val remotePushAmount: MilliSatoshi,
2016
val waitingSinceBlock: Long, // how many blocks have we been waiting for the funding tx to confirm
2117
val deferred: ChannelReady?,
2218
// We can have at most one ongoing RBF attempt.
@@ -85,12 +81,6 @@ data class WaitForFundingConfirmed(
8581
if (cmd.message.feerate < minNextFeerate) {
8682
logger.info { "rejecting rbf attempt: the new feerate must be at least $minNextFeerate (proposed=${cmd.message.feerate})" }
8783
Pair(this@WaitForFundingConfirmed.copy(rbfStatus = RbfStatus.RbfAborted), listOf(ChannelAction.Message.Send(TxAbort(channelId, InvalidRbfFeerate(channelId, cmd.message.feerate, minNextFeerate).message))))
88-
} else if (cmd.message.fundingContribution.toMilliSatoshi() < remotePushAmount) {
89-
logger.info { "rejecting rbf attempt: invalid amount pushed (fundingAmount=${cmd.message.fundingContribution}, pushAmount=$remotePushAmount)" }
90-
Pair(
91-
this@WaitForFundingConfirmed.copy(rbfStatus = RbfStatus.RbfAborted),
92-
listOf(ChannelAction.Message.Send(TxAbort(channelId, InvalidPushAmount(channelId, remotePushAmount, cmd.message.fundingContribution.toMilliSatoshi()).message)))
93-
)
9484
} else {
9585
logger.info { "our peer wants to raise the feerate of the funding transaction (previous=${latestFundingTx.fundingParams.targetFeerate} target=${cmd.message.feerate})" }
9686
val fundingParams = InteractiveTxParams(
@@ -136,7 +126,7 @@ data class WaitForFundingConfirmed(
136126
latestFundingTx.fundingParams.dustLimit,
137127
rbfStatus.command.targetFeerate
138128
)
139-
when (val contributions = FundingContributions.create(channelKeys(), keyManager.swapInOnChainWallet, fundingParams, rbfStatus.command.walletInputs, 0.msat, 0.msat, null)) {
129+
when (val contributions = FundingContributions.create(channelKeys(), keyManager.swapInOnChainWallet, fundingParams, rbfStatus.command.walletInputs, null)) {
140130
is Either.Left -> {
141131
logger.warning { "error creating funding contributions: ${contributions.value}" }
142132
Pair(this@WaitForFundingConfirmed.copy(rbfStatus = RbfStatus.RbfAborted), listOf(ChannelAction.Message.Send(TxAbort(channelId, ChannelFundingError(channelId).message))))
@@ -175,8 +165,6 @@ data class WaitForFundingConfirmed(
175165
rbfSession1.fundingParams,
176166
fundingTxIndex = replacedCommitment.fundingTxIndex,
177167
interactiveTxAction.sharedTx,
178-
localPushAmount,
179-
remotePushAmount,
180168
liquidityPurchase = null,
181169
localCommitmentIndex = replacedCommitment.localCommit.index,
182170
remoteCommitmentIndex = replacedCommitment.remoteCommit.index,
@@ -321,8 +309,6 @@ data class WaitForFundingConfirmed(
321309
val watchConfirmed = WatchConfirmed(channelId, action.commitment.fundingTxId, action.commitment.commitInput.txOut.publicKeyScript, fundingMinDepth.toLong(), BITCOIN_FUNDING_DEPTHOK)
322310
val nextState = WaitForFundingConfirmed(
323311
commitments.add(action.commitment).copy(remoteChannelData = remoteChannelData),
324-
localPushAmount,
325-
remotePushAmount,
326312
waitingSinceBlock,
327313
deferred,
328314
RbfStatus.None

0 commit comments

Comments
 (0)