Esempio n. 1
0
def clampTarget(target, DTMode):
	# ShareTarget is the minimum
	if ScryptCoin:
		if target is None or target > config.ShareTarget / 64:
		    target = config.ShareTarget / 64
	else:
		if target is None or target > config.ShareTarget:
		    target = config.ShareTarget

	# Never target above the network, as we'd lose blocks
	if target < networkTarget:
		target = networkTarget
	
	if DTMode == 2:
		# Ceil target to a power of two :)
		truebits = log(target, 2)
		if target <= 2**int(truebits):
			# Workaround for bug in Python's math.log function
			truebits = int(truebits)
		target = 2**ceil(truebits) - 1
	elif DTMode == 3:
		# Round target to multiple of bdiff 1
		target = bdiff1target / int(round(target2bdiff(target)))
	
	# Return None for ShareTarget to save memory
	if target == config.ShareTarget:
		return None
	return target
Esempio n. 2
0
def clampTarget(target, DTMode):
	# ShareTarget is the minimum
	divide_by = int(settings['divide_by'])
	if target is None or target > config.ShareTarget / divide_by:
		target = config.ShareTarget / divide_by
	
	# Never target above the network, as we'd lose blocks
	if target < networkTarget:
		target = networkTarget
	
	if DTMode == 2:
		# Ceil target to a power of two :)
		truebits = log(target, 2)
		if target <= 2**int(truebits):
			# Workaround for bug in Python's math.log function
			truebits = int(truebits)
			target = 2**ceil(truebits) - 1
	elif DTMode == 3:
		# Round target to multiple of bdiff 1
		target = bdiff1target / int(round(target2bdiff(target)))
	
	# Return None for ShareTarget to save memory
	if target == config.ShareTarget:
		return None
	return target
Esempio n. 3
0
 def sendJob(self):
     target = self.server.defaultTarget
     if len(self.Usernames) == 1:
         dtarget = self.server.getTarget(next(iter(self.Usernames)), time())
         if not dtarget is None:
             target = dtarget
     bdiff = target2bdiff(target)
     if self.lastBDiff != bdiff:
         self.sendReply({"id": None, "method": "mining.set_difficulty", "params": [bdiff]})
         self.lastBDiff = bdiff
     self.push(self.server.JobBytes)
     if len(self.JobTargets) > 4:
         self.JobTargets.popitem(False)
     self.JobTargets[self.server.JobId] = target
Esempio n. 4
0
 def sendJob(self):
     target = self.server.defaultTarget
     if len(self.Usernames) == 1:
         dtarget = self.server.getTarget(next(iter(self.Usernames)), time())
         if not dtarget is None:
             target = dtarget
     bdiff = target2bdiff(target)
     if self.lastBDiff != bdiff:
         self.sendReply({
             'id': None,
             'method': 'mining.set_difficulty',
             'params': [bdiff],
         })
         self.lastBDiff = bdiff
     self.push(self.server.JobBytes)
     if len(self.JobTargets) > 4:
         self.JobTargets.popitem(False)
     self.JobTargets[self.server.JobId] = target
Esempio n. 5
0
def clampTarget(target, DTMode):
	# ShareTarget is the minimum
	if target is None or target > config.ShareTarget / 64:
		target = config.ShareTarget / 64
	
	# Never target above the network, as we'd lose blocks
	if target < networkTarget:
		target = networkTarget
	
	if DTMode == 2:
		# Ceil target to a power of two :)
		target = 2**int(log(target, 2) + 1) - 1
	elif DTMode == 3:
		# Round target to multiple of bdiff 1
		target = bdiff1target / int(round(target2bdiff(target)))
	
	# Return None for ShareTarget to save memory
	if target == config.ShareTarget:
		return None
	return target
def clampTarget(target, DTMode):
	# ShareTarget is the minimum
	if target is None or target > config.ShareTarget:
		target = config.ShareTarget
	
	# Never target above upstream(s), as we'd lose blocks
	target = max(target, networkTarget, config.GotWorkTarget)
	
	if DTMode == 2:
		# Ceil target to a power of two :)
		truebits = log(target, 2)
		if target <= 2**int(truebits):
			# Workaround for bug in Python's math.log function
			truebits = int(truebits)
		target = 2**ceil(truebits) - 1
	elif DTMode == 3:
		# Round target to multiple of bdiff 1
		target = bdiff1target / int(round(target2bdiff(target)))
	
	# Return None for ShareTarget to save memory
	if target == config.ShareTarget:
		return None
	return target
Esempio n. 7
0
 def sendJob(self, rskLog=True):
     target = self.server.defaultTarget
     if len(self.Usernames) == 1:
         dtarget = self.server.getTarget(next(iter(self.Usernames)), time())
         if not dtarget is None:
             target = dtarget
     bdiff = target2bdiff(target)
     if self.lastBDiff != bdiff:
         setDifficultyMessage = {
             'id': None,
             'method': 'mining.set_difficulty',
             'params': [bdiff],
         }
         self.logger.info(
             "ROOTSTOCK: send_client_send: {}, {:X}, {}".format(
                 id(self), id(bdiff), json.dumps(setDifficultyMessage)))
         self.sendReply(setDifficultyMessage)
         self.logger.info(
             "ROOTSTOCK: send_client_complete: {}, {:X}".format(
                 id(self), id(bdiff)))
         self.lastBDiff = bdiff
     message = self.server.JobBytes.decode('utf-8') if hasattr(
         self.server,
         'JobBytes') and self.server.JobBytes is not None else '{}'
     if rskLog:
         self.logger.info(
             "ROOTSTOCK: send_client_send: {}, {:X}, {}".format(
                 id(self), id(bdiff), message))
     self.push(self.server.JobBytes)
     if rskLog:
         self.logger.info(
             "ROOTSTOCK: send_client_complete: {}, {:X}".format(
                 id(self), id(bdiff)))
     if len(self.JobTargets) > 4:
         self.JobTargets.popitem(False)
     self.JobTargets[self.server.JobId] = target