Skip to content

Commit

Permalink
slparser/statshttpd: Mark the detected duplicate share as rejected in…
Browse files Browse the repository at this point in the history
…stead of discarding it directly
  • Loading branch information
SwimmingTiger committed Jan 16, 2019
1 parent 256680e commit 9b4ec85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/ShareLogParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ShareLogParserT : public ShareLogParser {
}

void parseShareLog(const uint8_t *buf, size_t len);
void parseShare(const SHARE *share);
void parseShare(SHARE &share);

void generateDailyData(shared_ptr<ShareStatsDay<SHARE>> stats,
const int32_t userId, const int64_t workerId,
Expand Down
26 changes: 13 additions & 13 deletions src/ShareLogParser.inl
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,22 @@ void ShareLogParserT<SHARE>::parseShareLog(const uint8_t *buf, size_t len) {
LOG(INFO) << "parse share from base message failed! " ;
return;
}
parseShare(&share);
parseShare(share);
}

template <class SHARE>
void ShareLogParserT<SHARE>::parseShare(const SHARE *share) {
if (!share->isValid()) {
LOG(ERROR) << "invalid share: " << share->toString();
void ShareLogParserT<SHARE>::parseShare(SHARE &share) {
if (!share.isValid()) {
LOG(ERROR) << "invalid share: " << share.toString();
return;
}
if (dupShareChecker_ && !dupShareChecker_->addShare(*share)) {
LOG(INFO) << "duplicate share attack: " << share->toString();
return;
if (dupShareChecker_ && !dupShareChecker_->addShare(share)) {
LOG(INFO) << "duplicate share attack: " << share.toString();
share.set_status(StratumStatus::DUPLICATE_SHARE);
}

WorkerKey wkey(share->userid(), share->workerhashid());
WorkerKey ukey(share->userid(), 0);
WorkerKey wkey(share.userid(), share.workerhashid());
WorkerKey ukey(share.userid(), 0);
WorkerKey pkey(0, 0);

pthread_rwlock_wrlock(&rwlock_);
Expand All @@ -189,10 +189,10 @@ void ShareLogParserT<SHARE>::parseShare(const SHARE *share) {
}
pthread_rwlock_unlock(&rwlock_);

const uint32_t hourIdx = getHourIdx(share->timestamp());
workersStats_[wkey]->processShare(hourIdx, *share);
workersStats_[ukey]->processShare(hourIdx, *share);
workersStats_[pkey]->processShare(hourIdx, *share);
const uint32_t hourIdx = getHourIdx(share.timestamp());
workersStats_[wkey]->processShare(hourIdx, share);
workersStats_[ukey]->processShare(hourIdx, share);
workersStats_[pkey]->processShare(hourIdx, share);
}

template <class SHARE>
Expand Down
4 changes: 1 addition & 3 deletions src/StatsHttpd.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1004,15 +1004,13 @@ void StatsServerT<SHARE>::consumeShareLog(rd_kafka_message_t *rkmessage) {
return;
}



if (!share.isValid()) {
LOG(ERROR) << "invalid share: " << share.toString();
return;
}
if (dupShareChecker_ && !dupShareChecker_->addShare(share)) {
LOG(INFO) << "duplicate share attack: " << share.toString();
return;
share.set_status(StratumStatus::DUPLICATE_SHARE);
}

processShare(share);
Expand Down

0 comments on commit 9b4ec85

Please sign in to comment.