more difficulty fns

This commit is contained in:
Dobromir Popov
2025-09-23 18:38:28 +03:00
parent a6c271d3f3
commit 7a806e53cb
3 changed files with 74 additions and 33 deletions

View File

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

View File

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

View File

@@ -19,7 +19,7 @@ class RinCoinStratumProxy:
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 = {
@@ -400,12 +402,12 @@ class RinCoinStratumProxy:
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
@@ -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,6 +617,17 @@ 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")
@@ -674,18 +687,20 @@ class RinCoinStratumProxy:
# 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_threshold = 0.1 # Default 10%
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)
proxy = RinCoinStratumProxy(submit_all_blocks=submit_all, submit_threshold=submit_threshold)
proxy.start()