wip
This commit is contained in:
@@ -229,18 +229,58 @@ class RinCoinStratumBase:
|
||||
}
|
||||
|
||||
self.current_job = job
|
||||
print(f"New job: {job['job_id']} | Height: {job['height']} | Reward: {job['coinbasevalue']/100000000:.2f} RIN")
|
||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
network_difficulty = self.calculate_network_difficulty(job['target'])
|
||||
print(f"[{timestamp}] 🆕 NEW JOB: {job['job_id']} | Height: {job['height']} | Reward: {job['coinbasevalue']/100000000:.2f} RIN")
|
||||
print(f" 🎯 Network Difficulty: {network_difficulty:.6f} | Bits: {job['bits']}")
|
||||
print(f" 📍 Target: {job['target'][:16]}... | Transactions: {len(job['transactions'])}")
|
||||
return job
|
||||
|
||||
except Exception as e:
|
||||
print(f"Get block template error: {e}")
|
||||
return None
|
||||
|
||||
def calculate_share_difficulty(self, hash_hex, target_hex):
|
||||
"""Calculate actual share difficulty from hash"""
|
||||
try:
|
||||
hash_int = int(hash_hex, 16)
|
||||
target_int = int(target_hex, 16)
|
||||
|
||||
if hash_int == 0:
|
||||
return float('inf') # Perfect hash
|
||||
|
||||
# Bitcoin-style difficulty calculation
|
||||
# Lower hash = higher difficulty
|
||||
# Difficulty 1.0 = finding hash that meets network target exactly
|
||||
max_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
||||
|
||||
# Share difficulty = how hard this specific hash was to find
|
||||
difficulty = max_target / hash_int
|
||||
|
||||
return difficulty
|
||||
except Exception as e:
|
||||
print(f"Difficulty calculation error: {e}")
|
||||
return 0.0
|
||||
|
||||
def calculate_network_difficulty(self, target_hex):
|
||||
"""Calculate network difficulty from target"""
|
||||
try:
|
||||
target_int = int(target_hex, 16)
|
||||
|
||||
# Bitcoin difficulty 1.0 target
|
||||
max_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
||||
|
||||
# Network difficulty = how much harder than difficulty 1.0
|
||||
network_difficulty = max_target / target_int
|
||||
|
||||
return network_difficulty
|
||||
except Exception as e:
|
||||
print(f"Network difficulty calculation error: {e}")
|
||||
return 1.0
|
||||
|
||||
def submit_share(self, job, extranonce1, extranonce2, ntime, nonce, target_address=None):
|
||||
"""Validate share and submit block if valid"""
|
||||
try:
|
||||
print(f"Share: job={job['job_id']} nonce={nonce}")
|
||||
|
||||
# Use provided address or default
|
||||
address = target_address or self.target_address
|
||||
|
||||
@@ -269,16 +309,72 @@ class RinCoinStratumBase:
|
||||
block_hash = hashlib.sha256(hashlib.sha256(header).digest()).digest()
|
||||
block_hash_hex = block_hash[::-1].hex()
|
||||
|
||||
# Calculate real difficulties
|
||||
share_difficulty = self.calculate_share_difficulty(block_hash_hex, job['target'])
|
||||
network_difficulty = self.calculate_network_difficulty(job['target'])
|
||||
|
||||
# Check if hash meets target
|
||||
hash_int = int(block_hash_hex, 16)
|
||||
target_int = int(job['target'], 16)
|
||||
|
||||
# Enhanced logging
|
||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
difficulty_percentage = (share_difficulty / network_difficulty) * 100 if network_difficulty > 0 else 0
|
||||
|
||||
# Progress indicator based on percentage
|
||||
if difficulty_percentage >= 100:
|
||||
progress_icon = "🎉" # Block found!
|
||||
elif difficulty_percentage >= 50:
|
||||
progress_icon = "🔥" # Very close
|
||||
elif difficulty_percentage >= 10:
|
||||
progress_icon = "⚡" # Getting warm
|
||||
elif difficulty_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" 📍 Target: {job['target'][:16]}... | Height: {job['height']}")
|
||||
print(f" ⏰ Time: {ntime} | Extranonce: {extranonce1}:{extranonce2}")
|
||||
|
||||
if hash_int > target_int:
|
||||
# Valid share but not a block
|
||||
# Valid share but not a block - still send to node for validation
|
||||
print(f" ✅ Share accepted (below network difficulty)")
|
||||
|
||||
# Send to node anyway to validate our work
|
||||
try:
|
||||
# Build complete block for validation
|
||||
block = header
|
||||
tx_count = 1 + len(job['transactions'])
|
||||
block += self.encode_varint(tx_count)
|
||||
block += coinbase_wit
|
||||
for tx in job['transactions']:
|
||||
block += bytes.fromhex(tx['data'])
|
||||
|
||||
block_hex = block.hex()
|
||||
print(f" 🔍 Sending share to node for validation...")
|
||||
result = self.rpc_call("submitblock", [block_hex])
|
||||
|
||||
if result is None:
|
||||
print(f" 🎉 SURPRISE BLOCK! Node accepted our 'low difficulty' share as valid block!")
|
||||
return True, "Block found and submitted"
|
||||
else:
|
||||
print(f" 📊 Node rejected as expected: {result}")
|
||||
return True, "Share validated by node"
|
||||
|
||||
except Exception as e:
|
||||
print(f" ⚠️ Node validation error: {e}")
|
||||
return True, "Share accepted (node validation failed)"
|
||||
|
||||
return True, "Share accepted"
|
||||
|
||||
# Valid block! Build full block and submit
|
||||
print(f"BLOCK FOUND! Hash: {block_hash_hex}")
|
||||
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})")
|
||||
|
||||
# Build complete block
|
||||
block = header
|
||||
@@ -296,25 +392,25 @@ class RinCoinStratumBase:
|
||||
|
||||
# Submit block
|
||||
block_hex = block.hex()
|
||||
print(f"Submitting block of size {len(block_hex)//2} bytes...")
|
||||
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: {block_hash_hex}")
|
||||
print(f"💰 Reward: {job['coinbasevalue']/100000000:.2f} RIN -> {address}")
|
||||
print(f"📊 Block height: {job['height']}")
|
||||
print(f" ✅ Block accepted by network!")
|
||||
return True, "Block found and submitted"
|
||||
else:
|
||||
print(f"❌ Block rejected: {result}")
|
||||
print(f"📦 Block hash: {block_hash_hex}")
|
||||
print(f"📊 Block height: {job['height']}")
|
||||
print(f"🔍 Debug: Block size {len(block_hex)//2} bytes, {len(job['transactions'])} transactions")
|
||||
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}"
|
||||
|
||||
except Exception as e:
|
||||
print(f"Share submission error: {e}")
|
||||
return False, f"Submission error: {e}"
|
||||
|
||||
except Exception as e:
|
||||
print(f"Share submission error: {e}")
|
||||
return False, f"Submission error: {e}"
|
||||
|
||||
def send_stratum_response(self, client, msg_id, result, error=None):
|
||||
"""Send Stratum response to client"""
|
||||
@@ -381,7 +477,8 @@ class RinCoinStratumBase:
|
||||
username = params[0] if params else "anonymous"
|
||||
self.clients[addr]['username'] = username
|
||||
self.send_stratum_response(client, msg_id, True)
|
||||
print(f"[{addr}] Authorized as {username}")
|
||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f"[{timestamp}] 🔐 [{addr}] Authorized as {username}")
|
||||
|
||||
elif method == "mining.extranonce.subscribe":
|
||||
# Handle extranonce subscription
|
||||
@@ -551,13 +648,14 @@ class RinCoinStratumBase:
|
||||
server_socket.bind((self.stratum_host, self.stratum_port))
|
||||
server_socket.listen(10)
|
||||
|
||||
print(f"REAL Mining Stratum proxy ready!")
|
||||
print(f"Listening on {self.stratum_host}:{self.stratum_port}")
|
||||
print(f"Mining to: {self.target_address}")
|
||||
print(f"Current job: {self.current_job['job_id'] if self.current_job else 'None'}")
|
||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f"[{timestamp}] 🚀 REAL Mining Stratum proxy ready!")
|
||||
print(f" 📡 Listening on {self.stratum_host}:{self.stratum_port}")
|
||||
print(f" 💰 Mining to: {self.target_address}")
|
||||
print(f" 📊 Current job: {self.current_job['job_id'] if self.current_job else 'None'}")
|
||||
print("")
|
||||
print("Miner command:")
|
||||
print(f"./cpuminer -a rinhash -o stratum+tcp://{self.stratum_host}:{self.stratum_port} -u worker1 -p x -t 4")
|
||||
print(" 🔧 Miner command:")
|
||||
print(f" ./cpuminer -a rinhash -o stratum+tcp://{self.stratum_host}:{self.stratum_port} -u worker1 -p x -t 4")
|
||||
print("")
|
||||
|
||||
while self.running:
|
||||
|
Reference in New Issue
Block a user