Bitcoin Forum
April 24, 2024, 06:55:47 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How is an old block that forks the chain being validated in Bitcoin Core  (Read 181 times)
BusinessChain (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 34


View Profile
December 05, 2019, 10:14:20 AM
 #1

In the Bitcoin Core source code https://github.com/bitcoin/bitcoin/blob/21ee676dd6a7d9704367b6412bf8e1e443ec2b5b/src/chainparams.cpp#L139 I see that the latest checkpoint is at height 295000.
If I understand correctly, this means that today a miner could produce a block with height 295001. Although this block would not go into the main chain of course it still has to be validated by all nodes, and if valid, it would go into the secondary chain pool.
My question is, how is this block validated, since it is not known anymore what the state of the UTXO set was at height 295000. My guess is that in order to validate, the node has to temporarily reorganize the UTXO set to height 295000, check if block 295001 is valid, if yes store it, otherwise reject it, and then restore the current state of the UTXO.
 
Looks like a lot of work. Is that the way it works?
1713984947
Hero Member
*
Offline Offline

Posts: 1713984947

View Profile Personal Message (Offline)

Ignore
1713984947
Reply with quote  #2

1713984947
Report to moderator
Once a transaction has 6 confirmations, it is extremely unlikely that an attacker without at least 50% of the network's computation power would be able to reverse it.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713984947
Hero Member
*
Offline Offline

Posts: 1713984947

View Profile Personal Message (Offline)

Ignore
1713984947
Reply with quote  #2

1713984947
Report to moderator
1713984947
Hero Member
*
Offline Offline

Posts: 1713984947

View Profile Personal Message (Offline)

Ignore
1713984947
Reply with quote  #2

1713984947
Report to moderator
1713984947
Hero Member
*
Offline Offline

Posts: 1713984947

View Profile Personal Message (Offline)

Ignore
1713984947
Reply with quote  #2

1713984947
Report to moderator
darosior
Sr. Member
****
Offline Offline

Activity: 279
Merit: 435


View Profile
December 05, 2019, 10:20:38 AM
Merited by vapourminer (1), gmaxwell (1), ABCbits (1), hugeblack (1)
 #2

The proof-of-work is checked first, and in order to make a node validate a block that old, a miner would have to produce a chain of blocks with more total work than the one from 295000 to current height. If you are interested here is the work comparison function.
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4158
Merit: 8382



View Profile WWW
December 05, 2019, 10:24:28 AM
Merited by darosior (1)
 #3

What darosior said, plus it doesn't even fetch or store the block until it has headers that indicate it would be on the most-work chain assuming it at all its ancestors are valid.
BusinessChain (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 34


View Profile
January 26, 2020, 12:48:58 AM
Merited by gmaxwell (1)
 #4

ok so let's assume there is a long valid fork that is stronger than mainchain. This might happen if a split network rejoins. How would the reorganization of the UTXO take place? Please describe the process.
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4158
Merit: 8382



View Profile WWW
January 26, 2020, 11:10:44 AM
Merited by ABCbits (1), darosior (1)
 #5

ok so let's assume there is a long valid fork that is stronger than mainchain. This might happen if a split network rejoins. How would the reorganization of the UTXO take place? Please describe the process.

If another branch gets more work it will fetch the blocks on it, undo the blocks on its current chain back to the point of the fork, then it applies the new blocks. If it encounters invalidity in the new blocks it marks the invalid block and any descendants as invalid which would make that branch no longer the longest, then it would undo back to the common ancestor and apply forward back up to the tip.

So your original thinking is close, except it doesn't even start fetching the data or storing it unless it would be the best chain by POW if it was also valid.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!