0

For example, I have a nth block and when n + 1 th block is propagated, i have to compare with n+1 block's previous hash and nth block's hash for validation. It is pretty trivial.

But do i have to compare hash value for validation from genesis block to n + 1 block?

like comparing 0 and 1, 1 and 2, 2, and 3 ... n and n + 1

One of the most famous pseudo block chain code in github https://github.com/dvf/blockchain/blob/master/blockchain.py#L37, block is validated from genesis block.

Bitcoin use similar way to validate a new block?

1

1 Answer 1

2

Nodes do not validate blocks from genesis each time a new block is received.

During the initial sync, nodes will validate, at the very minimum, the headers from the genesis block upto the current chain head - this allows them to find the best chain (by amount of work done). They also usually verify the utxo set.

When a new block is received, simply validating it against the previous block hash and the current utxo set is enough, as your previous block is already verified, which means all blocks before that are also verified.

If you happen to lose your local copy of the chainstate and only have raw blocks left, then you would need to revalidate from genesis.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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