Skip to content

Commit

Permalink
Update target spacing and difficulty adjustment for buttercup update
Browse files Browse the repository at this point in the history
  • Loading branch information
hTrap committed Apr 14, 2020
1 parent 932bb07 commit 912c0bb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
1 change: 1 addition & 0 deletions contrib/zclassic/travis/before_install-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 28 additions & 13 deletions lib/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,32 @@
CHUNK_LEN = 100
BUBBLES_ACTIVATION_HEIGHT = 585318
DIFFADJ_ACTIVATION_HEIGHT = 585322
BUTTERCUP_ACTIVATION_HEIGHT = 707000

MAX_TARGET = 0x0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
POW_AVERAGING_WINDOW = 17
POW_MEDIAN_BLOCK_SPAN = 11
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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions lib/servers.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'})
}

Expand Down
2 changes: 1 addition & 1 deletion lib/version.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 912c0bb

Please sign in to comment.