Skip to content

Commit a1006d8

Browse files
committed
accessman: fix structured logging formatting
1 parent e54206f commit a1006d8

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

accessman.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ func (a *accessMan) addPeerAccess(remotePub *btcec.PublicKey,
611611

612612
// removePeerAccess removes the peer's access from the maps. This should be
613613
// called when the peer has been disconnected.
614-
func (a *accessMan) removePeerAccess(peerPubKey string) {
615-
ctx := btclog.WithCtx(context.TODO(), "peer", peerPubKey)
614+
func (a *accessMan) removePeerAccess(ctx context.Context, peerPubKey string) {
616615
acsmLog.DebugS(ctx, "Removing access:")
617616

618617
a.banScoreMtx.Lock()

accessman_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ func TestAddPeerAccessOutbound(t *testing.T) {
708708
// accessman's internal state based on the peer's status.
709709
func TestRemovePeerAccess(t *testing.T) {
710710
t.Parallel()
711+
ctx := context.Background()
711712

712713
// Create a testing accessMan.
713714
a := &accessMan{
@@ -758,7 +759,7 @@ func TestRemovePeerAccess(t *testing.T) {
758759
// We now assert `removePeerAccess` behaves as expected.
759760
//
760761
// Remove peer1 should change nothing.
761-
a.removePeerAccess(peer1)
762+
a.removePeerAccess(ctx, peer1)
762763

763764
// peer1 should be removed from peerScores but not peerChanInfo.
764765
_, found := a.peerScores[peer1]
@@ -767,7 +768,7 @@ func TestRemovePeerAccess(t *testing.T) {
767768
require.True(t, found)
768769

769770
// Remove peer2 should change nothing.
770-
a.removePeerAccess(peer2)
771+
a.removePeerAccess(ctx, peer2)
771772

772773
// peer2 should be removed from peerScores but not peerChanInfo.
773774
_, found = a.peerScores[peer2]
@@ -776,7 +777,7 @@ func TestRemovePeerAccess(t *testing.T) {
776777
require.True(t, found)
777778

778779
// Remove peer3 should remove it from the maps.
779-
a.removePeerAccess(peer3)
780+
a.removePeerAccess(ctx, peer3)
780781

781782
// peer3 should be removed from peerScores and peerChanInfo.
782783
_, found = a.peerScores[peer3]
@@ -785,7 +786,7 @@ func TestRemovePeerAccess(t *testing.T) {
785786
require.False(t, found)
786787

787788
// Remove peer4 should remove it from the maps.
788-
a.removePeerAccess(peer4)
789+
a.removePeerAccess(ctx, peer4)
789790

790791
// peer4 should be removed from peerScores and NOT be found in
791792
// peerChanInfo.
@@ -795,7 +796,7 @@ func TestRemovePeerAccess(t *testing.T) {
795796
require.False(t, found)
796797

797798
// Remove peer5 should be NOOP.
798-
a.removePeerAccess(peer5)
799+
a.removePeerAccess(ctx, peer5)
799800

800801
// peer5 should NOT be found.
801802
_, found = a.peerScores[peer5]

server.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/btcsuite/btcd/connmgr"
2525
"github.com/btcsuite/btcd/txscript"
2626
"github.com/btcsuite/btcd/wire"
27+
"github.com/btcsuite/btclog/v2"
2728
sphinx "github.com/lightningnetwork/lightning-onion"
2829
"github.com/lightningnetwork/lnd/aliasmgr"
2930
"github.com/lightningnetwork/lnd/autopilot"
@@ -56,6 +57,7 @@ import (
5657
"github.com/lightningnetwork/lnd/lnpeer"
5758
"github.com/lightningnetwork/lnd/lnrpc"
5859
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
60+
"github.com/lightningnetwork/lnd/lnutils"
5961
"github.com/lightningnetwork/lnd/lnwallet"
6062
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
6163
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
@@ -4974,7 +4976,11 @@ func (s *server) removePeerUnsafe(p *peer.Brontide) {
49744976
return
49754977
}
49764978

4977-
srvrLog.Debugf("Removing peer %v", p)
4979+
ctx := btclog.WithCtx(
4980+
context.TODO(), lnutils.LogPubKey("peer", p.IdentityKey()),
4981+
)
4982+
4983+
srvrLog.DebugS(ctx, "Removing peer")
49784984

49794985
// Exit early if we have already been instructed to shutdown, the peers
49804986
// will be disconnected in the server shutdown process.
@@ -5014,7 +5020,7 @@ func (s *server) removePeerUnsafe(p *peer.Brontide) {
50145020

50155021
// Remove the peer's access permission from the access manager.
50165022
peerPubStr := string(p.IdentityKey().SerializeCompressed())
5017-
s.peerAccessMan.removePeerAccess(peerPubStr)
5023+
s.peerAccessMan.removePeerAccess(ctx, peerPubStr)
50185024

50195025
// Copy the peer's error buffer across to the server if it has
50205026
// any items in it so that we can restore peer errors across

0 commit comments

Comments
 (0)