Skip to content

Commit

Permalink
Better strict control on blocknumber (if passed)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaLanfranchi committed Nov 28, 2018
1 parent 67dcbfb commit 5b6af91
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions libpoolprotocols/stratum/EthStratumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,25 +1243,29 @@ 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)
if (m_conn->StratumMode() == EthStratumClient::ETHPROXY &&
jPrm.size() > prmIdx &&
jPrm.get(Json::Value::ArrayIndex(prmIdx), "").asString().substr(0, 2) ==
"0x")
{
try
{
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
/*
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;
throw new std::exception();
}
catch (const std::exception&)
{
m_current.block = -1;
}
}

Expand Down

0 comments on commit 5b6af91

Please sign in to comment.