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

docs: clarify send,receive function documentation #407

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

0xBEEFCAF3
Copy link
Collaborator

Took some notes while I was reading the sender functions. Thought this could be useful for future contributors.
Also noticed that functions had docs but were not using doc comments ///. Let me know if that was an intentional decision, I can revert that. But doc comments are nice b/c my ide will ussually describe the function when I hover over it.

@@ -350,6 +355,7 @@ impl V1Context {

#[cfg(feature = "v2")]
pub struct V2PostContext {
/// The endpoint to send the request to. This is either a pj directory or a receiver's endpoint.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// The endpoint to send the request to. This is either a pj directory or a receiver's endpoint.
/// The payjoin directory subdirectory to send the request to.

I may have misinformed you. This is always the payjoin directory subdirectory in this typestate. Only V1Context's endpoint is a V1 receiver's endpoint.

Comment on lines 392 to 393
/// This is either the pj directory or the receiver's endpoint
endpoint: Url,
Copy link
Contributor

@DanGould DanGould Nov 26, 2024

Choose a reason for hiding this comment

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

Same comment as above. This is always the payjoin directory subdirectory to GET from

Copy link
Contributor

Choose a reason for hiding this comment

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

This still hasn't been addressed

Comment on lines 724 to 725
/// Ensure that the payee output spk is found the list of outputs only once.
/// And that the amount is the same as in the original PSBT.
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer "output script" or "output scriptPubKey" to "output spk." In general less jargon makes for clearer communication. Refer to Murch's terminology BIP for unambiguous consistent vocabulary

Copy link
Contributor

Choose a reason for hiding this comment

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

This is checking in the build step not between PSBTs. Do you think "And that the amount is the same as in the original PSBT" is sufficiently clear?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it. Thats my misunderstanding.
rephrashing to "Ensure that the payee's output scriptPubKey appears in the list of outputs exactly once, and that the payee's output amount matches the requested amount."

@@ -763,6 +772,7 @@ fn clear_unneeded_fields(psbt: &mut Psbt) {
}
}

/// Check that the output contributing to the fee is not less than the fee.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Check that the output contributing to the fee is not less than the fee.
/// Ensure that an additional fee output is sufficient to pay for the specified additional fee

Comment on lines 792 to 794
/// Find the sender's change output.
/// The first output should always be the payee spk.
/// If the fee contribution is clamped, any non-payee spk can be the change output.
Copy link
Contributor

@DanGould DanGould Nov 26, 2024

Choose a reason for hiding this comment

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

Suggested change
/// Find the sender's change output.
/// The first output should always be the payee spk.
/// If the fee contribution is clamped, any non-payee spk can be the change output.
/// Find the sender's change output index by eliminating the payee's as a candidate.

@spacebear21 "The first output should always be the payee script" screams privacy leak to me since receivers maintain relative ordering. I think this comment is wrong but please help me double check. If that is the behavior, must randomize this to address the issue. However, I believe the second line of the proposed comment is actually wrong since later in the function we check for the payee with .find() in the case of 2 outputs. This docstring suggests a readability refactor since the unit type return branch (2, _) => (), was misread to produce this docstring. An inline comment would help fix the misread.

I do NOT believe clamped fee contribution suggests which script can be a change output either. Rather, it ensures that in the case that a SenderBuilder-parameterized additional fee output can't pay for the parameterized max additional fee contribution, then the SenderBuilder will return a Sender with a decreased additional fee contribution rather than producing an error.

Copy link
Collaborator Author

@0xBEEFCAF3 0xBEEFCAF3 Nov 26, 2024

Choose a reason for hiding this comment

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

The first output should always be the payee script

This seems to only be true if there is no second output. Which makes sense as then we only have one output and that has to the the payee spk

payjoin/src/send/mod.rs Outdated Show resolved Hide resolved
Comment on lines 821 to 823
/// Checks that the change output index is valid
/// and that the amount is not less than the fee we are suppose to
/// be contributing.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Checks that the change output index is valid
/// and that the amount is not less than the fee we are suppose to
/// be contributing.
/// Check that the change output index is not out of bounds
/// and that the additional fee contribution is not less than specified.
  • Use imperative mood.
  • Saying "and that the additional fee contribution is not less than specified" covers both amount and clamp parameters.

The "and..." suggests to me the name is incorrect (should be check_change) but that's a nit and suggests the two *_change_index calls in determine_fee_contribution could both be named *_change instead. But this is a major nit and does not actually need to change.

@0xBEEFCAF3 0xBEEFCAF3 force-pushed the arm/chore/doc-comments branch from fc3afc6 to 9a73fa2 Compare November 26, 2024 17:34
@0xBEEFCAF3
Copy link
Collaborator Author

@DanGould snuck in one more commit (9a73fa2) fixing some typos I found

@DanGould
Copy link
Contributor

Also, this isn't this definitely docs(x) in conventional commits parlance

@0xBEEFCAF3 0xBEEFCAF3 force-pushed the arm/chore/doc-comments branch 2 times, most recently from 0b0e2c3 to 86fb9e1 Compare November 26, 2024 17:46
@@ -237,7 +237,7 @@ impl UncheckedProposal {
///
/// Receiver MUST check that the Original PSBT from the sender
/// can be broadcast, i.e. `testmempoolaccept` bitcoind rpc returns { "allowed": true,.. }
/// for `extract_tx_to_sheculed_broadcast()` before calling this method.
/// for `extract_tx_to_scheduled_broadcast()` before calling this method.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be extract_tx_to_schedule_broadcast

@0xBEEFCAF3 0xBEEFCAF3 force-pushed the arm/chore/doc-comments branch from 86fb9e1 to 3b0f0be Compare November 26, 2024 19:13
Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

ACK 3b0f0be

Many thanks for persisting with me to get all these details right

@DanGould DanGould changed the title chore(send): additional function docs docs: clarify send,receive function documentation Nov 26, 2024
@DanGould DanGould merged commit 0148630 into payjoin:master Nov 26, 2024
6 checks passed
@0xBEEFCAF3 0xBEEFCAF3 deleted the arm/chore/doc-comments branch November 26, 2024 19:48
@0xBEEFCAF3
Copy link
Collaborator Author

ACK 3b0f0be

Many thanks for persisting with me to get all these details right

Yeah you got it. Thanks for the review

@DanGould DanGould mentioned this pull request Dec 3, 2024
17 tasks
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