7

If I run the RPC call getBlock on the bitcoin-qt client it gives me field called chainwork containing a hash. I cant find any information what this value is about.

Request:

getblock 0000000000000000073dacdd0178da5158bd78c543fbc79bd0dacf56a2021bcc

Result:

{
"hash" : "0000000000000000073dacdd0178da5158bd78c543fbc79bd0dacf56a2021bcc",
"confirmations" : 1,
"size" : 182400,
"height" : 304962,
"version" : 2,
"merkleroot" : "b144b39759d4669cb92ca8b9084d68d1f05f1e28e16887bf062f37e3b5f79fd2",
"tx" : [
"3edc72d280edd0a7719670a5f0c97e8991a5bcfcfcfa77620969643f04d021a3",
"841840f8a7863c8fb99e26975d45ff9151b0a5f021fb479aa9ff91a138d3cd3f",
"a01af3f203313cdab4e8977cd2dccbd416872c9d9f76968fc7009f47ad630199"
],
"time" : 1402334610,
"nonce" : 2351732739,
"bits" : "185d859a",
"difficulty" : 11756551916.90395200,
"chainwork" : "0000000000000000000000000000000000000000000086859f7a841475b236fd",
"previousblockhash" : "000000000000000031132699bcb917e7e6ce3cc6cce1f20b6ad36a437436c821"
}
  • Possibly this: bitcointalk.org/index.php?topic=136628.0 – Tim S. Jun 9 '14 at 17:42
  • Not sure if this is about the chainwork or about best chain in logfiles of bitcoin-qt. On bitcointalk it says the hex data of best chain is just the first bytes of the rawblock. I checked if chainwork is the first bytes of the block but it doesnt match. Also best chain is not value of a blocks, it defines a block while chainwork changes at every block. But maybe its the sum of work put into this chain, i will check that tomorrow – Dennis Kriechel Jun 9 '14 at 19:38
8

The chainwork value is really just the total amount of work in the chain.

It is the total number of hashes that are expected to have been necessary to produce the current chain, in hexadecimal.

Converting 0000000000000000000000000000000000000000000086859f7a841475b236fd to decimal, you get 635262017308958427068157, or 635262 exahashes.

At june 2014 hash rates (100 petahash/s), it would require only 73 days to perform that many hashes, while in reality it took over 5 years. The hash rate has been going up so fast however that the impact of more than a few months ago is negligible.

  • 1
    Is this the number of single hashes or the number of double SHA-256 hashes? Or, asked in a different way, does double SHA-256 hashing the header count as a single hash or two hashes? – morsecoder Oct 3 '14 at 21:03
  • 2
    @StephenM347 that doesn't actually matter, as the chainwork is only used to compare different chains. But in practice, a double SHA-256 operation is counted as 1. – Pieter Wuille Oct 3 '14 at 22:54
11

Pieter's answer is good, the chainwork value is the expected work amount in the chain, expressed as a 32 bytes integer, for the double SHA-256 hashes calculation work.

The chainwork is used to identify the correct chain, the biggest chainwork value means the strongest or the correct chain.

By the way, Satoshi didn't initially realize that choosing the correct chain by just counting blocks allows for some extremely easy attacks. Version 0.1 just counted blocks. That's why the paper just says "longest". The idea of "chain work" was added a little later. For detail about this, please refer to here.

I just want to give some info about how this 'chainwork' value comes, for the better or deeper understanding about what it is.

Let's take a look at Satoshi's genesis block header (part of related info):

$ bitcoin-cli getblockhash 0
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

$ bitcoin-cli getblockheader 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
{
  ...
  "height": 0,
  ...
  "bits": "1d00ffff",
  "difficulty": 1,
  "chainwork": "0000000000000000000000000000000000000000000000000000000100010001",
  ...
}

As you see above, the genesis block has a '1' difficulty and a [0x01,0001,0001] chainwork . If you have a question about what's a 'difficulty', you can take a look at this answer. So, that's the right definition:

difficulty '1' = chainwork amount [0x01,0001,0001]

Then, each time when a new block generated, we just accumulate the chainwork with new block's 'difficulty' field value, but remember for each '1' difficulty we add a chainwork amount [0x01,0001,0001].

As the block chain grows, the difficulty will increase (or sometimes slightly decrease) little by little. You can take a look at the difficulty history here.

Before the first time of difficulty changed, the chain block height had reached 32255.

$ bitcoin-cli getblockhash 32255
00000000984f962134a7291e3693075ae03e521f0ee33378ec30a334d860034b

$ bitcoin-cli getblockheader 00000000984f962134a7291e3693075ae03e521f0ee33378ec30a334d860034b
{
  ...
  "height": 32255,
  ...
  "bits": "1d00ffff",
  "difficulty": 1,
  "chainwork": "00000000000000000000000000000000000000000000000000007e007e007e00”,
  ...
}

As you can see above, the chainwork value is [0x7e00,0x7e00,0x7e00], which is exactly the height[32255]+1(for the genesis block) times [0x01,0001,0001].

[0x7e00,0x7e00,0x7e00] = 32256 * [1.0] * [0x01,0001,0001]

Then let's take a look at block 32256:

$ bitcoin-cli getblockhash 32256
000000004f2886a170adb7204cb0c7a824217dd24d11a74423d564c4e0904967

$ bitcoin-cli getblockheader 000000004f2886a170adb7204cb0c7a824217dd24d11a74423d564c4e0904967
{
  ...
  "height": 32256,
  ...
  "bits": "1d00d86a",
  "difficulty": 1.182899534312841,
  "chainwork": "00000000000000000000000000000000000000000000000000007e01acd42dd2”,
  ...
}

At block 32256, because the difficulty increase from 1.0 to 1.182899534312841, then

 [chainwork value] = [previous chainwork value] + [difficulty] * [0x01,0001,0001]
 [0x7e01,acd4,2dd2] = [0x7e00,0x7e00,0x7e00] + [1.182899534312841] * [0x01,0001,0001]
  • 2
    Upvoted for extra detail. – Pieter Wuille Dec 29 '17 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.