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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.

### Update
* Support resource leeway parameter when simulating Soroban transactions. ([#561](https://github.com/stellar/java-stellar-sdk/pull/561))
* Add `accountConverter` to the `equals` and `hashCode` of `AbstractTransaction`. ([#566](https://github.com/stellar/java-stellar-sdk/pull/566))

### Breaking changes
* The types of the following fields have changed. ([#560](https://github.com/stellar/java-stellar-sdk/pull/560))
| field | before | now |
| --------------------------------------- | ------- | ---- |
| GetEventsRequest.startLedger | String | Long |
| GetEventsResponse.EventInfo.ledger | Integer | Long |
| GetLatestLedgerResponse.protocolVersion | Integer | Long |
* Add `accountConverter` to the `equals` and `hashCode` of `AbstractTransaction`, this will affect `Transaction` and `FeeBumpTransaction`, in previous versions, they would ignore `accountConverter`. ([#566](https://github.com/stellar/java-stellar-sdk/pull/566))

## 0.42.0
* Make `StrKey` public, this allows users to conveniently encode and decode Stellar keys to/from strings. ([#548](https://github.com/stellar/java-stellar-sdk/pull/548))
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/stellar/sdk/AbstractTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.

public abstract class AbstractTransaction {
/** The network that the transaction is to be submitted to. */
@NonNull @Getter protected final Network network;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/stellar/sdk/Sep10ChallengeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ public void testReadChallengeTransactionInvalidWebAuthDomainOperationValueIsNull
Operation[] operations =
new Operation[] {domainNameOperation, webAuthDomainOperation, otherDomainOperation};
Transaction transaction =
new TransactionBuilder(AccountConverter.disableMuxed(), sourceAccount, network)
new TransactionBuilder(AccountConverter.enableMuxed(), sourceAccount, network)
.setBaseFee(100 * operations.length)
.addOperations(Arrays.asList(operations))
.addMemo(Memo.none())
Expand Down
Loading