Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 8 additions & 5 deletions src/llmq/dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ void CDKGPendingMessages::PushPendingMessage(NodeId from, std::shared_ptr<CDataS
{
LOCK(cs_messages);

// Check duplicates before charging the per-node quota so a peer that
// resends the same hash cannot exhaust its budget with dupes.
if (seenMessages.count(hash) != 0) {
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- already seen %s, peer=%d\n", __func__, hash.ToString(), from);
return;
}

if (messagesPerNode[from] >= maxMessagesPerNode) {
// TODO ban?
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- too many messages, peer=%d\n", __func__, from);
return;
}
messagesPerNode[from]++;

if (!seenMessages.emplace(hash).second) {
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- already seen %s, peer=%d\n", __func__, hash.ToString(), from);
return;
}

seenMessages.emplace(hash);
pendingMessages.emplace_back(std::make_pair(from, std::move(pm)));
}

Expand Down
31 changes: 2 additions & 29 deletions src/llmq/dkgsessionhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <string_view>
#include <vector>

class CDataStream;
Expand Down Expand Up @@ -47,7 +45,7 @@ enum class QuorumPhase {
* main handler thread, we push them into a CDKGPendingMessages object and later pop+deserialize them in the DKG phase
* handler thread.
*
* Each message type has it's own instance of this class.
* Each message type has its own instance of this class.
*/
class CDKGPendingMessages
{
Expand All @@ -63,7 +61,7 @@ class CDKGPendingMessages

public:
explicit CDKGPendingMessages(size_t _maxMessagesPerNode) :
maxMessagesPerNode(_maxMessagesPerNode) {};
maxMessagesPerNode(_maxMessagesPerNode) {}

/**
* Enqueue a serialized DKG message under @p from with content hash @p hash.
Expand All @@ -77,31 +75,6 @@ class CDKGPendingMessages
std::list<BinaryMessage> PopPendingMessages(size_t maxCount) EXCLUSIVE_LOCKS_REQUIRED(!cs_messages);
bool HasSeen(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs_messages);
void Clear() EXCLUSIVE_LOCKS_REQUIRED(!cs_messages);

// Might return nullptr messages, which indicates that deserialization failed for some reason
template <typename Message>
std::vector<std::pair<NodeId, std::shared_ptr<Message>>> PopAndDeserializeMessages(size_t maxCount)
EXCLUSIVE_LOCKS_REQUIRED(!cs_messages)
{
auto binaryMessages = PopPendingMessages(maxCount);
if (binaryMessages.empty()) {
return {};
}

std::vector<std::pair<NodeId, std::shared_ptr<Message>>> ret;
ret.reserve(binaryMessages.size());
for (const auto& bm : binaryMessages) {
auto msg = std::make_shared<Message>();
try {
*bm.second >> *msg;
} catch (...) {
msg = nullptr;
}
ret.emplace_back(std::make_pair(bm.first, std::move(msg)));
}

return ret;
}
};

/**
Expand Down
Loading