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

api, metrics, network: check caps when deciding on next peer for a chunk #1749

Merged
merged 6 commits into from
Sep 12, 2019

Conversation

nonsense
Copy link
Contributor

@nonsense nonsense commented Sep 12, 2019

The findPeer function, which decides which peer the retrieve protocol should ask for a chunk, currently does not check if the returned peer supports the stream protocol - it only ignores light nodes. Because of that it is possible for it to return a bootnode in a given network.

So this PR is adding a filter in the findPeer function, so that we only suggest peers that run the stream protocol. With that change we might not need to even check for light nodes (the if-condition above).

@@ -69,7 +69,7 @@ func (i *Inspector) DeliveriesPerPeer() map[string]int64 {
// iterate connection in kademlia
i.hive.Kademlia.EachConn(nil, 255, func(p *network.Peer, po int) bool {
// get how many chunks we receive for retrieve requests per peer
peermetric := fmt.Sprintf("chunk.delivery.%x", p.Over()[:16])
peermetric := fmt.Sprintf("network.retrieve.chunk.delivery.%x", p.Over()[:16])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Independent of the findPeer - RequestFromPeers bug, but nonetheless a nice-to-have fix, so that DeliveriesFromPeers debug API works.

@@ -121,7 +121,7 @@ func datadirDiskUsage(path string, d time.Duration) {
for range time.Tick(d) {
bytes, err := dirSize(path)
if err != nil {
log.Warn("cannot get disk space", "err", err)
log.Trace("cannot get disk space", "err", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This warning is annoying when we hit LevelDB during compaction, and it is mostly useless in our monitoring system, therefore I am reducing its level.

@@ -231,6 +232,10 @@ func (r *Retrieval) findPeer(ctx context.Context, req *storage.Request) (retPeer
return true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the p.HasCap change, I think we don't need this if p.LightNode check, @janos what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, this can be removed. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted it back, because we change the check for capabilities for bzz-retrieve, and not bzz-stream.

Copy link
Member

@janos janos left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -231,6 +232,10 @@ func (r *Retrieval) findPeer(ctx context.Context, req *storage.Request) (retPeer
return true
Copy link
Member

Choose a reason for hiding this comment

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

I agree, this can be removed. 👍

@@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethersphere/swarm/chunk"
"github.com/ethersphere/swarm/network"
"github.com/ethersphere/swarm/network/stream/v2"
Copy link
Member

Choose a reason for hiding this comment

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

Actually, there is a circular dependency in tests reported by linter. Retrieval is needed in stream tests, and here stream is imported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, so I will just hard-code the name of the protocol. This is not something that should change often. OK?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is OK.

Copy link
Member

@janos janos left a comment

Choose a reason for hiding this comment

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

Thanks Anton

@nonsense nonsense merged commit bbb8612 into master Sep 12, 2019
@skylenet skylenet added this to the 0.5.0 milestone Sep 17, 2019
@nonsense nonsense deleted the retrieve-bootnode-findpeer branch September 30, 2019 10:43
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

3 participants