try to support xmrig
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
stratum_proxy.py
|
||||
RinCoin Stratum Proxy Server
|
||||
DEBUG RPC: we get node logs with 'docker logs --tail=200 rincoin-node'
|
||||
MINE: /mnt/shared/DEV/repos/d-popov.com/mines/rin/miner/cpuminer-opt-rin/cpuminer -a rinhash -o stratum+tcp://localhost:3334 -u x -p x -t 32
|
||||
@@ -807,11 +808,16 @@ class RinCoinStratumProxy:
|
||||
def handle_stratum_message(self, client, addr, message):
|
||||
"""Handle incoming Stratum message from miner"""
|
||||
try:
|
||||
# Debug: log raw message
|
||||
print(f"[{addr}] Raw message: {repr(message)}")
|
||||
|
||||
data = json.loads(message.strip())
|
||||
method = data.get("method")
|
||||
msg_id = data.get("id")
|
||||
params = data.get("params", [])
|
||||
|
||||
print(f"[{addr}] Parsed: method={method}, id={msg_id}, params={params}")
|
||||
|
||||
if method == "mining.subscribe":
|
||||
# Generate unique extranonce1 for this connection
|
||||
self.extranonce1_counter += 1
|
||||
@@ -858,6 +864,43 @@ class RinCoinStratumProxy:
|
||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f"[{timestamp}] 🔐 [{addr}] Authorized as {username}")
|
||||
|
||||
elif method == "login":
|
||||
# Handle xmrig's login method (JSON-RPC format with object params)
|
||||
if isinstance(params, dict):
|
||||
# xmrig format: {"login": "username", "pass": "password", "agent": "...", "algo": [...]}
|
||||
username = params.get('login', 'anonymous')
|
||||
password = params.get('pass', 'x')
|
||||
agent = params.get('agent', 'unknown')
|
||||
algorithms = params.get('algo', [])
|
||||
else:
|
||||
# Standard stratum format: ["username", "password"]
|
||||
username = params[0] if params else "anonymous"
|
||||
password = params[1] if len(params) > 1 else "x"
|
||||
agent = "unknown"
|
||||
algorithms = []
|
||||
|
||||
self.clients[addr]['username'] = username
|
||||
self.clients[addr]['password'] = password
|
||||
self.clients[addr]['agent'] = agent
|
||||
self.clients[addr]['algorithms'] = algorithms
|
||||
|
||||
# Check if rinhash is supported
|
||||
rinhash_supported = any('rinhash' in algo.lower() or 'rin' in algo.lower() for algo in algorithms)
|
||||
if not rinhash_supported:
|
||||
print(f"[{addr}] Warning: rinhash not in supported algorithms: {algorithms}")
|
||||
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f"[{timestamp}] 🔐 [{addr}] xmrig Login as {username} (agent: {agent})")
|
||||
print(f"[{addr}] Supported algorithms: {algorithms}")
|
||||
|
||||
# Send initial job after login
|
||||
if self.current_job:
|
||||
self.send_job_to_client(client, self.current_job)
|
||||
else:
|
||||
if self.get_block_template():
|
||||
self.send_job_to_client(client, self.current_job)
|
||||
|
||||
elif method == "mining.extranonce.subscribe":
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
|
||||
@@ -893,10 +936,12 @@ class RinCoinStratumProxy:
|
||||
print(f"[{addr}] Unknown method: {method}")
|
||||
self.send_stratum_response(client, msg_id, None, "Unknown method")
|
||||
|
||||
except json.JSONDecodeError:
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"[{addr}] Invalid JSON: {message}")
|
||||
print(f"[{addr}] JSON Error: {e}")
|
||||
except Exception as e:
|
||||
print(f"[{addr}] Message handling error: {e}")
|
||||
print(f"[{addr}] Error type: {type(e).__name__}")
|
||||
|
||||
def send_job_to_client(self, client, job):
|
||||
"""Send mining job to specific client with proper stratum parameters"""
|
||||
@@ -1293,10 +1338,10 @@ if __name__ == "__main__":
|
||||
elif arg == "--submit-threshold" and i + 1 < len(sys.argv):
|
||||
try:
|
||||
submit_threshold = float(sys.argv[i + 1])
|
||||
if submit_threshold <= 0 or submit_threshold > 1:
|
||||
print(f"❌ Invalid threshold {submit_threshold}. Must be between 0 and 1 (0-100%)")
|
||||
if submit_threshold <= 0:
|
||||
print(f"❌ Invalid threshold {submit_threshold}. Must be greater than 0")
|
||||
sys.exit(1)
|
||||
print(f"🧪 DEBUG MODE: Will submit blocks at {submit_threshold*100:.1f}% of network difficulty")
|
||||
print(f"🧪 DEBUG MODE: Will submit blocks at {submit_threshold:.1f}x network difficulty")
|
||||
except ValueError:
|
||||
print(f"❌ Invalid threshold value: {sys.argv[i + 1]}")
|
||||
sys.exit(1)
|
||||
|
Reference in New Issue
Block a user