mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-04 21:04:58 +02:00
test: remove bare CBlockHeader .rehash()/.calc_sha256() calls
Since the previous commit, CBlockHeader/CBlock object calls to the methods `.rehash()` and `.calc_sha256()` are effectively no-ops if the returned value is not used, so we can just remove them.
This commit is contained in:
@@ -111,7 +111,6 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl
|
||||
tx = tx_from_hex(tx)
|
||||
block.vtx.append(tx)
|
||||
block.hashMerkleRoot = block.calc_merkle_root()
|
||||
block.calc_sha256()
|
||||
return block
|
||||
|
||||
def get_witness_script(witness_root, witness_nonce):
|
||||
@@ -135,7 +134,6 @@ def add_witness_commitment(block, nonce=0):
|
||||
# witness commitment is the last OP_RETURN output in coinbase
|
||||
block.vtx[0].vout.append(CTxOut(0, get_witness_script(witness_root, witness_nonce)))
|
||||
block.hashMerkleRoot = block.calc_merkle_root()
|
||||
block.rehash()
|
||||
|
||||
|
||||
def script_BIP34_coinbase_height(height):
|
||||
|
||||
@@ -717,7 +717,6 @@ class CBlockHeader:
|
||||
self.nTime = header.nTime
|
||||
self.nBits = header.nBits
|
||||
self.nNonce = header.nNonce
|
||||
self.calc_sha256()
|
||||
|
||||
def set_null(self):
|
||||
self.nVersion = 4
|
||||
@@ -758,10 +757,6 @@ class CBlockHeader:
|
||||
"""Return block header hash as integer."""
|
||||
return uint256_from_str(hash256(self._serialize_header()))
|
||||
|
||||
# TODO: get rid of this method, remove call-sites
|
||||
def calc_sha256(self):
|
||||
pass
|
||||
|
||||
# TODO: get rid of this method, replace call-sites by .sha256 access (if return value is used)
|
||||
def rehash(self):
|
||||
return self.sha256
|
||||
@@ -823,7 +818,6 @@ class CBlock(CBlockHeader):
|
||||
return self.get_merkle_root(hashes)
|
||||
|
||||
def is_valid(self):
|
||||
self.calc_sha256()
|
||||
target = uint256_from_compact(self.nBits)
|
||||
if self.sha256 > target:
|
||||
return False
|
||||
@@ -835,11 +829,9 @@ class CBlock(CBlockHeader):
|
||||
return True
|
||||
|
||||
def solve(self):
|
||||
self.rehash()
|
||||
target = uint256_from_compact(self.nBits)
|
||||
while self.sha256 > target:
|
||||
self.nNonce += 1
|
||||
self.rehash()
|
||||
|
||||
# Calculate the block weight using witness and non-witness
|
||||
# serialization size (does NOT use sigops).
|
||||
|
||||
Reference in New Issue
Block a user