stratum - fix miner info
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
================================================================================
|
||||
RinCoin Mining Log
|
||||
================================================================================
|
||||
Started: 2025-09-23 11:28:19
|
||||
Started: 2025-09-23 11:31:27
|
||||
Target Address: rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q
|
||||
Stratum: 0.0.0.0:3334
|
||||
RPC: 127.0.0.1:9556
|
||||
================================================================================
|
||||
|
||||
[2025-09-23 11:28:19] 💰 Wallet Balance: 25.00000000 RIN
|
||||
[2025-09-23 11:31:27] 💰 Wallet Balance: 25.00000000 RIN
|
||||
|
@@ -222,25 +222,66 @@ class RinCoinStratumProxy:
|
||||
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 calculate_merkle_branches(self, tx_hashes, tx_index):
|
||||
"""Calculate merkle branches for a specific transaction index"""
|
||||
try:
|
||||
if not tx_hashes or tx_index >= len(tx_hashes):
|
||||
return []
|
||||
|
||||
branches = []
|
||||
current_index = tx_index
|
||||
|
||||
# Start with the full list of transaction hashes
|
||||
hashes = tx_hashes[:]
|
||||
|
||||
while len(hashes) > 1:
|
||||
if len(hashes) % 2 == 1:
|
||||
hashes.append(hashes[-1]) # Duplicate last hash if odd
|
||||
|
||||
# Find the partner for current_index
|
||||
partner_index = current_index ^ 1 # Flip the least significant bit
|
||||
|
||||
if partner_index < len(hashes):
|
||||
# Add the partner hash to branches (in big-endian for stratum)
|
||||
branches.append(hashes[partner_index][::-1].hex())
|
||||
else:
|
||||
# This shouldn't happen, but add the duplicate if it does
|
||||
branches.append(hashes[current_index][::-1].hex())
|
||||
|
||||
# Move to next level
|
||||
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
|
||||
current_index //= 2
|
||||
|
||||
return branches
|
||||
|
||||
except Exception as e:
|
||||
print(f"Merkle branches calculation error: {e}")
|
||||
return []
|
||||
|
||||
def bits_to_target(self, bits_hex):
|
||||
"""Convert bits to target - FIXED VERSION"""
|
||||
try:
|
||||
@@ -574,12 +615,33 @@ class RinCoinStratumProxy:
|
||||
def send_job_to_client(self, client, job):
|
||||
"""Send mining job to specific client"""
|
||||
try:
|
||||
# Build coinbase components for stratum
|
||||
height = job.get('height', 0)
|
||||
height_bytes = struct.pack('<I', height)
|
||||
height_compact = bytes([len(height_bytes.rstrip(b'\x00'))]) + height_bytes.rstrip(b'\x00')
|
||||
|
||||
# coinb1: prefix up to extranonce1 position
|
||||
coinb1 = height_compact + b'/RinCoin/'
|
||||
|
||||
# coinb2: empty (extranonce2 goes at the end)
|
||||
coinb2 = b''
|
||||
|
||||
# Calculate merkle branches for transactions
|
||||
# Start with coinbase txid placeholder and all transaction hashes
|
||||
coinbase_txid_placeholder = b'\x00' * 32 # Placeholder, miner will calculate
|
||||
tx_hashes = [coinbase_txid_placeholder]
|
||||
for tx in job.get('transactions', []):
|
||||
tx_hashes.append(bytes.fromhex(tx['hash'])[::-1]) # Little-endian
|
||||
|
||||
# Build merkle tree and get branches
|
||||
merkle_branches = self.calculate_merkle_branches(tx_hashes, 0) # For coinbase at index 0
|
||||
|
||||
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)
|
||||
coinb1.hex(),
|
||||
coinb2.hex(),
|
||||
merkle_branches,
|
||||
f"{job['version']:08x}",
|
||||
job["bits"],
|
||||
job["ntime"],
|
||||
|
Reference in New Issue
Block a user