Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: remove the commit fee clamp, add max fee #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/DotNetLightning.Core/Channel/Channel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,14 +1471,15 @@ and Channel =
let remoteChannelKeys =
this.SavedChannelState.StaticChannelConfig.RemoteChannelPubKeys

let lastCommitFeeSatoshi =
this.SavedChannelState.StaticChannelConfig.FundingScriptCoin.TxOut.Value
- (this.SavedChannelState.LocalCommit.PublishableTxs.CommitTx.Value.TotalOut)
let! idealFee =
this.FirstClosingFee
localShutdownScriptPubKey
remoteShutdownScriptPubKey
|> expectTransactionError

do!
checkRemoteProposedHigherFeeThanBaseFee
lastCommitFeeSatoshi
msg.FeeSatoshis
let maxFee =
this.SavedChannelState.StaticChannelConfig.LocalParams.MutualCloseMaxFeeMultiplier
* idealFee

do!
checkRemoteProposedFeeWithinNegotiatedRange
Expand Down Expand Up @@ -1550,6 +1551,12 @@ and Channel =
nextClosingFee
|> expectTransactionError

if this.SavedChannelState.StaticChannelConfig.IsFunder
&& nextClosingFee > maxFee then
return!
Error
<| ProposalExceedsMaxFee(nextClosingFee, maxFee)

let nextState =
{ this.NegotiatingState with
LocalClosingFeesProposed =
Expand Down
21 changes: 7 additions & 14 deletions src/DotNetLightning.Core/Channel/ChannelError.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ type ChannelError =
height: BlockHeight *
depth: BlockHeightOffset32
| CannotCloseChannel of msg: string
| RemoteProposedHigherFeeThanBaseFee of baseFee: Money * proposedFee: Money
| RemoteProposedFeeOutOfNegotiatedRange of
ourPreviousFee: Money *
theirPreviousFee: Money *
theirNextFee: Money
| ProposalExceedsMaxFee of proposalFee: Money * maxFee: Money
| NoUpdatesToSign
| CannotSignCommitmentBeforeRevocation
| InsufficientConfirmations of
Expand Down Expand Up @@ -108,8 +108,8 @@ type ChannelError =
| CannotSignCommitmentBeforeRevocation -> Ignore
| InsufficientConfirmations(_, _) -> Ignore
| InvalidOperationAddHTLC _ -> Ignore
| RemoteProposedHigherFeeThanBaseFee(_, _) -> Close
| RemoteProposedFeeOutOfNegotiatedRange(_, _, _) -> Close
| ProposalExceedsMaxFee(_, _) -> Ignore

member this.Message =
match this with
Expand Down Expand Up @@ -161,12 +161,6 @@ type ChannelError =
sprintf
"They sent shutdown msg (%A) while they have pending unsigned HTLCs, this is protocol violation"
msg
| RemoteProposedHigherFeeThanBaseFee(baseFee, proposedFee) ->
"remote proposed a closing fee higher than commitment fee of the final commitment transaction. "
+ sprintf
"commitment fee=%A; fee remote proposed=%A;"
baseFee
proposedFee
| RemoteProposedFeeOutOfNegotiatedRange
(
ourPreviousFee, theirPreviousFee, theirNextFee
Expand All @@ -178,6 +172,11 @@ type ChannelError =
ourPreviousFee
theirPreviousFee
theirNextFee
| ProposalExceedsMaxFee(proposalFee, maxFee) ->
sprintf
"latest fee proposal (%i) exceeds max fee (%i)"
proposalFee.Satoshi
maxFee.Satoshi
| CryptoError cryptoError ->
sprintf "Crypto error: %s" cryptoError.Message
| TransactionRelatedErrors transactionErrors ->
Expand Down Expand Up @@ -409,12 +408,6 @@ module internal ChannelError =
let receivedShutdownWhenRemoteHasUnsignedOutgoingHTLCs msg =
msg |> ReceivedShutdownWhenRemoteHasUnsignedOutgoingHTLCs |> Error

let checkRemoteProposedHigherFeeThanBaseFee baseFee proposedFee =
if (baseFee < proposedFee) then
RemoteProposedHigherFeeThanBaseFee(baseFee, proposedFee) |> Error
else
Ok()

let checkRemoteProposedFeeWithinNegotiatedRange
(ourPreviousFeeOpt: Option<Money>)
(theirPreviousFeeOpt: Option<Money>)
Expand Down
5 changes: 5 additions & 0 deletions src/DotNetLightning.Core/Channel/ChannelOperations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ type LocalParams =
ToSelfDelay: BlockHeightOffset16
MaxAcceptedHTLCs: uint16
Features: FeatureBits
// MutualCloseMaxFeeMultiplier is a multiplier we'll apply to the ideal fee
// of the funder, to decide when the negotiated fee is too high. By
// default, we want to bail out if we attempt to negotiate a fee that's
// 3x higher than our ideal fee.
MutualCloseMaxFeeMultiplier: int
}

type RemoteParams =
Expand Down
1 change: 1 addition & 0 deletions tests/DotNetLightning.Core.Tests/ChannelTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ let tests =
ToSelfDelay = 144us |> BlockHeightOffset16
MaxAcceptedHTLCs = 1000us
Features = FeatureBits.Zero
MutualCloseMaxFeeMultiplier = 3
}

let remoteParams: RemoteParams =
Expand Down
6 changes: 6 additions & 0 deletions tests/DotNetLightning.Core.Tests/TransactionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ let testList =
ToSelfDelay = 144us |> BlockHeightOffset16
MaxAcceptedHTLCs = 1000us
Features = FeatureBits.Zero
MutualCloseMaxFeeMultiplier = 3
}

let remoteLocalParam: LocalParams =
Expand All @@ -112,6 +113,7 @@ let testList =
ToSelfDelay = 144us |> BlockHeightOffset16
MaxAcceptedHTLCs = 1000us
Features = FeatureBits.Zero
MutualCloseMaxFeeMultiplier = 3
}

let remoteParam: RemoteParams =
Expand Down Expand Up @@ -532,6 +534,7 @@ let testList =
ToSelfDelay = 144us |> BlockHeightOffset16
MaxAcceptedHTLCs = 1000us
Features = FeatureBits.Zero
MutualCloseMaxFeeMultiplier = 3
}

let remoteLocalParam: LocalParams =
Expand All @@ -543,6 +546,7 @@ let testList =
ToSelfDelay = 144us |> BlockHeightOffset16
MaxAcceptedHTLCs = 1000us
Features = FeatureBits.Zero
MutualCloseMaxFeeMultiplier = 3
}

let remoteParams: RemoteParams =
Expand Down Expand Up @@ -887,6 +891,7 @@ let testList =
ToSelfDelay = 144us |> BlockHeightOffset16
MaxAcceptedHTLCs = 1000us
Features = FeatureBits.Zero
MutualCloseMaxFeeMultiplier = 3
}

let remoteLocalParam: LocalParams =
Expand All @@ -898,6 +903,7 @@ let testList =
ToSelfDelay = 144us |> BlockHeightOffset16
MaxAcceptedHTLCs = 1000us
Features = FeatureBits.Zero
MutualCloseMaxFeeMultiplier = 3
}

let remoteParam: RemoteParams =
Expand Down