Skip to content

Commit

Permalink
Merge pull request #92 from Rakni1988/fix-srbminer
Browse files Browse the repository at this point in the history
fix: SRB Miner
  • Loading branch information
pdxwebdev committed Dec 28, 2023
2 parents fc597be + d2810b5 commit ce2adaf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
2 changes: 0 additions & 2 deletions plugins/yadacoinpool/templates/pool-stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ <h4>TOTAL HASHES SUBMITTED: <b><span id="total-hash"></span></b></h4>
else if(data.network.current_hashes_per_second >= 1000000) {
$('#current-network-hash-rate').html((data.network.current_hashes_per_second / 1000000).toFixed(2) + ' MH/sec');
}
$('#market-last-btc').html(data.market.last_btc.toFixed(8));
$('#market-last-usdt').html(data.market.last_usdt.toFixed(8));

if(data.pool.blocks.length === 0) return $('#blocks-table').html('<tr><th>Time Found</th><th>Height</th><th>Reward</th><th>Block Hash</th></tr>');
for(var i=0; i < data.pool.blocks.length; i++) {
Expand Down
6 changes: 3 additions & 3 deletions yadacoin/core/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class Job:
@classmethod
async def from_dict(cls, job):
inst = cls()
inst.id = job["job_id"]
inst.id = job["peer_id"]
inst.job_id = job["job_id"]
inst.diff = job["difficulty"]
inst.target = job["target"]
inst.blob = job["blob"]
Expand All @@ -14,8 +15,7 @@ async def from_dict(cls, job):

def to_dict(self):
return {
"job_id": self.id,
"difficulty": self.diff,
"job_id": self.job_id,
"target": self.target,
"blob": self.blob,
"seed_hash": self.seed_hash,
Expand Down
5 changes: 3 additions & 2 deletions yadacoin/core/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Miner(MinerBase):
agent = ""
id_attribute = "address_only"

def __init__(self, address, agent=""):
def __init__(self, address, agent="", peer_id=""):
super(Miner, self).__init__()
if "." in address:
self.address = address
Expand All @@ -31,9 +31,10 @@ def __init__(self, address, agent=""):
if not self.config.address_is_valid(self.address):
raise InvalidAddressException()
self.agent = agent
self.peer_id = peer_id

def to_json(self):
return {"address": self.address_only, "worker": self.worker}
return {"address": self.address_only, "worker": self.worker, "agent": self.agent, "peer_id": self.peer_id}


class InvalidAddressException(Exception):
Expand Down
9 changes: 5 additions & 4 deletions yadacoin/core/miningpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def process_nonce_queue(self):
stream = item.stream
miner = item.miner
nonce = body["params"].get("nonce")
job = stream.jobs[body["params"]["id"]]
job = stream.jobs[body["params"]["id"] or body["params"]["job_id"]]
if type(nonce) is not str:
result = {"error": True, "message": "nonce is wrong data type"}
if len(nonce) > CHAIN.MAX_NONCE_LEN:
Expand Down Expand Up @@ -319,7 +319,7 @@ async def block_to_mine_info(self):
}
return res

async def block_template(self, agent):
async def block_template(self, agent, peer_id):
"""Returns info for current block to mine"""
if self.block_factory is None:
await self.refresh()
Expand All @@ -328,10 +328,10 @@ async def block_template(self, agent):
self.config.LatestBlock.block
)

job = await self.generate_job(agent)
job = await self.generate_job(agent, peer_id)
return job

async def generate_job(self, agent):
async def generate_job(self, agent, peer_id):
difficulty = int(self.max_target / self.block_factory.target)
seed_hash = "4181a493b397a733b083639334bc32b407915b9a82b7917ac361816f0a1f5d4d" # sha256(yadacoin65000)
job_id = str(uuid.uuid4())
Expand All @@ -351,6 +351,7 @@ async def generate_job(self, agent):

res = {
"job_id": job_id,
"peer_id": peer_id,
"difficulty": difficulty,
"target": target, # can only be 16 characters long
"blob": header.encode().hex(),
Expand Down
15 changes: 10 additions & 5 deletions yadacoin/tcpsocket/pool.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import time
import uuid
import traceback

from tornado.iostream import StreamClosedError
Expand Down Expand Up @@ -47,12 +48,14 @@ async def send_jobs(cls):

@classmethod
async def send_job(cls, stream):
job = await cls.config.mp.block_template(stream.peer.agent)
job = await cls.config.mp.block_template(stream.peer.agent, stream.peer.peer_id)
stream.jobs[job.id] = job
cls.current_header = cls.config.mp.block_factory.header
result = {"id": job.id, "job": job.to_dict()}
rpc_data = {"id": 1, "method": "job", "jsonrpc": 2.0, "result": result}
params = {"blob": job.blob, "job_id": job.job_id, "target": job.target, "seed_hash": job.seed_hash, "height": job.index}
rpc_data = {"jsonrpc": "2.0", "method": "job", "params": params}
try:
cls.config.app_log.info(f"Sent job to Miner: {stream.peer.to_json()}")
cls.config.app_log.debug(f"RPC Data: {json.dumps(rpc_data)}")
await stream.write("{}\n".format(json.dumps(rpc_data)).encode())
except StreamClosedError:
await StratumServer.remove_peer(stream)
Expand Down Expand Up @@ -173,8 +176,9 @@ async def login(self, body, stream):
)
await StratumServer.remove_peer(stream)
return
peer_id = str(uuid.uuid4())
await StratumServer.block_checker()
job = await StratumServer.config.mp.block_template(body["params"].get("agent"))
job = await StratumServer.config.mp.block_template(body["params"].get("agent"), peer_id)
if not hasattr(stream, "jobs"):
stream.jobs = {}
stream.jobs[job.id] = job
Expand All @@ -188,7 +192,7 @@ async def login(self, body, stream):

try:
stream.peer = Miner(
address=body["params"].get("login"), agent=body["params"].get("agent")
address=body["params"].get("login"), agent=body["params"].get("agent"), peer_id=peer_id
)
self.config.app_log.info(f"Connected to Miner: {stream.peer.to_json()}")
StratumServer.inbound_streams[Miner.__name__].setdefault(
Expand All @@ -200,6 +204,7 @@ async def login(self, body, stream):
await StratumServer.update_miner_count()
except:
rpc_data["error"] = {"message": "Invalid wallet address or invalid format"}
self.config.app_log.debug(f"Login RPC Data: {json.dumps(rpc_data)}")
await stream.write("{}\n".format(json.dumps(rpc_data)).encode())

async def keepalived(self, body, stream):
Expand Down

0 comments on commit ce2adaf

Please sign in to comment.