Skip to content

Commit a4a59d0

Browse files
Bobfaceknocte
andcommitted
Prevent possible F#4.0 issue
It seems that these attributes can cause this compilation error in F#4.0: error FS0927: The kind of the type specified by its attributes does not match the kind implied by its definition Newer versions of F# (like 4.5 or even newer, like the one being used by .NETCore to build the binary that is later published in nuget) allow compiling this code with no issues, but if you reference the generated assembly later from an old F# compiler, it could generate exceptions at runtime, e.g.: System.BadFormatImageException (or other types) whose inner exception could be the following: System.TypeLoadException : Could not load type of field 'GWallet.Backend.UtxoCoin.Lightning.SerializedChannel:MinSafeDepth@' (6) due to: Expected reference type but got type kind 17 FSharp.Core's Result type is also affected by this so in this commit we create a replacement for it that is only used in the BouncyCastle build (which we now rename as 'Portability' build). Co-authored-by: Andres G. Aragoneses <[email protected]>
1 parent ee56733 commit a4a59d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+254
-103
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
# we want to run only once.
2020
if: startsWith(matrix.os, 'ubuntu-18')
2121
run: |
22-
dotnet build tests/DotNetLightning.Core.Tests -p:BouncyCastle=True
22+
dotnet build tests/DotNetLightning.Core.Tests -p:Portability=True
2323
dotnet run --no-build --project tests/DotNetLightning.Core.Tests
2424
2525
- name: Clean to prepare for NSec build
@@ -41,5 +41,5 @@ jobs:
4141
DEBIAN_FRONTEND=noninteractive sudo apt install -y msbuild fsharp nuget
4242
4343
nuget restore DotNetLightning.sln
44-
msbuild src/DotNetLightning.Core/DotNetLightning.Core.fsproj -p:BouncyCastle=True -p:TargetFramework=netstandard2.0
44+
msbuild src/DotNetLightning.Core/DotNetLightning.Core.fsproj -p:Portability=True -p:TargetFramework=netstandard2.0
4545

.github/workflows/publish_master.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232
- name: Upload nuget packages (BouncyCastle)
3333
if: startsWith(matrix.os, 'ubuntu')
3434
run: |
35-
dotnet pack ./src/DotNetLightning.Core -p:Configuration=Release --version-suffix date`date +%Y%m%d-%H%M`-git-`echo $GITHUB_SHA | head -c 7` -p:BouncyCastle=True
35+
dotnet pack ./src/DotNetLightning.Core -p:Configuration=Release --version-suffix date`date +%Y%m%d-%H%M`-git-`echo $GITHUB_SHA | head -c 7` -p:Portability=True
3636
dotnet nuget push ./src/DotNetLightning.Core/bin/Release/DotNetLightning.Kiss.1*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
3737

.github/workflows/publish_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
if: startsWith(matrix.os, 'ubuntu-18')
7575
run: |
7676
echo "releasing BouncyCastle version to nuget..."
77-
dotnet pack -p:Configuration=Release src/DotNetLightning.Core -p:BouncyCastle=True
77+
dotnet pack -p:Configuration=Release src/DotNetLightning.Core -p:Portability=True
7878
if [ ${{ secrets.NUGET_API_KEY }} ]; then
7979
dotnet nuget push ./src/DotNetLightning.Core/bin/Release/DotNetLightning.${{ steps.get_version.outputs.VERSION }}.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
8080
fi

src/DotNetLightning.Core/Channel/Channel.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace DotNetLightning.Channel
22

3-
open ResultUtils
4-
53
open DotNetLightning.Utils
64
open DotNetLightning.Utils.NBitcoinExtensions
75
open DotNetLightning.Utils.Aether
@@ -12,6 +10,8 @@ open DotNetLightning.Serialize.Msgs
1210
open NBitcoin
1311
open System
1412

13+
open ResultUtils
14+
open ResultUtils.Portability
1515

1616
type ProvideFundingTx = IDestination * Money * FeeRatePerKw -> Result<FinalizedTx * TxOutIndex, string>
1717
type Channel = {

src/DotNetLightning.Core/Channel/ChannelError.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace DotNetLightning.Channel
22

3-
open ResultUtils
43
open DotNetLightning.Utils
54
open NBitcoinExtensions
65
open DotNetLightning.Utils.OnionError
@@ -11,6 +10,9 @@ open DotNetLightning.Transactions
1110

1211
open NBitcoin
1312

13+
open ResultUtils
14+
open ResultUtils.Portability
15+
1416
type ChannelError =
1517
| CryptoError of CryptoError
1618
| TransactionRelatedErrors of TransactionError list

src/DotNetLightning.Core/Channel/ChannelValidation.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace DotNetLightning.Channel
22

3-
open ResultUtils
43
open NBitcoin
54

65
open DotNetLightning.Chain
@@ -10,6 +9,9 @@ open DotNetLightning.Utils.NBitcoinExtensions
109
open DotNetLightning.Serialize.Msgs
1110
open DotNetLightning.Transactions
1211

12+
open ResultUtils
13+
open ResultUtils.Portability
14+
1315
exception ChannelException of ChannelError
1416
module internal ChannelHelpers =
1517

src/DotNetLightning.Core/Channel/Commitments.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ open DotNetLightning.Crypto
88
open DotNetLightning.Transactions
99
open DotNetLightning.Serialize.Msgs
1010

11+
open ResultUtils
12+
open ResultUtils.Portability
13+
1114
type LocalChanges = {
1215
Proposed: IUpdateMsg list
1316
Signed: IUpdateMsg list

src/DotNetLightning.Core/Channel/CommitmentsModule.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ namespace DotNetLightning.Channel
22

33
open NBitcoin
44

5-
open ResultUtils
6-
75
open DotNetLightning.Utils
86
open DotNetLightning.Transactions
97
open DotNetLightning.Crypto
108
open DotNetLightning.Chain
119
open DotNetLightning.Serialize.Msgs
1210

11+
open ResultUtils
12+
open ResultUtils.Portability
13+
1314
[<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
1415
module internal Commitments =
1516
module private Helpers =

src/DotNetLightning.Core/Crypto/CryptoUtils.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ open NBitcoin.Secp256k1
1313

1414
#endif
1515

16+
open ResultUtils.Portability
17+
1618
type CryptoError =
1719
| BadMac
1820
| InvalidErrorPacketLength of expected: int * actual: int

src/DotNetLightning.Core/Crypto/RevocationSet.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ open NBitcoin
44
open NBitcoin.Crypto
55
open DotNetLightning.Utils
66

7+
open ResultUtils.Portability
8+
79
type InsertRevocationKeyError =
810
| UnexpectedCommitmentNumber of got: CommitmentNumber * expected: CommitmentNumber
911
| KeyMismatch of previousCommitmentNumber: CommitmentNumber * newCommitmentNumber: CommitmentNumber

0 commit comments

Comments
 (0)