add headers init via checkpoints.json

This commit is contained in:
zebra-lucky 2018-06-09 00:30:43 +03:00
parent d06e6aa67e
commit e196cc205b
4 changed files with 14043 additions and 6 deletions

View File

@ -310,7 +310,10 @@ class Blockchain(util.PrintError):
elif height < len_checkpoints * CHUNK_LEN - POW_AVERAGING_WINDOW:
assert (height+1) % CHUNK_LEN == 0, height
index = height // CHUNK_LEN
h, t = self.checkpoints[index]
if index < len_checkpoints - 1:
h, t = self.checkpoints[index]
else:
h, t, extra_headers = self.checkpoints[index]
return h
else:
return hash_header(self.read_header(height))

14032
lib/checkpoints.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -46,7 +46,7 @@ class BitcoinMainnet:
GENESIS = "00040fe8ec8471911baa1db1266ea15dd06b4a8a5c453883c000b031973dce08"
DEFAULT_PORTS = {'t': '50021', 's': '50022'}
DEFAULT_SERVERS = read_json('servers.json', {})
CHECKPOINTS = []
CHECKPOINTS = read_json('checkpoints.json', [])
XPRV_HEADERS = {
'standard': 0x0488ade4, # xprv
@ -67,7 +67,7 @@ class BitcoinTestnet:
GENESIS = "05a60a92d99d85997cce3b87616c089f6124d7342af37106edc76126334a2c38"
DEFAULT_PORTS = {'t': '51021', 's': '51022'}
DEFAULT_SERVERS = read_json('servers_testnet.json', {})
CHECKPOINTS = []
CHECKPOINTS = read_json('checkpoints_testnet.json', [])
XPRV_HEADERS = {
'standard': 0x04358394, # tprv

View File

@ -987,9 +987,11 @@ class Network(util.DaemonThread):
length = HDR_LEN * len(constants.net.CHECKPOINTS) * CHUNK_LEN
if not os.path.exists(filename) or os.path.getsize(filename) < length:
with open(filename, 'wb') as f:
if length>0:
f.seek(length-1)
f.write(b'\x00')
if length > 0:
for height, hd in b.checkpoints[-1][2]:
f.seek(height*80)
bd = bfh(hd)
f.write(bd)
with b.lock:
b.update_size()