Skip to content

Commit 48f2a9f

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). Forward-ported from a4a59d0 Co-authored-by: Andres G. Aragoneses <[email protected]>
1 parent df5fbc7 commit 48f2a9f

Some content is hidden

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

45 files changed

+226
-103
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
with:
1616
dotnet-version: ${{ matrix.dotnet }}
1717

18-
- name: Run tests (BouncyCastle)
18+
- name: Run tests (Portability)
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
@@ -40,6 +40,6 @@ jobs:
4040
run: |
4141
DEBIAN_FRONTEND=noninteractive sudo apt install -y msbuild fsharp
4242
43-
dotnet restore -p:BouncyCastle=True DotNetLightning.sln
44-
msbuild src/DotNetLightning.Core/DotNetLightning.Core.fsproj -p:BouncyCastle=True -p:TargetFramework=netstandard2.0
43+
dotnet restore -p:Portability=True DotNetLightning.sln
44+
msbuild src/DotNetLightning.Core/DotNetLightning.Core.fsproj -p:Portability=True -p:TargetFramework=netstandard2.0
4545

.github/workflows/publish_master.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
with:
3030
dotnet-version: '3.1.200'
3131

32-
- name: Upload nuget packages (BouncyCastle)
32+
- name: Upload nuget packages (Portability)
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

Directory.Build.props

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88

99
<!-->Since NBitcoin.Secp256k1 does not support netstandard 2.0, we will fallback to BouncyCastle build<-->
1010
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
11-
<BouncyCastle>True</BouncyCastle>
11+
<Portability>True</Portability>
1212
</PropertyGroup>
1313

1414

1515
<Choose>
16-
<When Condition="'$(BouncyCastle)'=='true'">
16+
<When Condition="'$(Portability)'=='true'">
1717
<PropertyGroup>
18-
<OtherFlags>$(OtherFlags) -d:BouncyCastle</OtherFlags>
19-
<DefineConstants>$(DefineConstants);BouncyCastle</DefineConstants>
18+
<OtherFlags>$(OtherFlags) -d:NoDUsAsStructs -d:BouncyCastle</OtherFlags>
19+
<DefineConstants>$(DefineConstants);NoDUsAsStructs;BouncyCastle</DefineConstants>
2020
</PropertyGroup>
2121
</When>
2222
</Choose>
2323

2424
<ItemGroup>
2525
<PackageReference Include="NBitcoin" Version="5.0.65" />
26-
<PackageReference Condition="'$(BouncyCastle)'=='true'" Include="Portable.BouncyCastle" Version="1.8.6.7" />
26+
<PackageReference Condition="'$(Portability)'=='true'" Include="Portable.BouncyCastle" Version="1.8.6.7" />
2727
</ItemGroup>
2828

2929
<PropertyGroup>

src/DotNetLightning.Core/Channel/Channel.fs

Lines changed: 3 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,9 @@ open DotNetLightning.Serialization.Msgs
1210
open NBitcoin
1311
open System
1412

13+
open ResultUtils
14+
open ResultUtils.Portability
15+
1516

1617
type ProvideFundingTx = IDestination * Money * FeeRatePerKw -> Result<FinalizedTx * TxOutIndex, string>
1718
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/ChannelOperations.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 DotNetLightning.Utils.NBitcoinExtensions
65
open DotNetLightning.Utils.OnionError
@@ -13,6 +12,9 @@ open DotNetLightning.Serialization
1312

1413
open NBitcoin
1514

15+
open ResultUtils
16+
open ResultUtils.Portability
17+
1618
type OperationMonoHopUnidirectionalPayment = {
1719
Amount: LNMoney
1820
}

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.Serialization.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/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.Serialization.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/Sphinx.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ namespace DotNetLightning.Crypto
33
open System
44
open NBitcoin
55

6-
open ResultUtils
7-
86
open DotNetLightning.Utils
97
open DotNetLightning.Serialization
108
open DotNetLightning.Serialization.Msgs
119

10+
open ResultUtils
11+
open ResultUtils.Portability
12+
1213
module Sphinx =
1314
open NBitcoin.Crypto
1415

src/DotNetLightning.Core/DotNetLightning.Core.fsproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<Choose>
9-
<When Condition="'$(BouncyCastle)'=='true'">
9+
<When Condition="'$(Portability)'=='true'">
1010
<PropertyGroup>
1111
<PackageId>DotNetLightning.Kiss</PackageId>
1212
</PropertyGroup>
@@ -19,7 +19,7 @@
1919
</Choose>
2020

2121
<ItemGroup>
22-
<ProjectReference Condition="'$(BouncyCastle)'!='true'" Include="..\NSec\Experimental\NSec.Experimental.csproj" PrivateAssets="all" />
22+
<ProjectReference Condition="'$(Portability)'!='true'" Include="..\NSec\Experimental\NSec.Experimental.csproj" PrivateAssets="all" />
2323
<ProjectReference Include="..\ResultUtils\ResultUtils.fsproj" PrivateAssets="all" />
2424
<ProjectReference Include="..\InternalBech32Encoder\InternalBech32Encoder.csproj" PrivateAssets="all" />
2525
<ProjectReference Include="..\Macaroons\Macaroons.csproj" PrivateAssets="all" />
@@ -98,7 +98,7 @@
9898
</ItemGroup>
9999
<ItemGroup>
100100
<PackageReference Update="FSharp.Core" Version="4.7.0" />
101-
<PackageReference Condition="'$(BouncyCastle)' != 'true'" Include="NBitcoin.Secp256k1" Version="1.0.8" />
101+
<PackageReference Condition="'$(Portability)' != 'true'" Include="NBitcoin.Secp256k1" Version="1.0.8" />
102102
<PackageReference Include="System.Memory" Version="4.5.3" />
103103
</ItemGroup>
104104

0 commit comments

Comments
 (0)