Skip to content

Commit

Permalink
Merge pull request #99 from Rakni1988/fix-srbminer
Browse files Browse the repository at this point in the history
mining pool improvement, part I
  • Loading branch information
pdxwebdev committed Feb 13, 2024
2 parents d735717 + 90e8cb1 commit 27988df
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 21 deletions.
1 change: 1 addition & 0 deletions plugins/yadacoinpool/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ async def get(self):
},
"pool": {
"hashes_per_second": pool_hash_rate,
"pool_address": self.config.address,
"miner_count": miner_count_pool_stat["value"],
"worker_count": worker_count_pool_stat["value"],
"payout_scheme": "PPLNS",
Expand Down
34 changes: 30 additions & 4 deletions plugins/yadacoinpool/templates/pool-stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ <h5 id="network-last-block"></h5>
</div>
<div class="column">
<div class="box">
<h5><b>BLOCK REAWORD</b></h5>
<div><span id="network-reward"></span> YDA</div>
<h5><b>BLOCK REWARD</b></h5>
<h4>
<div>MINERS: <b><span id="miners-reward"></span></b></div>
<div>MASTER NODES: <b><span id="master-nodes-reward"></span></b></div>
</h4>
</div>
</div>
<div class="column">
Expand Down Expand Up @@ -162,7 +165,12 @@ <h4>TOTAL HASHES SUBMITTED: <b><span id="total-hash"></span></b></h4>
}
$('#network-difficulty').html(data.network.difficulty.toFixed(3));
$('#network-height').html(data.network.height);
$('#network-reward').html(data.network.reward);
var blockReward = parseFloat(data.network.reward);
var MinersReward = (90 / 100) * blockReward;
var NodesReward = (10 / 100) * blockReward;
$('#miners-reward').html(MinersReward.toFixed(2) + ' YDA');
$('#master-nodes-reward').html(NodesReward.toFixed(2) + ' YDA');
var poolAddress = data.pool.pool_address;
var newDate = new Date();
newDate.setTime(data.network.last_block*1000);
dateString = newDate.toLocaleString();
Expand Down Expand Up @@ -191,8 +199,26 @@ <h4>TOTAL HASHES SUBMITTED: <b><span id="total-hash"></span></b></h4>
var newDate = new Date();
newDate.setTime(data.pool.blocks[i].time*1000);
dateString = newDate.toLocaleString();
$('#blocks-table').append('<tr><td>' + dateString + '</td><td>' + data.pool.blocks[i].index + '</a></td><td>N/a</td><td><a target="_blank" href="https://yadacoin.io/explorer?term=' + data.pool.blocks[i].hash + '">' + data.pool.blocks[i].hash + '</td></tr>');
var reward = getRewardFromTransactions(data.pool.blocks[i].transactions, poolAddress);
$('#blocks-table').append('<tr><td>' + dateString + '</td><td>' + data.pool.blocks[i].index + '</a></td><<td>' + reward + '</td><td><a target="_blank" href="https://yadacoin.io/explorer?term=' + data.pool.blocks[i].hash + '">' + data.pool.blocks[i].hash + '</td></tr>');
}

function getRewardFromTransactions(transactions, poolAddress) {
var highestReward = 0.0;

for (var i = 0; i < transactions.length; i++) {
for (var j = 0; j < transactions[i].outputs.length; j++) {
if (transactions[i].outputs[j].to === poolAddress) {
var currentReward = transactions[i].outputs[j].value;
if (currentReward > highestReward) {
highestReward = currentReward;
}
}
}
}
return highestReward + ' YDA';
}

var pagelength = 5;
var pageIndex = 1;
var selector = "tr:gt(" + pagelength + ")";
Expand Down
1 change: 1 addition & 0 deletions yadacoin/core/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async def from_dict(cls, job):
inst.seed_hash = job["seed_hash"]
inst.index = job["height"]
inst.extra_nonce = job["extra_nonce"]
inst.miner_diff = job["miner_diff"]
inst.algo = job["algo"]
return inst

Expand Down
33 changes: 19 additions & 14 deletions yadacoin/core/miningpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ async def process_nonce_queue(self):
item = self.config.processing_queues.nonce_queue.pop()

async def process_nonce(self, miner, nonce, job):
nonce = nonce + job.extra_nonce.encode().hex()
header = (
binascii.unhexlify(job.blob)
.decode()
.replace("{00}", "{nonce}")
.replace(job.extra_nonce, "")
)
nonce = nonce + job.extra_nonce
header = self.block_factory.header
self.config.app_log.debug(f"Extra Nonce for job {job.index}: {job.extra_nonce}")
self.config.app_log.debug(f"Nonce for job {job.index}: {nonce}")

