From 992a7704b6b55d9fc40b96d7da47c2a15d12a944 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 23 Sep 2025 11:29:56 +0300 Subject: [PATCH] stratum proxy wip --- MINE/rin/mining_log.txt | 10 +++ MINE/rin/stratum_proxy.py | 150 ++++++++++++++++++++++---------------- mining_log.txt | 10 +++ 3 files changed, 106 insertions(+), 64 deletions(-) create mode 100644 MINE/rin/mining_log.txt create mode 100644 mining_log.txt diff --git a/MINE/rin/mining_log.txt b/MINE/rin/mining_log.txt new file mode 100644 index 0000000..5a399b5 --- /dev/null +++ b/MINE/rin/mining_log.txt @@ -0,0 +1,10 @@ +================================================================================ +RinCoin Mining Log +================================================================================ +Started: 2025-09-23 11:28:19 +Target Address: rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q +Stratum: 0.0.0.0:3334 +RPC: 127.0.0.1:9556 +================================================================================ + +[2025-09-23 11:28:19] 💰 Wallet Balance: 25.00000000 RIN diff --git a/MINE/rin/stratum_proxy.py b/MINE/rin/stratum_proxy.py index e9e4bd6..4378ad9 100644 --- a/MINE/rin/stratum_proxy.py +++ b/MINE/rin/stratum_proxy.py @@ -329,7 +329,7 @@ class RinCoinStratumProxy: print(f"Network difficulty calculation error: {e}") return 1.0 - def submit_share(self, job, extranonce1, extranonce2, ntime, nonce, target_address=None): + def submit_share(self, job, extranonce1, extranonce2, ntime, nonce, addr=None, target_address=None): """Validate share and submit block if valid - FIXED VERSION""" try: # Use provided address or default @@ -353,7 +353,7 @@ class RinCoinStratumProxy: header += bytes.fromhex(job['prevhash'])[::-1] # Previous block hash (big-endian in block) header += merkle_root # Merkle root (already in correct endian) header += struct.pack(' 0 else 0 - - # Progress indicator based on percentage - if meets_target: + network_percentage = (share_difficulty / network_difficulty) * 100 if network_difficulty > 0 else 0 + stratum_percentage = (share_difficulty / client_stratum_diff) * 100 if client_stratum_diff > 0 else 0 + + # Progress indicator based on network percentage + if meets_network_target: progress_icon = "🎉" # Block found! - elif difficulty_percentage >= 50: - progress_icon = "🔥" # Very close - elif difficulty_percentage >= 10: + elif meets_stratum_target: + progress_icon = "✅" # Valid share for stratum + elif network_percentage >= 50: + progress_icon = "🔥" # Very close to network + elif network_percentage >= 10: progress_icon = "⚡" # Getting warm - elif difficulty_percentage >= 1: + elif network_percentage >= 1: progress_icon = "💫" # Some progress else: progress_icon = "📊" # Low progress - + print(f"[{timestamp}] {progress_icon} SHARE: job={job['job_id']} | nonce={nonce} | hash={block_hash_hex[:16]}...") - print(f" 🎯 Share Diff: {share_difficulty:.2e} | Network Diff: {network_difficulty:.6f}") - print(f" 📈 Progress: {difficulty_percentage:.4f}% of network difficulty") + print(f" 🎯 Share Diff: {share_difficulty:.2e} | Stratum Diff: {client_stratum_diff:.6f} | Network Diff: {network_difficulty:.6f}") + print(f" 📈 Progress: {network_percentage:.4f}% of network, {stratum_percentage:.1f}% of stratum") print(f" 📍 Target: {job['target'][:16]}... | Height: {job['height']}") print(f" ⏰ Time: {ntime} | Extranonce: {extranonce1}:{extranonce2}") - print(f" 🔍 Hash vs Target: {hash_int} {'<=' if meets_target else '>'} {target_int}") - - if not meets_target: - # Share doesn't meet target - reject but still useful for debugging - print(f" ❌ Share rejected (hash > target)") + 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)") return False, "Share too high" - - # Valid block! Build full block and submit - print(f" 🎉 BLOCK FOUND! Hash: {block_hash_hex}") - 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})") - - # Log the found hash - reward_rin = job['coinbasevalue'] / 100000000 - self.log_hash_found(block_hash_hex, share_difficulty, job['height'], reward_rin, nonce, ntime) - - # Build complete block - block = header - - # Transaction count - tx_count = 1 + len(job['transactions']) - block += self.encode_varint(tx_count) - - # Add coinbase transaction (witness variant for block body) - block += coinbase_wit - - # Add other transactions - for tx in job['transactions']: - block += bytes.fromhex(tx['data']) - - # Submit block - block_hex = block.hex() - print(f" 📦 Submitting block of size {len(block_hex)//2} bytes...") - - result = self.rpc_call("submitblock", [block_hex]) - - if result is None: - print(f" ✅ Block accepted by network!") - # Log wallet balance after successful block submission - self.log_wallet_balance() - return True, "Block found and submitted" + + # Valid stratum share! Check if it's also a valid network block + if meets_network_target: + print(f" 🎉 BLOCK FOUND! Hash: {block_hash_hex}") + 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})") + + # Log the found hash + reward_rin = job['coinbasevalue'] / 100000000 + self.log_hash_found(block_hash_hex, share_difficulty, job['height'], reward_rin, nonce, ntime) + + # Build complete block + block = header + + # Transaction count + tx_count = 1 + len(job['transactions']) + block += self.encode_varint(tx_count) + + # Add coinbase transaction (witness variant for block body) + block += coinbase_wit + + # Add other transactions + for tx in job['transactions']: + block += bytes.fromhex(tx['data']) + + # Submit block + block_hex = block.hex() + print(f" 📦 Submitting block of size {len(block_hex)//2} bytes...") + + result = self.rpc_call("submitblock", [block_hex]) + + if result is None: + print(f" ✅ Block accepted by network!") + # Log wallet balance after successful block submission + self.log_wallet_balance() + return True, "Block found and submitted" + else: + print(f" ❌ Block rejected: {result}") + print(f" 🔍 Debug: Block size {len(block_hex)//2} bytes, {len(job['transactions'])} transactions") + return False, f"Block rejected: {result}" else: - print(f" ❌ Block rejected: {result}") - print(f" 🔍 Debug: Block size {len(block_hex)//2} bytes, {len(job['transactions'])} transactions") - return False, f"Block rejected: {result}" + # Valid stratum share but not network-valid block + print(f" ✅ Valid stratum share accepted") + return True, "Valid stratum share" except Exception as e: print(f"Share submission error: {e}") @@ -492,8 +508,14 @@ class RinCoinStratumProxy: 4 # extranonce2 size ]) - # Send difficulty - MUCH LOWER for testing - self.send_stratum_notification(client, "mining.set_difficulty", [0.00001]) + # Send difficulty - set to reasonable level for stratum mining + network_diff = self.calculate_network_difficulty(self.current_job['target']) if self.current_job else 1.0 + stratum_difficulty = min(network_diff * 0.001, 0.01) # Adaptive difficulty, max 0.01 + # Store stratum difficulty for this client + if addr not in self.clients: + self.clients[addr] = {} + self.clients[addr]['stratum_difficulty'] = stratum_difficulty + self.send_stratum_notification(client, "mining.set_difficulty", [stratum_difficulty]) # Send initial job if self.current_job: @@ -527,7 +549,7 @@ class RinCoinStratumProxy: extranonce1 = self.clients[addr].get('extranonce1', '00000000') # Submit share - success, message = self.submit_share(self.current_job, extranonce1, extranonce2, ntime, nonce) + success, message = self.submit_share(self.current_job, extranonce1, extranonce2, ntime, nonce, addr) # Always accept shares for debugging, even if they don't meet target self.send_stratum_response(client, msg_id, True) diff --git a/mining_log.txt b/mining_log.txt new file mode 100644 index 0000000..e731e0b --- /dev/null +++ b/mining_log.txt @@ -0,0 +1,10 @@ +================================================================================ +RinCoin Mining Log +================================================================================ +Started: 2025-09-23 11:27:51 +Target Address: rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q +Stratum: 0.0.0.0:3334 +RPC: 127.0.0.1:9556 +================================================================================ + +[2025-09-23 11:27:51] 💰 Wallet Balance: 25.00000000 RIN