bitcoind – What’s chainwork?

0
67


Pieter’s reply is nice, the chainwork worth is the anticipated work quantity within the chain, expressed as a 32 bytes integer, for the double SHA-256 hashes calculation work.

The chainwork is used to establish the right chain, the largest chainwork worth means the strongest or the right chain.

By the best way, Satoshi did not initially notice that selecting the right chain by simply counting blocks permits for some extraordinarily straightforward assaults. Model 0.1 simply counted blocks. That is why the paper simply says “longest”. The concept of “chain work” was added just a little later. For element about this, please consult with right here.

I simply wish to give some data about how this ‘chainwork’ worth comes, for the higher or deeper understanding about what it’s.

Let’s check out Satoshi’s genesis block header (a part of associated data):

$ bitcoin-cli getblockhash 0
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

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

As you see above, the genesis block has a ‘1’ issue and a [0x01,0001,0001] chainwork . If in case you have a query about what’s a ‘issue’, you may check out this reply. So, that is the proper definition:

issue '1' = chainwork quantity [0x01,0001,0001]

Then, every time when a brand new block generated, we simply accumulate the chainwork with new block’s ‘issue’ discipline worth, however keep in mind for every ‘1’ issue we add a chainwork quantity [0x01,0001,0001].

Because the block chain grows, the issue will improve (or generally barely lower) little by little.

Earlier than the primary time of issue modified, the chain block peak had reached 32255.

$ bitcoin-cli getblockhash 32255
00000000984f962134a7291e3693075ae03e521f0ee33378ec30a334d860034b

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

As you may see above, the chainwork worth is [0x7e00,0x7e00,0x7e00], which is strictly the peak[32255]+1(for the genesis block) instances [0x01,0001,0001].

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

Then let’s check out block 32256:

$ bitcoin-cli getblockhash 32256
000000004f2886a170adb7204cb0c7a824217dd24d11a74423d564c4e0904967

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

At block 32256, as a result of the issue improve 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]

LEAVE A REPLY

Please enter your comment!
Please enter your name here