Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
quorums_signing.cpp
Go to the documentation of this file.
43 // TODO this can be completely removed after some time (when we're pretty sure the conversion has been run on most testnet MNs)
55 // This converts time values in "rs_t" from host endiannes to big endiannes, which is required to have proper ordering of the keys
62 auto start = std::make_tuple(std::string("rs_t"), (uint32_t)0, (Consensus::LLMQType)0, uint256());
89 // This adds rs_vt keys for every rs_v entry to the DB. The time in the key is set to the current time.
128 bool CRecoveredSigsDb::HasRecoveredSig(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash)
190 bool CRecoveredSigsDb::ReadRecoveredSig(Consensus::LLMQType llmqType, const uint256& id, CRecoveredSig& ret)
218 bool CRecoveredSigsDb::GetRecoveredSigById(Consensus::LLMQType llmqType, const uint256& id, CRecoveredSig& ret)
230 // this way, the second key can be used for fast HasRecoveredSig checks while the first key stores the recSig
234 // this key is also used to store the current time, so that we can easily get to the "rs_t" key when we have the id
247 auto k5 = std::make_tuple(std::string("rs_t"), (uint32_t)htobe32(curTime), recSig.llmqType, recSig.id);
262 void CRecoveredSigsDb::RemoveRecoveredSig(CDBBatch& batch, Consensus::LLMQType llmqType, const uint256& id, bool deleteHashKey, bool deleteTimeKey)
286 // TODO remove the size() == sizeof(uint32_t) in a future version (when we stop supporting upgrades from < 0.14.1)
290 auto k5 = std::make_tuple(std::string("rs_t"), (uint32_t) htobe32(writeTime), recSig.llmqType, recSig.id);
325 auto start = std::make_tuple(std::string("rs_t"), (uint32_t)0, (Consensus::LLMQType)0, uint256());
372 LogPrint(BCLog::LLMQ, "CRecoveredSigsDb::%d -- deleted %d entries\n", __func__, toDelete.size());
381 bool CRecoveredSigsDb::GetVoteForId(Consensus::LLMQType llmqType, const uint256& id, uint256& msgHashRet)
387 void CRecoveredSigsDb::WriteVoteForId(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash)
390 auto k2 = std::make_tuple(std::string("rs_vt"), (uint32_t)htobe32(GetAdjustedTime()), llmqType, id);
403 auto start = std::make_tuple(std::string("rs_vt"), (uint32_t)0, (Consensus::LLMQType)0, uint256());
474 void CSigningManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
483 void CSigningManager::ProcessMessageRecoveredSig(CNode* pfrom, const CRecoveredSig& recoveredSig, CConnman& connman)
500 LogPrint(BCLog::LLMQ, "CSigningManager::%s -- signHash=%s, id=%s, msgHash=%s, node=%d\n", __func__,
501 CLLMQUtils::BuildSignHash(recoveredSig).ToString(), recoveredSig.id.ToString(), recoveredSig.msgHash.ToString(), pfrom->GetId());
506 LogPrint(BCLog::LLMQ, "CSigningManager::%s -- already pending reconstructed sig, signHash=%s, id=%s, msgHash=%s, node=%d\n", __func__,
507 CLLMQUtils::BuildSignHash(recoveredSig).ToString(), recoveredSig.id.ToString(), recoveredSig.msgHash.ToString(), pfrom->GetId());
513 bool CSigningManager::PreVerifyRecoveredSig(NodeId nodeId, const CRecoveredSig& recoveredSig, bool& retBan)
540 std::unordered_map<std::pair<Consensus::LLMQType, uint256>, CQuorumCPtr, StaticSaltedHasher>& retQuorums)
589 LogPrint(BCLog::LLMQ, "CSigningManager::%s -- quorum %s not active anymore, node=%d\n", __func__,
618 std::unordered_map<std::pair<Consensus::LLMQType, uint256>, CQuorumCPtr, StaticSaltedHasher> quorums;
627 // It's ok to perform insecure batched verification here as we verify against the quorum public keys, which are not
643 const auto& quorum = quorums.at(std::make_pair((Consensus::LLMQType)recSig.llmqType, recSig.quorumHash));
644 batchVerifier.PushMessage(nodeId, recSig.GetHash(), CLLMQUtils::BuildSignHash(recSig), recSig.sig.Get(), quorum->qc.quorumPublicKey);
653 LogPrint(BCLog::LLMQ, "CSigningManager::%s -- verified recovered sig(s). count=%d, vt=%d, nodes=%d\n", __func__, verifyCount, verifyTimer.count(), recSigsByNode.size());
662 LogPrint(BCLog::LLMQ, "CSigningManager::%s -- invalid recSig from other node, banning peer=%d\n", __func__, nodeId);
672 const auto& quorum = quorums.at(std::make_pair((Consensus::LLMQType)recSig.llmqType, recSig.quorumHash));
681 void CSigningManager::ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig& recoveredSig, const CQuorumCPtr& quorum, CConnman& connman)
701 LogPrint(BCLog::LLMQ, "CSigningManager::%s -- valid recSig. signHash=%s, id=%s, msgHash=%s, node=%d\n", __func__,
710 // even if it's a member of multiple quorums. so a majority is only possible on one quorum and one msgHash per id
711 LogPrintf("CSigningManager::%s -- conflicting recoveredSig for signHash=%s, id=%s, msgHash=%s, otherSignHash=%s\n", __func__,
712 signHash.ToString(), recoveredSig.id.ToString(), recoveredSig.msgHash.ToString(), otherSignHash.ToString());
714 // Looks like we're trying to process a recSig that is already known. This might happen if the same
715 // recSig comes in through regular QRECSIG messages and at the same time through some other message
720 // This case is very unlikely. It can only happen when cleanup caused this specific recSig to vanish
721 // between the HasRecoveredSigForId and GetRecoveredSigById call. If that happens, treat it as if we
743 void CSigningManager::PushReconstructedRecoveredSig(const llmq::CRecoveredSig& recoveredSig, const llmq::CQuorumCPtr& quorum)
784 bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash, bool allowReSign)
800 LogPrintf("CSigningManager::%s -- already voted for id=%s and msgHash=%s. Not voting on conflicting msgHash=%s\n", __func__,
804 LogPrint(BCLog::LLMQ, "CSigningManager::%s -- already voted for id=%s and msgHash=%s. Resigning!\n", __func__,
807 LogPrint(BCLog::LLMQ, "CSigningManager::%s -- already voted for id=%s and msgHash=%s. Not voting again.\n", __func__,
826 // TODO fix this by re-signing when the next block arrives, but only when that block results in a change of the quorum list and no recovered signature has been created in the mean time
829 LogPrint(BCLog::LLMQ, "CSigningManager::%s -- failed to select quorum. id=%s, msgHash=%s\n", __func__, id.ToString(), msgHash.ToString());
846 bool CSigningManager::HasRecoveredSig(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash)
861 bool CSigningManager::GetRecoveredSigForId(Consensus::LLMQType llmqType, const uint256& id, llmq::CRecoveredSig& retRecSig)
869 bool CSigningManager::IsConflicting(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash)
890 bool CSigningManager::GetVoteForId(Consensus::LLMQType llmqType, const uint256& id, uint256& msgHashRet)
895 CQuorumCPtr CSigningManager::SelectQuorumForSigning(Consensus::LLMQType llmqType, const uint256& selectionHash, int signHeight, int signOffset)
931 bool CSigningManager::VerifyRecoveredSig(Consensus::LLMQType llmqType, int signedAtHeight, const uint256& id, const uint256& msgHash, const CBLSSignature& sig)
void PushMessage(const SourceId &sourceId, const MessageId &msgId, const uint256 &msgHash, const CBLSSignature &sig, const CBLSPublicKey &pubKey)
Definition: bls_batchverifier.h:47
CSigSharesManager * quorumSigSharesManager
Definition: quorums_signing_shares.cpp:22
void CleanupOldVotes(int64_t maxAge)
Definition: quorums_signing.cpp:399
static uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256 &quorumHash, const uint256 &id, const uint256 &msgHash)
Definition: quorums_utils.cpp:37
void ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig &recoveredSig, const CQuorumCPtr &quorum, CConnman &connman)
Definition: quorums_signing.cpp:681
void ProcessMessage(CNode *pnode, const std::string &strCommand, CDataStream &vRecv, CConnman &connman)
Definition: quorums_signing.cpp:474
void TruncateRecoveredSig(Consensus::LLMQType llmqType, const uint256 &id)
Definition: quorums_signing.cpp:313
static bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256 &quorumHash)
Definition: quorums_utils.cpp:243
void CollectPendingRecoveredSigsToVerify(size_t maxUniqueSessions, std::unordered_map< NodeId, std::list< CRecoveredSig >> &retSigShares, std::unordered_map< std::pair< Consensus::LLMQType, uint256 >, CQuorumCPtr, StaticSaltedHasher > &retQuorums)
Definition: quorums_signing.cpp:537
Definition: dbwrapper.h:197
Definition: univalue.h:20
CRecoveredSigsDb(CDBWrapper &_db)
Definition: quorums_signing.cpp:39
bool HasRecoveredSig(Consensus::LLMQType llmqType, const uint256 &id, const uint256 &msgHash)
Definition: quorums_signing.cpp:128
void ProcessMessageRecoveredSig(CNode *pfrom, const CRecoveredSig &recoveredSig, CConnman &connman)
Definition: quorums_signing.cpp:483
std::vector< CQuorumCPtr > ScanQuorums(Consensus::LLMQType llmqType, size_t maxCount)
Definition: quorums.cpp:279
bool VerifyInsecure(const CBLSPublicKey &pubKey, const uint256 &hash) const
Definition: bls.cpp:335
bool GetRecoveredSigById(Consensus::LLMQType llmqType, const uint256 &id, CRecoveredSig &ret)
Definition: quorums_signing.cpp:218
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
Definition: deterministicmns.h:26
Definition: saltedhasher.h:64
bool ReadRecoveredSig(Consensus::LLMQType llmqType, const uint256 &id, CRecoveredSig &ret)
Definition: quorums_signing.cpp:190
bool HasRecoveredSigForHash(const uint256 &hash)
Definition: quorums_signing.cpp:172
bool ReadDataStream(const K &key, CDataStream &ssValue) const
Definition: dbwrapper.h:246
bool ProcessPendingRecoveredSigs(CConnman &connman)
Definition: quorums_signing.cpp:615
bool GetVoteForId(Consensus::LLMQType llmqType, const uint256 &id, uint256 &msgHashRet)
Definition: quorums_signing.cpp:381
void insert(const Key &key, const Value &v)
Definition: unordered_lru_cache.h:49
Definition: util.h:137
void Misbehaving(NodeId pnode, int howmuch, const std::string &message)
Increase a node's misbehavior score.
Definition: net_processing.cpp:1024
Definition: univalue.h:22
std::unordered_map< NodeId, std::list< CRecoveredSig > > pendingRecoveredSigs
Definition: quorums_signing.h:128
unordered_lru_cache< uint256, bool, StaticSaltedHasher, 30000 > hasSigForHashCache
Definition: quorums_signing.h:72
unordered_lru_cache< std::pair< Consensus::LLMQType, uint256 >, bool, StaticSaltedHasher, 30000 > hasSigForIdCache
Definition: quorums_signing.h:70
Definition: quorums_signing.h:112
Definition: bls.h:286
void ConvertInvalidTimeKeys()
Definition: quorums_signing.cpp:56
bool GetRecoveredSigForGetData(const uint256 &hash, CRecoveredSig &ret)
Definition: quorums_signing.cpp:462
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:185
bool GetRecoveredSigByHash(const uint256 &hash, CRecoveredSig &ret)
Definition: quorums_signing.cpp:207
Definition: quorums_signing.h:21
bool HasRecoveredSigForId(Consensus::LLMQType llmqType, const uint256 &id)
Definition: quorums_signing.cpp:134
void WriteVoteForId(Consensus::LLMQType llmqType, const uint256 &id, const uint256 &msgHash)
Definition: quorums_signing.cpp:387
void ProcessPendingReconstructedRecoveredSigs()
Definition: quorums_signing.cpp:603
std::unordered_map< uint256, std::pair< CRecoveredSig, CQuorumCPtr >, StaticSaltedHasher > pendingReconstructedRecoveredSigs
Definition: quorums_signing.h:129
static void IterateNodesRandom(NodesContainer &nodeStates, Continue &&cont, Callback &&callback, FastRandomContext &rnd)
Definition: quorums_utils.h:46
void CleanupOldRecoveredSigs(int64_t maxAge)
Definition: quorums_signing.cpp:321
bool Write(const K &key, const V &value, bool fSync=false)
Definition: dbwrapper.h:298
void RemoveRecoveredSig(Consensus::LLMQType llmqType, const uint256 &id)
Definition: quorums_signing.cpp:303
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:947
bool AlreadyHave(const CInv &inv)
Definition: quorums_signing.cpp:447
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: util.cpp:808
bool HasRecoveredSigForSession(const uint256 &signHash)
Definition: quorums_signing.cpp:154
Definition: bls_batchverifier.h:14
CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, const uint256 &quorumHash)
Definition: quorums.cpp:337
void EraseObjectRequest(CNodeState *nodestate, const CInv &inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: net_processing.cpp:676
bool WriteBatch(CDBBatch &batch, bool fSync=false)
Definition: dbwrapper.cpp:157
bool HasVotedOnId(Consensus::LLMQType llmqType, const uint256 &id)
Definition: quorums_signing.cpp:375
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:54
CChain & chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:217
AssertLockHeld(g_cs_orphans)
Definition: protocol.h:423
static const int CLIENT_VERSION
dashd-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:38
Definition: serialize.h:160
CSigningManager(CDBWrapper &llmqDb, bool fMemory)
Definition: quorums_signing.cpp:442
bool PreVerifyRecoveredSig(NodeId nodeId, const CRecoveredSig &recoveredSig, bool &retBan)
Definition: quorums_signing.cpp:513
Definition: serialize.h:161
void WriteRecoveredSig(const CRecoveredSig &recSig)
Definition: quorums_signing.cpp:223
unordered_lru_cache< uint256, bool, StaticSaltedHasher, 30000 > hasSigForSessionCache
Definition: quorums_signing.h:71