Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TODO: Simplify and find out how it works...
- 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 }):
- targetI = x["target"]
- pastMass = 0
- seconds_passed = 0
- totalMass = 0
- counter = 0
- current_block = self.current_height
- current_block_timestamp = self.blockchain[self.current_height]["time_stamp"]
- massive_retarget = False
- deviation_too_high = False
- last_two_deviation = 0.0
- if conf["ltd2"] > conf["ltd3"]:
- t = conf["ltd2"]
- conf["ltd2"] = conf["ltd3"]
- conf["ltd3"] = t
- #print conf
- while True:
- counter = counter + 1
- curmass = self.blockchain[current_block]["num_pow"][x["id"]]
- pastMass += curmass
- # if the maximum block-tx-limit of pM was reached, do maybe massive retargeting
- if counter == 1 and pastMass >= conf["pastMass"]:
- massive_retarget = True
- break
- # Also if deviation of last two block was too high, do some "more magic"
- if counter == 1 and curmass > 0:
- last_two_deviation = curmass / 10
- if last_two_deviation > conf["ltd2"] or last_two_deviation < conf["ltd3"]: #deviation of over X% is bad
- #print "last two deviation",last_two_deviation,"at block",block
- deviation_too_high = True
- break
- for y in self.blockchain[current_block]["num_pow"]:
- totalMass += self.blockchain[current_block]["num_pow"][y]
- seconds_passed = (current_block_timestamp - self.blockchain[current_block-1]["time_stamp"]).seconds
- current_block = current_block - 1
- if current_block < 1 or seconds_passed >= conf["retarg"]: # retarget every (?) seconds ~ some blocks on average
- break
- factor = 1
- if massive_retarget == True:
- factor = conf["scale"] # lower!!!
- elif deviation_too_high == True:
- factor = 1/last_two_deviation
- else:
- if seconds_passed < 1:
- seconds_passed = 1
- pows_per_360_seconds = ((pastMass * 360.0) / seconds_passed)
- if pows_per_360_seconds>0 and pows_per_360_seconds<1:
- pows_per_360_seconds = 1
- #and now for some fun
- minfac = conf["minfac"]
- maxfac = conf["maxfac"]
- factor = 1
- if pows_per_360_seconds > 0:
- factor = 10*6.0/pows_per_360_seconds
- if factor<minfac:
- factor = minfac
- if factor>maxfac:
- factor=maxfac
- elif pows_per_360_seconds == 0 and totalMass == 0:
- factor = conf["driftfac"] #1.05
- else:
- factor = 1
- #print "seconds",seconds_passed,"blocks",counter,"actual pows",pastMass,"per 360s:",pows_per_360_seconds,"wanted:",60,"factor",factor
- targetI = targetI * factor
- if targetI> self.base_target:
- targetI = self.base_target
- if x["id"]==0:
- self.blockchain[current_block]["first_work_factor"] = factor
- x["target"] = targetI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement