6 #ifndef PIVX_LLMQ_QUORUMS_SIGNING_SHARES_H
7 #define PIVX_LLMQ_QUORUMS_SIGNING_SHARES_H
23 #include <unordered_map>
24 #include <unordered_set>
54 assert(!
key.first.IsNull());
98 std::vector<bool>
inv;
103 uint64_t invSize = obj.inv.size();
110 void Init(
size_t size);
111 bool IsSet(uint16_t quorumMember)
const;
112 void Set(uint16_t quorumMember,
bool v);
125 std::vector<std::pair<uint16_t, CBLSLazySignature>>
sigShares;
137 template <
typename T>
147 return m.emplace(k.second, v).second;
156 it->second.erase(k.second);
157 if (it->second.empty()) {
173 return it->second.count(k.second) != 0;
183 auto jt = it->second.find(k.second);
184 if (jt == it->second.end()) {
206 return &
internalMap.begin()->second.begin()->second;
213 s += p.second.size();
224 return it->second.size();
246 template <
typename F>
252 for (
auto jt = it->second.begin(); jt != it->second.end();) {
253 k.second = jt->first;
254 if (f(k, jt->second)) {
255 jt = it->second.erase(jt);
260 if (it->second.empty()) {
268 template <
typename F>
274 for (
auto& p2 : p.second) {
313 std::unordered_map<uint256, Session, StaticSaltedHasher>
sessions;
374 std::vector<std::tuple<const CQuorumCPtr, uint256, uint256>>
pendingSigns;
415 std::unordered_map<
NodeId, std::vector<CSigShare>>& retSigShares,
439 void CollectSigSharesToSend(std::unordered_map<
NodeId, std::unordered_map<uint256, CBatchedSigShares, StaticSaltedHasher>>& sigSharesToSend);
Information about a peer.
std::vector< std::pair< uint16_t, CBLSLazySignature > > sigShares
SERIALIZE_METHODS(CBatchedSigShares, obj)
std::string ToInvString() const
std::string ToString() const
SERIALIZE_METHODS(CSigSesAnn, obj)
const SigShareKey & GetKey() const
CBLSLazySignature sigShare
const uint256 & GetSignHash() const
SERIALIZE_METHODS(CSigShare, obj)
std::string ToString() const
SERIALIZE_METHODS(CSigSharesInv, obj)
void Set(uint16_t quorumMember, bool v)
void Merge(const CSigSharesInv &inv2)
bool IsSet(uint16_t quorumMember) const
void AsyncSign(const CQuorumCPtr &quorum, const uint256 &id, const uint256 &msgHash)
void CollectSigSharesToAnnounce(std::unordered_map< NodeId, std::unordered_map< uint256, CSigSharesInv, StaticSaltedHasher >> &sigSharesToAnnounce)
const size_t MAX_MSGS_TOTAL_BATCHED_SIGS
static const int64_t SESSION_NEW_SHARES_TIMEOUT
bool VerifySigSharesInv(NodeId from, Consensus::LLMQType llmqType, const CSigSharesInv &inv)
const size_t MAX_MSGS_CNT_QSIGSHARESINV
const size_t MAX_MSGS_SIG_SHARES
bool ProcessMessageGetSigShares(CNode *pfrom, const CSigSharesInv &inv, CConnman &connman)
bool GetSessionInfoByRecvId(NodeId nodeId, uint32_t sessionId, CSigSharesNodeState::SessionInfo &retInfo)
void ProcessMessageSigShare(NodeId fromId, const CSigShare &sigShare, CConnman &connman)
std::unordered_map< NodeId, CSigSharesNodeState > nodeStates
void RemoveSigSharesForSession(const uint256 &signHash)
void UnregisterAsRecoveredSigsListener()
void CollectPendingSigSharesToVerify(size_t maxUniqueSessions, std::unordered_map< NodeId, std::vector< CSigShare >> &retSigShares, std::unordered_map< std::pair< Consensus::LLMQType, uint256 >, CQuorumCPtr, StaticSaltedHasher > &retQuorums)
std::vector< std::tuple< const CQuorumCPtr, uint256, uint256 > > pendingSigns
void ProcessPendingSigSharesFromNode(NodeId nodeId, const std::vector< CSigShare > &sigShares, const std::unordered_map< std::pair< Consensus::LLMQType, uint256 >, CQuorumCPtr, StaticSaltedHasher > &quorums, CConnman &connman)
void ProcessMessage(CNode *pnode, const std::string &strCommand, CDataStream &vRecv, CConnman &connman)
void CollectSigSharesToSend(std::unordered_map< NodeId, std::unordered_map< uint256, CBatchedSigShares, StaticSaltedHasher >> &sigSharesToSend)
const size_t MAX_MSGS_CNT_QGETSIGSHARES
std::unordered_map< uint256, int64_t, StaticSaltedHasher > timeSeenForSessions
SigShareMap< CSigShare > sigShares
std::atomic< uint32_t > recoveredSigsCounter
SigShareMap< bool > sigSharesToAnnounce
std::unordered_map< uint256, CSignedSession, StaticSaltedHasher > signedSessions
CSigShare RebuildSigShare(const CSigSharesNodeState::SessionInfo &session, const CBatchedSigShares &batchedSigShares, size_t idx)
static const int64_t SIG_SHARE_REQUEST_TIMEOUT
bool ProcessMessageSigSharesInv(CNode *pfrom, const CSigSharesInv &inv, CConnman &connman)
void Sign(const CQuorumCPtr &quorum, const uint256 &id, const uint256 &msgHash)
void ProcessSigShare(NodeId nodeId, const CSigShare &sigShare, CConnman &connman, const CQuorumCPtr &quorum)
CThreadInterrupt interruptSigningShare
void BanNode(NodeId nodeId)
bool ProcessMessageBatchedSigShares(CNode *pfrom, const CBatchedSigShares &batchedSigShares, CConnman &connman)
bool ProcessPendingSigShares(CConnman &connman)
bool PreVerifyBatchedSigShares(NodeId nodeId, const CSigSharesNodeState::SessionInfo &session, const CBatchedSigShares &batchedSigShares, bool &retBan)
void TryRecoverSig(const CQuorumCPtr &quorum, const uint256 &id, const uint256 &msgHash, CConnman &connman)
const int64_t MAX_SEND_FOR_RECOVERY_TIMEOUT
void RemoveBannedNodeStates()
void CollectSigSharesToRequest(std::unordered_map< NodeId, std::unordered_map< uint256, CSigSharesInv, StaticSaltedHasher >> &sigSharesToRequest)
bool ProcessMessageSigSesAnn(CNode *pfrom, const CSigSesAnn &ann, CConnman &connman)
bool SignPendingSigShares()
void HandleNewRecoveredSig(const CRecoveredSig &recoveredSig)
const int64_t EXP_SEND_FOR_RECOVERY_TIMEOUT
static CDeterministicMNCPtr SelectMemberForRecovery(const CQuorumCPtr &quorum, const uint256 &id, int attempt)
const size_t MAX_MSGS_CNT_QSIGSESANN
void RegisterAsRecoveredSigsListener()
SigShareMap< std::pair< NodeId, int64_t > > sigSharesRequested
void ForceReAnnouncement(const CQuorumCPtr &quorum, Consensus::LLMQType llmqType, const uint256 &id, const uint256 &msgHash)
SigShareMap< CSigShare > pendingIncomingSigShares
Session * GetSessionBySignHash(const uint256 &signHash)
Session & GetOrCreateSessionFromShare(const CSigShare &sigShare)
uint32_t nextSendSessionId
std::unordered_map< uint32_t, Session * > sessionByRecvId
void RemoveSession(const uint256 &signHash)
Session & GetOrCreateSessionFromAnn(const CSigSesAnn &ann)
bool GetSessionInfoByRecvId(uint32_t sessionId, SessionInfo &retInfo)
std::unordered_map< uint256, Session, StaticSaltedHasher > sessions
SigShareMap< int64_t > requestedSigShares
Session * GetSessionByRecvId(uint32_t sessionId)
void Erase(const SigShareKey &k)
bool Has(const SigShareKey &k) const
T * Get(const SigShareKey &k)
void EraseAllForSignHash(const uint256 &signHash)
const T * GetFirst() const
T & GetOrAdd(const SigShareKey &k)
std::unordered_map< uint256, std::unordered_map< uint16_t, T >, StaticSaltedHasher > internalMap
bool Add(const SigShareKey &k, const T &v)
size_t CountForSignHash(const uint256 &signHash) const
const std::unordered_map< uint16_t, T > * GetAllForSignHash(const uint256 &signHash)
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
#define T(expected, seed, data)
std::shared_ptr< const CQuorum > CQuorumCPtr
std::pair< uint256, uint16_t > SigShareKey
std::unique_ptr< CSigSharesManager > quorumSigSharesManager
#define SER_READ(obj, code)
#define AUTOBITSET(obj, size)
Consensus::LLMQType llmqType
Consensus::LLMQType llmqType