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

First Mining in logarithmic Space with constant difficulty try

parent ba8eeb39
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
MINING_IN_LOGARITHMIC_SPACE_CONSTANT_DIFFICULTY_LEVEL = True
class Block:
# `target` and `_hash` are `int`s.
......@@ -31,5 +32,5 @@ class Block:
def level(_hash, target):
ratio = _hash / target
ratio = _hash / (genesisTarget if MINING_IN_LOGARITHMIC_SPACE_CONSTANT_DIFFICULTY_LEVEL else target)
return math.floor(-math.log2(ratio))
\ No newline at end of file
from bcolors import bcolors
import time
import bitcoin
from block import IS_EPSILON_TARGET_DEFINITION
import json
from argparser import get_parser
import config
......@@ -9,36 +8,23 @@ import config
# Bitcoin parameters
κ = 256
# Minimal target difference
sanityTargetDifferenceThreshold = 0.03408116026637664
def Dissolve(m, k, C, previous_score, previous_ℓ):
CStar = C[:-k]
D = {}
if len(CStar) >= 2 * m:
= getℓ(CStar, previous_ℓ)
while True:
# Could make a single function iterating on `CStar` filling a dict with keys being levels and values being the number of blocks of the associated level and stop once a level value as reached a given number of blocks.
CIndex, μ = getFirstBlockExceedingBlocksPerLevel(CStar, 2 * m, )
if CIndex == None:
break
removed, blockRemoved = llbracket(CStar, μ, CIndex)
isScoreIncreasing = score(CStar, ) + sanityTargetDifferenceThreshold >= previous_score
if not isScoreIncreasing:
if removed:
CStar.insert(CIndex, blockRemoved)
else:
CStar[CIndex].level_min -= 1
break
for μ in range( + 1):
D[μ] = uparrow(CStar, μ)
D[] = uparrow(CStar, )
for μ in range( - 1, -1, -1):
# Could optimize by recycling previous computed `CStarμ`
b = uparrow(CStar, μ + 1)[-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)
else:
= 0
D[0] = CStar
CStarScore = score(CStar, )
if (IS_EPSILON_TARGET_DEFINITION and (previous_score - CStarScore) >= sanityTargetDifferenceThreshold) or (not IS_EPSILON_TARGET_DEFINITION and CStarScore < previous_score):
print(f'score decreasing! previous: {previous_score}, newest: {CStarScore}')
exit(2)
χ = C[-k:]
return (D, , χ, CStarScore)
......@@ -76,20 +62,6 @@ def getℓ(C, previous_ℓ):
if blocksPerLevel[level] < 2 * m:
return level - 1
def llbracket(C, μ, CIndex, actually = False):
removed = False
block = C[CIndex]
if block.level == μ:
if actually:
debug('removing', block.height)
del C[CIndex]
removed = True
else:
if actually:
debug(f'increasing {block.height} level_min from {block.level_min} to {μ + 1}')
block.level_min += 1
return removed, block
def score(C, ):
return sum([(min(block.level, ) + 1 - block.level_min) * block.score for block in C])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment