success log

This commit is contained in:
Dobromir Popov
2025-09-15 23:05:12 +03:00
parent d18906f1b1
commit 21b166fbe7
5 changed files with 135 additions and 53 deletions

View File

@@ -33,11 +33,57 @@ class RinCoinStratumProxy:
self.running = True
self.extranonce1_counter = 0
# Logging setup
self.log_file = "mining_log.txt"
self.init_log_file()
print(f"RinCoin Stratum Proxy Server")
print(f"Stratum: {stratum_host}:{stratum_port}")
print(f"RPC: {rpc_host}:{rpc_port}")
print(f"Target: {target_address}")
def init_log_file(self):
"""Initialize mining log file with header"""
try:
with open(self.log_file, 'w') as f:
f.write("=" * 80 + "\n")
f.write("RinCoin Mining Log\n")
f.write("=" * 80 + "\n")
f.write(f"Started: {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write(f"Target Address: {self.target_address}\n")
f.write(f"Stratum: {self.stratum_host}:{self.stratum_port}\n")
f.write(f"RPC: {self.rpc_host}:{self.rpc_port}\n")
f.write("=" * 80 + "\n\n")
except Exception as e:
print(f"Failed to initialize log file: {e}")
def log_hash_found(self, hash_hex, difficulty, height, reward, nonce, ntime):
"""Log found hash to file"""
try:
timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
with open(self.log_file, 'a') as f:
f.write(f"[{timestamp}] 🎉 HASH FOUND!\n")
f.write(f" Hash: {hash_hex}\n")
f.write(f" Difficulty: {difficulty:.6f}\n")
f.write(f" Height: {height}\n")
f.write(f" Reward: {reward:.8f} RIN\n")
f.write(f" Nonce: {nonce}\n")
f.write(f" Time: {ntime}\n")
f.write("-" * 40 + "\n")
except Exception as e:
print(f"Failed to log hash: {e}")
def log_wallet_balance(self):
"""Log current wallet balance to file"""
try:
balance = self.rpc_call("getbalance")
if balance is not None:
timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
with open(self.log_file, 'a') as f:
f.write(f"[{timestamp}] 💰 Wallet Balance: {balance:.8f} RIN\n")
except Exception as e:
print(f"Failed to log wallet balance: {e}")
def rpc_call(self, method, params=[]):
"""Make RPC call to RinCoin node"""
try:
@@ -357,6 +403,10 @@ class RinCoinStratumProxy:
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
@@ -379,6 +429,8 @@ class RinCoinStratumProxy:
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}")
@@ -563,6 +615,7 @@ class RinCoinStratumProxy:
def job_updater(self):
"""Periodically update mining jobs"""
balance_log_counter = 0
while self.running:
try:
time.sleep(30) # Update every 30 seconds
@@ -574,6 +627,12 @@ class RinCoinStratumProxy:
if new_height > old_height:
print(f"New block detected! Broadcasting new job...")
self.broadcast_new_job()
# Log wallet balance every 10 minutes (20 cycles of 30 seconds)
balance_log_counter += 1
if balance_log_counter >= 20:
self.log_wallet_balance()
balance_log_counter = 0
except Exception as e:
print(f"Job updater error: {e}")
@@ -591,6 +650,9 @@ class RinCoinStratumProxy:
print(f"Current height: {blockchain_info.get('blocks', 'unknown')}")
print(f"Chain: {blockchain_info.get('chain', 'unknown')}")
# Log initial wallet balance
self.log_wallet_balance()
# Get initial block template
if not self.get_block_template():
print("Failed to get initial block template!")
@@ -611,6 +673,7 @@ class RinCoinStratumProxy:
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(f" 📝 Mining log: {self.log_file}")
print("")
print(" 🔧 Miner command:")
print(f" ./cpuminer -a rinhash -o stratum+tcp://{self.stratum_host}:{self.stratum_port} -u worker1 -p x -t 4")