From 5126acd069bb29acd1ca75a7265947d7e393dcb1 Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Thu, 26 Nov 2020 15:10:29 +0800 Subject: [PATCH 1/3] Exclude macaroons tests on CI These tests are failing randomly and macaroons aren't used by geewallet anyway. So exclude them from CI. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43e80c85b..78ab8a5ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: dotnet run --project tests/DotNetLightning.Core.Tests - name: Run other tests run: | - dotnet test + dotnet test --filter FullyQualifiedName\!~Macaroons build_with_fsharp_from_mono: runs-on: ubuntu-18.04 From 9ba9e9d0da9e6760811c7959e3f3cdadc874d5c6 Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Mon, 23 Nov 2020 15:43:08 +0800 Subject: [PATCH 2/3] Move and export fee mismatch calculation function Move/rename ChannelError.feeRateMismatch to FeeRatePerKw.MismatchRatio. This function is useful outside of DotNetLightning, so we now export it so that library consumers can use it. --- src/DotNetLightning.Core/Channel/ChannelError.fs | 9 ++------- src/DotNetLightning.Core/Utils/Primitives.fs | 6 ++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/DotNetLightning.Core/Channel/ChannelError.fs b/src/DotNetLightning.Core/Channel/ChannelError.fs index 0f1b0bde8..5030a7ede 100644 --- a/src/DotNetLightning.Core/Channel/ChannelError.fs +++ b/src/DotNetLightning.Core/Channel/ChannelError.fs @@ -255,11 +255,6 @@ module private ValidationHelper = /// Helpers to create channel error [] module internal ChannelError = - let feeRateMismatch (FeeRatePerKw remote, FeeRatePerKw local) = - let remote = float remote - let local = float local - abs (2.0 * (remote - local) / (remote + local)) - let inline feeDeltaTooHigh msg (actualDelta, maxAccepted) = InvalidUpdateFeeError.Create msg @@ -366,7 +361,7 @@ module internal OpenChannelMsgValidation = (maxFeeRateMismatchRatio: float) = let localFeeRatePerKw = feeEstimator.GetEstSatPer1000Weight(ConfirmationTarget.Background) - let diff = feeRateMismatch(remoteFeeRatePerKw, localFeeRatePerKw) + let diff = remoteFeeRatePerKw.MismatchRatio localFeeRatePerKw if (diff > maxFeeRateMismatchRatio) then sprintf "Peer's feerate (%A) was unacceptably far from the estimated fee rate of %A" @@ -600,7 +595,7 @@ module internal UpdateAddHTLCValidationWithContext = module internal UpdateFeeValidation = let checkFeeDiffTooHigh (msg: UpdateFeeMsg) (localFeeRatePerKw: FeeRatePerKw) (maxFeeRateMismatchRatio) = let remoteFeeRatePerKw = msg.FeeRatePerKw - let diff = feeRateMismatch(remoteFeeRatePerKw, localFeeRatePerKw) + let diff = remoteFeeRatePerKw.MismatchRatio localFeeRatePerKw if (diff > maxFeeRateMismatchRatio) then (diff, maxFeeRateMismatchRatio) |> feeDeltaTooHigh msg diff --git a/src/DotNetLightning.Core/Utils/Primitives.fs b/src/DotNetLightning.Core/Utils/Primitives.fs index 16afc5b9b..9ea3df341 100644 --- a/src/DotNetLightning.Core/Utils/Primitives.fs +++ b/src/DotNetLightning.Core/Utils/Primitives.fs @@ -338,12 +338,18 @@ module Primitives = member this.AsNBitcoinFeeRate() = this.Value |> uint64 |> (*)4UL |> Money.Satoshis |> FeeRate + member this.MismatchRatio (other: FeeRatePerKw) = + let local = double this.Value + let remote = double other.Value + abs (2.0 * (remote - local) / (remote + local)) + static member Max(a: FeeRatePerKw, b: FeeRatePerKw) = if (a.Value >= b.Value) then a else b static member (+) (a: FeeRatePerKw, b: uint32) = (a.Value + b) |> FeeRatePerKw static member (*) (a: FeeRatePerKw, b: uint32) = (a.Value * b) |> FeeRatePerKw + /// Block Hash type BlockId = | BlockId of uint256 with member x.Value = let (BlockId v) = x in v From 2e569cba5e7d6407a2ea272de9108fdde4c680b7 Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Wed, 25 Nov 2020 15:45:06 +0800 Subject: [PATCH 3/3] Actually apply update fee messages 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. --- src/DotNetLightning.Core/Channel/Channel.fs | 3 ++- src/DotNetLightning.Core/Channel/ChannelTypes.fs | 2 +- .../Channel/CommitmentsModule.fs | 15 +++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/DotNetLightning.Core/Channel/Channel.fs b/src/DotNetLightning.Core/Channel/Channel.fs index 9773f0ed4..582b554ff 100644 --- a/src/DotNetLightning.Core/Channel/Channel.fs +++ b/src/DotNetLightning.Core/Channel/Channel.fs @@ -881,7 +881,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 }) } diff --git a/src/DotNetLightning.Core/Channel/ChannelTypes.fs b/src/DotNetLightning.Core/Channel/ChannelTypes.fs index a66ddc93b..73dafd725 100644 --- a/src/DotNetLightning.Core/Channel/ChannelTypes.fs +++ b/src/DotNetLightning.Core/Channel/ChannelTypes.fs @@ -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 diff --git a/src/DotNetLightning.Core/Channel/CommitmentsModule.fs b/src/DotNetLightning.Core/Channel/CommitmentsModule.fs index fa9bc90b2..342f1f2e0 100644 --- a/src/DotNetLightning.Core/Channel/CommitmentsModule.fs +++ b/src/DotNetLightning.Core/Channel/CommitmentsModule.fs @@ -249,19 +249,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) =