stratuu - try fix block subm - proper difficulty

This commit is contained in:
Dobromir Popov
2025-09-23 13:33:10 +03:00
parent 4743ee4369
commit b5c0375569

View File

@@ -408,8 +408,19 @@ class RinCoinStratumProxy:
diff1_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
optimal_difficulty = (estimated_hashrate * diff1_target) / (target_shares_per_second * (2**256))
# More practical approach: start with network difficulty scaled way down for solo mining
optimal_difficulty = max(network_diff * 0.00001, 0.000001) # 0.001% of network, min 0.000001
# Calculate proper difficulty based on expected hashrate for solo mining
# Target: 1 share every 2 minutes (120 seconds)
# Conservative estimate: 500 kH/s for CPU mining
estimated_hashrate = 500000 # 500 kH/s
target_shares_per_second = 1.0 / self.target_share_interval
# Calculate difficulty to achieve target share rate
# Formula: difficulty = hashrate / (target_shares_per_second * 2^32 / max_target)
max_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
optimal_difficulty = (estimated_hashrate * target_shares_per_second) / (max_target / (2**32))
# Ensure it's not too low or too high
optimal_difficulty = max(0.000001, min(optimal_difficulty, network_diff * 0.01))
print(f" 📊 New client {addr}: Network diff {network_diff:.6f}, starting with {optimal_difficulty:.6f}")
return optimal_difficulty
@@ -445,8 +456,8 @@ class RinCoinStratumProxy:
new_difficulty = current_difficulty / max_change
# Bounds checking for solo mining
min_difficulty = max(network_diff * 0.000001, 0.000001) # 0.0001% of network minimum
max_difficulty = network_diff * 0.01 # 1% of network maximum
min_difficulty = 0.0000001 # Very low minimum
max_difficulty = 0.001 # Maximum 0.1% of typical network diff
new_difficulty = max(min_difficulty, min(max_difficulty, new_difficulty))
print(f" 📊 {addr}: {share_count} shares in {mining_duration:.0f}s ({actual_share_rate:.4f}/s), adjusting {current_difficulty:.6f}{new_difficulty:.6f}")
@@ -561,31 +572,41 @@ class RinCoinStratumProxy:
print(f" 🔍 Hash vs Network: {hash_int} {'<=' if meets_network_target else '>'} {network_target_int}")
print(f" 🔍 Hash vs Stratum: {hash_int} {'<=' if meets_stratum_target else '>'} {stratum_target_int}")
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
if addr and addr in self.clients:
self.clients[addr]['share_count'] = self.clients[addr].get('share_count', 0) + 1
self.clients[addr]['last_share_time'] = time.time()
# Update global stats
# Handle submit_all_blocks mode - bypass all difficulty checks
if self.submit_all_blocks:
print(f" 🧪 TEST MODE: Submitting ALL shares to node for validation")
# Update stats for test mode
self.stats['total_shares'] += 1
self.stats['accepted_shares'] += 1
# Check if we should adjust difficulty
self.adjust_client_difficulty(addr)
# Always submit in test mode
should_submit = True
else:
# Track rejected shares
self.stats['total_shares'] += 1
self.stats['rejected_shares'] += 1
# Normal mode - check stratum difficulty
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"
# Check if it's also a valid network block OR if we should submit all blocks for testing
if meets_network_target or self.submit_all_blocks:
# Valid stratum share! Update client stats
if addr and addr in self.clients:
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)
# Only submit if it meets network target in normal mode
should_submit = meets_network_target
# Submit block if conditions are met
if should_submit:
if meets_network_target:
print(f" 🎉 VALID BLOCK FOUND! Hash: {block_hash_hex}")
else:
@@ -630,9 +651,13 @@ class RinCoinStratumProxy:
print(f" 🔍 Debug: Block size {len(block_hex)//2} bytes, {len(job['transactions'])} transactions")
return False, f"Block rejected: {result}"
else:
# Valid stratum share but not network-valid block
print(f" ✅ Valid stratum share accepted")
return True, "Valid stratum share"
# Valid stratum share but not network-valid block (normal mode only)
if not self.submit_all_blocks:
print(f"Valid stratum share accepted")
return True, "Valid stratum share"
else:
# This shouldn't happen in test mode since should_submit would be True
return True, "Test mode share processed"
except Exception as e:
print(f"Share submission error: {e}")