Skip to content
Snippets Groups Projects
Unverified Commit 5f09d42a authored by Benjamin Loison's avatar Benjamin Loison
Browse files

Don't compute multiple times same level `uparrow` in `Dissolve`

parent bd6658de
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ import math
# bits_to_target(int(headers[0]['bits'], 16))
genesisTarget = 26959535291011309493156476344723991336010898738574164086137773096960
IS_EPSILON_TARGET_DEFINITION = True
# Could be determined thanks to `sys.argv[0]` but I'm unsure what is our statement concerning running in an IDE such as Pyzo or if it would work fine on Windows (notably due to the possible `./` prefix).
MINING_IN_LOGARITHMIC_SPACE_CONSTANT_DIFFICULTY_LEVEL = True
class Block:
......
......@@ -14,13 +14,14 @@ def Dissolve(m, k, C, previous_score, previous_ℓ):
if len(CStar) >= 2 * m:
= getℓ(CStar, previous_ℓ)
D[] = uparrow(CStar, )
previousCStarμ = D[]
for μ in range( - 1, -1, -1):
# Could optimize by recycling previous computed `CStarμ`
b = uparrow(CStar, μ + 1)[-m]
b = previousCStarμ[-m]
CStarμ = uparrow(CStar, μ)
CStarμSinceb = [block for block in CStarμ if block.height >= b.height]
chains = {chainsIndex: chain for chainsIndex, chain in enumerate([CStarμ[-2 * m:], CStarμSinceb])}
D[μ] = U(0, 1, chains)
previousCStarμ = CStarμ
else:
= 0
D[0] = CStar
......@@ -36,19 +37,6 @@ def Compress(m, k, C, previous_score, previous_ℓ):
def uparrow(C, μ):
return [block for block in C if block.level >= μ and block.level_min <= μ]
def getFirstBlockExceedingBlocksPerLevel(C, maximumBlocksPerLevel, ):
-= 1
blocksPerLevel = [0] * κ
firstBlockIndexPerLevel = [None] * κ
for CIndex, block in enumerate(C):
for level in range(block.level_min, min(block.level, ) + 1):
blocksPerLevel[level] += 1
if firstBlockIndexPerLevel[level] == None:
firstBlockIndexPerLevel[level] = CIndex
if blocksPerLevel[level] > maximumBlocksPerLevel:
return firstBlockIndexPerLevel[level], level
return None, None
# Proceeding by dichotomy may not be worth it.
# For instance for the first 60 000 blocks, we have in theory 10 levels for the last blocks while log2(256) = 8, so because of first blocks not having a higher than 8 level, it doesn't seem worth it at the beginning at least.
def getℓ(C, previous_ℓ):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment