コード例 #1
0
 def set_difficulty(self, difficulty):
     self.difficulty = difficulty
     bits = '%08x' % bytereverse(difficulty)
     true_target = '%064x' % (int(bits[2:], 16) *
                              2**(8 * (int(bits[:2], 16) - 3)), )
     true_target = ''.join(list(chunks(true_target, 2))[::-1])
     self.true_target = unpack('<8I', true_target.decode('hex'))
コード例 #2
0
ファイル: GenesisMiner.py プロジェクト: utabit/GenesisMiner
	def send(self, result, send_callback):
		for nonce in result.miner.nonce_generator(result.nonces):

			h = hash(result.state, result.merkle_end, result.time, result.difficulty, nonce)

			if h[7] != 0:
				hash6 = pack('<I', long(h[6])).encode('hex')
				say_line('Verification failed, check hardware! (%s, %s)', (result.miner.id(), hash6))
				return True # consume this particular result
			else:
				self.diff1_found(bytereverse(h[6]), result.target[6])
				if belowOrEquals(h[:7], result.target[:7]):
					is_block = belowOrEquals(h[:7], self.true_target[:7])

					hash6 = pack('<I', long(h[6])).encode('hex')
					hash5 = pack('<I', long(h[5])).encode('hex')
					self.sent[nonce] = (is_block, hash6, hash5)
					ntime = long(pack('<I', long(result.time)).encode('hex'),16)
					resnonce = long(pack('<I', long(nonce)).encode('hex'),16)
					block = self.source.create_block_header(self.source.merkle_root, ntime, self.source.bits, resnonce)
					hash_header = hashlib.sha256(hashlib.sha256(block).digest()).digest()[::-1]
					shouldSend = int(hash_header.encode('hex_codec'), 16) < self.source.server_difficulty
					print "t->" + str(ntime) + " nonce->" + str(resnonce) + " shouldSend->" + str(shouldSend)
					if shouldSend:
						if not send_callback(result, nonce):
							return False

		return True
コード例 #3
0
ファイル: BFLMiner.py プロジェクト: utabit/GenesisMiner
    def put_job(self):
        if self.busy: return

        temperature = self.get_temperature()
        if temperature < self.cutoff_temp:
            response = request(self.device, b'ZDX')
            if self.is_ok(response):
                if self.switch.update_time:
                    self.job.time = bytereverse(
                        uint32(long(time())) - self.job.time_delta)
                data = b''.join([
                    pack('<8I', *self.job.state),
                    pack('<3I', self.job.merkle_end, self.job.time,
                         self.job.difficulty)
                ])
                response = request(self.device,
                                   b''.join([b'>>>>>>>>', data, b'>>>>>>>>']))
                if self.is_ok(response):
                    self.busy = True
                    self.job_started = time()

                    self.last_job = Object()
                    self.last_job.header = self.job.header
                    self.last_job.merkle_end = self.job.merkle_end
                    self.last_job.time = self.job.time
                    self.last_job.difficulty = self.job.difficulty
                    self.last_job.target = self.job.target
                    self.last_job.state = self.job.state
                    self.last_job.job_id = self.job.job_id
                    self.last_job.extranonce2 = self.job.extranonce2
                    self.last_job.server = self.job.server
                    self.last_job.miner = self

                    self.check_interval = CHECK_INTERVAL
                    if not self.switch.update_time or bytereverse(
                            self.job.time) - bytereverse(
                                self.job.original_time) > 55:
                        self.update = True
                        self.job = None
                else:
                    say_line('%s: bad response when sending block data: %s',
                             (self.id(), response))
            else:
                say_line('%s: bad response when submitting job (ZDX): %s',
                         (self.id(), response))
        else:
            say_line('%s: temperature exceeds cutoff, waiting...', self.id())
コード例 #4
0
ファイル: BFLMiner.py プロジェクト: AngelMarc/poclbm
	def put_job(self):
		if self.busy: return

		temperature = self.get_temperature()
		if temperature < self.cutoff_temp:
			response = request(self.device, b'ZDX')
			if self.is_ok(response):
				if self.switch.update_time:
					self.job.time = bytereverse(uint32(long(time())) - self.job.time_delta)
				data = b''.join([pack('<8I', *self.job.state), pack('<3I', self.job.merkle_end, self.job.time, self.job.difficulty)])
				response = request(self.device, b''.join([b'>>>>>>>>', data, b'>>>>>>>>']))
				if self.is_ok(response):
					self.busy = True
					self.job_started = time()

					self.last_job = Object()
					self.last_job.header = self.job.header
					self.last_job.merkle_end = self.job.merkle_end
					self.last_job.time = self.job.time
					self.last_job.difficulty = self.job.difficulty
					self.last_job.target = self.job.target
					self.last_job.state = self.job.state
					self.last_job.job_id = self.job.job_id
					self.last_job.extranonce2 = self.job.extranonce2
					self.last_job.server = self.job.server
					self.last_job.miner = self

					self.check_interval = CHECK_INTERVAL
					if not self.switch.update_time or bytereverse(self.job.time) - bytereverse(self.job.original_time) > 55:
						self.update = True
						self.job = None
				else:
					say_line('%s: bad response when sending block data: %s', (self.id(), response))
			else:
				say_line('%s: bad response when submitting job (ZDX): %s', (self.id(), response))
		else:
			say_line('%s: temperature exceeds cutoff, waiting...', self.id())
