Skip to content

Commit 6dadb48

Browse files
committed
Core: remove the commit fee clamp, add max fee
This commit removes the check that compares mutual close fee with commit tx fee, this check is outdated and has been changed by this spec PR [1]. To prevent unreasonably high fee, this commit introduces MutualCloseMaxFeeMultiplier setting. [1] lightning/bolts#847
1 parent 20b4f13 commit 6dadb48

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

src/DotNetLightning.Core/Channel/Channel.fs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,10 +1475,15 @@ and Channel =
14751475
this.SavedChannelState.StaticChannelConfig.FundingScriptCoin.TxOut.Value
14761476
- (this.SavedChannelState.LocalCommit.PublishableTxs.CommitTx.Value.TotalOut)
14771477

1478-
do!
1479-
checkRemoteProposedHigherFeeThanBaseFee
1480-
lastCommitFeeSatoshi
1481-
msg.FeeSatoshis
1478+
let! idealFee =
1479+
this.FirstClosingFee
1480+
localShutdownScriptPubKey
1481+
remoteShutdownScriptPubKey
1482+
|> expectTransactionError
1483+
1484+
let maxFee =
1485+
this.SavedChannelState.StaticChannelConfig.LocalParams.MutualCloseMaxFeeMultiplier
1486+
* idealFee
14821487

14831488
do!
14841489
checkRemoteProposedFeeWithinNegotiatedRange
@@ -1550,6 +1555,12 @@ and Channel =
15501555
nextClosingFee
15511556
|> expectTransactionError
15521557

1558+
if this.SavedChannelState.StaticChannelConfig.IsFunder
1559+
&& nextClosingFee > maxFee then
1560+
return!
1561+
Error
1562+
<| ProposalExceedsMaxFee(nextClosingFee, maxFee)
1563+
15531564
let nextState =
15541565
{ this.NegotiatingState with
15551566
LocalClosingFeesProposed =

src/DotNetLightning.Core/Channel/ChannelError.fs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ type ChannelError =
6262
height: BlockHeight *
6363
depth: BlockHeightOffset32
6464
| CannotCloseChannel of msg: string
65-
| RemoteProposedHigherFeeThanBaseFee of baseFee: Money * proposedFee: Money
6665
| RemoteProposedFeeOutOfNegotiatedRange of
6766
ourPreviousFee: Money *
6867
theirPreviousFee: Money *
6968
theirNextFee: Money
69+
| ProposalExceedsMaxFee of proposalFee: Money * maxFee: Money
7070
| NoUpdatesToSign
7171
| CannotSignCommitmentBeforeRevocation
7272
| InsufficientConfirmations of
@@ -108,8 +108,8 @@ type ChannelError =
108108
| CannotSignCommitmentBeforeRevocation -> Ignore
109109
| InsufficientConfirmations(_, _) -> Ignore
110110
| InvalidOperationAddHTLC _ -> Ignore
111-
| RemoteProposedHigherFeeThanBaseFee(_, _) -> Close
112111
| RemoteProposedFeeOutOfNegotiatedRange(_, _, _) -> Close
112+
| ProposalExceedsMaxFee(_, _) -> Ignore
113113

114114
member this.Message =
115115
match this with
@@ -161,12 +161,6 @@ type ChannelError =
161161
sprintf
162162
"They sent shutdown msg (%A) while they have pending unsigned HTLCs, this is protocol violation"
163163
msg
164-
| RemoteProposedHigherFeeThanBaseFee(baseFee, proposedFee) ->
165-
"remote proposed a closing fee higher than commitment fee of the final commitment transaction. "
166-
+ sprintf
167-
"commitment fee=%A; fee remote proposed=%A;"
168-
baseFee
169-
proposedFee
170164
| RemoteProposedFeeOutOfNegotiatedRange
171165
(
172166
ourPreviousFee, theirPreviousFee, theirNextFee
@@ -178,6 +172,11 @@ type ChannelError =
178172
ourPreviousFee
179173
theirPreviousFee
180174
theirNextFee
175+
| ProposalExceedsMaxFee(proposalFee, maxFee) ->
176+
sprintf
177+
"latest fee proposal (%i) exceeds max fee (%i)"
178+
proposalFee.Satoshi
179+
maxFee.Satoshi
181180
| CryptoError cryptoError ->
182181
sprintf "Crypto error: %s" cryptoError.Message
183182
| TransactionRelatedErrors transactionErrors ->
@@ -409,12 +408,6 @@ module internal ChannelError =
409408
let receivedShutdownWhenRemoteHasUnsignedOutgoingHTLCs msg =
410409
msg |> ReceivedShutdownWhenRemoteHasUnsignedOutgoingHTLCs |> Error
411410

412-
let checkRemoteProposedHigherFeeThanBaseFee baseFee proposedFee =
413-
if (baseFee < proposedFee) then
414-
RemoteProposedHigherFeeThanBaseFee(baseFee, proposedFee) |> Error
415-
else
416-
Ok()
417-
418411
let checkRemoteProposedFeeWithinNegotiatedRange
419412
(ourPreviousFeeOpt: Option<Money>)
420413
(theirPreviousFeeOpt: Option<Money>)

src/DotNetLightning.Core/Channel/ChannelOperations.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ type LocalParams =
8080
ToSelfDelay: BlockHeightOffset16
8181
MaxAcceptedHTLCs: uint16
8282
Features: FeatureBits
83+
// MutualCloseMaxFeeMultiplier is a multiplier we'll apply to the ideal fee
84+
// of the funder, to decide when the negotiated fee is too high. By
85+
// default, we want to bail out if we attempt to negotiate a fee that's
86+
// 3x higher than our ideal fee.
87+
MutualCloseMaxFeeMultiplier: int
8388
}
8489

8590
type RemoteParams =

tests/DotNetLightning.Core.Tests/ChannelTests.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ let tests =
103103
ToSelfDelay = 144us |> BlockHeightOffset16
104104
MaxAcceptedHTLCs = 1000us
105105
Features = FeatureBits.Zero
106+
MutualCloseMaxFeeMultiplier = 3
106107
}
107108

