Add 'chainwork' to getblock #2852

pull petertodd wants to merge 1 commits into bitcoin:master from petertodd:getblock-chainwork changing 1 files +1 −0
  1. petertodd commented at 6:12 AM on July 24, 2013: contributor

    Returns nChainWork from the block index, the total work done by all blocks since the genesis block.

    Worth exposing for pedagogical reasons at the very least.

    Anyone who tries to bikeshed either the name or the format the value is returned in will regret it - I'm warning you.

  2. Add 'chainwork' to getblock
    Returns nChainWork from the block index, the total work done by all
    blocks since the genesis block.
    1b3656d50b
  3. BitcoinPullTester commented at 7:05 AM on July 24, 2013: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/1b3656d50bda646822fd954714a88dea1528548b for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  4. sipa commented at 10:00 PM on August 15, 2013: member

    Given that the only work-related RPC output is already measured in difficulty, perhaps use the same unit?

    Another related and useful unit for transactions and blocks, is depth measured in "equivalent current blocks", namely the difference between chainwork of the tx/block under consideration and the chainwork of the tip, divided by the chainwork of the tip block.

  5. petertodd commented at 2:07 AM on August 16, 2013: contributor

    I used the raw hex value as the units for chainwork so that alt-implementations could use it as a way of double-checking their calculations - right now if you write your own chainwork calculating implementation there isn't a convenient way of ensuring your results match the reference implementation binary form exactly. Having said that other than verbosity I don't mind creating a "chainwork" and "chainworkhex" or something if people feel it is important, similar to how we have "bits" and "difficulty"

    re: "equivalent current blocks" Sounds reasonable for a subsequent pull-req, especially after headers first is merged.

  6. luke-jr commented at 6:27 AM on August 16, 2013: member

    The internal encoding of chainwork isn't relevant to implementations, just the relative measurement...

  7. petertodd commented at 8:00 AM on August 16, 2013: contributor

    @luke-jr You're not going to get consensus-level behavior unless you use the same arithmetic as Bitcoin, which uses bigints, so you have no choice but to export an integer; that's exactly what my implementation exports.

  8. luke-jr commented at 9:23 AM on August 16, 2013: member

    @petertodd You're exporting an integer as a hexified String, rather than a JSON Number, which I think is what @sipa was suggesting.

  9. petertodd commented at 9:56 AM on August 16, 2013: contributor

    @luke-jr Right, but the problem there is that JSON numbers are kinda-sorta double-precision floats - matching Javascript semantics - and support for bigints is pretty spotty in libraries.

    Also sipa was talking about making the number in "difficulty" units, with has a 2^32 factor, so you'd always wind up with floating point numbers. I haven't worked it out, but I wouldn't be surprised if double-precision floats aren't precise enough for consensus purposes.

  10. luke-jr commented at 10:02 AM on August 16, 2013: member

    Already some libraries have issues with bitcoind's output. I don't think trying to workaround bugs that might or might not exist in other software should be a concern...

  11. petertodd commented at 10:06 AM on August 16, 2013: contributor

    It's not a bug, it's just a limitation of JSON - bigints just aren't standard JSON. Bitcoin internally uses a uint256, so I'm not worried about exporting exactly that even if it's in hex. (like uint256 digests...) Anyway, as I said above:

    "Anyone who tries to bikeshed either the name or the format the value is returned in will regret it - I'm warning you."

    ...apparently I'm not threatening looking enough. Maybe I need a leather jacket and a motorcycle?

  12. luke-jr commented at 10:21 AM on August 16, 2013: member

    JSON doesn't place any precision limits on Numbers.

  13. sipa commented at 9:06 AM on August 17, 2013: member

    @petertodd Do you have an actual use case where the full-precision chainwork is useful?

  14. petertodd commented at 12:24 AM on August 18, 2013: contributor

    @sipa Testing alt-implementations. chainwork is nasty, because subtle arithmetic mistakes in calculating it that only affect low-order bits are easy to not notice if any rounding is done anywhere, yet still can cause an (unlikely) fork. In addition it lets us easily compare different bitcoin versions to make sure we ourselves don't introduce any subtle mistakes.

  15. sipa commented at 12:37 AM on August 18, 2013: member

    ACK

  16. jgarzik commented at 2:45 AM on August 25, 2013: contributor

    ACK

  17. jgarzik referenced this in commit 750ae29664 on Aug 25, 2013
  18. jgarzik merged this on Aug 25, 2013
  19. jgarzik closed this on Aug 25, 2013

  20. petertodd deleted the branch on Aug 25, 2013
  21. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-17 12:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me