read checkpoints file in NetworkConstants, add it to setup.py
This commit is contained in:
parent
40e13224f7
commit
44a83c2401
|
@ -22,6 +22,7 @@ hiddenimports += collect_submodules('keepkeylib')
|
||||||
datas = [
|
datas = [
|
||||||
(home+'lib/currencies.json', 'electrum'),
|
(home+'lib/currencies.json', 'electrum'),
|
||||||
(home+'lib/servers.json', 'electrum'),
|
(home+'lib/servers.json', 'electrum'),
|
||||||
|
(home+'lib/checkpoints.json', 'electrum'),
|
||||||
(home+'lib/servers_testnet.json', 'electrum'),
|
(home+'lib/servers_testnet.json', 'electrum'),
|
||||||
(home+'lib/wordlist/english.txt', 'electrum/wordlist'),
|
(home+'lib/wordlist/english.txt', 'electrum/wordlist'),
|
||||||
(home+'lib/locale', 'electrum/locale'),
|
(home+'lib/locale', 'electrum/locale'),
|
||||||
|
|
|
@ -22,6 +22,7 @@ hiddenimports += collect_submodules('keepkeylib')
|
||||||
datas = [
|
datas = [
|
||||||
(home+'lib/currencies.json', 'electrum'),
|
(home+'lib/currencies.json', 'electrum'),
|
||||||
(home+'lib/servers.json', 'electrum'),
|
(home+'lib/servers.json', 'electrum'),
|
||||||
|
(home+'lib/checkpoints.json', 'electrum'),
|
||||||
(home+'lib/wordlist/english.txt', 'electrum/wordlist'),
|
(home+'lib/wordlist/english.txt', 'electrum/wordlist'),
|
||||||
(home+'lib/locale', 'electrum/locale'),
|
(home+'lib/locale', 'electrum/locale'),
|
||||||
(home+'plugins', 'electrum_plugins'),
|
(home+'plugins', 'electrum_plugins'),
|
||||||
|
|
|
@ -37,13 +37,13 @@ from . import version
|
||||||
from .util import print_error, InvalidPassword, assert_bytes, to_bytes, inv_dict
|
from .util import print_error, InvalidPassword, assert_bytes, to_bytes, inv_dict
|
||||||
from . import segwit_addr
|
from . import segwit_addr
|
||||||
|
|
||||||
def read_json_dict(filename):
|
def read_json(filename, default):
|
||||||
path = os.path.join(os.path.dirname(__file__), filename)
|
path = os.path.join(os.path.dirname(__file__), filename)
|
||||||
try:
|
try:
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
r = json.loads(f.read())
|
r = json.loads(f.read())
|
||||||
except:
|
except:
|
||||||
r = {}
|
r = default
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,10 +78,10 @@ class NetworkConstants:
|
||||||
cls.ADDRTYPE_P2PKH = 0
|
cls.ADDRTYPE_P2PKH = 0
|
||||||
cls.ADDRTYPE_P2SH = 5
|
cls.ADDRTYPE_P2SH = 5
|
||||||
cls.SEGWIT_HRP = "bc"
|
cls.SEGWIT_HRP = "bc"
|
||||||
cls.HEADERS_URL = "https://headers.electrum.org/blockchain_headers"
|
|
||||||
cls.GENESIS = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
|
cls.GENESIS = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
|
||||||
cls.DEFAULT_PORTS = {'t': '50001', 's': '50002'}
|
cls.DEFAULT_PORTS = {'t': '50001', 's': '50002'}
|
||||||
cls.DEFAULT_SERVERS = read_json_dict('servers.json')
|
cls.DEFAULT_SERVERS = read_json('servers.json', {})
|
||||||
|
cls.CHECKPOINTS = read_json('checkpoints.json', [])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_testnet(cls):
|
def set_testnet(cls):
|
||||||
|
@ -90,10 +90,10 @@ class NetworkConstants:
|
||||||
cls.ADDRTYPE_P2PKH = 111
|
cls.ADDRTYPE_P2PKH = 111
|
||||||
cls.ADDRTYPE_P2SH = 196
|
cls.ADDRTYPE_P2SH = 196
|
||||||
cls.SEGWIT_HRP = "tb"
|
cls.SEGWIT_HRP = "tb"
|
||||||
cls.HEADERS_URL = "https://headers.electrum.org/testnet_headers"
|
|
||||||
cls.GENESIS = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
|
cls.GENESIS = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
|
||||||
cls.DEFAULT_PORTS = {'t':'51001', 's':'51002'}
|
cls.DEFAULT_PORTS = {'t':'51001', 's':'51002'}
|
||||||
cls.DEFAULT_SERVERS = read_json_dict('servers_testnet.json')
|
cls.DEFAULT_SERVERS = read_json('servers_testnet.json', {})
|
||||||
|
cls.CHECKPOINTS = read_json('checkpoints_testnet.json', [])
|
||||||
|
|
||||||
|
|
||||||
NetworkConstants.set_mainnet()
|
NetworkConstants.set_mainnet()
|
||||||
|
|
|
@ -60,8 +60,8 @@ def hash_header(header):
|
||||||
|
|
||||||
blockchains = {}
|
blockchains = {}
|
||||||
|
|
||||||
def read_blockchains(config, checkpoints):
|
def read_blockchains(config):
|
||||||
blockchains[0] = Blockchain(config, checkpoints, 0, None)
|
blockchains[0] = Blockchain(config, 0, None)
|
||||||
fdir = os.path.join(util.get_headers_dir(config), 'forks')
|
fdir = os.path.join(util.get_headers_dir(config), 'forks')
|
||||||
if not os.path.exists(fdir):
|
if not os.path.exists(fdir):
|
||||||
os.mkdir(fdir)
|
os.mkdir(fdir)
|
||||||
|
@ -70,7 +70,7 @@ def read_blockchains(config, checkpoints):
|
||||||
for filename in l:
|
for filename in l:
|
||||||
checkpoint = int(filename.split('_')[2])
|
checkpoint = int(filename.split('_')[2])
|
||||||
parent_id = int(filename.split('_')[1])
|
parent_id = int(filename.split('_')[1])
|
||||||
b = Blockchain(config, checkpoints, checkpoint, parent_id)
|
b = Blockchain(config, checkpoint, parent_id)
|
||||||
blockchains[b.checkpoint] = b
|
blockchains[b.checkpoint] = b
|
||||||
return blockchains
|
return blockchains
|
||||||
|
|
||||||
|
@ -94,11 +94,11 @@ class Blockchain(util.PrintError):
|
||||||
Manages blockchain headers and their verification
|
Manages blockchain headers and their verification
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config, checkpoints, checkpoint, parent_id):
|
def __init__(self, config, checkpoint, parent_id):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.catch_up = None # interface catching up
|
self.catch_up = None # interface catching up
|
||||||
self.checkpoint = checkpoint
|
self.checkpoint = checkpoint
|
||||||
self.checkpoints = checkpoints
|
self.checkpoints = bitcoin.NetworkConstants.CHECKPOINTS
|
||||||
self.parent_id = parent_id
|
self.parent_id = parent_id
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
@ -128,7 +128,7 @@ class Blockchain(util.PrintError):
|
||||||
|
|
||||||
def fork(parent, header):
|
def fork(parent, header):
|
||||||
checkpoint = header.get('block_height')
|
checkpoint = header.get('block_height')
|
||||||
self = Blockchain(parent.config, parent.checkpoints, checkpoint, parent.checkpoint)
|
self = Blockchain(parent.config, checkpoint, parent.checkpoint)
|
||||||
open(self.path(), 'w+').close()
|
open(self.path(), 'w+').close()
|
||||||
self.save_header(header)
|
self.save_header(header)
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -165,8 +165,7 @@ class Network(util.DaemonThread):
|
||||||
util.DaemonThread.__init__(self)
|
util.DaemonThread.__init__(self)
|
||||||
self.config = SimpleConfig(config) if isinstance(config, dict) else config
|
self.config = SimpleConfig(config) if isinstance(config, dict) else config
|
||||||
self.num_server = 10 if not self.config.get('oneserver') else 0
|
self.num_server = 10 if not self.config.get('oneserver') else 0
|
||||||
self.read_checkpoints()
|
self.blockchains = blockchain.read_blockchains(self.config)
|
||||||
self.blockchains = blockchain.read_blockchains(self.config, self.checkpoints)
|
|
||||||
self.print_error("blockchains", self.blockchains.keys())
|
self.print_error("blockchains", self.blockchains.keys())
|
||||||
self.blockchain_index = config.get('blockchain_index', 0)
|
self.blockchain_index = config.get('blockchain_index', 0)
|
||||||
if self.blockchain_index not in self.blockchains.keys():
|
if self.blockchain_index not in self.blockchains.keys():
|
||||||
|
@ -951,7 +950,7 @@ class Network(util.DaemonThread):
|
||||||
b = self.blockchains[0]
|
b = self.blockchains[0]
|
||||||
filename = b.path()
|
filename = b.path()
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
length = 80 * len(self.checkpoints) * 2016
|
length = 80 * len(bitcoin.NetworkConstants.CHECKPOINTS) * 2016
|
||||||
with open(filename, 'wb') as f:
|
with open(filename, 'wb') as f:
|
||||||
if length>0:
|
if length>0:
|
||||||
f.seek(length-1)
|
f.seek(length-1)
|
||||||
|
@ -1065,22 +1064,11 @@ class Network(util.DaemonThread):
|
||||||
return False, "error: " + out
|
return False, "error: " + out
|
||||||
return True, out
|
return True, out
|
||||||
|
|
||||||
def checkpoints_path(self):
|
def export_checkpoints(self, path):
|
||||||
return os.path.join(os.path.dirname(__file__), 'checkpoints.json')
|
# run manually from the console to generate checkpoints
|
||||||
|
|
||||||
def export_checkpoints(self):
|
|
||||||
# for each chunk, store the hash of the last block and the target after the chunk
|
|
||||||
cp = self.blockchain().get_checkpoints()
|
cp = self.blockchain().get_checkpoints()
|
||||||
with open(self.checkpoints_path(), 'w') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(json.dumps(cp, indent=4))
|
f.write(json.dumps(cp, indent=4))
|
||||||
|
|
||||||
def read_checkpoints(self):
|
|
||||||
try:
|
|
||||||
with open(self.checkpoints_path(), 'r') as f:
|
|
||||||
self.checkpoints = json.loads(f.read())
|
|
||||||
self.print_error("Read %d checkpoints" % len(self.checkpoints))
|
|
||||||
except:
|
|
||||||
self.checkpoints = []
|
|
||||||
|
|
||||||
def max_checkpoint(self):
|
def max_checkpoint(self):
|
||||||
return max(0, len(self.checkpoints) * 2016 - 1)
|
return max(0, len(bitcoin.NetworkConstants.CHECKPOINTS) * 2016 - 1)
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -74,6 +74,7 @@ setup(
|
||||||
'servers.json',
|
'servers.json',
|
||||||
'servers_testnet.json',
|
'servers_testnet.json',
|
||||||
'currencies.json',
|
'currencies.json',
|
||||||
|
'checkpoints.json',
|
||||||
'www/index.html',
|
'www/index.html',
|
||||||
'wordlist/*.txt',
|
'wordlist/*.txt',
|
||||||
'locale/*/LC_MESSAGES/electrum.mo',
|
'locale/*/LC_MESSAGES/electrum.mo',
|
||||||
|
|
Loading…
Reference in New Issue