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: adding onValidated observer #1128

Merged
merged 10 commits into from
Aug 1, 2024
Merged

feat: adding onValidated observer #1128

merged 10 commits into from
Aug 1, 2024

Conversation

gabrielmer
Copy link
Contributor

@gabrielmer gabrielmer commented Jun 17, 2024

Description

Adding an onValidated observer which will run every time a message is received and validated. This comes from the necessity of precisely track message deliveries and network activity.

onRecv observers run before any check is performed on the received message, which means that it runs every time a duplicate or invalid message arrives, which is inefficient and inaccurate for our purpose of tracking only received, unique and valid messages. Therefore, adding this extra option of running an observer for every message after all validation checks pass.

@gabrielmer gabrielmer self-assigned this Jun 17, 2024
@diegomrsantos
Copy link
Contributor

Are you using the latest master? It seems there are some formatting changes that should be addressed in the latest master.

@gabrielmer
Copy link
Contributor Author

Are you using the latest master? It seems there are some formatting changes that should be addressed in the latest master.

I branched out from dc83a1e so we do have the formatting changes. We actually use currently v1.3.0 but branched out one commit after the release to have the formatting in.

We also use nph v0.5.1 so we're aligned with that :))

There may be many compilation issues now, I wanted to run the CI first and see what pops up, but will fix them promptly

@diegomrsantos
Copy link
Contributor

I see. It's cause a new param was added exactly when the param list stopped being in one line and it was difficult to see the change https://github.com/vacp2p/nim-libp2p/pull/1128/files#diff-abbf987f19a24c9940cd01bde79a1b1e0819f1c3b6d7ba2efa04ad680d022c78R385

@kaiserd
Copy link
Collaborator

kaiserd commented Jun 20, 2024

Thinking about how we could potentially integrate this in master:

  1. Would it be possible to express what you need in a app layer validator call back that gets handed tovalidateAndRelay ?
    That seems to be a generally useful approach.
    It could be called after the standard nim-libp2p validation, and add app specific validation.
    This might allow moving the additional logging to Waku / applications.

  2. In case 1) is not enough: logging specific parts necessary in nim-libp2p could be enabled at compile time using enabled_topcis
    This is fine as long as this additional logging does not cause any runtime overhead.

@gabrielmer
Copy link
Contributor Author

  1. Would it be possible to express what you need in a app layer validator call back that gets handed tovalidateAndRelay ?
    That seems to be a generally useful approach.
    It could be called after the standard nim-libp2p validation, and add app specific validation.
    This might allow moving the additional logging to Waku / applications.

Thanks so much! I think I can do exactly the same I'm doing in this PR but adding a generic construct to add app specific logic.

I think it can be hard to accurately understand what we exactly need without actually coding it and finding constraints we might hadn't think about.

If it sounds good to you, I can implement the same thing by doing this generic extension, get feedback, iterate and go from there.

lmk what you think :)) @kaiserd @Ivansete-status

@diegomrsantos
Copy link
Contributor

I believe you can experiment here until you find what you need, but eventually it's better to find a way to add the changes to master for two reasons:

  1. it can benefit other projects if they need the same.
  2. it's going to be bothersome to keep this branch up-to-date with master.

@gabrielmer
Copy link
Contributor Author

I believe you can experiment here until you find what you need, but eventually it's better to find a way to add the changes to master for two reasons:

  1. it can benefit other projects if they need the same.
  2. it's going to be bothersome to keep this branch up-to-date with master.

I agree 100%, the idea is to now change this PR with a more generic approach with the target to actually get merged to master

@gabrielmer
Copy link
Contributor Author

It does seem that we can actually get the information that we want without changing anything in nim-libp2p by using onSend observers instead of onRecv which was our first approach.

We will merge waku-org/nwaku#2851 for it.

If after using it for simulations we conclude that this approach logs all the necessary information, then I will close this PR. Otherwise, will implement over here a solution for it that could be merged to nim-libp2p

@diegomrsantos
Copy link
Contributor

Thanks for the update.

@gabrielmer
Copy link
Contributor Author

We started having the original issue and were in need of info only available at the nim-libp2p layer, so pushed again changes to this PR

Currently having it over an old nim-libp2p commit so it matches the one used in our latest release, but soon will rebase it.

I think this new approach is simpler and pretty neat, please let me know if a solution like this is something that could be eventually merged into master :)

@gabrielmer
Copy link
Contributor Author

@diegomrsantos @kaiserd WDYT about this new approach? is it something that could be merged?

@gabrielmer gabrielmer marked this pull request as ready for review July 30, 2024 07:30
@codecov-commenter
Copy link

codecov-commenter commented Jul 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.53%. Comparing base (02c96fc) to head (5c307da).
Report is 40 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #1128    +/-   ##
========================================
  Coverage   84.53%   84.53%            
========================================
  Files          91       92     +1     
  Lines       15517    16423   +906     
========================================
+ Hits        13118    13884   +766     
- Misses       2399     2539   +140     
Files Coverage Δ
libp2p/protocols/pubsub/gossipsub.nim 85.02% <100.00%> (-1.45%) ⬇️
libp2p/protocols/pubsub/pubsubpeer.nim 82.91% <100.00%> (-3.23%) ⬇️

... and 79 files with indirect coverage changes

@gabrielmer gabrielmer marked this pull request as draft July 31, 2024 12:38
@gabrielmer gabrielmer marked this pull request as ready for review July 31, 2024 13:07
@diegomrsantos
Copy link
Contributor

Please update the PR's title and description to reflect its current state.

@gabrielmer gabrielmer changed the title chore: creating branch to test Waku's received messages chore: adding onValidated observer Aug 1, 2024
@gabrielmer
Copy link
Contributor Author

Please update the PR's title and description to reflect its current state.

Yup, ready 🫡

Copy link
Contributor

@diegomrsantos diegomrsantos left a comment

Choose a reason for hiding this comment

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

Amazing job, thanks a lot!

@diegomrsantos diegomrsantos changed the title chore: adding onValidated observer feat: adding onValidated observer Aug 1, 2024
@gabrielmer
Copy link
Contributor Author

Amazing job, thanks a lot!

Thanks to you for the time and all the help! 🫶

Copy link
Collaborator

@kaiserd kaiserd left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you very much.
Feel free to merge. The interop test is inactive for now.

@gabrielmer gabrielmer merged commit a60f0c5 into master Aug 1, 2024
13 of 14 checks passed
@gabrielmer gabrielmer deleted the enhance-logs-for-nwaku branch August 1, 2024 15:50
AlejandroCabeza added a commit that referenced this pull request Aug 1, 2024
* master:
  feat: adding onValidated observer (#1128)
  fix: add gcc 14 support (#1151)
  fix(ci): windows-amd64 (Nim version-1-6) (#1160)
AlejandroCabeza added a commit that referenced this pull request Aug 1, 2024
* master:
  feat: adding onValidated observer (#1128)
  fix: add gcc 14 support (#1151)
  fix(ci): windows-amd64 (Nim version-1-6) (#1160)
@diegomrsantos
Copy link
Contributor

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

Successfully merging this pull request may close these issues.

4 participants