Repository navigation
Conversation
c78646a to
704929d
Compare
704929d to
47567c5
Compare
|
IMHO #23 helps implementors by having just the method they need on the "verification stage" they are, for example Even though you are required to verify the steps in order |
|
Yeah, I prefer type state. AFAIR some checks need additional information anyway. If you strongly want to allow doing the checks in any order use type-based flags: pub enum Checked {}
pub enum NotChecked {}
pub trait CheckState: sealed::CheckState {}
impl<T: sealed::CheckState> CheckState for T {}
impl sealed::CheckState for Checked {}
impl sealed::CheckState for NotChecked {}
// use meaningful names, this is just example
pub struct UncheckedProposal<Check1: CheckState, Check2: CheckState, Check3: CheckState> {
// the fields
_phantom: PhantomData<(Check1, Check2, Check3)>,
}
impl<C2: CheckState, C3: CheckState> UncheckedProposal<Unchecked, C2, C3> {
fn assume_check1_verified(self) -> UncheckedProposal<Checked, C2, C3> {
// ...
}
}Anyway, even if we decided to go for runtime flags, the |
|
Because it had only a single state and for each state there'd still need to be a new struct so it didn't add much value. Having individual checks in type state at least provides something tangible: reorderable checks. Still not sure if worth the effort TBH. |
955f540 to
3c71214
Compare
|
So now this has 4 states that don't need new structs. Looks like the whole proposal might be best served with a |
|
I don't understand this change, it looks like you re-did #23 instead of making checks type-level flags. |
|
Well, unlike #23 this doesn't require a new struct for each state nor rely on a single state which were the stated flaws of #23. It's also 1/2 the changes including tests which 23 lacks. What do you mean by type-level flags? to remove the generic? I understood your comments to say that reorderable checks were not particularly desirable because they were extra work, so I didn't bother in this PR. This does exactly the proposal stated in 23:
|
It does require a new enum. Adding types is the issue.
Check my example above - tracking individual checks in type using generics. This allows reordering. But yes, it's a bunch of extra code and being reorderable doesn't seem very important. |
3c71214 to
b169d53
Compare
|
Adding types for typestate is an issue because ...? What will it take to get checks merged? I'm grateful for the reviews from a high rust wizard. |
|
Implementing typestate using generics adds more types to the API that the consumer sees and they are not helping. To simplify: pub struct StateA {
// field: Type,
}
pub struct StateB {
// field: Type,
}Consumer see two types: pub enum StateA {}
pub enum StateB {}
pub trait State: selaed::State {}
pub struct Thing<S: State> {
// field: Type,
_phantom: PahntomData<S>,
}Consumer sees 3 types and 1 trait - this is strictly more complex and doesn't help the consumer with anything. However, using flags: pub enum Yes {}
pub enum No {}
pub trait Check: selaed::Check {}
pub struct Thing<A: Check, B: Check, C: Check> {
// field: Type,
_phantom: PahntomData<(A, B ,C)>,
}Models 8 possible states that can be traversed in any order with just 3 types and one traits - same number of items needed for 4 states. |
b169d53 to
52fe533
Compare
|
I understand the tradeoff now. Thank you. I implemented non-generic typestate with the methods to supply downstream relevant data and documented them too. |
52fe533 to
e580600
Compare
|
@Kixunil @RCasatta May you please take another look at this for review? It's pruned to just the typestate changes (no actual psbt checks for this PR). I think the interface makes more sense than the generic typestate machine I also implemented as an exercise. An opinionated interface like this is easier to use. Each check only has 1 data check method to call. There's also less code for us to maintain. |
Kixunil
left a comment
There was a problem hiding this comment.
Concept ACK, just some nits/questions.
| } | ||
|
|
||
| pub struct MaybeInputsOwned { | ||
| psbt: Psbt, |
There was a problem hiding this comment.
We will also have to carry around information from HTTP request.
There was a problem hiding this comment.
certainly, receiver parse & application of sender proposal params are in scope for the params pr
There was a problem hiding this comment.
Ah, I now think I understood what you intended in the other PR. You wanted to reuse the Params struct here.
I suggest:
- Keep
Paramspub(crate)and move to a common module - What currently is exposed as
Paramsshould be namedConfiguration, it can holdParamsinside - Consumers can manipulate
Configurationvia builder API but notParamsdirectly.
There was a problem hiding this comment.
This was the comment I looking for. I feel like I'm getting the ultimate trial by fire rust experience here :D
There was a problem hiding this comment.
Yeah, I can see many details. :) Hope it helps you get more skilled.
| /// Call this after checking downstream. | ||
| /// | ||
| /// Note: mixed spends are not necessarily indicative of distinct wallet fingerprints but they can be. | ||
| /// This check is intended to prevent some types of wallet fingerprinting. |
There was a problem hiding this comment.
I believe the check is actually an error in the BIP itself :) See bitcoin/bips#1244
There was a problem hiding this comment.
I'm fine dropping the check for the time being, which I did. However, a 1.0 release we should match the spec (either they change or we change)
There was a problem hiding this comment.
I actually wanted to keep it according to spec the whole time. I just clarified what I meant.
There was a problem hiding this comment.
Do you want it removed since we can do it internally, or do you want it as part of the checklist? based on your next comment, posted below, I think we should remove it
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.
#30 (comment)
e580600 to
301ca25
Compare
301ca25 to
fff6062
Compare
|
All 4 checks included according to your changes. Changed "MaybePrevoutsSeen" to "MaybeInputsSeen" with Outpoint {txid, vout} in the name signature to stay consistent with the rust-bitcoin dependency. It's the same as utxos to lock in the next step. Removed immaterial e.g. spacing changes |
8bcd838 to
39b275a
Compare
|
Concept ACK from me |
|
Looks like this has consensus. May we merge it? |
|
I want to give it one more review pass, but have to go rn. |
39b275a to
4baadcc
Compare
|
Removed sharing MockHeaders because of this comment in the params pr. The functionality has not changed. |
4baadcc to
4544624
Compare
4544624 to
35769f1
Compare
35769f1 to
541501d
Compare
|
@Kixunil I think this is a beautiful start. It includes changes to doc comments from your review on #30. WRT |
|
#30 is quite big so it'll take time. This one is smaller but can't review rn. |
|
fyi they're about the same size, #30 is really 10 files changed, 18 insertions(+), 183 deletions(-) built on this PR |
|
@Kixunil may you please take that second look? |
|
Damn, I'm very short on time now. Hopefully no later than the next week. |
|
Don't sweat it, you've been extremely generous with your time. I have patience. I spoke with @cryptoquick about wrapping and re-exporting this crate from https://github.com/chaincase-app/rust-payjoin so we can have a semver dependency downstream and to keep your desire for bip78 logic ultimately to end up in one place |
Interesting, is it really important in prototyping phase? What is the motivation? I'm mainly curious because it could inform broader Rust community about these things, looks like we can learn something new here. |
|
@Kixunil Just that with conditional compilation, crate features, and the traits system, there's no reason to bloat or fork dependencies; code simply needs to be reorganized. This keeps projects focused, maintainers aren't stuck with keeping up code they don't use or need, and the boundaries between core code and application code help improve code stability, which is especially important when doing security reviews. |
The first patch does Receive Checklist to support sync/async. It uses typestate to guide the downstream wallet through each check in opinionated order.
The second patch is unit tests
The third patch shares
MockHeadersinreceiver::test_utils, since it was used in integration tests too.closes #26
All GitHub Actions checks passed: payjoin#1