Bitcoin Forum
May 26, 2024, 11:05:43 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: what is the role of nChainWork in CBlockIndex  (Read 539 times)
lovecodelc (OP)
Newbie
*
Offline Offline

Activity: 15
Merit: 2


View Profile
October 10, 2016, 03:14:21 AM
 #1

Hello, i have question about nChainWork:
The block index database gets loaded into memory when the node starts, in src/main.cpp LoadBlockIndexDB function,
the code "pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);", why do this?

nChainWork noted:"Total amount of work (expected number of hashes) in the chain up to and including this block".
here:https://en.bitcoin.it/wiki/Bitcoin_Core_0.11_(ch_6):_The_Blockchain

Thank you.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3402
Merit: 6659


Just writing some code


View Profile WWW
October 10, 2016, 03:27:46 AM
Merited by ABCbits (1)
 #2

Can you stop spamming with all of these threads? Just make a thread for questions about the code breakdown. Also, I highly suggest that you read the Documentation at https://dev.visucore.com/bitcoin/doxygen/ and you logically think through what you are asking before asking the question.

I don't need to even read the code to understand this line, just logically thinking.

This line adds the chainwork of the previous block to the chainwork of the current block. It uses the ternary operator to start at 0 if the previous block doesn't exist, i.e. the genesis block. Otherwise it will get the chainwork of the previous block.

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!