Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: iacz489 on February 19, 2014, 09:30:53 PM



Title: Question - Tx Confirmation Details
Post by: iacz489 on February 19, 2014, 09:30:53 PM
According to the protocol specific given by BitcoinWiki, after a transaction is broadcast,  ""it may be included in a block that is published to the network". Here comes something trivial: When is the newly confirmed transaction written into a block? Suppose I am an average node and I received a transaction and verified it is valid. What is the next step for me? Do I write this transaction into the latest block? How to make sure all nodes have a specific transaction written consistently into the same block?
I am currently researching network consistency issues and security problems in the Bitcoin system. This problem seems to remains an unsolved issue given I have not misunderstood anything else. I appreciate any help from anyone professional. Thanks in advance.


Title: Re: Question - Tx Confirmation Details
Post by: wheatstone on February 19, 2014, 10:26:03 PM
A transaction is only confirmed once it is mined, i.e. contained in a valid block in the blockchain.

Transactions are broadcast to the network (typically) and miners (pools) decide which transactions they want to include in their next block. Each miner can freely chose which transactions to include and which not to.

Once a valid solution is found (i.e. the block is mined), whatever transactions the miner chose to include are then confirmed and part of the blockchain.

(At this stage there is actually still a small chance that the block will NOT be part of the consensus blockchain, if another valid block is distributed AND a subsequent block on that branch is mined.)


Title: Re: Question - Tx Confirmation Details
Post by: DannyHamilton on February 19, 2014, 11:28:33 PM
According to the protocol specific given by BitcoinWiki, after a transaction is broadcast,  ""it may be included in a block that is published to the network". Here comes something trivial: When is the newly confirmed transaction written into a block? Suppose I am an average node and I received a transaction and verified it is valid. What is the next step for me? Do I write this transaction into the latest block? How to make sure all nodes have a specific transaction written consistently into the same block?
I am currently researching network consistency issues and security problems in the Bitcoin system. This problem seems to remains an unsolved issue given I have not misunderstood anything else. I appreciate any help from anyone professional. Thanks in advance.

Have you read the Bitcoin Whitepaper written by Satoshi Nakamoto yet?  If not, then you should do that *before* "researching network consistency issues and security problems in the Bitcoin system".

That being said.  If we are going to "Suppose you are an average node", then you will verify that the inputs are all valid previously unspent outputs that you know about.  You will also verify that the necessary signaures (or other script requirements) have been met.  Once you've confirmed that all the pieces of the transaction are valid, you will store the transaction in a memory pool, and relay it to all the peers that you are connected to.  That's it.  Not much more than that.

Now, if instead of supposing that you are an "average node", we suppose that you are a miner (or mining pool), then you will choose some of the unconfirmed transactions from your memory pool and will arrange them in a particular order.  You will also create a special "coinbase" transaction that has no inputs and pays out the current block subsidy split among as many outputs as you like (as long as you don't exceed the maximum transaction size).  You will take this list of transactions and compute a merkle root (this is a hash that is unique to this particular set of chosen transactions arranged in this particular order).  When choosing transactions, you will not include any transaction that is using an unconfirmed output as its input unless you also include that "parent" transaction in your block.  Then you will build a block header that includes the hash of the previous block, the merkle root of your chosen list of transactions, and a few other important pieces of information (such as the size of the block).  You will begin searching for a nonce value that will result in the hash of that block header being less than the current target difficulty.  Once you find a low enough hash, you will broadcast to all your connected peers the block with the appropriate nonce.  If your block is the first that any peer has heard about that uses the same "previous block" hash, then they will all validate the contents of your block and header.  Then they will add it to their blockchain and relay it to all their connected peers.  Any transaction that is included in the block that you built is now considered to be "confirmed" with 1 confirmations.