5

I know from the Ethereum Stats that a block is mined on average within 14 secs. But that is only on average. I want to know, step by step if possible, what are he mechanisms to say "okay, this block is done, let's create a new one".

In my opinion, it is not a limit of block size (even if there is one), because the Ethereum network can adapt itself if transactions does not consume more than 3 141 592 gas, which represent a lot of transactions.

So, I think this is related to the nounce which set the difficulty to have a block/12 secs. But I'm not sure about it.

Thank you for your valuable time and help.

4

So basically, ethereum is a state machine. You have a database of states (for example accounts with amounts). How these states change? by via of transactions. Which can be give X ether from A to B to smart contracts invocations. OK, the transactions are grouped in a block. And here is where it gets interesting.

You have the universe of miners working on producing blocks. They take transactions from the pool, process them, until they reach the gasLimit, assigning to their designated account (called the etherbase) the transaction fees and the reward for block found in the end, and from here they produce a random nonce. The nonce is important: from this nonce and the block you made, you create a hash, complicated enough to make your machine work a lot (i.e. using a lot of CPU, memory and energy. That's why it's called Proof of work). Once the miner has a hash, this is compared to the target, which is no other than 2**256 / Difficulty, so the greater the difficulty, the lesser the odds of finding a hash lesser than the target.

Since you can produce randomly 2**256 possible hashes, from your block made and your nonce, your probability at any moment of finding a valid hash is 1/D. The first miner able to find a hash lesser than the target, propagates its result. If the other miners get this block, and find it valid (by replaying its transactions and verifying nonce and hash), it is incorporated in their respective blockchain.

Now, the question: How do they manage to reach about 14 seconds in average? Well, there is a difficulty calculation function (see this post for an outstanding explanation of it), that every time a block is made, is recalculated. Then, you see that based on what you take to produce the last block, you adjust the difficulty to be able to reach a time between 10 and 19 seconds. Of course this difficulty is validated along the new block too.

To answer your question, in the end, the difficulty is related to data from the parent block, namely the difficulty, block number and time of this parent, and the time of the current block.

  • Note that miners are profit maximizers, and the work to make a block with 0 transactions is the same in probabilistic terms to the work of making a block with the maximum transactions permitted by the system (gasLimit). They will want to include as much transactions as possible to get the tx fees. – Herman Junge Jan 31 '17 at 14:05

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.