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

feat: logic for atoma p2p for gossip nodes public urls #286

Merged
merged 1 commit into from
Feb 6, 2025
Merged

Conversation

jorgeantonio21
Copy link
Contributor

No description provided.

@jorgeantonio21 jorgeantonio21 requested a review from Cifko December 15, 2024 19:42
@jorgeantonio21 jorgeantonio21 self-assigned this Dec 15, 2024
atoma-p2p/src/service.rs Outdated Show resolved Hide resolved
atoma-p2p/src/service.rs Outdated Show resolved Hide resolved
atoma-p2p/src/service.rs Show resolved Hide resolved
event = "gossipsub_message_data",
"Received gossipsub message data"
);
let message_acceptance =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sdbondi I added here error handling for message validation, and providing the acceptance criteria resulting from it, which is then passed below in the report_message_validation_result. How does this look like ?

"Received gossipsub message data"
);
// Address request messages are always accepted and propagated on the p2p network
self.swarm
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sdbondi also added a report_message_validation_result to always accept requests for node addresses, as if I understand correctly, otherwise this message would not be propagated to other nodes.

Copy link

Choose a reason for hiding this comment

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

That is correct - however since gossipsub gossips the message to all subscribers, you probably don't want to use it for this part of the protocol. i.e. a single request will arrive at all subscribers (i.e all nodes) and will result in all nodes sending a response to all nodes. I assume that all nodes also send a request. $O(n^2)$ message complexity.

https://docs.rs/libp2p-request-response/latest/libp2p_request_response/ might be what you're looking for

.swarm
.behaviour_mut()
.gossipsub
.publish(topic, serialized_response)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sdbondi publishing new messages does not require further validation, am I correct ?

@maschad maschad self-assigned this Jan 29, 2025
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

I'm still not convinced having p2p nodes register their public url is an effective mechanism for peer routing

If we are going to be using Kademlia DHTs for discovery this seems counter intuitive, nodes should be located by their PeerID and the content of that peer's route be stored upon discovery.

We can use the NewListenAddress event to dial them upon discovery.

It may be useful to examine how Kademlia works so that this is clearer

EDIT: After discussing with @jorgeantonio21 we decided that for this first iteration we would like to leverage the easy API request routing via axum and then we can move to a more decoupled seperation of concerns with the proxy having an exposed compatible [OpenAPI}(https://www.openapis.org/) which will then routing requests to the nodes, which will be discovered via Kademlia and connected in mesh.

atoma-p2p/src/config.rs Outdated Show resolved Hide resolved
atoma-p2p/src/timer.rs Outdated Show resolved Hide resolved
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

Awesome work on this @jorgeantonio21 🚀

Looking good but left some comments

atoma-p2p/src/service.rs Outdated Show resolved Hide resolved
atoma-p2p/src/service.rs Outdated Show resolved Hide resolved
atoma-p2p/src/service.rs Outdated Show resolved Hide resolved
);
// TODO: should we remove the locally stored public url from an unsubscribed peer?
}
_ => {}
Copy link
Member

Choose a reason for hiding this comment

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

I think there are quite a few more events we will want to explicitly handle here, namely:

     SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(mdns::Event::Discovered(list))) => {
                    for (peer_id, _multiaddr) in list {
                       debug!(
                                target = "atoma-p2p",
                                event = "mdns_discovered",
                                peer_id = %peer_id,
                                "mDNS discovered a new peer"
                            );
    			// Let's explicitly add peers discovered that, they may allow us to find new peers or they may be already subscribed to the topic
                        swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id);
                    }
                },
                SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(mdns::Event::Expired(list))) => {
                    for (peer_id, _multiaddr) in list {
                      debug!(
                                target = "atoma-p2p",
                                event = "mdns_expired",
                                peer_id = %peer_id,
                                "mDNS  peer expired"
                            );
                        swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer_id);
                    }
                },
                  SwarmEvent::NewListenAddr { address, .. } => {
                      debug!(
                                target = "atoma-p2p",
                                event = "new_listen_address",
                                peer_id = %peer_id,
                                ""
                            );
                }
                SwarmEvent::Dialing {
                peer_id: Some(peer_id),
                ..
            } => debug!("Dialing {peer_id}"),
            e => panic!("{e:?}"),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are all these the events to handle ? If I understand correctly gossipsub already integrates kademlia for peer discovery, so there seems to not be much to do on that front..

Copy link
Member

@maschad maschad Feb 5, 2025

Choose a reason for hiding this comment

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

That's inaccurate for rust-libp2p see libp2p/rust-libp2p#5313

At the moment one has to explicitly add them when the Discovered event is emitted as you can see the discovered_nodes is not merged into the gossipsub nor Kademlia properties, which is why in this example it's done explicitly

EDIT: mdns will update the gossipsub mesh but not Kademlia, so this still applies here for that use case.

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 believe we don't need to update kademlia for any new mdns discovery, as these peers are mostly residing on a local network. 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 disagree I think it will help because the bootstrap nodes will now have any locally discovered nodes, which will help any future node during it's bootstrap node.

atoma-p2p/src/service.rs Outdated Show resolved Hide resolved
atoma-p2p/src/service.rs Show resolved Hide resolved
atoma-p2p/src/service.rs Outdated Show resolved Hide resolved
atoma-p2p/src/service.rs Outdated Show resolved Hide resolved
atoma-p2p/src/service.rs Show resolved Hide resolved
@maschad maschad added enhancement New feature or request atoma-service p2p labels Feb 5, 2025
atoma-p2p/src/service.rs Show resolved Hide resolved
atoma-p2p/src/service.rs Show resolved Hide resolved
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

LGTM minus this one comment #286 (comment) Great job @jorgeantonio21 🚀

Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

Excellent work!

@maschad maschad merged commit 4cf4322 into main Feb 6, 2025
12 checks passed
@maschad maschad deleted the ja-atoma-p2p branch February 6, 2025 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants