mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-23 03:49:23 +00:00
StratumServer: added scoring system for clients
Ban clients only after a few bad shares without good shares compensating them.
This commit is contained in:
parent
42f7e6f486
commit
cc60ab3d63
2 changed files with 14 additions and 1 deletions
|
@ -33,6 +33,10 @@ static constexpr uint64_t AUTO_DIFF_TARGET_TIME = 30;
|
|||
// Use short target format (4 bytes) for diff <= 4 million
|
||||
static constexpr uint64_t TARGET_4_BYTES_LIMIT = std::numeric_limits<uint64_t>::max() / 4000001;
|
||||
|
||||
static constexpr int32_t BAD_SHARE_POINTS = -5;
|
||||
static constexpr int32_t GOOD_SHARE_POINTS = 1;
|
||||
static constexpr int32_t BAN_THRESHOLD_POINTS = -15;
|
||||
|
||||
#include "tcp_server.inl"
|
||||
|
||||
namespace p2pool {
|
||||
|
@ -840,9 +844,12 @@ void StratumServer::on_share_found(uv_work_t* req)
|
|||
if (pow_hash != share->m_resultHash) {
|
||||
LOGWARN(4, "client " << static_cast<char*>(client->m_addrString) << " submitted a share with invalid PoW");
|
||||
share->m_result = SubmittedShare::Result::INVALID_POW;
|
||||
client->m_score += BAD_SHARE_POINTS;
|
||||
return;
|
||||
}
|
||||
|
||||
client->m_score += GOOD_SHARE_POINTS;
|
||||
|
||||
const uint64_t n = server->m_cumulativeHashes + hashes;
|
||||
const double diff = sidechain_difficulty.to_double();
|
||||
const double effort = static_cast<double>(n - server->m_cumulativeHashesAtLastShare) * 100.0 / diff;
|
||||
|
@ -868,6 +875,7 @@ void StratumServer::on_share_found(uv_work_t* req)
|
|||
else {
|
||||
LOGWARN(4, "client " << static_cast<char*>(client->m_addrString) << " got a low diff share");
|
||||
share->m_result = SubmittedShare::Result::LOW_DIFF;
|
||||
client->m_score += BAD_SHARE_POINTS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -910,7 +918,7 @@ void StratumServer::on_after_share_found(uv_work_t* req, int /*status*/)
|
|||
return s.m_pos;
|
||||
});
|
||||
|
||||
if (bad_share) {
|
||||
if (bad_share && (client->m_score <= BAN_THRESHOLD_POINTS)) {
|
||||
client->ban(DEFAULT_BAN_TIME);
|
||||
client->close();
|
||||
}
|
||||
|
@ -934,6 +942,7 @@ StratumServer::StratumClient::StratumClient()
|
|||
, m_customDiff{}
|
||||
, m_autoDiff{}
|
||||
, m_customUser{}
|
||||
, m_score(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -953,6 +962,8 @@ void StratumServer::StratumClient::reset()
|
|||
m_customDiff = {};
|
||||
m_autoDiff = {};
|
||||
m_customUser[0] = '\0';
|
||||
|
||||
m_score = 0;
|
||||
}
|
||||
|
||||
bool StratumServer::StratumClient::on_connect()
|
||||
|
|
|
@ -78,6 +78,8 @@ public:
|
|||
difficulty_type m_customDiff;
|
||||
difficulty_type m_autoDiff;
|
||||
char m_customUser[32];
|
||||
|
||||
int32_t m_score;
|
||||
};
|
||||
|
||||
bool on_login(StratumClient* client, uint32_t id, const char* login);
|
||||
|
|
Loading…
Reference in a new issue