Bitcoin Forum
May 12, 2024, 05:05:23 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [TUTORIAL]getting a low-fee transaction unstuck by creating a CPFP with electrum  (Read 480 times)
mocacinno (OP)
Legendary
*
Offline Offline

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
October 29, 2020, 09:31:38 AM
Last edit: October 29, 2020, 10:13:55 AM by mocacinno
Merited by hugeblack (10), Rath_ (10), LoyceV (8), joniboini (5), suchmoon (4), o_e_l_e_o (4), 1miau (4), marlboroza (4), ABCbits (2), TryNinja (2), Halab (2), DdmrDdmr (2), RickDeckard (2), hatshepsut93 (1), LeGaulois (1), Pmalek (1), tranthidung (1), Husna QA (1), hd49728 (1), zasad@ (1), Charles-Tim (1), Cookdata (1)
 #1

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:
  • CPFP is NOT the only tool in your toolbox when being faced with stuck transactions. Ideally you should have enabled opt-in RBF so you can just bump the fee.. Or you could pay viabtc or use their free accelerator, or you could just wait it out...
  • I'm giving demos on the TESTNET... Yeah, at current feerates i'm not going to do a demo on the main net Smiley
  • I take no responsability if you follow this walktrough and things go wrong... DYOR before executing following steps
  • I'm using electrum... Why electrum? Well, to begin with, electrum is a popular wallet by itself... But, it also allows you to use many popular hardware wallets together with electrum without compromising your xprv. It also allows you restore wallets from many other popular vendors, and last but not least: it allows you to easily import multiple private keys... So many situations can be solved by using electrum, even if the initial problem wasn't "created" using electrum. Oh yeah, electrum runs on linux, windows, mac and android Wink
  • Do be carefull when downloading electrum: only download from electrum.org AND verify ThomasV's signature!!!


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 Smiley


you'll be presented with a nice gui:


and what do we learn from this gui?
  • the sum of the sizes of the stuck tx + the cpfp tx is 417 bytes
  • since the testnet only requires 1 sat/byte, the gui proposes a fee of 417 sats...
  • since the stuck tx already had a fee of 226 sats, this makes the total fee for child + parent 643 sats

If presented with the following screen, just click on "sign", sometimes you have to enter your password or use your hardware wallet to sign


if presented with the following screen, click on "broadcast"



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!



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


if i copy the tx id and look it up on an explorer like blockstream, or blockchair, or blockchain,...

you can see the following things:
  • the status is unconfirmed... that's the big problem isn't it Smiley
  • the ETA is one block because we're on the testnet... You'll probably see a much larger number, otherwise you wouldn't be reading this walktrough
  • you see a fee of 1 sat/vbyte
  • you see i opted in RBF... If you see the same for YOUR transaction, there's a much easyer way to solve your stuck transaction... Just increase the fee with electrum's gui... But for this tutorial, i wanted to show a CPFP, so that's what we're going to do (eventough i can get this tx unstuck in an easyer way)
  • but the most interesting thing to see on this screenshot is: there are 2 unspent outputs created: one funding address 2MyMu3v5U7P7Ri2gThigxRn9VmandyepBVG with an unspent output with value 0.005 (this is the "payment"), and one funding address mjUxPsHYbn9rrs9c8bqNr4WFKCoeWCatmw with an unspent output with value 0.04499776 (this is the change)... Remember address mjUxPsHYbn9rrs9c8bqNr4WFKCoeWCatmw it's going to come back to haunt us


we want to show our unspent outputs in electrum


go to the "coins" tab, and you'll see a list of unspent outputs funding your addresses:


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 Smiley

once you've found the unspent output funding the change address created by the stuck transaction, do the following:




go to "preferences"


the transactions tab:

  • use replace by fee => check if you never want to create another CPFP
  • check advanced preview
  • the rest are my personal settings, you can do with them what you want after reading the help info

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)


copy it


click on the send tab, paste it, click on "max"


since you enabled "advanced preview" in the settings, you'll end up on this page:

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


enter your password (or sign using your hardware wallet)


click on "broadcast"


here's the block explorer's view of the address i'm using to receive the change from my CPFP:


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:


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 Smiley


█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
TalkImg was created especially for hosting images on bitcointalk.org: try it next time you want to post an image
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715490323
Hero Member
*
Offline Offline

Posts: 1715490323

View Profile Personal Message (Offline)

Ignore
1715490323
Reply with quote  #2

1715490323
Report to moderator
Charles-Tim
Legendary
*
Offline Offline

Activity: 1540
Merit: 4862



View Profile
October 29, 2020, 09:47:09 AM
 #2

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?

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
mocacinno (OP)
Legendary
*
Offline Offline

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
October 29, 2020, 10:05:59 AM
 #3

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 CPFP

RBF 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 Sad


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.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Pmalek
Legendary
*
Offline Offline

Activity: 2758
Merit: 7137



View Profile
October 29, 2020, 10:21:02 AM
 #4

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. Grin

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
zasad@
Legendary
*
Offline Offline

Activity: 1750
Merit: 4285



View Profile WWW
October 31, 2020, 10:11:11 PM
 #5

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.

.BEST..CHANGE.███████████████
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
███████████████
..BUY/ SELL CRYPTO..
PrimeNumber7
Copper Member
Legendary
*
Offline Offline

Activity: 1624
Merit: 1899

Amazon Prime Member #7


View Profile
November 01, 2020, 07:40:03 PM
 #6


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?
Transactions have inputs and outputs. Many transactions that individuals send will have one output to whoever you are paying and a 'change' output back to yourself.

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.
OutCast3k
Hero Member
*****
Offline Offline

Activity: 714
Merit: 601


View Profile WWW
November 02, 2020, 09:54:52 AM
 #7

Nice guide, heres another one to help with double spends and RBF https://blog.coinb.in/guide_double_spend_rbf

coinb.in - Open Source, Multi Signature, HD Wallet and more! | Donate: 33tht1bKDgZVxb39MnZsWa8oxHXHvUYE4G
bomberb17
Hero Member
*****
Offline Offline

Activity: 771
Merit: 528



View Profile
January 17, 2021, 09:04:06 PM
 #8

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.
PrimeNumber7
Copper Member
Legendary
*
Offline Offline

Activity: 1624
Merit: 1899

Amazon Prime Member #7


View Profile
January 17, 2021, 09:09:17 PM
 #9

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.
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.
bomberb17
Hero Member
*****
Offline Offline

Activity: 771
Merit: 528



View Profile
January 17, 2021, 09:44:05 PM
 #10

So is change address basically forced in CPFP?
Pokapoka124
Hero Member
*****
Offline Offline

Activity: 1148
Merit: 555


View Profile WWW
January 17, 2021, 10:08:27 PM
 #11

Thanks OP. This is very informative I have been struggling with high fees from blockchain. Glad I found bitcointalk forum
PrimeNumber7
Copper Member
Legendary
*
Offline Offline

Activity: 1624
Merit: 1899

Amazon Prime Member #7


View Profile
January 17, 2021, 10:12:13 PM
Merited by mocacinno (1)
 #12

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.
bomberb17
Hero Member
*****
Offline Offline

Activity: 771
Merit: 528



View Profile
January 17, 2021, 10:37:34 PM
 #13

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)
mocacinno (OP)
Legendary
*
Offline Offline

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
January 19, 2021, 11:36:03 AM
 #14

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).

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!