Skip to content

Commit

Permalink
fixed blockchain bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xilanma committed Dec 11, 2014
1 parent c3bf539 commit a61dcf6
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lib/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import pprint
pp = pprint.PrettyPrinter(indent=4)

max_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
#max_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
max_target = 0x00000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

# https://github.com/dogecoin/dogecoin/blob/65228644e10328172e9fa3ebe64251983e1153b3/src/core.h#L39
auxpow_start = 371337
Expand Down Expand Up @@ -235,6 +236,9 @@ def verify_chunk(self, index, hexdata):
assert int('0x'+_hash,16) < target
except Exception as e:
print 'block ', height, ' failed validation'
print previous_hash, '==', header.get('prev_block_hash')
print hex(bits), '==', hex(header.get('bits'))
print int('0x'+_hash,16), '<', target
raise e

if height % 240 == 0:
Expand Down Expand Up @@ -385,11 +389,11 @@ def get_target(self, height, chain=None):
if chain is None:
chain = [] # Do not use mutables as default values!

max_target = 0x00000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
if height < 240: return 0x1e0ffff0, 0x00000FFFF0000000000000000000000000000000000000000000000000000000

nTargetTimespan = 4*60*60 #dogecoin: every 4 hours
nTargetTimespanNEW = 60 #dogecoin: every 1 minute

nTargetSpacing = 60 #dogecoin: 1 minute
nInterval = nTargetTimespan / nTargetSpacing #240

Expand All @@ -407,12 +411,7 @@ def get_target(self, height, chain=None):
latest_retarget_height = (height / retargetInterval) * retargetInterval
#print 'latest_retarget_height', latest_retarget_height
last_height = latest_retarget_height - 1
first_height = latest_retarget_height - blockstogoback - 1

#if (height == 145002):
#1b6558a4
#first_height = 144999
#last_height = 145001
first_height = last_height - blockstogoback

#print 'first height', first_height
#print 'last height', last_height
Expand All @@ -434,10 +433,12 @@ def get_target(self, height, chain=None):
nModulatedTimespan = nActualTimespan

#print 'nActualTimespan', nActualTimespan
#print 'nTargetTimespan', nTargetTimespan
#print 'retargetTimespan', retargetTimespan

if height <= 5000:
nModulatedTimespan = max(nModulatedTimespan, cdiv(nTargetTimespan, 16))
nModulatedTimespan = min(nModulatedTimespan, nTargetTimespan * 4)
nModulatedTimespan = min(nModulatedTimespan, nTargetTimespan*4)
elif height <= 10000:
nModulatedTimespan = max(nModulatedTimespan, cdiv(nTargetTimespan, 8))
nModulatedTimespan = min(nModulatedTimespan, nTargetTimespan*4)
Expand All @@ -447,12 +448,6 @@ def get_target(self, height, chain=None):
# digishield
# https://github.com/dogecoin/dogecoin/blob/master/src/main.cpp#L1354
else:
#if (nModulatedTimespan < (retargetTimespan - (retargetTimespan/4)) )
#nModulatedTimespan = (retargetTimespan - (retargetTimespan/4));
#if (nModulatedTimespan > (retargetTimespan + (retargetTimespan/2)) )
#nModulatedTimespan = (retargetTimespan + (retargetTimespan/2));
#print retargetTimespan
# 60 + (48 - 60)/8
nModulatedTimespan = retargetTimespan + cdiv(nModulatedTimespan - retargetTimespan, 8)
nModulatedTimespan = max(nModulatedTimespan, retargetTimespan - cdiv(retargetTimespan, 4))
nModulatedTimespan = min(nModulatedTimespan, retargetTimespan + cdiv(retargetTimespan, 2))
Expand Down

0 comments on commit a61dcf6

Please sign in to comment.