Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: bfisher1968 on May 31, 2015, 04:40:19 PM



Title: Block with 1 transaction(txid = merkleroot) ???
Post by: bfisher1968 on May 31, 2015, 04:40:19 PM
https://blockchain.info/block/000000000000000008dcd35e54862709e577d68ff608dc40f9858de7541b13cc (https://blockchain.info/block/000000000000000008dcd35e54862709e577d68ff608dc40f9858de7541b13cc)

If the txid is the merkleroot when a block has only 1 transaction and you need the merkleroot to solve the block, how does the only transaction get created?

I've been searching all over and never found anything mentioning what I'm asking.



Title: Re: Block with 1 transaction(txid = merkleroot) ???
Post by: Muhammed Zakir on May 31, 2015, 04:48:54 PM
If a block only has a coinbase transaction, the coinbase TXID is used as the merkle root hash.


Title: Re: Block with 1 transaction(txid = merkleroot) ???
Post by: bfisher1968 on May 31, 2015, 05:01:07 PM
Sorry for another stupid question, but how is the coinbase transaction created? Do I create that first, use the TXID for the merkleroot and hash the block header hoping I solve the block?

http://bitcoin.stackexchange.com/questions/20721/what-is-the-format-of-coinbase-transaction (http://bitcoin.stackexchange.com/questions/20721/what-is-the-format-of-coinbase-transaction) I think I found part of the answer in this url.

If a block only has a coinbase transaction, the coinbase TXID is used as the merkle root hash.


Title: Re: Block with 1 transaction(txid = merkleroot) ???
Post by: Muhammed Zakir on May 31, 2015, 05:07:58 PM
Sorry for another stupid question, but how is the coinbase transaction created?

https://en.bitcoin.it/wiki/Transaction#Generation

Do I create that first, use the TXID for the merkleroot and hash the block header hoping I solve the block?

Miner generates coinbase transaction and if a block only has a coinbase transaction, the coinbase TXID is used as the merkle root hash.


Title: Re: Block with 1 transaction(txid = merkleroot) ???
Post by: DannyHamilton on May 31, 2015, 05:18:11 PM
Sorry for another stupid question, but how is the coinbase transaction created? Do I create that first, use the TXID for the merkleroot and hash the block header hoping I solve the block?

The coinbase transaction (AKA Generation Transaction) is created similarly to how any other transaction is created.  The creator of the transaction chooses the outputs, and a single input. This input has a "coinbase" parameter instead of a scriptSig. The data in "coinbase" can be anything; it isn't used. Bitcoin puts the current compact-format target and the arbitrary-precision "extraNonce" number there, which increments every time the Nonce field in the block header overflows.

A miner (or mining pool) assembles a set of transactions in an arbitrary order and calculates the merkle root to be used in the block header when attempting to solve the block.  If the "set" of transactions contains ONLY the generation transaction, then the merkle root will be the hash of the generation transaction.

The rest of the block header fields are populated with the necessary data and then the miner can begin attempting to solve the block.  The block header is repeatedly hashed, while incrementing the nonce value after each attempt until one of the following:

  • The hash of the header is found to be lower in value than the current target.  Hooray, you've solved a block.  Quickly broadcast it to as many other miners and pools as you possibly can before someone else solves a block and yours is orphaned!
  • You receive a solved block from a peer that is using the same "prev_block" as you are using.  The blockchain has extended, you need to build a new block header. You may also need to build a new set of transactions (and therefore a new merkle root) if the previous block has effected the set of transactions that you had been using.
  • You have exhausted all nonce values and still haven't found a blockheader hash value that is lower than the current target.  You'll need to modify something else in the block header, and then start your search through all nonce values over again.  Some commonly modified values are the timestamp and the merkle root.  The merkle root can be modified by changing the input value of the generation transaction (extraNonce) or by updating the set of transactions being used


Title: Re: Block with 1 transaction(txid = merkleroot) ???
Post by: bfisher1968 on June 04, 2015, 07:36:19 PM
Since my first post I have made a simple TCP client that send json-rpc requests like "getblocktemplate". The capabilities I'm including are coinbasetxn, workid and coinbase/append. The problem I'm having is that the coinbasetxn is not part of what I'm getting back. How do I get this information since it is needed in calculating the merkleroot?