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

Fix the hashCode and equals methods in Transaction and FeeBumpTransaction. #566

Merged

Conversation

overcat
Copy link
Member

@overcat overcat commented Jan 12, 2024

Fix the hashCode and equals methods in Transaction and FeeBumpTransaction, now they will compare based on the signatureBase().

@overcat overcat requested a review from sreuland January 12, 2024 04:02
@@ -15,8 +15,7 @@
import org.stellar.sdk.xdr.TransactionSignaturePayload;

/** Abstract class for transaction classes. */
@EqualsAndHashCode(exclude = {"accountConverter"})
// TODO: maybe we should not exclude accountConverter from equals and hashCode
@EqualsAndHashCode
Copy link
Contributor

Choose a reason for hiding this comment

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

this will introduce non-deterministic equality or false mis-matches on equals/hash? since AccountConverter is a stateless function not a value object, it can produce the same output account values whether it's enableMuxed property is true or false when the incoming accounts of the tx are edd25519, this would result in the a sub-class object instance with AccountConverter(enabledMuxed=false) to not match based on equals/hash to another instance of same sub-class but with AccountConverter(enabledMuxed=true), even though both of those instances will result in generated the exact same tx xdr via toXdr().

I'm wondering if this abstract tx class should even have an equals/hash code implementation at all, b/c the subclasses of this should decide how tx instance state is created for equals/hash.

Further, it seems like lombok @EqualsAndHashCode which derives instance equality from member value comparisons alone is not well suited for Transaction sub classes(Transaction and FeeBumpTransaction) equality, since subclass instance state does not represent the complete value of a stellar transaction yet, correct? What do you think about the equals/hash of Transaction and FeeBumpTransaction using the output of toXdr() as instance value instead of member values? since that compiled xdr value represents an instance's true stellar transaction?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for pointing this out, comparing XDR objects is indeed a good approach, and I have already made the modification.

@overcat overcat changed the title Add accountConverter to the equals and hashCode of AbstractTransaction. * Fix the hashCode and equals methods in Transaction and FeeBumpTransaction. Jan 13, 2024
@overcat overcat requested a review from sreuland January 13, 2024 03:39
@overcat overcat changed the title * Fix the hashCode and equals methods in Transaction and FeeBumpTransaction. Fix the hashCode and equals methods in Transaction and FeeBumpTransaction. Jan 13, 2024
@sreuland sreuland mentioned this pull request Jan 15, 2024
…Transaction`, now they will compare based on the `signatureBase()`.
# Conflicts:
#	CHANGELOG.md
#	src/main/java/org/stellar/sdk/Transaction.java
@overcat overcat requested a review from sreuland January 16, 2024 02:22
Copy link
Contributor

@sreuland sreuland left a comment

Choose a reason for hiding this comment

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

lgtm, thanks for discussion on tx equals/hash

@overcat overcat merged commit cb8678d into lightsail-network:master Jan 16, 2024
6 checks passed
@overcat overcat deleted the tx-accountConverter branch January 16, 2024 06:01
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.

2 participants