Example #1
0
def getTarget(username, now, DTMode = None):
	if DTMode is None:
		DTMode = config.DynamicTargetting
	if not DTMode:
		return None
	if username in userStatus:
		status = userStatus[username]
	else:
		# No record, use default target
		userStatus[username] = [None, now, 0]
		return clampTarget(None, DTMode)
	(targetIn, lastUpdate, work) = status
	if work <= config.DynamicTargetGoal:
		if now < lastUpdate + config.DynamicTargetWindow and (targetIn is None or targetIn >= networkTarget):
			# No reason to change it just yet
			return clampTarget(targetIn, DTMode)
		if not work:
			# No shares received, reset to minimum
			if targetIn:
				getTarget.logger.debug("No shares from '%s', resetting to minimum target")
				userStatus[username] = [None, now, 0]
			return clampTarget(None, DTMode)
	
	deltaSec = now - lastUpdate
	target = targetIn or config.ShareTarget
	target = int(target * config.DynamicTargetGoal * deltaSec / config.DynamicTargetWindow / work)
	target = clampTarget(target, DTMode)
	if target != targetIn:
		pfx = 'Retargetting %s' % (repr(username),)
		tin = targetIn or config.ShareTarget
		getTarget.logger.debug("%s from: %064x (pdiff %s)" % (pfx, tin, target2pdiff(tin)))
		tgt = target or config.ShareTarget
		getTarget.logger.debug("%s   to: %064x (pdiff %s)" % (pfx, tgt, target2pdiff(tgt)))
	userStatus[username] = [target, now, 0]
	return target
Example #2
0
def getTarget(username, now):
    if not config.DynamicTargetting:
        return None
    if username in userStatus:
        status = userStatus[username]
    else:
        userStatus[username] = [None, now, 0]
        return None
    (targetIn, lastUpdate, work) = status
    if work <= config.DynamicTargetGoal:
        if now < lastUpdate + config.DynamicTargetWindow and (
                targetIn is None or targetIn >= networkTarget):
            return targetIn
        if not work:
            if targetIn:
                getTarget.logger.debug(
                    "No shares from '%s', resetting to minimum target")
                userStatus[username] = [None, now, 0]
            return None

    deltaSec = now - lastUpdate
    target = targetIn or config.ShareTarget
    target = int(target * config.DynamicTargetGoal * deltaSec /
                 config.DynamicTargetWindow / work)
    if target >= config.ShareTarget:
        target = None
    else:
        if target < networkTarget:
            target = networkTarget
        if config.DynamicTargetting == 2:
            # Round target to a power of two :)
            target = 2**int(log(target, 2) + 1) - 1
        if target == config.ShareTarget:
            target = None
    if target != targetIn:
        pfx = 'Retargetting %s' % (repr(username), )
        tin = targetIn or config.ShareTarget
        getTarget.logger.debug("%s from: %064x (pdiff %s)" %
                               (pfx, tin, target2pdiff(tin)))
        tgt = target or config.ShareTarget
        getTarget.logger.debug("%s   to: %064x (pdiff %s)" %
                               (pfx, tgt, target2pdiff(tgt)))
    userStatus[username] = [target, now, 0]
    return target
Example #3
0
def getTarget(username, now):
	if not config.DynamicTargetting:
		return None
	if username in userStatus:
		status = userStatus[username]
	else:
		userStatus[username] = [None, now, 0]
		return None
	(targetIn, lastUpdate, work) = status
	if work <= config.DynamicTargetGoal:
		if now < lastUpdate + config.DynamicTargetWindow and (targetIn is None or targetIn >= networkTarget):
			return targetIn
		if not work:
			if targetIn:
				getTarget.logger.debug("No shares from '%s', resetting to minimum target")
				userStatus[username] = [None, now, 0]
			return None
	
	deltaSec = now - lastUpdate
	target = targetIn or config.ShareTarget
	target = int(target * config.DynamicTargetGoal * deltaSec / config.DynamicTargetWindow / work)
	if target >= config.ShareTarget:
		target = None
	else:
		if target < networkTarget:
			target = networkTarget
		if config.DynamicTargetting == 2:
			# Round target to a power of two :)
			target = 2**int(log(target, 2) + 1) - 1
		if target == config.ShareTarget:
			target = None
	if target != targetIn:
		pfx = 'Retargetting %s' % (repr(username),)
		tin = targetIn or config.ShareTarget
		getTarget.logger.debug("%s from: %064x (pdiff %s)" % (pfx, tin, target2pdiff(tin)))
		tgt = target or config.ShareTarget
		getTarget.logger.debug("%s   to: %064x (pdiff %s)" % (pfx, tgt, target2pdiff(tgt)))
	userStatus[username] = [target, now, 0]
	return target
Example #4
0
	def t2d(t):
		if t not in tmp2:
			tmp2[t] = target2pdiff(t)
		return tmp2[t]
	def t2d(t):
		if t not in tmp2:
			tmp2[t] = target2pdiff(t)
		return tmp2[t]