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

CPFP #3

Open
louneskmt opened this issue Dec 22, 2023 · 8 comments
Open

CPFP #3

louneskmt opened this issue Dec 22, 2023 · 8 comments

Comments

@louneskmt
Copy link

Hey! I'm trying to use this to build a transaction that CPFP another one. It could be useful to have an option to specify the previous transaction fee rate, so the algorithm can take it into account. I can add this, but would need to check with you @landabaso the best way to do it. We need to know the previous transaction fee rate, so we can compute a new fee rate from the given fee rate and the previous one: newFeeRate = 2 * feeRate - previousFeeRate (with feeRate > previousFeeRate otherwise it wouldn't bump anything). Then use that new fee rate as replacement of the input fee rate in the algos.

@louneskmt
Copy link
Author

Now that I think about it, I can definitely do this calculation outside of the library haha.

@louneskmt
Copy link
Author

louneskmt commented Dec 22, 2023

But I still need a way to coinselect for only one output: the change. maxFunds doesn't do any coin selection and coinselect validates that targets is not empty. And to force specific utxos (the anchor) to be selected as well.

@landabaso
Copy link
Member

Thank you for your message. I would need to make sure I fully undestand the approach you're planning to implement outside of the library. Regarding maxFunds, your understanding is right - it's indeed set up to use all available UTXOs. And coinselect is designed to validate that the targets array is not empty. This validation ensures there's at least one output for the transaction.

I would need a more detailed explanation of your specific requirements.

@louneskmt
Copy link
Author

louneskmt commented Dec 22, 2023

The goal is to bump a previous transaction fee using Child Pay For Parent. So, I need to build a transaction that spends given (unconfirmed) UTXOs to a single change target.

The current coinselect:

  • takes an array of UTXOs in which it will select some to pay the sum of the targets values + fees
  • needs at least 2 outputs (1 target and 1 change)

What would be necessary to do a proper CPFP:

  • be able to specify fixed UTXOs to use (basically add them in the utxosSoFar from the start)
  • be able to coinselect for a transaction sending to a change output only (no target)

What we could do would be:

  • add another function like maxFunds but for a self-payment, that would take no target, only a change
  • add an argument to the algos functions for the UTXOs to always include in the selection

Thinking about it, we could even replace maxFunds by that selfPayment function if we give it no UTXOs to select, and only fixed UTXOs to always include.

Is that clearer?

@landabaso
Copy link
Member

landabaso commented Dec 22, 2023

add another function like maxFunds but for a self-payment, that would take no target, only a change

That's the part I don't understand. You can already use maxFunds with an empty array of targets. And then pass your change to remainder.

See, for example:

@louneskmt
Copy link
Author

Sure but it doesn't select UTXOs, it spends all of them. For example, I have a 1000 sats anchor output I want to spend to bump the transaction fees. 1000 sats isn't enough to pay for the high fees, so I need to add some UTXOs to the inputs, and I need to select these UTXOs.

@landabaso
Copy link
Member

I see. So this is a tx you want to unstuck by sending it back completely to yourself. Right?

What about using coinselect with a SegWit remainder, even if you end up not utilizing it? After running coinselect, you'll have two targets: the real one and the remainder.

You could add the values of these two targets together. Then, build a transaction using only the real target address but using the sum of the 2 targets as value.

Of course, coinselect will have computed the transaction assuming an extra output, so you'll actually be paying a slightly higher fee to the miner.

If desired, you can adjust this by adding back the excess fee to the real output, with something like this: realTargetValue = realTargetValue + remainingTargetValue + (feeRate * remainingOutput.outputWeight() / 4). Does this approach make sense?

@louneskmt
Copy link
Author

What about the extra input for the anchor?

I'm sure I could get it done with some tricky workarounds (like I am currently doing), but it feels like it would be nice to get this natively? If we settle on an API, I can make a PR 👍

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

No branches or pull requests

2 participants