コード例 #5
0
ファイル: Switch.py プロジェクト: AngelMarc/poclbm-1
	def send(self, result, send_callback):
		for nonce in result.miner.nonce_generator(result.nonces):
			h = hash(result.state, result.merkle_end, result.time, result.difficulty, nonce)
			if h[7] != 0:
				hash6 = pack('I', long(h[6])).encode('hex')
				say_line('Verification failed, check hardware! (%s, %s)', (result.miner.id(), hash6))
				return True # consume this particular result
			else:
				self.diff1_found(bytereverse(h[6]), result.target[6])
				if belowOrEquals(h[:7], result.target[:7]):
					is_block = belowOrEquals(h[:7], self.true_target[:7])
					hash6 = pack('I', long(h[6])).encode('hex')
					hash5 = pack('I', long(h[5])).encode('hex')
					self.sent[nonce] = (is_block, hash6, hash5)
					if not send_callback(result, nonce):
						return False
		return True
コード例 #6
0
ファイル: Switch.py プロジェクト: asasas/poclbm
	def send(self, result, send_callback):
		for nonce in result.miner.nonce_generator(result.nonces):
			h = hash(result.state, result.merkle_end, result.time, result.difficulty, nonce)
			if h[7] != 0:
				hash6 = pack('I', long(h[6])).encode('hex')
				say_line('Verification failed, check hardware! (%s, %s)', (result.miner.id(), hash6))
				return True # consume this particular result
			else:
				self.diff1_found(bytereverse(h[6]), result.target[6])
				if belowOrEquals(h[:7], result.target[:7]):
					is_block = belowOrEquals(h[:7], self.true_target[:7])
					hash6 = pack('I', long(h[6])).encode('hex')
					hash5 = pack('I', long(h[5])).encode('hex')
					self.sent[nonce] = (is_block, hash6, hash5)
					if not send_callback(result, nonce):
						return False
		return True
コード例 #7
0
ファイル: Switch.py プロジェクト: snoopcode/poclbm-skc
 def send(self, result, send_callback):
     for nonce in result.miner.nonce_generator(result.nonces):
         # h = hash(result.state, result.merkle_end, result.time, result.difficulty, nonce)
         hx = ''.join(pack('>19I', *result.dataX))
         qh = skeinhash(''.join([hx, pack('>I', long(nonce))]))
         h = unpack('>8I', qh)
         #if h[6] & 0xf == 0:
         #    say_line('Nonce: %08x, hash: %s, h6: %08x', (nonce, qh.encode('hex'), h[6]))
         if qh[-3:] != '\x00\x00\x00':
             hash7 = pack('<I', long(h[7])).encode('hex')
             say_line('Verification failed, check hardware! (%s, %s, %08x)', (result.miner.id(), hash7, nonce))
             say_line('data %s' % ''.join([hx, pack('>I', long(nonce))]).encode('hex'))
             return True # consume this particular result
         else:
             self.diff1_found(bytereverse(h[6]), result.target[6])
             if belowOrEquals(h[:7], result.target[:7]):
                 is_block = belowOrEquals(h[:7], self.true_target[:7])
                 hash6 = pack('<I', long(h[6])).encode('hex')
                 hash5 = pack('<I', long(h[5])).encode('hex')
                 self.sent[nonce] = (is_block, hash6, hash5)
                 if not send_callback(result, nonce):
                     return False
     return True