hash1 = self.block_factory.generate_hash_from_header(job.index, header, nonce)
self.config.app_log.info(f"Hash1 for job {job.index}: {hash1}")

if self.block_factory.index >= CHAIN.BLOCK_V5_FORK:
hash1_test = Blockchain.little_hash(hash1)
else:
Expand Down Expand Up @@ -164,6 +164,7 @@ async def process_nonce(self, miner, nonce, job):
"index": block_candidate.index,
"hash": block_candidate.hash,
"nonce": nonce,
"weight": job.miner_diff,
"time": int(time()),
}
},
Expand Down Expand Up @@ -333,32 +334,36 @@ async def block_template(self, agent, peer_id):

async def generate_job(self, agent, peer_id):
difficulty = int(self.max_target / self.block_factory.target)
custom_diff = None
miner_diff = max(int(custom_diff), 50000) if custom_diff is not None else self.config.pool_diff
seed_hash = "4181a493b397a733b083639334bc32b407915b9a82b7917ac361816f0a1f5d4d" # sha256(yadacoin65000)
job_id = str(uuid.uuid4())
extra_nonce = hex(random.randrange(1000000, 1000000000000000))[2:]
header = self.block_factory.header.replace("{nonce}", "{00}" + extra_nonce)
extra_nonce = str(random.randrange(100001, 999999))
header = self.block_factory.header
blob = header.encode().hex().replace("7b6e6f6e63657d", "00000000" + extra_nonce)

if "XMRigCC/3" in agent or "XMRig/3" in agent:
target = hex(0x10000000000000001 // self.config.pool_diff)
elif self.config.pool_diff <= 69905:
target = hex(0x10000000000000001 // miner_diff)
elif miner_diff <= 69905:
target = hex(
0x10000000000000001 // self.config.pool_diff - 0x0000F00000000000
0x10000000000000001 // miner_diff - 0x0000F00000000000
)[2:].zfill(48)
else:
target = "-" + hex(
0x10000000000000001 // self.config.pool_diff - 0x0000F00000000000
0x10000000000000001 // miner_diff - 0x0000F00000000000
)[3:].zfill(48)

res = {
"job_id": job_id,
"peer_id": peer_id,
"difficulty": difficulty,
"target": target, # can only be 16 characters long
"blob": header.encode().hex(),
"blob": blob,
"seed_hash": seed_hash,
"height": self.config.LatestBlock.block.index
+ 1, # This is the height of the one we are mining
"extra_nonce": extra_nonce,
"miner_diff": miner_diff,
"algo": "rx/yada",
}
return await Job.from_dict(res)
Expand Down
4 changes: 2 additions & 2 deletions yadacoin/core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ def __init__(self):
SeedGateway.from_dict(
{
"host": "yada-bravo.mynodes.live",
"port": 8080,
"port": 8000,
"identity": {
"username": "",
"username_signature": "MEQCIFvpbWRQU9Ty4JXxoGH4YXgR8RiLoLBm11RNKBVeaz4GAiAyGMbhXc+J+z5VIh2GGJi9uDsqdPpEweerViSrxpxzPQ==",
Expand Down Expand Up @@ -2539,7 +2539,7 @@ def __init__(self):
ServiceProvider.from_dict(
{
"host": "yada-charlie.mynodes.live",
"port": 8080,
"port": 8000,
"identity": {
"username": "",
"username_signature": "MEQCIG5VITo79hYorFepmBB6zRqSl/PSbRPpz5gTaSteJQlaAiAmuQnTZFCuccjTtufWJ8CI+w/ddka/AoNQgat3H+18Jw==",
Expand Down
2 changes: 1 addition & 1 deletion yadacoin/tcpsocket/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def send_job(cls, stream):
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
params = {"blob": job.blob, "job_id": job.job_id, "target": job.target, "seed_hash": job.seed_hash, "height": job.index}
params = {"blob": job.blob, "job_id": job.job_id, "target": job.target, "seed_hash": job.seed_hash, "height": job.index, "extra_nonce": job.extra_nonce}
rpc_data = {"jsonrpc": "2.0", "method": "job", "params": params}
try:
cls.config.app_log.info(f"Sent job to Miner: {stream.peer.to_json()}")
Expand Down

0 comments on commit 27988df

Please sign in to comment.