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

kad: Revisit FIND_NODE and increase test coverage #100

Closed
Tracked by #140
lexnv opened this issue May 6, 2024 · 0 comments · Fixed by #114
Closed
Tracked by #140

kad: Revisit FIND_NODE and increase test coverage #100

lexnv opened this issue May 6, 2024 · 0 comments · Fixed by #114
Labels
enhancement New feature or request

Comments

@lexnv
Copy link
Collaborator

lexnv commented May 6, 2024

Refactor the FIND_NODE query to make the code more robust

  • avoid panics / unwraps / unimplemented
  • add an immutable config for the main query logic
  • simplify the next_action method to handle cases in a graceful way
  • add tests to increase test coverage
    • check the fulfillment of parallelism queries
    • no candidates for further actions
    • responding peers that we didn't query
    • completion logic etc

Similar to #97

@lexnv lexnv added the enhancement New feature or request label May 6, 2024
lexnv added a commit that referenced this issue May 24, 2024
This PR refactors the FindNode query to make it more robust.
 - Avoid panics on unwraps and unimplemented logic
 - Separate config immutable variables from main query logic
 - Simplifies logic of next_action method
 - Private methods for internal logic

It also fixes a bug where only the last peer ID of our results was
updated.
- we were registering the first 20 (repl factor) responses
- whenever we got a new response (better) we tried to update just the
peerID_ of the last entry

This had a few implications:
- the first 19 entries are never updated with a better (closer) peer
- the distance of the last entry was never updated. And because of this,
we might end up in a situation where the record is updated with a
furthest distance

```rust
// Presume: 
last_entry: distance = 10, peer = A

// Registering a new response
new_response: distance = 2, peer = B
-> last entry: distance = 10, peer = B

// Registering a new response
new_response: distance = 7, peer = C
-> last entry: distance = 10, peer = C

// we should've kept B as best
```

### Testing Done
- Completes if there's no further candidate to query
- Fulfill number of parallel queries
- Completes on the number of responses
- Provides the closest response out of the batch
- Provides the closest response when the closest peer is indirectly
found and K factor is already fulfilled

Closes #100

cc @paritytech/networking

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant