Conversation
8b05efa to
badd2c7
Compare
Pull Request Test Coverage Report for Build 14868573150Details
💛 - Coveralls |
|
have you considered an explicit discriminant enum? I can't imagine our Something like the following is what I was thinking about. I'm not suggesting a change per se but trying to understand the rationale for one over the other if there was one #[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Version {
One = 1,
Two = 2,
} |
|
@DanGould I hadn't considered it, but I think it makes more sense to have it as an explicit discriminant enum so we don't need the extra logic to convert to a |
There was a problem hiding this comment.
I'm glad you picked this up and wrote some tests. Thank you.
I wonder which branches aren't tested making our code coverage go down.
I know we use some differing BIP XX/BIP-XX/BIPXX formatting in this repo but at least keep them consistent in one PR please
| default = ["v2"] | ||
| #[doc = "Core features for payjoin state machines"] | ||
| _core = ["bitcoin/rand-std", "serde_json", "url", "bitcoin_uri"] | ||
| _core = ["bitcoin/rand-std", "serde_json", "url", "bitcoin_uri", "serde"] |
There was a problem hiding this comment.
Is this change strictly necessary? for Version compilation i.e. all _core-enabled compilations? If so, shouldn't the redundant explicit feature be removed from v2 = ["serde"...] be removed?
There was a problem hiding this comment.
it's needed for Serialize - I'll remove the redundant feature in v2
There was a problem hiding this comment.
And is that serde::Serialize required for the v1 feature used exclusively?
There was a problem hiding this comment.
From BIP-77:
HPKE binds ciphertexts to application-specific
infostrings. Because
of this domain separation, BIP 78'svparameter is redundant and
should be omitted for version 2.
If we aren't using the v parameter, we can probably keep it to v1 exclusively
There was a problem hiding this comment.
I'm not sure our code reflects that suggested omission yet, and it also seems based on your later comment that serde is still required for the error. If for some reason that error that serializes a version array never gets hit, v1 exclusivity would be great. If not, it's ok to keep in core.
cdce962 to
25f3d44
Compare
|
Also moved |
DanGould
left a comment
There was a problem hiding this comment.
ser/de behavior, both having a serializer/deserializer and their feature gated applicability are my only remaining concerns
| impl Serialize for Version { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: Serializer, | ||
| { | ||
| (*self as u8).serialize(serializer) | ||
| } | ||
| } |
There was a problem hiding this comment.
is this not missing a matching deserialize impl?
There was a problem hiding this comment.
you're right, i'll add it actually, i'm not seeing anywhere it's being used, unlike Serialize, which is being used here:
rust-payjoin/payjoin/src/receive/error.rs
Line 220 in eb26494
is it okay to leave out until we are actually using it?
There was a problem hiding this comment.
Ah! very well.
In this case, please document the omission and design decisions on the Version type itself. That is, both the docstring on impl fmt::Display (which right now isn't actually linked to Version::fmt because it comes before the impl block), and notes about what is implemented need to go on the Version enum itself and then this is golden.
/// The Payjoin version
///
/// From [BIP 78](https://github.com/bitcoin/bips/blob/master/bip-0078.mediawiki#optional-parameters),
/// the supported versions should be output as numbers:
///
/// ```json
/// {
/// "errorCode": "version-unsupported",
/// "supported" : [ 2, 3, 4 ],
/// "message": "The version is not supported anymore"
/// }
/// ```
///
/// # Note
/// - Only [`Serialize`] is implemented for json array serialization in the `unsupported-version` error message,
/// not [`serde::Deserialize`], as deserialization is not required for this type.
/// - [`fmt::Display`] and [`fmt::Debug`] output the `u8` representation for compatibility with BIP 78/77
/// and to match the expected wire format.
DanGould
left a comment
There was a problem hiding this comment.
Thanks for the clarifications. I noticed one more thing. Version should be pub(crate) in lib.rs.
And please put the documentation on the Version type itself so that it's discoverable.
| default = ["v2"] | ||
| #[doc = "Core features for payjoin state machines"] | ||
| _core = ["bitcoin/rand-std", "serde_json", "url", "bitcoin_uri"] | ||
| _core = ["bitcoin/rand-std", "serde_json", "url", "bitcoin_uri", "serde"] |
There was a problem hiding this comment.
I'm not sure our code reflects that suggested omission yet, and it also seems based on your later comment that serde is still required for the error. If for some reason that error that serializes a version array never gets hit, v1 exclusivity would be great. If not, it's ok to keep in core.
| impl Serialize for Version { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: Serializer, | ||
| { | ||
| (*self as u8).serialize(serializer) | ||
| } | ||
| } |
There was a problem hiding this comment.
Ah! very well.
In this case, please document the omission and design decisions on the Version type itself. That is, both the docstring on impl fmt::Display (which right now isn't actually linked to Version::fmt because it comes before the impl block), and notes about what is implemented need to go on the Version enum itself and then this is golden.
/// The Payjoin version
///
/// From [BIP 78](https://github.com/bitcoin/bips/blob/master/bip-0078.mediawiki#optional-parameters),
/// the supported versions should be output as numbers:
///
/// ```json
/// {
/// "errorCode": "version-unsupported",
/// "supported" : [ 2, 3, 4 ],
/// "message": "The version is not supported anymore"
/// }
/// ```
///
/// # Note
/// - Only [`Serialize`] is implemented for json array serialization in the `unsupported-version` error message,
/// not [`serde::Deserialize`], as deserialization is not required for this type.
/// - [`fmt::Display`] and [`fmt::Debug`] output the `u8` representation for compatibility with BIP 78/77
/// and to match the expected wire format.
payjoin/src/lib.rs
Outdated
| #[cfg(feature = "_core")] | ||
| pub use crate::core::version::Version; |
There was a problem hiding this comment.
I think pub(crate) is sufficient since Version is an internal API
| #[cfg(feature = "_core")] | |
| pub use crate::core::version::Version; | |
| #[cfg(feature = "_core")] | |
| pub(crate) use crate::core::version::Version; |
In a follow up, all of these internal crate re-exports can be done inside core/mod.rs, and then something like
#[cfg(feature = "_core")]
pub use crate::core::*;can be used in lib.rs to clean up the verbose syntax here. Thanks for starting the cleanup by adding the core mod 😎
Fixes #643