Skip to content

Commit

Permalink
Merge pull request ethereum-mining#1714 from ethereum-mining/fixStrat…
Browse files Browse the repository at this point in the history
…umBlockEpoch

Initialize blocknumber when new job arrives.
  • Loading branch information
chfast committed Nov 28, 2018
2 parents 759fa65 + 70b671e commit 4df6898
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libpoolprotocols/stratum/EthStratumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void EthStratumClient::init_socket()
m_socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout));
#else
timeval tv{
static_cast<suseconds_t>(keepAlive / 1000),
static_cast<suseconds_t>(keepAlive / 1000),
static_cast<suseconds_t>(keepAlive % 1000)};
setsockopt(m_socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(m_socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
Expand Down Expand Up @@ -1226,6 +1226,7 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
m_current.startNonce = m_extraNonce;
m_current.exSizeBytes = m_extraNonceSizeBytes;
m_current_timestamp = std::chrono::steady_clock::now();
m_current.block = -1;

// This will signal to dispatch the job
// at the end of the transmission.
Expand All @@ -1241,6 +1242,7 @@ void EthStratumClient::processResponse(Json::Value& responseObject)

// Only some eth-proxy compatible implementations carry the block number
// namely ethermine.org
m_current.block = -1;
if (m_conn->StratumMode() ==
EthStratumClient::ETHPROXY && jPrm.size() > prmIdx)
{
Expand All @@ -1249,10 +1251,17 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
m_current.block = std::stoul(
jPrm.get(Json::Value::ArrayIndex(prmIdx), "").asString(), nullptr,
16);
/* check if the block number is in a valid range
A year has ~31536000 seconds
50 years have ~1576800000
assuming a (very fast) blocktime of 10s:
==> in 50 years we get 157680000 (=0x9660180) blocks
*/
if (m_current.block > 0x9660180)
m_current.block = -1;
}
catch (const std::exception&)
{
m_current.block = -1;
}
}

Expand Down

0 comments on commit 4df6898

Please sign in to comment.