-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2p: add peer name to networking component contexts #652
Conversation
p2p/peer.go
Outdated
@@ -27,6 +27,8 @@ import ( | |||
"github.com/obolnetwork/charon/app/errors" | |||
) | |||
|
|||
const PeerCtxKey = "peer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it okay to let other packages depend on p2p just for the context key
? other workaround is adding //nolint:revive
to all the changes above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, this is not worth it. We use string literals in many places without needing to add nolint
...
Codecov Report
@@ Coverage Diff @@
## main #652 +/- ##
==========================================
- Coverage 55.23% 54.56% -0.68%
==========================================
Files 98 98
Lines 9477 9517 +40
==========================================
- Hits 5235 5193 -42
- Misses 3492 3575 +83
+ Partials 750 749 -1
Continue to review full report at Codecov.
|
core/consensus/component.go
Outdated
@@ -181,6 +181,7 @@ func (c *Component) Propose(ctx context.Context, duty core.Duty, data core.Unsig | |||
func (c *Component) makeHandler(ctx context.Context) func(s network.Stream) { | |||
ctx = log.WithTopic(ctx, "qbft") | |||
return func(s network.Stream) { | |||
ctx = context.WithValue(ctx, p2p.PeerCtxKey, p2p.PeerName(s.Conn().RemotePeer())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use the log
package for this to work: ctx = log.WithCtx(ctx, z.Str("peer", p2p.PeerName(s.Conn().RemotePeer()))
core/consensus/transport.go
Outdated
@@ -115,6 +116,7 @@ func (t *transport) Broadcast(ctx context.Context, typ qbft.MsgType, duty core.D | |||
continue | |||
} | |||
|
|||
ctx = context.WithValue(ctx, p2p.PeerCtxKey, p2p.PeerName(t.component.tcpNode.ID())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is broadcasting, this ticket is for receiving. p2pSender
will handle sending logs.
Add peer names to "receiver" networking components like parsigex.
category: misc
ticket: #645