Skip to content

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Nov 12, 2021

Solving a block involves continously rehashing it,

def solve(self):
self.rehash()
target = uint256_from_compact(self.nBits)
while self.sha256 > target:
self.nNonce += 1
self.rehash()

i.e. any extra rehash calls before are not necessary and can be dropped.

The instances were identified by searching for all block solving calls via git grep "solve(" in ./test/functional/. From 95 instances of CBlock.solve() calls, 20 contained an unnecessary rehashing instruction before that are removed in this PR.

Solving a block involves continously rehashing it, i.e. any extra
calls to rehash it before are not necessary and can be dropped.
@DrahtBot DrahtBot added the Tests label Nov 12, 2021
Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK a9872e1

Ran the modified tests successfully.

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23127 (tests: Use test framework utils where possible by vincenzopalazzo)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK a9872e1

Checked there's no more rehashing before solve.

@fanquake fanquake merged commit ffcb437 into bitcoin:master Nov 15, 2021
@theStack theStack deleted the 202111-test-remove_superflous_block_rehashs_before_solving branch November 15, 2021 11:42
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 15, 2021
…o solving

a9872e1 test: remove unnecessary block rehashing prior to solving (Sebastian Falbesoner)

Pull request description:

  Solving a block involves continously rehashing it,

  https://github.com/bitcoin/bitcoin/blob/c9dd5c8d6e59e27af98e99d2844d6ead8eec3162/test/functional/test_framework/messages.py#L759-L764

  i.e. any extra `rehash` calls before are not necessary and can be dropped.

  The instances were identified by searching for all block solving calls via `git grep "solve("` in `./test/functional/`. From 95 instances of `CBlock.solve()` calls, 20 contained an unnecessary rehashing instruction before that are removed in this PR.

ACKs for top commit:
  brunoerg:
    tACK a9872e1
  rajarshimaitra:
    tACK bitcoin@a9872e1

Tree-SHA512: 160092be717d0d250778b8ab091ebd77cc6865d2754ef150cf3b4d4ac7304d4bf3d2ebb61ec6b04a55040c8895b9fb4d28653ea4b099d56d90776c9111cf173f
@bitcoin bitcoin locked and limited conversation to collaborators Nov 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants