Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: d4n13 on July 06, 2015, 09:10:39 PM



Title: Question on CPFP and what happens if its violated.
Post by: d4n13 on July 06, 2015, 09:10:39 PM
I know there is already a pull request on this, but seeing how many of the devs have there hands full answering BIP66 questions, I thought I might be this question to the community to hopefully set my mind right.

https://github.com/bitcoin/bitcoin/pull/1647 AKA "Child-Pays-For-Parent" (CPFP) effectively puts selection logic into the mining reference code to select dependent transactions together.  My question is this...

What happens if a child is accepted into a block and a parent is not?

To define terms,

Parent TXid = x.  It spends outputs that have already had 6+ confirmations.
Child TXid = y.  It spends outputs from Parent (x).

Parent and child enter the mempool together, but the child (txid:y) is paying high fees to try to get into the blockchain.  CPFP would make the two dependent transactions go in together, but what if a miner doesn't do that?

Would a block be valid if one of it's TXs (txid:y, aka "child") is spending outputs that are still in the mempool (txid:x, aka "parent")?

If the block was accepted then the "child" (txid:y), should it be reported as 0 confirms since it's dependent "parent" (txid:x) is still in the mempool?

references:
[PR1647] Child Pays For Parent (https://github.com/bitcoin/bitcoin/pull/1647)
bitcoin-dev mailing list discussion on this subject (https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-July/009304.html)



Title: Re: Question on CPFP and what happens if its violated.
Post by: dexX7 on July 06, 2015, 09:23:02 PM
Would a block be valid if one of it's TXs (txid:y, aka "child") is spending outputs that are still in the mempool (txid:x, aka "parent")?

No, this isn't possible. The parent must be processed/mined before the child can.


Title: Re: Question on CPFP and what happens if its violated.
Post by: achow101 on July 06, 2015, 09:27:54 PM
Would a block be valid if one of it's TXs (txid:y, aka "child") is spending outputs that are still in the mempool (txid:x, aka "parent")?

If the block was accepted then the "child" (txid:y), should it be reported as 0 confirms since it's dependent "parent" (txid:x) is still in the mempool?
The idea behind CPFP is that both transactions will go into the same block, thus confirming both transactions at the same time. A transaction cannot be considered confirmed nor added into a block unless its parent is also confirmed, be it previously or in the same block.


Title: Re: Question on CPFP and what happens if its violated.
Post by: d4n13 on July 07, 2015, 12:07:34 AM
The idea behind CPFP is that both transactions will go into the same block, thus confirming both transactions at the same time. A transaction cannot be considered confirmed nor added into a block unless its parent is also confirmed, be it previously or in the same block.

OK... With the fall out of the BIP66 SPV Miners who were not performing complete block verification, I got worried.  I was looking for codified consensus rules.  I see that the COrphan class (https://github.com/bitcoin/bitcoin/blob/master/src/miner.cpp#L34) does take dependencies into account in the HaveCoins (https://github.com/bitcoin/bitcoin/blob/master/src/miner.cpp#L165) check.  Also, HaveCoins (https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L817) is checking for mempool dependencies on incoming transactions from peers.

So I'm convinced that bitcoind is handling this for miners using getblocktemplate (https://github.com/bitcoin/bitcoin/blob/master/src/rpcmining.cpp#L315), but how many miners out there are using their own custom code?

So feeding my paranoia for a bit here, even if a miner running custom code did submit a new block with an unfunded tx (since the tx was in mempool), then hopefully the clients would reject it.  I searched through ConnectBlock (https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1656), looking for where this was checked, like with HaveCoins, but eventually gave up.

So if mempool dependencies are already taken into account, then what does CPFP do?  Best I can tell it adjusts the priority weighting calculate child and parent together.  True?

Thx


Title: Re: Question on CPFP and what happens if its violated.
Post by: achow101 on July 07, 2015, 12:13:55 AM
So if mempool dependencies are already taken into account, then what does CPFP do?  Best I can tell it adjusts the priority weighting calculate child and parent together.  True?
I believe so. you can check the code from the pull request you reference above, it should relatively easy to figure out what CPFP does. To aid you in your search through the code, I recommend that you look at the docs for Bitcoin which can be found here: https://dev.visucore.com/bitcoin/doxygen/. These docs make it much easier to find things in the code.


Title: Re: Question on CPFP and what happens if its violated.
Post by: d4n13 on July 07, 2015, 12:17:34 AM
I believe so. you can check the code from the pull request you reference above, it should relatively easy to figure out what CPFP does. To aid you in your search through the code, I recommend that you look at the docs for Bitcoin which can be found here: https://dev.visucore.com/bitcoin/doxygen/. These docs make it much easier to find things in the code.

 ;D The Holy Grail

I'm sure that link was likely in a README that I should have read, so extra thanks for pushing me along.



Title: Re: Question on CPFP and what happens if its violated.
Post by: arnuschky on July 13, 2015, 06:17:36 AM
So feeding my paranoia for a bit here, even if a miner running custom code did submit a new block with an unfunded tx (since the tx was in mempool), then hopefully the clients would reject it.  I searched through ConnectBlock (https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1656), looking for where this was checked, like with HaveCoins, but eventually gave up.

While I cannot provide the exact location of that check in the code, you can be certain that this is happening. Else all I would need to do to become filthy rich is to mine a single block that generates thousands of coins from nothing... ;)