Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

all:bzzaddr instead of just overlay for logging #2000

Merged
merged 18 commits into from
Dec 4, 2019
Merged

Conversation

pradovic
Copy link
Contributor

@pradovic pradovic commented Dec 2, 2019

Trying to improve logs by printing the bzzaddr, with both overlay and underlay address, instead of just printing the overlay address, or node-id. This is attempt to solve this: #1961. It is covering mainly the network module, but there are also minor changes in the other modules as well.

In most modules, the logger is initialized with base and/or peer prefix that are used to log info about the node performing the action.

base logger:
I tried to cover all the instances of base logger and use BzzAddr here so we get both overlay/underlay pair in logs.

peer logger:
The same rationale is used as for base, however since the overlay address is not accurate for peers without the bzz-handshake I don't see a way to log this information correctly outside of the, mostly, network package.

Questions:

  • Is this needed for base?
  • Do we need to print both overlay and underlay instead of peer.ID on all places? (ex. r.logger.Trace("findpeer skip peer", "peer", id, "ref", req.Addr.String()))

Improvement:

  • It would be nice to figure out the way to exclude base logs in production and include it only in tests.

@pradovic pradovic requested a review from janos December 2, 2019 13:10
@pradovic pradovic self-assigned this Dec 2, 2019
@janos
Copy link
Member

janos commented Dec 2, 2019

Thanks Petar.

  • Is this needed for base?

I would assume that base address in this context is BzzAddr of the running node itself, not its peers it is connected to. In that case, node addresses are not needed in the production, but that information is useful when debugging test simulations, where we have printed logs from all nodes in the single output.

  • Do we need to print both overlay and underlay instead of peer.ID on all places? (ex. r.logger.Trace("findpeer skip peer", "peer", id, "ref", req.Addr.String()))

I believe that this would improve information that are relevant for debugging.

@pradovic
Copy link
Contributor Author

pradovic commented Dec 2, 2019

Thanks Janos. Cool, I will leave the short address in the base as well, and check if I can add it wherever peer id is used, if possible. At least in network module.

@@ -92,14 +94,14 @@ type NetStore struct {
}

// NewNetStore creates a new NetStore using the provided chunk.Store and localID of the node.
func NewNetStore(store chunk.Store, baseAddr []byte, localID enode.ID) *NetStore {
func NewNetStore(store chunk.Store, baseAddr *network.BzzAddr, localID enode.ID) *NetStore {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BzzAddr already provides enode.ID with its ID() method, so localID should not be needed.

// NewPeer is the constructor for Peer
func NewPeer(peer *network.BzzPeer, baseKey []byte, i state.Store, providers map[string]StreamProvider) *Peer {
// newPeer is the constructor for Peer
func newPeer(peer *network.BzzPeer, address *network.BzzAddr, i state.Store, providers map[string]StreamProvider) *Peer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BzzPeer already has BzzAddr. Maybe it is possible to remove address argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken, peer has a BzzAddr for a peer, and address is a base address. I will rename the argument to baseAddress to avoid the confusion.

@@ -621,7 +621,7 @@ func newRetrievalTester(t *testing.T, prvkey *ecdsa.PrivateKey, netStore *storag
prvkey = key
}

r := New(kad, netStore, kad.BaseAddr(), nil)
r := New(kad, netStore, network.NewBzzAddr(kad.BaseAddr(), network.PrivateKeyToBzzKey(prvkey)), nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PrivateKeyToBzzKey is creating an Overlay address, but here is used in place of Underlay address. Is it correct to set it to nil as it is not available in this function and not used in these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think we can set it to nil as well.

network/network.go Outdated Show resolved Hide resolved
@@ -33,16 +32,17 @@ func TestInspectorPeerStreams(t *testing.T) {
t.Fatal(err)
}

baseAddress := network.NewBzzAddr(baseKey, baseKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea, for the underlay address, to use nil instead, not to present an example where overlay address is used as a value from underlay?

The same question stands for other places where NewBzzAddr is used with identical value for arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I started to change this on the whole project but did not push yet :) Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this concrete case needs underlay address because of the PeerInfo() function, so I have decided to create another rand key for peer base address. I know it's not needed, but I think it gives more info in tests about the nature of address. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe just to add a comment justifying the usage of baseKey in this particular case. That would be also good, at least for me.


i := NewInspector(nil, nil, netStore, stream.New(state.NewInmemoryStore(), baseKey, stream.NewSyncProvider(netStore, network.NewKademlia(
i := NewInspector(nil, nil, netStore, stream.New(state.NewInmemoryStore(), network.NewBzzAddr(baseKey, baseKey), stream.NewSyncProvider(netStore, network.NewKademlia(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseAddress instead NewBzzAddr?

swarm.go Outdated
self.netStore = storage.NewNetStore(lstore, bzzconfig.OverlayAddr, nodeID)
self.retrieval = retrieval.New(to, self.netStore, bzzconfig.OverlayAddr, self.swap) // nodeID.Bytes())
self.netStore = storage.NewNetStore(lstore, bzzconfig.Address)
self.retrieval = retrieval.New(to, self.netStore, bzzconfig.Address, self.swap) // nodeID.Bytes())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it was there before, so I did not erase it yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I did not notice it, thanks.

@pradovic pradovic changed the title network:bzzaddr instead of just overlay for logging all:bzzaddr instead of just overlay for logging Dec 3, 2019
return fmt.Sprintf("%s:%s", a.ShortOver(), a.ShortUnder())
}

func (a *BzzAddr) ShortOver() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment exported functions

return fmt.Sprintf("%s:%s", a.ShortOver(), a.ShortUnder())
}

// ShortOver prints shortened version of Overlay address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prints -> returns

@pradovic pradovic merged commit 45a40fc into master Dec 4, 2019
@pradovic pradovic deleted the oaddr-logs-improve branch December 5, 2019 10:52
@acud acud added this to the 0.5.5 milestone Jan 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants