Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: webtricks on January 01, 2020, 06:36:17 AM



Title: A question regarding Timestamp
Post by: webtricks on January 01, 2020, 06:36:17 AM
As we all know nonce is the number that keeps on changing until the hash generated with the joint string of nonce and other block data matches the target difficulty requirement.
Other block data such as data, last hash and difficulty remain constant but what about timestamp? Does timestamp also changes alongside nonce at every iteration until required hash is found or it remains constant?


Title: Re: A question regarding Timestamp
Post by: pooya87 on January 01, 2020, 07:14:55 AM
not at every iteration but it also changes.
you have this structure:
1- version
2- Previous Block Header Hash
3- MerkleRoot Hash
4- Block Time (or timestamp)
5- N Bits
6- Nonce
these make up 80 bytes and 1&2&5 are fixed for that block while 3&4&6 can change. mining is basically changing 1 bit at a time (from the bits that can change) and hashing it again until you  get the result. so you start from somewhere (nonce) then when you run out of bits you move to another variable.

the loop could look like this:
start: nonce=0
increment nonce(+1)
reach nonce max (0xffffffff)
change nonce to 0 and change something else:
  - timestamp if enough time has been passed
  - merkle root if new transactions were added to the mempool and were included in this block
    or have a variable in coinbase tx called extranonce and change that.
increment nonce(+1)
...