Skip to content

Implement clone for some structs#7

Merged
str4d merged 0 commit into
str4d:transaction-builder-transparent-inputsfrom
adityapk00:add_clones
Oct 14, 2019
Merged

Implement clone for some structs#7
str4d merged 0 commit into
str4d:transaction-builder-transparent-inputsfrom
adityapk00:add_clones

Conversation

@adityapk00
Copy link
Copy Markdown

Derive Clone for some structs to make it easier for light clients to move around transparent inputs

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you actually require Eq to be implemented? I know that PartialEq is usually required for test comparisons.

Copy link
Copy Markdown

@zancas zancas Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason to include Eq (which is derived from PartialEq) is to enforce x == x (reflexivity), which is relevant for this type.

PartialEq's are not strict equivalence relations because they do not enforce x == x.

This counterintuitive property makes sense when you think about the concrete example of IEEE floating-point values. They are specified to be NaN in some cases (e.g. 0.0/0.0), but NaN != NaN, i.e. NaN is not reflexive.

e.g.:

assert_eq!(0.0/0.0 == 0.0/0.0, false)

Since f32 and f64 are the only types in the standard library that are PartialEq, but not Eq, it's generally best practice to implement Eq on any type that doesn't include them.

Most of what I am asserting here is rehashed from the Equality Tests section of this book:

http://shop.oreilly.com/product/0636920040385.do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a lot of the same info, but readable!!
https://doc.rust-lang.org/std/cmp/trait.PartialEq.html

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

@zancas zancas Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: The reason this type can be used in equivalences without explicitly defining "fn eq" in either the PartialEq, or Eq trait (either as a default, or when implementing for the type), is because the PartialEq trait is being implemented with the #[derive( macro which is supplying an fn eq implementation.

At least... I think that's what's happening, when I drilled into the macro implementation I hit this:

https://doc.rust-lang.org/src/core/cmp.rs.html#209

When I replace the #[derive(PartialEq)] with an explicit:

impl PartialEq for OutPoint {} I get the compiler error I expect:

error[E0046]: not all trait items implemented, missing: `eq`
  --> src/main.rs:11:1
   |
11 | impl PartialEq for OutPoint {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `eq` in implementation
   |
   = note: `eq` from trait: `fn(&Self, &Rhs) -> bool`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is consistent with this documentation (and the fact that u8's are Eq):
https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#derivable

Copy link
Copy Markdown

@zancas zancas Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR OutPoints should be Eq

Unless their use dictates that having op1.hash == op2.hash && op1.n == op2.n does not imply equivalence.. in that case they should be neither Eq nor #[derive(PartialEq)

Copy link
Copy Markdown
Owner

@str4d str4d Oct 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically under the BIP 30 consensus rules we inherited from Bitcoin Core, OutPoints do not have full equivalence, because transaction IDs are allowed to repeat in the block chain as long as they do not repeat in the UTXO set. Thus an OutPoint is a unique reference in the context of a block chain (to the transaction with that ID in the most recent block), but not technically unique on its own.

In practice, wallet code assumes that transaction IDs will never repeat (which causes the overwriting problem that BIP 30 was written to solve). So maybe we're fine assuming that we can treat identical OutPoints as equivalent.

Copy link
Copy Markdown
Owner

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current preference is that the Eq derive be removed if it is not needed by @adityapk00 (to unblock the higher-level goal of having ZecWallet depend on versioned crates), and then we can take more time to consider whether Eq makes sense (both for this and other types in the API). Removing derives later is a more problematic API change than adding missing derives.

Copy link
Copy Markdown
Owner

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. I opened zcash#140 for the question about Eq.

@str4d str4d merged this pull request into str4d:transaction-builder-transparent-inputs Oct 14, 2019
str4d pushed a commit that referenced this pull request Dec 15, 2025
…14868de..23f0768ea

23f0768ea Release lightwallet-protocol v0.4.0
41156c767 Merge pull request #11 from zcash/feature/get_mempool_tx_pools
7c130e883 Add `lightwalletProtocolVersion` field to `LightdInfo` struct.
edbb726d7 Apply suggestion from code review
38fddd73b Apply suggestions from code review
0250f2720 Add pool type filtering to `GetMempoolTx` argument.
54ccaadd5 Change semantics of pool-based pruning of compact transactions from "may prune" to "must prune".
b0667ec99 Merge pull request #9 from zcash/2025-11-doc-TransparentAddressBlockFilter
f3fea7bd4 doc: TransparentAddressBlockFilter doesn't include mempool
a67dd323a Merge pull request #8 from zcash/2025-11-lightdinfo-upgrade-info
11da4b7e3 add next upgrade info to LightdInfo structure (GetLightdInfo)
42cd8f720 Transparent data docs update (#7)
c0cf957ac Merge pull request #5 from zcash/2025-11-comments
912fc3609 Minor clarification in GetBlockRange documentation.
6b03f2cce Documentation (comments) only
d978256a2 Merge pull request #1 from zcash/compact_tx_transparent
7eeb82e7c Merge pull request #4 from zcash/add_changelog
a95359dc9 Apply suggestions from code review
592b637a8 Add transparent data to the `CompactBlock` format.
9d1fb2c41 Add a CHANGELOG.md that documents the evolution of the light client protocol.
180717dfa Merge pull request #3 from zcash/merge_librustzcash_history
450bd4181 Merge the history of the .proto files from `librustzcash` for complete history preservation.
a4859d11d Move protobuf files into place for use in `zcash/lightwallet-protocol`
2e66cdd9e Update zcash_client_backend/proto/service.proto
eda012519 fix comment
f838d10ad Add gRPC LightdInfo Donation Address
db12c0415 Merge pull request zcash#1473 from nuttycom/wallet/enrichment_queue
698feba96 Apply suggestions from code review
20ce57ab3 zcash_client_backend: Add `block_height` argument to `decrypt_and_store_transaction`
a6dea1da8 Merge pull request zcash#1482 from zancas/doc_tweak
4d2d45fc9 fix incorrect doc-comment
e826f4740 update CompactBlock doc-comment, to cover non-Sapling shielded notes, and addresses
e9a6c00bf Various documentation improvements
988bc7214 Merge pull request zcash#872 from nuttycom/feature/pre_dag_sync-suggest_scan_ranges
58d07d469 Implement `suggest_scan_ranges` and `update_chain_tip`
a9222b338 Address comments from code review.
e20310857 Rename proto::compact::{BlockMetadata => ChainMetadata}
ac63418c5 Reorganize Sapling and Orchard note commitment tree sizes in CompactBlock.
0fdca14f1 zcash_client_backend: Add note commitment tree sizes to `CompactBlock` serialization.
2a0c2b8b7 zcash_client_backend: Add gRPC bindings behind feature flag
1342f0480 zcash_client_backend: Address compact_formats.proto comments
68aa4e01b zcash_client_backend: Bring in latest `compact_formats.proto`
e712eb1bc Add prevHash field to CompactBlock
440384c3e Build protobufs for compact formats

git-subtree-dir: zcash_client_backend/lightwallet-protocol
git-subtree-split: 23f0768ea4471b63285f3c0e9b6fbb361674aa2b
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

Successfully merging this pull request may close these issues.

3 participants