litep2p icon indicating copy to clipboard operation
litep2p copied to clipboard

kad: `Query::next_action()` message is ignored by the kademlia handler

Open lexnv opened this issue 5 months ago • 0 comments

Query::next_action() method returns a QueryAction that contains a raw kademlia message. For the FindNode query type it is the FIND_NODE message, for GetRecords query type it is the GET_VALUE message. https://github.com/paritytech/litep2p/blob/e3a22d5cfbf255e74be1acceb3ea6ec0baa43c09/src/protocol/libp2p/kademlia/query/find_node.rs#L232

The message is ignored by the kademlia handler on_query_action method:

https://github.com/paritytech/litep2p/blob/e3a22d5cfbf255e74be1acceb3ea6ec0baa43c09/src/protocol/libp2p/kademlia/mod.rs#L787-L791

The following lines are ignoring the provided message, and sending the FindNode request regardless of the message provided: https://github.com/paritytech/litep2p/blob/e3a22d5cfbf255e74be1acceb3ea6ec0baa43c09/src/protocol/libp2p/kademlia/mod.rs#L700-L707

The intention behind this behavior was to advance the discoverability of the network. For example, GetRecords query must first discover the network, then publish a GET_VALUE request.

Consider untangling the query message with the kademlia handler and to allow queries to decide which message should be sent. We can further look into optimizing the number of messages sent from the query engine to the kademlia handler (since some of them may be redundant as in this case)

lexnv avatar Sep 03 '24 10:09 lexnv