reward distributions

This commit is contained in:
Dobromir Popov
2025-09-02 12:16:56 +03:00
parent 3dd0e55fde
commit b3ec402a2e
3 changed files with 158 additions and 4 deletions

View File

@@ -15,6 +15,9 @@ import sqlite3
from datetime import datetime
from requests.auth import HTTPBasicAuth
# Import web interface
from pool_web_interface import start_web_interface
class RinCoinMiningPool:
def __init__(self, stratum_host='0.0.0.0', stratum_port=3333,
rpc_host='127.0.0.1', rpc_port=9556,
@@ -226,15 +229,47 @@ class RinCoinMiningPool:
# Calculate total difficulty
total_difficulty = sum(row[2] for row in miners)
# Separate miners with and without addresses
miners_with_addresses = []
miners_without_addresses = []
total_difficulty_with_addresses = 0
total_difficulty_without_addresses = 0
for address, share_count, difficulty in miners:
if address:
miners_with_addresses.append((address, share_count, difficulty))
total_difficulty_with_addresses += difficulty
else:
miners_without_addresses.append((address, share_count, difficulty))
total_difficulty_without_addresses += difficulty
# Calculate total difficulty
total_difficulty = total_difficulty_with_addresses + total_difficulty_without_addresses
if total_difficulty == 0:
print("No valid difficulty found")
return
# Distribute rewards
miner_rewards = {}
for address, share_count, difficulty in miners:
if address and total_difficulty > 0:
# First, distribute to miners with valid addresses
if miners_with_addresses:
for address, share_count, difficulty in miners_with_addresses:
reward_share = (difficulty / total_difficulty) * miner_reward
miner_rewards[address] = reward_share
print(f"💰 Miner {address}: {reward_share:.8f} RIN ({difficulty} difficulty)")
# Calculate undistributed rewards (from miners without addresses)
if miners_without_addresses:
undistributed_reward = 0
for address, share_count, difficulty in miners_without_addresses:
undistributed_reward += (difficulty / total_difficulty) * miner_reward
print(f"⚠️ Miner without address: {difficulty} difficulty -> {undistributed_reward:.8f} RIN to pool")
# Keep undistributed rewards for pool (no redistribution)
print(f"💰 Pool keeps {undistributed_reward:.8f} RIN from miners without addresses")
# Record block
cursor.execute('''
INSERT INTO blocks (block_hash, height, reward, pool_fee, miner_rewards)
@@ -247,6 +282,10 @@ class RinCoinMiningPool:
print(f"🎉 Block {block_height} reward distributed!")
print(f"💰 Pool fee: {pool_fee:.8f} RIN")
print(f"💰 Total distributed: {sum(miner_rewards.values()):.8f} RIN")
# Summary
if miners_without_addresses:
print(f"📊 Summary: {len(miners_with_addresses)} miners with addresses, {len(miners_without_addresses)} without (rewards to pool)")
def send_stratum_response(self, client, msg_id, result, error=None):
"""Send Stratum response to client"""
@@ -373,7 +412,7 @@ class RinCoinMiningPool:
if miner_address:
print(f"[{addr}] ✅ Authorized: {user}.{worker} -> {miner_address}")
else:
print(f"[{addr}] ⚠️ Authorized: {user}.{worker} (no address specified)")
print(f"[{addr}] ⚠️ Authorized: {user}.{worker} (rewards will go to pool address)")
self.send_stratum_response(client, msg_id, True)
else:
self.send_stratum_response(client, msg_id, False, "Invalid authorization")