From e650574438fae410b8513c9210037f6a41d06986 Mon Sep 17 00:00:00 2001 From: Calin Culianu Date: Tue, 25 Aug 2020 01:37:25 +0300 Subject: [PATCH 1/2] Add testnet4 Added support for the new experimental testnet4 chain. Start Electron Cash wih --testnet4 to use. TODO: Add a servers_testnet4.json whenever we get more permanent Fulcrum or ElectrumX servers supporting this chain. --- electron-cash | 7 +++++++ lib/blockchain.py | 18 +++++++++++------- lib/commands.py | 1 + lib/networks.py | 27 +++++++++++++++++++++++++++ lib/simple_config.py | 5 ++++- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/electron-cash b/electron-cash index 34743b9caa52..456f6b0e7068 100755 --- a/electron-cash +++ b/electron-cash @@ -384,7 +384,14 @@ if __name__ == '__main__': set_verbosity(config_options.get('verbose')) + have_testnet4 = False + if config_options.get('testnet4'): + networks.set_testnet4() + have_testnet4 = True + if config_options.get('testnet'): + if have_testnet4: + sys.exit("Cannot specify both --testnet and --testnet4") networks.set_testnet() # check uri diff --git a/lib/blockchain.py b/lib/blockchain.py index 8098c20ed118..8980f47f5d38 100644 --- a/lib/blockchain.py +++ b/lib/blockchain.py @@ -491,7 +491,7 @@ def get_bits(self, header, chunk=None): # Mon Nov 13 19:06:40 2017 DAA HF - if daa_mtp >= 1510600000: + if prevheight >= networks.net.CW144_HEIGHT: if networks.net.TESTNET: # testnet 20 minute rule @@ -527,15 +527,18 @@ def get_bits(self, header, chunk=None): return daa_retval #END OF NOV-2017 DAA - - if height % 2016 == 0: + N_BLOCKS = networks.net.LEGACY_POW_RETARGET_BLOCKS # Normally 2016 + if height % N_BLOCKS == 0: return self.get_new_bits(height, chunk) if networks.net.TESTNET: # testnet 20 minute rule if header['timestamp'] - prior['timestamp'] > 20*60: return MAX_BITS - return self.read_header(height // 2016 * 2016, chunk)['bits'] + # special case for a newly started testnet (such as testnet4) + if height < N_BLOCKS: + return MAX_BITS + return self.read_header(height // N_BLOCKS * N_BLOCKS, chunk)['bits'] # bitcoin cash EDA # Can't go below minimum, so early bail @@ -553,15 +556,16 @@ def get_bits(self, header, chunk=None): return target_to_bits(target) def get_new_bits(self, height, chunk=None): - assert height % 2016 == 0 + N_BLOCKS = networks.net.LEGACY_POW_RETARGET_BLOCKS + assert height % N_BLOCKS == 0 # Genesis if height == 0: return MAX_BITS - first = self.read_header(height - 2016, chunk) + first = self.read_header(height - N_BLOCKS, chunk) prior = self.read_header(height - 1, chunk) prior_target = bits_to_target(prior['bits']) - target_span = 14 * 24 * 60 * 60 + target_span = networks.net.LEGACY_POW_TARGET_TIMESPAN # usually: 14 * 24 * 60 * 60 = 2 weeks span = prior['timestamp'] - first['timestamp'] span = min(max(span, target_span // 4), target_span * 4) new_target = (prior_target * span) // target_span diff --git a/lib/commands.py b/lib/commands.py index 8e66bb93d39e..fbe01d07843d 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -985,6 +985,7 @@ def add_global_options(parser): group.add_argument("-w", "--wallet", dest="wallet_path", help="wallet path") group.add_argument("-wp", "--walletpassword", dest="wallet_password", default=None, help="Supply wallet password") group.add_argument("--testnet", action="store_true", dest="testnet", default=False, help="Use Testnet") + group.add_argument("--testnet4", action="store_true", dest="testnet4", default=False, help="Use Testnet4") def get_parser(): # create main parser diff --git a/lib/networks.py b/lib/networks.py index e600341a2141..597771e89b8e 100644 --- a/lib/networks.py +++ b/lib/networks.py @@ -37,6 +37,9 @@ def _read_json_dict(filename): class AbstractNet: TESTNET = False asert_daa = ASERTDaa() + LEGACY_POW_TARGET_TIMESPAN = 14 * 24 * 60 * 60 # 2 weeks + LEGACY_POW_TARGET_INTERVAL = 10 * 60 # 10 minutes + LEGACY_POW_RETARGET_BLOCKS = LEGACY_POW_TARGET_TIMESPAN // LEGACY_POW_TARGET_INTERVAL # 2016 blocks class MainNet(AbstractNet): @@ -57,6 +60,9 @@ class MainNet(AbstractNet): BITCOIN_CASH_FORK_BLOCK_HEIGHT = 478559 BITCOIN_CASH_FORK_BLOCK_HASH = "000000000000000000651ef99cb9fcbe0dadde1d424bd9f15ff20136191a5eec" + # Nov 13. 2017 HF to CW144 DAA height (height of last block mined on old DAA) + CW144_HEIGHT = 504031 + # Note: this is not the Merkle root of the verification block itself , but a Merkle root of # all blockchain headers up until and including this block. To get this value you need to # connect to an ElectrumX server you trust and issue it a protocol command. This can be @@ -94,6 +100,9 @@ class TestNet(AbstractNet): DEFAULT_SERVERS = _read_json_dict('servers_testnet.json') # DO NOT MODIFY IN CLIENT CODE TITLE = 'Electron Cash Testnet' + # Nov 13. 2017 HF to CW144 DAA height (height of last block mined on old DAA) + CW144_HEIGHT = 1155875 + # Bitcoin Cash fork block specification BITCOIN_CASH_FORK_BLOCK_HEIGHT = 1155876 BITCOIN_CASH_FORK_BLOCK_HASH = "00000000000e38fef93ed9582a7df43815d5c2ba9fd37ef70c9a0ea4a285b8f5" @@ -112,6 +121,20 @@ class TestNet(AbstractNet): } +class TestNet4(TestNet): + GENESIS = "000000001dd410c49a788668ce26751718cc797474d3152a5fc073dd44fd9f7b" + TITLE = 'Electron Cash Testnet4' + + VERIFICATION_BLOCK_MERKLE_ROOT = "cfb7f86cf574ffc765f1531c9474c4aa74573c8acf085ab239a366570ad57f9d" + VERIFICATION_BLOCK_HEIGHT = 2016 + + BITCOIN_CASH_FORK_BLOCK_HEIGHT = 6 + BITCOIN_CASH_FORK_BLOCK_HASH = "00000000d71b9b1f7e13b0c9b218a12df6526c1bcd1b667764b8693ae9a413cb" + + # Nov 13. 2017 HF to CW144 DAA height (height of last block mined on old DAA) + CW144_HEIGHT = 3000 + + # All new code should access this to get the current network config. net = MainNet @@ -123,6 +146,10 @@ def set_testnet(): global net net = TestNet +def set_testnet4(): + global net + net = TestNet4 + # Compatibility def _instancer(cls): diff --git a/lib/simple_config.py b/lib/simple_config.py index 7fc1ac805206..1997a0299d6c 100644 --- a/lib/simple_config.py +++ b/lib/simple_config.py @@ -93,7 +93,10 @@ def electrum_path(self): path = self.user_dir() make_dir(path) - if self.get('testnet'): + if self.get('testnet4'): + path = os.path.join(path, 'testnet4') + make_dir(path) + elif self.get('testnet'): path = os.path.join(path, 'testnet') make_dir(path) From 14e944db1f49f6c9795f2ed9f4d37b861d62ce5a Mon Sep 17 00:00:00 2001 From: Calin Culianu Date: Tue, 25 Aug 2020 14:12:12 +0300 Subject: [PATCH 2/2] Testnet4: Added servers_testnet4.json Currently only 1 server is in this file (blackie.c3-soft.com Fulcrum testnet 4 server), but it serves as a decent starting point. --- contrib/build-wine/deterministic.spec | 1 + contrib/osx/osx.spec | 1 + lib/networks.py | 2 ++ lib/servers_testnet4.json | 7 +++++++ setup.py | 1 + 5 files changed, 12 insertions(+) create mode 100644 lib/servers_testnet4.json diff --git a/contrib/build-wine/deterministic.spec b/contrib/build-wine/deterministic.spec index ab6279778dfc..2c67d25bd0fe 100644 --- a/contrib/build-wine/deterministic.spec +++ b/contrib/build-wine/deterministic.spec @@ -52,6 +52,7 @@ datas = [ (home+'lib/currencies.json', 'electroncash'), (home+'lib/servers.json', 'electroncash'), (home+'lib/servers_testnet.json', 'electroncash'), + (home+'lib/servers_testnet4.json', 'electroncash'), (home+'lib/wordlist/english.txt', 'electroncash/wordlist'), (home+'lib/locale', 'electroncash/locale'), (home+'gui/qt/data/ecsupplemental_win.ttf', 'electroncash_gui/qt/data'), diff --git a/contrib/osx/osx.spec b/contrib/osx/osx.spec index d26e1e5eb6a9..ce1b39ebc69d 100644 --- a/contrib/osx/osx.spec +++ b/contrib/osx/osx.spec @@ -31,6 +31,7 @@ datas = [ (home+'lib/currencies.json', PYPKG), (home+'lib/servers.json', PYPKG), (home+'lib/servers_testnet.json', PYPKG), + (home+'lib/servers_testnet4.json', PYPKG), (home+'lib/wordlist/english.txt', PYPKG + '/wordlist'), (home+'lib/locale', PYPKG + '/locale'), (home+'plugins', PYPKG + '_plugins'), diff --git a/lib/networks.py b/lib/networks.py index 597771e89b8e..60e3f32797c4 100644 --- a/lib/networks.py +++ b/lib/networks.py @@ -125,6 +125,8 @@ class TestNet4(TestNet): GENESIS = "000000001dd410c49a788668ce26751718cc797474d3152a5fc073dd44fd9f7b" TITLE = 'Electron Cash Testnet4' + DEFAULT_SERVERS = _read_json_dict('servers_testnet4.json') # DO NOT MODIFY IN CLIENT CODE + VERIFICATION_BLOCK_MERKLE_ROOT = "cfb7f86cf574ffc765f1531c9474c4aa74573c8acf085ab239a366570ad57f9d" VERIFICATION_BLOCK_HEIGHT = 2016 diff --git a/lib/servers_testnet4.json b/lib/servers_testnet4.json new file mode 100644 index 000000000000..49f19b381af8 --- /dev/null +++ b/lib/servers_testnet4.json @@ -0,0 +1,7 @@ +{ + "blackie.c3-soft.com": { + "t": "62001", + "s": "62002" + } +} + diff --git a/setup.py b/setup.py index 5736bef8a07f..b545e698ef62 100755 --- a/setup.py +++ b/setup.py @@ -182,6 +182,7 @@ def run(self): 'electroncash': [ 'servers.json', 'servers_testnet.json', + 'servers_testnet4.json', 'currencies.json', 'www/index.html', 'wordlist/*.txt',