3

I am currently reading an interesting book about solidity, and I'm reading about block creation. This gives a good overview:

enter image description here

The book mentions that the maximum size of a block is determined by the upper gas limit and block size.

I am a bit confused as for when a new block needs to be created.
In another example, they give an example in which the gas value does not even reach the gasUsed property of a block doesn't even come close to the gasLimit.

So in the example added, Sam wants to add $$ to Mark. But it isn't clear to me how it is decided that a new block needs to be created.
I mean, a block consists of multiple transactions, so why wouldn't this transaction just be appended to an already existing block?

Related, everywhere I read that a new block gets created by the miner who 'solves the puzzle' based on a changing nonce. So who creates this puzzle?
Also related, they mention the 'genesis' block, which is the first block in a blockchain, but there is no puzzle for this, so who creates the first block? And in a blockchain, how is it decided that we need a new genesis block? Is the ' Ethereum blockchain' therefore a combination of blockchains (each having their own genesis block)?

I know, quite a few questions... If you prefer me to split up these questions, I will. But as they're closely related, I would have hoped that a single answer could clarify these questions at once.

1 Answer 1

1

Answering your questions in a bit of a different order. I think I covered everything, but feel free to ask follow-ups in the comments.

  1. The genesis block is simply agreed upon, and there's only ever one. Anyone working from the same genesis block is part of the same blockchain.
  2. To add a block to the chain, miners "solve a puzzle" as you said. This is called mining. They construct a block out of some set of transactions. It's totally up to them, but they typically use all the transactions they know about that will fit. This new block has a bunch of headers, including a reference to the previous block in the chain. They then try to find a nonce such that hashing that nonce together with all the other headers yields a value smaller than a difficulty threshold.
  3. Once a miner finds a valid nonce, they have mined a new block. This block is sent out to the rest of the network. Now that there's a new block, everyone switches to mining on top of that. So "Who creates the puzzle?" is sort of "everyone". The puzzle is defined by the hash of the previous block and the contents of the new block being mined.
  4. The answer to why not just add a transaction to an existing block is that blocks are immutable. Changing one would mean changing its hash, and that would mean it would have to be mined again. A miner could try to do that, but in the meantime, all the other miners have moved on to the next block, so they will have a longer blockchain, and the longest blockchain is always the "correct" blockchain.

It should be noted that the difficulty is automatically adjusted according to a formula every so often with the goal being that blocks are mined at a certain pace. If blocks are being mined too fast, then the difficulty is adjusted to make mining harder and vice versa.

3
  • This answers a good part of my questions. Still a question. Transactions are requested by clients all the time and I assume that they go to the transaction pool (which I assume is some distributed in-memory db). So if there is 1 eth blockchain, then it would imply that only 1 miner can create a block at any point in time and other miners stay idle until that miner has finished the block and created a new puzzle for the next miner to fulfil, take new transactions from the pool etc. I read somewhere that is possible to have forks as well so it's a bit confusing. Could you elaborate on this?
    – Trace
    Apr 7, 2019 at 16:59
  • It's a race. All miners are trying to create the next block at all times, so none are sitting idle. Generally one will succeed, and everyone will quickly move to start mining on top of that newly generated block. But it's possible for multiple miners to succeed at around the same time, at which point there are two blockchains that are tied for being the longest. This generally just resolves itself when the next block is mined. (Whichever chain it was mined on is now the longest.)
    – user19510
    Apr 7, 2019 at 17:03
  • Many thanks, makes total sense now. Looking forward to learn more about this technology.
    – Trace
    Apr 7, 2019 at 17:04

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.