Bitcoin Forum
April 25, 2024, 02:37:59 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How exactly are forks resolved in bitcoin?  (Read 250 times)
Anonymous Kid (OP)
Member
**
Offline Offline

Activity: 183
Merit: 25


View Profile
November 05, 2018, 06:28:30 PM
Merited by DarkStar_ (3), ABCbits (1)
 #1

so say there is one block 1500. the next block published is 1501_a. but at the same time another block is published 1501_b.
a node recieves 1501_a first and stores it as the main chain. but the next block is actually mined on top of 1502_b.

so now the node has to revert any changes made with block 1501_a. and change it so that it never happened but was instead 1501_b and then 1502_b.

how does the node revert the changes exactly?

the only thing i can think that has to be changed are, the utxo set would need to be edited to go back to 1500. and then 1501_b, 1502_b.
and the last block hash has to be changed to 1502_b as well as deleting 1501_b.

but how is the utxo set reverted? it means that utxos that were spent and deleted from the db after block 1502_a was processed, will have to some how be recovered again. how is this done?
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714012679
Hero Member
*
Offline Offline

Posts: 1714012679

View Profile Personal Message (Offline)

Ignore
1714012679
Reply with quote  #2

1714012679
Report to moderator
1714012679
Hero Member
*
Offline Offline

Posts: 1714012679

View Profile Personal Message (Offline)

Ignore
1714012679
Reply with quote  #2

1714012679
Report to moderator
domob
Legendary
*
Offline Offline

Activity: 1135
Merit: 1161


View Profile WWW
November 05, 2018, 06:58:20 PM
Merited by suchmoon (4), ABCbits (2)
 #2

Your description is correct - the UTXO set is reverted to the previous state and then updated for the blocks in the new chain branch.  Reverting is done by means of "undo data" that is stored along each block by Bitcoin Core - and that keeps all the information necessary to revert changes made (e.g. outputs that have been spent in the block and were thus removed from the UTXO set, so that they can be added back in).

Use your Namecoin identity as OpenID: https://nameid.org/
Donations: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS | GPG 0xA7330737
Anonymous Kid (OP)
Member
**
Offline Offline

Activity: 183
Merit: 25


View Profile
November 05, 2018, 11:30:17 PM
 #3

Your description is correct - the UTXO set is reverted to the previous state and then updated for the blocks in the new chain branch.  Reverting is done by means of "undo data" that is stored along each block by Bitcoin Core - and that keeps all the information necessary to revert changes made (e.g. outputs that have been spent in the block and were thus removed from the UTXO set, so that they can be added back in).

Oh i see its quite an obvious answer  Roll Eyes. thanks
aliashraf
Legendary
*
Offline Offline

Activity: 1456
Merit: 1174

Always remember the cause!


View Profile WWW
November 07, 2018, 08:42:16 PM
 #4

Your description is correct - the UTXO set is reverted to the previous state and then updated for the blocks in the new chain branch.  Reverting is done by means of "undo data" that is stored along each block by Bitcoin Core - and that keeps all the information necessary to revert changes made (e.g. outputs that have been spent in the block and were thus removed from the UTXO set, so that they can be added back in).
Actually there is no need to any "undo" data, the block which has to be thrown out of the main chain holds all of the data necessary for undo: its transactions have spent utxos as inputs which are the rows to be added (again) and their outputs are the rows to be removed, given the reorg process is happening reasonably in a bottom-up fashion.
domob
Legendary
*
Offline Offline

Activity: 1135
Merit: 1161


View Profile WWW
November 10, 2018, 07:37:04 PM
Merited by DarkStar_ (3), ABCbits (1)
 #5

Your description is correct - the UTXO set is reverted to the previous state and then updated for the blocks in the new chain branch.  Reverting is done by means of "undo data" that is stored along each block by Bitcoin Core - and that keeps all the information necessary to revert changes made (e.g. outputs that have been spent in the block and were thus removed from the UTXO set, so that they can be added back in).
Actually there is no need to any "undo" data, the block which has to be thrown out of the main chain holds all of the data necessary for undo: its transactions have spent utxos as inputs which are the rows to be added (again) and their outputs are the rows to be removed, given the reorg process is happening reasonably in a bottom-up fashion.

That's unfortunately not true.  While the spending transaction contains the txid and vout of the spent output, it does not contain all data that the UTXO set holds - notably missing are the scriptPubKey and amount, among other things.  Those could be looked up in the block that created the output, but that one might already be pruned and the lookup would be inefficient.  Because of that, these pieces of data are stored by Bitcoin Core in undo data.

Use your Namecoin identity as OpenID: https://nameid.org/
Donations: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS | GPG 0xA7330737
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!