Home Bitcoin Is that this how a sequence reorganization and fork upkeep works in Bitcoin?

Is that this how a sequence reorganization and fork upkeep works in Bitcoin?

0
Is that this how a sequence reorganization and fork upkeep works in Bitcoin?

[ad_1]

I’m attempting to know how reorganization and forks associated to them work in Bitcoin. I’ve reviewed all of the questions (round 80/90 of them) associated to the chain-reorganization tag, and I feel I’ve gained some perception into how every little thing works, however I nonetheless have some uncertainties, which I’ll define beneath. First, I’ll begin with how I perceive reorganization and forks, after which I’ll pose the questions.

Solutions which have helped me essentially the most in understanding how every little thing works (Massive Because of this nice folks!):

Murch:

Pieter Wuille:

Ava Chow:

Thanks all upfront in your understanding and help and actually apologize for the extreme textual content. Any assist could be appreciated

I’m contemplating a state of affairs the place we’re synchronized, have not been offline after which reconnect.

Forks happen when two miners create the subsequent block (block A and block B) at roughly the identical time. On this state of affairs, block A is accepted by one a part of the community, whereas block B is accepted by one other a part of the community. Relying on which block a node first receives (by way of header or cmpct message), the node will first validate that block (for example A), and if every little thing is okay, declare its department as the primary/canonical department, leaving it in place. Block A is then propagated to all its friends. As for the second block (block B), no matter whether or not it solely obtained the header or your entire block because of cmpct, it’s going to solely carry out validation to test if it has a legitimate PoW and a identified guardian (all different particulars are irrelevant; whether or not the transactions are right or not). Additionally, we’ll solely ahead block A to all our friends since it’s a part of our predominant chain, whereas we maintain B solely regionally as one of many chain suggestions. At this level, now we have two chains (predominant and “facet”), ready to see which of those two might be prolonged subsequent (block C). If the chain with block A is prolonged, every little thing is okay; we carry out common validation, and that is it. Nonetheless, if the chain with block B is prolonged, a reorganization is important. On this case, all transactions from block A are returned to the mempool, and all spent UTXOs are returned to the UTXO set. After that, an entire validation is carried out on the opposite fields of the header and transactions of block B (if we solely had the header, it’s essential to additionally ship a getdata request for your entire block or a getblocktxn request for the remaining lacking transactions). If every little thing is okay, block C is validated. If C can also be tremendous, it’s forwarded to all friends, and that department turns into the brand new canonical/predominant department.

My questions are:

  1. Is every little thing written above right?
  2. I do know {that a} node solely accepts blocks for which it is aware of the guardian (if it does not know, they’re orphan blocks). Nonetheless, does that guardian must be solely one of many department suggestions, or does it simply have to be one of many blocks from any of the branches (both predominant or one of many forks)? For instance, if the primary chain has 100,000 blocks and there are two forks on the facet: the primary cut up at 20,000 blocks with the primary and has a further 5 blocks, and the second cut up at 60,000 blocks with a further 30 blocks. Will a block be accepted provided that a block comes whose guardian is the 100,000th block of the primary chain, the 20,005th block of the primary fork, or the 60,030th block of the second fork? Or will blocks whose mother and father should not department suggestions even be accepted (for instance, the 86,004th block of the primary chain, the 20,002nd block of the primary fork, and so forth.)? After I say accepted, I imply validation of PoW and checking if it may need develop into the brand new predominant chain. If it does develop into the primary chain, then different validation checks comply with.
  3. What occurs to the blocks that stay in that stale fork throughout reorganization? Do they keep as they’re, or are transactions discarded, leaving solely the header?
  4. If the chain with the B block is prolonged with the C block, for me, that turns into the primary chain, so on this case, I ahead block C to all my friends. Nonetheless, because it was beforehand the chain with block A, I did not propagate block B to my friends, so block C might be discarded as an orphan block. What occurs if such friends have by no means heard of block B? They are going to by no means settle for this department…
  5. Is all that I’ve written simply the best way Bitcoin Core implements blockchain and fork administration (upkeep), and nothing right here is a part of the consensus aside from monitoring the chain with essentially the most work, or is that not even a part of the consensus? Is it solely essential to comply with the chain with essentially the most work, and the way we implement it’s irrelevant?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here