Skip to content

Commit d3b20b3

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 <knocte@gmail.com>
1 parent df5fbc7 commit d3b20b3

61 files changed

Lines changed: 272 additions & 105 deletions

Some content is hidden

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ open DotNetLightning.Utils
66
open DotNetLightning.Utils.SeqConsumer
77
open DotNetLightning.Crypto
88

9+
open ResultUtils
10+
open ResultUtils.Portability
11+
912
type CommitmentToLocalParameters = {
1013
RevocationPubKey: RevocationPubKey
1114
ToSelfDelay: BlockHeightOffset16

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.Serialization.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.Serialization.Msgs
1210

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

0 commit comments

Comments
 (0)