Skip to content

Commit fa5e80c

Browse files
committed
Completely remove walletStaticPaymentBasepoint
It was initially kept as it could have been useful for v3 transactions, but it turns out that it's actually unnecessary. We can thus completely get rid of that field, which simplifies the code and tests.
1 parent fee8737 commit fa5e80c

23 files changed

+93
-136
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,11 +786,11 @@ object DATA_CLOSED {
786786
},
787787
closingAmount = closingType match {
788788
case Closing.MutualClose(closingTx) => closingTx.toLocalOutput_opt.map(_.amount).getOrElse(0 sat)
789-
case Closing.LocalClose(_, localCommitPublished) => Closing.closingBalance(d.channelParams, d.commitments.latest.commitmentFormat, d.finalScriptPubKey, localCommitPublished)
790-
case Closing.CurrentRemoteClose(_, remoteCommitPublished) => Closing.closingBalance(d.channelParams, d.commitments.latest.commitmentFormat, d.finalScriptPubKey, remoteCommitPublished)
791-
case Closing.NextRemoteClose(_, remoteCommitPublished) => Closing.closingBalance(d.channelParams, d.commitments.latest.commitmentFormat, d.finalScriptPubKey, remoteCommitPublished)
792-
case Closing.RecoveryClose(remoteCommitPublished) => Closing.closingBalance(d.channelParams, d.commitments.latest.commitmentFormat, d.finalScriptPubKey, remoteCommitPublished)
793-
case Closing.RevokedClose(revokedCommitPublished) => Closing.closingBalance(d.channelParams, d.commitments.latest.commitmentFormat, d.finalScriptPubKey, revokedCommitPublished)
789+
case Closing.LocalClose(_, localCommitPublished) => Closing.closingBalance(d.finalScriptPubKey, localCommitPublished)
790+
case Closing.CurrentRemoteClose(_, remoteCommitPublished) => Closing.closingBalance(d.finalScriptPubKey, remoteCommitPublished)
791+
case Closing.NextRemoteClose(_, remoteCommitPublished) => Closing.closingBalance(d.finalScriptPubKey, remoteCommitPublished)
792+
case Closing.RecoveryClose(remoteCommitPublished) => Closing.closingBalance(d.finalScriptPubKey, remoteCommitPublished)
793+
case Closing.RevokedClose(revokedCommitPublished) => Closing.closingBalance(d.finalScriptPubKey, revokedCommitPublished)
794794
}
795795
)
796796
}
@@ -805,7 +805,6 @@ case class LocalChannelParams(nodeId: PublicKey,
805805
isChannelOpener: Boolean,
806806
paysCommitTxFees: Boolean,
807807
upfrontShutdownScript_opt: Option[ByteVector],
808-
walletStaticPaymentBasepoint: Option[PublicKey],
809808
// Current connection features, or last features used if the channel is disconnected. Note that
810809
// these features are updated at each reconnection and may be different from the channel permanent
811810
// features (see [[ChannelFeatures]]).

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ object LocalCommit {
202202
case class RemoteCommit(index: Long, spec: CommitmentSpec, txId: TxId, remotePerCommitmentPoint: PublicKey) {
203203
def sign(channelParams: ChannelParams, commitParams: CommitParams, channelKeys: ChannelKeys, fundingTxIndex: Long, remoteFundingPubKey: PublicKey, commitInput: InputInfo, commitmentFormat: CommitmentFormat, remoteNonce_opt: Option[IndividualNonce], batchSize: Int = 1): Either[ChannelException, CommitSig] = {
204204
val fundingKey = channelKeys.fundingKey(fundingTxIndex)
205-
val commitKeys = RemoteCommitmentKeys(channelParams, channelKeys, remotePerCommitmentPoint, commitmentFormat)
205+
val commitKeys = RemoteCommitmentKeys(channelParams, channelKeys, remotePerCommitmentPoint)
206206
val (remoteCommitTx, htlcTxs) = Commitment.makeRemoteTxs(channelParams, commitParams, commitKeys, index, fundingKey, remoteFundingPubKey, commitInput, commitmentFormat, spec)
207207
val sortedHtlcTxs = htlcTxs.sortBy(_.input.outPoint.index)
208208
val htlcSigs = sortedHtlcTxs.map(_.localSig(commitKeys))
@@ -278,9 +278,9 @@ case class Commitment(fundingTxIndex: Long,
278278

279279
def commitInput(channelKeys: ChannelKeys): InputInfo = commitInput(localFundingKey(channelKeys))
280280

281-
def localKeys(params: ChannelParams, channelKeys: ChannelKeys): LocalCommitmentKeys = LocalCommitmentKeys(params, channelKeys, localCommit.index, commitmentFormat)
281+
def localKeys(params: ChannelParams, channelKeys: ChannelKeys): LocalCommitmentKeys = LocalCommitmentKeys(params, channelKeys, localCommit.index)
282282

283-
def remoteKeys(params: ChannelParams, channelKeys: ChannelKeys, remotePerCommitmentPoint: PublicKey): RemoteCommitmentKeys = RemoteCommitmentKeys(params, channelKeys, remotePerCommitmentPoint, commitmentFormat)
283+
def remoteKeys(params: ChannelParams, channelKeys: ChannelKeys, remotePerCommitmentPoint: PublicKey): RemoteCommitmentKeys = RemoteCommitmentKeys(params, channelKeys, remotePerCommitmentPoint)
284284

285285
/** Channel reserve that applies to our funds. */
286286
def localChannelReserve(params: ChannelParams): Satoshi = if (params.channelFeatures.hasFeature(Features.DualFunding) || fundingTxIndex > 0) {
@@ -1062,8 +1062,8 @@ case class Commitments(channelParams: ChannelParams,
10621062
remoteNextCommitInfo match {
10631063
case Right(_) if !changes.localHasChanges => Left(CannotSignWithoutChanges(channelId))
10641064
case Right(remoteNextPerCommitmentPoint) =>
1065+
val commitKeys = RemoteCommitmentKeys(channelParams, channelKeys, remoteNextPerCommitmentPoint)
10651066
val (active1, sigs) = active.map(c => {
1066-
val commitKeys = RemoteCommitmentKeys(channelParams, channelKeys, remoteNextPerCommitmentPoint, c.commitmentFormat)
10671067
c.sendCommit(channelParams, channelKeys, commitKeys, changes, remoteNextPerCommitmentPoint, active.size, nextRemoteCommitNonces.get(c.fundingTxId)) match {
10681068
case Left(e) => return Left(e)
10691069
case Right((c, cs)) => (c, cs)
@@ -1093,8 +1093,8 @@ case class Commitments(channelParams: ChannelParams,
10931093
case commitSig: CommitSig => Seq(commitSig)
10941094
}
10951095
// Signatures are sent in order (most recent first), calling `zip` will drop trailing sigs that are for deactivated/pruned commitments.
1096+
val commitKeys = LocalCommitmentKeys(channelParams, channelKeys, localCommitIndex + 1)
10961097
val active1 = active.zip(sigs).map { case (commitment, commit) =>
1097-
val commitKeys = LocalCommitmentKeys(channelParams, channelKeys, localCommitIndex + 1, commitment.commitmentFormat)
10981098
commitment.receiveCommit(channelParams, channelKeys, commitKeys, changes, commit) match {
10991099
case Left(f) => return Left(f)
11001100
case Right(commitment1) => commitment1

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ object Helpers {
13491349
// a valid tx will always have at least one input, but this ensures we don't throw in tests
13501350
val sequence = commitTx.txIn.headOption.map(_.sequence).getOrElse(0L)
13511351
val obscuredTxNumber = Transactions.decodeTxNumber(sequence, commitTx.lockTime)
1352-
val localPaymentPoint = params.localParams.walletStaticPaymentBasepoint.getOrElse(channelKeys.paymentBasePoint)
1352+
val localPaymentPoint = channelKeys.paymentBasePoint
13531353
// this tx has been published by remote, so we need to invert local/remote params
13541354
val txNumber = Transactions.obscuredCommitTxNumber(obscuredTxNumber, !params.localParams.isChannelOpener, params.remoteParams.paymentBasepoint, localPaymentPoint)
13551355
if (txNumber > 0xffffffffffffL) {
@@ -1368,7 +1368,7 @@ object Helpers {
13681368
def claimCommitTxOutputs(channelParams: ChannelParams, channelKeys: ChannelKeys, commitTx: Transaction, commitmentNumber: Long, remotePerCommitmentSecret: PrivateKey, toSelfDelay: CltvExpiryDelta, commitmentFormat: CommitmentFormat, db: ChannelsDb, dustLimit: Satoshi, feerates: FeeratesPerKw, onChainFeeConf: OnChainFeeConf, finalScriptPubKey: ByteVector)(implicit log: LoggingAdapter): (RevokedCommitPublished, SecondStageTransactions) = {
13691369
log.warning("a revoked commit has been published with commitmentNumber={}", commitmentNumber)
13701370

1371-
val commitKeys = RemoteCommitmentKeys(channelParams, channelKeys, remotePerCommitmentSecret.publicKey, commitmentFormat)
1371+
val commitKeys = RemoteCommitmentKeys(channelParams, channelKeys, remotePerCommitmentSecret.publicKey)
13721372
val revocationKey = channelKeys.revocationKey(remotePerCommitmentSecret)
13731373

13741374
val feerateMain = onChainFeeConf.getClosingFeerate(feerates, maxClosingFeerateOverride_opt = None)
@@ -1428,7 +1428,7 @@ object Helpers {
14281428
if (spendsHtlcOutput) {
14291429
getRemotePerCommitmentSecret(channelParams, channelKeys, remotePerCommitmentSecrets, revokedCommitPublished.commitTx).map {
14301430
case (_, remotePerCommitmentSecret) =>
1431-
val commitmentKeys = RemoteCommitmentKeys(channelParams, channelKeys, remotePerCommitmentSecret.publicKey, commitmentFormat)
1431+
val commitmentKeys = RemoteCommitmentKeys(channelParams, channelKeys, remotePerCommitmentSecret.publicKey)
14321432
val revocationKey = channelKeys.revocationKey(remotePerCommitmentSecret)
14331433
val penaltyTxs = claimHtlcTxOutputs(commitmentKeys, revocationKey, toSelfDelay, commitmentFormat, htlcTx, dustLimit, feerates, finalScriptPubKey)
14341434
val revokedCommitPublished1 = revokedCommitPublished.copy(htlcDelayedOutputs = revokedCommitPublished.htlcDelayedOutputs ++ penaltyTxs.map(_.input.outPoint))
@@ -1452,7 +1452,7 @@ object Helpers {
14521452
* Claim the outputs of all 2nd-stage HTLC transactions that have been confirmed.
14531453
*/
14541454
def claimHtlcTxsOutputs(channelParams: ChannelParams, channelKeys: ChannelKeys, remotePerCommitmentSecret: PrivateKey, toSelfDelay: CltvExpiryDelta, commitmentFormat: CommitmentFormat, revokedCommitPublished: RevokedCommitPublished, dustLimit: Satoshi, feerates: FeeratesPerKw, finalScriptPubKey: ByteVector)(implicit log: LoggingAdapter): ThirdStageTransactions = {
1455-
val commitmentKeys = RemoteCommitmentKeys(channelParams, channelKeys, remotePerCommitmentSecret.publicKey, commitmentFormat)
1455+
val commitmentKeys = RemoteCommitmentKeys(channelParams, channelKeys, remotePerCommitmentSecret.publicKey)
14561456
val revocationKey = channelKeys.revocationKey(remotePerCommitmentSecret)
14571457
val confirmedHtlcTxs = revokedCommitPublished.htlcOutputs.flatMap(htlcOutput => revokedCommitPublished.irrevocablySpent.get(htlcOutput))
14581458
val penaltyTxs = confirmedHtlcTxs.flatMap(htlcTx => claimHtlcTxOutputs(commitmentKeys, revocationKey, toSelfDelay, commitmentFormat, htlcTx, dustLimit, feerates, finalScriptPubKey))
@@ -1680,18 +1680,11 @@ object Helpers {
16801680
}
16811681

16821682
/** Returns the amount we've successfully claimed from a force-closed channel. */
1683-
def closingBalance(channelParams: ChannelParams, commitmentFormat: CommitmentFormat, closingScript: ByteVector, commit: CommitPublished): Satoshi = {
1684-
val toLocal = commit.localOutput_opt match {
1685-
case Some(o) if o.index < commit.commitTx.txOut.size => commit.commitTx.txOut(o.index.toInt).amount
1686-
case _ => 0 sat
1687-
}
1688-
val toClosingScript = commit.irrevocablySpent.values.flatMap(_.txOut)
1683+
def closingBalance(closingScript: ByteVector, commit: CommitPublished): Satoshi = {
1684+
commit.irrevocablySpent.values.flatMap(_.txOut)
16891685
.filter(_.publicKeyScript == closingScript)
16901686
.map(_.amount)
16911687
.sum
1692-
commitmentFormat match {
1693-
case _: AnchorOutputsCommitmentFormat | _: SimpleTaprootChannelCommitmentFormat => toClosingScript
1694-
}
16951688
}
16961689

16971690
}

eclair-core/src/main/scala/fr/acinq/eclair/channel/fsm/ChannelOpenDualFunded.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ trait ChannelOpenDualFunded extends DualFundingHandlers with ErrorHandlers {
127127
lockTime = nodeParams.currentBlockHeight.toLong,
128128
fundingPubkey = fundingPubKey,
129129
revocationBasepoint = channelKeys.revocationBasePoint,
130-
paymentBasepoint = input.localChannelParams.walletStaticPaymentBasepoint.getOrElse(channelKeys.paymentBasePoint),
130+
paymentBasepoint = channelKeys.paymentBasePoint,
131131
delayedPaymentBasepoint = channelKeys.delayedPaymentBasePoint,
132132
htlcBasepoint = channelKeys.htlcBasePoint,
133133
firstPerCommitmentPoint = channelKeys.commitmentPoint(0),
@@ -179,7 +179,7 @@ trait ChannelOpenDualFunded extends DualFundingHandlers with ErrorHandlers {
179179
maxAcceptedHtlcs = localCommitParams.maxAcceptedHtlcs,
180180
fundingPubkey = localFundingPubkey,
181181
revocationBasepoint = channelKeys.revocationBasePoint,
182-
paymentBasepoint = d.init.localChannelParams.walletStaticPaymentBasepoint.getOrElse(channelKeys.paymentBasePoint),
182+
paymentBasepoint = channelKeys.paymentBasePoint,
183183
delayedPaymentBasepoint = channelKeys.delayedPaymentBasePoint,
184184
htlcBasepoint = channelKeys.htlcBasePoint,
185185
firstPerCommitmentPoint = channelKeys.commitmentPoint(0),

eclair-core/src/main/scala/fr/acinq/eclair/channel/fsm/ChannelOpenSingleFunded.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ trait ChannelOpenSingleFunded extends SingleFundingHandlers with ErrorHandlers {
9595
maxAcceptedHtlcs = input.proposedCommitParams.localMaxAcceptedHtlcs,
9696
fundingPubkey = fundingKey.publicKey,
9797
revocationBasepoint = channelKeys.revocationBasePoint,
98-
paymentBasepoint = input.localChannelParams.walletStaticPaymentBasepoint.getOrElse(channelKeys.paymentBasePoint),
98+
paymentBasepoint = channelKeys.paymentBasePoint,
9999
delayedPaymentBasepoint = channelKeys.delayedPaymentBasePoint,
100100
htlcBasepoint = channelKeys.htlcBasePoint,
101101
firstPerCommitmentPoint = channelKeys.commitmentPoint(0),
@@ -146,7 +146,7 @@ trait ChannelOpenSingleFunded extends SingleFundingHandlers with ErrorHandlers {
146146
maxAcceptedHtlcs = localCommitParams.maxAcceptedHtlcs,
147147
fundingPubkey = fundingKey.publicKey,
148148
revocationBasepoint = channelKeys.revocationBasePoint,
149-
paymentBasepoint = d.initFundee.localChannelParams.walletStaticPaymentBasepoint.getOrElse(channelKeys.paymentBasePoint),
149+
paymentBasepoint = channelKeys.paymentBasePoint,
150150
delayedPaymentBasepoint = channelKeys.delayedPaymentBasePoint,
151151
htlcBasepoint = channelKeys.htlcBasePoint,
152152
firstPerCommitmentPoint = channelKeys.commitmentPoint(0),
@@ -215,8 +215,8 @@ trait ChannelOpenSingleFunded extends SingleFundingHandlers with ErrorHandlers {
215215
val temporaryChannelId = d.channelParams.channelId
216216
// let's create the first commitment tx that spends the yet uncommitted funding tx
217217
val fundingKey = channelKeys.fundingKey(fundingTxIndex = 0)
218-
val localCommitmentKeys = LocalCommitmentKeys(d.channelParams, channelKeys, localCommitIndex = 0, d.commitmentFormat)
219-
val remoteCommitmentKeys = RemoteCommitmentKeys(d.channelParams, channelKeys, d.remoteFirstPerCommitmentPoint, d.commitmentFormat)
218+
val localCommitmentKeys = LocalCommitmentKeys(d.channelParams, channelKeys, localCommitIndex = 0)
219+
val remoteCommitmentKeys = RemoteCommitmentKeys(d.channelParams, channelKeys, d.remoteFirstPerCommitmentPoint)
220220
Funding.makeFirstCommitTxs(d.channelParams, d.localCommitParams, d.remoteCommitParams, localFundingAmount = d.fundingAmount, remoteFundingAmount = 0 sat, localPushAmount = d.pushAmount, remotePushAmount = 0 msat, d.commitTxFeerate, d.commitmentFormat, fundingTx.txid, fundingTxOutputIndex, fundingKey, d.remoteFundingPubKey, localCommitmentKeys, remoteCommitmentKeys) match {
221221
case Left(ex) => handleLocalError(ex, d, None)
222222
case Right((localSpec, localCommitTx, remoteSpec, remoteCommitTx)) =>
@@ -275,8 +275,8 @@ trait ChannelOpenSingleFunded extends SingleFundingHandlers with ErrorHandlers {
275275
case Event(fc@FundingCreated(_, fundingTxId, fundingTxOutputIndex, _, _), d: DATA_WAIT_FOR_FUNDING_CREATED) =>
276276
val temporaryChannelId = d.channelParams.channelId
277277
val fundingKey = channelKeys.fundingKey(fundingTxIndex = 0)
278-
val localCommitmentKeys = LocalCommitmentKeys(d.channelParams, channelKeys, localCommitIndex = 0, d.commitmentFormat)
279-
val remoteCommitmentKeys = RemoteCommitmentKeys(d.channelParams, channelKeys, d.remoteFirstPerCommitmentPoint, d.commitmentFormat)
278+
val localCommitmentKeys = LocalCommitmentKeys(d.channelParams, channelKeys, localCommitIndex = 0)
279+
val remoteCommitmentKeys = RemoteCommitmentKeys(d.channelParams, channelKeys, d.remoteFirstPerCommitmentPoint)
280280
Funding.makeFirstCommitTxs(d.channelParams, d.localCommitParams, d.remoteCommitParams, localFundingAmount = 0 sat, remoteFundingAmount = d.fundingAmount, localPushAmount = 0 msat, remotePushAmount = d.pushAmount, d.commitTxFeerate, d.commitmentFormat, fundingTxId, fundingTxOutputIndex, fundingKey, d.remoteFundingPubKey, localCommitmentKeys, remoteCommitmentKeys) match {
281281
case Left(ex) => handleLocalError(ex, d, Some(fc))
282282
case Right((localSpec, localCommitTx, remoteSpec, remoteCommitTx)) =>

eclair-core/src/main/scala/fr/acinq/eclair/channel/fund/InteractiveTxBuilder.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,8 @@ private class InteractiveTxBuilder(replyTo: ActorRef[InteractiveTxBuilder.Respon
894894
val fundingTx = completeTx.buildUnsignedTx()
895895
val fundingOutputIndex = fundingTx.txOut.indexWhere(_.publicKeyScript == fundingPubkeyScript)
896896
val liquidityFee = fundingParams.liquidityFees(liquidityPurchase_opt)
897-
val localCommitmentKeys = LocalCommitmentKeys(channelParams, channelKeys, purpose.localCommitIndex, fundingParams.commitmentFormat)
898-
val remoteCommitmentKeys = RemoteCommitmentKeys(channelParams, channelKeys, purpose.remotePerCommitmentPoint, fundingParams.commitmentFormat)
897+
val localCommitmentKeys = LocalCommitmentKeys(channelParams, channelKeys, purpose.localCommitIndex)
898+
val remoteCommitmentKeys = RemoteCommitmentKeys(channelParams, channelKeys, purpose.remotePerCommitmentPoint)
899899
Funding.makeCommitTxs(channelParams, localCommitParams, remoteCommitParams,
900900
fundingAmount = fundingParams.fundingAmount,
901901
toLocal = completeTx.sharedOutput.localAmount - localPushAmount + remotePushAmount - liquidityFee,
@@ -1218,7 +1218,7 @@ object InteractiveTxSigningSession {
12181218
localCommit match {
12191219
case Left(unsignedLocalCommit) =>
12201220
val fundingKey = localFundingKey(channelKeys)
1221-
val commitKeys = LocalCommitmentKeys(channelParams, channelKeys, localCommitIndex, fundingParams.commitmentFormat)
1221+
val commitKeys = LocalCommitmentKeys(channelParams, channelKeys, localCommitIndex)
12221222
val fundingOutput = commitInput(fundingKey)
12231223
LocalCommit.fromCommitSig(channelParams, localCommitParams, commitKeys, fundingTx.txId, fundingKey, fundingParams.remoteFundingPubKey, fundingOutput, remoteCommitSig, localCommitIndex, unsignedLocalCommit.spec, fundingParams.commitmentFormat).map { signedLocalCommit =>
12241224
if (shouldSignFirst(fundingParams.isInitiator, channelParams, fundingTx.tx)) {

0 commit comments

Comments
 (0)