def process_mineDUCO(hashcount, accepted, rejected, job_request_bytes): soc = socket.socket() soc.settimeout(16.0) try: soc.connect((pool_ip, pool_port)) soc.recv(3) # Receive version, but don't bother decoding start_time = time.time() compute_start_time = time.time() while time.time() < start_time + AUTO_RESTART_TIME: soc.send(job_request_bytes) job = soc.recv(1024) # Receive work byte-string from pool prefix_bytes = job[0:40] # Prefix is first 40 bytes target_bytes = job[41:81] # Target is 40 bytes after comma difficulty = int(job[82:]) # Difficulty is all bytes after second comma in utf-8 result = nonceMiner.c_mine_DUCO_S1(prefix_bytes, target_bytes, difficulty) compute_end_time = time.time() local_hashrate = int(result/(compute_end_time-compute_start_time)) compute_start_time = compute_end_time # Send result of hashing algorithm to pool along with metadata soc.send(f'{result},{local_hashrate},nonceMiner_{MINER_VERSION}'.encode('utf-8')) feedback_bytes = soc.recv(1024) # Receive feedback, don't bother decoding # Update counters according to feedback with hashcount.get_lock(): hashcount.value += result if feedback_bytes == b'GOOD' or feedback_bytes == b'BLOCK': with accepted.get_lock(): accepted.value += 1 else: with rejected.get_lock(): rejected.value += 1 soc.close() return except (OSError, KeyboardInterrupt): # Handle socket errors and KeyboardInterrupt the same, with a restart soc.close() return except: # TODO: Gracefully report other encountered exceptions before restarting as well soc.close() return
def process_mineDUCO(hashcount, job_request_bytes): soc = socket.socket() soc.settimeout(16.0) try: soc.connect((pool_ip, pool_port)) soc.recv(3) # Receive version, but don't bother decoding start_time = time.time() compute_start_time = time.time() while time.time() < start_time + AUTO_RESTART_TIME: soc.send(job_request_bytes) job = soc.recv(1024) # Receive work byte-string from pool prefix_bytes = job[0:40] # Prefix is first 40 bytes target_bytes = job[41:81] # Target is 40 bytes after comma difficulty = int( job[82:] ) # Difficulty is all bytes after second comma in utf-8 result = nonceMiner.c_mine_DUCO_S1(prefix_bytes, target_bytes, difficulty) compute_end_time = time.time() local_hashrate = int(result / (compute_end_time - compute_start_time)) compute_start_time = compute_end_time # Send result of hashing algorithm to pool along with metadata soc.send(('%i,%i,nonceMiner_%s' % (result, local_hashrate, MINER_VERSION)).encode('utf-8')) soc.recv(1024) # Receive feedback, don't bother decoding with hashcount.get_lock(): hashcount.value += result soc.close() return except: soc.close() return
with urllib.request.urlopen(serverip) as content: content = content.read().decode().splitlines( ) #Read content and split into lines pool_address = content[0] #Line 1 = pool address pool_port = content[1] #Line 2 = pool port # This section connects and logs user to the server soc.connect((str(pool_address), int(pool_port))) # Connect to the server server_version = soc.recv(3).decode() # Get server version print('Server is on version', server_version) # Mining section while True: soc.send(bytes('JOB,' + str(username), encoding='utf8')) # Send job request job = soc.recv(1024) # Receive work byte-string from pool prefix_bytes = job[0:40] # Prefix is first 40 bytes target_bytes = job[41:81] # Target is 40 bytes after comma difficulty = int( job[82:]) # Difficulty is all bytes after second comma in utf-8 result = nonceMiner.c_mine_DUCO_S1(prefix_bytes, target_bytes, difficulty) soc.send( bytes(str(result), encoding='utf8')) # Send result of hashing algorithm to pool feedback = soc.recv(1024).decode() # Get feedback about the result if feedback == 'GOOD': # If result was good print('Accepted share', result, 'Difficulty', difficulty) elif feedback == 'BAD': # If result was bad print('Rejected share', result, 'Difficulty', difficulty)
def process_mineDUCO( hashcount, accepted, rejected, job_request_bytes, thread_i, thread_c, reconnect: bool = False, ): if TOR_PROXY: soc = socks.socksocket() else: soc = socket.socket() soc.settimeout(10.0) try: soc.connect((pool_ip, pool_port)) if not reconnect: log( "sys", f"connected to \033[36;1m{pool_ip}:{pool_port}\033[0m pool ({thread_i}/{thread_c})", ) else: log("sys", f"reconnected ({thread_i}/{thread_c})") log("net", f'\033[33mserver version: {soc.recv(3).decode("utf-8")}\033[0m') start_time = time.time() compute_start_time = time.time() while time.time() < start_time + AUTO_RESTART_TIME: soc.send(job_request_bytes) job = soc.recv(1024) # Receive work byte-string from pool prefix_bytes = job[0:40] # Prefix is first 40 bytes target_bytes = job[41:81] # Target is 40 bytes after comma difficulty = int( job[82:] ) # Difficulty is all bytes after second comma in utf-8 log("net", f"\033[35;1mnew job\033[0m diff {difficulty}") result = nonceMiner.c_mine_DUCO_S1(prefix_bytes, target_bytes, difficulty) compute_end_time = time.time() local_hashrate = int(result / (compute_end_time - compute_start_time)) compute_start_time = compute_end_time # Send result of hashing algorithm to pool along with metadata soc.send(f"{result},{local_hashrate},DUCO M1N3R,{RIG_ID}".encode( "utf-8")) feedback_bytes = soc.recv( 1024) # Receive feedback, don't bother decoding # Update counters according to feedback with hashcount.get_lock(): hashcount.value += result if feedback_bytes == b"GOOD" or feedback_bytes == b"BLOCK": with accepted.get_lock(): accepted.value += 1 log( "cpu", f"\033[32maccepted\033[0m share {result} ({accepted.value}/{rejected.value})", ) else: with rejected.get_lock(): rejected.value += 1 log( "cpu", f"\033[31mrejected\033[0m share {result} ({accepted.value}/{rejected.value})", ) soc.close() return except ( OSError, KeyboardInterrupt, ): # Handle socket errors and KeyboardInterrupt the same, with a restart soc.close() return except: # TODO: Gracefully report other encountered exceptions before restarting as well soc.close() return