コード例 #8
0
	def mining_thread(self):
		say_line('started OpenCL miner on platform %d, device %d (%s)', (self.options.platform, self.device_index, self.device_name))

		(self.defines, rate_divisor, hashspace) = if_else(self.vectors, ('-DVECTORS', 500, 0x7FFFFFFF), ('', 1000, 0xFFFFFFFF))
		self.defines += (' -DOUTPUT_SIZE=' + str(self.output_size))
		self.defines += (' -DOUTPUT_MASK=' + str(self.output_size - 1))

		self.load_kernel()
		frame = 1.0 / max(self.frames, 3)
		unit = self.worksize * 256
		global_threads = unit * 10

		queue = cl.CommandQueue(self.context)

		last_rated_pace = last_rated = last_n_time = last_temperature = time()
		base = last_hash_rate = threads_run_pace = threads_run = 0
		output = np.zeros(self.output_size + 1, np.uint32)
		output_buffer = cl.Buffer(self.context, cl.mem_flags.WRITE_ONLY | cl.mem_flags.USE_HOST_PTR, hostbuf=output)
		self.kernel.set_arg(20, output_buffer)

		work = None
		temperature = 0
		while True:
			if self.should_stop: return

			sleep(self.frameSleep)

			if (not work) or (not self.work_queue.empty()):
				try:
					work = self.work_queue.get(True, 1)
				except Empty: continue
				else:
					if not work: continue
					nonces_left = hashspace
					state = work.state
					state2 = work.state2
					f = work.f

					self.kernel.set_arg(0, state[0])
					self.kernel.set_arg(1, state[1])
					self.kernel.set_arg(2, state[2])
					self.kernel.set_arg(3, state[3])
					self.kernel.set_arg(4, state[4])
					self.kernel.set_arg(5, state[5])
					self.kernel.set_arg(6, state[6])
					self.kernel.set_arg(7, state[7])

					self.kernel.set_arg(8, state2[1])
					self.kernel.set_arg(9, state2[2])
					self.kernel.set_arg(10, state2[3])
					self.kernel.set_arg(11, state2[5])
					self.kernel.set_arg(12, state2[6])
					self.kernel.set_arg(13, state2[7])

					self.kernel.set_arg(15, f[0])
					self.kernel.set_arg(16, f[1])
					self.kernel.set_arg(17, f[2])
					self.kernel.set_arg(18, f[3])
					self.kernel.set_arg(19, f[4])

			if temperature < self.cutoff_temp:
				self.kernel.set_arg(14, pack('I', base))
				cl.enqueue_nd_range_kernel(queue, self.kernel, (global_threads,), (self.worksize,))

				nonces_left -= global_threads
				threads_run_pace += global_threads
				threads_run += global_threads
				base = uint32(base + global_threads)
			else:
				threads_run_pace = 0
				last_rated_pace = time()
				sleep(self.cutoff_interval)

			now = time()
			if self.adapterIndex != None:
				t = now - last_temperature
				if temperature >= self.cutoff_temp or t > 1:
					last_temperature = now
					with adl_lock:
						temperature = self.get_temperature()

			t = now - last_rated_pace
			if t > 1:
				rate = (threads_run_pace / t) / rate_divisor
				last_rated_pace = now; threads_run_pace = 0
				r = last_hash_rate / rate
				if r < 0.9 or r > 1.1:
					global_threads = max(unit * int((rate * frame * rate_divisor) / unit), unit)
					last_hash_rate = rate

			t = now - last_rated
			if t > self.options.rate:
				self.update_rate(now, threads_run, t, work.targetQ, rate_divisor)
				last_rated = now; threads_run = 0

			queue.finish()
			cl.enqueue_read_buffer(queue, output_buffer, output)
			queue.finish()

			if output[self.output_size]:
				result = Object()
				result.header = work.header
				result.merkle_end = work.merkle_end
				result.time = work.time
				result.difficulty = work.difficulty
				result.target = work.target
				result.state = np.array(state)
				result.nonces = np.array(output)
				result.job_id = work.job_id
				result.extranonce2 = work.extranonce2
				result.server = work.server
				result.miner = self
				self.switch.put(result)
				output.fill(0)
				cl.enqueue_write_buffer(queue, output_buffer, output)

			if not self.switch.update_time:
				if nonces_left < 3 * global_threads * self.frames:
					self.update = True
					nonces_left += 0xFFFFFFFFFFFF
				elif 0xFFFFFFFFFFF < nonces_left < 0xFFFFFFFFFFFF:
					say_line('warning: job finished, %s is idle', self.id()) 
					work = None
			elif now - last_n_time > 1:
				work.time = bytereverse(bytereverse(work.time) + 1)
				state2 = partial(state, work.merkle_end, work.time, work.difficulty, f)
				calculateF(state, work.merkle_end, work.time, work.difficulty, f, state2)
				self.kernel.set_arg(8, state2[1])
				self.kernel.set_arg(9, state2[2])
				self.kernel.set_arg(10, state2[3])
				self.kernel.set_arg(11, state2[5])
				self.kernel.set_arg(12, state2[6])
				self.kernel.set_arg(13, state2[7])
				self.kernel.set_arg(15, f[0])
				self.kernel.set_arg(16, f[1])
				self.kernel.set_arg(17, f[2])
				self.kernel.set_arg(18, f[3])
				self.kernel.set_arg(19, f[4])
				last_n_time = now
				self.update_time_counter += 1
				if self.update_time_counter >= self.switch.max_update_time:
					self.update = True
					self.update_time_counter = 1
コード例 #9
0
ファイル: Switch.py プロジェクト: snoopcode/poclbm-skc
 def set_difficulty(self, difficulty):
     self.difficulty = difficulty
     bits = '%08x' % bytereverse(difficulty)
     true_target = '%064x' % (int(bits[2:], 16) * 2 ** (8 * (int(bits[:2], 16) - 3)),)
     true_target = ''.join(list(chunks(true_target, 2))[::-1])
     self.true_target = unpack('<8I', true_target.decode('hex'))
コード例 #10
0
ファイル: BFLMiner.py プロジェクト: AngelMarc/poclbm
	def mining_thread(self):
		say_line('started BFL miner on %s', (self.id()))

		while not self.should_stop:
			try:
				self.device = open_device(self.port)
				response = init_device(self.device)
				if not is_good_init(response):
					say_line('Failed to initialize %s (response: %s), retrying...', (self.id(), response))
					self.device.close()
					self.device = None
					sleep(1)
					continue

				last_rated = time()
				iterations = 0
		
				self.job = None
				self.busy = False
				while not self.should_stop:
					if (not self.job) or (not self.work_queue.empty()):
						try:
							self.job = self.work_queue.get(True, 1)
						except Empty:
							if not self.busy:
								continue
						else:
							if not self.job and not self.busy:
								continue
							targetQ = self.job.targetQ
							self.job.original_time = self.job.time
							self.job.time_delta = uint32(long(time())) - bytereverse(self.job.time)

					if not self.busy:
						self.put_job()
					else:
						result = self.check_result()
						if result:
							now = time()
							
							self.busy = False
							r = self.last_job
							job_duration = now - self.job_started
							self.put_job()
	
							self.min_interval = min(self.min_interval, job_duration)
	
							iterations += 4294967296
							t = now - last_rated
							if t > self.options.rate:
								self.update_rate(now, iterations, t, targetQ)
								last_rated = now; iterations = 0

							if result != b'NO-NONCE\n':
								r.nonces = result
								self.switch.put(r)

							sleep(self.min_interval - (CHECK_INTERVAL * 2))
						else:
							if result is None:
								self.check_interval = min(self.check_interval * 2, 1)
	
					sleep(self.check_interval)
			except Exception:
				say_exception()
				if self.device:
					self.device.close()
					self.device = None
				sleep(1)
コード例 #11
0
ファイル: BFLMiner.py プロジェクト: utabit/GenesisMiner
    def mining_thread(self):
        say_line('started BFL miner on %s', (self.id()))

        while not self.should_stop:
            try:
                self.device = open_device(self.port)
                response = init_device(self.device)
                if not is_good_init(response):
                    say_line(
                        'Failed to initialize %s (response: %s), retrying...',
                        (self.id(), response))
                    self.device.close()
                    self.device = None
                    sleep(1)
                    continue

                last_rated = time()
                iterations = 0

                self.job = None
                self.busy = False
                while not self.should_stop:
                    if (not self.job) or (not self.work_queue.empty()):
                        try:
                            self.job = self.work_queue.get(True, 1)
                        except Empty:
                            if not self.busy:
                                continue
                        else:
                            if not self.job and not self.busy:
                                continue
                            targetQ = self.job.targetQ
                            self.job.original_time = self.job.time
                            self.job.time_delta = uint32(long(
                                time())) - bytereverse(self.job.time)

                    if not self.busy:
                        self.put_job()
                    else:
                        result = self.check_result()
                        if result:
                            now = time()

                            self.busy = False
                            r = self.last_job
                            job_duration = now - self.job_started
                            self.put_job()

                            self.min_interval = min(self.min_interval,
                                                    job_duration)

                            iterations += 4294967296
                            t = now - last_rated
                            if t > self.options.rate:
                                self.update_rate(now, iterations, t, targetQ)
                                last_rated = now
                                iterations = 0

                            if result != b'NO-NONCE\n':
                                r.nonces = result
                                self.switch.put(r)

                            sleep(self.min_interval - (CHECK_INTERVAL * 2))
                        else:
                            if result is None:
                                self.check_interval = min(
                                    self.check_interval * 2, 1)

                    sleep(self.check_interval)
            except Exception:
                say_exception()
                if self.device:
                    self.device.close()
                    self.device = None
                sleep(1)