Title: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: mocacinno on October 29, 2020, 09:31:38 AM Since the mempool is filling up nicely the last couple of days and i see loads of new and longtime members struggeling getting their transactions confirmed after paying a fee that's to low for the current status of the mempool, i decided to dedicate a long post to executing a Child Pays For Parent (CPFP).
What is a CPFP? Well, if you create a transaction, you use one or more unspent outputs as an input for your new transaction, and your transaction creates one or more new unspent outputs funding an address created by the receiver and USUALLY the leftover funds (the change) funds an address created by your own wallet (the change address). If the fee (in sat/vbyte) you chose when creating your transaction was to low (sometimes the wallet set a low fee in your place), miners won't have an incentive to add your transaction to the block they're currently trying to solve (yep, the fees go to the miner, NOT to the creator of the wallet), so the odds of getting your transaction confirmed are low. A CPFP fixes this problem. A CPFP is taking one new unspent output created by your unconfirmed transaction and using it as an input for a new transaction. This new transaction should have a fee that is at least enough to cover the fee of your stuck transaction + the fee of your new transaction (minus the fee already payed for the stuck transaction). If i miner wants to collect this big fee of the second transaction, he also has to put the stuck transaction into the block he's trying to solve. A theoretical example unspent output aaa with a value of 1 BTC funds address 1MyWalletAddress you use unspent output aaa as an input for a new transaction funding address 1ReceiverAddress with unspent output bbb (value 0.5 BTC) and change address 1ChangeAddress with unspent output ccc (value 0.499999). The fee payed by this transaction is 1 - (0.5+0.499999) => 0.000001 (100 sats). Waaaay to low... This transaction is stuck in the mempool for ages if we don't do something... Well, luckily both you and the receiver have access to an address that was funded by this stuck transaction: you have address 1ChangeAddress funded by unspent output ccc the receiver has address 1ReceiverAddress funded by unspent output bbb Soooo.... Either you create a new transaction using unspent output ccc as an input or the receiver creates a new transaction using unspent output bbb as an input. The fee you should pay for this new is: (the optimal fee of the first transaction) + (the optimal fee of the second transaction) - (the fee already payed for the first transaction => 100 sat) + (something extra since you don't want both transactions to get stuck if there's a sudden influx of tx's in the mempool). For newbies, it might be usefull to use tools like https://coinb.in/#fees, together with block explorers like blockchair.com to get a hold of the sizes of transactions (yes, it's the size of the transaction that matters, not it's value... It's perfectly possible to transfer $1.000.000 in value and pay a smaller fee than transferring $50 in value... It all depends on the amount of unspent outputs used as an input, the amount of new unspent outputs created, and the type of wallet). A little boilerplate background info before i start posting screenshots:
Now, let's get to it... Creating a CPFP for newbies (the easy version): Right click on the stuck transaction and see if there's a menu: child pays for parent... Follow the wizard :) https://i.imgur.com/H78R2YH.png you'll be presented with a nice gui: https://i.imgur.com/bywrp0i.png and what do we learn from this gui?
If presented with the following screen, just click on "sign", sometimes you have to enter your password or use your hardware wallet to sign https://i.imgur.com/xDFAqeY.png if presented with the following screen, click on "broadcast" https://i.imgur.com/WSqfUdF.png Now, let's get to it... Creating a CPFP for newbies (the hard version where you'll actually learn what you're doing and have full controll): i started my electrum client on the testnet... But everything should work the same on the main net! https://www.mocacinno.com/hotlinkimages/electrum_cpfp/1.png https://www.mocacinno.com/hotlinkimages/electrum_cpfp/2.png I "accidentally" created a tx with a fee of 1 sat/byte... For the testnet, that's actually sufficient... But we're going to pretend we're on the main net, and our sat/byte tx will be stuck for days/weeks https://www.mocacinno.com/hotlinkimages/electrum_cpfp/3.png if i copy the tx id and look it up on an explorer like blockstream, or blockchair, or blockchain,... https://www.mocacinno.com/hotlinkimages/electrum_cpfp/4.png you can see the following things:
we want to show our unspent outputs in electrum https://www.mocacinno.com/hotlinkimages/electrum_cpfp/5.png go to the "coins" tab, and you'll see a list of unspent outputs funding your addresses: https://www.mocacinno.com/hotlinkimages/electrum_cpfp/6.png Do you see the unspent output funding my change address? mjUxPsHYbn9rrs9c8bqNr4WFKCoeWCatmw? That's the one we need!!! You could verify this by looking in the same "coins" tab to the "output point" column. This should be the tx id of the stuck transaction!!! This tutorial is written from the sender's point of view... HOWEVER, it works exactly the same way if you're the receiver. In this case, you'll also see an unspent output funding the address you gave to the sender, this is the unspent output you want to use :) once you've found the unspent output funding the change address created by the stuck transaction, do the following: https://www.mocacinno.com/hotlinkimages/electrum_cpfp/7.png https://www.mocacinno.com/hotlinkimages/electrum_cpfp/8.png go to "preferences" https://www.mocacinno.com/hotlinkimages/electrum_cpfp/9.png the transactions tab: https://www.mocacinno.com/hotlinkimages/electrum_cpfp/10.png
go to the "addresses" tab (wich you might have to activate by clicking "view" => "show addresses" and pick an unused address (or a used one, i don't care) https://www.mocacinno.com/hotlinkimages/electrum_cpfp/11.png copy it https://www.mocacinno.com/hotlinkimages/electrum_cpfp/12.png click on the send tab, paste it, click on "max" https://www.mocacinno.com/hotlinkimages/electrum_cpfp/13.png since you enabled "advanced preview" in the settings, you'll end up on this page: https://www.mocacinno.com/hotlinkimages/electrum_cpfp/14.png As you can see, you can manually set the fee for your CPFP tx... Remember, you need the fee to cover the fee for your stuck transaction AND your cpfp transaction... Calculating an appropriate fee is a completely different discussion... And since this post is already huge i'll skip it... As a rule of thumb, you should at least double the current fee, unless the stuck transaction is big (in that case doubling it won't do the trick). click on sign https://www.mocacinno.com/hotlinkimages/electrum_cpfp/15.png enter your password (or sign using your hardware wallet) https://www.mocacinno.com/hotlinkimages/electrum_cpfp/16.png click on "broadcast" https://www.mocacinno.com/hotlinkimages/electrum_cpfp/17.png here's the block explorer's view of the address i'm using to receive the change from my CPFP: https://www.mocacinno.com/hotlinkimages/electrum_cpfp/18.png Now, this is concludes creating a CPFP... Now let's see on my node what we actually did... This step cannot be executed by you, and it's not something that's necessary to create a CPFP... It's just my way of showing what actually happened: https://www.mocacinno.com/hotlinkimages/electrum_cpfp/19.png This is the mempool view of my CPFP tx: do you see the fee? It's much higher than the 1 sat/vbyte fee we used for our stuck transaction isn't it? What's even more important is to see the tx id of the stuck transaction in the section "depends". This actually means that a miner cannot claim the fee of the CPFP tx without also including the stuck transaction... The CPFP tx depends on the stuck transaction. Once a miner mines a block that includes the CPFP tx, he also has to include the stuck tx, solving your problem :) Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: Charles-Tim on October 29, 2020, 09:47:09 AM This is a very well explained, cpfp is a very good means to make the transaction (child and parents transactions) confirmed faster, but how about using rbf also in which we can just pump the fee so that the transaction will have high chance of getting placed in the next block. I have used rbf several times on electrum and it worked effectively.
1. But, I have few questions, if cpfp is used, that means the sender is sending to two addresses, is the fee (for the two addresses) divided by 2 going to be lower than using rbf? 2. Can I use cpfp to send back to my own address? Like, I send to my friend with low fee but later use cpfp using my own another new address as the child address? In this case, is the fee will be the same as rbf or higher? Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: mocacinno on October 29, 2020, 10:05:59 AM This is a very well explained, cpfp is a very good means to make the transaction (child and parents transactions) confirmed faster, but how about using rbf also in which we can just pump the fee so that the transaction will have high chance of getting placed in the next block. I have used rbf several times on electrum and it worked effectively. Yup, there are several ways of getting a tx unstuck... I've already explained that in my OP (big red letters). The thing is: you have to opt-in rbf... Once a newbie has his tx stuck, it's to late if he didn't opt-in... 1. But, I have few questions, if cpfp is used, that means the sender is sending to two addresses, is the fee (for the two addresses) divided by 2 going to be lower than using rbf? Not always. But usually, a change address is generated. It's possible to spend the complete value of one or more unspent outputs without sending change to a change address. In this case, only the receiver can do a CPFPRBF is usually cheaper by the way... an rbf has to pay for it's own bandwith tough... I'm going to assume a tx has a size of 200 vbytes for this example. So if your original tx had a size of 200 vbytes and a fee of 1 sat/vbyte (so 200 sats) and this tx gets stuck and you bump the fee the following will happen: Let's assume your rbf tx has a size of 200 vbytes so it's fee has to be at least 200 sat's higher than the original (so 400 sats) . In this case, this is the same as a minimum fee of 2 sats/vbyte. So, if you look at it this way, an RBF requires a minimum increase in the fee of 1 sat/vbyte. That's not a lot, and usually you need to bump the fee by far more in order to "fix" your problem. A CPFP will actually have to pay for two transactions with a size of 200 vbytes (400 vbytes in total). If you use a fee of 2 sats/vbyte you'll end up with 800 sats in fee vs 400 for a RBF... Offcourse, we're talking about fees of >200 sats/vbyte at this moment :( 2. Can I use cpfp to send back to my own address? Like, I send to my friend with low fee but later use cpfp using my own another new address as the child address? In this case, is the fee will be the same as rbf or higher? I have a hard time understanding the question... But i'll try to give a more generic answer: if you send funds to your friend and there's change going back to your wallet, you can execute a CPFP using the unspent output funding your change address. A CPFP's output can be an address belonging to your own wallet. Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: Pmalek on October 29, 2020, 10:21:02 AM I must admit that in all my years in Bitcoin, I have never carried out a CPFP transaction. This entire ordeal could easily be prevented if users would simply configure their Electrum (and other wallet software) to always opt-in for RBF. If they are using a wallet that doesn't have an RBF, it's a good idea to find a better app. The crazy fees of the last few days prove exactly why an RBF option should be ticked. And you said yourself, that using the RBF feature is cheaper than a CPFP transaction.
Excellent guide, but I hope I will never have to use it. ;D Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: zasad@ on October 31, 2020, 10:11:11 PM Thank you for the detailed description and good presentation of the material.
I made a translation of your theme for Russian-speaking users https://bitcointalk.org/index.php?topic=5285817 I always use RBF for payments to avoid testing an important method in practice. But I learned a lot from your post. Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: PrimeNumber7 on November 01, 2020, 07:40:03 PM 2. Can I use cpfp to send back to my own address? Like, I send to my friend with low fee but later use cpfp using my own another new address as the child address? In this case, is the fee will be the same as rbf or higher? If your transaction has a change output, you can create a CPFP transaction using the change output as an input, and the output back to yourself. In this case, your CPFP transaction will have only one output. If you send a transaction to your friend, and there is no change output (you send him the entire amount of all the inputs in the transaction, less transaction fees), if you want to create a CPFP transaction, your friend will have to create a CPFP transaction and pay the higher fee out of the coin he received from you. The total fees you pay in a CPFP transaction will almost always be higher than you would pay with a Replace By Fee (RBF) because you are paying for two transactions with CPFP, while only one transaction with a RBF transaction. I believe this is answering your question. Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: OutCast3k on November 02, 2020, 09:54:52 AM Nice guide, heres another one to help with double spends and RBF https://blog.coinb.in/guide_double_spend_rbf
Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: bomberb17 on January 17, 2021, 09:04:06 PM Question: why is the CPFP transaction output address different?
Is this because change address was enabled? I tried to test this with my electrum wallet and the output address was also different, even though I had change address disabled. Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: PrimeNumber7 on January 17, 2021, 09:09:17 PM Question: why is the CPFP transaction output address different? A CPFP transaction is spending one of the outputs from an unconfirmed transaction, typically the change address. If your wallet software is not reusing addresses (it shouldn’t), it will send the transaction to a new, unused address. Is this because change address was enabled? I tried to test this with my electrum wallet and the output address was also different, even though I had change address disabled. Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: bomberb17 on January 17, 2021, 09:44:05 PM So is change address basically forced in CPFP?
Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: Pokapoka124 on January 17, 2021, 10:08:27 PM Thanks OP. This is very informative I have been struggling with high fees from blockchain. Glad I found bitcointalk forum
Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: PrimeNumber7 on January 17, 2021, 10:12:13 PM So is change address basically forced in CPFP? No, it is not forced, it would be possible to send a transaction back to the same address as you are sending from, if that is what you wanted to do. Doing so will result in reduced privacy for you though. Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: bomberb17 on January 17, 2021, 10:37:34 PM So is change address basically forced in CPFP? No, it is not forced, it would be possible to send a transaction back to the same address as you are sending from, if that is what you wanted to do. Doing so will result in reduced privacy for you though. I completely understand the privacy issue. However I cannot find how to use same address in CPFP (using Electrum 4.0.9 with change address box disabled) Title: Re: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum Post by: mocacinno on January 19, 2021, 11:36:03 AM So is change address basically forced in CPFP? No, it is not forced, it would be possible to send a transaction back to the same address as you are sending from, if that is what you wanted to do. Doing so will result in reduced privacy for you though. Exactly, re-using the address would only have (minor) downsides... Your public key would have been broadcasted and you'll lose some privacy... Neither of these things is a "big deal" (unless you value your privacy to a great extent). |