From 50eebd236e6e37eba1adc2c6cc6282b3434676cd Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Wed, 31 Jul 2019 22:50:01 +0700 Subject: [PATCH 01/18] Minor fixes and TODOs --- qa/rpc-tests/{src => }/nspv_client_test.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) rename qa/rpc-tests/{src => }/nspv_client_test.py (89%) diff --git a/qa/rpc-tests/src/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py similarity index 89% rename from qa/rpc-tests/src/nspv_client_test.py rename to qa/rpc-tests/nspv_client_test.py index fbf0e5360..aecff3696 100644 --- a/qa/rpc-tests/src/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -3,19 +3,22 @@ sys.path.append('../../src/tui') from lib import tuilib import unittest +import time ''' specify chain ticker (daemon should be up), wif which will be imported and address to which you want to broadcast added 1 second sleep after each case to surely not face the nSPV server limitation (1 call/second) ''' -wif = '' -dest_address = 'RMjy5VkHFJkXTJDTJ3XX1zVzukP48sKyva' +wif = 'UsJgUBrmcsthJEGbyBBfD77tZ1FuRMkB68jqkP8E3PEE88eXesEH' +dest_address = 'RNvAWip4DuFrZf8WhqdTBEcAg1bWjd4rKr' amount = '0.1' chain = 'ILN' rpc_proxy = tuilib.def_credentials(chain) +# TODO: recheck nspv_login_timeout, nspv_notarizations +# TODO: add brand new methods, add one-utxo-only addr for test purpose class TestNspvClient(unittest.TestCase): @@ -31,14 +34,14 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_notarizations("2000") self.assertEqual(result["result"], "success") self.assertEqual(result["prev"]["notarized_height"], 1998) - self.assertEqual(result["next"]["notarized_height"], 2002) + self.assertEqual(result["next"]["notarized_height"], 2008) # check suspicious behaviour time.sleep(1) def test_nspv_hdrsproof(self): print("testing nspv_hdrsproof") result = rpc_proxy.nspv_hdrsproof("2000", "2100") self.assertEqual(result["result"], "success") - self.assertEqual(result["numhdrs"], 101) + self.assertEqual(result["numhdrs"], 113) time.sleep(1) def test_nspv_login(self): @@ -54,7 +57,8 @@ class TestNspvClient(unittest.TestCase): self.assertEqual(result["result"], "success") time.sleep(1) result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") - self.assertEqual(result["result"], "error") + self.assertEqual(result["result"], "success") + self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") def test_nspv_spend(self): print("testing nspv_spend") From f878c9e05ecf77e2ddaf3b9539489096e5c62b78 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Wed, 31 Jul 2019 23:35:54 +0700 Subject: [PATCH 02/18] More fixes less TODOs --- qa/rpc-tests/nspv_client_test.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index aecff3696..aecc05fb7 100644 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -17,8 +17,7 @@ chain = 'ILN' rpc_proxy = tuilib.def_credentials(chain) -# TODO: recheck nspv_login_timeout, nspv_notarizations -# TODO: add brand new methods, add one-utxo-only addr for test purpose +# TODO: add brand new methods, add one-utxo-only addr for test purpose, recheck test once more at least class TestNspvClient(unittest.TestCase): @@ -107,7 +106,7 @@ class TestNspvClient(unittest.TestCase): def test_nspv_login_timout(self): print("testing auto-logout in 777 seconds") rpc_proxy.nspv_login(wif) - time.sleep(777) + time.sleep(778) result = rpc_proxy.nspv_spend(dest_address, amount) self.assertEqual(result["result"], "error") self.assertEqual(result["error"], "wif expired") From aa1539afd08cd82afff4f5f7e78a1321f8fc4fb7 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Thu, 1 Aug 2019 14:31:20 +0700 Subject: [PATCH 03/18] added nspv_listtransactions call test --- qa/rpc-tests/nspv_client_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index aecc05fb7..d5d1e4bba 100644 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -21,6 +21,17 @@ rpc_proxy = tuilib.def_credentials(chain) class TestNspvClient(unittest.TestCase): + def test_nspv_listtransactions(self): + print("testing nspv_listtransactions") + rpc_proxy.nspv_login(wif) + result = rpc_proxy.nspv_listtransactions() + self.assertEqual(result["result"], "success") + time.sleep(1) + result = rpc_proxy.nspv_listtransactions("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + self.assertEqual(result["result"], "success") + self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + rpc_proxy.nspv_logout() + def test_nspv_getinfo(self): print("testing nspv_getinfo") result = rpc_proxy.nspv_getinfo() @@ -36,6 +47,16 @@ class TestNspvClient(unittest.TestCase): self.assertEqual(result["next"]["notarized_height"], 2008) # check suspicious behaviour time.sleep(1) + def test_nspv_listtransactions(self): + print("testing nspv_listtransactions") + result = rpc_proxy.nspv_listtransactions() + self.assertEqual(result["result"], "success") + time.sleep(1) + result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + self.assertEqual(result["result"], "success") + self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + + def test_nspv_hdrsproof(self): print("testing nspv_hdrsproof") result = rpc_proxy.nspv_hdrsproof("2000", "2100") From 887d54fd813d6093060c3a1d30a1ffd171595a17 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Thu, 1 Aug 2019 16:13:30 +0700 Subject: [PATCH 04/18] cleanup and recheck --- qa/rpc-tests/nspv_client_test.py | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index d5d1e4bba..e247a45a2 100644 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -10,26 +10,36 @@ specify chain ticker (daemon should be up), wif which will be imported and addre added 1 second sleep after each case to surely not face the nSPV server limitation (1 call/second) ''' -wif = 'UsJgUBrmcsthJEGbyBBfD77tZ1FuRMkB68jqkP8E3PEE88eXesEH' -dest_address = 'RNvAWip4DuFrZf8WhqdTBEcAg1bWjd4rKr' +wif = '' +dest_address = '' amount = '0.1' chain = 'ILN' +if not wif or not dest_address: + raise Exception("Please set test wif and address to send transactions to.") + rpc_proxy = tuilib.def_credentials(chain) -# TODO: add brand new methods, add one-utxo-only addr for test purpose, recheck test once more at least class TestNspvClient(unittest.TestCase): + def test_nspv_mempool(self): + print("testing nspv_mempool") + result = rpc_proxy.nspv_mempool("0", dest_address, "0") + self.assertEqual(result["result"], "success") + self.assertEqual(result["address"], dest_address) + self.assertEqual(result["isCC"], 0) + time.sleep(1) + def test_nspv_listtransactions(self): print("testing nspv_listtransactions") rpc_proxy.nspv_login(wif) result = rpc_proxy.nspv_listtransactions() self.assertEqual(result["result"], "success") time.sleep(1) - result = rpc_proxy.nspv_listtransactions("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + result = rpc_proxy.nspv_listtransactions("RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + self.assertEqual(result["address"], "RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") rpc_proxy.nspv_logout() def test_nspv_getinfo(self): @@ -47,16 +57,6 @@ class TestNspvClient(unittest.TestCase): self.assertEqual(result["next"]["notarized_height"], 2008) # check suspicious behaviour time.sleep(1) - def test_nspv_listtransactions(self): - print("testing nspv_listtransactions") - result = rpc_proxy.nspv_listtransactions() - self.assertEqual(result["result"], "success") - time.sleep(1) - result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") - self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") - - def test_nspv_hdrsproof(self): print("testing nspv_hdrsproof") result = rpc_proxy.nspv_hdrsproof("2000", "2100") @@ -76,9 +76,9 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_listunspent() self.assertEqual(result["result"], "success") time.sleep(1) - result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + result = rpc_proxy.nspv_listunspent("RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + self.assertEqual(result["address"], "RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") def test_nspv_spend(self): print("testing nspv_spend") From ad6f142a92e20442a48505fb22c0d3bf0d995490 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Thu, 1 Aug 2019 16:34:50 +0700 Subject: [PATCH 05/18] final cleanup lowered coins amount --- qa/rpc-tests/nspv_client_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index e247a45a2..63b7f78d1 100644 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -12,11 +12,11 @@ added 1 second sleep after each case to surely not face the nSPV server limitati wif = '' dest_address = '' -amount = '0.1' +amount = '0.01' chain = 'ILN' if not wif or not dest_address: - raise Exception("Please set test wif and address to send transactions to.") + raise Exception("Please set test wif and address to send transactions to") rpc_proxy = tuilib.def_credentials(chain) @@ -54,7 +54,7 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_notarizations("2000") self.assertEqual(result["result"], "success") self.assertEqual(result["prev"]["notarized_height"], 1998) - self.assertEqual(result["next"]["notarized_height"], 2008) # check suspicious behaviour + self.assertEqual(result["next"]["notarized_height"], 2008) time.sleep(1) def test_nspv_hdrsproof(self): @@ -85,7 +85,7 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_login(wif) result = rpc_proxy.nspv_spend(dest_address, amount) self.assertEqual(result["result"], "success") - self.assertEqual(result["vout"][0]["valueZat"], 10000000) + self.assertEqual(result["vout"][0]["valueZat"], 1000000) time.sleep(1) def test_nspv_broadcast(self): From 7a4f8b3401a67e505eaa68fa74974b585a08e23e Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Fri, 2 Aug 2019 03:05:47 +0700 Subject: [PATCH 06/18] Prolonged Proxy timeout Added support for multiple test chains --- qa/rpc-tests/nspv_client_test.py | 81 ++++++++++++++++++++++---------- src/tui/lib/tuilib.py | 20 +++++++- 2 files changed, 75 insertions(+), 26 deletions(-) mode change 100644 => 100755 qa/rpc-tests/nspv_client_test.py diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py old mode 100644 new mode 100755 index 63b7f78d1..ddc1d8093 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -7,19 +7,48 @@ import time ''' specify chain ticker (daemon should be up), wif which will be imported and address to which you want to broadcast +change chain parameters if needed or add a new chain to test below added 1 second sleep after each case to surely not face the nSPV server limitation (1 call/second) ''' wif = '' dest_address = '' amount = '0.01' -chain = 'ILN' +chain = 'KMD' if not wif or not dest_address: raise Exception("Please set test wif and address to send transactions to") rpc_proxy = tuilib.def_credentials(chain) +chain_params = {"KMD": { + 'tx_list_address': 'RGShWG446Pv24CKzzxjA23obrzYwNbs1kA', + 'min_chain_height': 1468080, + 'notarization_height': '1468000', + 'prev_notarization_h': 1467980, + 'next_notarization_h': 1468020, + 'hdrs_proof_low': '1468100', + 'hdrs_proof_high': '1468200', + 'numhdrs_expected': 151, + 'tx_proof_id': 'f7beb36a65bc5bcbc9c8f398345aab7948160493955eb4a1f05da08c4ac3784f', + 'tx_spent_height': 1456212, + 'tx_proof_height': '1468520', + }, + "ILN": { + 'tx_list_address': 'RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu', + 'min_chain_height': 3689, + 'notarization_height': '2000', + 'prev_notarization_h': 1998, + 'next_notarization_h': 2008, + 'hdrs_proof_low': '2000', + 'hdrs_proof_high': '2100', + 'numhdrs_expected': 113, + 'tx_proof_id': '67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418', + 'tx_spent_height': 2681, + 'tx_proof_height': '2690', + } + } + class TestNspvClient(unittest.TestCase): @@ -37,31 +66,32 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_listtransactions() self.assertEqual(result["result"], "success") time.sleep(1) - result = rpc_proxy.nspv_listtransactions("RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") + result = rpc_proxy.nspv_listtransactions(chain_params.get(chain).get("tx_list_address")) self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") + self.assertEqual(result["address"], chain_params.get(chain).get("tx_list_address")) rpc_proxy.nspv_logout() def test_nspv_getinfo(self): print("testing nspv_getinfo") result = rpc_proxy.nspv_getinfo() self.assertEqual(result["result"], "success") - self.assertGreater(result["height"], 2689) + self.assertGreater(result["height"], chain_params.get(chain).get("min_chain_height")) time.sleep(1) def test_nspv_notarizations(self): print("testing nspv_notarizations") - result = rpc_proxy.nspv_notarizations("2000") + result = rpc_proxy.nspv_notarizations(chain_params.get(chain).get("notarization_height")) self.assertEqual(result["result"], "success") - self.assertEqual(result["prev"]["notarized_height"], 1998) - self.assertEqual(result["next"]["notarized_height"], 2008) + self.assertEqual(result["prev"]["notarized_height"], chain_params.get(chain).get("prev_notarization_h")) + self.assertEqual(result["next"]["notarized_height"], chain_params.get(chain).get("next_notarization_h")) time.sleep(1) def test_nspv_hdrsproof(self): print("testing nspv_hdrsproof") - result = rpc_proxy.nspv_hdrsproof("2000", "2100") + result = rpc_proxy.nspv_hdrsproof(chain_params.get(chain).get("hdrs_proof_low"), + chain_params.get(chain).get("hdrs_proof_high")) self.assertEqual(result["result"], "success") - self.assertEqual(result["numhdrs"], 113) + self.assertEqual(result["numhdrs"], chain_params.get(chain).get("numhdrs_expected")) time.sleep(1) def test_nspv_login(self): @@ -76,9 +106,9 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_listunspent() self.assertEqual(result["result"], "success") time.sleep(1) - result = rpc_proxy.nspv_listunspent("RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") + result = rpc_proxy.nspv_listunspent(chain_params.get(chain).get("tx_list_address")) self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") + self.assertEqual(result["address"], chain_params.get(chain).get("tx_list_address")) def test_nspv_spend(self): print("testing nspv_spend") @@ -113,25 +143,26 @@ class TestNspvClient(unittest.TestCase): def test_nspv_spentinfo(self): print("testing nspv_spent_info") - result = rpc_proxy.nspv_spentinfo("67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418", "1") + result = rpc_proxy.nspv_spentinfo(chain_params.get(chain).get("tx_proof_id"), "1") self.assertEqual(result["result"], "success") - self.assertEqual(result["spentheight"], 2681) + self.assertEqual(result["spentheight"], chain_params.get(chain).get("tx_spent_height")) time.sleep(1) def test_nspv_txproof(self): print("testing nspv_txproof") - result = rpc_proxy.nspv_txproof("67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418", "2673") - self.assertEqual(result["txid"], "67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418") - time.sleep(1) - - def test_nspv_login_timout(self): - print("testing auto-logout in 777 seconds") - rpc_proxy.nspv_login(wif) - time.sleep(778) - result = rpc_proxy.nspv_spend(dest_address, amount) - self.assertEqual(result["result"], "error") - self.assertEqual(result["error"], "wif expired") - time.sleep(1) + result = rpc_proxy.nspv_txproof(chain_params.get(chain).get("tx_proof_id"), + chain_params.get(chain).get("tx_proof_height")) + self.assertEqual(result["txid"], chain_params.get(chain).get("tx_proof_id")) + time.sleep(1) + + def test_nspv_login_timout(self): + print("testing auto-logout in 777 seconds") + rpc_proxy.nspv_login(wif) + time.sleep(778) + result = rpc_proxy.nspv_spend(dest_address, amount) + self.assertEqual(result["result"], "error") + self.assertEqual(result["error"], "wif expired") + time.sleep(1) if __name__ == '__main__': diff --git a/src/tui/lib/tuilib.py b/src/tui/lib/tuilib.py index 9a2fed639..afb4fad63 100755 --- a/src/tui/lib/tuilib.py +++ b/src/tui/lib/tuilib.py @@ -21,6 +21,24 @@ if operating_system != 'Win64' and operating_system != 'Windows': import readline +class CustomProxy(Proxy): + def __init__(self, + service_url=None, + service_port=None, + conf_file=None, + timeout=3000): + config = dict() + if conf_file: + config = slickrpc.ConfigObj(conf_file) + if service_url: + config.update(self.url_to_conf(service_url)) + if service_port: + config.update(rpcport=service_port) + elif not config.get('rpcport'): + config['rpcport'] = 7771 + self.conn = self.prepare_connection(config, timeout=timeout) + + def colorize(string, color): colors = { @@ -97,7 +115,7 @@ def def_credentials(chain): print("check "+coin_config_file) exit(1) - return(Proxy("http://%s:%s@127.0.0.1:%d"%(rpcuser, rpcpassword, int(rpcport)))) + return(CustomProxy("http://%s:%s@127.0.0.1:%d"%(rpcuser, rpcpassword, int(rpcport)))) def getinfo_tui(rpc_connection): From 1108c4cb32b8c5537ac9cbd73363867c6666d297 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Fri, 2 Aug 2019 03:06:38 +0700 Subject: [PATCH 07/18] typo fix --- qa/rpc-tests/nspv_client_test.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index ddc1d8093..5611e1e31 100755 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -155,14 +155,14 @@ class TestNspvClient(unittest.TestCase): self.assertEqual(result["txid"], chain_params.get(chain).get("tx_proof_id")) time.sleep(1) - def test_nspv_login_timout(self): - print("testing auto-logout in 777 seconds") - rpc_proxy.nspv_login(wif) - time.sleep(778) - result = rpc_proxy.nspv_spend(dest_address, amount) - self.assertEqual(result["result"], "error") - self.assertEqual(result["error"], "wif expired") - time.sleep(1) + def test_nspv_login_timout(self): + print("testing auto-logout in 777 seconds") + rpc_proxy.nspv_login(wif) + time.sleep(778) + result = rpc_proxy.nspv_spend(dest_address, amount) + self.assertEqual(result["result"], "error") + self.assertEqual(result["error"], "wif expired") + time.sleep(1) if __name__ == '__main__': From f3e341722bf6fb2189e17f7d38a7a7957e3130de Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 02:30:24 -1100 Subject: [PATCH 08/18] Zawy7 --- src/pow.cpp | 64 +++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 406fca63c..e1b57f042 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -166,42 +166,44 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - bnSum4 = zawy_targetMA(easy,bnSum4,block4diff * 5); - bnSum7 = zawy_targetMA(easy,bnSum7,block7diff * 3); - bnSum12 = zawy_targetMA(easy,bnSum12,block12diff * 2); - if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) - { - if ( bnSum4 < bnSum7 ) - bnTmp = bnSum4; - else bnTmp = bnSum7; - if ( bnSum12 < bnTmp ) - bnTmp = bnSum12; - if ( bnTmp < bnTarget ) - { - fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - bnTarget = bnTmp; - } //else fprintf(stderr,"nothing smaller\n"); - } - else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) - { - if ( bnSum4 > bnSum7 ) - bnTmp = bnSum4; - else bnTmp = bnSum7; - if ( bnSum12 > bnTmp ) - bnTmp = bnSum12; - if ( bnTmp > bnTarget ) - { - fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); - bnTarget = bnTmp; - } //else fprintf(stderr,"nothing bigger\n"); - } - /*if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases + if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases { block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); } - */ + else + { + bnSum4 = zawy_targetMA(easy,bnSum4,block4diff * 5); + bnSum7 = zawy_targetMA(easy,bnSum7,block7diff * 3); + bnSum12 = zawy_targetMA(easy,bnSum12,block12diff * 2); + if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) + { + if ( bnSum4 < bnSum7 ) + bnTmp = bnSum4; + else bnTmp = bnSum7; + if ( bnSum12 < bnTmp ) + bnTmp = bnSum12; + if ( bnTmp < bnTarget ) + { + fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); + bnTarget = bnTmp; + } //else fprintf(stderr,"nothing smaller\n"); + } + else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) + { + if ( bnSum4 > bnSum7 ) + bnTmp = bnSum4; + else bnTmp = bnSum7; + if ( bnSum12 > bnTmp ) + bnTmp = bnSum12; + if ( bnTmp > bnTarget ) + { + fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); + bnTarget = bnTmp; + } //else fprintf(stderr,"nothing bigger\n"); + } + } } // else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); nbits = bnTarget.GetCompact(); } From 31ebd139b85787397bcb71098f8be7d0102051e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 02:34:20 -1100 Subject: [PATCH 09/18] /2 --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index e1b57f042..3d616dc42 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -166,7 +166,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases + if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME/2 ) // for 10x and higher hashrate increases { block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); From cdb3980abc0ae37ceb5eebf582988661eaf74c56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 03:12:13 -1100 Subject: [PATCH 10/18] Fix zawyMA calc --- src/pow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 3d616dc42..b32bf845f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,10 +42,10 @@ uint32_t komodo_chainactive_timestamp(); unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params); unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); -arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnTarget,int32_t divisor) +arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnTarget,int32_t numerator) { - bnTarget /= arith_uint256(divisor); - bnTarget *= arith_uint256(ASSETCHAINS_BLOCKTIME); + bnTarget /= arith_uint256(ASSETCHAINS_BLOCKTIME); + bnTarget *= arith_uint256(numerator); if ( bnTarget > easy ) bnTarget = easy; return(bnTarget); @@ -166,7 +166,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME/2 ) // for 10x and higher hashrate increases + if ( (0) && block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME/2 ) // added /2 { block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); From ecfec20ff87ae0f9519f4443e6bd6d2385bc5815 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 03:28:48 -1100 Subject: [PATCH 11/18] Zawy9 --- src/pow.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index b32bf845f..d863efa19 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,10 +42,10 @@ uint32_t komodo_chainactive_timestamp(); unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params); unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); -arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnTarget,int32_t numerator) +arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnTarget,int32_t divisor) { - bnTarget /= arith_uint256(ASSETCHAINS_BLOCKTIME); - bnTarget *= arith_uint256(numerator); + bnTarget /= arith_uint256(divisor); + bnTarget *= arith_uint256(ASSETCHAINS_BLOCKTIME); if ( bnTarget > easy ) bnTarget = easy; return(bnTarget); @@ -166,13 +166,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - if ( (0) && block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME/2 ) // added /2 + if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases { block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); } - else + // else { bnSum4 = zawy_targetMA(easy,bnSum4,block4diff * 5); bnSum7 = zawy_targetMA(easy,bnSum7,block7diff * 3); From e5045e995cc62ca601413eaac55e95b7ca5f5a35 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 03:59:52 -1100 Subject: [PATCH 12/18] Zawy10 --- src/pow.cpp | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index d863efa19..51850f78b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,13 +42,13 @@ uint32_t komodo_chainactive_timestamp(); unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params); unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); -arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnTarget,int32_t divisor) +arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,int32_t numerator) { - bnTarget /= arith_uint256(divisor); - bnTarget *= arith_uint256(ASSETCHAINS_BLOCKTIME); - if ( bnTarget > easy ) - bnTarget = easy; - return(bnTarget); + bnSum /= arith_uint256(ASSETCHAINS_BLOCKTIME * num); + bnSum *= arith_uint256(numerator); + if ( bnSum > easy ) + bnSum = easy; + return(bnSum); } arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) @@ -148,7 +148,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; + bool fNegative,fOverflow; int32_t flag; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { @@ -166,17 +166,30 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases + flag = 0; + if ( block4diff >= 4 && block4diff < ASSETCHAINS_BLOCKTIME/3 ) + { + bnTarget /= arith_uint256(4); + flag = 4; + fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff,0.25); + } + if ( block7diff >= 7 && block7diff < ASSETCHAINS_BLOCKTIME/2 ) + { + bnTarget /= arith_uint256(7); + flag = 7; + fprintf(stderr,"ht.%d 7 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block7diff,1./7); + } + if ( block12diff >= 12 && block12diff < ASSETCHAINS_BLOCKTIME ) { - block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; - bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); - fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); + bnTarget /= arith_uint256(12); + flag = 12; + fprintf(stderr,"ht.%d 12 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block12diff,1./12); } - // else + else if ( flag == 0 ) { - bnSum4 = zawy_targetMA(easy,bnSum4,block4diff * 5); - bnSum7 = zawy_targetMA(easy,bnSum7,block7diff * 3); - bnSum12 = zawy_targetMA(easy,bnSum12,block12diff * 2); + bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5); + bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3); + bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2); if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) { if ( bnSum4 < bnSum7 ) From 8dc5c7c60a955ed61dffb17af5d5146f5c03e38d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 05:36:34 -1100 Subject: [PATCH 13/18] zawy11 Fix MA calc, different numerators for max() --- src/pow.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 51850f78b..e4678bfe2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,9 +42,9 @@ uint32_t komodo_chainactive_timestamp(); unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params); unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); -arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,int32_t numerator) +arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,int32_t numerator,int32_t divisor) { - bnSum /= arith_uint256(ASSETCHAINS_BLOCKTIME * num); + bnSum /= arith_uint256(ASSETCHAINS_BLOCKTIME * num * num * divisor); bnSum *= arith_uint256(numerator); if ( bnSum > easy ) bnSum = easy; @@ -187,11 +187,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( flag == 0 ) { - bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5); - bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3); - bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2); if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) { + bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); + bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); + bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); if ( bnSum4 < bnSum7 ) bnTmp = bnSum4; else bnTmp = bnSum7; @@ -205,6 +205,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) { + bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 3,10); + bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 5,10); + bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 6,10); if ( bnSum4 > bnSum7 ) bnTmp = bnSum4; else bnTmp = bnSum7; From 62a57c1ebd69620a7499a42a3a4565fc1090957b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 05:49:38 -1100 Subject: [PATCH 14/18] Remove boosters for zawy11 --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index e4678bfe2..7d084141b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -167,7 +167,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { flag = 0; - if ( block4diff >= 4 && block4diff < ASSETCHAINS_BLOCKTIME/3 ) + /*if ( block4diff >= 4 && block4diff < ASSETCHAINS_BLOCKTIME/3 ) { bnTarget /= arith_uint256(4); flag = 4; @@ -185,7 +185,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead flag = 12; fprintf(stderr,"ht.%d 12 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block12diff,1./12); } - else if ( flag == 0 ) + else if ( flag == 0 )*/ { if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) { From 4fa1f639e21f912665c101428385f897c2cf72c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 06:24:09 -1100 Subject: [PATCH 15/18] Zawy12, reduce noise ave with bnPrev --- src/pow.cpp | 81 ++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 51 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 7d084141b..2e5e03539 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -100,11 +100,12 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 bnTmp,bnTarget,bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0}; + arith_uint256 bnTmp,bnTarget,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0}; uint32_t nbits,blocktime,block4diff=0,block7diff=0,block12diff=0; int32_t diff,mult = 0; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) { mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; + bnPrev.SetCompact(pindexFirst->nBits); //fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime); } for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) @@ -148,7 +149,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; int32_t flag; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; + bool fNegative,fOverflow; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { @@ -166,59 +167,37 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - flag = 0; - /*if ( block4diff >= 4 && block4diff < ASSETCHAINS_BLOCKTIME/3 ) + if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) { - bnTarget /= arith_uint256(4); - flag = 4; - fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff,0.25); - } - if ( block7diff >= 7 && block7diff < ASSETCHAINS_BLOCKTIME/2 ) - { - bnTarget /= arith_uint256(7); - flag = 7; - fprintf(stderr,"ht.%d 7 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block7diff,1./7); - } - if ( block12diff >= 12 && block12diff < ASSETCHAINS_BLOCKTIME ) - { - bnTarget /= arith_uint256(12); - flag = 12; - fprintf(stderr,"ht.%d 12 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block12diff,1./12); + bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); + bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); + bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); + if ( bnSum4 < bnSum7 ) + bnTmp = bnSum4; + else bnTmp = bnSum7; + if ( bnSum12 < bnTmp ) + bnTmp = bnSum12; + if ( bnTmp < bnTarget ) + { + fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); + bnTarget = (bnTmp + bnPrev) / arith_uint256(2); + } //else fprintf(stderr,"nothing smaller\n"); } - else if ( flag == 0 )*/ + else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) { - if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) + bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 3,10); + bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 5,10); + bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 6,10); + if ( bnSum4 > bnSum7 ) + bnTmp = bnSum4; + else bnTmp = bnSum7; + if ( bnSum12 > bnTmp ) + bnTmp = bnSum12; + if ( bnTmp > bnTarget ) { - bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); - bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); - bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); - if ( bnSum4 < bnSum7 ) - bnTmp = bnSum4; - else bnTmp = bnSum7; - if ( bnSum12 < bnTmp ) - bnTmp = bnSum12; - if ( bnTmp < bnTarget ) - { - fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - bnTarget = bnTmp; - } //else fprintf(stderr,"nothing smaller\n"); - } - else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) - { - bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 3,10); - bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 5,10); - bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 6,10); - if ( bnSum4 > bnSum7 ) - bnTmp = bnSum4; - else bnTmp = bnSum7; - if ( bnSum12 > bnTmp ) - bnTmp = bnSum12; - if ( bnTmp > bnTarget ) - { - fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); - bnTarget = bnTmp; - } //else fprintf(stderr,"nothing bigger\n"); - } + fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); + bnTarget = (bnTmp + bnPrev) / arith_uint256(2); + } //else fprintf(stderr,"nothing bigger\n"); } } // else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); nbits = bnTarget.GetCompact(); From 7a7788419fcdaa423d8f91a868ffa5a38a911f2f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 06:51:46 -1100 Subject: [PATCH 16/18] Implement precedence of digishield, max(), e^x, min() --- src/pow.cpp | 69 +++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 2e5e03539..a84db0015 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -149,15 +149,30 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; + bool fNegative,fOverflow; int32_t flag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); - if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && block12diff != 0 && block7diff != 0 && block4diff != 0 ) { origtarget = bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - if ( mult > 1 ) // chain is stuck case, jl777: test of mult > 1 failed when it was int64_t??? + bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); + bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); + bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); + if ( bnSum4 < bnSum7 ) + bnTmp = bnSum4; + else bnTmp = bnSum7; + if ( bnSum12 < bnTmp ) + bnTmp = bnSum12; + if ( bnTmp < bnTarget ) { - bnTarget = zawy_exponential(bnTarget,mult); //replaces: bnTarget * arith_uint256(mult * mult); + fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); + bnTarget = (bnTmp + bnPrev) / arith_uint256(2); + flag = 1; + } + else if ( flag == 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? + { + flag = 1; + bnTarget = zawy_exponential(bnTarget,mult); if ( bnTarget < origtarget || bnTarget > easy ) { bnTarget = easy; @@ -165,41 +180,23 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return(KOMODO_MINDIFF_NBITS); } else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); } - else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) + if ( flag == 0 ) { - if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) - { - bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); - bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); - bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); - if ( bnSum4 < bnSum7 ) - bnTmp = bnSum4; - else bnTmp = bnSum7; - if ( bnSum12 < bnTmp ) - bnTmp = bnSum12; - if ( bnTmp < bnTarget ) - { - fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - bnTarget = (bnTmp + bnPrev) / arith_uint256(2); - } //else fprintf(stderr,"nothing smaller\n"); - } - else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) + bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 3,10); + bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 5,10); + bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 6,10); + if ( bnSum4 > bnSum7 ) + bnTmp = bnSum4; + else bnTmp = bnSum7; + if ( bnSum12 > bnTmp ) + bnTmp = bnSum12; + if ( bnTmp > bnTarget ) { - bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 3,10); - bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 5,10); - bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 6,10); - if ( bnSum4 > bnSum7 ) - bnTmp = bnSum4; - else bnTmp = bnSum7; - if ( bnSum12 > bnTmp ) - bnTmp = bnSum12; - if ( bnTmp > bnTarget ) - { - fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); - bnTarget = (bnTmp + bnPrev) / arith_uint256(2); - } //else fprintf(stderr,"nothing bigger\n"); + fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); + bnTarget = (bnTmp + bnPrev) / arith_uint256(2); + flag = 1; } - } // else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); + } nbits = bnTarget.GetCompact(); } return(nbits); From c07f73e217304ae6ee6b005648224699cafdb585 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Sun, 4 Aug 2019 01:29:20 +0700 Subject: [PATCH 17/18] change default chain to ILN --- qa/rpc-tests/nspv_client_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index 5611e1e31..8487105ff 100755 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -13,8 +13,8 @@ added 1 second sleep after each case to surely not face the nSPV server limitati wif = '' dest_address = '' -amount = '0.01' -chain = 'KMD' +amount = '0.001' +chain = 'ILN' if not wif or not dest_address: raise Exception("Please set test wif and address to send transactions to") From cf844ce5a49318dbb1e4fb2ffe9f0c34c7e7df56 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Sun, 4 Aug 2019 01:29:50 +0700 Subject: [PATCH 18/18] def amount change --- qa/rpc-tests/nspv_client_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index 8487105ff..26f88cf5a 100755 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -13,7 +13,7 @@ added 1 second sleep after each case to surely not face the nSPV server limitati wif = '' dest_address = '' -amount = '0.001' +amount = '0.01' chain = 'ILN' if not wif or not dest_address: