Skip to content

Commit

Permalink
GossipSnapshotter: rm mut var in readIntermediates
Browse files Browse the repository at this point in the history
  • Loading branch information
aarani committed Jun 6, 2023
1 parent 66e8d16 commit 22f15db
Showing 1 changed file with 77 additions and 46 deletions.
123 changes: 77 additions & 46 deletions DotNetRGS/GossipSnapshotter.fs
Expand Up @@ -454,13 +454,12 @@ type GossipSnapshotter

use reader = readCommand.ExecuteReader()

let mutable previousShortChannelId =
ShortChannelId.FromUInt64 UInt64.MaxValue

let mutable previouslySeenDirections = false, false

if reader.HasRows then
let rec readRow(deltaSet: DeltaSet) =
let rec readRow
(previousShortChannelId: ShortChannelId)
(previouslySeenDirections: bool * bool)
(deltaSet: DeltaSet)
=
async {
let readResult = reader.Read()

Expand All @@ -470,7 +469,11 @@ type GossipSnapshotter
|> reader.GetInt32

if referenceIds.Contains updateId then
return! readRow deltaSet
return!
readRow
previousShortChannelId
previouslySeenDirections
deltaSet
else
let direction =
reader.GetOrdinal "direction"
Expand All @@ -484,11 +487,13 @@ type GossipSnapshotter
let scId =
updateMsg.Contents.ShortChannelId

if previousShortChannelId <> scId then
previousShortChannelId <- scId

previouslySeenDirections <-
false, false
let (previousShortChannelId,
previouslySeenDirections) =
if previousShortChannelId <> scId then
scId, (false, false)
else
previousShortChannelId,
previouslySeenDirections

let currentSeenTimestamp =
reader.GetOrdinal "seen"
Expand All @@ -513,40 +518,60 @@ type GossipSnapshotter
|> Option.defaultValue
DirectedUpdateDelta.Default

if
not direction
&& not(fst previouslySeenDirections)
then
previouslySeenDirections <-
true,
snd previouslySeenDirections
let (previouslySeenDirections,
updateDelta) =
if
not direction
&& not
(
fst
previouslySeenDirections
)
then
let previouslySeenDirections =
true,
snd previouslySeenDirections

previouslySeenDirections,
{ updateDelta with
LastUpdateAfterSeen =
Some
{
Seen =
DateTimeUtils.ToUnixTimestamp
currentSeenTimestamp
Update =
updateMsg.Contents
}
}
elif
direction
&& not
(
snd
previouslySeenDirections
)
then
let previouslySeenDirections =
fst previouslySeenDirections,
true

previouslySeenDirections,
{ updateDelta with
LastUpdateAfterSeen =
Some
{
Seen =
DateTimeUtils.ToUnixTimestamp
currentSeenTimestamp
Update =
updateMsg.Contents
}
}
else
previouslySeenDirections,
updateDelta

updateDelta.LastUpdateAfterSeen <-
Some
{
Seen =
DateTimeUtils.ToUnixTimestamp
currentSeenTimestamp
Update =
updateMsg.Contents
}
elif
direction
&& not(snd previouslySeenDirections)
then
previouslySeenDirections <-
fst previouslySeenDirections,
true

updateDelta.LastUpdateAfterSeen <-
Some
{
Seen =
DateTimeUtils.ToUnixTimestamp
currentSeenTimestamp
Update =
updateMsg.Contents
}

let lastSeenUpdate =
updateDelta.LastUpdateBeforeSeen
Expand Down Expand Up @@ -603,12 +628,18 @@ type GossipSnapshotter
deltaSet
|> Map.add scId channelDelta
|> readRow
previousShortChannelId
previouslySeenDirections

else
return deltaSet
}

return! readRow deltaSet
return!
readRow
(ShortChannelId.FromUInt64 UInt64.MaxValue)
(false, false)
deltaSet
else
return deltaSet
}
Expand Down

0 comments on commit 22f15db

Please sign in to comment.