stratum: "shares should now be accepted"

This commit is contained in:
Dobromir Popov
2025-09-23 11:52:01 +03:00
parent 210bfc5176
commit 44d6d91103
2 changed files with 84 additions and 4 deletions

View File

@@ -1,9 +1,10 @@
================================================================================
RinCoin Mining Log
================================================================================
Started: 2025-09-23 11:44:13
Started: 2025-09-23 11:51:14
Target Address: rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q
Stratum: 0.0.0.0:3334
RPC: 127.0.0.1:9556
================================================================================
[2025-09-23 11:51:14] 💰 Wallet Balance: 25.00000000 RIN

View File

@@ -2,6 +2,7 @@
"""
RinCoin Stratum Proxy Server - FIXED VERSION
Fixed block hash calculation and validation issues
DEBUG: we get node logs with 'docker logs --tail=200 rincoin-node'
"""
import socket
@@ -38,6 +39,18 @@ class RinCoinStratumProxy:
self.last_difficulty_adjustment = time.time()
self.target_share_interval = 120 # Target: 1 share every 2 minutes per miner (aligned with ~1min blocks)
# Production monitoring
self.stats = {
'start_time': time.time(),
'total_shares': 0,
'accepted_shares': 0,
'rejected_shares': 0,
'blocks_found': 0,
'total_hashrate': 0,
'connections': 0
}
self.max_connections = 50 # Production limit
# Logging setup
self.log_file = "mining_log.txt"
self.init_log_file()
@@ -513,7 +526,8 @@ class RinCoinStratumProxy:
# Get the stratum difficulty that was sent to this miner
client_stratum_diff = self.clients.get(addr, {}).get('stratum_difficulty', 0.001)
diff1_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
stratum_target_int = diff1_target // max(1, int(client_stratum_diff * 1000000)) * 1000000
# Correct stratum target calculation: target = diff1_target / difficulty
stratum_target_int = int(diff1_target / client_stratum_diff)
meets_stratum_target = hash_int <= stratum_target_int
meets_network_target = hash_int <= network_target_int
@@ -548,6 +562,8 @@ class RinCoinStratumProxy:
if not meets_stratum_target:
# Share doesn't meet stratum target - reject
print(f" ❌ Share rejected (hash > stratum target)")
self.stats['total_shares'] += 1
self.stats['rejected_shares'] += 1
return False, "Share too high"
# Valid stratum share! Update client stats
@@ -555,8 +571,16 @@ class RinCoinStratumProxy:
self.clients[addr]['share_count'] = self.clients[addr].get('share_count', 0) + 1
self.clients[addr]['last_share_time'] = time.time()
# Update global stats
self.stats['total_shares'] += 1
self.stats['accepted_shares'] += 1
# Check if we should adjust difficulty
self.adjust_client_difficulty(addr)
else:
# Track rejected shares
self.stats['total_shares'] += 1
self.stats['rejected_shares'] += 1
# Check if it's also a valid network block
if meets_network_target:
@@ -591,6 +615,8 @@ class RinCoinStratumProxy:
if result is None:
print(f" ✅ Block accepted by network!")
# Update block stats
self.stats['blocks_found'] += 1
# Log wallet balance after successful block submission
self.log_wallet_balance()
return True, "Block found and submitted"
@@ -859,10 +885,17 @@ class RinCoinStratumProxy:
def handle_client(self, client, addr):
"""Handle individual client connection"""
print(f"[{addr}] Connected")
# Check connection limits
if len(self.clients) >= self.max_connections:
print(f"[{addr}] Connection rejected - max connections ({self.max_connections}) reached")
client.close()
return
print(f"[{addr}] Connected (clients: {len(self.clients) + 1}/{self.max_connections})")
if addr not in self.clients:
self.clients[addr] = {}
self.clients[addr]['socket'] = client
self.stats['connections'] = len(self.clients)
try:
while self.running:
@@ -882,11 +915,51 @@ class RinCoinStratumProxy:
client.close()
if addr in self.clients:
del self.clients[addr]
print(f"[{addr}] Disconnected")
self.stats['connections'] = len(self.clients)
print(f"[{addr}] Disconnected (clients: {len(self.clients)}/{self.max_connections})")
def print_stats(self):
"""Print pool statistics"""
try:
uptime = time.time() - self.stats['start_time']
uptime_str = f"{int(uptime//3600)}h {int((uptime%3600)//60)}m"
accept_rate = 0
if self.stats['total_shares'] > 0:
accept_rate = (self.stats['accepted_shares'] / self.stats['total_shares']) * 100
print(f"\n📊 POOL STATISTICS:")
print(f" ⏰ Uptime: {uptime_str}")
print(f" 👥 Connected miners: {self.stats['connections']}")
print(f" 📈 Shares: {self.stats['accepted_shares']}/{self.stats['total_shares']} ({accept_rate:.1f}% accepted)")
print(f" 🎉 Blocks found: {self.stats['blocks_found']}")
print(f" 🎯 Network difficulty: {self.calculate_network_difficulty(self.current_job['target']) if self.current_job else 'unknown':.6f}")
# Calculate hashrate estimate from connected clients
total_hashrate = 0
for addr, client_data in self.clients.items():
share_count = client_data.get('share_count', 0)
connect_time = client_data.get('connect_time', time.time())
mining_duration = time.time() - connect_time
if mining_duration > 60 and share_count > 0:
stratum_diff = client_data.get('stratum_difficulty', 0.001)
# Rough hashrate estimate: shares * difficulty * 2^32 / time
hashrate = (share_count * stratum_diff * 4294967296) / mining_duration
total_hashrate += hashrate
print(f" 🔥 {addr}: ~{hashrate/1000:.0f} kH/s")
if total_hashrate > 0:
print(f" 🚀 Total pool hashrate: ~{total_hashrate/1000:.0f} kH/s")
print()
except Exception as e:
print(f"Stats error: {e}")
def job_updater(self):
"""Periodically update mining jobs"""
balance_log_counter = 0
stats_counter = 0
while self.running:
try:
time.sleep(30) # Update every 30 seconds
@@ -904,6 +977,12 @@ class RinCoinStratumProxy:
if balance_log_counter >= 20:
self.log_wallet_balance()
balance_log_counter = 0
# Print stats every 5 minutes (10 cycles of 30 seconds)
stats_counter += 1
if stats_counter >= 10:
self.print_stats()
stats_counter = 0
except Exception as e:
print(f"Job updater error: {e}")