From 912c0bbeea603abaa4ea8f430490cad1b9dc2132 Mon Sep 17 00:00:00 2001 From: Parth Oberoi Date: Mon, 13 Apr 2020 15:03:02 +0530 Subject: [PATCH] Update target spacing and difficulty adjustment for buttercup update --- contrib/zclassic/travis/before_install-osx.sh | 1 + lib/blockchain.py | 41 +++++++++++++------ lib/servers.json | 12 ------ lib/util.py | 2 +- lib/version.py | 2 +- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/contrib/zclassic/travis/before_install-osx.sh b/contrib/zclassic/travis/before_install-osx.sh index c2d566546..482024d45 100755 --- a/contrib/zclassic/travis/before_install-osx.sh +++ b/contrib/zclassic/travis/before_install-osx.sh @@ -8,6 +8,7 @@ fi cd build +brew untap homebrew/homebrew-versions brew update brew tap zebra-lucky/qt5 brew install zebra-lucky/qt5/qt diff --git a/lib/blockchain.py b/lib/blockchain.py index eebcf9afc..1f57762ae 100644 --- a/lib/blockchain.py +++ b/lib/blockchain.py @@ -34,6 +34,7 @@ CHUNK_LEN = 100 BUBBLES_ACTIVATION_HEIGHT = 585318 DIFFADJ_ACTIVATION_HEIGHT = 585322 +BUTTERCUP_ACTIVATION_HEIGHT = 707000 MAX_TARGET = 0x0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF POW_AVERAGING_WINDOW = 17 @@ -41,18 +42,24 @@ POW_MAX_ADJUST_DOWN = 32 POW_MAX_ADJUST_UP = 16 POW_DAMPING_FACTOR = 4 -POW_TARGET_SPACING = 150 +PRE_BUTTERCUP_POW_TARGET_SPACING = 150 +POST_BUTTERCUP_POW_TARGET_SPACING = 75 TARGET_CALC_BLOCKS = POW_AVERAGING_WINDOW + POW_MEDIAN_BLOCK_SPAN -AVERAGING_WINDOW_TIMESPAN = POW_AVERAGING_WINDOW * POW_TARGET_SPACING +def get_pow_target_spacing(height): + if height >= BUTTERCUP_ACTIVATION_HEIGHT: + return POST_BUTTERCUP_POW_TARGET_SPACING + return PRE_BUTTERCUP_POW_TARGET_SPACING -MIN_ACTUAL_TIMESPAN = AVERAGING_WINDOW_TIMESPAN * \ - (100 - POW_MAX_ADJUST_UP) // 100 +def get_averaging_window_timespan(height): + return POW_AVERAGING_WINDOW * get_pow_target_spacing(height) -MAX_ACTUAL_TIMESPAN = AVERAGING_WINDOW_TIMESPAN * \ - (100 + POW_MAX_ADJUST_DOWN) // 100 +def get_min_actual_timespan(height): + return get_averaging_window_timespan(height) * (100 - POW_MAX_ADJUST_UP) // 100 +def get_max_actual_timespan(height): + return get_averaging_window_timespan(height) * (100 + POW_MAX_ADJUST_DOWN) // 100 def is_post_equihash_fork(height): return height >= BUBBLES_ACTIVATION_HEIGHT @@ -231,6 +238,14 @@ def verify_header(self, header, prev_hash, target): ] bits = valid_bits[height%DIFFADJ_ACTIVATION_HEIGHT] target = self.bits_to_target(bits) + elif height >= BUTTERCUP_ACTIVATION_HEIGHT and height < BUTTERCUP_ACTIVATION_HEIGHT + POW_AVERAGING_WINDOW: + valid_bits = [ + 0x1f07ffff, 0x1f00a083, 0x1f00ace2, 0x1f00ba38, 0x1f07ffff, 0x1f016783, + 0x1f018356, 0x1f01a152, 0x1f01c1a2, 0x1f01e474, 0x1f0209fc, 0x1f02326c, + 0x1f025e01, 0x1f028cf8, 0x1f02bf93, 0x1f02f61c, 0x1f0330df, + ] + bits = valid_bits[height%BUTTERCUP_ACTIVATION_HEIGHT] + target = self.bits_to_target(bits) if bits != header.get('bits'): raise Exception("bits mismatch: %s vs %s" % (bits, header.get('bits'))) if int('0x' + _hash, 16) > target: @@ -426,15 +441,15 @@ def get_target(self, height, chunk_headers=None): actual_timespan = self.get_median_time(height, chunk_headers) - \ self.get_median_time(height - POW_AVERAGING_WINDOW, chunk_headers) - actual_timespan = AVERAGING_WINDOW_TIMESPAN + \ - int((actual_timespan - AVERAGING_WINDOW_TIMESPAN) / \ + actual_timespan = get_averaging_window_timespan(height) + \ + int((actual_timespan - get_averaging_window_timespan(height)) / \ POW_DAMPING_FACTOR) - if actual_timespan < MIN_ACTUAL_TIMESPAN: - actual_timespan = MIN_ACTUAL_TIMESPAN - elif actual_timespan > MAX_ACTUAL_TIMESPAN: - actual_timespan = MAX_ACTUAL_TIMESPAN + if actual_timespan < get_min_actual_timespan(height): + actual_timespan = get_min_actual_timespan(height) + elif actual_timespan > get_max_actual_timespan(height): + actual_timespan = get_max_actual_timespan(height) - next_target = mean_target // AVERAGING_WINDOW_TIMESPAN * actual_timespan + next_target = mean_target // get_averaging_window_timespan(height) * actual_timespan if next_target > MAX_TARGET: next_target = MAX_TARGET diff --git a/lib/servers.json b/lib/servers.json index 72377b813..2617755fa 100644 --- a/lib/servers.json +++ b/lib/servers.json @@ -4,17 +4,5 @@ "s": "50002", "t": "50001", "version": "1.2" - }, - "electrum.zclassic.ch": { - "pruning": "-", - "s": "50002", - "t": "50001", - "version": "1.2" - }, - "electrum.zcl.community": { - "pruning": "-", - "s": "50002", - "t": "50001", - "version": "1.2" } } diff --git a/lib/util.py b/lib/util.py index 9c57eeaac..29df1f028 100644 --- a/lib/util.py +++ b/lib/util.py @@ -506,7 +506,7 @@ def time_difference(distance_in_time, include_seconds): return "over %d years" % (round(distance_in_minutes / 525600)) mainnet_block_explorers = { - 'zeltrez.io': ('https://explorer.zcl.zeltrez.io/', + 'zeltrez.io': ('https://explorer.zcl.zelcore.io/', {'tx': 'tx/', 'addr': 'address/'}) } diff --git a/lib/version.py b/lib/version.py index 5af1e74a3..4174f1b78 100644 --- a/lib/version.py +++ b/lib/version.py @@ -1,4 +1,4 @@ -ELECTRUM_VERSION = 'v3.2.5' # version of the client package +ELECTRUM_VERSION = 'v3.2.6' # version of the client package PROTOCOL_VERSION = '1.2' # protocol version requested # The hash of the mnemonic seed must begin with this