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

swarm/network/stream: RPC to request subscription info #18284

Closed
wants to merge 3 commits into from

Conversation

holisticode
Copy link
Contributor

This PR adds to the debugging information available.

Over RPC, this code allows to request the stream syncing subscriptions and returns them as a map.
It adds a simulation test which over a snapshot requests all subscriptions.
If provided with a -printstats true flag, it will print the results to STDOUT

Copy link
Contributor

@nolash nolash left a comment

Choose a reason for hiding this comment

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

Reviewed with the disclaimer that I know quite little about the streamer code in general

//arbitrarily set to 16
nodeCount := 16
//set the syncUpdateDelay for sync registrations to start
syncUpdateDelay := 500 * time.Millisecond
Copy link
Contributor

Choose a reason for hiding this comment

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

Why delay and healthy-check?

Copy link
Contributor Author

@holisticode holisticode Dec 13, 2018

Choose a reason for hiding this comment

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

The health check is about the kademlia's health. It will be commented out/removed for now until we have it fixed.

The syncUpdateDelay is a streamer's internal delay time after which it starts actual syncing.
It is relevant to this test in so much as we need to wait at least this delay + the syncing duration time before we actually can check anything.

Check https://github.com/ethereum/go-ethereum/blob/c41721da4849f14ae5bb7fb4509ce94f3a155e53/swarm/network/stream/stream.go#L110-L112

and

https://github.com/ethereum/go-ethereum/blob/c41721da4849f14ae5bb7fb4509ce94f3a155e53/swarm/network/stream/stream.go#L184

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this also be done with messageevents?

Copy link
Contributor Author

@holisticode holisticode Dec 14, 2018

Choose a reason for hiding this comment

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

What do you mean?

There is no streamingStarted event or something like that, and the SyncUpdateDelay is part of the main code, so we need to set it to something and wait for it.

Copy link
Contributor

@nolash nolash Dec 14, 2018

Choose a reason for hiding this comment

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

Like also mentioned herer #18284 (comment) what I mean is then the streaming starts that streaming itself is actually devp2p messages being exchanged, no? Those messages could be inspected, I think;

  • is it a syncSomethingType
  • is it from a peer that hasn't sent this type of message yet

Not sure if I'm making myself clear...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I already updated the PR to wait for SubscribeMsg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nolash can you pls mark this as resolved if you agree or comment further if you think it still needs attention. Thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

The syncUpdateDelay is a streamer's internal delay time after which it starts actual syncing.

In such cases we should always get the value directly from the source where it's defined IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nolash in this case no. If no SyncUpdateDelay is provided, the streamer will set it to 15 * time.Second, which is obviously too long for a test.

Thus we need to set it, which is why it is set to 500 * time.Millisecond for this test.

Check this #18284 (comment) comment please, that has the relevant snippet

swarm/network/stream/stream.go Show resolved Hide resolved
swarm/network/stream/stream.go Outdated Show resolved Hide resolved
swarm/network/stream/streamer_test.go Outdated Show resolved Hide resolved
swarm/network/stream/streamer_test.go Outdated Show resolved Hide resolved
swarm/network/stream/streamer_test.go Outdated Show resolved Hide resolved
swarm/network/stream/streamer_test.go Outdated Show resolved Hide resolved
//arbitrarily set to 16
nodeCount := 16
//set the syncUpdateDelay for sync registrations to start
syncUpdateDelay := 500 * time.Millisecond
Copy link
Contributor

Choose a reason for hiding this comment

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

The syncUpdateDelay is a streamer's internal delay time after which it starts actual syncing.

In such cases we should always get the value directly from the source where it's defined IMO.

msgs := sim.PeerEvents(
context.Background(),
sim.NodeIDs(),
simulation.NewPeerEventsFilter().ReceivedMessages().Protocol("stream").MsgCode(4), //4 is SubscribeMsg
Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh, dangerous with the literal 4.

In fact, if this is the only way to get a message type then the simulation framework has skipped the functionality enabled in the p2p/protocols layer where you can get the message code from the struct type.

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 changed it to get the code via spec.

As a side note though, our tests are littered with tests using hardcoded message codes (see this very same test file, all other codes are literals).

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make an issue for this!

}
log.Debug("Expected message count: ", "expectedMsgCount", expectedMsgCount)
//wait until all subscriptions are done
<-allSubscriptionsDone
Copy link
Contributor

Choose a reason for hiding this comment

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

catch the context timeout in a select here?

t.Fatal(err)
}
//length of the subscriptions can not be smaller than number of peers
if len(pstreams) < len(registry.peers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, are we absolutely sure here that the message is not only sent but the change also processed at this point, resulting in the change in the streamer state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point we are sure that the message has been received. There is no way currently to make sure that a message has been processed - I dare to say that none of our tests based on listening to message exchange can actually do that. To that end we would need a node-wide event propagation system.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes that or message acks after state change :)

@fjl fjl changed the title RPC call to request subscription info swarm/network/stream: RPC to request subscription info Dec 19, 2018
@holisticode
Copy link
Contributor Author

Reopened upstream as #18338

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants