Skip to content

Instantly share code, notes, and snippets.

@EggPool
Created July 10, 2018 09:28
Show Gist options
  • Save EggPool/66208970e7362ed1e19c8404f71d2d1d to your computer and use it in GitHub Desktop.
Save EggPool/66208970e7362ed1e19c8404f71d2d1d to your computer and use it in GitHub Desktop.
mining_condition.py
mining_hash = bin_convert(hashlib.sha224((miner_address + nonce + db_block_hash)
.encode("utf-8")).hexdigest())
diff_drop_time = 180
mining_condition = bin_convert(db_block_hash)[:diff]
if mining_condition in mining_hash: # simplified comparison, no backwards mining
app_log.info("Difficulty requirement satisfied for block {} from {}".format (block_height_new, peer_ip))
diff_save = diff
# Tail Removal Condition Check Starts Here
elif received_timestamp > db_timestamp_last + diff_drop_time:
time_difference = received_timestamp - db_timestamp_last
diff_dropped = diff - time_difference / diff_drop_time
if diff_dropped < 50:
diff_dropped = 50
mining_condition = bin_convert(db_block_hash)[:diff_dropped]
if mining_condition in mining_hash:
app_log.info("Readjusted difficulty requirement satisfied for block {} from {}"
.format(block_height_new, peer_ip))
diff_save = diff
else:
raise ValueError("Readjusted difficulty too low for block {} from {}, should be at least {}"
.format(block_height_new, peer_ip, diff_dropped))
else:
raise ValueError("Difficulty too low for block {} from {}, should be at least {}"
.format(block_height_new, peer_ip, diff))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment