channeldb+lnd: rename peerCounts to peerChanInfo for clarity

This commit is contained in:
yyforyongyu committed 2025-06-19 16:48:13 +08:00
1 parent 03de0f9e4b
commit 32d8e2123d
4 files changed
+76 -76

No files matched your search

+7 -7
View File
@@ -742,7 +742,7 @@ type ChanCount struct {
func (c *ChannelStateDB) FetchPermAndTempPeers(
chainHash []byte) (map[string]ChanCount, error) {
peerCounts := make(map[string]ChanCount)
peerChanInfo := make(map[string]ChanCount)
err := kvdb.View(c.backend, func(tx kvdb.RTx) error {
openChanBucket := tx.ReadBucket(openChannelBucket)
@@ -828,7 +828,7 @@ func (c *ChannelStateDB) FetchPermAndTempPeers(
HasOpenOrClosedChan: isPermPeer,
PendingOpenCount: pendingOpenCount,
}
peerCounts[string(nodePub)] = peerCount
peerChanInfo[string(nodePub)] = peerCount
return nil
})
@@ -892,15 +892,15 @@ func (c *ChannelStateDB) FetchPermAndTempPeers(
remoteSer := remotePub.SerializeCompressed()
remoteKey := string(remoteSer)
count, exists := peerCounts[remoteKey]
count, exists := peerChanInfo[remoteKey]
if exists {
count.HasOpenOrClosedChan = true
peerCounts[remoteKey] = count
peerChanInfo[remoteKey] = count
} else {
peerCount := ChanCount{
HasOpenOrClosedChan: true,
}
peerCounts[remoteKey] = peerCount
peerChanInfo[remoteKey] = peerCount
}
}
@@ -912,10 +912,10 @@ func (c *ChannelStateDB) FetchPermAndTempPeers(
return nil
}, func() {
clear(peerCounts)
clear(peerChanInfo)
})
return peerCounts, err
return peerChanInfo, err
}
// channelSelector describes a function that takes a chain-hash bucket from
+8 -8
View File
@@ -768,16 +768,16 @@ func TestFetchPermTempPeer(t *testing.T) {
)
// Fetch the ChanCount for our peers.
peerCounts, err := cdb.FetchPermAndTempPeers(key[:])
peerChanInfo, err := cdb.FetchPermAndTempPeers(key[:])
require.NoError(t, err, "unable to fetch perm and temp peers")
// There should only be three entries.
require.Len(t, peerCounts, 3)
require.Len(t, peerChanInfo, 3)
// The first entry should have OpenClosed set to true and Pending set
// to 0.
count1, found := peerCounts[string(pubKey1.SerializeCompressed())]
require.True(t, found, "unable to find peer 1 in peerCounts")
count1, found := peerChanInfo[string(pubKey1.SerializeCompressed())]
require.True(t, found, "unable to find peer 1 in peerChanInfo")
require.True(
t, count1.HasOpenOrClosedChan,
"couldn't find peer 1's channels",
@@ -787,15 +787,15 @@ func TestFetchPermTempPeer(t *testing.T) {
"peer 1 doesn't have 0 pending-open",
)
count2, found := peerCounts[string(pubKey2.SerializeCompressed())]
require.True(t, found, "unable to find peer 2 in peerCounts")
count2, found := peerChanInfo[string(pubKey2.SerializeCompressed())]
require.True(t, found, "unable to find peer 2 in peerChanInfo")
require.False(
t, count2.HasOpenOrClosedChan, "found erroneous channels",
)
require.Equal(t, uint64(1), count2.PendingOpenCount)
count3, found := peerCounts[string(pubKey3.SerializeCompressed())]
require.True(t, found, "unable to find peer 3 in peerCounts")
count3, found := peerChanInfo[string(pubKey3.SerializeCompressed())]
require.True(t, found, "unable to find peer 3 in peerChanInfo")
require.True(
t, count3.HasOpenOrClosedChan,
"couldn't find peer 3's channels",