Skip to content

Commit

Permalink
DotNetRGS: remove mut var in serializeChanUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
aarani committed May 29, 2023
1 parent 1823ce7 commit 4cda7b6
Showing 1 changed file with 109 additions and 68 deletions.
177 changes: 109 additions & 68 deletions DotNetRGS/GossipSnapshotter.fs
Expand Up @@ -847,7 +847,7 @@ type GossipSnapshotter
(previousShortChannelId: ShortChannelId)
=
let latestUpdate = update.Update
let mutable serializedFlags = latestUpdate.ChannelFlags
let channelFlags = latestUpdate.ChannelFlags

if previousShortChannelId > latestUpdate.ShortChannelId then
failwith
Expand All @@ -856,91 +856,132 @@ type GossipSnapshotter
use deltaMemStream = new MemoryStream()
use deltaWriterStream = new LightningWriterStream(deltaMemStream)

match update.Mechanism with
| UpdateSerializationMechanism.Full ->
if latestUpdate.CLTVExpiryDelta <> defaultValues.CLTVExpiryDelta then
serializedFlags <- serializedFlags ||| 0b0100_0000uy
let serializedFlags =
match update.Mechanism with
| UpdateSerializationMechanism.Full ->
let serializedFlags = channelFlags

deltaWriterStream.Write(
latestUpdate.CLTVExpiryDelta.Value,
false
)
let serializedFlags =
if latestUpdate.CLTVExpiryDelta
<> defaultValues.CLTVExpiryDelta then
deltaWriterStream.Write(
latestUpdate.CLTVExpiryDelta.Value,
false
)

if latestUpdate.HTLCMinimumMSat <> defaultValues.HTLCMinimumMSat then
serializedFlags <- serializedFlags ||| 0b0010_0000uy
serializedFlags ||| 0b0100_0000uy
else
serializedFlags

deltaWriterStream.Write(
latestUpdate.HTLCMinimumMSat.MilliSatoshi |> uint64,
false
)
let serializedFlags =
if latestUpdate.HTLCMinimumMSat
<> defaultValues.HTLCMinimumMSat then
deltaWriterStream.Write(
latestUpdate.HTLCMinimumMSat.MilliSatoshi |> uint64,
false
)

if latestUpdate.FeeBaseMSat <> defaultValues.FeeBaseMSat then
serializedFlags <- serializedFlags ||| 0b0001_0000uy
serializedFlags ||| 0b0010_0000uy
else
serializedFlags

deltaWriterStream.Write(
latestUpdate.FeeBaseMSat.MilliSatoshi |> uint32,
false
)
let serializedFlags =
if latestUpdate.FeeBaseMSat <> defaultValues.FeeBaseMSat then
deltaWriterStream.Write(
latestUpdate.FeeBaseMSat.MilliSatoshi |> uint32,
false
)

if latestUpdate.FeeProportionalMillionths
<> defaultValues.FeeProportionalMillionths then
serializedFlags <- serializedFlags ||| 0b0000_1000uy
serializedFlags ||| 0b0001_0000uy
else
serializedFlags

deltaWriterStream.Write(
latestUpdate.FeeProportionalMillionths,
false
)
let serializedFlags =
if latestUpdate.FeeProportionalMillionths
<> defaultValues.FeeProportionalMillionths then
deltaWriterStream.Write(
latestUpdate.FeeProportionalMillionths,
false
)

if latestUpdate.HTLCMaximumMSat.Value
<> defaultValues.HTLCMaximumMSat then
serializedFlags <- serializedFlags ||| 0b0000_0100uy
serializedFlags ||| 0b0000_1000uy
else
serializedFlags

let serializedFlags =
if latestUpdate.HTLCMaximumMSat.Value
<> defaultValues.HTLCMaximumMSat then
deltaWriterStream.Write(
latestUpdate.HTLCMaximumMSat.Value.MilliSatoshi
|> uint64,
false
)

deltaWriterStream.Write(
latestUpdate.HTLCMaximumMSat.Value.MilliSatoshi |> uint64,
false
)
| UpdateSerializationMechanism.Incremental mutatedProperties ->
serializedFlags <- serializedFlags ||| 0b1000_0000uy
serializedFlags ||| 0b0000_0100uy
else
serializedFlags

if mutatedProperties.CltvExpiryDelta then
serializedFlags <- serializedFlags ||| 0b0100_0000uy
serializedFlags
| UpdateSerializationMechanism.Incremental mutatedProperties ->
let serializedFlags = channelFlags ||| 0b1000_0000uy

deltaWriterStream.Write(
latestUpdate.CLTVExpiryDelta.Value,
false
)
let serializedFlags =
if mutatedProperties.CltvExpiryDelta then
deltaWriterStream.Write(
latestUpdate.CLTVExpiryDelta.Value,
false
)

if mutatedProperties.HtlcMinimumMSat then
serializedFlags <- serializedFlags ||| 0b0010_0000uy
serializedFlags ||| 0b0100_0000uy
else
serializedFlags

deltaWriterStream.Write(
latestUpdate.HTLCMinimumMSat.MilliSatoshi |> uint64,
false
)
let serializedFlags =
if mutatedProperties.HtlcMinimumMSat then
deltaWriterStream.Write(
latestUpdate.HTLCMinimumMSat.MilliSatoshi |> uint64,
false
)

if mutatedProperties.FeeBaseMSat then
serializedFlags <- serializedFlags ||| 0b0001_0000uy
serializedFlags ||| 0b0010_0000uy
else
serializedFlags

deltaWriterStream.Write(
latestUpdate.FeeBaseMSat.MilliSatoshi |> uint32,
false
)
let serializedFlags =
if mutatedProperties.FeeBaseMSat then
deltaWriterStream.Write(
latestUpdate.FeeBaseMSat.MilliSatoshi |> uint32,
false
)

if mutatedProperties.FeeProportionalMillionths then
serializedFlags <- serializedFlags ||| 0b0000_1000uy
serializedFlags ||| 0b0001_0000uy
else
serializedFlags

deltaWriterStream.Write(
latestUpdate.FeeProportionalMillionths,
false
)
let serializedFlags =
if mutatedProperties.FeeProportionalMillionths then
deltaWriterStream.Write(
latestUpdate.FeeProportionalMillionths,
false
)

if mutatedProperties.HtlcMaximumMSat then
serializedFlags <- serializedFlags ||| 0b0000_0100uy
serializedFlags ||| 0b0000_1000uy
else
serializedFlags

deltaWriterStream.Write(
latestUpdate.HTLCMaximumMSat.Value.MilliSatoshi |> uint64,
false
)
let serializedFlags =
if mutatedProperties.HtlcMaximumMSat then
deltaWriterStream.Write(
latestUpdate.HTLCMaximumMSat.Value.MilliSatoshi
|> uint64,
false
)

serializedFlags ||| 0b0000_0100uy
else
serializedFlags

serializedFlags

use prefixedMemStream = new MemoryStream()
use prefixedWriterStream = new LightningWriterStream(prefixedMemStream)
Expand Down Expand Up @@ -1144,6 +1185,7 @@ type GossipSnapshotter

let snapshotSyncDayFactors =
[
Int32.MaxValue
1
2
3
Expand All @@ -1153,7 +1195,6 @@ type GossipSnapshotter
7
14
21
Int32.MaxValue
]

let referenceTimestamp =
Expand Down

0 comments on commit 4cda7b6

Please sign in to comment.