Skip to content

Commit

Permalink
Actually apply update fee messages
Browse files Browse the repository at this point in the history
Prior to this commit, apply an update_fee message would cause DNL to
validate the message but not actually apply it to its commitments.

It now updates its commitments as it should.

Upstream PR: joemphilips#159
  • Loading branch information
canndrew authored and knocte committed May 20, 2021
1 parent 31286f1 commit 1c551b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/DotNetLightning.Core/Channel/Channel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ module Channel =

| WeAcceptedOperationUpdateFee(_msg, newCommitments), ChannelState.Normal d ->
{ c with State = ChannelState.Normal({ d with Commitments = newCommitments }) }
| WeAcceptedUpdateFee(_msg), ChannelState.Normal _d -> c
| WeAcceptedUpdateFee(_msg, newCommitments), ChannelState.Normal normalData ->
{ c with State = ChannelState.Normal({ normalData with Commitments = newCommitments }) }

| WeAcceptedOperationSign(_msg, newCommitments), ChannelState.Normal d ->
{ c with State = ChannelState.Normal({ d with Commitments = newCommitments }) }
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetLightning.Core/Channel/ChannelTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ type ChannelEvent =
| WeAcceptedFailMalformedHTLC of origin: HTLCSource * msg: UpdateAddHTLCMsg * newCommitments: Commitments

| WeAcceptedOperationUpdateFee of msg: UpdateFeeMsg * nextCommitments: Commitments
| WeAcceptedUpdateFee of msg: UpdateFeeMsg
| WeAcceptedUpdateFee of msg: UpdateFeeMsg * newCommitments: Commitments

| WeAcceptedOperationSign of msg: CommitmentSignedMsg * nextCommitments: Commitments
| WeAcceptedCommitmentSigned of msg: RevokeAndACKMsg * nextCommitments: Commitments
Expand Down
15 changes: 9 additions & 6 deletions src/DotNetLightning.Core/Channel/CommitmentsModule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,22 @@ module internal Commitments =
else
result {
do! Helpers.checkUpdateFee (config) (msg) (localFeerate)
let c1 = cm.AddRemoteProposal(msg)
let nextCommitments = cm.AddRemoteProposal(msg)
let! reduced =
c1.LocalCommit.Spec.Reduce(c1.LocalChanges.ACKed, c1.RemoteChanges.Proposed) |> expectTransactionError
nextCommitments.LocalCommit.Spec.Reduce(
nextCommitments.LocalChanges.ACKed,
nextCommitments.RemoteChanges.Proposed
) |> expectTransactionError

let fees = Transactions.commitTxFee(c1.RemoteParams.DustLimitSatoshis) reduced
let missing = reduced.ToRemote.ToMoney() - c1.RemoteParams.ChannelReserveSatoshis - fees
let fees = Transactions.commitTxFee(nextCommitments.RemoteParams.DustLimitSatoshis) reduced
let missing = reduced.ToRemote.ToMoney() - nextCommitments.RemoteParams.ChannelReserveSatoshis - fees
if (missing < Money.Zero) then
return!
(c1.LocalParams.ChannelReserveSatoshis, fees, (-1 * missing))
(nextCommitments.LocalParams.ChannelReserveSatoshis, fees, (-1 * missing))
|> cannotAffordFee
else
return
[ WeAcceptedUpdateFee msg ]
[ WeAcceptedUpdateFee(msg, nextCommitments) ]
}

let sendCommit (channelPrivKeys: ChannelPrivKeys) (n: Network) (cm: Commitments) =
Expand Down

0 comments on commit 1c551b8

Please sign in to comment.