// Copyright (c) 2018-2019 The Dash Core developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_LLMQ_QUORUMS_DKGSESSIONMGR_H #define BITCOIN_LLMQ_QUORUMS_DKGSESSIONMGR_H #include #include #include class UniValue; namespace llmq { class CDKGSessionManager { static const int64_t MAX_CONTRIBUTION_CACHE_TIME = 60 * 1000; private: CDBWrapper& llmqDb; CBLSWorker& blsWorker; std::map dkgSessionHandlers; CCriticalSection contributionsCacheCs; struct ContributionsCacheKey { Consensus::LLMQType llmqType; uint256 quorumHash; uint256 proTxHash; bool operator<(const ContributionsCacheKey& r) const { if (llmqType != r.llmqType) return llmqType < r.llmqType; if (quorumHash != r.quorumHash) return quorumHash < r.quorumHash; return proTxHash < r.proTxHash; } }; struct ContributionsCacheEntry { int64_t entryTime; BLSVerificationVectorPtr vvec; CBLSSecretKey skContribution; }; std::map contributionsCache; public: CDKGSessionManager(CDBWrapper& _llmqDb, CBLSWorker& _blsWorker); ~CDKGSessionManager(); void StartThreads(); void StopThreads(); void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload); void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv); bool AlreadyHave(const CInv& inv) const; bool GetContribution(const uint256& hash, CDKGContribution& ret) const; bool GetComplaint(const uint256& hash, CDKGComplaint& ret) const; bool GetJustification(const uint256& hash, CDKGJustification& ret) const; bool GetPrematureCommitment(const uint256& hash, CDKGPrematureCommitment& ret) const; // Verified contributions are written while in the DKG void WriteVerifiedVvecContribution(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& proTxHash, const BLSVerificationVectorPtr& vvec); void WriteVerifiedSkContribution(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& proTxHash, const CBLSSecretKey& skContribution); bool GetVerifiedContributions(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const std::vector& validMembers, std::vector& memberIndexesRet, std::vector& vvecsRet, BLSSecretKeyVector& skContributionsRet); private: void CleanupCache(); }; bool IsQuorumDKGEnabled(); extern CDKGSessionManager* quorumDKGSessionManager; } // namespace llmq #endif // BITCOIN_LLMQ_QUORUMS_DKGSESSIONMGR_H