stratuu - try fix block subm - proper difficulty
This commit is contained in:
@@ -408,8 +408,19 @@ class RinCoinStratumProxy:
|
|||||||
diff1_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
diff1_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
||||||
optimal_difficulty = (estimated_hashrate * diff1_target) / (target_shares_per_second * (2**256))
|
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
|
# Calculate proper difficulty based on expected hashrate for solo mining
|
||||||
optimal_difficulty = max(network_diff * 0.00001, 0.000001) # 0.001% of network, min 0.000001
|
# 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}")
|
print(f" 📊 New client {addr}: Network diff {network_diff:.6f}, starting with {optimal_difficulty:.6f}")
|
||||||
return optimal_difficulty
|
return optimal_difficulty
|
||||||
@@ -445,8 +456,8 @@ class RinCoinStratumProxy:
|
|||||||
new_difficulty = current_difficulty / max_change
|
new_difficulty = current_difficulty / max_change
|
||||||
|
|
||||||
# Bounds checking for solo mining
|
# Bounds checking for solo mining
|
||||||
min_difficulty = max(network_diff * 0.000001, 0.000001) # 0.0001% of network minimum
|
min_difficulty = 0.0000001 # Very low minimum
|
||||||
max_difficulty = network_diff * 0.01 # 1% of network maximum
|
max_difficulty = 0.001 # Maximum 0.1% of typical network diff
|
||||||
new_difficulty = max(min_difficulty, min(max_difficulty, new_difficulty))
|
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}")
|
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 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}")
|
print(f" 🔍 Hash vs Stratum: {hash_int} {'<=' if meets_stratum_target else '>'} {stratum_target_int}")
|
||||||
|
|
||||||
if not meets_stratum_target:
|
# Handle submit_all_blocks mode - bypass all difficulty checks
|
||||||
# Share doesn't meet stratum target - reject
|
if self.submit_all_blocks:
|
||||||
print(f" ❌ Share rejected (hash > stratum target)")
|
print(f" 🧪 TEST MODE: Submitting ALL shares to node for validation")
|
||||||
self.stats['total_shares'] += 1
|
# Update stats for test mode
|
||||||
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
|
|
||||||
self.stats['total_shares'] += 1
|
self.stats['total_shares'] += 1
|
||||||
self.stats['accepted_shares'] += 1
|
self.stats['accepted_shares'] += 1
|
||||||
|
|
||||||
# Check if we should adjust difficulty
|
# Always submit in test mode
|
||||||
self.adjust_client_difficulty(addr)
|
should_submit = True
|
||||||
else:
|
else:
|
||||||
# Track rejected shares
|
# Normal mode - check stratum difficulty
|
||||||
self.stats['total_shares'] += 1
|
if not meets_stratum_target:
|
||||||
self.stats['rejected_shares'] += 1
|
# 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
|
# Valid stratum share! Update client stats
|
||||||
if meets_network_target or self.submit_all_blocks:
|
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:
|
if meets_network_target:
|
||||||
print(f" 🎉 VALID BLOCK FOUND! Hash: {block_hash_hex}")
|
print(f" 🎉 VALID BLOCK FOUND! Hash: {block_hash_hex}")
|
||||||
else:
|
else:
|
||||||
@@ -630,9 +651,13 @@ class RinCoinStratumProxy:
|
|||||||
print(f" 🔍 Debug: Block size {len(block_hex)//2} bytes, {len(job['transactions'])} transactions")
|
print(f" 🔍 Debug: Block size {len(block_hex)//2} bytes, {len(job['transactions'])} transactions")
|
||||||
return False, f"Block rejected: {result}"
|
return False, f"Block rejected: {result}"
|
||||||
else:
|
else:
|
||||||
# Valid stratum share but not network-valid block
|
# Valid stratum share but not network-valid block (normal mode only)
|
||||||
print(f" ✅ Valid stratum share accepted")
|
if not self.submit_all_blocks:
|
||||||
return True, "Valid stratum share"
|
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:
|
except Exception as e:
|
||||||
print(f"Share submission error: {e}")
|
print(f"Share submission error: {e}")
|
||||||
|
Reference in New Issue
Block a user