Skip to content

Commit

Permalink
Merge pull request #4940 from PastaPastaPasta/backport-rc10
Browse files Browse the repository at this point in the history
[v18.x] rc10 backports
  • Loading branch information
UdjinM6 authored Jul 26, 2022
2 parents 1fa81c6 + d238549 commit b504b97
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 33 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ([2.69])
define(_CLIENT_VERSION_MAJOR, 18)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_RC, 10)
define(_CLIENT_VERSION_RC, 11)
define(_CLIENT_VERSION_IS_RELEASE, false)
define(_COPYRIGHT_YEAR, 2022)
define(_COPYRIGHT_HOLDERS,[The %s developers])
Expand Down
44 changes: 26 additions & 18 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ static const std::string DB_QUORUM_QUORUM_VVEC = "q_Qqvvec";
CQuorumManager* quorumManager;

CCriticalSection cs_data_requests;
//key = <ProTx, bool, quorumHash, llmqType>
//TODO: Document purpose of bool
using key_t = std::tuple<uint256, bool, uint256, uint8_t>;
static std::unordered_map<key_t, CQuorumDataRequest, StaticSaltedHasher> mapQuorumDataRequests GUARDED_BY(cs_data_requests);
static std::unordered_map<CQuorumDataRequestKey, CQuorumDataRequest, StaticSaltedHasher> mapQuorumDataRequests GUARDED_BY(cs_data_requests);

static uint256 MakeQuorumKey(const CQuorum& q)
{
Expand Down Expand Up @@ -436,8 +433,11 @@ bool CQuorumManager::RequestQuorumData(CNode* pFrom, Consensus::LLMQType llmqTyp
}

LOCK(cs_data_requests);
auto quorumHash = pQuorumBaseBlockIndex->GetBlockHash();
auto key = std::make_tuple(pFrom->GetVerifiedProRegTxHash(), true, quorumHash, (uint8_t)llmqType);
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()) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Already requested\n", __func__);
Expand Down Expand Up @@ -588,9 +588,11 @@ void CQuorumManager::ProcessMessage(CNode* pFrom, const std::string& msg_type, C

{
LOCK2(cs_main, cs_data_requests);
auto quorumHash = request.GetQuorumHash();
auto llmqType = (uint8_t) request.GetLLMQType();
auto key = std::make_tuple(pFrom->GetVerifiedProRegTxHash(), false, quorumHash, llmqType);
CQuorumDataRequestKey key;
key.proRegTx = pFrom->GetVerifiedProRegTxHash();
key.flag = false;
key.quorumHash = request.GetQuorumHash();
key.llmqType = request.GetLLMQType();
auto it = mapQuorumDataRequests.find(key);
if (it == mapQuorumDataRequests.end()) {
it = mapQuorumDataRequests.emplace(key, request).first;
Expand Down Expand Up @@ -663,9 +665,11 @@ void CQuorumManager::ProcessMessage(CNode* pFrom, const std::string& msg_type, C

{
LOCK2(cs_main, cs_data_requests);
auto quorumHash = request.GetQuorumHash();
auto llmqType = (uint8_t) request.GetLLMQType();
auto key = std::make_tuple(pFrom->GetVerifiedProRegTxHash(), true, quorumHash, llmqType);
CQuorumDataRequestKey key;
key.proRegTx = pFrom->GetVerifiedProRegTxHash();
key.flag = true;
key.quorumHash = request.GetQuorumHash();
key.llmqType = request.GetLLMQType();
auto it = mapQuorumDataRequests.find(key);
if (it == mapQuorumDataRequests.end()) {
errorHandler("Not requested");
Expand Down Expand Up @@ -838,9 +842,11 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
pCurrentMemberHash = &vecMemberHashes[(nMyStartOffset + nTries++) % vecMemberHashes.size()];
{
LOCK(cs_data_requests);
auto quorumHash = pQuorum->qc->quorumHash;
auto llmqType = (uint8_t)pQuorum->qc->quorumIndex;
auto key = std::make_tuple(*pCurrentMemberHash, true, quorumHash, (uint8_t)llmqType);
CQuorumDataRequestKey key;
key.proRegTx = *pCurrentMemberHash;
key.flag = true;
key.quorumHash = pQuorum->qc->quorumHash;
key.llmqType = pQuorum->qc->llmqType;
auto it = mapQuorumDataRequests.find(key);
if (it != mapQuorumDataRequests.end() && !it->second.IsExpired()) {
printLog("Already asked");
Expand All @@ -866,9 +872,11 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
printLog("Requested");
} else {
LOCK(cs_data_requests);
auto quorumHash = pQuorum->qc->quorumHash;
auto llmqType = (uint8_t)pQuorum->qc->quorumIndex;
auto key = std::make_tuple(*pCurrentMemberHash, true, quorumHash, (uint8_t)llmqType);
CQuorumDataRequestKey key;
key.proRegTx = *pCurrentMemberHash;
key.flag = true;
key.quorumHash = pQuorum->qc->quorumHash;
key.llmqType = pQuorum->qc->llmqType;
auto it = mapQuorumDataRequests.find(key);
if (it == mapQuorumDataRequests.end()) {
printLog("Failed");
Expand Down
31 changes: 31 additions & 0 deletions src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ class CDKGSessionManager;
// If true, we will connect to all new quorums and watch their communication
static constexpr bool DEFAULT_WATCH_QUORUMS{false};

/**
* Object used as a key to store CQuorumDataRequest
*/
struct CQuorumDataRequestKey
{
uint256 proRegTx;
//TODO: Investigate purpose of this flag and rename accordingly
bool flag;
uint256 quorumHash;
Consensus::LLMQType llmqType;

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

/**
* An object of this class represents a QGETDATA request or a QDATA response header
Expand Down Expand Up @@ -243,6 +259,21 @@ extern CQuorumManager* quorumManager;

} // namespace llmq

template<typename T> struct SaltedHasherImpl;
template<>
struct SaltedHasherImpl<llmq::CQuorumDataRequestKey>
{
static std::size_t CalcHash(const llmq::CQuorumDataRequestKey& v, uint64_t k0, uint64_t k1)
{
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.quorumHash), sizeof(v.quorumHash));
c.Write((unsigned char*)&(v.llmqType), sizeof(v.llmqType));
return c.Finalize();
}
};

template<> struct is_serializable_enum<llmq::CQuorumDataRequest::Errors> : std::true_type {};

#endif // BITCOIN_LLMQ_QUORUMS_H
14 changes: 0 additions & 14 deletions src/saltedhasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@

template<typename T> struct SaltedHasherImpl;

template<typename N, typename M, typename K, typename Q>
struct SaltedHasherImpl<std::tuple<N, M, K, Q>>
{
static std::size_t CalcHash(const std::tuple<N, M, K, Q>& v, uint64_t k0, uint64_t k1)
{
CSipHasher c(k0, k1);
c.Write((unsigned char*)&std::get<0>(v), sizeof(M));
c.Write((unsigned char*)&std::get<1>(v), sizeof(N));
c.Write((unsigned char*)&std::get<2>(v), sizeof(K));
c.Write((unsigned char*)&std::get<3>(v), sizeof(Q));
return c.Finalize();
}
};

template<typename N>
struct SaltedHasherImpl<std::pair<uint256, N>>
{
Expand Down

0 comments on commit b504b97

Please sign in to comment.