From b5c03755696d7c2e6ff6d0e6c19ce8b7e2cb040e Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 23 Sep 2025 13:33:10 +0300 Subject: [PATCH] stratuu - try fix block subm - proper difficulty --- MINE/rin/stratum_proxy.py | 79 ++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/MINE/rin/stratum_proxy.py b/MINE/rin/stratum_proxy.py index aff5ee6..8635169 100644 --- a/MINE/rin/stratum_proxy.py +++ b/MINE/rin/stratum_proxy.py @@ -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}")