Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Stratum: Support for set_target and set_difficulty #2191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion libpoolprotocols/stratum/EthStratumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,19 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
// at the end of the transmission.
m_newjobprocessed = true;
}
else if (_method == "mining.set_difficulty" && m_conn->StratumMode() == ETHEREUMSTRATUM)
else if (_method == "mining.set_target")
{
string target;
jPrm = responseObject.get("params", Json::Value::null);
if (jPrm.isArray())
{
target = jPrm[0].asString();
target = dev::padLeft(target, 64, '0');
target = "0x" + target;
m_session->nextWorkBoundary = h256(target);
}
}
else if (_method == "mining.set_difficulty")
{
if (m_conn->StratumMode() == EthStratumClient::ETHEREUMSTRATUM)
{
Expand All @@ -1443,8 +1455,20 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
max(jPrm.get(Json::Value::ArrayIndex(0), 1).asDouble(), 0.0001);

m_session->nextWorkBoundary = h256(dev::getTargetFromDiff(nextWorkDifficulty));

}
}
else if (m_conn->StratumMode() == EthStratumClient::STRATUM)
{
jPrm = responseObject.get("params", Json::Value::null);
if (jPrm.isArray())
{
double nextWorkDifficulty =
max(jPrm[0].asDouble(), 0.0001);

m_session->nextWorkBoundary = h256(dev::getTargetFromDiff(nextWorkDifficulty));
}
}
else
Copy link

@Stoom Stoom Apr 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, this else never could execute before...

{
cwarn << "Invalid mining.set_difficulty rpc method. Disconnecting ...";
Expand Down