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

Parse sender params #30

Closed
wants to merge 5 commits into from
Closed

Conversation

DanGould
Copy link

@DanGould DanGould commented Jul 31, 2022

This PR clarifies the sender::Params struct to more closely resemble spec (additional fee contribution != fee contribution) and parses it from query: &str. hyper and reqwest can pass query.unwrap_or("") which can be shown in integration.

The changed Params struct varied from spec in that it allowed independent maxadditionalfeerate and additionalfeeoutput index. Spec says those come together or not at all. Else we log:warn! and ignore.

@Kixunil
Copy link
Owner

Kixunil commented Jul 31, 2022

Did you find the names confusing? I intentionally named them shorter for non-public code. Perhaps a comment would be better? I'm not a hater of long names it's just that those seemed good enough for non-public code.

Edit: oh, sorry, there are also public items not named after spec. Theses really should be renamed.

@@ -57,7 +57,7 @@ fn main() {
.psbt;
let psbt = load_psbt_from_base64(psbt.as_bytes()).unwrap();
println!("Original psbt: {:#?}", psbt);
let pj_params = bip78::sender::Params::with_fee_contribution(bip78::bitcoin::Amount::from_sat(10000), None);
let pj_params = bip78::sender::Params::non_incentivizing();
Copy link
Owner

@Kixunil Kixunil Jul 31, 2022

Choose a reason for hiding this comment

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

There's nothing against spec here, this is client-side code where client wants the library to detect the change coming from bitcoind. It's useful in simple scenarios like this one.

From doc:

change_index specifies which output can be used to pay fee. I None is provided, then
the output is auto-detected unless the supplied transaction has more than two outputs

Copy link
Author

Choose a reason for hiding this comment

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

ok, Let's keep it. That's useful.

@@ -36,7 +36,7 @@ type InternalResult<T> = Result<T, InternalValidationError>;
/// Builder for sender-side payjoin parameters
///
/// These parameters define how client wants to handle PayJoin.
pub(super) struct Params {
pub struct Params {
Copy link
Owner

Choose a reason for hiding this comment

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

This destroys forward-compatibility and is definitely not acceptable. #[non_exhaustive] would work but builders are still more convenient for user code.

Copy link
Author

Choose a reason for hiding this comment

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

I'm confused about this comment. That change is only on an intermediate commit. The original is pub struct Params { as exists on master right now

Copy link
Owner

Choose a reason for hiding this comment

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

The fields are public and adding a public field to a public struct is breaking change unless it's non_exhaustive.

@Kixunil
Copy link
Owner

Kixunil commented Jul 31, 2022

Also could you please split sender and receiver contributions into two PRs? It's much easier to handle them that way.

@Kixunil
Copy link
Owner

Kixunil commented Jul 31, 2022

I now realized what you meant by this PR, in case you read this before #27 see this comment: #27 (comment)

@DanGould
Copy link
Author

DanGould commented Aug 1, 2022

A note to clarify what may be confusion, there are receiver params aka uri::PjParams { pj: Url, pjos: bool } and sender::Params { v, disableoutputsubstitution, maxadditionalfeecontribution, additionalfeeoutputindex, minfeerate}. Only the latter are the subject of this PR

@DanGould
Copy link
Author

DanGould commented Aug 1, 2022

I'm can try to separate the name issues from the architectural ones. I think names like non_incentivising are confusing because the receiver can already get a fee without a change output. additional fee is on top of what's already sent.

I think the naming & interface clean up is better off in another pr. There's more work than what's needed to get a basic receiver to parse the sender params, which is the goal of this change.

@DanGould DanGould force-pushed the parse-sender-params branch 2 times, most recently from 9c16190 to a259d1e Compare August 1, 2022 08:45
@DanGould
Copy link
Author

DanGould commented Aug 1, 2022

This is now the minimum change to parse. I split it according to ##27 (comment). Other things I attempted before are noted in #31

bip78/src/params.rs Outdated Show resolved Hide resolved
bip78/src/params.rs Outdated Show resolved Hide resolved
bip78/src/params.rs Outdated Show resolved Hide resolved
bip78/src/params.rs Outdated Show resolved Hide resolved
bip78/src/params.rs Outdated Show resolved Hide resolved
bip78/src/params.rs Show resolved Hide resolved
bip78/src/receiver/mod.rs Outdated Show resolved Hide resolved
bip78/src/receiver/mod.rs Outdated Show resolved Hide resolved
bip78/src/receiver/mod.rs Outdated Show resolved Hide resolved
@DanGould
Copy link
Author

rebased on #27, I believed I addressed at the comments

@DanGould DanGould requested a review from Kixunil August 16, 2022 05:11
bip78/Cargo.toml Outdated Show resolved Hide resolved
bip78/src/params.rs Outdated Show resolved Hide resolved
bip78/src/params.rs Outdated Show resolved Hide resolved
bip78/src/params.rs Outdated Show resolved Hide resolved
bip78/src/params.rs Outdated Show resolved Hide resolved
///
/// Note: mixed spends do not necessarily indicate distinct wallet fingerprints.
/// This check is intended to prevent some types of wallet fingerprinting.
pub fn assume_no_mixed_input_scripts(self) -> MaybeInputsSeen {
Copy link
Owner

Choose a reason for hiding this comment

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

We can actually do this check internally, no need to burden the consumer with it. The consumer only needs to get one address type which is the same for all inputs and check that one.

Copy link
Author

Choose a reason for hiding this comment

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

Is this true? Can we stay up to date on all the possible bitcoin scripts?

Copy link
Owner

Choose a reason for hiding this comment

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

It's a good point that allowing people to manually check would allow them to work around the library not being updated but if we fail to maintain it they probably should fork it rather than using an obsolete library for potentially security-critical software.

Copy link
Author

Choose a reason for hiding this comment

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

it'd be better if the alpha version of this forgoes mixed input script check since we want to use it for loptos. Is it blocking this PR or may we leave it for the next iteration like some of the warns? I'd love for us to get loptos out ASAP

Copy link
Owner

Choose a reason for hiding this comment

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

Even if we skip the check AFAIK there are no wallets currently that support mixed inputs, so that's still useless. If you know of any wallet that does please let me know.

@DanGould DanGould force-pushed the parse-sender-params branch 3 times, most recently from c8f37b1 to 7f715a1 Compare August 26, 2022 09:57
@DanGould
Copy link
Author

Requested changes applied ✅

Copy link
Owner

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

I'd like at least macros not be public, the rest are just suggestions.

bip78/src/lib.rs Outdated Show resolved Hide resolved
bip78/src/params.rs Outdated Show resolved Hide resolved
bip78/src/receiver/mock.rs Outdated Show resolved Hide resolved
bip78/src/receiver/mod.rs Show resolved Hide resolved
}
}
}

impl MaybeInputsOwned {
/// The receiver should not be able to sign for any of these Original PSBT inputs.
/// Check that none of them are owned by the receiver downstream before proceeding.
Copy link
Owner

Choose a reason for hiding this comment

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

Separate into paragraphs.

bip78/src/receiver/mod.rs Outdated Show resolved Hide resolved
bip78/src/receiver/mod.rs Outdated Show resolved Hide resolved
@@ -36,14 +36,14 @@ type InternalResult<T> = Result<T, InternalValidationError>;
/// Builder for sender-side payjoin parameters
///
/// These parameters define how client wants to handle PayJoin.
pub struct Params {
pub struct Configuration {
disable_output_substitution: bool,
fee_contribution: Option<(bitcoin::Amount, Option<usize>)>,
clamp_fee_contribution: bool,
min_fee_rate: FeeRate,
Copy link
Owner

Choose a reason for hiding this comment

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

Params could be inside but not sure if it helps anything.

bip78/tests/integration.rs Outdated Show resolved Hide resolved
@DanGould DanGould force-pushed the parse-sender-params branch 2 times, most recently from d8294b9 to b0fcb51 Compare October 27, 2022 23:42
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