Skip to content

Commit c25d9ae

Browse files
authored
fix: A set of qdata/qwatch related fixes (dashpay#5745)
## Issue being fixed or feature implemented Fix/tidy up a few `qdata`/`qwatch` related parts, improve performance for regular non-watching nodes ~based on dashpay#5744 atm~ ## What was done? pls see individual commits ## How Has This Been Tested? run tests ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
1 parent 3c7c283 commit c25d9ae

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

src/llmq/dkgsessionmgr.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,21 @@ void CDKGSessionManager::ProcessMessage(CNode& pfrom, const CQuorumManager& quor
189189
}
190190

191191
if (msg_type == NetMsgType::QWATCH) {
192+
if (!fMasternodeMode) {
193+
// non-masternodes should never receive this
194+
m_peerman->Misbehaving(pfrom.GetId(), 10);
195+
return;
196+
}
192197
pfrom.qwatch = true;
193198
return;
194199
}
195200

201+
if ((!fMasternodeMode && !utils::IsWatchQuorumsEnabled())) {
202+
// regular non-watching nodes should never receive any of these
203+
m_peerman->Misbehaving(pfrom.GetId(), 10);
204+
return;
205+
}
206+
196207
if (vRecv.empty()) {
197208
m_peerman->Misbehaving(pfrom.GetId(), 100);
198209
return;
@@ -429,13 +440,15 @@ bool CDKGSessionManager::GetEncryptedContributions(Consensus::LLMQType llmqType,
429440
}
430441
}
431442
if (nRequestedMemberIdx == std::numeric_limits<size_t>::max()) {
443+
LogPrint(BCLog::LLMQ, "CDKGSessionManager::%s -- not a member, nProTxHash=%s\n", __func__, nProTxHash.ToString());
432444
return false;
433445
}
434446

435447
for (const auto i : irange::range(members.size())) {
436448
if (validMembers[i]) {
437449
CBLSIESMultiRecipientObjects<CBLSSecretKey> encryptedContributions;
438450
if (!db->Read(std::make_tuple(DB_ENC_CONTRIB, llmqType, pQuorumBaseBlockIndex->GetBlockHash(), members[i]->proTxHash), encryptedContributions)) {
451+
LogPrint(BCLog::LLMQ, "CDKGSessionManager::%s -- can't read from db, nProTxHash=%s\n", __func__, nProTxHash.ToString());
439452
return false;
440453
}
441454
vecRet.emplace_back(encryptedContributions.Get(nRequestedMemberIdx));

src/llmq/quorums.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void CQuorumManager::Stop()
221221

222222
void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex) const
223223
{
224-
if (!fMasternodeMode || !utils::QuorumDataRecoveryEnabled() || pIndex == nullptr) {
224+
if ((!fMasternodeMode && !utils::IsWatchQuorumsEnabled()) || !utils::QuorumDataRecoveryEnabled() || pIndex == nullptr) {
225225
return;
226226
}
227227

@@ -272,15 +272,13 @@ void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex)
272272

273273
void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitialDownload) const
274274
{
275-
if (!m_mn_sync->IsBlockchainSynced()) {
276-
return;
277-
}
275+
if (!m_mn_sync->IsBlockchainSynced()) return;
278276

279277
for (const auto& params : Params().GetConsensus().llmqs) {
280278
CheckQuorumConnections(params, pindexNew);
281279
}
282280

283-
{
281+
if (fMasternodeMode || utils::IsWatchQuorumsEnabled()) {
284282
// Cleanup expired data requests
285283
LOCK(cs_data_requests);
286284
auto it = mapQuorumDataRequests.begin();
@@ -299,6 +297,8 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial
299297

300298
void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const
301299
{
300+
if (!fMasternodeMode && !utils::IsWatchQuorumsEnabled()) return;
301+
302302
auto lastQuorums = ScanQuorums(llmqParams.type, pindexNew, (size_t)llmqParams.keepOldConnections);
303303

304304
auto connmanQuorumsToDelete = connman.GetMasternodeQuorums(llmqParams.type);
@@ -450,8 +450,8 @@ bool CQuorumManager::RequestQuorumData(CNode* pfrom, Consensus::LLMQType llmqTyp
450450
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Version must be %d or greater.\n", __func__, LLMQ_DATA_MESSAGES_VERSION);
451451
return false;
452452
}
453-
if (pfrom->GetVerifiedProRegTxHash().IsNull() && !pfrom->qwatch) {
454-
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- pfrom is neither a verified masternode nor a qwatch connection\n", __func__);
453+
if (pfrom->GetVerifiedProRegTxHash().IsNull()) {
454+
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- pfrom is not a verified masternode\n", __func__);
455455
return false;
456456
}
457457
if (!GetLLMQParams(llmqType).has_value()) {
@@ -470,8 +470,8 @@ bool CQuorumManager::RequestQuorumData(CNode* pfrom, Consensus::LLMQType llmqTyp
470470
LOCK(cs_data_requests);
471471
const CQuorumDataRequestKey key(pfrom->GetVerifiedProRegTxHash(), true, pQuorumBaseBlockIndex->GetBlockHash(), llmqType);
472472
const CQuorumDataRequest request(llmqType, pQuorumBaseBlockIndex->GetBlockHash(), nDataMask, proTxHash);
473-
auto [old_pair, exists] = mapQuorumDataRequests.emplace(key, request);
474-
if (!exists) {
473+
auto [old_pair, inserted] = mapQuorumDataRequests.emplace(key, request);
474+
if (!inserted) {
475475
if (old_pair->second.IsExpired(/*add_bias=*/true)) {
476476
old_pair->second = request;
477477
} else {
@@ -752,8 +752,8 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C
752752
}
753753

754754
if (msg_type == NetMsgType::QDATA) {
755-
if ((!fMasternodeMode && !utils::IsWatchQuorumsEnabled()) || (pfrom.GetVerifiedProRegTxHash().IsNull() && !pfrom.qwatch)) {
756-
errorHandler("Not a verified masternode or a qwatch connection");
755+
if ((!fMasternodeMode && !utils::IsWatchQuorumsEnabled()) || pfrom.GetVerifiedProRegTxHash().IsNull()) {
756+
errorHandler("Not a verified masternode and -watchquorums is not enabled");
757757
return;
758758
}
759759

@@ -1051,7 +1051,7 @@ void CQuorumManager::StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex)
10511051
// window and it's better to have more room so we pick next cycle.
10521052
// dkgMiningWindowStart for small quorums is 10 i.e. a safe block to start
10531053
// these calculations is at height 576 + 24 * 2 + 10 = 576 + 58.
1054-
if (!fMasternodeMode || pIndex == nullptr || (pIndex->nHeight % 576 != 58)) {
1054+
if ((!fMasternodeMode && !utils::IsWatchQuorumsEnabled()) || pIndex == nullptr || (pIndex->nHeight % 576 != 58)) {
10551055
return;
10561056
}
10571057

test/functional/p2p_quorum_data.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def test_basics():
154154
"and does bump our score")
155155
p2p_node0.test_qgetdata(qgetdata_all, response_expected=False)
156156
wait_for_banscore(node0, id_p2p_node0, 10)
157+
self.log.info("Check that normal node bumps our score for qwatch")
158+
p2p_node0.send_message(msg_qwatch())
159+
wait_for_banscore(node0, id_p2p_node0, 20)
157160
# The masternode should not respond to qgetdata for non-masternode connections
158161
self.log.info("Check that masternode doesn't respond to "
159162
"non-masternode connection and does bump our score")
@@ -383,6 +386,10 @@ def test_watchquorums():
383386
p2p_node0.wait_for_qmessage("qgetdata")
384387
p2p_node0.send_message(p2p_mn2.get_qdata())
385388
wait_for_banscore(node0, id_p2p_node0, (1 - len(extra_args)) * 10)
389+
# Non-masternodes should bump peer's score for qwatch no matter
390+
# whether they (non-masternodes) are watching or not.
391+
p2p_node0.send_message(msg_qwatch())
392+
wait_for_banscore(node0, id_p2p_node0, (1 - len(extra_args)) * 10 + 10)
386393
node0.disconnect_p2ps()
387394
mn2.node.disconnect_p2ps()
388395

0 commit comments

Comments
 (0)