From 7a806e53cbc31c045fa983e34f6eaf04afef23d4 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 23 Sep 2025 18:38:28 +0300 Subject: [PATCH] more difficulty fns --- MINE/rin/README.md | 12 ++++++ MINE/rin/mining_log.txt | 4 +- MINE/rin/stratum_proxy.py | 91 ++++++++++++++++++++++++++------------- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/MINE/rin/README.md b/MINE/rin/README.md index 6869eef..d2304fe 100644 --- a/MINE/rin/README.md +++ b/MINE/rin/README.md @@ -154,6 +154,18 @@ Your Stratum proxy can be enhanced to work as a **full mining pool** that distri # submit every share cd /mnt/shared/DEV/repos/d-popov.com/scripts/MINE/rin && python3 stratum_proxy.py --submit-all-blocks + +python3 stratum_proxy.py --submit-threshold 0.05 + +# For production (10% threshold - good balance) +python3 stratum_proxy.py --submit-threshold 0.1 + +# For aggressive testing (1% threshold) +python3 stratum_proxy.py --submit-threshold 0.01 + +# For normal operation (only valid blocks) +python3 stratum_proxy.py + ``` ### **Pool vs Solo Mining:** diff --git a/MINE/rin/mining_log.txt b/MINE/rin/mining_log.txt index 67a3143..8310afb 100644 --- a/MINE/rin/mining_log.txt +++ b/MINE/rin/mining_log.txt @@ -1,10 +1,10 @@ ================================================================================ RinCoin Mining Log ================================================================================ -Started: 2025-09-23 18:18:32 +Started: 2025-09-23 18:38:03 Target Address: rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q Stratum: 0.0.0.0:3334 RPC: 127.0.0.1:9556 ================================================================================ -[2025-09-23 18:18:32] ๐Ÿ’ฐ Wallet Balance: 25.00000000 RIN +[2025-09-23 18:38:03] ๐Ÿ’ฐ Wallet Balance: 25.00000000 RIN diff --git a/MINE/rin/stratum_proxy.py b/MINE/rin/stratum_proxy.py index aecc5aa..c47fb9e 100644 --- a/MINE/rin/stratum_proxy.py +++ b/MINE/rin/stratum_proxy.py @@ -15,11 +15,11 @@ import struct from requests.auth import HTTPBasicAuth class RinCoinStratumProxy: - def __init__(self, stratum_host='0.0.0.0', stratum_port=3334, - rpc_host='127.0.0.1', rpc_port=9556, + def __init__(self, stratum_host='0.0.0.0', stratum_port=3334, + rpc_host='127.0.0.1', rpc_port=9556, rpc_user='rinrpc', rpc_password='745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90', target_address='rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q', - submit_all_blocks=False): + submit_all_blocks=False, submit_threshold=0.1): self.stratum_host = stratum_host self.stratum_port = stratum_port @@ -28,7 +28,9 @@ class RinCoinStratumProxy: self.rpc_user = rpc_user self.rpc_password = rpc_password self.target_address = target_address - self.submit_all_blocks = submit_all_blocks # If True, submit even invalid blocks for testing + self.submit_all_blocks = submit_all_blocks + # For debugging: submit blocks that meet this fraction of network difficulty + self.submit_threshold = submit_threshold # Configurable percentage of network difficulty self.clients = {} self.job_counter = 0 @@ -39,7 +41,7 @@ class RinCoinStratumProxy: # Dynamic difficulty adjustment self.share_stats = {} # Track shares per client self.last_difficulty_adjustment = time.time() - self.target_share_interval = 20 # Target: 1 share every 20 seconds (optimized from public pool data) + self.target_share_interval = 15 # Target: 1 share every 15 seconds (optimal for 1-min blocks) # Production monitoring self.stats = { @@ -398,16 +400,16 @@ class RinCoinStratumProxy: try: # Get current network difficulty network_diff = self.calculate_network_difficulty(self.current_job['target']) if self.current_job else 1.0 - + if is_new_client: - # Use optimized difficulty based on updated hashrate analysis (680kH/s, 20s intervals) - # Updated: Doubled hashrate requires doubled difficulty for same share rate - optimal_difficulty = 0.003182 # Optimized for 680kH/s (2x original 340kH/s) - + # Use optimized difficulty based on updated hashrate analysis (680kH/s, 15s intervals) + # Updated: 15s intervals for better responsiveness with 1-min blocks + optimal_difficulty = 0.002375 # Optimized for 680kH/s at 15s intervals + # Scale based on network difficulty to maintain relative percentage - target_percentage = 0.003924 # 0.3924% of network (updated for 680kH/s) + target_percentage = 0.003382 # 0.3382% of network (updated for 680kH/s, 15s) scaled_difficulty = network_diff * target_percentage - + # Use the better of the two approaches initial_difficulty = min(optimal_difficulty, scaled_difficulty) @@ -444,7 +446,7 @@ class RinCoinStratumProxy: return current_difficulty # Calculate target difficulty based on hashrate and desired share interval - # Target: 1 share every 60 seconds (self.target_share_interval) + # Target: 1 share every 15 seconds (self.target_share_interval) if estimated_hashrate > 0: # Formula: difficulty = (hashrate * target_time) / (2^32) diff1_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000 @@ -615,13 +617,24 @@ class RinCoinStratumProxy: print(f" ๐Ÿ” Difficulty Check: Share {share_difficulty:.2e} vs Stratum {client_stratum_diff:.6f} = {'โœ…' if meets_stratum_difficulty else 'โŒ'}") print(f" ๐Ÿ” Difficulty Check: Share {share_difficulty:.2e} vs Network {network_difficulty:.6f} = {'โœ…' if meets_network_difficulty else 'โŒ'}") + # Initialize submission variables + submit_network_difficulty = meets_network_difficulty + submit_debug_threshold = share_difficulty >= (network_difficulty * self.submit_threshold) + + if submit_network_difficulty: + submit_reason = "meets network difficulty" + elif submit_debug_threshold: + submit_reason = f"meets debug threshold ({self.submit_threshold*100:.0f}% of network)" + else: + submit_reason = "does not meet minimum requirements" + # 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 - + # Always submit in test mode should_submit = True else: @@ -638,17 +651,17 @@ class RinCoinStratumProxy: current_time = time.time() self.clients[addr]['share_count'] = self.clients[addr].get('share_count', 0) + 1 self.clients[addr]['last_share_time'] = current_time - + # Calculate hashrate from this share # Hashrate = difficulty * 2^32 / time_to_find_share client_difficulty = self.clients[addr].get('stratum_difficulty', 0.001) last_share_time = self.clients[addr].get('last_share_time', current_time - 60) time_since_last = max(1, current_time - last_share_time) # Avoid division by zero - + # Calculate instantaneous hashrate for this share diff1_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000 instant_hashrate = (client_difficulty * (2**32)) / time_since_last - + # Store hashrate sample (keep last 10 samples) if 'hashrate_samples' not in self.clients[addr]: self.clients[addr]['hashrate_samples'] = [] @@ -656,36 +669,38 @@ class RinCoinStratumProxy: # Keep only last 10 samples if len(self.clients[addr]['hashrate_samples']) > 10: self.clients[addr]['hashrate_samples'] = self.clients[addr]['hashrate_samples'][-10:] - + # Calculate average hashrate from recent samples if self.clients[addr]['hashrate_samples']: total_hashrate = sum(hr for _, hr in self.clients[addr]['hashrate_samples']) self.clients[addr]['estimated_hashrate'] = total_hashrate / len(self.clients[addr]['hashrate_samples']) - + print(f" โ›๏ธ Miner {addr}: {self.clients[addr]['estimated_hashrate']:.0f} H/s (avg of {len(self.clients[addr]['hashrate_samples'])} samples)") - + # Update global stats self.stats['total_shares'] += 1 self.stats['accepted_shares'] += 1 - + # Check if we should adjust difficulty self.adjust_client_difficulty(addr) - + # Global difficulty adjustment based on share rate self.adjust_global_difficulty_if_needed() - - # Only submit if it meets network difficulty in normal mode - should_submit = meets_network_difficulty + + should_submit = submit_network_difficulty or submit_debug_threshold # Submit block if conditions are met if should_submit: - if meets_network_difficulty: + if submit_network_difficulty: print(f" ๐ŸŽ‰ VALID BLOCK FOUND! Hash: {block_hash_hex}") + elif submit_debug_threshold: + print(f" ๐Ÿงช DEBUG SUBMISSION! Hash: {block_hash_hex} ({submit_reason})") else: print(f" ๐Ÿงช TEST BLOCK SUBMISSION! Hash: {block_hash_hex} (submit_all_blocks=True)") print(f" ๐Ÿ’ฐ Reward: {job['coinbasevalue']/100000000:.2f} RIN -> {address}") print(f" ๐Ÿ“Š Block height: {job['height']}") print(f" ๐Ÿ” Difficulty: {share_difficulty:.6f} (target: {network_difficulty:.6f})") + print(f" ๐Ÿ“‹ Submit reason: {submit_reason}") # Log the found hash reward_rin = job['coinbasevalue'] / 100000000 @@ -1214,6 +1229,7 @@ class RinCoinStratumProxy: print(f" ๐Ÿ’ฐ Mining to: {self.target_address}") print(f" ๐Ÿ“Š Current job: {self.current_job['job_id'] if self.current_job else 'None'}") print(f" ๐Ÿ“ Mining log: {self.log_file}") + print(f" ๐Ÿงช Debug mode: Submit blocks at {self.submit_threshold*100:.0f}% of network difficulty") print("") print(" ๐Ÿ”ง Miner command:") print(f" ./cpuminer -a rinhash -o stratum+tcp://{self.stratum_host}:{self.stratum_port} -u worker1 -p x -t 4") @@ -1243,11 +1259,24 @@ class RinCoinStratumProxy: if __name__ == "__main__": import sys - # Check for submit_all_blocks parameter + # Parse command line arguments submit_all = False - if len(sys.argv) > 1 and sys.argv[1] == "--submit-all-blocks": - submit_all = True - print("๐Ÿงช TEST MODE: Will submit ALL blocks for validation (submit_all_blocks=True)") + submit_threshold = 0.1 # Default 10% - proxy = RinCoinStratumProxy(submit_all_blocks=submit_all) + for i, arg in enumerate(sys.argv[1:], 1): + if arg == "--submit-all-blocks": + submit_all = True + print("๐Ÿงช TEST MODE: Will submit ALL blocks for validation (submit_all_blocks=True)") + elif arg == "--submit-threshold" and i + 1 < len(sys.argv): + try: + submit_threshold = float(sys.argv[i + 1]) + if submit_threshold <= 0 or submit_threshold > 1: + print(f"โŒ Invalid threshold {submit_threshold}. Must be between 0 and 1 (0-100%)") + sys.exit(1) + print(f"๐Ÿงช DEBUG MODE: Will submit blocks at {submit_threshold*100:.1f}% of network difficulty") + except ValueError: + print(f"โŒ Invalid threshold value: {sys.argv[i + 1]}") + sys.exit(1) + + proxy = RinCoinStratumProxy(submit_all_blocks=submit_all, submit_threshold=submit_threshold) proxy.start()