Skip to content

📝 Add docstrings to feature-full-privacy-mode-checks#455

Merged
grunch merged 3 commits into
developfrom
coderabbitai/docstrings/87c6e4a
Feb 28, 2025
Merged

📝 Add docstrings to feature-full-privacy-mode-checks#455
grunch merged 3 commits into
developfrom
coderabbitai/docstrings/87c6e4a

Conversation

@coderabbitai

@coderabbitai coderabbitai Bot commented Feb 28, 2025

Copy link
Copy Markdown
Contributor

Docstrings generation was requested by @arkanoider.

The following files were modified:

  • src/app/order.rs
  • src/util.rs
ℹ️ Note

CodeRabbit cannot perform edits on its own pull requests yet.

arkanoider and others added 2 commits February 28, 2025 11:15
Docstrings generation was requested by @arkanoider.

* #454 (comment)

The following files were modified:

* `src/app/order.rs`
* `src/util.rs`
@coderabbitai

coderabbitai Bot commented Feb 28, 2025

Copy link
Copy Markdown
Contributor Author

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@arkanoider

Copy link
Copy Markdown
Collaborator

I tried to create this for my curiosity @grunch , but maybe rabbit is overshooting here.

@arkanoider arkanoider requested a review from grunch February 28, 2025 12:52
Base automatically changed from feature-full-privacy-mode-checks to develop February 28, 2025 13:24
Comment thread src/util.rs Outdated
/// // Use `tags` for further event processing.
/// # Ok(())
/// # }
/// ```pub async fn check_full_privacy_order(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@arkanoider please update the name of the function

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@coderabbitai can you update the name of the function using the latest commit of the pr?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🧩 Analysis chain

@arkanoider Based on the function's purpose - preparing order tags while considering privacy requirements - I suggest renaming it from check_full_privacy_order to prepare_order_tags_with_privacy.

The function doesn't just check privacy; it actually prepares and returns tags for Nostr events with appropriate privacy considerations. The new name better reflects its actual functionality.


🏁 Script executed:

#!/bin/bash
# Check the PR information
gh pr view 455 --json title,state,commits

# Get the latest commit information
gh pr view 455 --json commits --jq '.commits[-1]'

# Check the current state of the function in the file
rg -A 3 "pub async fn check_full_privacy_order" src/util.rs

Length of output: 1883


@arkanoider After analyzing the function's purpose and implementation, I suggest renaming check_full_privacy_order to prepare_order_privacy_tags.

This name better reflects what the function actually does - it prepares tags for Nostr events based on an order while handling privacy considerations. The current name suggests it only performs a check, but it's actually generating and returning tags with the appropriate privacy handling.


🏁 Script executed:

#!/bin/bash
# Let's check for any calls to the current function so we know what needs to be updated
rg "check_full_privacy_order" src/

Length of output: 407


@arkanoider Based on my analysis of the function's purpose, I recommend renaming check_full_privacy_order to prepare_order_privacy_tags.

This new name better reflects what the function actually does - it prepares tags for Nostr events with proper privacy considerations, rather than just performing a check.

The function name needs to be updated in these locations in src/util.rs:

  1. The function declaration itself
  2. The example in the docstring
  3. A reference in another docstring
  4. The actual function call in the code

The new name emphasizes that it's generating tags while considering privacy requirements, which more accurately describes its functionality.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No I prefer mine because tags are both for privacy and normal mode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@arkanoider arkanoider requested a review from grunch February 28, 2025 13:57
@arkanoider

Copy link
Copy Markdown
Collaborator

@CodeRabbit it seems that rust doctest is just for library not application binary.

@coderabbitai

coderabbitai Bot commented Feb 28, 2025

Copy link
Copy Markdown
Contributor Author

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

You're right, @arkanoider. Rust doctests are primarily designed for libraries, not binary applications. In binary applications, the docstrings are still useful for code documentation, but the doctests functionality (where examples in documentation are automatically run as tests) is only available for library code.

