Skip to content

Commit

Permalink
DotNetRGS: remove mut var in serializeDeltaSet
Browse files Browse the repository at this point in the history
This commit also moves the ChainHash selection
to a new Constants file so we can get rid of
the mutable chainHashSet variable.
  • Loading branch information
aarani committed May 30, 2023
1 parent 48b0dd7 commit 8dd67c2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 45 deletions.
9 changes: 9 additions & 0 deletions DotNetRGS/Constants.fs
@@ -0,0 +1,9 @@
namespace DotNetRGS

open GWallet.Backend

open NBitcoin

module Constants =
let Currency = Currency.BTC
let ChainHash = Network.Main.GenesisHash
1 change: 1 addition & 0 deletions DotNetRGS/DotNetRGS.fsproj
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="Constants.fs" />
<Content Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
80 changes: 39 additions & 41 deletions DotNetRGS/GossipSnapshotter.fs
Expand Up @@ -650,11 +650,9 @@ type GossipSnapshotter
Updates = List.Empty
FullUpdateDefaults = DefaultUpdateValues.Default
LatestSeen = 0u
ChainHash = uint256.Zero
ChainHash = Constants.ChainHash
}

let mutable chainHashSet = false

let fullUpdateHistograms = FullUpdateValueHistograms.Default

let recordFullUpdateInHistograms(fullUpdate: UnsignedChannelUpdateMsg) =
Expand Down Expand Up @@ -704,12 +702,6 @@ type GossipSnapshotter
channelDelta.Announcement
"channelDelta.Announcement is none, did you forget to run filterDeltaSet?"

if not chainHashSet then
chainHashSet <- true

serializationSet.ChainHash <-
channelAnnouncementDelta.Announcement.ChainHash

let currentAnnouncementSeen = channelAnnouncementDelta.Seen
let isNewAnnouncement = currentAnnouncementSeen >= lastSyncTimestamp

Expand All @@ -721,13 +713,19 @@ type GossipSnapshotter
let sendAnnouncement =
isNewAnnouncement || isNewlyUpdatedAnnouncement

if sendAnnouncement then
serializationSet.LatestSeen <-
max serializationSet.LatestSeen currentAnnouncementSeen

serializationSet.Announcements <-
channelAnnouncementDelta.Announcement
:: serializationSet.Announcements
let serializationSet =
if sendAnnouncement then
{ serializationSet with
LatestSeen =
max
serializationSet.LatestSeen
currentAnnouncementSeen
Announcements =
channelAnnouncementDelta.Announcement
:: serializationSet.Announcements
}
else
serializationSet

let directionAUpdates, directionBUpdates = channelDelta.Updates

Expand Down Expand Up @@ -788,31 +786,31 @@ type GossipSnapshotter
categorizeDirectedUpdateSerialization directionAUpdates
categorizeDirectedUpdateSerialization directionBUpdates

serializationSet.FullUpdateDefaults <-
{
CLTVExpiryDelta =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.CLTVExpiryDelta
BlockHeightOffset16.Zero
HTLCMinimumMSat =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.HTLCMinimumMSat
LNMoney.Zero
FeeBaseMSat =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.FeeBaseMSat
LNMoney.Zero
FeeProportionalMillionths =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.FeeProportionalMillionths
0u
HTLCMaximumMSat =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.HTLCMaximumMSat
LNMoney.Zero
}

serializationSet
{ serializationSet with
FullUpdateDefaults =
{
CLTVExpiryDelta =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.CLTVExpiryDelta
BlockHeightOffset16.Zero
HTLCMinimumMSat =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.HTLCMinimumMSat
LNMoney.Zero
FeeBaseMSat =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.FeeBaseMSat
LNMoney.Zero
FeeProportionalMillionths =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.FeeProportionalMillionths
0u
HTLCMaximumMSat =
Histogram.findMostCommonHistogramEntryWithDefault
fullUpdateHistograms.HTLCMaximumMSat
LNMoney.Zero
}
}

let serializeStrippedChannelAnnouncement
(announcement: UnsignedChannelAnnouncementMsg)
Expand Down
7 changes: 3 additions & 4 deletions DotNetRGS/GossipSyncer.fs
Expand Up @@ -39,7 +39,7 @@ type internal GossipSyncer
PeerNode.Connect
throwawayPrivKey
peer
Currency.BTC
Constants.Currency
Money.Zero
ConnectionPurpose.Routing

Expand All @@ -48,7 +48,7 @@ type internal GossipSyncer
| Ok node -> node
| Error e -> failwith "connecting to peer failed"

let chainHash = Network.Main.GenesisHash
let chainHash = Constants.ChainHash

let recvMsg msgStream =
async {
Expand Down Expand Up @@ -235,8 +235,7 @@ type internal GossipSyncer

let gossipTimeStampFilter =
{
GossipTimestampFilterMsg.ChainHash =
Network.Main.GenesisHash
GossipTimestampFilterMsg.ChainHash = chainHash
FirstTimestamp = firstTimestamp
TimestampRange = UInt32.MaxValue
}
Expand Down

0 comments on commit 8dd67c2

Please sign in to comment.