Skip to content
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

Merged
merged 2 commits into from
Jun 2, 2022

Conversation

xenowits
Copy link
Contributor

@xenowits xenowits commented Jun 2, 2022

Add peer names to "receiver" networking components like parsigex.

category: misc
ticket: #645

p2p/peer.go Outdated
@@ -27,6 +27,8 @@ import (
"github.com/obolnetwork/charon/app/errors"
)

const PeerCtxKey = "peer"
Copy link
Contributor Author

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

Copy link
Contributor

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
Copy link

codecov bot commented Jun 2, 2022

Codecov Report

Merging #652 (ce4e77f) into main (87c2054) will decrease coverage by 0.67%.
The diff coverage is 100.00%.

@@            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     
Impacted Files Coverage Δ
core/consensus/component.go 61.58% <100.00%> (+0.25%) ⬆️
core/leadercast/transport.go 77.09% <100.00%> (+0.35%) ⬆️
core/parsigex/parsigex.go 64.36% <100.00%> (+0.41%) ⬆️
dkg/frostp2p.go 72.55% <100.00%> (+0.20%) ⬆️
dkg/transport.go 53.70% <100.00%> (+0.87%) ⬆️
core/qbft/qbft.go 71.55% <0.00%> (-10.35%) ⬇️
core/aggsigdb/memory.go 86.17% <0.00%> (-2.13%) ⬇️
core/scheduler/scheduler.go 74.26% <0.00%> (-0.60%) ⬇️
testutil/compose/config.go 83.33% <0.00%> (ø)
testutil/compose/template.go 43.75% <0.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87c2054...ce4e77f. Read the comment docs.

@xenowits xenowits linked an issue Jun 2, 2022 that may be closed by this pull request
@@ -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()))
Copy link
Contributor

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()))

@@ -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()))
Copy link
Contributor

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.

@xenowits xenowits added the merge when ready Indicates bulldozer bot may merge when all checks pass label Jun 2, 2022
@obol-bulldozer obol-bulldozer bot merged commit 09a53fb into main Jun 2, 2022
@obol-bulldozer obol-bulldozer bot deleted the xenowits/networking-peer-names branch June 2, 2022 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge when ready Indicates bulldozer bot may merge when all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add peer names to context and log it
2 participants