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

+30 -30
View File
@@ -21,24 +21,24 @@ type accessMan struct {
// the server mutex. // the server mutex.
banScoreMtx sync.RWMutex banScoreMtx sync.RWMutex
// peerCounts is a mapping from remote public key to {bool, uint64} // peerChanInfo is a mapping from remote public key to {bool, uint64}
// where the bool indicates that we have an open/closed channel with // where the bool indicates that we have an open/closed channel with the
// the peer and where the uint64 indicates the number of pending-open // peer and where the uint64 indicates the number of pending-open
// channels we currently have with them. This mapping will be used to // channels we currently have with them. This mapping will be used to
// determine access permissions for the peer. The map key is the // determine access permissions for the peer. The map key is the
// string-version of the serialized public key. // string-version of the serialized public key.
// //
// NOTE: This MUST be accessed with the banScoreMtx held. // NOTE: This MUST be accessed with the banScoreMtx held.
peerCounts map[string]channeldb.ChanCount peerChanInfo map[string]channeldb.ChanCount
// peerScores stores each connected peer's access status. The map key // peerScores stores each connected peer's access status. The map key
// is the string-version of the serialized public key. // is the string-version of the serialized public key.
// //
// NOTE: This MUST be accessed with the banScoreMtx held. // NOTE: This MUST be accessed with the banScoreMtx held.
// //
// TODO(yy): unify `peerScores` and `peerCounts` - there's no need to // TODO(yy): unify `peerScores` and `peerChanInfo` - there's no need to
// create two maps tracking essentially the same info. `numRestricted` // create two maps tracking essentially the same info. `numRestricted`
// can also be derived from `peerCounts`. // can also be derived from `peerChanInfo`.
peerScores map[string]peerSlotStatus peerScores map[string]peerSlotStatus
// numRestricted tracks the number of peers with restricted access in // numRestricted tracks the number of peers with restricted access in
@@ -48,7 +48,7 @@ type accessMan struct {
type accessManConfig struct { type accessManConfig struct {
// initAccessPerms checks the channeldb for initial access permissions // initAccessPerms checks the channeldb for initial access permissions
// and then populates the peerCounts and peerScores maps. // and then populates the peerChanInfo and peerScores maps.
initAccessPerms func() (map[string]channeldb.ChanCount, error) initAccessPerms func() (map[string]channeldb.ChanCount, error)
// shouldDisconnect determines whether we should disconnect a peer or // shouldDisconnect determines whether we should disconnect a peer or
@@ -61,9 +61,9 @@ type accessManConfig struct {
func newAccessMan(cfg *accessManConfig) (*accessMan, error) { func newAccessMan(cfg *accessManConfig) (*accessMan, error) {
a := &accessMan{ a := &accessMan{
cfg: cfg, cfg: cfg,
peerCounts: make(map[string]channeldb.ChanCount), peerChanInfo: make(map[string]channeldb.ChanCount),
peerScores: make(map[string]peerSlotStatus), peerScores: make(map[string]peerSlotStatus),
} }
counts, err := a.cfg.initAccessPerms() counts, err := a.cfg.initAccessPerms()
@@ -71,10 +71,10 @@ func newAccessMan(cfg *accessManConfig) (*accessMan, error) {
return nil, err return nil, err
} }
// We'll populate the server's peerCounts map with the counts fetched // We'll populate the server's peerChanInfo map with the counts fetched
// via initAccessPerms. Also note that we haven't yet connected to the // via initAccessPerms. Also note that we haven't yet connected to the
// peers. // peers.
maps.Copy(a.peerCounts, counts) maps.Copy(a.peerChanInfo, counts)
acsmLog.Info("Access Manager initialized") acsmLog.Info("Access Manager initialized")
@@ -90,7 +90,7 @@ func (a *accessMan) hasPeer(ctx context.Context,
a.banScoreMtx.RLock() a.banScoreMtx.RLock()
defer a.banScoreMtx.RUnlock() defer a.banScoreMtx.RUnlock()
count, found := a.peerCounts[pub] count, found := a.peerChanInfo[pub]
if found { if found {
if count.HasOpenOrClosedChan { if count.HasOpenOrClosedChan {
acsmLog.DebugS(ctx, "Peer has open/closed channel, "+ acsmLog.DebugS(ctx, "Peer has open/closed channel, "+
@@ -223,11 +223,11 @@ func (a *accessMan) newPendingOpenChan(remotePub *btcec.PublicKey) error {
case peerStatusTemporary: case peerStatusTemporary:
// If this peer's access status is temporary, we'll need to // If this peer's access status is temporary, we'll need to
// update the peerCounts map. The peer's access status will stay // update the peerChanInfo map. The peer's access status will
// temporary. // stay temporary.
peerCount, found := a.peerCounts[peerMapKey] peerCount, found := a.peerChanInfo[peerMapKey]
if !found { if !found {
// Error if we did not find any info in peerCounts. // Error if we did not find any info in peerChanInfo.
acsmLog.ErrorS(ctx, "Pending peer info not found", acsmLog.ErrorS(ctx, "Pending peer info not found",
ErrNoPendingPeerInfo) ErrNoPendingPeerInfo)
@@ -236,7 +236,7 @@ func (a *accessMan) newPendingOpenChan(remotePub *btcec.PublicKey) error {
// Increment the pending channel amount. // Increment the pending channel amount.
peerCount.PendingOpenCount += 1 peerCount.PendingOpenCount += 1
a.peerCounts[peerMapKey] = peerCount a.peerChanInfo[peerMapKey] = peerCount
acsmLog.DebugS(ctx, "Peer is temporary, incremented "+ acsmLog.DebugS(ctx, "Peer is temporary, incremented "+
"pending count", "pending count",
@@ -246,13 +246,13 @@ func (a *accessMan) newPendingOpenChan(remotePub *btcec.PublicKey) error {
// If the peer's access status is restricted, then we can // If the peer's access status is restricted, then we can
// transition it to a temporary-access peer. We'll need to // transition it to a temporary-access peer. We'll need to
// update numRestricted and also peerScores. We'll also need to // update numRestricted and also peerScores. We'll also need to
// update peerCounts. // update peerChanInfo.
peerCount := channeldb.ChanCount{ peerCount := channeldb.ChanCount{
HasOpenOrClosedChan: false, HasOpenOrClosedChan: false,
PendingOpenCount: 1, PendingOpenCount: 1,
} }
a.peerCounts[peerMapKey] = peerCount a.peerChanInfo[peerMapKey] = peerCount
// A restricted-access slot has opened up. // A restricted-access slot has opened up.
oldRestricted := a.numRestricted oldRestricted := a.numRestricted
@@ -313,12 +313,12 @@ func (a *accessMan) newPendingCloseChan(remotePub *btcec.PublicKey) error {
case peerStatusTemporary: case peerStatusTemporary:
// If this peer is temporary, we need to check if it will // If this peer is temporary, we need to check if it will
// revert to a restricted-access peer. // revert to a restricted-access peer.
peerCount, found := a.peerCounts[peerMapKey] peerCount, found := a.peerChanInfo[peerMapKey]
if !found { if !found {
acsmLog.ErrorS(ctx, "Pending peer info not found", acsmLog.ErrorS(ctx, "Pending peer info not found",
ErrNoPendingPeerInfo) ErrNoPendingPeerInfo)
// Error if we did not find any info in peerCounts. // Error if we did not find any info in peerChanInfo.
return ErrNoPendingPeerInfo return ErrNoPendingPeerInfo
} }
@@ -329,8 +329,8 @@ func (a *accessMan) newPendingCloseChan(remotePub *btcec.PublicKey) error {
"pending_count", currentNumPending) "pending_count", currentNumPending)
if currentNumPending == 0 { if currentNumPending == 0 {
// Remove the entry from peerCounts. // Remove the entry from peerChanInfo.
delete(a.peerCounts, peerMapKey) delete(a.peerChanInfo, peerMapKey)
// If this is the only pending-open channel for this // If this is the only pending-open channel for this
// peer and it's getting removed, attempt to demote // peer and it's getting removed, attempt to demote
@@ -370,7 +370,7 @@ func (a *accessMan) newPendingCloseChan(remotePub *btcec.PublicKey) error {
// Else, we don't need to demote this peer since it has other // Else, we don't need to demote this peer since it has other
// pending-open channels with us. // pending-open channels with us.
peerCount.PendingOpenCount = currentNumPending peerCount.PendingOpenCount = currentNumPending
a.peerCounts[peerMapKey] = peerCount a.peerChanInfo[peerMapKey] = peerCount
acsmLog.DebugS(ctx, "Peer still has other pending channels", acsmLog.DebugS(ctx, "Peer still has other pending channels",
"pending_count", currentNumPending) "pending_count", currentNumPending)
@@ -430,9 +430,9 @@ func (a *accessMan) newOpenChan(remotePub *btcec.PublicKey) error {
case peerStatusTemporary: case peerStatusTemporary:
// If the peer's state is temporary, we'll upgrade the peer to // If the peer's state is temporary, we'll upgrade the peer to
// a protected peer. // a protected peer.
peerCount, found := a.peerCounts[peerMapKey] peerCount, found := a.peerChanInfo[peerMapKey]
if !found { if !found {
// Error if we did not find any info in peerCounts. // Error if we did not find any info in peerChanInfo.
acsmLog.ErrorS(ctx, "Pending peer info not found", acsmLog.ErrorS(ctx, "Pending peer info not found",
ErrNoPendingPeerInfo) ErrNoPendingPeerInfo)
@@ -442,7 +442,7 @@ func (a *accessMan) newOpenChan(remotePub *btcec.PublicKey) error {
peerCount.HasOpenOrClosedChan = true peerCount.HasOpenOrClosedChan = true
peerCount.PendingOpenCount -= 1 peerCount.PendingOpenCount -= 1
a.peerCounts[peerMapKey] = peerCount a.peerChanInfo[peerMapKey] = peerCount
newStatus := peerSlotStatus{ newStatus := peerSlotStatus{
state: peerStatusProtected, state: peerStatusProtected,
@@ -503,7 +503,7 @@ func (a *accessMan) checkAcceptIncomingConn(remotePub *btcec.PublicKey) (
a.banScoreMtx.RLock() a.banScoreMtx.RLock()
defer a.banScoreMtx.RUnlock() defer a.banScoreMtx.RUnlock()
_, found := a.peerCounts[peerMapKey] _, found := a.peerChanInfo[peerMapKey]
// Exit early if found. // Exit early if found.
if found { if found {
@@ -601,7 +601,7 @@ func (a *accessMan) addPeerAccess(remotePub *btcec.PublicKey,
PendingOpenCount: 0, PendingOpenCount: 0,
} }
a.peerCounts[peerMapKey] = peerCount a.peerChanInfo[peerMapKey] = peerCount
a.peerScores[peerMapKey] = peerSlotStatus{ a.peerScores[peerMapKey] = peerSlotStatus{
state: peerStatusTemporary, state: peerStatusTemporary,
} }
+31 -31
View File
@@ -100,22 +100,22 @@ func TestAccessManRestrictedSlots(t *testing.T) {
a, err := newAccessMan(cfg) a, err := newAccessMan(cfg)
require.NoError(t, err) require.NoError(t, err)
// Check that the peerCounts map is correctly populated with three // Check that the peerChanInfo map is correctly populated with three
// peers. // peers.
require.Equal(t, 0, int(a.numRestricted)) require.Equal(t, 0, int(a.numRestricted))
require.Equal(t, 3, len(a.peerCounts)) require.Equal(t, 3, len(a.peerChanInfo))
peerCount1, ok := a.peerCounts[peerKeySer1] peerCount1, ok := a.peerChanInfo[peerKeySer1]
require.True(t, ok) require.True(t, ok)
require.True(t, peerCount1.HasOpenOrClosedChan) require.True(t, peerCount1.HasOpenOrClosedChan)
require.Equal(t, peer1PendingCount, int(peerCount1.PendingOpenCount)) require.Equal(t, peer1PendingCount, int(peerCount1.PendingOpenCount))
peerCount2, ok := a.peerCounts[peerKeySer2] peerCount2, ok := a.peerChanInfo[peerKeySer2]
require.True(t, ok) require.True(t, ok)
require.True(t, peerCount2.HasOpenOrClosedChan) require.True(t, peerCount2.HasOpenOrClosedChan)
require.Equal(t, peer2PendingCount, int(peerCount2.PendingOpenCount)) require.Equal(t, peer2PendingCount, int(peerCount2.PendingOpenCount))
peerCount3, ok := a.peerCounts[peerKeySer3] peerCount3, ok := a.peerChanInfo[peerKeySer3]
require.True(t, ok) require.True(t, ok)
require.False(t, peerCount3.HasOpenOrClosedChan) require.False(t, peerCount3.HasOpenOrClosedChan)
require.Equal(t, peer3PendingCount, int(peerCount3.PendingOpenCount)) require.Equal(t, peer3PendingCount, int(peerCount3.PendingOpenCount))
@@ -144,7 +144,7 @@ func TestAccessManRestrictedSlots(t *testing.T) {
// Assert that accessman's internal state is updated with peer4. We // Assert that accessman's internal state is updated with peer4. We
// expect this new peer to have 1 pending open count. // expect this new peer to have 1 pending open count.
peerCount4, ok := a.peerCounts[string(peerKey4.SerializeCompressed())] peerCount4, ok := a.peerChanInfo[string(peerKey4.SerializeCompressed())]
require.True(t, ok) require.True(t, ok)
require.False(t, peerCount4.HasOpenOrClosedChan) require.False(t, peerCount4.HasOpenOrClosedChan)
require.Equal(t, 1, int(peerCount4.PendingOpenCount)) require.Equal(t, 1, int(peerCount4.PendingOpenCount))
@@ -157,7 +157,7 @@ func TestAccessManRestrictedSlots(t *testing.T) {
// Assert that accessman's internal state is updated with peer3. We // Assert that accessman's internal state is updated with peer3. We
// expect this existing peer to decrement its pending open count and the // expect this existing peer to decrement its pending open count and the
// flag `HasOpenOrClosedChan` should be true. // flag `HasOpenOrClosedChan` should be true.
peerCount3, ok = a.peerCounts[peerKeySer3] peerCount3, ok = a.peerChanInfo[peerKeySer3]
require.True(t, ok) require.True(t, ok)
require.True(t, peerCount3.HasOpenOrClosedChan) require.True(t, peerCount3.HasOpenOrClosedChan)
require.Equal(t, peer3PendingCount-1, int(peerCount3.PendingOpenCount)) require.Equal(t, peer3PendingCount-1, int(peerCount3.PendingOpenCount))
@@ -175,7 +175,7 @@ func TestAccessManRestrictedSlots(t *testing.T) {
require.ErrorIs(t, err, ErrNoMoreRestrictedAccessSlots) require.ErrorIs(t, err, ErrNoMoreRestrictedAccessSlots)
// Assert that peer4 is removed. // Assert that peer4 is removed.
_, ok = a.peerCounts[string(peerKey4.SerializeCompressed())] _, ok = a.peerChanInfo[string(peerKey4.SerializeCompressed())]
require.False(t, ok) require.False(t, ok)
} }
@@ -434,7 +434,7 @@ func TestAssignPeerPermsBypassExisting(t *testing.T) {
return peerPriv.PubKey() return peerPriv.PubKey()
} }
// peer1 exists in `peerCounts` map. // peer1 exists in `peerChanInfo` map.
peer1 := genPeerPub() peer1 := genPeerPub()
peer1Str := string(peer1.SerializeCompressed()) peer1Str := string(peer1.SerializeCompressed())
@@ -494,27 +494,27 @@ func TestHasPeer(t *testing.T) {
// Create a testing accessMan. // Create a testing accessMan.
a := &accessMan{ a := &accessMan{
peerCounts: make(map[string]channeldb.ChanCount), peerChanInfo: make(map[string]channeldb.ChanCount),
peerScores: make(map[string]peerSlotStatus), peerScores: make(map[string]peerSlotStatus),
} }
// peer1 exists with an open channel. // peer1 exists with an open channel.
peer1 := "peer1" peer1 := "peer1"
a.peerCounts[peer1] = channeldb.ChanCount{ a.peerChanInfo[peer1] = channeldb.ChanCount{
HasOpenOrClosedChan: true, HasOpenOrClosedChan: true,
} }
peer1Access := peerStatusProtected peer1Access := peerStatusProtected
// peer2 exists with a pending channel. // peer2 exists with a pending channel.
peer2 := "peer2" peer2 := "peer2"
a.peerCounts[peer2] = channeldb.ChanCount{ a.peerChanInfo[peer2] = channeldb.ChanCount{
PendingOpenCount: 1, PendingOpenCount: 1,
} }
peer2Access := peerStatusTemporary peer2Access := peerStatusTemporary
// peer3 exists without any channels. // peer3 exists without any channels.
peer3 := "peer3" peer3 := "peer3"
a.peerCounts[peer3] = channeldb.ChanCount{} a.peerChanInfo[peer3] = channeldb.ChanCount{}
peer3Access := peerStatusRestricted peer3Access := peerStatusRestricted
// peer4 exists with a score. // peer4 exists with a score.
@@ -560,8 +560,8 @@ func TestAddPeerAccessInbound(t *testing.T) {
// Create a testing accessMan. // Create a testing accessMan.
a := &accessMan{ a := &accessMan{
peerCounts: make(map[string]channeldb.ChanCount), peerChanInfo: make(map[string]channeldb.ChanCount),
peerScores: make(map[string]peerSlotStatus), peerScores: make(map[string]peerSlotStatus),
} }
// Create a testing key. // Create a testing key.
@@ -579,7 +579,7 @@ func TestAddPeerAccessInbound(t *testing.T) {
// taken, and this peer is not found in the counts map. // taken, and this peer is not found in the counts map.
require.Len(t, a.peerScores, 1) require.Len(t, a.peerScores, 1)
require.Equal(t, int64(1), a.numRestricted) require.Equal(t, int64(1), a.numRestricted)
require.NotContains(t, a.peerCounts, pubStr) require.NotContains(t, a.peerChanInfo, pubStr)
// The peer should be found in the score map. // The peer should be found in the score map.
score, ok := a.peerScores[pubStr] score, ok := a.peerScores[pubStr]
@@ -594,12 +594,12 @@ func TestAddPeerAccessInbound(t *testing.T) {
// Assert the internal state is not changed. // Assert the internal state is not changed.
require.Len(t, a.peerScores, 1) require.Len(t, a.peerScores, 1)
require.Equal(t, int64(1), a.numRestricted) require.Equal(t, int64(1), a.numRestricted)
require.NotContains(t, a.peerCounts, pubStr) require.NotContains(t, a.peerChanInfo, pubStr)
// Reset the accessMan. // Reset the accessMan.
a = &accessMan{ a = &accessMan{
peerCounts: make(map[string]channeldb.ChanCount), peerChanInfo: make(map[string]channeldb.ChanCount),
peerScores: make(map[string]peerSlotStatus), peerScores: make(map[string]peerSlotStatus),
} }
// Add this peer as an inbound peer with peerStatusTemporary. // Add this peer as an inbound peer with peerStatusTemporary.
@@ -613,8 +613,8 @@ func TestAddPeerAccessInbound(t *testing.T) {
require.Equal(t, int64(0), a.numRestricted) require.Equal(t, int64(0), a.numRestricted)
// NOTE: in reality this is not possible as the peer must have been put // NOTE: in reality this is not possible as the peer must have been put
// into the map `peerCounts` before its perm can be upgraded. // into the map `peerChanInfo` before its perm can be upgraded.
require.NotContains(t, a.peerCounts, pubStr) require.NotContains(t, a.peerChanInfo, pubStr)
// The peer should be found in the score map. // The peer should be found in the score map.
score, ok = a.peerScores[pubStr] score, ok = a.peerScores[pubStr]
@@ -631,8 +631,8 @@ func TestAddPeerAccessOutbound(t *testing.T) {
// Create a testing accessMan. // Create a testing accessMan.
a := &accessMan{ a := &accessMan{
peerCounts: make(map[string]channeldb.ChanCount), peerChanInfo: make(map[string]channeldb.ChanCount),
peerScores: make(map[string]peerSlotStatus), peerScores: make(map[string]peerSlotStatus),
} }
// Create a testing key. // Create a testing key.
@@ -650,7 +650,7 @@ func TestAddPeerAccessOutbound(t *testing.T) {
// taken, and this peer is found in the counts map. // taken, and this peer is found in the counts map.
require.Len(t, a.peerScores, 1) require.Len(t, a.peerScores, 1)
require.Equal(t, int64(0), a.numRestricted) require.Equal(t, int64(0), a.numRestricted)
require.Contains(t, a.peerCounts, pubStr) require.Contains(t, a.peerChanInfo, pubStr)
// The peer should be found in the score map. // The peer should be found in the score map.
score, ok := a.peerScores[pubStr] score, ok := a.peerScores[pubStr]
@@ -661,7 +661,7 @@ func TestAddPeerAccessOutbound(t *testing.T) {
require.Equal(t, expecedScore, score) require.Equal(t, expecedScore, score)
// The peer should be found in the peer counts map. // The peer should be found in the peer counts map.
count, ok := a.peerCounts[pubStr] count, ok := a.peerChanInfo[pubStr]
require.True(t, ok) require.True(t, ok)
// The peer's count should be initialized correctly. // The peer's count should be initialized correctly.
@@ -674,12 +674,12 @@ func TestAddPeerAccessOutbound(t *testing.T) {
// Assert the internal state is not changed. // Assert the internal state is not changed.
require.Len(t, a.peerScores, 1) require.Len(t, a.peerScores, 1)
require.Equal(t, int64(0), a.numRestricted) require.Equal(t, int64(0), a.numRestricted)
require.Contains(t, a.peerCounts, pubStr) require.Contains(t, a.peerChanInfo, pubStr)
// Reset the accessMan. // Reset the accessMan.
a = &accessMan{ a = &accessMan{
peerCounts: make(map[string]channeldb.ChanCount), peerChanInfo: make(map[string]channeldb.ChanCount),
peerScores: make(map[string]peerSlotStatus), peerScores: make(map[string]peerSlotStatus),
} }
// Add this peer as an inbound peer with peerStatusTemporary. // Add this peer as an inbound peer with peerStatusTemporary.
@@ -693,8 +693,8 @@ func TestAddPeerAccessOutbound(t *testing.T) {
require.Equal(t, int64(0), a.numRestricted) require.Equal(t, int64(0), a.numRestricted)
// NOTE: in reality this is not possible as the peer must have been put // NOTE: in reality this is not possible as the peer must have been put
// into the map `peerCounts` before its perm can be upgraded. // into the map `peerChanInfo` before its perm can be upgraded.
require.NotContains(t, a.peerCounts, pubStr) require.NotContains(t, a.peerChanInfo, pubStr)
// The peer should be found in the score map. // The peer should be found in the score map.
score, ok = a.peerScores[pubStr] score, ok = a.peerScores[pubStr]
+7 -7
View File
@@ -742,7 +742,7 @@ type ChanCount struct {
func (c *ChannelStateDB) FetchPermAndTempPeers( func (c *ChannelStateDB) FetchPermAndTempPeers(
chainHash []byte) (map[string]ChanCount, error) { 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 { err := kvdb.View(c.backend, func(tx kvdb.RTx) error {
openChanBucket := tx.ReadBucket(openChannelBucket) openChanBucket := tx.ReadBucket(openChannelBucket)
@@ -828,7 +828,7 @@ func (c *ChannelStateDB) FetchPermAndTempPeers(
HasOpenOrClosedChan: isPermPeer, HasOpenOrClosedChan: isPermPeer,
PendingOpenCount: pendingOpenCount, PendingOpenCount: pendingOpenCount,
} }
peerCounts[string(nodePub)] = peerCount peerChanInfo[string(nodePub)] = peerCount
return nil return nil
}) })
@@ -892,15 +892,15 @@ func (c *ChannelStateDB) FetchPermAndTempPeers(
remoteSer := remotePub.SerializeCompressed() remoteSer := remotePub.SerializeCompressed()
remoteKey := string(remoteSer) remoteKey := string(remoteSer)
count, exists := peerCounts[remoteKey] count, exists := peerChanInfo[remoteKey]
if exists { if exists {
count.HasOpenOrClosedChan = true count.HasOpenOrClosedChan = true
peerCounts[remoteKey] = count peerChanInfo[remoteKey] = count
} else { } else {
peerCount := ChanCount{ peerCount := ChanCount{
HasOpenOrClosedChan: true, HasOpenOrClosedChan: true,
} }
peerCounts[remoteKey] = peerCount peerChanInfo[remoteKey] = peerCount
} }
} }
@@ -912,10 +912,10 @@ func (c *ChannelStateDB) FetchPermAndTempPeers(
return nil return nil
}, func() { }, func() {
clear(peerCounts) clear(peerChanInfo)
}) })
return peerCounts, err return peerChanInfo, err
} }
// channelSelector describes a function that takes a chain-hash bucket from // 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. // 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") require.NoError(t, err, "unable to fetch perm and temp peers")
// There should only be three entries. // 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 // The first entry should have OpenClosed set to true and Pending set
// to 0. // to 0.
count1, found := peerCounts[string(pubKey1.SerializeCompressed())] count1, found := peerChanInfo[string(pubKey1.SerializeCompressed())]
require.True(t, found, "unable to find peer 1 in peerCounts") require.True(t, found, "unable to find peer 1 in peerChanInfo")
require.True( require.True(
t, count1.HasOpenOrClosedChan, t, count1.HasOpenOrClosedChan,
"couldn't find peer 1's channels", "couldn't find peer 1's channels",
@@ -787,15 +787,15 @@ func TestFetchPermTempPeer(t *testing.T) {
"peer 1 doesn't have 0 pending-open", "peer 1 doesn't have 0 pending-open",
) )
count2, found := peerCounts[string(pubKey2.SerializeCompressed())] count2, found := peerChanInfo[string(pubKey2.SerializeCompressed())]
require.True(t, found, "unable to find peer 2 in peerCounts") require.True(t, found, "unable to find peer 2 in peerChanInfo")
require.False( require.False(
t, count2.HasOpenOrClosedChan, "found erroneous channels", t, count2.HasOpenOrClosedChan, "found erroneous channels",
) )
require.Equal(t, uint64(1), count2.PendingOpenCount) require.Equal(t, uint64(1), count2.PendingOpenCount)
count3, found := peerCounts[string(pubKey3.SerializeCompressed())] count3, found := peerChanInfo[string(pubKey3.SerializeCompressed())]
require.True(t, found, "unable to find peer 3 in peerCounts") require.True(t, found, "unable to find peer 3 in peerChanInfo")
require.True( require.True(
t, count3.HasOpenOrClosedChan, t, count3.HasOpenOrClosedChan,
"couldn't find peer 3's channels", "couldn't find peer 3's channels",