Advertisement
Guest User

Eviler-Knieveler

a guest
Dec 5th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1.     #TODO: Simplify and find out how it works...
  2.     def retarget_work(self, block, x, conf={"pastMass": 0xf, "ltd2": 811436.6, "ltd3": 6.7, "retarg": 0x4, "scale": 0.0150202, "minfac": 406.6 , "maxfac": 6.7, "driftfac": 0.0150202 }):
  3.     targetI = x["target"]
  4.     pastMass = 0
  5.     seconds_passed = 0
  6.     totalMass = 0
  7.     counter = 0
  8.     current_block = self.current_height
  9.     current_block_timestamp = self.blockchain[self.current_height]["time_stamp"]
  10.  
  11.     massive_retarget = False
  12.     deviation_too_high = False
  13.     last_two_deviation = 0.0
  14.     if conf["ltd2"] > conf["ltd3"]:
  15.       t = conf["ltd2"]
  16.       conf["ltd2"] = conf["ltd3"]
  17.       conf["ltd3"] = t
  18.     #print conf
  19.     while True:
  20.         counter = counter + 1
  21.         curmass = self.blockchain[current_block]["num_pow"][x["id"]]
  22.         pastMass += curmass
  23.  
  24.  
  25.         # if the maximum block-tx-limit of pM was reached, do maybe massive retargeting
  26.         if counter == 1 and pastMass >= conf["pastMass"]:
  27.             massive_retarget = True
  28.             break
  29.  
  30.         # Also if deviation of last two block was too high, do some "more magic"
  31.         if counter == 1 and curmass > 0:
  32.             last_two_deviation = curmass / 10
  33.             if last_two_deviation > conf["ltd2"] or last_two_deviation < conf["ltd3"]:  #deviation of over X% is bad
  34.                 #print "last two deviation",last_two_deviation,"at block",block
  35.                 deviation_too_high = True
  36.                 break
  37.         for y in self.blockchain[current_block]["num_pow"]:
  38.             totalMass += self.blockchain[current_block]["num_pow"][y]
  39.         seconds_passed = (current_block_timestamp - self.blockchain[current_block-1]["time_stamp"]).seconds
  40.         current_block = current_block - 1
  41.        
  42.         if current_block < 1 or seconds_passed >= conf["retarg"]: # retarget every (?) seconds ~ some blocks on average
  43.             break
  44.  
  45.     factor = 1
  46.     if massive_retarget == True:
  47.         factor = conf["scale"] # lower!!!
  48.     elif deviation_too_high == True:
  49.         factor = 1/last_two_deviation
  50.     else:
  51.         if seconds_passed < 1:
  52.             seconds_passed = 1
  53.  
  54.         pows_per_360_seconds = ((pastMass * 360.0) / seconds_passed)
  55.         if pows_per_360_seconds>0 and pows_per_360_seconds<1:
  56.             pows_per_360_seconds = 1
  57.            
  58.         #and now for some fun
  59.         minfac = conf["minfac"]
  60.         maxfac = conf["maxfac"]
  61.         factor = 1
  62.         if pows_per_360_seconds > 0:
  63.             factor = 10*6.0/pows_per_360_seconds
  64.             if factor<minfac:
  65.                 factor = minfac
  66.             if factor>maxfac:
  67.                 factor=maxfac
  68.         elif pows_per_360_seconds == 0 and totalMass == 0:
  69.             factor = conf["driftfac"] #1.05
  70.         else:
  71.             factor = 1
  72.  
  73.     #print "seconds",seconds_passed,"blocks",counter,"actual pows",pastMass,"per 360s:",pows_per_360_seconds,"wanted:",60,"factor",factor
  74.  
  75.     targetI = targetI * factor
  76.     if targetI> self.base_target:
  77.         targetI = self.base_target
  78.     if x["id"]==0:
  79.         self.blockchain[current_block]["first_work_factor"] = factor
  80.     x["target"] = targetI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement