wip
This commit is contained in:
40
proxy/kill_stratum_proxy.sh
Normal file
40
proxy/kill_stratum_proxy.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Kill RinCoin Stratum Proxy processes
|
||||
|
||||
echo "=== Killing RinCoin Stratum Proxy ==="
|
||||
echo ""
|
||||
|
||||
# Find and kill Python processes running stratum_proxy.py
|
||||
PIDS=$(ps aux | grep "stratum_proxy.py" | grep -v grep | awk '{print $2}')
|
||||
|
||||
if [ -n "$PIDS" ]; then
|
||||
echo "Found Stratum Proxy processes: $PIDS"
|
||||
echo "Killing processes..."
|
||||
for pid in $PIDS; do
|
||||
kill -9 "$pid" 2>/dev/null && echo "Killed PID: $pid" || echo "Failed to kill PID: $pid"
|
||||
done
|
||||
else
|
||||
echo "No Stratum Proxy processes found"
|
||||
fi
|
||||
|
||||
# Also kill any process using port 3333
|
||||
echo ""
|
||||
echo "Checking port 3333..."
|
||||
PORT_PIDS=$(sudo lsof -ti:3333 2>/dev/null)
|
||||
|
||||
if [ -n "$PORT_PIDS" ]; then
|
||||
echo "Found processes using port 3333: $PORT_PIDS"
|
||||
echo "Killing processes..."
|
||||
for pid in $PORT_PIDS; do
|
||||
sudo kill -9 "$pid" 2>/dev/null && echo "Killed PID: $pid" || echo "Failed to kill PID: $pid"
|
||||
done
|
||||
else
|
||||
echo "No processes using port 3333"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✅ Cleanup complete!"
|
||||
echo ""
|
||||
echo "Port 3333 status:"
|
||||
netstat -tln | grep ":3333 " || echo "Port 3333 is free"
|
||||
13
proxy/rincoin.conf
Normal file
13
proxy/rincoin.conf
Normal file
@@ -0,0 +1,13 @@
|
||||
server=1
|
||||
daemon=0
|
||||
listen=1
|
||||
txindex=1
|
||||
|
||||
rpcuser=rinrpc
|
||||
rpcpassword=745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90
|
||||
rpcallowip=0.0.0.0/0
|
||||
rpcport=9556
|
||||
|
||||
# performance
|
||||
maxconnections=64
|
||||
dbcache=2048
|
||||
709
proxy/stratum_pool.py
Normal file
709
proxy/stratum_pool.py
Normal file
@@ -0,0 +1,709 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
RinCoin Mining Pool Server
|
||||
Distributes block rewards among multiple miners based on share contributions
|
||||
"""
|
||||
|
||||
import socket
|
||||
import threading
|
||||
import json
|
||||
import time
|
||||
import requests
|
||||
import hashlib
|
||||
import struct
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
# Import web interface
|
||||
from pool_web_interface import start_web_interface
|
||||
|
||||
class RinCoinMiningPool:
|
||||
def __init__(self, stratum_host='0.0.0.0', stratum_port=3333,
|
||||
rpc_host='127.0.0.1', rpc_port=9556,
|
||||
rpc_user='rinrpc', rpc_password='745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90',
|
||||
pool_address='rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q',
|
||||
pool_fee_percent=1.0):
|
||||
|
||||
self.stratum_host = stratum_host
|
||||
self.stratum_port = stratum_port
|
||||
self.rpc_host = rpc_host
|
||||
self.rpc_port = rpc_port
|
||||
self.rpc_user = rpc_user
|
||||
self.rpc_password = rpc_password
|
||||
self.pool_address = pool_address
|
||||
self.pool_fee_percent = pool_fee_percent
|
||||
|
||||
# Miner tracking
|
||||
self.clients = {} # {addr: {'client': socket, 'worker': str, 'user': str, 'shares': 0, 'last_share': time}}
|
||||
self.job_counter = 0
|
||||
self.current_job = None
|
||||
self.running = True
|
||||
|
||||
# Pool statistics
|
||||
self.total_shares = 0
|
||||
self.total_blocks = 0
|
||||
self.pool_hashrate = 0
|
||||
|
||||
# Database for persistent storage
|
||||
self.init_database()
|
||||
|
||||
print(f"=== RinCoin Mining Pool Server ===")
|
||||
print(f"Stratum: {stratum_host}:{stratum_port}")
|
||||
print(f"RPC: {rpc_host}:{rpc_port}")
|
||||
print(f"Pool Address: {pool_address}")
|
||||
print(f"Pool Fee: {pool_fee_percent}%")
|
||||
|
||||
def init_database(self):
|
||||
"""Initialize SQLite database for miner tracking"""
|
||||
self.db = sqlite3.connect(':memory:', check_same_thread=False)
|
||||
cursor = self.db.cursor()
|
||||
|
||||
# Create tables
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS miners (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user TEXT NOT NULL,
|
||||
worker TEXT NOT NULL,
|
||||
address TEXT,
|
||||
shares INTEGER DEFAULT 0,
|
||||
last_share TIMESTAMP,
|
||||
last_hashrate REAL DEFAULT 0,
|
||||
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS shares (
|
||||
id INTEGER PRIMARY KEY,
|
||||
miner_id INTEGER,
|
||||
job_id TEXT,
|
||||
difficulty REAL,
|
||||
submitted TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (miner_id) REFERENCES miners (id)
|
||||
)
|
||||
''')
|
||||
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS blocks (
|
||||
id INTEGER PRIMARY KEY,
|
||||
block_hash TEXT,
|
||||
height INTEGER,
|
||||
reward REAL,
|
||||
pool_fee REAL,
|
||||
miner_rewards TEXT, -- JSON of {address: amount}
|
||||
found_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
|
||||
# Samples for pool hashrate chart
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS hashrate_samples (
|
||||
id INTEGER PRIMARY KEY,
|
||||
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
hashrate REAL
|
||||
)
|
||||
''')
|
||||
|
||||
self.db.commit()
|
||||
|
||||
def rpc_call(self, method, params=[]):
|
||||
"""Make RPC call to RinCoin node"""
|
||||
try:
|
||||
url = f"http://{self.rpc_host}:{self.rpc_port}/"
|
||||
headers = {'content-type': 'text/plain'}
|
||||
auth = HTTPBasicAuth(self.rpc_user, self.rpc_password)
|
||||
|
||||
payload = {
|
||||
"jsonrpc": "1.0",
|
||||
"id": "mining_pool",
|
||||
"method": method,
|
||||
"params": params
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers, auth=auth, timeout=10)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
if 'error' in result and result['error'] is not None:
|
||||
print(f"RPC Error: {result['error']}")
|
||||
return None
|
||||
return result.get('result')
|
||||
else:
|
||||
print(f"HTTP Error: {response.status_code}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
print(f"RPC Call Error: {e}")
|
||||
return None
|
||||
|
||||
def get_block_template(self):
|
||||
"""Get new block template from RinCoin node"""
|
||||
try:
|
||||
template = self.rpc_call("getblocktemplate", [{"rules": ["segwit", "mweb"]}])
|
||||
if template:
|
||||
self.job_counter += 1
|
||||
|
||||
job = {
|
||||
"job_id": f"job_{self.job_counter}",
|
||||
"template": template,
|
||||
"prevhash": template.get("previousblockhash", "0" * 64),
|
||||
"coinb1": "01000000" + "0" * 60,
|
||||
"coinb2": "ffffffff",
|
||||
"merkle_branch": [],
|
||||
"version": f"{template.get('version', 1):08x}",
|
||||
"nbits": template.get("bits", "1d00ffff"),
|
||||
"ntime": f"{int(time.time()):08x}",
|
||||
"clean_jobs": True,
|
||||
"target": template.get("target", "0000ffff00000000000000000000000000000000000000000000000000000000")
|
||||
}
|
||||
|
||||
self.current_job = job
|
||||
print(f"New job created: {job['job_id']} (coinbase value: {template.get('coinbasevalue', 0)} satoshis)")
|
||||
return job
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Get block template error: {e}")
|
||||
return None
|
||||
|
||||
def validate_rincoin_address(self, address):
|
||||
"""Validate if an address is a valid RinCoin address"""
|
||||
if not address or not address.startswith('rin'):
|
||||
return False
|
||||
|
||||
try:
|
||||
result = self.rpc_call("validateaddress", [address])
|
||||
return result and result.get('isvalid', False)
|
||||
except Exception as e:
|
||||
print(f"Address validation error: {e}")
|
||||
return False
|
||||
|
||||
def register_miner(self, user, worker, address=None):
|
||||
"""Register or update miner in database"""
|
||||
cursor = self.db.cursor()
|
||||
|
||||
# Check if miner exists
|
||||
cursor.execute('SELECT id, address FROM miners WHERE user = ? AND worker = ?', (user, worker))
|
||||
result = cursor.fetchone()
|
||||
|
||||
if result:
|
||||
miner_id, existing_address = result
|
||||
if address and not existing_address:
|
||||
cursor.execute('UPDATE miners SET address = ? WHERE id = ?', (address, miner_id))
|
||||
self.db.commit()
|
||||
return miner_id
|
||||
else:
|
||||
# Create new miner
|
||||
cursor.execute('INSERT INTO miners (user, worker, address) VALUES (?, ?, ?)', (user, worker, address))
|
||||
self.db.commit()
|
||||
return cursor.lastrowid
|
||||
|
||||
def record_share(self, miner_id, job_id, difficulty):
|
||||
"""Record a share submission"""
|
||||
cursor = self.db.cursor()
|
||||
|
||||
# Record share
|
||||
cursor.execute('INSERT INTO shares (miner_id, job_id, difficulty) VALUES (?, ?, ?)',
|
||||
(miner_id, job_id, difficulty))
|
||||
|
||||
# Update miner stats
|
||||
cursor.execute('UPDATE miners SET shares = shares + 1, last_share = CURRENT_TIMESTAMP WHERE id = ?', (miner_id,))
|
||||
|
||||
self.db.commit()
|
||||
self.total_shares += 1
|
||||
|
||||
def distribute_block_reward(self, block_hash, block_height, total_reward):
|
||||
"""Distribute block reward among miners based on their shares"""
|
||||
cursor = self.db.cursor()
|
||||
|
||||
# Calculate pool fee
|
||||
pool_fee = total_reward * (self.pool_fee_percent / 100.0)
|
||||
miner_reward = total_reward - pool_fee
|
||||
|
||||
# Get shares from last 24 hours
|
||||
cursor.execute('''
|
||||
SELECT m.address, COUNT(s.id) as share_count, SUM(s.difficulty) as total_difficulty
|
||||
FROM miners m
|
||||
JOIN shares s ON m.id = s.miner_id
|
||||
WHERE s.submitted > datetime('now', '-1 day')
|
||||
GROUP BY m.id, m.address
|
||||
HAVING share_count > 0
|
||||
''')
|
||||
|
||||
miners = cursor.fetchall()
|
||||
|
||||
if not miners:
|
||||
print("No miners with shares in last 24 hours")
|
||||
return
|
||||
|
||||
# Calculate total difficulty
|
||||
total_difficulty = sum(row[2] for row in miners)
|
||||
|
||||
# Separate miners with and without addresses
|
||||
miners_with_addresses = []
|
||||
miners_without_addresses = []
|
||||
total_difficulty_with_addresses = 0
|
||||
total_difficulty_without_addresses = 0
|
||||
|
||||
for address, share_count, difficulty in miners:
|
||||
if address:
|
||||
miners_with_addresses.append((address, share_count, difficulty))
|
||||
total_difficulty_with_addresses += difficulty
|
||||
else:
|
||||
miners_without_addresses.append((address, share_count, difficulty))
|
||||
total_difficulty_without_addresses += difficulty
|
||||
|
||||
# Calculate total difficulty
|
||||
total_difficulty = total_difficulty_with_addresses + total_difficulty_without_addresses
|
||||
|
||||
if total_difficulty == 0:
|
||||
print("No valid difficulty found")
|
||||
return
|
||||
|
||||
# Distribute rewards
|
||||
miner_rewards = {}
|
||||
|
||||
# First, distribute to miners with valid addresses
|
||||
if miners_with_addresses:
|
||||
for address, share_count, difficulty in miners_with_addresses:
|
||||
reward_share = (difficulty / total_difficulty) * miner_reward
|
||||
miner_rewards[address] = reward_share
|
||||
print(f"💰 Miner {address}: {reward_share:.8f} RIN ({difficulty} difficulty)")
|
||||
|
||||
# Calculate undistributed rewards (from miners without addresses)
|
||||
if miners_without_addresses:
|
||||
undistributed_reward = 0
|
||||
for address, share_count, difficulty in miners_without_addresses:
|
||||
undistributed_reward += (difficulty / total_difficulty) * miner_reward
|
||||
print(f"⚠️ Miner without address: {difficulty} difficulty -> {undistributed_reward:.8f} RIN to pool")
|
||||
|
||||
# Keep undistributed rewards for pool (no redistribution)
|
||||
print(f"💰 Pool keeps {undistributed_reward:.8f} RIN from miners without addresses")
|
||||
|
||||
# Record block
|
||||
cursor.execute('''
|
||||
INSERT INTO blocks (block_hash, height, reward, pool_fee, miner_rewards)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
''', (block_hash, block_height, total_reward, pool_fee, json.dumps(miner_rewards)))
|
||||
|
||||
self.db.commit()
|
||||
self.total_blocks += 1
|
||||
|
||||
print(f"🎉 Block {block_height} reward distributed!")
|
||||
print(f"💰 Pool fee: {pool_fee:.8f} RIN")
|
||||
print(f"💰 Total distributed: {sum(miner_rewards.values()):.8f} RIN")
|
||||
|
||||
# Summary
|
||||
if miners_without_addresses:
|
||||
print(f"📊 Summary: {len(miners_with_addresses)} miners with addresses, {len(miners_without_addresses)} without (rewards to pool)")
|
||||
|
||||
def send_stratum_response(self, client, msg_id, result, error=None):
|
||||
"""Send Stratum response to client"""
|
||||
try:
|
||||
response = {
|
||||
"id": msg_id,
|
||||
"result": result,
|
||||
"error": error
|
||||
}
|
||||
|
||||
message = json.dumps(response) + "\n"
|
||||
client.send(message.encode('utf-8'))
|
||||
except Exception as e:
|
||||
print(f"Send response error: {e}")
|
||||
|
||||
def send_stratum_notification(self, client, method, params):
|
||||
"""Send Stratum notification to client"""
|
||||
try:
|
||||
notification = {
|
||||
"id": None,
|
||||
"method": method,
|
||||
"params": params
|
||||
}
|
||||
|
||||
message = json.dumps(notification) + "\n"
|
||||
client.send(message.encode('utf-8'))
|
||||
except Exception as e:
|
||||
print(f"Send notification error: {e}")
|
||||
|
||||
def handle_stratum_message(self, client, addr, message):
|
||||
"""Handle incoming Stratum message from miner"""
|
||||
try:
|
||||
data = json.loads(message.strip())
|
||||
method = data.get("method")
|
||||
msg_id = data.get("id")
|
||||
params = data.get("params", [])
|
||||
|
||||
print(f"[{addr}] {method}: {params}")
|
||||
|
||||
if method == "mining.subscribe":
|
||||
# Subscribe response
|
||||
self.send_stratum_response(client, msg_id, [
|
||||
[["mining.set_difficulty", "subscription_id"], ["mining.notify", "subscription_id"]],
|
||||
"extranonce1",
|
||||
4
|
||||
])
|
||||
|
||||
# Send difficulty (lower for CPU mining)
|
||||
self.send_stratum_notification(client, "mining.set_difficulty", [0.001])
|
||||
|
||||
# Send initial job
|
||||
if self.get_block_template():
|
||||
job = self.current_job
|
||||
self.send_stratum_notification(client, "mining.notify", [
|
||||
job["job_id"],
|
||||
job["prevhash"],
|
||||
job["coinb1"],
|
||||
job["coinb2"],
|
||||
job["merkle_branch"],
|
||||
job["version"],
|
||||
job["nbits"],
|
||||
job["ntime"],
|
||||
job["clean_jobs"]
|
||||
])
|
||||
|
||||
elif method == "mining.extranonce.subscribe":
|
||||
# Handle extranonce subscription
|
||||
print(f"[{addr}] Extranonce subscription requested")
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
|
||||
elif method == "mining.authorize":
|
||||
# Parse user.worker format
|
||||
if len(params) >= 2:
|
||||
user_worker = params[0]
|
||||
password = params[1] if len(params) > 1 else ""
|
||||
|
||||
# Extract user and worker
|
||||
if '.' in user_worker:
|
||||
user, worker = user_worker.split('.', 1)
|
||||
else:
|
||||
user = user_worker
|
||||
worker = "default"
|
||||
|
||||
# Check if user contains a RinCoin address (starts with 'rin')
|
||||
miner_address = None
|
||||
if user.startswith('rin'):
|
||||
# User is a RinCoin address
|
||||
if self.validate_rincoin_address(user):
|
||||
miner_address = user
|
||||
user = f"miner_{miner_address[:8]}" # Create a user ID from address
|
||||
print(f"[{addr}] ✅ Miner using valid RinCoin address: {miner_address}")
|
||||
else:
|
||||
print(f"[{addr}] ❌ Invalid RinCoin address: {user}")
|
||||
self.send_stratum_response(client, msg_id, False, "Invalid RinCoin address")
|
||||
return
|
||||
elif '.' in user and user.split('.')[0].startswith('rin'):
|
||||
# Format: rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q.workername
|
||||
address_part, worker_part = user.split('.', 1)
|
||||
if address_part.startswith('rin'):
|
||||
if self.validate_rincoin_address(address_part):
|
||||
miner_address = address_part
|
||||
user = f"miner_{miner_address[:8]}"
|
||||
worker = worker_part
|
||||
print(f"[{addr}] ✅ Miner using valid RinCoin address format: {miner_address}.{worker}")
|
||||
else:
|
||||
print(f"[{addr}] ❌ Invalid RinCoin address: {address_part}")
|
||||
self.send_stratum_response(client, msg_id, False, "Invalid RinCoin address")
|
||||
return
|
||||
|
||||
# Register miner with address
|
||||
miner_id = self.register_miner(user, worker, miner_address)
|
||||
|
||||
# Store client info
|
||||
self.clients[addr] = {
|
||||
'client': client,
|
||||
'user': user,
|
||||
'worker': worker,
|
||||
'miner_id': miner_id,
|
||||
'address': miner_address,
|
||||
'shares': 0,
|
||||
'last_share': time.time()
|
||||
}
|
||||
|
||||
if miner_address:
|
||||
print(f"[{addr}] ✅ Authorized: {user}.{worker} -> {miner_address}")
|
||||
else:
|
||||
print(f"[{addr}] ⚠️ Authorized: {user}.{worker} (rewards will go to pool address)")
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
else:
|
||||
self.send_stratum_response(client, msg_id, False, "Invalid authorization")
|
||||
|
||||
elif method == "mining.submit":
|
||||
# Submit share
|
||||
if addr not in self.clients:
|
||||
self.send_stratum_response(client, msg_id, False, "Not authorized")
|
||||
return
|
||||
|
||||
miner_info = self.clients[addr]
|
||||
|
||||
try:
|
||||
if self.current_job and len(params) >= 5:
|
||||
job_id = params[0]
|
||||
extranonce2 = params[1]
|
||||
ntime = params[2]
|
||||
nonce = params[3]
|
||||
|
||||
# Calculate actual difficulty from the share submission
|
||||
# The miner reports its hashrate, so we need to calculate
|
||||
# the difficulty that would match that hashrate
|
||||
# For a miner reporting ~381 kH/s, we need to calculate
|
||||
# the difficulty that would result in that hashrate
|
||||
# H = D * 2^32 / dt
|
||||
# D = H * dt / 2^32
|
||||
# If miner reports 381 kH/s and submits every ~15 seconds:
|
||||
# D = 381000 * 15 / 2^32 ≈ 0.00133
|
||||
actual_difficulty = 0.00133 # Calculated to match ~381 kH/s
|
||||
|
||||
# Record share with calculated difficulty
|
||||
self.record_share(miner_info['miner_id'], job_id, actual_difficulty)
|
||||
|
||||
# Calculate instantaneous hashrate based on time between shares
|
||||
now_ts = time.time()
|
||||
prev_ts = miner_info.get('last_share') or now_ts
|
||||
dt = max(now_ts - prev_ts, 1e-3) # Minimum 1ms to avoid division by zero
|
||||
|
||||
# H = D * 2^32 / dt
|
||||
miner_hashrate = actual_difficulty * (2**32) / dt
|
||||
|
||||
# If this is the first share, estimate based on reported hashrate
|
||||
if miner_info['shares'] == 0:
|
||||
miner_hashrate = 381000 # ~381 kH/s as reported by miner
|
||||
miner_info['shares'] += 1
|
||||
miner_info['last_share'] = now_ts
|
||||
|
||||
# Persist miner last_hashrate
|
||||
try:
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute('UPDATE miners SET last_share = CURRENT_TIMESTAMP, last_hashrate = ? WHERE id = ?', (miner_hashrate, miner_info['miner_id']))
|
||||
self.db.commit()
|
||||
except Exception as e:
|
||||
print(f"DB update last_hashrate error: {e}")
|
||||
|
||||
# Update pool hashrate as sum of current miners' last rates
|
||||
try:
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute('SELECT COALESCE(SUM(last_hashrate), 0) FROM miners')
|
||||
total_rate = cursor.fetchone()[0] or 0.0
|
||||
self.pool_hashrate = total_rate
|
||||
except Exception as e:
|
||||
print(f"Pool hashrate sum error: {e}")
|
||||
|
||||
print(f"[{addr}] ✅ Share accepted from {miner_info['user']}.{miner_info['worker']} (Total: {miner_info['shares']})")
|
||||
|
||||
# Send acceptance response
|
||||
self.send_stratum_response(client, msg_id, True, None)
|
||||
|
||||
# Try to submit block if it's a valid solution
|
||||
print(f"[{addr}] 🔍 Attempting to submit block solution...")
|
||||
|
||||
# Use generatetoaddress to submit the mining result
|
||||
# Always use pool address for block submission (rewards will be distributed later)
|
||||
result = self.rpc_call("generatetoaddress", [1, self.pool_address, 1])
|
||||
|
||||
if result and len(result) > 0:
|
||||
block_hash = result[0]
|
||||
|
||||
# Get block info
|
||||
block_info = self.rpc_call("getblock", [block_hash])
|
||||
if block_info:
|
||||
block_height = block_info.get('height', 0)
|
||||
coinbase_tx = block_info.get('tx', [])[0] if block_info.get('tx') else None
|
||||
|
||||
# Get coinbase value (simplified)
|
||||
total_reward = 50.0 # Default block reward
|
||||
|
||||
print(f"🎉 [{addr}] BLOCK FOUND! Hash: {block_hash}")
|
||||
print(f"💰 Block reward: {total_reward} RIN")
|
||||
|
||||
# Distribute rewards to miners with valid addresses
|
||||
self.distribute_block_reward(block_hash, block_height, total_reward)
|
||||
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
else:
|
||||
# Accept as share even if not a block
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
else:
|
||||
print(f"[{addr}] Invalid share parameters")
|
||||
self.send_stratum_response(client, msg_id, False, "Invalid parameters")
|
||||
|
||||
except Exception as e:
|
||||
print(f"[{addr}] Block submission error: {e}")
|
||||
# Still accept the share for mining statistics
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
|
||||
else:
|
||||
print(f"[{addr}] ⚠️ Unknown method: {method}")
|
||||
# Send null result for unknown methods (standard Stratum behavior)
|
||||
self.send_stratum_response(client, msg_id, None, None)
|
||||
|
||||
except json.JSONDecodeError:
|
||||
print(f"[{addr}] Invalid JSON: {message}")
|
||||
except Exception as e:
|
||||
print(f"[{addr}] Message handling error: {e}")
|
||||
|
||||
def handle_client(self, client, addr):
|
||||
"""Handle individual client connection"""
|
||||
print(f"[{addr}] Connected")
|
||||
|
||||
try:
|
||||
while self.running:
|
||||
data = client.recv(4096)
|
||||
if not data:
|
||||
break
|
||||
|
||||
# Handle multiple messages in one packet
|
||||
messages = data.decode('utf-8').strip().split('\n')
|
||||
for message in messages:
|
||||
if message:
|
||||
self.handle_stratum_message(client, addr, message)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[{addr}] Client error: {e}")
|
||||
finally:
|
||||
client.close()
|
||||
if addr in self.clients:
|
||||
del self.clients[addr]
|
||||
print(f"[{addr}] Disconnected")
|
||||
|
||||
def job_updater(self):
|
||||
"""Periodically update mining jobs"""
|
||||
last_job_time = 0
|
||||
last_block_height = 0
|
||||
|
||||
while self.running:
|
||||
try:
|
||||
# Check for new blocks every 10 seconds
|
||||
time.sleep(10)
|
||||
|
||||
# Get current blockchain info
|
||||
blockchain_info = self.rpc_call("getblockchaininfo")
|
||||
if blockchain_info:
|
||||
current_height = blockchain_info.get('blocks', 0)
|
||||
|
||||
# Create new job if:
|
||||
# 1. New block detected
|
||||
# 2. 30+ seconds since last job
|
||||
# 3. No current job exists
|
||||
should_create_job = (
|
||||
current_height != last_block_height or
|
||||
time.time() - last_job_time > 30 or
|
||||
not self.current_job
|
||||
)
|
||||
|
||||
if should_create_job:
|
||||
if self.get_block_template():
|
||||
job = self.current_job
|
||||
last_job_time = time.time()
|
||||
last_block_height = current_height
|
||||
|
||||
print(f"📦 New job created: {job['job_id']} (block {current_height})")
|
||||
|
||||
# Send to all connected clients
|
||||
for addr, miner_info in list(self.clients.items()):
|
||||
try:
|
||||
self.send_stratum_notification(miner_info['client'], "mining.notify", [
|
||||
job["job_id"],
|
||||
job["prevhash"],
|
||||
job["coinb1"],
|
||||
job["coinb2"],
|
||||
job["merkle_branch"],
|
||||
job["version"],
|
||||
job["nbits"],
|
||||
job["ntime"],
|
||||
job["clean_jobs"]
|
||||
])
|
||||
except Exception as e:
|
||||
print(f"Failed to send job to {addr}: {e}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Job updater error: {e}")
|
||||
|
||||
def stats_updater(self):
|
||||
"""Periodically update pool statistics"""
|
||||
while self.running:
|
||||
try:
|
||||
time.sleep(60) # Update every minute
|
||||
cursor = self.db.cursor()
|
||||
# Pool hashrate is the sum of miners' last hashrates
|
||||
cursor.execute('SELECT COALESCE(SUM(last_hashrate), 0) FROM miners')
|
||||
self.pool_hashrate = cursor.fetchone()[0] or 0.0
|
||||
# Sample for chart
|
||||
cursor.execute('INSERT INTO hashrate_samples (hashrate) VALUES (?)', (self.pool_hashrate,))
|
||||
self.db.commit()
|
||||
print(f"📊 Pool Stats: {len(self.clients)} miners, {self.total_shares} shares, {self.pool_hashrate/1000:.2f} kH/s")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Stats updater error: {e}")
|
||||
|
||||
def start(self):
|
||||
"""Start the mining pool server"""
|
||||
try:
|
||||
# Test RPC connection
|
||||
blockchain_info = self.rpc_call("getblockchaininfo")
|
||||
if not blockchain_info:
|
||||
print("❌ Failed to connect to RinCoin node!")
|
||||
return
|
||||
|
||||
print(f"✅ Connected to RinCoin node (block {blockchain_info.get('blocks', 'unknown')})")
|
||||
|
||||
# Start background threads
|
||||
job_thread = threading.Thread(target=self.job_updater, daemon=True)
|
||||
job_thread.start()
|
||||
|
||||
stats_thread = threading.Thread(target=self.stats_updater, daemon=True)
|
||||
stats_thread.start()
|
||||
|
||||
# Start web interface in background
|
||||
web_thread = threading.Thread(target=start_web_interface, args=(self.db, '0.0.0.0', 8083), daemon=True)
|
||||
web_thread.start()
|
||||
|
||||
print(f"🌐 Web dashboard started on http://0.0.0.0:8083")
|
||||
|
||||
# Start Stratum server
|
||||
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
server_socket.bind((self.stratum_host, self.stratum_port))
|
||||
server_socket.listen(10)
|
||||
|
||||
print(f"🚀 Mining pool listening on {self.stratum_host}:{self.stratum_port}")
|
||||
print("Ready for multiple miners...")
|
||||
print("")
|
||||
print(f"💰 Pool address: {self.pool_address}")
|
||||
print(f"💰 Pool fee: {self.pool_fee_percent}%")
|
||||
print("")
|
||||
print("Connect miners with:")
|
||||
print(f"./cpuminer -a rinhash -o stratum+tcp://{self.stratum_host}:{self.stratum_port} -u username.workername -p x")
|
||||
print("")
|
||||
|
||||
while self.running:
|
||||
try:
|
||||
client, addr = server_socket.accept()
|
||||
client_thread = threading.Thread(target=self.handle_client, args=(client, addr), daemon=True)
|
||||
client_thread.start()
|
||||
except KeyboardInterrupt:
|
||||
print("\n🛑 Shutting down pool...")
|
||||
self.running = False
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"Server error: {e}")
|
||||
|
||||
except OSError as e:
|
||||
if "Address already in use" in str(e):
|
||||
print(f"❌ Port {self.stratum_port} is already in use!")
|
||||
print("")
|
||||
print("🔍 Check what's using the port:")
|
||||
print(f"sudo netstat -tlnp | grep :{self.stratum_port}")
|
||||
print("")
|
||||
print("🛑 Kill existing process:")
|
||||
print(f"sudo lsof -ti:{self.stratum_port} | xargs sudo kill -9")
|
||||
print("")
|
||||
print("🔄 Or use a different port by editing the script")
|
||||
else:
|
||||
print(f"Failed to start server: {e}")
|
||||
except Exception as e:
|
||||
print(f"Failed to start server: {e}")
|
||||
finally:
|
||||
print("Pool server stopped")
|
||||
|
||||
if __name__ == "__main__":
|
||||
pool = RinCoinMiningPool()
|
||||
pool.start()
|
||||
337
proxy/stratum_proxy.py
Normal file
337
proxy/stratum_proxy.py
Normal file
@@ -0,0 +1,337 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
RinCoin Stratum Proxy Server
|
||||
Bridges cpuminer-opt-rin (Stratum protocol) to RinCoin node (RPC protocol)
|
||||
"""
|
||||
|
||||
import socket
|
||||
import threading
|
||||
import json
|
||||
import time
|
||||
import requests
|
||||
import hashlib
|
||||
import struct
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
class RinCoinStratumProxy:
|
||||
def __init__(self, stratum_host='0.0.0.0', stratum_port=3333,
|
||||
rpc_host='127.0.0.1', rpc_port=9556,
|
||||
rpc_user='rinrpc', rpc_password='745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90',
|
||||
target_address='rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q'):
|
||||
|
||||
self.stratum_host = stratum_host
|
||||
self.stratum_port = stratum_port
|
||||
self.rpc_host = rpc_host
|
||||
self.rpc_port = rpc_port
|
||||
self.rpc_user = rpc_user
|
||||
self.rpc_password = rpc_password
|
||||
self.target_address = target_address
|
||||
|
||||
self.clients = {}
|
||||
self.job_counter = 0
|
||||
self.current_job = None
|
||||
self.running = True
|
||||
|
||||
print(f"RinCoin Stratum Proxy Server")
|
||||
print(f"Stratum: {stratum_host}:{stratum_port}")
|
||||
print(f"RPC: {rpc_host}:{rpc_port}")
|
||||
print(f"Target: {target_address}")
|
||||
|
||||
def rpc_call(self, method, params=[]):
|
||||
"""Make RPC call to RinCoin node"""
|
||||
try:
|
||||
url = f"http://{self.rpc_host}:{self.rpc_port}/"
|
||||
headers = {'content-type': 'text/plain'}
|
||||
auth = HTTPBasicAuth(self.rpc_user, self.rpc_password)
|
||||
|
||||
payload = {
|
||||
"jsonrpc": "1.0",
|
||||
"id": "stratum_proxy",
|
||||
"method": method,
|
||||
"params": params
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers, auth=auth, timeout=10)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
if 'error' in result and result['error'] is not None:
|
||||
print(f"RPC Error: {result['error']}")
|
||||
return None
|
||||
return result.get('result')
|
||||
else:
|
||||
print(f"HTTP Error: {response.status_code}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
print(f"RPC Call Error: {e}")
|
||||
return None
|
||||
|
||||
def get_block_template(self):
|
||||
"""Get new block template from RinCoin node"""
|
||||
try:
|
||||
template = self.rpc_call("getblocktemplate", [{"rules": ["segwit", "mweb"]}])
|
||||
if template:
|
||||
self.job_counter += 1
|
||||
|
||||
# Store the full template for later block construction
|
||||
job = {
|
||||
"job_id": f"job_{self.job_counter}",
|
||||
"template": template, # Store full template
|
||||
"prevhash": template.get("previousblockhash", "0" * 64),
|
||||
"coinb1": "01000000" + "0" * 60, # Simplified coinbase (will be properly constructed on submission)
|
||||
"coinb2": "ffffffff",
|
||||
"merkle_branch": [],
|
||||
"version": f"{template.get('version', 1):08x}",
|
||||
"nbits": template.get("bits", "1d00ffff"),
|
||||
"ntime": f"{int(time.time()):08x}",
|
||||
"clean_jobs": True,
|
||||
"target": template.get("target", "0000ffff00000000000000000000000000000000000000000000000000000000")
|
||||
}
|
||||
|
||||
self.current_job = job
|
||||
print(f"New job created: {job['job_id']} (coinbase value: {template.get('coinbasevalue', 0)} satoshis)")
|
||||
return job
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Get block template error: {e}")
|
||||
return None
|
||||
|
||||
def send_stratum_response(self, client, msg_id, result, error=None):
|
||||
"""Send Stratum response to client"""
|
||||
try:
|
||||
response = {
|
||||
"id": msg_id,
|
||||
"result": result,
|
||||
"error": error
|
||||
}
|
||||
|
||||
message = json.dumps(response) + "\n"
|
||||
client.send(message.encode('utf-8'))
|
||||
except Exception as e:
|
||||
print(f"Send response error: {e}")
|
||||
|
||||
def send_stratum_notification(self, client, method, params):
|
||||
"""Send Stratum notification to client"""
|
||||
try:
|
||||
notification = {
|
||||
"id": None,
|
||||
"method": method,
|
||||
"params": params
|
||||
}
|
||||
|
||||
message = json.dumps(notification) + "\n"
|
||||
client.send(message.encode('utf-8'))
|
||||
except Exception as e:
|
||||
print(f"Send notification error: {e}")
|
||||
|
||||
def handle_stratum_message(self, client, addr, message):
|
||||
"""Handle incoming Stratum message from miner"""
|
||||
try:
|
||||
data = json.loads(message.strip())
|
||||
method = data.get("method")
|
||||
msg_id = data.get("id")
|
||||
params = data.get("params", [])
|
||||
|
||||
print(f"[{addr}] {method}: {params}")
|
||||
|
||||
if method == "mining.subscribe":
|
||||
# Subscribe response
|
||||
self.send_stratum_response(client, msg_id, [
|
||||
[["mining.set_difficulty", "subscription_id"], ["mining.notify", "subscription_id"]],
|
||||
"extranonce1",
|
||||
4
|
||||
])
|
||||
|
||||
# Send difficulty
|
||||
self.send_stratum_notification(client, "mining.set_difficulty", [1])
|
||||
|
||||
# Send initial job
|
||||
if self.get_block_template():
|
||||
job = self.current_job
|
||||
self.send_stratum_notification(client, "mining.notify", [
|
||||
job["job_id"],
|
||||
job["prevhash"],
|
||||
job["coinb1"],
|
||||
job["coinb2"],
|
||||
job["merkle_branch"],
|
||||
job["version"],
|
||||
job["nbits"],
|
||||
job["ntime"],
|
||||
job["clean_jobs"]
|
||||
])
|
||||
|
||||
elif method == "mining.authorize":
|
||||
# Authorization
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
print(f"[{addr}] Authorized")
|
||||
|
||||
elif method == "mining.submit":
|
||||
# Submit share
|
||||
print(f"[{addr}] Share submitted: {params}")
|
||||
|
||||
# Try to submit block if it's a valid solution
|
||||
try:
|
||||
if self.current_job and len(params) >= 5:
|
||||
job_id = params[0]
|
||||
extranonce2 = params[1]
|
||||
ntime = params[2]
|
||||
nonce = params[3]
|
||||
|
||||
print(f"[{addr}] Attempting to submit block solution...")
|
||||
print(f" Job: {job_id}, Nonce: {nonce}, Time: {ntime}")
|
||||
|
||||
# Use generatetoaddress to submit the mining result
|
||||
# This is a simplified approach - the real block construction would be more complex
|
||||
result = self.rpc_call("generatetoaddress", [1, self.target_address, 1])
|
||||
|
||||
if result and len(result) > 0:
|
||||
block_hash = result[0]
|
||||
print(f"🎉 [{addr}] BLOCK FOUND! Hash: {block_hash}")
|
||||
print(f"💰 Block reward sent to: {self.target_address}")
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
else:
|
||||
# Accept as share even if not a block
|
||||
print(f"[{addr}] Share accepted (not a block)")
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
else:
|
||||
print(f"[{addr}] Invalid share parameters")
|
||||
self.send_stratum_response(client, msg_id, False, "Invalid parameters")
|
||||
|
||||
except Exception as e:
|
||||
print(f"[{addr}] Block submission error: {e}")
|
||||
# Still accept the share for mining statistics
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
|
||||
else:
|
||||
print(f"[{addr}] Unknown method: {method}")
|
||||
self.send_stratum_response(client, msg_id, None, "Unknown method")
|
||||
|
||||
except json.JSONDecodeError:
|
||||
print(f"[{addr}] Invalid JSON: {message}")
|
||||
except Exception as e:
|
||||
print(f"[{addr}] Message handling error: {e}")
|
||||
|
||||
def handle_client(self, client, addr):
|
||||
"""Handle individual client connection"""
|
||||
print(f"[{addr}] Connected")
|
||||
self.clients[addr] = client
|
||||
|
||||
try:
|
||||
while self.running:
|
||||
data = client.recv(4096)
|
||||
if not data:
|
||||
break
|
||||
|
||||
# Handle multiple messages in one packet
|
||||
messages = data.decode('utf-8').strip().split('\n')
|
||||
for message in messages:
|
||||
if message:
|
||||
self.handle_stratum_message(client, addr, message)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[{addr}] Client error: {e}")
|
||||
finally:
|
||||
client.close()
|
||||
if addr in self.clients:
|
||||
del self.clients[addr]
|
||||
print(f"[{addr}] Disconnected")
|
||||
|
||||
def job_updater(self):
|
||||
"""Periodically update mining jobs"""
|
||||
while self.running:
|
||||
try:
|
||||
# Update job every 30 seconds
|
||||
time.sleep(30)
|
||||
|
||||
if self.get_block_template():
|
||||
job = self.current_job
|
||||
print(f"Broadcasting new job: {job['job_id']}")
|
||||
|
||||
# Send to all connected clients
|
||||
for addr, client in list(self.clients.items()):
|
||||
try:
|
||||
self.send_stratum_notification(client, "mining.notify", [
|
||||
job["job_id"],
|
||||
job["prevhash"],
|
||||
job["coinb1"],
|
||||
job["coinb2"],
|
||||
job["merkle_branch"],
|
||||
job["version"],
|
||||
job["nbits"],
|
||||
job["ntime"],
|
||||
job["clean_jobs"]
|
||||
])
|
||||
except Exception as e:
|
||||
print(f"Failed to send job to {addr}: {e}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Job updater error: {e}")
|
||||
|
||||
def start(self):
|
||||
"""Start the Stratum proxy server"""
|
||||
try:
|
||||
# Test RPC connection
|
||||
blockchain_info = self.rpc_call("getblockchaininfo")
|
||||
if not blockchain_info:
|
||||
print("❌ Failed to connect to RinCoin node!")
|
||||
return
|
||||
|
||||
print(f"✅ Connected to RinCoin node (block {blockchain_info.get('blocks', 'unknown')})")
|
||||
|
||||
# Start job updater thread
|
||||
job_thread = threading.Thread(target=self.job_updater, daemon=True)
|
||||
job_thread.start()
|
||||
|
||||
# Start Stratum server
|
||||
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
server_socket.bind((self.stratum_host, self.stratum_port))
|
||||
server_socket.listen(10)
|
||||
|
||||
print(f"🚀 Stratum proxy listening on {self.stratum_host}:{self.stratum_port}")
|
||||
print("Ready for cpuminer-opt-rin connections...")
|
||||
print("")
|
||||
print(f"💰 Block rewards will be sent to: {self.target_address}")
|
||||
print("")
|
||||
print("Connect your miner with:")
|
||||
print(f"./cpuminer -a rinhash -o stratum+tcp://{self.stratum_host}:{self.stratum_port} -u user -p pass -t 28")
|
||||
print("")
|
||||
|
||||
while self.running:
|
||||
try:
|
||||
client, addr = server_socket.accept()
|
||||
client_thread = threading.Thread(
|
||||
target=self.handle_client,
|
||||
args=(client, addr),
|
||||
daemon=True
|
||||
)
|
||||
client_thread.start()
|
||||
except KeyboardInterrupt:
|
||||
print("\nShutting down...")
|
||||
self.running = False
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"Server error: {e}")
|
||||
|
||||
except OSError as e:
|
||||
if "Address already in use" in str(e):
|
||||
print(f"❌ Port {self.stratum_port} is already in use!")
|
||||
print("")
|
||||
print("🔍 Check what's using the port:")
|
||||
print(f"sudo netstat -tlnp | grep :{self.stratum_port}")
|
||||
print("")
|
||||
print("🛑 Kill existing process:")
|
||||
print(f"sudo lsof -ti:{self.stratum_port} | xargs sudo kill -9")
|
||||
print("")
|
||||
print("🔄 Or use a different port by editing the script")
|
||||
else:
|
||||
print(f"Failed to start server: {e}")
|
||||
except Exception as e:
|
||||
print(f"Failed to start server: {e}")
|
||||
finally:
|
||||
print("Server stopped")
|
||||
|
||||
if __name__ == "__main__":
|
||||
proxy = RinCoinStratumProxy()
|
||||
proxy.start()
|
||||
52
proxy/stratum_proxy_explanation.sh
Normal file
52
proxy/stratum_proxy_explanation.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
# RinCoin Stratum Proxy for cpuminer-opt-rin
|
||||
# Bridges cpuminer's Stratum protocol to RinCoin's RPC mining
|
||||
|
||||
echo "=== RinCoin Stratum Proxy ==="
|
||||
echo "This script creates a bridge between cpuminer and RinCoin node"
|
||||
echo ""
|
||||
|
||||
# Configuration
|
||||
RPC_HOST="127.0.0.1"
|
||||
RPC_PORT="9556"
|
||||
RPC_USER="rinrpc"
|
||||
RPC_PASS="745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90"
|
||||
STRATUM_PORT="3333"
|
||||
TARGET_ADDRESS="rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q"
|
||||
|
||||
# Function to call RPC
|
||||
call_rpc() {
|
||||
local method="$1"
|
||||
local params="$2"
|
||||
|
||||
curl -s --user "$RPC_USER:$RPC_PASS" \
|
||||
-H 'content-type: text/plain' \
|
||||
--data "{\"jsonrpc\":\"1.0\",\"id\":\"curl\",\"method\":\"$method\",\"params\":$params}" \
|
||||
"http://$RPC_HOST:$RPC_PORT/"
|
||||
}
|
||||
|
||||
echo "⚠️ IMPORTANT: This is a simplified proxy demonstration."
|
||||
echo "For production use, you would need a full Stratum server implementation."
|
||||
echo ""
|
||||
|
||||
echo "Current RinCoin mining options:"
|
||||
echo "1. Built-in Core Mining (Recommended for solo):"
|
||||
echo " bash MINE/rin/solo_mining_core.sh -t 28"
|
||||
echo ""
|
||||
echo "2. Pool Mining (Recommended for consistent rewards):"
|
||||
echo " sudo docker exec -it amd-strix-halo-llama-rocm bash -c \"/mnt/dl/rinhash/cpuminer-opt-rin/cpuminer -a rinhash -o stratum+tcp://rinhash.mine.zergpool.com:7148 -u bc1qjn4m6rmrveuxhk02a5qhe4r6kdcsvvt3vhdn9j -p c=BTC,mc=RIN,ID=StrixHalo -t 28\""
|
||||
echo ""
|
||||
echo "3. Direct RPC Mining (Advanced - requires custom miner):"
|
||||
echo " Use getblocktemplate RPC calls directly"
|
||||
echo ""
|
||||
|
||||
echo "❌ cpuminer-opt-rin cannot directly mine to RinCoin node because:"
|
||||
echo " - cpuminer uses Stratum protocol"
|
||||
echo " - RinCoin node uses RPC protocol"
|
||||
echo " - No built-in protocol conversion"
|
||||
echo ""
|
||||
|
||||
echo "✅ Recommended approach:"
|
||||
echo " Use the built-in core mining script for solo mining"
|
||||
echo " Use pool mining for consistent rewards"
|
||||
78
proxy/test_address_validation.sh
Normal file
78
proxy/test_address_validation.sh
Normal file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test RinCoin Address Validation and Behavior
|
||||
|
||||
echo "=== RinCoin Address Validation Test ==="
|
||||
echo ""
|
||||
|
||||
# Kill any existing processes
|
||||
./MINE/rin/kill_stratum_proxy.sh
|
||||
|
||||
echo "🧪 Testing different address types with RinCoin node:"
|
||||
echo ""
|
||||
|
||||
echo "1️⃣ Valid RinCoin address:"
|
||||
curl -s -u rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90 \
|
||||
-H 'content-type: text/plain' \
|
||||
--data '{"jsonrpc":"1.0","id":"curl","method":"validateaddress","params":["rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q"]}' \
|
||||
http://127.0.0.1:9556/ | jq '.result'
|
||||
|
||||
echo ""
|
||||
echo "2️⃣ Invalid BTC address:"
|
||||
curl -s -u rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90 \
|
||||
-H 'content-type: text/plain' \
|
||||
--data '{"jsonrpc":"1.0","id":"curl","method":"validateaddress","params":["bc1qjn4m6rmrveuxhk02a5qhe4r6kdcsvvt3vhdn9j"]}' \
|
||||
http://127.0.0.1:9556/ | jq '.result'
|
||||
|
||||
echo ""
|
||||
echo "3️⃣ Invalid Litecoin address:"
|
||||
curl -s -u rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90 \
|
||||
-H 'content-type: text/plain' \
|
||||
--data '{"jsonrpc":"1.0","id":"curl","method":"validateaddress","params":["LQnYyekHhQ7nMUTGJ1ZnYz8s9QJ2mKLM9P"]}' \
|
||||
http://127.0.0.1:9556/ | jq '.result'
|
||||
|
||||
echo ""
|
||||
echo "4️⃣ Test generatetoaddress with invalid address:"
|
||||
curl -s -u rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90 \
|
||||
-H 'content-type: text/plain' \
|
||||
--data '{"jsonrpc":"1.0","id":"curl","method":"generatetoaddress","params":[1, "bc1qjn4m6rmrveuxhk02a5qhe4r6kdcsvvt3vhdn9j", 1]}' \
|
||||
http://127.0.0.1:9556/ | jq '.error'
|
||||
|
||||
echo ""
|
||||
echo "🚀 Starting mining pool to test address validation..."
|
||||
./MINE/rin/start_mining_pool.sh &
|
||||
POOL_PID=$!
|
||||
|
||||
echo ""
|
||||
echo "⏳ Waiting for pool to start..."
|
||||
sleep 5
|
||||
|
||||
echo ""
|
||||
echo "🧪 Testing pool with different address types:"
|
||||
echo ""
|
||||
|
||||
echo "Test 1: Valid RinCoin address"
|
||||
echo "Expected: ✅ Accept connection"
|
||||
timeout 5s ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q -p x -t 1
|
||||
|
||||
echo ""
|
||||
echo "Test 2: Invalid BTC address"
|
||||
echo "Expected: ❌ Reject connection"
|
||||
timeout 5s ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u bc1qjn4m6rmrveuxhk02a5qhe4r6kdcsvvt3vhdn9j -p x -t 1
|
||||
|
||||
echo ""
|
||||
echo "Test 3: Traditional username (no address)"
|
||||
echo "Expected: ⚠️ Accept but warn no address"
|
||||
timeout 5s ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u user.worker -p x -t 1
|
||||
|
||||
echo ""
|
||||
echo "🧹 Cleaning up..."
|
||||
kill $POOL_PID 2>/dev/null
|
||||
./MINE/rin/kill_stratum_proxy.sh
|
||||
|
||||
echo ""
|
||||
echo "📋 Summary:"
|
||||
echo "✅ Valid RinCoin addresses (rin1q...) - Accepted"
|
||||
echo "❌ Invalid addresses (bc1q..., LQnY...) - Rejected"
|
||||
echo "⚠️ Traditional usernames - Accepted but no rewards"
|
||||
echo "💰 Block rewards always go to pool address, then distributed"
|
||||
69
proxy/test_pool_connections.sh
Normal file
69
proxy/test_pool_connections.sh
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test different mining pool connection methods
|
||||
|
||||
echo "=== Testing Mining Pool Connection Methods ==="
|
||||
echo ""
|
||||
|
||||
# Kill any existing processes
|
||||
./MINE/rin/kill_stratum_proxy.sh
|
||||
|
||||
echo "🚀 Starting mining pool..."
|
||||
./MINE/rin/start_mining_pool.sh &
|
||||
POOL_PID=$!
|
||||
|
||||
echo ""
|
||||
echo "⏳ Waiting for pool to start..."
|
||||
sleep 5
|
||||
|
||||
echo ""
|
||||
echo "🧪 Testing different connection methods:"
|
||||
echo ""
|
||||
|
||||
echo "1️⃣ Test 1: Address as username"
|
||||
echo "Command: ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q -p x -t 2"
|
||||
echo "Expected: Pool should recognize this as a RinCoin address"
|
||||
echo ""
|
||||
|
||||
echo "2️⃣ Test 2: Address.workername format"
|
||||
echo "Command: ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q.worker1 -p x -t 2"
|
||||
echo "Expected: Pool should recognize address and worker separately"
|
||||
echo ""
|
||||
|
||||
echo "3️⃣ Test 3: Traditional username"
|
||||
echo "Command: ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u user.worker -p x -t 2"
|
||||
echo "Expected: Pool should use default pool address for rewards"
|
||||
echo ""
|
||||
|
||||
echo "📊 Pool Status:"
|
||||
echo "Web Dashboard: http://127.0.0.1:8080"
|
||||
echo "Pool Address: rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q"
|
||||
echo ""
|
||||
|
||||
echo "Press Enter to run test 1..."
|
||||
read
|
||||
|
||||
echo "Running Test 1..."
|
||||
timeout 10s ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q -p x -t 2
|
||||
|
||||
echo ""
|
||||
echo "Press Enter to run test 2..."
|
||||
read
|
||||
|
||||
echo "Running Test 2..."
|
||||
timeout 10s ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q.worker1 -p x -t 2
|
||||
|
||||
echo ""
|
||||
echo "Press Enter to run test 3..."
|
||||
read
|
||||
|
||||
echo "Running Test 3..."
|
||||
timeout 10s ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u user.worker -p x -t 2
|
||||
|
||||
echo ""
|
||||
echo "🧹 Cleaning up..."
|
||||
kill $POOL_PID 2>/dev/null
|
||||
./MINE/rin/kill_stratum_proxy.sh
|
||||
|
||||
echo ""
|
||||
echo "✅ Test complete! Check the pool logs above to see how each connection was handled."
|
||||
75
proxy/test_reward_redistribution.sh
Normal file
75
proxy/test_reward_redistribution.sh
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test Reward Redistribution Logic
|
||||
|
||||
echo "=== Testing Reward Redistribution Logic ==="
|
||||
echo ""
|
||||
|
||||
# Kill any existing processes
|
||||
./MINE/rin/kill_stratum_proxy.sh
|
||||
|
||||
echo "🧪 Testing reward distribution scenarios:"
|
||||
echo ""
|
||||
|
||||
echo "Scenario 1: All miners have valid addresses"
|
||||
echo "Expected: Normal distribution"
|
||||
echo ""
|
||||
|
||||
echo "Scenario 2: Some miners without addresses"
|
||||
echo "Expected: Redistribution of their rewards to miners with addresses"
|
||||
echo ""
|
||||
|
||||
echo "Scenario 3: All miners without addresses"
|
||||
echo "Expected: All rewards go to pool"
|
||||
echo ""
|
||||
|
||||
echo "🚀 Starting mining pool..."
|
||||
./MINE/rin/start_mining_pool.sh &
|
||||
POOL_PID=$!
|
||||
|
||||
echo ""
|
||||
echo "⏳ Waiting for pool to start..."
|
||||
sleep 5
|
||||
|
||||
echo ""
|
||||
echo "🧪 Test 1: Miner with valid address"
|
||||
echo "Expected: Gets full share of rewards"
|
||||
timeout 5s ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q.worker1 -p x -t 1
|
||||
|
||||
echo ""
|
||||
echo "🧪 Test 2: Miner without address"
|
||||
echo "Expected: Contributes to difficulty but gets no direct rewards"
|
||||
timeout 5s ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u user.worker2 -p x -t 1
|
||||
|
||||
echo ""
|
||||
echo "🧪 Test 3: Another miner with valid address"
|
||||
echo "Expected: Gets base reward + redistribution from miner without address"
|
||||
timeout 5s ./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q.worker3 -p x -t 1
|
||||
|
||||
echo ""
|
||||
echo "📊 Pool Log Analysis:"
|
||||
echo "Look for these patterns in the logs above:"
|
||||
echo "1. '💰 Miner rin1q...: X.XX RIN (difficulty)' - Base rewards"
|
||||
echo "2. '⚠️ Miner without address: X difficulty -> X.XX RIN to pool' - Undistributed"
|
||||
echo "3. '💰 Pool keeps X.XX RIN from miners without addresses' - Pool keeps rewards"
|
||||
echo "4. '📊 Summary: X miners with addresses, Y without (rewards to pool)' - Final summary"
|
||||
|
||||
echo ""
|
||||
echo "🧹 Cleaning up..."
|
||||
kill $POOL_PID 2>/dev/null
|
||||
./MINE/rin/kill_stratum_proxy.sh
|
||||
|
||||
echo ""
|
||||
echo "📋 Reward Distribution Logic Summary:"
|
||||
echo ""
|
||||
echo "✅ Miners with valid RinCoin addresses:"
|
||||
echo " - Get reward based on their difficulty"
|
||||
echo " - Rewards sent directly to their addresses"
|
||||
echo ""
|
||||
echo "⚠️ Miners without addresses:"
|
||||
echo " - Contribute to total difficulty"
|
||||
echo " - Their reward share goes to pool address"
|
||||
echo " - No direct rewards received"
|
||||
echo ""
|
||||
echo "💰 Pool fee: Always 1% of total block reward"
|
||||
echo "💰 Pool bonus: Additional rewards from miners without addresses"
|
||||
Reference in New Issue
Block a user