-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keys: 🥰
Address
defers computation of diversified base (#4285)
### 💬 describe your changes fixes #1957. the last remaining item mentioned in #1957 is that currently, while `Address` _caches_ the diversified base point, it eagerly computes it when `Address::from_components()` is called. we can defer this action until the base point is needed, using `OnceLock<T>`. in order to do that, we must revoke the `Copy` derivation. essentially, this branch makes the following change(s) to `Address`: ```diff -#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(try_from = "pb::Address", into = "pb::Address")] pub struct Address { d: Diversifier, /// cached copy of the diversified base - g_d: decaf377::Element, + g_d: OnceLock<decaf377::Element>, /// extra invariant: the bytes in pk_d should be the canonical encoding of an /// s value (whether or not it is a valid decaf377 encoding) /// this ensures we can use a PaymentAddress to form a note commitment, /// which involves hashing s as a field element. pk_d: ka::Public, /// transmission key s value transmission_key_s: Fq, ck_d: fmd::ClueKey, } ``` out of that, a few other types also lose their `Copy` property: * AddressView * FundingStream * Recipient ..which leads to the addition of explicit `.clone()` calls in various places. largely, that tends to affect test code, but it is a more invasive change than expected, and i want to draw attention to that. it should _not_ be a change in behavior, however. these are the same copies as previously made, but are now performed explicitly. for more, see the `Copy` documentation: https://doc.rust-lang.org/stable/std/marker/trait.Copy.html#whats-the-difference-between-copy-and-clone some extra documentation, a small compile-time check to enshrine thread-safety properties (`Send` and `Sync`), and an extra `From<T>` implementation are added too. #### ➕ changes to facilitate review and to make this easier to reason about, this branch is divided into distinct steps: * keys: 🔖 add more `Address` documentation * keys: 🙂 add compile-time assertions about addresses * keys: 📫 `pb::Address: From<&Address>` * keys: 👯 `Address` is not `Copy` * keys: 🥰 defer diversified base using `OnceLock<T>` ...reviewers are encouraged to review this step-by-step. :mag: **NB:** using `OnceLock<T>` is the core change at play here. ### issue ticket number and link * #1957 ### checklist before requesting a review - [x] if this code contains consensus-breaking changes, i have added the "consensus-breaking" label. otherwise, i declare my belief that there are not consensus-breaking changes, for the following reason: > this does not change the behavior of addresses, it only defers the > computation of the diversified base point.
- Loading branch information
Showing
29 changed files
with
252 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.