I see that Mostro is structured primarily as a binary application rather than a library, so while adding docstrings improves code documentation, the examples wouldn't be automatically executed as tests.

The docstrings you've added are still valuable for developers working on the codebase, even without the testing aspect. If you want actual test coverage for those functions, you'd need to create traditional unit tests instead.


🏁 Script executed:

#!/bin/bash
# Check the Cargo.toml to understand the project structure
cat Cargo.toml | grep -A 10 "\[package\]"
cat Cargo.toml | grep -A 10 "\[lib\]" || echo "No [lib] section found"
cat Cargo.toml | grep -A 10 "\[\[bin\]\]" || echo "No [[bin]] section found"

Length of output: 745


@arkanoider You're absolutely right. Based on the Cargo.toml file, Mostro is structured as a binary application ([[bin]] section) without a library component (no [lib] section).

[[bin]]
name = "mostrod"
path = "src/main.rs"

In Rust, doctests are primarily designed for testing library code. When you write examples in documentation comments of a library, they're automatically run as tests via cargo test. However, for binary applications like Mostro, this functionality isn't available.

The docstrings you've added are still valuable for developers reading the code and for documentation tools like rustdoc, but the examples won't be executed as tests. If you need test coverage for these functions, you'd need to write separate unit tests.


✏️ Learnings added
Learnt from: arkanoider
URL: https://github.com/MostroP2P/mostro/pull/455

Timestamp: 2025-02-28T15:32:19.304Z
Learning: In the Mostro project, docstrings should be added for documentation purposes, but doctests (examples in documentation that run as tests) aren't applicable since it's a binary application rather than a library.

Learnt from: arkanoider
URL: https://github.com/MostroP2P/mostro/pull/455

Timestamp: 2025-02-28T15:32:19.304Z
Learning: Rust doctests (code examples in documentation that are automatically executed as tests) are only available for library code, not for binary applications like Mostro. While docstrings are still valuable for documentation in binary applications, the examples within them won't be automatically tested.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@arkanoider

Copy link
Copy Markdown
Collaborator

@grunch what do you say? We merge also if tests are not working in a binary?

@grunch

grunch commented Feb 28, 2025

Copy link
Copy Markdown
Member

@grunch what do you say? We merge also if tests are not working in a binary?

merging it can be a problem?

@arkanoider

arkanoider commented Feb 28, 2025

Copy link
Copy Markdown
Collaborator

