<p>FYI the code under discussion is available <a href="https://github.com/bitcoin/bitcoin/blob/6a877e870e0237f66414d0229f1b5cb38c5ca06d/src/main.cpp#L1970">here on GitHub</a>.</p>

<p><code>-&gt;</code> is a member access operator in C++, just as <code>.</code> is. They both expect the name of an object's member on the right (e.g. a member function or variable). The difference is that <code>.</code> expects an object on the left, whereas <code>-&gt;</code> expects a pointer to an object which it first dereferences.</p>

<p>So <code>chainActive.Tip()-&gt;nChainWork.getdouble()</code> starts with the active chain, gets a pointer to a CBlockIndex object which represents the current tip, dereferences that pointer and gets the total chain work of the tip (which is a 256 bit integer), and converts it to a double.</p>

<p>Next it calculates <code>natural_log(total_chain_work) / natural_log(2)</code>, which is the same as calculating <code>log_base_2(total_chain_work)</code>. I presume this is simply to make the output smaller, as opposed to having to output the entire (much longer) <code>total_chain_work</code>.</p>

<p>If you'd like to get it back into the <code>total_chain_work</code> format used in older versions, just calculate 2<sup>log2_work</sup>, e.g. <code>pow(2.0, log2_work)</code>.</p>

CC BY-SA 3.0
2015-05-07T06:30:04.180Z
Minor correction: the ´log´ function in C and C++ computes the natural logarithm (base *e*), not base 10.
Nate Eldredge
CC BY-SA 3.0
2015-05-08T08:53:57.147Z
What's the "total chain work of the tip"? What's the "tip" (I assume the currently known head of the "best" blockchain)? If I see e.g. `log2_work=69.1234` what does it tell me?
Flow
CC BY-SA 3.0
2015-05-08T12:33:14.073Z
@Flow Yes, the "tip" is the most recent block in the "best" chain. The "total chain work" is the number of SHA-256d hashes that would be required (on average) to recreate the entire chain up to and including this tip (assuming the same the difficulty *target* of each block in the best chain). The "best" chain is the chain whose total work is greatest. If you see `log2_work=82.749277` (which is the current `log2_work` according to my node), it means that the total work (approximate total # of hashes calculated) is about 2^82.749277 ≈ 8.12858 * 10^24.
Christopher Gurnee
CC BY-SA 3.0
2015-05-06T17:12:17.933Z
2015-05-07T13:39:26.703Z
2015-05-07T13:39:26.703Z
Christopher Gurnee
<p>I looked up log2_work inside <code>main.cpp</code> and I can't follow its calculation by <code>log(chainActive.Tip()-&gt;nChainWork.getdouble())/log(2.0)</code>.</p>

<p>a) What is <code>-&gt;</code> explicitely indicating? (I'm at basic level of C++)</p>

<p>b) And what is <code>log2_work</code> exactly saying? Does it quantify the effort of calculation?</p>

<p>Related Question: <a href="https://bitcoin.stackexchange.com/questions/28173/what-does-updatetip-mean#comment43584_28173">here</a></p>

<blockchain><block><bitcoin-core-development><c++>
Parameters in UpdateTip - calculation of log2_work
Aliakbar Ahmadi
# Parameters in UpdateTip - calculation of log2_work

(Asked by: username_0 on 2015-05-06)

I looked up log2\_work inside `main.cpp` and I can't follow its calculation by `log(chainActive.Tip()->nChainWork.getdouble())/log(2.0)`.

a) What is `->` explicitely indicating? (I'm at basic level of C++)

b) And what is `log2_work` exactly saying? Does it quantify the effort of calculation?

Related Question: [here](https://bitcoin.stackexchange.com/questions/28173/what-does-updatetip-mean#comment43584_28173)

**Tags:** blockchain, block, bitcoin-core-development, c++


---

## 1 answers

### Answer by username_1 on 2015-05-06. Score: 10 | Accepted answer

FYI the code under discussion is available [here on GitHub](https://github.com/bitcoin/bitcoin/blob/6a877e870e0237f66414d0229f1b5cb38c5ca06d/src/main.cpp#L1970).

`->` is a member access operator in C++, just as `.` is. They both expect the name of an object's member on the right (e.g. a member function or variable). The difference is that `.` expects an object on the left, whereas `->` expects a pointer to an object which it first dereferences.

So `chainActive.Tip()->nChainWork.getdouble()` starts with the active chain, gets a pointer to a CBlockIndex object which represents the current tip, dereferences that pointer and gets the total chain work of the tip (which is a 256 bit integer), and converts it to a double.

Next it calculates `natural_log(total_chain_work) / natural_log(2)`, which is the same as calculating `log_base_2(total_chain_work)`. I presume this is simply to make the output smaller, as opposed to having to output the entire (much longer) `total_chain_work`.

If you'd like to get it back into the `total_chain_work` format used in older versions, just calculate 2log2\_work, e.g. `pow(2.0, log2_work)`.

> **Comments:**
> **username_2**: Minor correction: the ´log´ function in C and C++ computes the natural logarithm (base *e*), not base 10.  
> **username_3**: What's the "total chain work of the tip"? What's the "tip" (I assume the currently known head of the "best" blockchain)? If I see e.g. `log2_work=69.1234` what does it tell me?  
> **username_1**: @username_3 Yes, the "tip" is the most recent block in the "best" chain. The "total chain work" is the number of SHA-256d hashes that would be required (on average) to recreate the entire chain up to and including this tip (assuming the same the difficulty *target* of each block in the best chain). The "best" chain is the chain whose total work is greatest. If you see `log2_work=82.749277` (which is the current `log2_work` according to my node), it means that the total work (approximate total # of hashes calculated) is about 2^82.749277 ≈ 8.12858 * 10^24.  

---

