Files
mines/rin/proxy
Dobromir Popov d18906f1b1 fix name
2025-09-15 22:58:27 +03:00
..
2025-09-15 22:58:27 +03:00
2025-09-15 22:58:27 +03:00

RinCoin Stratum Proxy

This repository contains stratum proxy implementations for RinCoin mining.

Problem Analysis

Original Issue

You were mining for 23+ hours with ~750 kH/s hashrate but finding no blocks, despite the network difficulty (0.544320) suggesting blocks should be found approximately every 52 minutes.

Root Cause Analysis

After analyzing the original stratum proxy code, I found several critical issues:

1. Incorrect Target Comparison (CRITICAL)

# WRONG (original code line 342)
if hash_int > target_int:
    # Valid share but not a block

# CORRECT (should be)
if hash_int <= target_int:
    # Valid block found!

Impact: The logic was inverted! Shares that met the target (valid blocks) were being treated as "shares below network difficulty", while shares that didn't meet the target were being treated as potential blocks.

2. Bits-to-Target Conversion Issues

The original bits_to_target() function had potential issues with the Bitcoin target calculation that could result in incorrect target values.

3. Block Header Endianness

Some fields in the block header construction had inconsistent endianness handling, which could cause hash calculation errors.

4. Missing Hash Comparison Debug Info

The original code didn't show the actual hash vs target comparison, making it difficult to debug why blocks weren't being found.

Fixed Implementation

Key Fixes Applied

  1. Fixed Target Comparison Logic

    • Changed hash_int > target_int to hash_int <= target_int
    • Added debug output showing hash vs target comparison
  2. Improved Bits-to-Target Conversion

    • Implemented proper Bitcoin-style bits to target conversion
    • Added error handling and fallback values
  3. Enhanced Block Header Construction

    • Fixed endianness consistency across all header fields
    • Ensured proper byte ordering for hash calculation
  4. Better Debugging

    • Added detailed logging showing hash vs target
    • Lowered mining difficulty for testing (0.00001)
    • Show actual hash and target values in hex
  5. Simplified Share Validation

    • Removed confusing "send shares to node for validation" logic
    • Focus on finding actual valid blocks

Directory Structure

/mnt/shared/DEV/repos/d-popov.com/mines/rin/proxy/
├── custom/                          # Our implementation
│   ├── stratum_proxy.py            # Fixed version with all issues resolved
│   └── start_stratum_proxy.sh      # Startup script
├── third-party/                    # External stratum implementations
│   └── [stratum library files]     # Node.js stratum implementation
├── README.md                       # This file
└── CRITICAL_FIXES.md               # Detailed explanation of fixes

Usage

1. Start Stratum Proxy

cd /mnt/shared/DEV/repos/d-popov.com/mines/rin/proxy/custom
./start_stratum_proxy.sh

2. Connect Miner

sudo docker exec -it amd-strix-halo-llama-rocm bash -c "/mnt/dl/rinhash/cpuminer-opt-rin/cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3334 -u user -p pass -t 28"

Expected Behavior with Fixed Version

With your ~750 kH/s hashrate and network difficulty of 0.544320:

  • Block finding frequency: Approximately every 52 minutes
  • Share acceptance: All valid shares will be accepted
  • Block detection: When hash ≤ target, block will be immediately submitted
  • Debug output: You'll see exact hash vs target comparisons

Monitoring

The fixed version provides enhanced logging:

[2025-09-15 22:23:08] 🎉 SHARE: job=job_00000002 | nonce=380787eb | hash=05a73adec63707d3...
   🎯 Share Diff: 1.05e-08 | Network Diff: 0.544320
   📈 Progress: 0.0000% of network difficulty
   📍 Target: 00000001d64e0000... | Height: 246531
   ⏰ Time: 68c86788 | Extranonce: 00000001:00000000
   🔍 Hash vs Target: 123456789... <= 987654321... (shows if block found)

When a block is found, you'll see:

   🎉 BLOCK FOUND! Hash: [hash]
   💰 Reward: [amount] RIN -> [address]
   📦 Submitting block of size [bytes] bytes...
   ✅ Block accepted by network!

Testing

The fixed version sets a very low mining difficulty (0.00001) for initial testing. This means you should find "test blocks" very frequently to verify the logic is working. Once confirmed, the difficulty will automatically adjust to network levels.

Comparison with Third-Party Implementation

The third-party/ directory contains a Node.js stratum implementation for cross-reference and validation of our approach.

Next Steps

  1. Test the fixed implementation - Run for 1-2 hours and verify block finding frequency
  2. Monitor for blocks - With the fixes, you should find blocks at the expected rate
  3. Production deployment - Once validated, deploy the fixed version for full mining

The critical issue was the inverted comparison logic. With this fixed, your mining operation should start finding blocks at the expected frequency based on your hashrate and network difficulty.