import hashlib
import random
+import warnings
import p2pool
from p2pool.util import math, pack
# targets
def target_to_average_attempts(target):
+ assert 0 <= target and isinstance(target, (int, long)), target
+ if target >= 2**256: warnings.warn('target >= 2**256!')
return 2**256//(target + 1)
def target_to_difficulty(target):
+ assert 0 <= target and isinstance(target, (int, long)), target
+ if target >= 2**256: warnings.warn('target >= 2**256!')
return (0xffff0000 * 2**(256-64) + 1)/(target + 1)
def difficulty_to_target(difficulty):
- return (0xffff0000 * 2**(256-64) + 1)/difficulty - 1
+ assert difficulty >= 0
+ return min(int((0xffff0000 * 2**(256-64) + 1)/difficulty - 1 + 0.5), 2**256-1)
# human addresses
best = best_share.previous_hash
timestamp_cutoff = min(int(time.time()), best_share.timestamp) - 3600
- target_cutoff = 2**256//(self.net.SHARE_PERIOD*best_tail_score[1] + 1) * 2 if best_tail_score[1] is not None else 2**256-1
+ target_cutoff = int(2**256//(self.net.SHARE_PERIOD*best_tail_score[1] + 1) * 2 + .5) if best_tail_score[1] is not None else 2**256-1
else:
timestamp_cutoff = int(time.time()) - 24*60*60
target_cutoff = 2**256-1