Skip to content

Conversation

@0xMimir
Copy link
Contributor

@0xMimir 0xMimir commented Apr 24, 2024

I have code to handle action being SendResponse and state being Incoming(RequestIsReady) in kademlia stream effects, this allows for node to respond to incoming requests.

@akoptelov, Could you take a look

Copy link
Contributor

@akoptelov akoptelov left a comment

Choose a reason for hiding this comment

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

This fix resolves the issue only partially.

Please take a look at the existing effect code for IncomingData action, when state is RequestIsReady. It first dispatches AnswerFindNodeRequest (to query Kademlia routing table) and then WaitOutgoing so reducer changes the state. It looks like the order should be opposite -- we should first switch to expecting an answer from our Kademlia routing table, and only then ask it to provide the answer. I think this is a common pitfall when we dispatch actions are not "asyncronous", i.e. triggering other actions that change the current state.

Also, regarding the amount of states, incoming kademlia stream should be properly handled. A server (this node in this case) should expect more queries, and close the stream only after the client closes its half.

https://github.com/libp2p/specs/tree/master/kad-dht#rpc-messages

@akoptelov
Copy link
Contributor

@0xMimir Don't you mind also adding a test on this? There's a brand new p2p framework, I can help you with that.

This is very basic example of a test: https://github.com/openmina/openmina/blob/develop/p2p/tests/basic.rs

Shortly I'll add one for identify protocol.

@akoptelov
Copy link
Contributor

Shortly I'll add one for identify protocol.

This one:
https://github.com/openmina/openmina/blob/3bcae092f34ee862d16b1cb7c979495eb8438b24/p2p/tests/identify.rs

Copy link
Contributor

@akoptelov akoptelov left a comment

Choose a reason for hiding this comment

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

@0xMimir In order to run the cluster, you should poll its events by using some stream operations. Without it statemachines of the nodes inside it won't progress.

This might look tool low-level, but in this way you have the full control over the nodes, where to continue or stop the execution, and inject an action at the right time.

Please take a look at the basic.rs example, there's a code that waits for node to listen, then connects another node to it, and waits for it to be a ready peer, and so on.

For your case, I think it makes sense to wait for a specific event that signals that Kademlia bootstrap is finished. You might need to extend RustNodeEvent enum with that and add a code to "record" such event:

https://github.com/openmina/openmina/pull/374/files#diff-8c283320f6fd13d3f67602540e9eb813405702c36d4925f9f2d1e342168b90ec

@akoptelov
Copy link
Contributor

@0xMimir
Also, can you put all kademlia tests into a single file?

Copy link
Contributor

@akoptelov akoptelov left a comment

Choose a reason for hiding this comment

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

Looks good, but I want to ask you about the last change. I've changed the default node configuration for p2p tests so discovery is turned off. Please enable it explicitly when needed.

@akoptelov
Copy link
Contributor

@0xMimir you will need to rebase on top of the latest develop

akoptelov
akoptelov previously approved these changes May 1, 2024
Copy link
Contributor

@akoptelov akoptelov left a comment

Choose a reason for hiding this comment

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

LGTM, with a comment for a future.

std::env::set_var("OPENMINA_DISCOVERY_FILTER_ADDR", "false");

let mut cluster = ClusterBuilder::new()
.ports(11000..11200)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tests from a single test file are executed in different threads, and we should make sure they use disjoint set of ports, otherwise they will fail randomly.

I need to implement a shared storage for port ranges...

For now this is fine as the test is ignored.

@akoptelov akoptelov self-requested a review May 1, 2024 17:05
@akoptelov
Copy link
Contributor

UPD. I see, there is no discovery enabled in the test yet...

@akoptelov akoptelov dismissed their stale review May 1, 2024 17:07

Test is failing

@0xMimir
Copy link
Contributor Author

0xMimir commented May 1, 2024

After rebase test started failing, but when testing if second node gets into BOOTSTRAP state and first node responds with kademlia, everything works, I am currently debugging why the test is failing

@0xMimir
Copy link
Contributor Author

0xMimir commented May 1, 2024

UPD. I see, there is no discovery enabled in the test yet...

I enabled it in last commit

Copy link
Contributor

@akoptelov akoptelov left a comment

Choose a reason for hiding this comment

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

LGTM

@0xMimir
Copy link
Contributor Author

0xMimir commented May 1, 2024

LGTM

I don't have permission to merge pull requests, so can you do it.

@tizoc tizoc merged commit 10c9bf8 into o1-labs:develop May 1, 2024
@0xMimir 0xMimir deleted the bugfix/#361 branch September 16, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants