stratum proxy wip

This commit is contained in:
Dobromir Popov
2025-09-23 11:29:56 +03:00
parent 747b8efb10
commit 992a7704b6
3 changed files with 106 additions and 64 deletions

10
MINE/rin/mining_log.txt Normal file
View File

@@ -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

View File

@@ -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('<I', int(ntime, 16)) # Timestamp (little-endian)
header += bytes.fromhex(job['bits'])[::-1] # Bits (big-endian in block)
header += bytes.fromhex(job['bits']) # Bits (big-endian in block)
header += struct.pack('<I', int(nonce, 16)) # Nonce (little-endian)
# Calculate block hash - FIXED DOUBLE SHA256
@@ -364,78 +364,94 @@ class RinCoinStratumProxy:
share_difficulty = self.calculate_share_difficulty(block_hash_hex, job['target'])
network_difficulty = self.calculate_network_difficulty(job['target'])
# Check if hash meets target - FIXED COMPARISON
# Check if hash meets stratum difficulty first, then network target
hash_int = int(block_hash_hex, 16)
target_int = int(job['target'], 16)
meets_target = hash_int <= target_int # FIXED: less than or equal
network_target_int = int(job['target'], 16)
# Get the stratum difficulty that was sent to this miner
client_stratum_diff = self.clients.get(addr, {}).get('stratum_difficulty', 0.001)
diff1_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
stratum_target_int = diff1_target // max(1, int(client_stratum_diff * 1000000)) * 1000000
meets_stratum_target = hash_int <= stratum_target_int
meets_network_target = hash_int <= network_target_int
# Enhanced logging
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
difficulty_percentage = (share_difficulty / network_difficulty) * 100 if network_difficulty > 0 else 0
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 percentage
if meets_target:
# 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}")
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_target:
# Share doesn't meet target - reject but still useful for debugging
print(f" ❌ Share rejected (hash > target)")
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})")
# 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)
# 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
# Build complete block
block = header
# Transaction count
tx_count = 1 + len(job['transactions'])
block += self.encode_varint(tx_count)
# 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 coinbase transaction (witness variant for block body)
block += coinbase_wit
# Add other transactions
for tx in job['transactions']:
block += bytes.fromhex(tx['data'])
# 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...")
# Submit block
block_hex = block.hex()
print(f" 📦 Submitting block of size {len(block_hex)//2} bytes...")
result = self.rpc_call("submitblock", [block_hex])
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"
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)

10
mining_log.txt Normal file
View File

@@ -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