Skip to content

Commit

Permalink
Prevent possible F#4.0 compilation issue
Browse files Browse the repository at this point in the history
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 but could generate exceptions at runtime if the
resulting binary is referenced when compiling with an old compiler, e.g.:

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
  • Loading branch information
knocte committed Aug 22, 2020
1 parent a0ea6e1 commit 45061ad
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/DotNetLightning.Core/Utils/Errors.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ module OnionError =
let CHANNEL_DISABLED = UPDATE ||| 20us

[<Flags>]
[<Struct>]
type FailureCode = | FailureCode of uint16 with

member this.Value = let (FailureCode v) = this in v
Expand Down
1 change: 0 additions & 1 deletion src/DotNetLightning.Core/Utils/LNMoney.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type LNMoneyUnit =
/// Why not use the package directly? because it might cause circular dependency in the future.
/// (i.e. We might want to support this package in BTCPayServer.Lightning)
/// refs: https://github.com/btcpayserver/BTCPayServer.Lightning/blob/f65a883a63bf607176a3b7b0baa94527ac592f5e/src/BTCPayServer.Lightning.Common/LightMoney.cs
[<Struct>]
type LNMoney = | LNMoney of int64 with

static member private BitcoinStyle =
Expand Down
10 changes: 3 additions & 7 deletions src/DotNetLightning.Core/Utils/Primitives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module Primitives =
output

/// Absolute block height
[<Struct>]
type BlockHeight = | BlockHeight of uint32 with
static member Zero = 0u |> BlockHeight
static member One = 1u |> BlockHeight
Expand All @@ -58,7 +57,7 @@ module Primitives =
/// 16bit relative block height used for `OP_CSV` locks,
/// Since OP_CSV allow only block number of 0 ~ 65535, it is safe
/// to restrict into the range smaller than BlockHeight
and [<Struct>] BlockHeightOffset16 = | BlockHeightOffset16 of uint16 with
and BlockHeightOffset16 = | BlockHeightOffset16 of uint16 with
member x.Value = let (BlockHeightOffset16 v) = x in v

static member ofBlockHeightOffset32(bho32: BlockHeightOffset32) =
Expand All @@ -77,7 +76,7 @@ module Primitives =
///
/// 32bit relative block height. For `OP_CSV` locks, BlockHeightOffset16
/// should be used instead.
and [<Struct>] BlockHeightOffset32 = | BlockHeightOffset32 of uint32 with
and BlockHeightOffset32 = | BlockHeightOffset32 of uint32 with
member x.Value = let (BlockHeightOffset32 v) = x in v

static member ofBlockHeightOffset16(bho16: BlockHeightOffset16) =
Expand Down Expand Up @@ -336,23 +335,20 @@ module Primitives =
type BlockId = | BlockId of uint256 with
member x.Value = let (BlockId v) = x in v

[<Struct>]
type HTLCId = | HTLCId of uint64 with
static member Zero = HTLCId(0UL)
member x.Value = let (HTLCId v) = x in v

static member (+) (a: HTLCId, b: uint64) = (a.Value + b) |> HTLCId

[<Struct>]
type TxOutIndex = | TxOutIndex of uint16 with
member x.Value = let (TxOutIndex v) = x in v

[<Struct>]
type TxIndexInBlock = | TxIndexInBlock of uint32 with
member x.Value = let (TxIndexInBlock v) = x in v


[<Struct;StructuredFormatDisplay("{AsString}")>]
[<StructuredFormatDisplay("{AsString}")>]
type ShortChannelId = {
BlockHeight: BlockHeight
BlockIndex: TxIndexInBlock
Expand Down
1 change: 0 additions & 1 deletion src/DotNetLightning.Core/Utils/UInt48.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace DotNetLightning.Utils
open System
open DotNetLightning.Core.Utils.Extensions

[<Struct>]
type UInt48 = {
UInt64: uint64
} with
Expand Down

0 comments on commit 45061ad

Please sign in to comment.