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

Correcting `KEEPING_ALL_BLOCKS_SINCE_LAST_M_HIGHER_BLOCK`

parent b5833c06
No related branches found
No related tags found
No related merge requests found
......@@ -53,13 +53,13 @@ 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] * κ
# Could maybe merge both cases if doesn't unoptimize much.
if KEEPING_ALL_BLOCKS_SINCE_LAST_M_HIGHER_BLOCK:
# Could maybe optimize by only keeping last `m` blocks height per level but due to Python list implementation I have doubts.
# Could maybe get rid of `blocksPerLevel` but only use `blocksHeightPerLevel` if don't apply just above optimization.
# Don't have to first fill data structures and only then check if can remove a block? It seems necessary, for instance if have in this order: 2 * m blocks at level 0, then 2 * m blocks at level 1 (even if this particular case is very unlikely), it won't return the index of the first block at level 0, as have to first ingest half of level 1 blocks and then the considered block height is higher than this middle level 1 block. While it should return the index of the first block at level 0.
blocksHeightPerLevel = [[]] * κ
for CIndex, block in enumerate(C):
for level in range(block.level_min, min(block.level, ) + 1):
......@@ -67,11 +67,13 @@ def getFirstBlockExceedingBlocksPerLevel(C, maximumBlocksPerLevel, ℓ):
blocksHeightPerLevel[level] += [C[CIndex].height]
if firstBlockIndexPerLevel[level] == None:
firstBlockIndexPerLevel[level] = CIndex
for level in range():
firstBlockLevelIndex = firstBlockIndexPerLevel[level]
if blocksPerLevel[level] > maximumBlocksPerLevel and blocksPerLevel[level + 1] >= m and C[firstBlockLevelIndex].height < blocksHeightPerLevel[level + 1][-m]:
return firstBlockLevelIndex, level
return None, None
else:
-= 1
for CIndex, block in enumerate(C):
for level in range(block.level_min, min(block.level, ) + 1):
blocksPerLevel[level] += 1
......@@ -164,6 +166,9 @@ previous_ℓ = 0
Π = []
headersNumber = bitcoin.loadHeaders(args.break_at)
for height in range(headersNumber):
#if height >= 428088:
# debugging = True
# verifyCorrectness = True
lastTimeCheck = time.time()
b = bitcoin.getBlockByHeight(height)
......
......@@ -10,11 +10,14 @@ with open('data.json') as f:
with open('data_constant_difficulty.json') as f:
dataConstantDifficulty = json.load(f)
with open('data_keeping_all_blocks_since_last_m_higher_block.json') as f:
dataKeepingAllBlocksSinceLastMHigherBlock = json.load(f)
fig, targetsAxis = plt.subplots()
fig.subplots_adjust(right = 0.8)
fig.subplots_adjust(bottom = 0.4)
compressedScoreAxis = targetsAxis.twinx()
axes = [targetsAxis, targetsAxis.twinx(), compressedScoreAxis, targetsAxis.twinx(), compressedScoreAxis]
axes = [targetsAxis, targetsAxis.twinx(), compressedScoreAxis, targetsAxis.twinx(), compressedScoreAxis, targetsAxis.twinx(), compressedScoreAxis]
targets = data['targets']
......@@ -32,9 +35,9 @@ for x, (target, nextTarget) in enumerate(zip(targets, targets[1:])):
if nextTarget > target:
targetIncreaseCurve = plt.axvline(x = x, alpha = 0.5, color = 'red', label = 'target increase')
axesColors = ['blue', 'green', 'brown', 'orange', 'brown']
axesLabels = ['targets', 'compressed blockchain size (in blocks)', 'compressed blockchain score', 'constant difficulty compressed blockchain size (in blocks)', 'constant difficulty compressed blockchain score']
axesYValues = [targets, data['compressSize'], data['compressScore'], dataConstantDifficulty['compressSize'], dataConstantDifficulty['compressScore']]
axesColors = ['blue', 'green', 'brown', 'orange', 'brown', 'red', 'purple']
axesLabels = ['targets', 'compressed blockchain size (in blocks)', 'compressed blockchain score', 'constant difficulty compressed blockchain size (in blocks)', 'constant difficulty compressed blockchain score', 'compressed blockchain size keeping all blocks since last m higher block (in blocks)', 'compressed blockchain score keeping all blocks since last m higher block']
axesYValues = [targets, data['compressSize'], data['compressScore'], dataConstantDifficulty['compressSize'], dataConstantDifficulty['compressScore'], dataKeepingAllBlocksSinceLastMHigherBlock['compressSize'], dataKeepingAllBlocksSinceLastMHigherBlock['compressScore']]
curves = []
for curvesIndex, (axis, color, label, yValues) in enumerate(zip(axes, axesColors, axesLabels, axesYValues)):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment