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

consider removing receiver_preimage field from ExpectedUtxo. #176

Open
dan-da opened this issue Aug 20, 2024 · 0 comments
Open

consider removing receiver_preimage field from ExpectedUtxo. #176

dan-da opened this issue Aug 20, 2024 · 0 comments

Comments

@dan-da
Copy link
Collaborator

dan-da commented Aug 20, 2024

I'm just moving this lengthy comment from code (expected_utxo.rs) into github. The code will reference this issue.

/// ### about `receiver_preimage`
///
/// The `receiver_preimage` field in expected_utxo is not strictly necessary.
/// It is an optimization and a compromise.
///
/// #### optimization
///
/// An `ExpectedUtxo` really only needs `utxo`, `sender_randomness` and
/// `receiver_identifier`.  These match the fields used in `PublicAnnouncement`.
///
/// However it then becomes necessary to scan all known wallet keys (of all key
/// types) in order to find the matching key, in order to obtain the preimage.
///
/// improvement: To avoid scanning a map of \[`receiver_identifier`\] -->
/// `derivation_index` could be stored in local wallet state for all known keys.
///
/// However no such map presently exists, and so the most efficient and easy
/// thing is to include the preimage in [ExpectedUtxo] instead of a
/// `receiver_identifier`.  This buys us an equivalent optimization for little
/// effort.
///
/// #### compromise
///
/// Because the preimage is necessary to create an [ExpectedUtxo]
/// `create_transaction()` must accept a `change_key: SpendingKey` parameter
/// rather than `change_address: ReceivingAddress`.  One would normally expect
/// an output to require only an address.
///
/// note: one *would* expect the SpendingKey parameter for inputs.
///
/// Further if [ExpectedUtxo] and `PublicAnnouncement` use the same fields then
/// they can share much of the same codepath when claiming.  At present, we have
/// separate codepaths that perform largely the same function.
///
/// We may revisit this area in the future, as it seems ripe for improvement.
/// In particular wallet receiver_identifier map idea indicates it is possible
/// to do this efficiently.  As such it may be best to implement at least the
/// scanning based approach before mainnet.
///
/// A branch with an implementation of the scanning approach exists:
/// danda/symmetric_keys_and_expected_utxos_without_receiver_preimage
///
/// At time of writing many tests are not passing and need updating with the new
/// field.
@dan-da dan-da changed the title documenting ExpectedUtxo::receiver_preimage consider removing receiver_preimage field from ExpectedUtxo. Aug 20, 2024
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

No branches or pull requests

1 participant