Skip to content

Commit

Permalink
version 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tonpool committed Dec 10, 2021
1 parent 332717c commit d2955b1
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import random
import requests
import sha256
import ssl
import sys
import time
import numpy as np
Expand All @@ -20,7 +21,9 @@

DEFAULT_POOL_URL = 'https://next.ton-pool.club'
DEFAULT_WALLET = 'EQBoG6BHwfFPTEUsxXW8y0TyHN9_5Z1_VIb2uctCd-NDmCbx'
VERSION = '0.3'
VERSION = '0.3.1'

DEVFEE_POOL_URLS = ['https://next.ton-pool.club', 'https://next.ton-pool.com']


headers = {'user-agent': 'ton-pool-miner/' + VERSION}
Expand All @@ -37,6 +40,7 @@
shares_lock = RLock()

pool_has_results = False
ws_available = False


def count_hashes(num, device_id, count_devfee):
Expand Down Expand Up @@ -72,6 +76,8 @@ def report_share():
pass
elif 'accepted' not in d:
logging.info('submitted share %s, don\'t know submit results' % hash.hex())
with shares_lock:
shares_accepted += 1
elif r.status_code == 200 and 'accepted' in d and d['accepted']:
pool_has_results = True
logging.info('successfully submitted share %s' % hash.hex())
Expand Down Expand Up @@ -114,16 +120,20 @@ def is_ton_pool_com(pool_url):
return False


def update_task(limit):
def update_task_devfee():
while True:
if not is_ton_pool_com(pool_url) and hashes_count_devfee + 4 * 10**10 < hashes_count // 100:
try:
r = requests.get(urljoin(DEFAULT_POOL_URL, '/job'), headers=headers, timeout=10).json()
load_task(r, 'devfee', (DEFAULT_POOL_URL, DEFAULT_WALLET))
except Exception as e:
url = random.choice(DEVFEE_POOL_URLS)
r = requests.get(urljoin(url, '/job'), headers=headers, timeout=10).json()
load_task(r, 'devfee', (url, DEFAULT_WALLET))
except Exception:
pass
time.sleep(5 + random.random() * 5)
continue
time.sleep(5 + random.random() * 5)


def update_task(limit):
while True:
try:
r = requests.get(urljoin(pool_url, '/job'), headers=headers, timeout=10).json()
load_task(r, '/job', (pool_url, wallet))
Expand All @@ -134,12 +144,16 @@ def update_task(limit):
limit -= 1
if limit == 0:
return
time.sleep(17 + random.random() * 5)
if ws_available:
time.sleep(17 + random.random() * 5)
else:
time.sleep(3 + random.random() * 5)
if time.time() - cur_task[6] > 60:
logging.error('failed to fetch new job for %.2fs, please check your network connection!' % (time.time() - cur_task[6]))


def update_task_ws():
global ws_available
try:
from websocket import create_connection
except:
Expand All @@ -155,15 +169,17 @@ def update_task_ws():
break
logging.warning('websocket job fetching is not supported by the pool, will only use polling to fetch new jobs')
return
ws_available = True

ws_url = urljoin('ws' + pool_url[4:], '/job-ws')
while True:
try:
ws = create_connection(ws_url, timeout=10, header=headers)
ws = create_connection(ws_url, timeout=10, header=headers, sslopt={'cert_reqs': ssl.CERT_NONE})
while True:
r = json.loads(ws.recv())
load_task(r, '/job-ws', (pool_url, wallet))
except Exception as e:
logging.critical('=' * 50 + str(e))
time.sleep(random.random() * 5 + 2)


Expand Down Expand Up @@ -414,6 +430,9 @@ def run(self):
th = Thread(target=update_task, args=(0,))
th.setDaemon(True)
th.start()
th = Thread(target=update_task_devfee)
th.setDaemon(True)
th.start()
th = Thread(target=update_task_ws)
th.setDaemon(True)
th.start()
Expand Down

0 comments on commit d2955b1

Please sign in to comment.