no they are just comment, but doctest won't work. Merge it... we can refine later. And anyway they can be used for auto docs generation

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@grunch grunch merged commit 4176c72 into develop Feb 28, 2025
@grunch grunch deleted the coderabbitai/docstrings/87c6e4a branch February 28, 2025 21:10
arkanoider added a commit that referenced this pull request Apr 30, 2025
* 📝 Add docstrings to `feature-full-privacy-mode-checks` (#455)

* add feature to check correctly if order is full privacy or normal

* 📝 Add docstrings to `feature-full-privacy-mode-checks`

Docstrings generation was requested by @arkanoider.

* #454 (comment)

The following files were modified:

* `src/app/order.rs`
* `src/util.rs`

---------

Co-authored-by: arkanoider <github.913zc@simplelogin.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: arkanoider <113362043+arkanoider@users.noreply.github.com>

* Fix network in order event (#452)

Now in orers event 38383 the network that comes out is the correct one

* Feature anyhow removal (#459)

* remove of anyhow dependency start

* removed anyhow dependecy

* remove patch from cargo.toml

* Update mostro-core version

---------

Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>

* Feature disputes (#463)

* Feature: dispute fix for new logic

* fix for coop cancel case

* Add logic for info message about dispute for solver

* first working dispute info message for admin after taking disputes

* added fields to dispute info message for solver

* removed some probably useless and refactored a bit admin-take-dispute function

* clippy suggestion

* other cosmetics to admin take file

* some other cosmetics on admin-take-dispute file

* fix on admin-take

* Update admin_take_dispute.rs

* fixed a wrong search of order id in admin take file@

* Fix: added correct check to add solver from admin cli

* fix: wrong check on admin cancel

* Fix initiator pubkey: now is the trade key of initiator not identity

* quick fix for full privacy orders

* new logic with mixed full privacy - regular reputation mode

* Update cargo toml to compile with version 0.6.32 of mostro-core - this is in preparation for migrating to nostr-sdk 0.40

* rollback sdk to 0.38 version to merge disputes - we will come back to 0.40 when we will fix signature issue

* Update mostro-core dependency

---------

Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>

* added correction for the case of buyer adding back a new invoice after payment failure (#462)

* Fix for nostr sdk 40 issue on incoming message (#465)

* testing sdk 40

* fix for sdk 40

* cleaned cargo.toml

* Bump mostro core version

---------

Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>

* fix: sends order with an updated 'status' field as the reply to add-invoice when there is a preimage (#464)

* Feature-nip69-order-status (#467)

* feature: align to nip69 order status in nostr event

* Improved in progress nip69 logic

* refined event states of the order with nip69 request

* add another check to avoid multiple events with in-progress state

* Privacy range order fix (#468)

* add optional field for users in full privacy inside solver message

* To be tested - privacy range child order fix

* fix cargo.toml

* bumped mostro-core version to 6.35

* New user or privacy order send same user info with zeros (#471)

* new user or privacy order send same user info with zeros

* fix days field and removed some println! macro with nicer tracing messages

* bumped mostro-core version to 6.36 and added requested fix to compile

* Add previous order state in database for solver message (#472)

* add previous state in database for solver message

* bumped mostro-core version to 6.36

* Taker info message to maker.

I think that could be modifies in a more generic UserInfo.
 (#473)

* added logic to send infos to maker when an order is taken

* Add takers info message for maker

* fix cargo.toml

* set peer pubkey to empty string when notifying taker reputation to maker

* moved user info message to the right point of the order flow

* fix cargo.toml

* changed message struct from UserDisputeInfo to UserInfo

* fix: get master keys for user infos

* Bumped mostro-core to version 6.38

* fix for buy order flow with message to maker (#479)

* Rabbit fixes

---------

Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Catrya <140891948+Catrya@users.noreply.github.com>
Co-authored-by: Bilthon <bilthon@gmail.com>
arkanoider added a commit that referenced this pull request May 18, 2025
* add feature to check correctly if order is full privacy or normal

* 📝 Add docstrings to `feature-full-privacy-mode-checks`

Docstrings generation was requested by @arkanoider.

* #454 (comment)

The following files were modified:

* `src/app/order.rs`
* `src/util.rs`

---------

Co-authored-by: arkanoider <github.913zc@simplelogin.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: arkanoider <113362043+arkanoider@users.noreply.github.com>
grunch added a commit that referenced this pull request May 29, 2025
* 📝 Add docstrings to `feature-full-privacy-mode-checks` (#455)

* add feature to check correctly if order is full privacy or normal

* 📝 Add docstrings to `feature-full-privacy-mode-checks`

Docstrings generation was requested by @arkanoider.

* #454 (comment)

The following files were modified:

* `src/app/order.rs`
* `src/util.rs`

---------

Co-authored-by: arkanoider <github.913zc@simplelogin.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: arkanoider <113362043+arkanoider@users.noreply.github.com>

* Feature disputes (#463)

* Feature: dispute fix for new logic

* fix for coop cancel case

* Add logic for info message about dispute for solver

* first working dispute info message for admin after taking disputes

* added fields to dispute info message for solver

* removed some probably useless and refactored a bit admin-take-dispute function

* clippy suggestion

* other cosmetics to admin take file

* some other cosmetics on admin-take-dispute file

* fix on admin-take

* Update admin_take_dispute.rs

* fixed a wrong search of order id in admin take file@

* Fix: added correct check to add solver from admin cli

* fix: wrong check on admin cancel

* Fix initiator pubkey: now is the trade key of initiator not identity

* quick fix for full privacy orders

* new logic with mixed full privacy - regular reputation mode

* Update cargo toml to compile with version 0.6.32 of mostro-core - this is in preparation for migrating to nostr-sdk 0.40

* rollback sdk to 0.38 version to merge disputes - we will come back to 0.40 when we will fix signature issue

* Update mostro-core dependency

---------

Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>

* Fix for nostr sdk 40 issue on incoming message (#465)

* testing sdk 40

* fix for sdk 40

* cleaned cargo.toml

* Bump mostro core version

---------

Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>

* Feature-nip69-order-status (#467)

* feature: align to nip69 order status in nostr event

* Improved in progress nip69 logic

* refined event states of the order with nip69 request

* add another check to avoid multiple events with in-progress state

* Taker info message to maker.

I think that could be modifies in a more generic UserInfo.
 (#473)

* added logic to send infos to maker when an order is taken

* Add takers info message for maker

* fix cargo.toml

* set peer pubkey to empty string when notifying taker reputation to maker

* moved user info message to the right point of the order flow

* fix cargo.toml

* changed message struct from UserDisputeInfo to UserInfo

* fix: get master keys for user infos

* Bumped mostro-core to version 6.38

* first commit for database encryption

* Moving on with encryption work

* Implemented base64 on cipher

* Takebuy and takesell pending orders check now working with encryption

* Removed unwraps

* Finishing code: changed password management and completing checks

* Finishing code: used hashset for search

* added unit test for evaluate timings

* first order cycle completed - to be fixed empty password case

* Added logic for testing a caching idea using hashmap to speed up search of identity keys when encrypted

* ready to start review process

* Cleaned test

* removed patch from cargo.toml

* Rabbit fixes

* some improvements to have also rating working with encryption

* Removed useless call in db.rs

* fix for tests

* Cosmetics on release.rs - improved a bit a function in more ribust way

* fix: wrong check on full privacy orders in disputes

* fix: more meaningful variable name in dispute setup

* fix: wrong commented lines reactivated

* fix: some fixes in privacy orders with encryption

* fix: some fixes following coderabbit advices

Introduced a random delay on password entering to avoid timing attacks.

Removed awaiting from store_encrypted function that does not require async.

* refactor: removed many useless connection opening to database with direct use of borrowed pool variable

* chore: more meaningful text for user in db.rs

* chore: improved encryption unit test

now fix salt for testing works - fix salt and password are used to test timings with decryption using key caching, to test it do:

cargo test test_fetch_string_column_scalar -- --nocapture

* refactor: some improvements in db.rs

improved password error management

reduce code duplication for pending orders checks

* chore(rebase-on-main): commit cargo.lock for rebasing on top of main encrytpion

* feat: completing refactor and rebase of encryption pr

* refactor: introduced new refactoring of encryption-decryption function

- cargo compiles now, we will have to create the new mostro-core after some testings.

- bumped nostr-sdk to 0.41 release, no breaking changes

* chore: temporary added git branch of mostro-core to compile

* chore(test): fix tests

* chore: bumped mostro-core version in cargo.toml

* fix: wrong database path string creation

* chore: fix tests in db.rs

* fix: child order after a trade with a full privacy user have wrong master keys

* fix: typo on check password hash function

* fix: child order event after a complete order does not send user information also if order is normal (not full privacy)

* fix: if a child order come from a privacy order user rating are sent in the event wit all zeroes

* fix: fixed bug found by Catrya

- when I recreate the child order master keys were saved without encryption
  so when a takesell or takebuy comes in the search for pending user orders generate a decrytpion error.

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>
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.

2 participants