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

Cw 649 rbf improvements opt in #1772

Merged
merged 7 commits into from
Nov 28, 2024
Merged

Conversation

Serhii-Borodenko
Copy link
Contributor

Issue Number (if Applicable): Fixes #

Description

Please include a summary of the changes and which issue is fixed / feature is added.

Pull Request - Checklist

  • Initial Manual Tests Passed
  • Double check modified code and verify it with the feature/task requirements
  • Format code
  • Look for code duplication
  • Clear naming for variables and methods

Comment on lines 1705 to 1663
if (utxo.utxo.isP2tr()) {
return key.signTapRoot(txDigest, sighash: sighash);
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was accidentally removed during a merge. I’ve restored it to handle Taproot signing

@@ -1543,14 +1543,17 @@ abstract class ElectrumWalletBase extends WalletBase<
final bundle = await getTransactionExpanded(hash: txId);
final outputs = bundle.originalTransaction.outputs;

final changeAddresses = walletAddresses.allAddresses.where((element) => element.isHidden);
final receiverAmount = outputs.isNotEmpty ? outputs[0].amount.toInt() : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

what if it has multiple outputs?
why not just use outputs.fold

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Receiver amount is what the receiver should get, not just the sum of all outputs. I’ve improved this to sum outputs that aren’t change outputs, as using the first output isn’t reliable

Comment on lines 1731 to +1736
int deduction = (outputAmount - _dustAmount >= remainingFee)
? remainingFee
: outputAmount - _dustAmount;

outputs[i] = BitcoinOutput(
address: outputs[i].address, value: BigInt.from(outputAmount - deduction));
address: output.address, value: BigInt.from(outputAmount - deduction));
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we keep the output with the dust amount?
why not just check if the outputAmount - remainingFee > _dustAmount then simply deduct the remaining fee from the output and break

else, then deduct the whole output amount from remainingFee and remove the whole output, and decrement the variable i
i.e

if (outputAmount - remainingFee > _dustAmount) {
    _remainingFee = 0;
    outputs[i] = BitcoinOutput(
                address: output.address, value: BigInt.from(outputAmount - remainingFee));
   break;
} else {
    _remainingFee -= outputAmount;
    outputs.remove(i);
    i--;
}

Copy link
Contributor Author

@Serhii-Borodenko Serhii-Borodenko Nov 15, 2024

Choose a reason for hiding this comment

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

I’ve double-checked, and if I remove the output completely, I get the error “Sum value of utxo not spending” in some cases because the transaction becomes unbalanced—the inputs no longer equal the outputs plus the fee.

Copy link
Contributor

Choose a reason for hiding this comment

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

but like this it might also error out because of the dust amount

my solution is to remove it, and you can add the remaining funds (which would be a dust amount) to the fees, so that the transaction becomes balanced again

@OmarHatem28 OmarHatem28 merged commit 4ca50b5 into main Nov 28, 2024
2 checks passed
@OmarHatem28 OmarHatem28 deleted the CW-649-RBF-improvements-Opt-in branch November 28, 2024 00:42
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