108109
let remoteParams: RemoteParams =

tests/DotNetLightning.Core.Tests/TransactionTests.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ let testList =
101101
ToSelfDelay = 144us |> BlockHeightOffset16
102102
MaxAcceptedHTLCs = 1000us
103103
Features = FeatureBits.Zero
104+
MutualCloseMaxFeeMultiplier = 3
104105
}
105106

106107
let remoteLocalParam: LocalParams =
@@ -112,6 +113,7 @@ let testList =
112113
ToSelfDelay = 144us |> BlockHeightOffset16
113114
MaxAcceptedHTLCs = 1000us
114115
Features = FeatureBits.Zero
116+
MutualCloseMaxFeeMultiplier = 3
115117
}
116118

117119
let remoteParam: RemoteParams =
@@ -532,6 +534,7 @@ let testList =
532534
ToSelfDelay = 144us |> BlockHeightOffset16
533535
MaxAcceptedHTLCs = 1000us
534536
Features = FeatureBits.Zero
537+
MutualCloseMaxFeeMultiplier = 3
535538
}
536539

537540
let remoteLocalParam: LocalParams =
@@ -543,6 +546,7 @@ let testList =
543546
ToSelfDelay = 144us |> BlockHeightOffset16
544547
MaxAcceptedHTLCs = 1000us
545548
Features = FeatureBits.Zero
549+
MutualCloseMaxFeeMultiplier = 3
546550
}
547551

548552
let remoteParams: RemoteParams =
@@ -887,6 +891,7 @@ let testList =
887891
ToSelfDelay = 144us |> BlockHeightOffset16
888892
MaxAcceptedHTLCs = 1000us
889893
Features = FeatureBits.Zero
894+
MutualCloseMaxFeeMultiplier = 3
890895
}
891896

892897
let remoteLocalParam: LocalParams =
@@ -898,6 +903,7 @@ let testList =
898903
ToSelfDelay = 144us |> BlockHeightOffset16
899904
MaxAcceptedHTLCs = 1000us
900905
Features = FeatureBits.Zero
906+
MutualCloseMaxFeeMultiplier = 3
901907
}
902908

903909
let remoteParam: RemoteParams =

0 commit comments

Comments
 (0)