-1

I am currently looking on how does Bitcoin work, and I would like to sum things up with your help. The point is, if I ever want to write my own mining agent, what do I have to understand in order to do so ?

First Point: The Data

Through my research, I didn't really understand WHO gives the current hash to work on. I know that it is working as a P2P network, and I think, but not sure, that all clients connected to the network are aware of the transactions.

But what should I do if I want to have access to the latest OFFICIAL (might not be the best word) block, without being in a mining pool ?

Second Point: The Computation

If I undestood this part, I have to try every nonce until sha256(sha256(data + nonce)) meets the requirements from Bitcoin.

Third part, submitting the answer

Assuming I found the right nonce, how can I submit my result. But I didn't find how I can do that.

I want to make this point clear, I want to be SOLO, not mining solo, but if I wanted to write my own mining program, how could I do that WITHOUT being in a mining pool and finding information all by myself.

Thanks for your answers.

  • 1
    I ever want to write my own mining agent Do you mean a mining program that connects to the standard client and does a getwork request, or a complete replacement of the standard client? – Nick ODell May 28 '13 at 16:54
  • The idea was, if I wanted to start from scratch, what do I have to know ? – Shitrozore May 29 '13 at 7:59
  • Start with the original bitcoin paper, then read the hashcash paper, then Hal Finney's RPOW explanation. Do you want to make something Bitcoin-like, or something compatible with Bitcoin? – Nick ODell May 29 '13 at 16:00
1

In fact, all these functions are implemented in the original Bitcoin client. Mining pools do only distribute it to contributors and sometimes slightly change the problem like Stratum does, but that's not very relevant.

Like I say, the original Bitcoin client performs the first and the last functions, but I'll explain what they imply.

  1. WHO gives the current hash to work on?

    The data to work on is the header of the current block. You can build this block yourself, but the client also does it for you. Some important pieces of information in this header (that will be hashed so that they are confirmed by the hash) are the hash of the previous block, the merkle root of all transactions in the block (this is used to check if a transaction has been included in the block) and nonce.

    So basically what you do is hash this header and check if the hash complies with the current target. If not, you can change the nonce and try again. When a new transaction comes in, you add it, update the merkle root and continue. When a new block comes in, you update the previous block hash, remove transactions in the new block from yours, update the merkle root and continue.

  2. The Computation

    As explained on the Bitcoin wiki, a double SHA-256 hash is used to hash the complete block header.

    SHA256( SHA256( Block_Header ) )

  3. How can I submit my result?

    The original Bitcoin API has a method called submitblock that you should use to submit the block to the network. Note that you will have to create the block yourself in binary format, containing all the transactions in it.

As for

I want to be SOLO, not mining solo

those things are exactly the same. Mining solo means that you do not rely on a mining pool. You can easily start with solo mining using many of the existing mining programs or simply by only using the original client.

Note that it is almost always required to have the Bitcoin client running and and being up to date in order to mine solo.

0

I think you have the (common) misconception that everyone is working on the same block. That is not true. There is no "official" block to work on. All miners just gather a bunch of transactions that are valid and haven't already been included in previous blocks. Usually even as you are mining a block you are adding more transactions to it. This does not make finding the nonce any harder. It is pretty much a random shot every time you increment it, even if the content you are hashing keeps changing.

When you (the miner) solve the nonce, you publish the block on the P2P network and all the other miners and clients pick it up, abandon the block they were working on and start with a new block that links to the one you just published.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.