-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: limit signing share sessions per peer #7351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 3 commits
e5e8d1e
135f8ce
6595948
f6aa12a
03dddee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,21 @@ | |
|
|
||
| #include <cxxtimer.hpp> | ||
|
|
||
| #include <algorithm> | ||
| #include <ranges> | ||
|
|
||
| namespace llmq | ||
| { | ||
| namespace { | ||
| constexpr size_t MAX_SESSIONS_PER_PEER_FACTOR{4}; | ||
| constexpr size_t MIN_SESSIONS_PER_PEER{100}; | ||
|
|
||
| size_t GetMaxSessionsForPeer(const Consensus::LLMQParams& params) | ||
| { | ||
| return std::max<size_t>(size_t(params.size) * MAX_SESSIONS_PER_PEER_FACTOR, MIN_SESSIONS_PER_PEER); | ||
| } | ||
| } // namespace | ||
|
|
||
| void CSigShare::UpdateKey() | ||
| { | ||
| key.first = this->buildSignHash().Get(); | ||
|
|
@@ -133,6 +144,21 @@ CSigSharesNodeState::Session& CSigSharesNodeState::GetOrCreateSessionFromAnn(con | |
| return s; | ||
| } | ||
|
|
||
| bool CSigSharesNodeState::CanCreateSessionFromAnn(const llmq::CSigSesAnn& ann, size_t maxSessions) const | ||
| { | ||
| return sessions.count(ann.buildSignHash().Get()) != 0 || GetSessionCount(ann.getLlmqType()) < maxSessions; | ||
| } | ||
|
|
||
| size_t CSigSharesNodeState::GetSessionCount() const | ||
| { | ||
| return sessions.size(); | ||
| } | ||
|
|
||
| size_t CSigSharesNodeState::GetSessionCount(Consensus::LLMQType llmqType) const | ||
| { | ||
| return std::ranges::count_if(sessions, [&](const auto& kv) { return kv.second.llmqType == llmqType; }); | ||
| } | ||
|
|
||
| CSigSharesNodeState::Session* CSigSharesNodeState::GetSessionBySignHash(const uint256& signHash) | ||
| { | ||
| auto it = sessions.find(signHash); | ||
|
|
@@ -206,7 +232,8 @@ void CSigSharesManager::UnregisterRecoveryInterface() | |
| bool CSigSharesManager::ProcessMessageSigSesAnn(const CNode& pfrom, const CSigSesAnn& ann) | ||
| { | ||
| auto llmqType = ann.getLlmqType(); | ||
| if (!Params().GetLLMQ(llmqType).has_value()) { | ||
| const auto& llmq_params_opt = Params().GetLLMQ(llmqType); | ||
| if (!llmq_params_opt.has_value()) { | ||
| return false; | ||
| } | ||
| if (ann.getSessionId() == UNINITIALIZED_SESSION_ID || ann.getQuorumHash().IsNull() || ann.getId().IsNull() || ann.getMsgHash().IsNull()) { | ||
|
|
@@ -225,7 +252,14 @@ bool CSigSharesManager::ProcessMessageSigSesAnn(const CNode& pfrom, const CSigSe | |
|
|
||
| LOCK(cs); | ||
| auto& nodeState = nodeStates[pfrom.GetId()]; | ||
| const size_t maxSessions = GetMaxSessionsForPeer(*llmq_params_opt); | ||
| if (!nodeState.CanCreateSessionFromAnn(ann, maxSessions)) { | ||
| LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many sessions. cnt=%d, max=%d, llmqType=%d, node=%d\n", | ||
| __func__, nodeState.GetSessionCount(llmqType), maxSessions, static_cast<int>(llmqType), pfrom.GetId()); | ||
| return false; | ||
| } | ||
| auto& session = nodeState.GetOrCreateSessionFromAnn(ann); | ||
| timeSeenForSessions.insert_or_assign(ann.buildSignHash().Get(), GetTime<std::chrono::seconds>().count()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a peer periodically re-announces an already-known Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in f6aa12a: |
||
| nodeState.sessionByRecvId.erase(session.recvSessionId); | ||
| nodeState.sessionByRecvId.erase(ann.getSessionId()); | ||
| session.recvSessionId = ann.getSessionId(); | ||
|
|
@@ -1247,6 +1281,11 @@ void CSigSharesManager::Cleanup() | |
| doneSessions.emplace(sigShare.GetSignHash()); | ||
| } | ||
| }); | ||
| for (const auto& [signHash, _] : timeSeenForSessions) { | ||
| if (doneSessions.count(signHash) == 0 && sigman.HasRecoveredSigForSession(signHash)) { | ||
| doneSessions.emplace(signHash); | ||
| } | ||
| } | ||
| for (const auto& signHash : doneSessions) { | ||
| RemoveSigSharesForSession(signHash); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this node already has
maxSessionssessions for a peer that were created locally for outgoing traffic (for exampleCollectSigSharesToAnnouncecallsGetOrCreateSessionFromSharefor that peer beforeSendMessagesassigns a send session), this count rejects the peer's first unrelatedQSIGSESANNeven though the new limit is meant to constrain sessions created from announcements.NetSigning::ProcessMessagetreats thisfalsereturn as a ban, so under a busy signing backlog an honest peer can be banned because our own send-side sessions filled the per-peer count; the cap should exclude send-only sessions or track announcement-created sessions separately.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 03dddee: the session cap now counts only sessions that were actually introduced by
QSIGSESANNannouncements. Send-only sessions created locally via sig shares no longer consume the announcement-session budget, while existing-session announcements are still accepted and then marked as announcement-backed.Validation:
git diff --checkmake -C src -j8 test/test_dashsrc/test/test_dash --run_test=llmq_utils_tests --catch_system_errors=no