more difficulty fns
This commit is contained in:
@@ -15,11 +15,11 @@ import struct
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
class RinCoinStratumProxy:
|
||||
def __init__(self, stratum_host='0.0.0.0', stratum_port=3334,
|
||||
rpc_host='127.0.0.1', rpc_port=9556,
|
||||
def __init__(self, stratum_host='0.0.0.0', stratum_port=3334,
|
||||
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 = {
|
||||
@@ -398,16 +400,16 @@ class RinCoinStratumProxy:
|
||||
try:
|
||||
# Get current network difficulty
|
||||
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
|
||||
initial_difficulty = min(optimal_difficulty, scaled_difficulty)
|
||||
|
||||
@@ -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,13 +617,24 @@ 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")
|
||||
# Update stats for test mode
|
||||
self.stats['total_shares'] += 1
|
||||
self.stats['accepted_shares'] += 1
|
||||
|
||||
|
||||
# Always submit in test mode
|
||||
should_submit = True
|
||||
else:
|
||||
@@ -638,17 +651,17 @@ class RinCoinStratumProxy:
|
||||
current_time = time.time()
|
||||
self.clients[addr]['share_count'] = self.clients[addr].get('share_count', 0) + 1
|
||||
self.clients[addr]['last_share_time'] = current_time
|
||||
|
||||
|
||||
# Calculate hashrate from this share
|
||||
# Hashrate = difficulty * 2^32 / time_to_find_share
|
||||
client_difficulty = self.clients[addr].get('stratum_difficulty', 0.001)
|
||||
last_share_time = self.clients[addr].get('last_share_time', current_time - 60)
|
||||
time_since_last = max(1, current_time - last_share_time) # Avoid division by zero
|
||||
|
||||
|
||||
# Calculate instantaneous hashrate for this share
|
||||
diff1_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
||||
instant_hashrate = (client_difficulty * (2**32)) / time_since_last
|
||||
|
||||
|
||||
# Store hashrate sample (keep last 10 samples)
|
||||
if 'hashrate_samples' not in self.clients[addr]:
|
||||
self.clients[addr]['hashrate_samples'] = []
|
||||
@@ -656,36 +669,38 @@ class RinCoinStratumProxy:
|
||||
# Keep only last 10 samples
|
||||
if len(self.clients[addr]['hashrate_samples']) > 10:
|
||||
self.clients[addr]['hashrate_samples'] = self.clients[addr]['hashrate_samples'][-10:]
|
||||
|
||||
|
||||
# Calculate average hashrate from recent samples
|
||||
if self.clients[addr]['hashrate_samples']:
|
||||
total_hashrate = sum(hr for _, hr in self.clients[addr]['hashrate_samples'])
|
||||
self.clients[addr]['estimated_hashrate'] = total_hashrate / len(self.clients[addr]['hashrate_samples'])
|
||||
|
||||
|
||||
print(f" ⛏️ Miner {addr}: {self.clients[addr]['estimated_hashrate']:.0f} H/s (avg of {len(self.clients[addr]['hashrate_samples'])} samples)")
|
||||
|
||||
|
||||
# Update global stats
|
||||
self.stats['total_shares'] += 1
|
||||
self.stats['accepted_shares'] += 1
|
||||
|
||||
|
||||
# Check if we should adjust difficulty
|
||||
self.adjust_client_difficulty(addr)
|
||||
|
||||
|
||||
# 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_all = True
|
||||
print("🧪 TEST MODE: Will submit ALL blocks for validation (submit_all_blocks=True)")
|
||||
submit_threshold = 0.1 # Default 10%
|
||||
|
||||
proxy = RinCoinStratumProxy(submit_all_blocks=submit_all)
|
||||
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, submit_threshold=submit_threshold)
|
||||
proxy.start()
|
||||
|
Reference in New Issue
Block a user