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

feat(coinjoin): improve asset lock handling and other fixes #244

Merged
merged 10 commits into from
Jan 16, 2024

Conversation

HashEngineering
Copy link
Collaborator

@HashEngineering HashEngineering commented Jan 10, 2024

Issue being fixed or feature implemented

What was done?

  • Fixed two bugs related to creating denominations
  • added transaction history report to wallet dump

How Has This Been Tested?

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Attention: 75 lines in your changes are missing coverage. Please review.

Comparison is base (eb4e227) 48.47% compared to head (bdae05b) 48.60%.

Files Patch % Lines
...a/org/bitcoinj/evolution/AssetLockTransaction.java 68.75% 23 Missing and 2 partials ⚠️
...t/authentication/AuthenticationGroupExtension.java 9.52% 18 Missing and 1 partial ⚠️
core/src/main/java/org/bitcoinj/wallet/Wallet.java 17.64% 13 Missing and 1 partial ⚠️
...re/src/main/java/org/bitcoinj/wallet/WalletEx.java 79.31% 3 Missing and 3 partials ⚠️
...e/src/main/java/org/bitcoinj/core/Transaction.java 58.33% 1 Missing and 4 partials ⚠️
...src/main/java/org/bitcoinj/wallet/SendRequest.java 50.00% 2 Missing ⚠️
...a/org/bitcoinj/coinjoin/CoinJoinClientSession.java 0.00% 1 Missing ⚠️
...ava/org/bitcoinj/coinjoin/CoinJoinSendRequest.java 0.00% 1 Missing ⚠️
.../java/org/bitcoinj/evolution/AssetLockPayload.java 93.75% 0 Missing and 1 partial ⚠️
...c/main/java/org/bitcoinj/script/ScriptPattern.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##             feature-coinjoin     #244      +/-   ##
======================================================
+ Coverage               48.47%   48.60%   +0.12%     
- Complexity               7446     7474      +28     
======================================================
  Files                     451      451              
  Lines                   50127    50169      +42     
  Branches                 7128     7128              
======================================================
+ Hits                    24300    24384      +84     
+ Misses                  23087    23043      -44     
- Partials                 2740     2742       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HashEngineering HashEngineering changed the base branch from master to feature-coinjoin January 10, 2024 19:33
Comment on lines +986 to +990
public String getTransactionReport() {
MonetaryFormat format = MonetaryFormat.BTC.noCode();
StringBuilder s = new StringBuilder("Transaction History Report");
s.append("\n-----------------------------------------------\n");

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function will give us a high level view of transaction history that will display transactions in order by date.

Comment on lines 91 to 105
public String toString() {
return String.format("AssetLockPayload(creditOutputs: %d)",
creditOutputs.size());
StringBuilder s = new StringBuilder("AssetLockPayload");
creditOutputs.forEach(output -> {
Script scriptPubKey = output.getScriptPubKey();
s.append("\n out ");
s.append(scriptPubKey.getChunks().size() > 0 ? scriptPubKey.toString() : "<no scriptPubKey>");
s.append(" ");
s.append(output.getValue().toFriendlyString());
s.append('\n');
s.append(" ");
Script.ScriptType scriptType = scriptPubKey.getScriptType();
s.append(scriptType).append(" addr:").append(scriptPubKey.getToAddress(params));
});
return s.toString();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This output will be similar to that of Transaction.toString

Comment on lines +566 to 571
public static Script createAssetLockOutput() {
ScriptBuilder builder = new ScriptBuilder();
builder.addChunk(new ScriptChunk(OP_RETURN, null));
builder.data(creditBurnKey.getPubKeyHash());
builder.data(new byte[0]);
return builder.build();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The OP_RETURN will not have a reference to the key that will sign the state transitions that uses this asset lock. instead this information is in the AssetLockPayload.

Comment on lines +764 to +772
if (version != MIN_STANDARD_VERSION) {
if (getVersionShort() == SPECIAL_VERSION) {
s.append(indent).append("version: ").append(getVersionShort()).append('\n');
Type type = (getVersionShort() == SPECIAL_VERSION) ? getType() : Type.TRANSACTION_NORMAL;
s.append(" type: ").append(type.toString()).append('(').append(type.getValue()).append(")\n");
} else {
s.append(indent).append("version: ").append(version).append('\n');
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to make the version number nicer to look at. This should also be added to master.

Comment on lines +630 to 638
for (TransactionOutput output : myUnspents) {
TransactionConfidence confidence = output.getParentTransaction().getConfidence();
// confirmations must be 0 or higher, not conflicted or dead
if (confidence != null && (confidence.getConfidenceType() == TransactionConfidence.ConfidenceType.PENDING || confidence.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)) {
// inputValue must match, the TX is mine and is not spent
if (output.getValue().equals(inputValue) && output.getSpentBy() == null) {
count++;
}
}
Copy link
Collaborator Author

@HashEngineering HashEngineering Jan 12, 2024

Choose a reason for hiding this comment

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

This fixes a minor bug where spent outputs were counted. Over time this would keep some denominations from being unused, especially 0.001 and 0.01. Though there was another bug that was contributing to this too.

Also refactored to turn change this from O(n^2) to O(n).

Though the output.getSpentBy() == null is redundant because myUnspents would only have unspent outputs.

if (balanceToDenominate.isGreaterThanOrEqualTo(Coin.ZERO)) break;
if (balanceToDenominate.isLessThanOrEqualTo(Coin.ZERO)) break;
Copy link
Collaborator Author

@HashEngineering HashEngineering Jan 12, 2024

Choose a reason for hiding this comment

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

This problem of > being used instead of < meant that this for loop was not being executed when it should have been. This bug prevented part of the demomination process from running.

Copy link
Member

@Syn-McJ Syn-McJ left a comment

Choose a reason for hiding this comment

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

Looks good

@HashEngineering HashEngineering marked this pull request as ready for review January 16, 2024 21:52
@HashEngineering HashEngineering merged commit f6cd23d into feature-coinjoin Jan 16, 2024
4 of 6 checks passed
@HashEngineering HashEngineering deleted the feature-coinjoin-assetlocks branch March 19, 2024 13:40
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