Bitcoin Forum
May 13, 2024, 12:16:44 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Other / Beginners & Help / Need help for understanding block formation on: January 04, 2022, 05:41:52 PM
Hi everyone, wish you a happy new year.
As I am new to the bitcoin stuff I have a loads of n00b questions and I would like to have your opinions and guidance.
First of all, I intend to develop a simple miner in python3, of course not for the purpose of making any money since ASICs are now the bare minimum, but for getting a decent understanding of what is done and how.

I started with the installation of the bitcoin core (22.0) stuff and run a full node with incoming connections.
Then I tried to find a python miner to look at the code, of course they are some, especially this one : https://github.com/jgarzik/pyminer/blob/master/pyminer.py

However this one uses the pre 2012 ‘getwork’ rpc meaning that it does not work anymore (and it’s python 2 anyway).
Thus I started to look at the ‘getblocktemplate’ rpc as this should be its acknowledged replacement. From what I understand, it is more complicated but gives miners/pool more visibility on what is mined.
Of course, mining is linked to the block building and block header mining. So to build a block for my solo miner I have to build a block from scratch querying my full node.
 
Basically it should amounts to select pending transaction obtained from ‘getblocktemplate’ and  first to build the ‘coinbase’ generating transaction. This very one isn’t clear to me as it should contain an op (since it is a specific generating one), it should contain a bitcoin address (mine would be better) and an amount of BTC. If I am not mistaken, it should be the reward for the block (6.5 BTC currently?) plus the sum of the selected transaction fees.
From my understanding, a part of this very transaction can be used as an ‘extranonce’, since part of it is not strictly used for the transaction but as it modifies the content of the block, it also modifies the base merkle tree hash of the block, seen in the block header. This implies (and it was not clear to me) that every miner (unless in a pool ?) work on a different block header, even if they have selected the very same pending transactions to build their block, since their bitcoin address and possibly chosen extra nonce  changes the block header.

Any pointer (code, step by step tutorial) explaining clearly how to ‘binary’ build this first transaction would be great.
It is also not clear to me how the double sha-256 is used since sha-256 works on batches of 512 bits reusing the previous obtained hashes. Are their several rounds (in the first pass) necessary for this transaction ? I believe that in the 2nd sha-256 pass, only the obtained ‘digest’ is used thus one round is enough (thus with the default hash values as it is considered a ‘new’ message).

Ok thanks for reading and I hope some of you have pointers for me Cheesy




Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!