testnet setup

This commit is contained in:
nxsofsys 2018-01-18 22:10:02 +03:00
parent f596d6e105
commit 48dada5f64
3 changed files with 12 additions and 23 deletions

View File

@ -63,19 +63,6 @@ def deserialize_header(f, height):
h['block_height'] = height
return h
# def deserialize_header(f, height):
# h = {}
# h['version'] = struct.unpack("<I", f.read(4))[0]
# h['prev_block_hash'] = hash_to_str(f.read(32))
# h['merkle_root'] = hash_to_str(f.read(32))
# h['hash_reserved'] = hash_to_str(f.read(32))
# h['timestamp'] = struct.unpack("<I", f.read(4))[0]
# h['bits'] = struct.unpack("<I", f.read(4))[0]
# h['nonce'] = hash_to_str(f.read(32))
# h['n_solution'] = base64.b64encode(bytes(deser_char_vector(f))).decode('utf8')
# h['block_height'] = height
# return h
def sha256_header(header):
return uint256_from_bytes(Hash(serialize_header(header)))
@ -199,8 +186,8 @@ class Blockchain(util.PrintError):
prev_header = self.read_header(index * NetworkConstants.CHUNK_SIZE - 1)
for i in range(num):
raw_header = data[i*bitcoin.HEADER_SIZE:(i+1) * bitcoin.HEADER_SIZE]
header = deserialize_header(raw_header, index*NetworkConstants.CHUNK_SIZE + i)
raw_header = data[i * bitcoin.HEADER_SIZE : (i + 1) * bitcoin.HEADER_SIZE]
header = deserialize_header(raw_header, index * NetworkConstants.CHUNK_SIZE + i)
self.verify_header(header, prev_header)
prev_header = header

View File

@ -950,15 +950,18 @@ class Network(util.DaemonThread):
def init_headers_file(self):
b = self.blockchains[0]
filename = b.path()
open(filename, 'wb+').close()
self.downloading_headers = False
return
print(b.get_hash(0), NetworkConstants.GENESIS)
if b.get_hash(0) == NetworkConstants.GENESIS:
if NetworkConstants.TESTNET:
if not os.path.exists(filename) or b.get_hash(0) != NetworkConstants.GENESIS:
open(filename, 'wb+').close()
with b.lock: b.update_size()
self.downloading_headers = False
return
if b.get_hash(0) == NetworkConstants.GENESIS:
self.downloading_headers = False
return
def download_thread():
try:
import urllib, socket
@ -981,7 +984,6 @@ class Network(util.DaemonThread):
t.start()
def run(self):
print('zzzzzzzzzzzzzzzzzzzz')
self.init_headers_file()
while self.is_running() and self.downloading_headers:
time.sleep(1)

View File

@ -614,7 +614,7 @@ class SocketPipe:
if err.errno == 60:
raise timeout
elif err.errno in [11, 35, 10035]:
print_error("socket errno %d (resource temporarily unavailable)"% err.errno)
# print_error("socket errno %d (resource temporarily unavailable)"% err.errno)
time.sleep(0.2)
raise timeout
else: