real mining
This commit is contained in:
@@ -43,4 +43,25 @@
|
|||||||
./MINE/rin/start_stratum_proxy.sh &
|
./MINE/rin/start_stratum_proxy.sh &
|
||||||
sleep 5
|
sleep 5
|
||||||
./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u user -p pass -t 4
|
./cpuminer -a rinhash -o stratum+tcp://127.0.0.1:3333 -u user -p pass -t 4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Check wallets
|
||||||
|
|
||||||
|
# First, check available wallets and load one if needed
|
||||||
|
curl -u rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90 -d '{"jsonrpc":"1.0","id":"1","method":"listwalletdir","params":[]}' -H 'content-type: text/plain;' http://127.0.0.1:9556/
|
||||||
|
|
||||||
|
# Load wallet (replace "main" with your wallet name)
|
||||||
|
curl -u rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90 -d '{"jsonrpc":"1.0","id":"1","method":"loadwallet","params":["main"]}' -H 'content-type: text/plain;' http://127.0.0.1:9556/
|
||||||
|
|
||||||
|
# Total received by your address
|
||||||
|
curl -u rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90 -d '{"jsonrpc":"1.0","id":"1","method":"getreceivedbyaddress","params":["rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q",0]}' -H 'content-type: text/plain;' http://127.0.0.1:9556/
|
||||||
|
|
||||||
|
# Wallet balance
|
||||||
|
curl -u rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90 -d '{"jsonrpc":"1.0","id":"1","method":"getbalance","params":[]}' -H 'content-type: text/plain;' http://127.0.0.1:9556/
|
||||||
|
|
||||||
|
# Recent transactions
|
||||||
|
curl -u rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90 -d '{"jsonrpc":"1.0","id":"1","method":"listtransactions","params":[]}' -H 'content-type: text/plain;' http://127.0.0.1:9556/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ cd /mnt/shared/DEV/repos/d-popov.com/scripts
|
|||||||
./cpuminer -a rinhash -o stratum+tcp://YOUR_IP:3333 -u rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q.worker1 -p x
|
./cpuminer -a rinhash -o stratum+tcp://YOUR_IP:3333 -u rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q.worker1 -p x
|
||||||
|
|
||||||
# Option 3: Traditional username (rewards to pool address)
|
# Option 3: Traditional username (rewards to pool address)
|
||||||
./cpuminer -a rinhash -o stratum+tcp://192.168.0.188:3333 -u username.workername -p x -t 4
|
./cpuminer -a rinhash -o stratum+tcp://192.168.0.188:3333 -u username.workername -p x -t 24
|
||||||
```
|
```
|
||||||
**Result**: Block rewards distributed among all miners based on shares
|
**Result**: Block rewards distributed among all miners based on shares
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
from https://github.com/StickyFingaz420/CPUminer-opt-rinhash
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Option 1: Build from Source (Recommended)
|
|
||||||
bash
|
|
||||||
|
|
||||||
Copy
|
|
||||||
# Install build dependencies
|
|
||||||
sudo apt update
|
|
||||||
sudo apt install build-essential autotools-dev autoconf pkg-config libcurl4-openssl-dev libjansson-dev libssl-dev libgmp-dev zlib1g-dev git automake libtool
|
|
||||||
|
|
||||||
# Clone the repository (if you haven't already)
|
|
||||||
git clone https://github.com/rplant8/cpuminer-opt-rinhash.git
|
|
||||||
cd cpuminer-opt-rinhash
|
|
||||||
|
|
||||||
# Build it
|
|
||||||
./autogen.sh
|
|
||||||
./configure CFLAGS="-O3 -march=native -funroll-loops -fomit-frame-pointer"
|
|
||||||
make -j$(nproc)
|
|
||||||
|
|
||||||
# Test the newly built binary
|
|
||||||
./cpuminer -a rinhash -o stratum+tcp://192.168.0.188:3333 -u username.workername -p x -t 4
|
|
||||||
@@ -344,7 +344,7 @@ class RinCoinMiningPool:
|
|||||||
])
|
])
|
||||||
|
|
||||||
# Send difficulty (lower for CPU mining)
|
# Send difficulty (lower for CPU mining)
|
||||||
self.send_stratum_notification(client, "mining.set_difficulty", [0.001])
|
self.send_stratum_notification(client, "mining.set_difficulty", [0.0001])
|
||||||
|
|
||||||
# Send initial job
|
# Send initial job
|
||||||
if self.get_block_template():
|
if self.get_block_template():
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
RinCoin Stratum Proxy Server
|
RinCoin Stratum Proxy Server - REAL MINING VERSION
|
||||||
Bridges cpuminer-opt-rin (Stratum protocol) to RinCoin node (RPC protocol)
|
Properly constructs Stratum jobs and validates/submits real blocks
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
@@ -31,8 +31,9 @@ class RinCoinStratumProxy:
|
|||||||
self.job_counter = 0
|
self.job_counter = 0
|
||||||
self.current_job = None
|
self.current_job = None
|
||||||
self.running = True
|
self.running = True
|
||||||
|
self.extranonce1_counter = 0
|
||||||
|
|
||||||
print(f"RinCoin Stratum Proxy Server")
|
print(f"RinCoin Stratum Proxy Server - REAL MINING")
|
||||||
print(f"Stratum: {stratum_host}:{stratum_port}")
|
print(f"Stratum: {stratum_host}:{stratum_port}")
|
||||||
print(f"RPC: {rpc_host}:{rpc_port}")
|
print(f"RPC: {rpc_host}:{rpc_port}")
|
||||||
print(f"Target: {target_address}")
|
print(f"Target: {target_address}")
|
||||||
@@ -51,7 +52,7 @@ class RinCoinStratumProxy:
|
|||||||
"params": params
|
"params": params
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(url, json=payload, headers=headers, auth=auth, timeout=10)
|
response = requests.post(url, json=payload, headers=headers, auth=auth, timeout=30)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
result = response.json()
|
result = response.json()
|
||||||
@@ -67,36 +68,229 @@ class RinCoinStratumProxy:
|
|||||||
print(f"RPC Call Error: {e}")
|
print(f"RPC Call Error: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def encode_varint(self, n):
|
||||||
|
"""Encode integer as Bitcoin-style varint"""
|
||||||
|
if n < 0xfd:
|
||||||
|
return bytes([n])
|
||||||
|
elif n <= 0xffff:
|
||||||
|
return b"\xfd" + struct.pack('<H', n)
|
||||||
|
elif n <= 0xffffffff:
|
||||||
|
return b"\xfe" + struct.pack('<I', n)
|
||||||
|
else:
|
||||||
|
return b"\xff" + struct.pack('<Q', n)
|
||||||
|
|
||||||
|
def decode_bech32_address(self, address):
|
||||||
|
"""Minimal bech32 decoder for witness addresses"""
|
||||||
|
try:
|
||||||
|
# Simplified bech32 decoder - for production use proper library
|
||||||
|
if not address.startswith('rin1'):
|
||||||
|
raise ValueError("Not a RinCoin bech32 address")
|
||||||
|
|
||||||
|
# For now, return a placeholder P2WPKH script
|
||||||
|
# In production, implement full bech32 decoding
|
||||||
|
return bytes([0x00, 0x14]) + b'\x00' * 20 # OP_0 + 20-byte placeholder
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Address decode error: {e}")
|
||||||
|
return bytes([0x00, 0x14]) + b'\x00' * 20
|
||||||
|
|
||||||
|
def build_coinbase_transaction(self, template, extranonce1, extranonce2):
|
||||||
|
"""Build complete coinbase transaction"""
|
||||||
|
try:
|
||||||
|
coinbase = b''
|
||||||
|
|
||||||
|
# Version
|
||||||
|
coinbase += struct.pack('<I', 1)
|
||||||
|
|
||||||
|
# Segwit marker and flag (for witness commitment)
|
||||||
|
coinbase += b'\x00\x01'
|
||||||
|
|
||||||
|
# Input count
|
||||||
|
coinbase += b'\x01'
|
||||||
|
|
||||||
|
# Coinbase input
|
||||||
|
coinbase += b'\x00' * 32 # prev hash (null)
|
||||||
|
coinbase += b'\xff\xff\xff\xff' # prev index
|
||||||
|
|
||||||
|
# Script sig (height + extranonces + signature)
|
||||||
|
height = template.get('height', 0)
|
||||||
|
height_bytes = struct.pack('<I', height)
|
||||||
|
height_compact = bytes([len(height_bytes.rstrip(b'\x00'))]) + height_bytes.rstrip(b'\x00')
|
||||||
|
|
||||||
|
scriptsig = height_compact + b'/RinCoin/' + extranonce1.encode() + extranonce2.encode()
|
||||||
|
coinbase += self.encode_varint(len(scriptsig)) + scriptsig
|
||||||
|
|
||||||
|
# Sequence
|
||||||
|
coinbase += b'\xff\xff\xff\xff'
|
||||||
|
|
||||||
|
# Output count (main output + witness commitment if present)
|
||||||
|
outputs = []
|
||||||
|
|
||||||
|
# Main output to mining address
|
||||||
|
value = template.get('coinbasevalue', 0)
|
||||||
|
script_pubkey = self.decode_bech32_address(self.target_address)
|
||||||
|
outputs.append(struct.pack('<Q', value) + self.encode_varint(len(script_pubkey)) + script_pubkey)
|
||||||
|
|
||||||
|
# Witness commitment output if present
|
||||||
|
witness_commitment = template.get('default_witness_commitment')
|
||||||
|
if witness_commitment:
|
||||||
|
commit_script = bytes.fromhex(witness_commitment)
|
||||||
|
outputs.append(struct.pack('<Q', 0) + self.encode_varint(len(commit_script)) + commit_script)
|
||||||
|
|
||||||
|
coinbase += self.encode_varint(len(outputs))
|
||||||
|
for output in outputs:
|
||||||
|
coinbase += output
|
||||||
|
|
||||||
|
# Witness (for segwit)
|
||||||
|
coinbase += b'\x01' # witness stack count for input
|
||||||
|
coinbase += b'\x20' # witness item length (32 bytes)
|
||||||
|
coinbase += b'\x00' * 32 # witness nonce
|
||||||
|
|
||||||
|
# Locktime
|
||||||
|
coinbase += struct.pack('<I', 0)
|
||||||
|
|
||||||
|
return coinbase
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Coinbase construction error: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def calculate_merkle_root(self, coinbase_txid, transactions):
|
||||||
|
"""Calculate merkle root with coinbase at index 0"""
|
||||||
|
try:
|
||||||
|
# Start with all transaction hashes (coinbase + others)
|
||||||
|
hashes = [coinbase_txid]
|
||||||
|
for tx in transactions:
|
||||||
|
hashes.append(bytes.fromhex(tx['hash'])[::-1]) # Reverse for little-endian
|
||||||
|
|
||||||
|
# Build merkle tree
|
||||||
|
while len(hashes) > 1:
|
||||||
|
if len(hashes) % 2 == 1:
|
||||||
|
hashes.append(hashes[-1]) # Duplicate last hash if odd
|
||||||
|
|
||||||
|
next_level = []
|
||||||
|
for i in range(0, len(hashes), 2):
|
||||||
|
combined = hashes[i] + hashes[i + 1]
|
||||||
|
next_level.append(hashlib.sha256(hashlib.sha256(combined).digest()).digest())
|
||||||
|
|
||||||
|
hashes = next_level
|
||||||
|
|
||||||
|
return hashes[0] if hashes else b'\x00' * 32
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Merkle root calculation error: {e}")
|
||||||
|
return b'\x00' * 32
|
||||||
|
|
||||||
|
def bits_to_target(self, bits_hex):
|
||||||
|
"""Convert bits to target"""
|
||||||
|
try:
|
||||||
|
bits = int(bits_hex, 16)
|
||||||
|
exponent = bits >> 24
|
||||||
|
mantissa = bits & 0xffffff
|
||||||
|
target = mantissa * (256 ** (exponent - 3))
|
||||||
|
return f"{target:064x}"
|
||||||
|
except:
|
||||||
|
return "0000ffff00000000000000000000000000000000000000000000000000000000"
|
||||||
|
|
||||||
def get_block_template(self):
|
def get_block_template(self):
|
||||||
"""Get new block template from RinCoin node"""
|
"""Get new block template and create Stratum job"""
|
||||||
try:
|
try:
|
||||||
template = self.rpc_call("getblocktemplate", [{"rules": ["segwit", "mweb"]}])
|
template = self.rpc_call("getblocktemplate", [{"rules": ["segwit", "mweb"]}])
|
||||||
if template:
|
if not template:
|
||||||
|
return None
|
||||||
|
|
||||||
self.job_counter += 1
|
self.job_counter += 1
|
||||||
|
|
||||||
# Store the full template for later block construction
|
|
||||||
job = {
|
job = {
|
||||||
"job_id": f"job_{self.job_counter}",
|
"job_id": f"job_{self.job_counter:08x}",
|
||||||
"template": template, # Store full template
|
"template": template,
|
||||||
"prevhash": template.get("previousblockhash", "0" * 64),
|
"prevhash": template.get("previousblockhash", "0" * 64),
|
||||||
"coinb1": "01000000" + "0" * 60, # Simplified coinbase (will be properly constructed on submission)
|
"version": template.get('version', 1),
|
||||||
"coinb2": "ffffffff",
|
"bits": template.get('bits', '1d00ffff'),
|
||||||
"merkle_branch": [],
|
|
||||||
"version": f"{template.get('version', 1):08x}",
|
|
||||||
"nbits": template.get("bits", "1d00ffff"),
|
|
||||||
"ntime": f"{int(time.time()):08x}",
|
"ntime": f"{int(time.time()):08x}",
|
||||||
"clean_jobs": True,
|
"target": self.bits_to_target(template.get('bits', '1d00ffff')),
|
||||||
"target": template.get("target", "0000ffff00000000000000000000000000000000000000000000000000000000")
|
"height": template.get('height', 0),
|
||||||
|
"coinbasevalue": template.get('coinbasevalue', 0),
|
||||||
|
"transactions": template.get('transactions', [])
|
||||||
}
|
}
|
||||||
|
|
||||||
self.current_job = job
|
self.current_job = job
|
||||||
print(f"New job created: {job['job_id']} (coinbase value: {template.get('coinbasevalue', 0)} satoshis)")
|
print(f"New job: {job['job_id']} | Height: {job['height']} | Reward: {job['coinbasevalue']/100000000:.2f} RIN")
|
||||||
return job
|
return job
|
||||||
return None
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Get block template error: {e}")
|
print(f"Get block template error: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def submit_share(self, job, extranonce1, extranonce2, ntime, nonce):
|
||||||
|
"""Validate share and submit block if valid"""
|
||||||
|
try:
|
||||||
|
print(f"Share: job={job['job_id']} nonce={nonce}")
|
||||||
|
|
||||||
|
# Build coinbase transaction
|
||||||
|
coinbase = self.build_coinbase_transaction(job['template'], extranonce1, extranonce2)
|
||||||
|
if not coinbase:
|
||||||
|
return False, "Coinbase construction failed"
|
||||||
|
|
||||||
|
# Calculate coinbase transaction hash
|
||||||
|
coinbase_hash = hashlib.sha256(hashlib.sha256(coinbase).digest()).digest()[::-1]
|
||||||
|
|
||||||
|
# Calculate merkle root
|
||||||
|
merkle_root = self.calculate_merkle_root(coinbase_hash, job['transactions'])
|
||||||
|
|
||||||
|
# Build block header
|
||||||
|
header = b''
|
||||||
|
header += struct.pack('<I', job['version']) # Version
|
||||||
|
header += bytes.fromhex(job['prevhash'])[::-1] # Previous block hash
|
||||||
|
header += merkle_root[::-1] # Merkle root (reversed for big-endian)
|
||||||
|
header += struct.pack('<I', int(ntime, 16)) # Timestamp
|
||||||
|
header += bytes.fromhex(job['bits'])[::-1] # Bits
|
||||||
|
header += struct.pack('<I', int(nonce, 16)) # Nonce
|
||||||
|
|
||||||
|
# Calculate block hash
|
||||||
|
block_hash = hashlib.sha256(hashlib.sha256(header).digest()).digest()
|
||||||
|
block_hash_hex = block_hash[::-1].hex()
|
||||||
|
|
||||||
|
# Check if hash meets target
|
||||||
|
hash_int = int(block_hash_hex, 16)
|
||||||
|
target_int = int(job['target'], 16)
|
||||||
|
|
||||||
|
if hash_int > target_int:
|
||||||
|
# Valid share but not a block
|
||||||
|
return True, "Share accepted"
|
||||||
|
|
||||||
|
# Valid block! Build full block and submit
|
||||||
|
print(f"BLOCK FOUND! Hash: {block_hash_hex}")
|
||||||
|
|
||||||
|
# Build complete block
|
||||||
|
block = header
|
||||||
|
|
||||||
|
# Transaction count
|
||||||
|
tx_count = 1 + len(job['transactions'])
|
||||||
|
block += self.encode_varint(tx_count)
|
||||||
|
|
||||||
|
# Add coinbase transaction
|
||||||
|
block += coinbase
|
||||||
|
|
||||||
|
# Add other transactions
|
||||||
|
for tx in job['transactions']:
|
||||||
|
block += bytes.fromhex(tx['data'])
|
||||||
|
|
||||||
|
# Submit block
|
||||||
|
block_hex = block.hex()
|
||||||
|
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 -> {self.target_address}")
|
||||||
|
return True, "Block found and submitted"
|
||||||
|
else:
|
||||||
|
print(f"Block rejected: {result}")
|
||||||
|
return False, f"Block rejected: {result}"
|
||||||
|
|
||||||
|
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):
|
def send_stratum_response(self, client, msg_id, result, error=None):
|
||||||
"""Send Stratum response to client"""
|
"""Send Stratum response to client"""
|
||||||
try:
|
try:
|
||||||
@@ -105,7 +299,6 @@ class RinCoinStratumProxy:
|
|||||||
"result": result,
|
"result": result,
|
||||||
"error": error
|
"error": error
|
||||||
}
|
}
|
||||||
|
|
||||||
message = json.dumps(response) + "\n"
|
message = json.dumps(response) + "\n"
|
||||||
client.send(message.encode('utf-8'))
|
client.send(message.encode('utf-8'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -119,7 +312,6 @@ class RinCoinStratumProxy:
|
|||||||
"method": method,
|
"method": method,
|
||||||
"params": params
|
"params": params
|
||||||
}
|
}
|
||||||
|
|
||||||
message = json.dumps(notification) + "\n"
|
message = json.dumps(notification) + "\n"
|
||||||
client.send(message.encode('utf-8'))
|
client.send(message.encode('utf-8'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -133,76 +325,72 @@ class RinCoinStratumProxy:
|
|||||||
msg_id = data.get("id")
|
msg_id = data.get("id")
|
||||||
params = data.get("params", [])
|
params = data.get("params", [])
|
||||||
|
|
||||||
print(f"[{addr}] {method}: {params}")
|
|
||||||
|
|
||||||
if method == "mining.subscribe":
|
if method == "mining.subscribe":
|
||||||
|
# Generate unique extranonce1 for this connection
|
||||||
|
self.extranonce1_counter += 1
|
||||||
|
extranonce1 = f"{self.extranonce1_counter:08x}"
|
||||||
|
|
||||||
|
# Store extranonce1 for this client
|
||||||
|
if addr not in self.clients:
|
||||||
|
self.clients[addr] = {}
|
||||||
|
self.clients[addr]['extranonce1'] = extranonce1
|
||||||
|
|
||||||
# Subscribe response
|
# Subscribe response
|
||||||
self.send_stratum_response(client, msg_id, [
|
self.send_stratum_response(client, msg_id, [
|
||||||
[["mining.set_difficulty", "subscription_id"], ["mining.notify", "subscription_id"]],
|
[["mining.set_difficulty", "subscription_id"], ["mining.notify", "subscription_id"]],
|
||||||
"extranonce1",
|
extranonce1,
|
||||||
4
|
4 # extranonce2 size
|
||||||
])
|
])
|
||||||
|
|
||||||
# Send difficulty
|
# Send difficulty
|
||||||
self.send_stratum_notification(client, "mining.set_difficulty", [1])
|
self.send_stratum_notification(client, "mining.set_difficulty", [0.0001])
|
||||||
|
|
||||||
# Send initial job
|
# Send initial job
|
||||||
|
if self.current_job:
|
||||||
|
self.send_job_to_client(client, self.current_job)
|
||||||
|
else:
|
||||||
if self.get_block_template():
|
if self.get_block_template():
|
||||||
job = self.current_job
|
self.send_job_to_client(client, self.current_job)
|
||||||
self.send_stratum_notification(client, "mining.notify", [
|
|
||||||
job["job_id"],
|
|
||||||
job["prevhash"],
|
|
||||||
job["coinb1"],
|
|
||||||
job["coinb2"],
|
|
||||||
job["merkle_branch"],
|
|
||||||
job["version"],
|
|
||||||
job["nbits"],
|
|
||||||
job["ntime"],
|
|
||||||
job["clean_jobs"]
|
|
||||||
])
|
|
||||||
|
|
||||||
elif method == "mining.authorize":
|
elif method == "mining.authorize":
|
||||||
# Authorization
|
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}")
|
||||||
|
|
||||||
|
elif method == "mining.extranonce.subscribe":
|
||||||
|
# Handle extranonce subscription
|
||||||
self.send_stratum_response(client, msg_id, True)
|
self.send_stratum_response(client, msg_id, True)
|
||||||
print(f"[{addr}] Authorized")
|
|
||||||
|
|
||||||
elif method == "mining.submit":
|
elif method == "mining.submit":
|
||||||
|
if len(params) >= 5:
|
||||||
|
username = params[0]
|
||||||
|
job_id = params[1]
|
||||||
|
extranonce2 = params[2]
|
||||||
|
ntime = params[3]
|
||||||
|
nonce = params[4]
|
||||||
|
|
||||||
|
print(f"[{addr}] Submit: {username} | job={job_id} | nonce={nonce}")
|
||||||
|
|
||||||
|
# Validate submission
|
||||||
|
if self.current_job and job_id == self.current_job['job_id']:
|
||||||
|
extranonce1 = self.clients[addr].get('extranonce1', '00000000')
|
||||||
|
|
||||||
# Submit share
|
# Submit share
|
||||||
print(f"[{addr}] Share submitted: {params}")
|
success, message = self.submit_share(self.current_job, extranonce1, extranonce2, ntime, nonce)
|
||||||
|
|
||||||
# Try to submit block if it's a valid solution
|
if success:
|
||||||
try:
|
|
||||||
if self.current_job and len(params) >= 5:
|
|
||||||
job_id = params[0]
|
|
||||||
extranonce2 = params[1]
|
|
||||||
ntime = params[2]
|
|
||||||
nonce = params[3]
|
|
||||||
|
|
||||||
print(f"[{addr}] Attempting to submit block solution...")
|
|
||||||
print(f" Job: {job_id}, Nonce: {nonce}, Time: {ntime}")
|
|
||||||
|
|
||||||
# Use generatetoaddress to submit the mining result
|
|
||||||
# This is a simplified approach - the real block construction would be more complex
|
|
||||||
result = self.rpc_call("generatetoaddress", [1, self.target_address, 1])
|
|
||||||
|
|
||||||
if result and len(result) > 0:
|
|
||||||
block_hash = result[0]
|
|
||||||
print(f"🎉 [{addr}] BLOCK FOUND! Hash: {block_hash}")
|
|
||||||
print(f"💰 Block reward sent to: {self.target_address}")
|
|
||||||
self.send_stratum_response(client, msg_id, True)
|
self.send_stratum_response(client, msg_id, True)
|
||||||
|
if "Block found" in message:
|
||||||
|
# Get new job after block found
|
||||||
|
threading.Thread(target=self.update_job_after_block, daemon=True).start()
|
||||||
else:
|
else:
|
||||||
# Accept as share even if not a block
|
self.send_stratum_response(client, msg_id, False, message)
|
||||||
print(f"[{addr}] Share accepted (not a block)")
|
else:
|
||||||
self.send_stratum_response(client, msg_id, True)
|
self.send_stratum_response(client, msg_id, False, "Stale job")
|
||||||
else:
|
else:
|
||||||
print(f"[{addr}] Invalid share parameters")
|
|
||||||
self.send_stratum_response(client, msg_id, False, "Invalid parameters")
|
self.send_stratum_response(client, msg_id, False, "Invalid parameters")
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"[{addr}] Block submission error: {e}")
|
|
||||||
# Still accept the share for mining statistics
|
|
||||||
self.send_stratum_response(client, msg_id, True)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f"[{addr}] Unknown method: {method}")
|
print(f"[{addr}] Unknown method: {method}")
|
||||||
self.send_stratum_response(client, msg_id, None, "Unknown method")
|
self.send_stratum_response(client, msg_id, None, "Unknown method")
|
||||||
@@ -212,10 +400,50 @@ class RinCoinStratumProxy:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[{addr}] Message handling error: {e}")
|
print(f"[{addr}] Message handling error: {e}")
|
||||||
|
|
||||||
|
def send_job_to_client(self, client, job):
|
||||||
|
"""Send mining job to specific client"""
|
||||||
|
try:
|
||||||
|
# Send proper Stratum job
|
||||||
|
self.send_stratum_notification(client, "mining.notify", [
|
||||||
|
job["job_id"],
|
||||||
|
job["prevhash"],
|
||||||
|
"", # coinb1 (empty for now - miner handles coinbase)
|
||||||
|
"", # coinb2 (empty for now - miner handles coinbase)
|
||||||
|
[], # merkle_branch (empty for now - we calculate merkle root)
|
||||||
|
f"{job['version']:08x}",
|
||||||
|
job["bits"],
|
||||||
|
job["ntime"],
|
||||||
|
True # clean_jobs
|
||||||
|
])
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to send job: {e}")
|
||||||
|
|
||||||
|
def update_job_after_block(self):
|
||||||
|
"""Update job after a block is found"""
|
||||||
|
time.sleep(2) # Brief delay to let network propagate
|
||||||
|
if self.get_block_template():
|
||||||
|
self.broadcast_new_job()
|
||||||
|
|
||||||
|
def broadcast_new_job(self):
|
||||||
|
"""Broadcast new job to all connected clients"""
|
||||||
|
if not self.current_job:
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"Broadcasting new job to {len(self.clients)} clients")
|
||||||
|
|
||||||
|
for addr, client_data in list(self.clients.items()):
|
||||||
|
try:
|
||||||
|
if 'socket' in client_data:
|
||||||
|
self.send_job_to_client(client_data['socket'], self.current_job)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to send job to {addr}: {e}")
|
||||||
|
|
||||||
def handle_client(self, client, addr):
|
def handle_client(self, client, addr):
|
||||||
"""Handle individual client connection"""
|
"""Handle individual client connection"""
|
||||||
print(f"[{addr}] Connected")
|
print(f"[{addr}] Connected")
|
||||||
self.clients[addr] = client
|
if addr not in self.clients:
|
||||||
|
self.clients[addr] = {}
|
||||||
|
self.clients[addr]['socket'] = client
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while self.running:
|
while self.running:
|
||||||
@@ -241,29 +469,15 @@ class RinCoinStratumProxy:
|
|||||||
"""Periodically update mining jobs"""
|
"""Periodically update mining jobs"""
|
||||||
while self.running:
|
while self.running:
|
||||||
try:
|
try:
|
||||||
# Update job every 30 seconds
|
time.sleep(30) # Update every 30 seconds
|
||||||
time.sleep(30)
|
|
||||||
|
old_height = self.current_job['height'] if self.current_job else 0
|
||||||
|
|
||||||
if self.get_block_template():
|
if self.get_block_template():
|
||||||
job = self.current_job
|
new_height = self.current_job['height']
|
||||||
print(f"Broadcasting new job: {job['job_id']}")
|
if new_height > old_height:
|
||||||
|
print(f"New block detected! Broadcasting new job...")
|
||||||
# Send to all connected clients
|
self.broadcast_new_job()
|
||||||
for addr, client in list(self.clients.items()):
|
|
||||||
try:
|
|
||||||
self.send_stratum_notification(client, "mining.notify", [
|
|
||||||
job["job_id"],
|
|
||||||
job["prevhash"],
|
|
||||||
job["coinb1"],
|
|
||||||
job["coinb2"],
|
|
||||||
job["merkle_branch"],
|
|
||||||
job["version"],
|
|
||||||
job["nbits"],
|
|
||||||
job["ntime"],
|
|
||||||
job["clean_jobs"]
|
|
||||||
])
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Failed to send job to {addr}: {e}")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Job updater error: {e}")
|
print(f"Job updater error: {e}")
|
||||||
@@ -274,10 +488,17 @@ class RinCoinStratumProxy:
|
|||||||
# Test RPC connection
|
# Test RPC connection
|
||||||
blockchain_info = self.rpc_call("getblockchaininfo")
|
blockchain_info = self.rpc_call("getblockchaininfo")
|
||||||
if not blockchain_info:
|
if not blockchain_info:
|
||||||
print("❌ Failed to connect to RinCoin node!")
|
print("Failed to connect to RinCoin node!")
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f"✅ Connected to RinCoin node (block {blockchain_info.get('blocks', 'unknown')})")
|
print(f"Connected to RinCoin node")
|
||||||
|
print(f"Current height: {blockchain_info.get('blocks', 'unknown')}")
|
||||||
|
print(f"Chain: {blockchain_info.get('chain', 'unknown')}")
|
||||||
|
|
||||||
|
# Get initial block template
|
||||||
|
if not self.get_block_template():
|
||||||
|
print("Failed to get initial block template!")
|
||||||
|
return
|
||||||
|
|
||||||
# Start job updater thread
|
# Start job updater thread
|
||||||
job_thread = threading.Thread(target=self.job_updater, daemon=True)
|
job_thread = threading.Thread(target=self.job_updater, daemon=True)
|
||||||
@@ -289,13 +510,13 @@ class RinCoinStratumProxy:
|
|||||||
server_socket.bind((self.stratum_host, self.stratum_port))
|
server_socket.bind((self.stratum_host, self.stratum_port))
|
||||||
server_socket.listen(10)
|
server_socket.listen(10)
|
||||||
|
|
||||||
print(f"🚀 Stratum proxy listening on {self.stratum_host}:{self.stratum_port}")
|
print(f"REAL Mining Stratum proxy ready!")
|
||||||
print("Ready for cpuminer-opt-rin connections...")
|
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("")
|
||||||
print(f"💰 Block rewards will be sent to: {self.target_address}")
|
print("Miner command:")
|
||||||
print("")
|
print(f"./cpuminer -a rinhash -o stratum+tcp://{self.stratum_host}:{self.stratum_port} -u worker1 -p x -t 4")
|
||||||
print("Connect your miner with:")
|
|
||||||
print(f"./cpuminer -a rinhash -o stratum+tcp://{self.stratum_host}:{self.stratum_port} -u user -p pass -t 28")
|
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
while self.running:
|
while self.running:
|
||||||
@@ -314,19 +535,6 @@ class RinCoinStratumProxy:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Server error: {e}")
|
print(f"Server error: {e}")
|
||||||
|
|
||||||
except OSError as e:
|
|
||||||
if "Address already in use" in str(e):
|
|
||||||
print(f"❌ Port {self.stratum_port} is already in use!")
|
|
||||||
print("")
|
|
||||||
print("🔍 Check what's using the port:")
|
|
||||||
print(f"sudo netstat -tlnp | grep :{self.stratum_port}")
|
|
||||||
print("")
|
|
||||||
print("🛑 Kill existing process:")
|
|
||||||
print(f"sudo lsof -ti:{self.stratum_port} | xargs sudo kill -9")
|
|
||||||
print("")
|
|
||||||
print("🔄 Or use a different port by editing the script")
|
|
||||||
else:
|
|
||||||
print(f"Failed to start server: {e}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to start server: {e}")
|
print(f"Failed to start server: {e}")
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user