I'm looking for a detailed explanation (video would be the best) how and when transaction is being mined on Ethereum network (in theory), since the moment it's created with web3.eth.sendTransaction().

To be more specific: Assumptions: time to mine Ethereum block = 16s. If block no. 99 was started to be mined at t=0, and finished mined at t=16, block 100 started at t=16 and is still being mined and I'm creating the transaction (t=17) and it's in pendingTransactions pool.

  1. When transaction is being chosen to be included in the block? (I know that gas and gasPrice are being key factors and I'm aware that gas block limit exist), but I'm looking for graphical explanation (let's assume that gasPrice is quite high 700 Gwei). What are possible scenarios?
    • Will transaction be included in block 101?
    • Can it be still included in block 100 if one of the miners didn't start to mine block 100?
    • If it's mined in blocked 101, will the rest of the network know about transaction in block 102, once it's at least confirmed one time?

I've being looking for answers to my questions and found many related topics, read about gas, gasPrice, GHOTS protocol, but this still seems not entirely clear to me.

Thanks!

As per my understanding I would like to point out few things that I feel you are missing,

  1. There is no guarantee that mining a block will be done exactly at every t seconds (going with your assumptions t = 16 seconds). The time defined by t is the average time for a block to be mined and the network protocol maintains the average by changing the difficulty accordingly after a block is mined. Mining a block includes generating a hash that matches the difficulty(the no of zeros in front of the hash value) at that time(Generating this hash is the competition among nodes).

  2. Generating blocks will be always happening irrespective of whether there are pending transactions or not to keeping the growth rate of the blockchain which avoids attackers generating a longer blockchain without owning at least 51% of the processing power of the network.

  3. A transaction Getting selected to be included in a block depends on the gas price that you are willing to pay. This is due to miner will not include your transaction if it can find a transaction that would like to pay more. Refer the answer to this question (However if the transactions are from the same account address the nonce will matter to avoid double spending).

Referring to your scenario, the transaction can be included in any block starting from the 100th(i.e. including the 100th) depending on the gas rice you defined and other pending transaction and their gas prices. However once a block is mined, the miner node broadcast it to the network and upon receiving the message the block is mined the other nodes will validate it and stop mining for the that block and start mining the next block. Hence the nodes get to know about the transactions included in the previous block.

The Ethereum white paper explains this well. You may refer to Bitcoin white paper as well

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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