Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
racquemis committed Jan 14, 2018
1 parent d8a72f9 commit 57587b6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/blockchain.py
Expand Up @@ -168,8 +168,10 @@ def verify_header(self, header, prev_hash, target):
return
#bits = self.target_to_bits(target)
#if bits != header.get('bits'):
# print("test4")
# raise BaseException("bits mismatch: %s vs %s" % (bits, header.get('bits')))
#if int('0x' + _hash, 16) > target:
# print("test4")
# raise BaseException("insufficient proof of work: %s vs target %s" % (int('0x' + _hash, 16), target))

def verify_chunk(self, index, data):
Expand All @@ -193,7 +195,7 @@ def save_chunk(self, index, chunk):
if d < 0:
chunk = chunk[-d:]
d = 0
self.write(chunk, d)
self.write(chunk, d, index > len(self.checkpoints))
self.swap_with_parent()

def swap_with_parent(self):
Expand Down Expand Up @@ -230,11 +232,11 @@ def swap_with_parent(self):
blockchains[self.checkpoint] = self
blockchains[parent.checkpoint] = parent

def write(self, data, offset):
def write(self, data, offset, truncate = True):
filename = self.path()
with self.lock:
with open(filename, 'rb+') as f:
if offset != self._size*209:
if truncate and offset != self._size*209:
f.seek(offset)
f.truncate()
f.seek(offset)
Expand Down Expand Up @@ -277,7 +279,7 @@ def get_hash(self, height):
elif height == 0:
return bitcoin.NetworkConstants.GENESIS
elif height < len(self.checkpoints) * 960:
assert (height+1) % 960 == 0
assert (height+1) % 960 == 0, height
index = height // 960
h, t = self.checkpoints[index]
return h
Expand All @@ -287,9 +289,9 @@ def get_hash(self, height):
def get_target(self, index):
# compute target from chunk x, used in chunk x+1
if bitcoin.NetworkConstants.TESTNET:
return 0
return 0, 0
if index == -1:
return MAX_TARGET
return 0x207fffff, MAX_TARGET
if index < len(self.checkpoints):
h, t = self.checkpoints[index]
return t
Expand Down

0 comments on commit 57587b6

Please sign in to comment.