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

Add `timestamp` to `Block`s

parent ab1245c8
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,10 @@ def getBlockByHeight(height):
blockHeader = headers[height]
_hash = int(blockHeader['hash'], 16)
bits = bits_to_target(int(blockHeader['bits'], 16))
block = Block(height, bits, _hash)
# How is `mediantime` computed and is it only increasing?
# Note that `time` isn't only increasing. Cf https://en.bitcoin.it/wiki/Block_timestamp
timestamp = int(blockHeader['time'])
block = Block(height, bits, _hash, timestamp)
return block
def cli(arguments):
......
......@@ -7,13 +7,14 @@ MINING_IN_LOGARITHMIC_SPACE_CONSTANT_DIFFICULTY_LEVEL = False
class Block:
# `target` and `_hash` are `int`s.
def __init__(self, height, target, _hash):
def __init__(self, height, target, _hash, timestamp):
self.height = height
self.target = target
# As penultimate and most minimal difference targets differ only up to the third decimal.
self.score = round(genesisTarget / target, 4) if IS_EPSILON_TARGET_DEFINITION else genesisTarget - target
self.level_min = 0
self.level = level(_hash, target)
self.timestamp = timestamp
def __hash__(self):
return hash((self.height, self.target, self.score, self.level_min, self.level))
......
......@@ -9,7 +9,7 @@ import config
# Bitcoin parameters
κ = 256
KEEPING_ALL_BLOCKS_SINCE_LAST_M_HIGHER_BLOCK = True
KEEPING_ALL_BLOCKS_SINCE_LAST_M_HIGHER_BLOCK = False
# Minimal target difference
sanityTargetDifferenceThreshold = 0.03408116026637664
......@@ -160,6 +160,7 @@ lvls = {}
targets = []
compressSize = []
compressScore = []
timestamps = []
previous_score = 0
previous_ℓ = 0
......@@ -176,6 +177,7 @@ for height in range(headersNumber):
targets += [b.target]
compressSize += [len(Π)]
compressScore += [previous_score]
timestamps += [b.timestamp]
#printTimeSinceLastTimeCheck('block retrieval')
isLastIteration = height == headersNumber - 1
......@@ -210,7 +212,8 @@ for height in range(headersNumber):
data = {
'targets': targets,
'compressSize': compressSize,
'compressScore': compressScore
'compressScore': compressScore,
'timestamps': timestamps
}
with open('data.json', 'w') as f:
......
......@@ -104,6 +104,7 @@ lvls = {}
targets = []
compressSize = []
compressScore = []
timestamps = []
previous_score = 0
previous_ℓ = 0
......@@ -117,6 +118,7 @@ for height in range(headersNumber):
targets += [b.target]
compressSize += [len(Π)]
compressScore += [previous_score]
timestamps += [b.timestamp]
#printTimeSinceLastTimeCheck('block retrieval')
isLastIteration = height == headersNumber - 1
......@@ -151,7 +153,8 @@ for height in range(headersNumber):
data = {
'targets': targets,
'compressSize': compressSize,
'compressScore': compressScore
'compressScore': compressScore,
'timestamps': timestamps
}
with open('data.json', 'w') as f:
......
......@@ -16,8 +16,9 @@ with open('data_keeping_all_blocks_since_last_m_higher_block.json') as f:
fig, targetsAxis = plt.subplots()
fig.subplots_adjust(right = 0.8)
fig.subplots_adjust(bottom = 0.4)
compressedSizeAxis = targetsAxis.twinx()
compressedScoreAxis = targetsAxis.twinx()
axes = [targetsAxis, targetsAxis.twinx(), compressedScoreAxis, targetsAxis.twinx(), compressedScoreAxis, targetsAxis.twinx(), compressedScoreAxis]
axes = [targetsAxis, compressedSizeAxis, compressedScoreAxis, targetsAxis.twinx(), compressedScoreAxis, compressedSizeAxis, compressedScoreAxis]
targets = data['targets']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment