Author

Topic: what is the role of nChainWork in CBlockIndex (Read 558 times)

staff
Activity: 3458
Merit: 6793
Just writing some code
October 09, 2016, 10:27:46 PM
#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.
newbie
Activity: 15
Merit: 2
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.
Jump to: