zcash_client_backend: Introduce an "orchard" feature flag.#1080
zcash_client_backend: Introduce an "orchard" feature flag.#1080str4d merged 3 commits intozcash:mainfrom
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main zcash/librustzcash#1080 +/- ##
==========================================
+ Coverage 66.41% 66.48% +0.07%
==========================================
Files 113 113
Lines 10821 10856 +35
==========================================
+ Hits 7187 7218 +31
- Misses 3634 3638 +4 ☔ View full report in Codecov by Sentry. |
ce44169 to
fd14b00
Compare
97f31e2 to
c272c0c
Compare
We plan to also introduce a similar flag to gate access to Sapling functionality. Since introduction of Orchard functionality is still nascent, it's the correct time to introduce this isolation, before there's more functionality that needs to be isolated in this fashion.
c272c0c to
f18d082
Compare
…commitment and nullifier data.
5c155ce to
857e44a
Compare
| #[cfg(feature = "orchard")] | ||
| let has_orchard = orchard.is_some(); | ||
| #[cfg(not(feature = "orchard"))] | ||
| let has_orchard = true; |
There was a problem hiding this comment.
Nit: this is fine for now, but when sapling is given a feature flag, we will need to ensure that we can never produce a USK if both sapling and orchard are disabled (probably by gating the entire UnifiedSpendingKey type on #[cfg(any(feature = "orchard", feature = "sapling"))].
There was a problem hiding this comment.
After having done this exercise, I think that we should go ahead with adding the sapling feature flag to zcash_client_backend in the near future; it's not that much work now that the pattern is established and it really does help tease out coupling and improve modularity.
There was a problem hiding this comment.
Given transparent support is also under a feature flag, what will happen when no feature flag is specified? Do we expect that to build, or would the error be helpful in directing the consumer to specify at least one?
There was a problem hiding this comment.
We can just have that cause a compilation error.
|
|
||
| ## Enables support for storing data related to the sending and receiving of | ||
| ## Orchard funds. | ||
| orchard = ["zcash_client_backend/orchard"] |
There was a problem hiding this comment.
Should orchard be default-enabled (both here and in zcash_client_backend)? I think that's likely what we want as the default here eventually (and for compatibility it will be the default for the eventual sapling feature flag), and then downstreams that don't want Orchard can use default-features = false (like is done to disable multicore). But maybe while developing it we leave it default-disabled? IDK.
There was a problem hiding this comment.
Yes, ultimately, but I want it to be default-disabled until there are no more FIXME or unimplemented() sections.
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "orchard")] |
There was a problem hiding this comment.
I forget: does the client have a way to tell lightwalletd to only send one or the other of Sapling and Orchard? Or will real CompactBlocks always contain both Sapling and Orchard components of transactions even if the local client only supports one of them? If the latter, we should probably have some way to test that case (but maybe not here, given that this is predicated on transaction parsing support for Orchard types).
There was a problem hiding this comment.
Right now I think they'll always contain both.
| // We test the full roundtrip only with the `orchard` feature enabled, because we will | ||
| // not generate the `orchard` part of the encoding if the UFVK does not have an Orchard | ||
| // part. |
There was a problem hiding this comment.
Non-blocking: we should instead update these test vectors to cover the matrix of flags.
There was a problem hiding this comment.
| #[cfg(feature = "orchard")] | ||
| if _params |
There was a problem hiding this comment.
Per my comment above, if we're still going to have the database tables for Orchard in the schema, then for values that don't depend on orchard crate types and aren't wallet-specific (like the Orchard tree size for a given block), we probably don't want to feature flag this off.
The main reason for doing so would be if the presence of an Orchard tree size is used as some kind of indicator or switch for later logic. Do we need to use it as such?
There was a problem hiding this comment.
I don't want to use the presence or absence of data to be used as a logic switch, for sure. However, as I stated above, I think that we should try to fully segregate protocol-specific functionality so that as much orchard stuff as possible is removed from the API when the orchard flag is disabled; a smaller API surface is going to be less error-prone.
| sapling_anchor: Option<sapling::Anchor>, | ||
| orchard_anchor: Option<orchard::Anchor>, |
There was a problem hiding this comment.
(Asking so I can keep track of the design:) Why are the anchors now optional again? (And why the change in this PR - what about the orchard flag necessitates this?)
There was a problem hiding this comment.
So, the anchors are optional so that we don't have to depend on the orchard crate in zcash_client_backend, since the feature flagging doesn't yet extend to zcash_primitives. We will likely want to do that work in zcash_primitives, but that's a bigger job that I didn't want to tackle yet. So making these optional is the compromise.
| @@ -522,20 +528,22 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder< | |||
| transparent_inputs, | |||
| self.transparent_builder.outputs(), | |||
| sapling_spends, | |||
There was a problem hiding this comment.
Non-blocking: I think we need to alter this to call bundle_type.num_spends() after the changes in zcash/sapling-crypto#114. This should happen in a separate PR.
Co-authored-by: str4d <thestr4d@gmail.com>
| let ua = UnifiedAddress::from_receivers(orchard, sapling, transparent).unwrap(); | ||
|
|
||
| #[cfg(not(feature = "orchard"))] | ||
| let ua = UnifiedAddress::from_receivers(sapling, transparent).unwrap(); |
There was a problem hiding this comment.
This could just be
let ua = UnifiedAddress::from_receivers(
#[cfg(feature = "orchard")] orchard,
sapling,
transparent,
).unwrap();(which will be simpler once we add the "sapling" feature).
We plan to also introduce a similar flag to gate access to Sapling functionality. Since introduction of Orchard functionality is still nascent, it's the correct time to introduce this isolation, before there's more functionality that needs to be isolated in this fashion.