Work is calculated as work = 2^256 / block_target, as stated in the linked answer, which is the minimum hash value that counts as a valid proof-of-work (note this only changes every 2016 blocks). The source code for this is src/chain.cpp L#121. The total chain work is the sum of work for all blocks in the chain, and is calculated here: src/validation.cpp L#3713. So to visualize, the lower the block target, the more work has been done.
Example
Block 0 target: 00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Block 1 target:
00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Block 0: work = (2^256) / <block 0 hash> = 4.295 × 10^9
Block 1: work = (2^256) / <block 1 hash> = 4.295 × 10^9
You can see that they have both done the same amount of work. In case of a tie, the following rules apply, see https://bitcoin.stackexchange.com/a/37275/60443
- Which one was received first? (This can be different for different clients, which is why the previous rule is applied first.)
- Which one has a larger pointer address? (This is largely random, and different for different clients.)
An explanation for "block_target" was missing. Now I understand that it is the literal block hash. – problemofficer – 2018-08-28T14:23:29.800
Could you by any chance provide a link to the respective method/line in the Bitcoin source code? – problemofficer – 2018-08-28T14:27:22.367
I've edited my answer, as I was mistaken about using the block hash for the
block_target– JBaczuk – 2018-08-28T14:37:13.900Also, added links to the source code. – JBaczuk – 2018-08-28T14:44:23.053