Skip to content

Commit

Permalink
use log.WithCtx..
Browse files Browse the repository at this point in the history
  • Loading branch information
xenowits committed Jun 2, 2022
1 parent dce97aa commit ce4e77f
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/consensus/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +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()))
ctx = log.WithCtx(ctx, z.Str("peer", p2p.PeerName(s.Conn().RemotePeer())))
defer s.Close()

b, err := io.ReadAll(s)
Expand Down
2 changes: 0 additions & 2 deletions core/consensus/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/obolnetwork/charon/core"
pbv1 "github.com/obolnetwork/charon/core/corepb/v1"
"github.com/obolnetwork/charon/core/qbft"
"github.com/obolnetwork/charon/p2p"
)

// transport encapsulates receiving and broadcasting for a consensus instance/duty.
Expand Down Expand Up @@ -116,7 +115,6 @@ 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()))
err := send(ctx, t.component.tcpNode, p.ID, msg.ToConsensusMsg())
if err != nil {
log.Warn(ctx, "Failed sending message", err)
Expand Down
2 changes: 1 addition & 1 deletion core/leadercast/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type p2pTransport struct {
// handle implements p2p network.StreamHandler processing new incoming messages.
func (t *p2pTransport) handle(s network.Stream) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
ctx = context.WithValue(ctx, p2p.PeerCtxKey, p2p.PeerName(s.Conn().RemotePeer()))
ctx = log.WithCtx(ctx, z.Str("peer", p2p.PeerName(s.Conn().RemotePeer())))

defer cancel()
defer s.Close()
Expand Down
2 changes: 1 addition & 1 deletion core/parsigex/parsigex.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type ParSigEx struct {
func (m *ParSigEx) handle(s network.Stream) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
ctx = log.WithTopic(ctx, "parsigex")
ctx = context.WithValue(ctx, p2p.PeerCtxKey, p2p.PeerName(s.Conn().RemotePeer()))
ctx = log.WithCtx(ctx, z.Str("peer", p2p.PeerName(s.Conn().RemotePeer())))
defer cancel()
defer s.Close()

Expand Down
4 changes: 2 additions & 2 deletions dkg/frostp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newFrostP2P(ctx context.Context, tcpNode host.Host, peers map[uint32]peer.I
}

tcpNode.SetStreamHandler(round1Protocol(clusterID), func(s network.Stream) {
ctx = context.WithValue(ctx, p2p.PeerCtxKey, p2p.PeerName(s.Conn().RemotePeer()))
ctx = log.WithCtx(ctx, z.Str("peer", p2p.PeerName(s.Conn().RemotePeer())))
defer s.Close()

b, err := io.ReadAll(s)
Expand Down Expand Up @@ -79,7 +79,7 @@ func newFrostP2P(ctx context.Context, tcpNode host.Host, peers map[uint32]peer.I
})

tcpNode.SetStreamHandler(round2Protocol(clusterID), func(s network.Stream) {
ctx = context.WithValue(ctx, p2p.PeerCtxKey, p2p.PeerName(s.Conn().RemotePeer()))
ctx = log.WithCtx(ctx, z.Str("peer", p2p.PeerName(s.Conn().RemotePeer())))
defer s.Close()

b, err := io.ReadAll(s)
Expand Down
2 changes: 1 addition & 1 deletion dkg/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type keycastP2P struct {
// ServeShares serves the dealer shares to other nodes on request. It returns when the context is closed.
func (t keycastP2P) ServeShares(ctx context.Context, handler func(nodeIdx int) (msg []byte, err error)) {
t.tcpNode.SetStreamHandler(getProtocol(t.clusterID), func(s network.Stream) {
ctx = context.WithValue(ctx, p2p.PeerCtxKey, p2p.PeerName(s.Conn().RemotePeer()))
ctx = log.WithCtx(ctx, z.Str("peer", p2p.PeerName(s.Conn().RemotePeer())))
defer s.Close()

var (
Expand Down
2 changes: 0 additions & 2 deletions p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"github.com/obolnetwork/charon/app/errors"
)

const PeerCtxKey = "peer"

// Peer represents a peer in the libp2p network, either a charon node or a relay.
type Peer struct {
// ENR defines the networking information of the peer.
Expand Down

0 comments on commit ce4e77f

Please sign in to comment.