Page MenuHomePhabricator

Backport current GetDifficulty logic (& tests) from Core
AcceptedPublic

Authored by markblundeberg on Fri, May 10, 04:27.

Details

Reviewers
jasonbcox
schancel
deadalnix
Group Reviewers
Restricted Project
Summary

Current GetDifficulty has a divergent history from core, time to patch
it up.

We missed a couple backports:
PR9612 https://github.com/bitcoin/bitcoin/pull/9612/files
PR10095 https://github.com/bitcoin/bitcoin/pull/10095/files

Then in D619, we simplified the logic of GetDifficulty in a nice way.

Core would later do the same:
PR13288 https://github.com/bitcoin/bitcoin/pull/13288/files
PR14135 https://github.com/bitcoin/bitcoin/pull/14135/files
But they had also added some tests in the meantime:
PR11748 https://github.com/bitcoin/bitcoin/pull/11748/files

This diff brings back basically into sync with core:

  • get tests
  • remove GetDifficultyFromBits function that isn't used elsewhere
  • and most importantly -- have less code ownership

It can't be simply done with revert-backport-backport-backport-backport so
I'm doing a snapshot update.

Depends on D3021

Test Plan

make check

Diff Detail

Repository
rABC Bitcoin ABC
Branch
backport-getdiff
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 5805
Build 9672: Bitcoin ABC Teamcity Staging
Build 9671: arc lint + arc unit

Event Timeline

markblundeberg created this revision.Fri, May 10, 04:27
Herald added a reviewer: Restricted Project. · View Herald TranscriptFri, May 10, 04:27
markblundeberg retitled this revision from Backport GetDifficulty logic from Core to Backport current GetDifficulty logic from Core.Fri, May 10, 04:27
markblundeberg planned changes to this revision.Fri, May 10, 05:00
markblundeberg retitled this revision from Backport current GetDifficulty logic from Core to Backport current GetDifficulty logic (& tests) from Core.
markblundeberg edited the summary of this revision. (Show Details)

rebase onto 10095 backport

markblundeberg edited the summary of this revision. (Show Details)Fri, May 10, 14:43
markblundeberg planned changes to this revision.Fri, May 10, 15:18
schancel accepted this revision.Sun, May 12, 02:29
schancel added inline comments.
src/rpc/blockchain.cpp
50

uint32_t nbits = blockindex->nBits; and leave the other two things alone.

src/rpc/blockchain.h
18

`Get the required difficulty of the next block w/r/t to the given block index.

This revision is now accepted and ready to land.Sun, May 12, 02:29
markblundeberg added inline comments.Sun, May 12, 04:55
src/rpc/blockchain.cpp
50

I agree but just want to get this backported for now.