Skip to content
Merged
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
45 changes: 15 additions & 30 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,21 +468,22 @@ bool CQuorumManager::RequestQuorumData(CNode* pfrom, Consensus::LLMQType llmqTyp
}

LOCK(cs_data_requests);
CQuorumDataRequestKey key;
key.proRegTx = pfrom->GetVerifiedProRegTxHash();
key.flag = true;
key.quorumHash = pQuorumBaseBlockIndex->GetBlockHash();
key.llmqType = llmqType;
auto it = mapQuorumDataRequests.emplace(key, CQuorumDataRequest(llmqType, pQuorumBaseBlockIndex->GetBlockHash(), nDataMask, proTxHash));
if (!it.second && !it.first->second.IsExpired(/*add_bias=*/true)) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Already requested\n", __func__);
return false;
const CQuorumDataRequestKey key(pfrom->GetVerifiedProRegTxHash(), true, pQuorumBaseBlockIndex->GetBlockHash(), llmqType);
const CQuorumDataRequest request(llmqType, pQuorumBaseBlockIndex->GetBlockHash(), nDataMask, proTxHash);
auto [old_pair, exists] = mapQuorumDataRequests.emplace(key, request);
if (!exists) {
if (old_pair->second.IsExpired(/*add_bias=*/true)) {
old_pair->second = request;
} else {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Already requested\n", __func__);
return false;
}
}
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- sending QGETDATA quorumHash[%s] llmqType[%d] proRegTx[%s]\n", __func__, key.quorumHash.ToString(),
ToUnderlying(key.llmqType), key.proRegTx.ToString());

CNetMsgMaker msgMaker(pfrom->GetSendVersion());
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::QGETDATA, it.first->second));
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::QGETDATA, request));

return true;
}
Expand Down Expand Up @@ -656,11 +657,7 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C
bool request_limit_exceeded(false);
{
LOCK2(cs_main, cs_data_requests);
CQuorumDataRequestKey key;
key.proRegTx = pfrom.GetVerifiedProRegTxHash();
key.flag = false;
key.quorumHash = request.GetQuorumHash();
key.llmqType = request.GetLLMQType();
const CQuorumDataRequestKey key(pfrom.GetVerifiedProRegTxHash(), false, request.GetQuorumHash(), request.GetLLMQType());
auto it = mapQuorumDataRequests.find(key);
if (it == mapQuorumDataRequests.end()) {
it = mapQuorumDataRequests.emplace(key, request).first;
Expand Down Expand Up @@ -733,11 +730,7 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C

{
LOCK2(cs_main, cs_data_requests);
CQuorumDataRequestKey key;
key.proRegTx = pfrom.GetVerifiedProRegTxHash();
key.flag = true;
key.quorumHash = request.GetQuorumHash();
key.llmqType = request.GetLLMQType();
const CQuorumDataRequestKey key(pfrom.GetVerifiedProRegTxHash(), true, request.GetQuorumHash(), request.GetLLMQType());
auto it = mapQuorumDataRequests.find(key);
if (it == mapQuorumDataRequests.end()) {
errorHandler("Not requested");
Expand Down Expand Up @@ -913,11 +906,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
pCurrentMemberHash = &vecMemberHashes[(nMyStartOffset + nTries++) % vecMemberHashes.size()];
{
LOCK(cs_data_requests);
CQuorumDataRequestKey key;
key.proRegTx = *pCurrentMemberHash;
key.flag = true;
key.quorumHash = pQuorum->qc->quorumHash;
key.llmqType = pQuorum->qc->llmqType;
const CQuorumDataRequestKey key(*pCurrentMemberHash, true, pQuorum->qc->quorumHash, pQuorum->qc->llmqType);
auto it = mapQuorumDataRequests.find(key);
if (it != mapQuorumDataRequests.end() && !it->second.IsExpired(/*add_bias=*/true)) {
printLog("Already asked");
Expand All @@ -943,11 +932,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
printLog("Requested");
} else {
LOCK(cs_data_requests);
CQuorumDataRequestKey key;
key.proRegTx = *pCurrentMemberHash;
key.flag = true;
key.quorumHash = pQuorum->qc->quorumHash;
key.llmqType = pQuorum->qc->llmqType;
const CQuorumDataRequestKey key(*pCurrentMemberHash, true, pQuorum->qc->quorumHash, pQuorum->qc->llmqType);
auto it = mapQuorumDataRequests.find(key);
if (it == mapQuorumDataRequests.end()) {
printLog("Failed");
Expand Down
14 changes: 10 additions & 4 deletions src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ static constexpr bool DEFAULT_WATCH_QUORUMS{false};
struct CQuorumDataRequestKey
{
uint256 proRegTx;
//TODO: Investigate purpose of this flag and rename accordingly
bool flag;
bool m_we_requested;
uint256 quorumHash;
Consensus::LLMQType llmqType;

CQuorumDataRequestKey(const uint256& proRegTxIn, const bool _m_we_requested, const uint256& quorumHashIn, const Consensus::LLMQType llmqTypeIn) :
proRegTx(proRegTxIn),
m_we_requested(_m_we_requested),
quorumHash(quorumHashIn),
llmqType(llmqTypeIn)
{}

bool operator ==(const CQuorumDataRequestKey& obj) const
{
return (proRegTx == obj.proRegTx && flag == obj.flag && quorumHash == obj.quorumHash && llmqType == obj.llmqType);
return (proRegTx == obj.proRegTx && m_we_requested == obj.m_we_requested && quorumHash == obj.quorumHash && llmqType == obj.llmqType);
}
};

Expand Down Expand Up @@ -275,7 +281,7 @@ struct SaltedHasherImpl<llmq::CQuorumDataRequestKey>
{
CSipHasher c(k0, k1);
c.Write((unsigned char*)&(v.proRegTx), sizeof(v.proRegTx));
c.Write((unsigned char*)&(v.flag), sizeof(v.flag));
c.Write((unsigned char*)&(v.m_we_requested), sizeof(v.m_we_requested));
c.Write((unsigned char*)&(v.quorumHash), sizeof(v.quorumHash));
c.Write((unsigned char*)&(v.llmqType), sizeof(v.llmqType));
return c.Finalize();
Expand Down