mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
refactor: introduce CSigBase which becomes the base class for CRecoveredSig, CSigShare and CSigSesAnn (#4776)
* refactor: introduce CSigBase which becomes the base class for CRecoveredSig, CSigShare and CSigSesAnn * fix: add optional include
This commit is contained in:
parent
608a099c87
commit
a9aac3ba9f
@ -540,7 +540,7 @@ void CChainLocksHandler::HandleNewRecoveredSig(const llmq::CRecoveredSig& recove
|
||||
{
|
||||
LOCK(cs);
|
||||
|
||||
if (recoveredSig.id != lastSignedRequestId || recoveredSig.msgHash != lastSignedMsgHash) {
|
||||
if (recoveredSig.getId() != lastSignedRequestId || recoveredSig.getMsgHash() != lastSignedMsgHash) {
|
||||
// this is not what we signed, so lets not create a CLSIG for it
|
||||
return;
|
||||
}
|
||||
|
@ -651,10 +651,10 @@ void CInstantSendManager::HandleNewRecoveredSig(const CRecoveredSig& recoveredSi
|
||||
bool isInstantSendLock = false;
|
||||
{
|
||||
LOCK(cs);
|
||||
if (inputRequestIds.count(recoveredSig.id)) {
|
||||
txid = recoveredSig.msgHash;
|
||||
if (inputRequestIds.count(recoveredSig.getId())) {
|
||||
txid = recoveredSig.getMsgHash();
|
||||
}
|
||||
if (creatingInstantSendLocks.count(recoveredSig.id)) {
|
||||
if (creatingInstantSendLocks.count(recoveredSig.getId())) {
|
||||
isInstantSendLock = true;
|
||||
}
|
||||
}
|
||||
@ -680,7 +680,7 @@ void CInstantSendManager::HandleNewInputLockRecoveredSig(const CRecoveredSig& re
|
||||
if (LogAcceptCategory(BCLog::INSTANTSEND)) {
|
||||
for (auto& in : tx->vin) {
|
||||
auto id = ::SerializeHash(std::make_pair(INPUTLOCK_REQUESTID_PREFIX, in.prevout));
|
||||
if (id == recoveredSig.id) {
|
||||
if (id == recoveredSig.getId()) {
|
||||
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s: got recovered sig for input %s\n", __func__,
|
||||
txid.ToString(), in.prevout.ToStringShort());
|
||||
break;
|
||||
@ -743,7 +743,7 @@ void CInstantSendManager::HandleNewInstantSendLockRecoveredSig(const llmq::CReco
|
||||
|
||||
{
|
||||
LOCK(cs);
|
||||
auto it = creatingInstantSendLocks.find(recoveredSig.id);
|
||||
auto it = creatingInstantSendLocks.find(recoveredSig.getId());
|
||||
if (it == creatingInstantSendLocks.end()) {
|
||||
return;
|
||||
}
|
||||
@ -753,9 +753,9 @@ void CInstantSendManager::HandleNewInstantSendLockRecoveredSig(const llmq::CReco
|
||||
txToCreatingInstantSendLocks.erase(islock->txid);
|
||||
}
|
||||
|
||||
if (islock->txid != recoveredSig.msgHash) {
|
||||
if (islock->txid != recoveredSig.getMsgHash()) {
|
||||
LogPrintf("CInstantSendManager::%s -- txid=%s: islock conflicts with %s, dropping own version\n", __func__,
|
||||
islock->txid.ToString(), recoveredSig.msgHash.ToString());
|
||||
islock->txid.ToString(), recoveredSig.getMsgHash().ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1024,7 +1024,7 @@ std::unordered_set<uint256, StaticSaltedHasher> CInstantSendManager::ProcessPend
|
||||
auto it = recSigs.find(hash);
|
||||
if (it != recSigs.end()) {
|
||||
auto recSig = std::make_shared<CRecoveredSig>(std::move(it->second));
|
||||
if (!quorumSigningManager->HasRecoveredSigForId(llmqType, recSig->id)) {
|
||||
if (!quorumSigningManager->HasRecoveredSigForId(llmqType, recSig->getId())) {
|
||||
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: passing reconstructed recSig to signing mgr, peer=%d\n", __func__,
|
||||
islock->txid.ToString(), hash.ToString(), nodeId);
|
||||
quorumSigningManager->PushReconstructedRecoveredSig(recSig);
|
||||
|
@ -327,30 +327,30 @@ void CRecoveredSigsDb::WriteRecoveredSig(const llmq::CRecoveredSig& recSig)
|
||||
|
||||
// we put these close to each other to leverage leveldb's key compaction
|
||||
// this way, the second key can be used for fast HasRecoveredSig checks while the first key stores the recSig
|
||||
auto k1 = std::make_tuple(std::string("rs_r"), recSig.llmqType, recSig.id);
|
||||
auto k2 = std::make_tuple(std::string("rs_r"), recSig.llmqType, recSig.id, recSig.msgHash);
|
||||
auto k1 = std::make_tuple(std::string("rs_r"), recSig.getLlmqType(), recSig.getId());
|
||||
auto k2 = std::make_tuple(std::string("rs_r"), recSig.getLlmqType(), recSig.getId(), recSig.getMsgHash());
|
||||
batch.Write(k1, recSig);
|
||||
// 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
|
||||
batch.Write(k2, curTime);
|
||||
|
||||
// store by object hash
|
||||
auto k3 = std::make_tuple(std::string("rs_h"), recSig.GetHash());
|
||||
batch.Write(k3, std::make_pair(recSig.llmqType, recSig.id));
|
||||
batch.Write(k3, std::make_pair(recSig.getLlmqType(), recSig.getId()));
|
||||
|
||||
// store by signHash
|
||||
auto signHash = CLLMQUtils::BuildSignHash(recSig);
|
||||
auto signHash = recSig.buildSignHash();
|
||||
auto k4 = std::make_tuple(std::string("rs_s"), signHash);
|
||||
batch.Write(k4, (uint8_t)1);
|
||||
|
||||
// store by current time. Allows fast cleanup of old recSigs
|
||||
auto k5 = std::make_tuple(std::string("rs_t"), (uint32_t)htobe32(curTime), recSig.llmqType, recSig.id);
|
||||
auto k5 = std::make_tuple(std::string("rs_t"), (uint32_t)htobe32(curTime), recSig.getLlmqType(), recSig.getId());
|
||||
batch.Write(k5, (uint8_t)1);
|
||||
|
||||
db->WriteBatch(batch);
|
||||
|
||||
{
|
||||
LOCK(cs);
|
||||
hasSigForIdCache.insert(std::make_pair(recSig.llmqType, recSig.id), true);
|
||||
hasSigForIdCache.insert(std::make_pair(recSig.getLlmqType(), recSig.getId()), true);
|
||||
hasSigForSessionCache.insert(signHash, true);
|
||||
hasSigForHashCache.insert(recSig.GetHash(), true);
|
||||
}
|
||||
@ -365,10 +365,10 @@ void CRecoveredSigsDb::RemoveRecoveredSig(CDBBatch& batch, Consensus::LLMQType l
|
||||
return;
|
||||
}
|
||||
|
||||
auto signHash = CLLMQUtils::BuildSignHash(recSig);
|
||||
auto signHash = recSig.buildSignHash();
|
||||
|
||||
auto k1 = std::make_tuple(std::string("rs_r"), recSig.llmqType, recSig.id);
|
||||
auto k2 = std::make_tuple(std::string("rs_r"), recSig.llmqType, recSig.id, recSig.msgHash);
|
||||
auto k1 = std::make_tuple(std::string("rs_r"), recSig.getLlmqType(), recSig.getId());
|
||||
auto k2 = std::make_tuple(std::string("rs_r"), recSig.getLlmqType(), recSig.getId(), recSig.getMsgHash());
|
||||
auto k3 = std::make_tuple(std::string("rs_h"), recSig.GetHash());
|
||||
auto k4 = std::make_tuple(std::string("rs_s"), signHash);
|
||||
batch.Erase(k1);
|
||||
@ -384,12 +384,12 @@ void CRecoveredSigsDb::RemoveRecoveredSig(CDBBatch& batch, Consensus::LLMQType l
|
||||
if (db->ReadDataStream(k2, writeTimeDs) && writeTimeDs.size() == sizeof(uint32_t)) {
|
||||
uint32_t writeTime;
|
||||
writeTimeDs >> writeTime;
|
||||
auto k5 = std::make_tuple(std::string("rs_t"), (uint32_t) htobe32(writeTime), recSig.llmqType, recSig.id);
|
||||
auto k5 = std::make_tuple(std::string("rs_t"), (uint32_t) htobe32(writeTime), recSig.getLlmqType(), recSig.getId());
|
||||
batch.Erase(k5);
|
||||
}
|
||||
}
|
||||
|
||||
hasSigForIdCache.erase(std::make_pair(recSig.llmqType, recSig.id));
|
||||
hasSigForIdCache.erase(std::make_pair(recSig.getLlmqType(), recSig.getId()));
|
||||
hasSigForSessionCache.erase(signHash);
|
||||
if (deleteHashKey) {
|
||||
hasSigForHashCache.erase(recSig.GetHash());
|
||||
@ -561,7 +561,7 @@ bool CSigningManager::GetRecoveredSigForGetData(const uint256& hash, CRecoveredS
|
||||
if (!db.GetRecoveredSigByHash(hash, ret)) {
|
||||
return false;
|
||||
}
|
||||
if (!CLLMQUtils::IsQuorumActive(ret.llmqType, ret.quorumHash)) {
|
||||
if (!CLLMQUtils::IsQuorumActive(ret.getLlmqType(), ret.getQuorumHash())) {
|
||||
// we don't want to propagate sigs from inactive quorums
|
||||
return false;
|
||||
}
|
||||
@ -600,13 +600,13 @@ void CSigningManager::ProcessMessageRecoveredSig(CNode* pfrom, const std::shared
|
||||
}
|
||||
|
||||
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- signHash=%s, id=%s, msgHash=%s, node=%d\n", __func__,
|
||||
CLLMQUtils::BuildSignHash(*recoveredSig).ToString(), recoveredSig->id.ToString(), recoveredSig->msgHash.ToString(), pfrom->GetId());
|
||||
recoveredSig->buildSignHash().ToString(), recoveredSig->getId().ToString(), recoveredSig->getMsgHash().ToString(), pfrom->GetId());
|
||||
|
||||
LOCK(cs);
|
||||
if (pendingReconstructedRecoveredSigs.count(recoveredSig->GetHash())) {
|
||||
// no need to perform full verification
|
||||
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- already pending reconstructed sig, signHash=%s, id=%s, msgHash=%s, node=%d\n", __func__,
|
||||
CLLMQUtils::BuildSignHash(*recoveredSig).ToString(), recoveredSig->id.ToString(), recoveredSig->msgHash.ToString(), pfrom->GetId());
|
||||
recoveredSig->buildSignHash().ToString(), recoveredSig->getId().ToString(), recoveredSig->getMsgHash().ToString(), pfrom->GetId());
|
||||
return;
|
||||
}
|
||||
pendingRecoveredSigs[pfrom->GetId()].emplace_back(recoveredSig);
|
||||
@ -616,17 +616,17 @@ bool CSigningManager::PreVerifyRecoveredSig(const CRecoveredSig& recoveredSig, b
|
||||
{
|
||||
retBan = false;
|
||||
|
||||
auto llmqType = recoveredSig.llmqType;
|
||||
auto llmqType = recoveredSig.getLlmqType();
|
||||
if (!Params().HasLLMQ(llmqType)) {
|
||||
retBan = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
CQuorumCPtr quorum = quorumManager->GetQuorum(llmqType, recoveredSig.quorumHash);
|
||||
CQuorumCPtr quorum = quorumManager->GetQuorum(llmqType, recoveredSig.getQuorumHash());
|
||||
|
||||
if (!quorum) {
|
||||
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- quorum %s not found\n", __func__,
|
||||
recoveredSig.quorumHash.ToString());
|
||||
recoveredSig.getQuorumHash().ToString());
|
||||
return false;
|
||||
}
|
||||
if (!CLLMQUtils::IsQuorumActive(llmqType, quorum->qc->quorumHash)) {
|
||||
@ -658,7 +658,7 @@ void CSigningManager::CollectPendingRecoveredSigsToVerify(
|
||||
|
||||
bool alreadyHave = db.HasRecoveredSigForHash(recSig->GetHash());
|
||||
if (!alreadyHave) {
|
||||
uniqueSignHashes.emplace(nodeId, CLLMQUtils::BuildSignHash(*recSig));
|
||||
uniqueSignHashes.emplace(nodeId, recSig->buildSignHash());
|
||||
retSigShares[nodeId].emplace_back(recSig);
|
||||
}
|
||||
ns.erase(ns.begin());
|
||||
@ -677,19 +677,19 @@ void CSigningManager::CollectPendingRecoveredSigsToVerify(
|
||||
for (auto it = v.begin(); it != v.end();) {
|
||||
const auto& recSig = *it;
|
||||
|
||||
auto llmqType = recSig->llmqType;
|
||||
auto quorumKey = std::make_pair(recSig->llmqType, recSig->quorumHash);
|
||||
auto llmqType = recSig->getLlmqType();
|
||||
auto quorumKey = std::make_pair(recSig->getLlmqType(), recSig->getQuorumHash());
|
||||
if (!retQuorums.count(quorumKey)) {
|
||||
CQuorumCPtr quorum = quorumManager->GetQuorum(llmqType, recSig->quorumHash);
|
||||
CQuorumCPtr quorum = quorumManager->GetQuorum(llmqType, recSig->getQuorumHash());
|
||||
if (!quorum) {
|
||||
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- quorum %s not found, node=%d\n", __func__,
|
||||
recSig->quorumHash.ToString(), nodeId);
|
||||
recSig->getQuorumHash().ToString(), nodeId);
|
||||
it = v.erase(it);
|
||||
continue;
|
||||
}
|
||||
if (!CLLMQUtils::IsQuorumActive(llmqType, quorum->qc->quorumHash)) {
|
||||
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- quorum %s not active anymore, node=%d\n", __func__,
|
||||
recSig->quorumHash.ToString(), nodeId);
|
||||
recSig->getQuorumHash().ToString(), nodeId);
|
||||
it = v.erase(it);
|
||||
continue;
|
||||
}
|
||||
@ -743,8 +743,8 @@ bool CSigningManager::ProcessPendingRecoveredSigs()
|
||||
break;
|
||||
}
|
||||
|
||||
const auto& quorum = quorums.at(std::make_pair(recSig->llmqType, recSig->quorumHash));
|
||||
batchVerifier.PushMessage(nodeId, recSig->GetHash(), CLLMQUtils::BuildSignHash(*recSig), recSig->sig.Get(), quorum->qc->quorumPublicKey);
|
||||
const auto& quorum = quorums.at(std::make_pair(recSig->getLlmqType(), recSig->getQuorumHash()));
|
||||
batchVerifier.PushMessage(nodeId, recSig->GetHash(), recSig->buildSignHash(), recSig->sig.Get(), quorum->qc->quorumPublicKey);
|
||||
verifyCount++;
|
||||
}
|
||||
}
|
||||
@ -782,7 +782,7 @@ bool CSigningManager::ProcessPendingRecoveredSigs()
|
||||
// signature must be verified already
|
||||
void CSigningManager::ProcessRecoveredSig(const std::shared_ptr<const CRecoveredSig>& recoveredSig)
|
||||
{
|
||||
auto llmqType = recoveredSig->llmqType;
|
||||
auto llmqType = recoveredSig->getLlmqType();
|
||||
|
||||
if (db.HasRecoveredSigForHash(recoveredSig->GetHash())) {
|
||||
return;
|
||||
@ -793,20 +793,20 @@ void CSigningManager::ProcessRecoveredSig(const std::shared_ptr<const CRecovered
|
||||
LOCK(cs);
|
||||
listeners = recoveredSigsListeners;
|
||||
|
||||
auto signHash = CLLMQUtils::BuildSignHash(*recoveredSig);
|
||||
auto signHash = recoveredSig->buildSignHash();
|
||||
|
||||
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- valid recSig. signHash=%s, id=%s, msgHash=%s\n", __func__,
|
||||
signHash.ToString(), recoveredSig->id.ToString(), recoveredSig->msgHash.ToString());
|
||||
signHash.ToString(), recoveredSig->getId().ToString(), recoveredSig->getMsgHash().ToString());
|
||||
|
||||
if (db.HasRecoveredSigForId(llmqType, recoveredSig->id)) {
|
||||
if (db.HasRecoveredSigForId(llmqType, recoveredSig->getId())) {
|
||||
CRecoveredSig otherRecoveredSig;
|
||||
if (db.GetRecoveredSigById(llmqType, recoveredSig->id, otherRecoveredSig)) {
|
||||
auto otherSignHash = CLLMQUtils::BuildSignHash(otherRecoveredSig);
|
||||
if (db.GetRecoveredSigById(llmqType, recoveredSig->getId(), otherRecoveredSig)) {
|
||||
auto otherSignHash = otherRecoveredSig.buildSignHash();
|
||||
if (signHash != otherSignHash) {
|
||||
// this should really not happen, as each masternode is participating in only one vote,
|
||||
// even if it's a member of multiple quorums. so a majority is only possible on one quorum and one msgHash per id
|
||||
LogPrintf("CSigningManager::%s -- conflicting recoveredSig for signHash=%s, id=%s, msgHash=%s, otherSignHash=%s\n", __func__,
|
||||
signHash.ToString(), recoveredSig->id.ToString(), recoveredSig->msgHash.ToString(), otherSignHash.ToString());
|
||||
signHash.ToString(), recoveredSig->getId().ToString(), recoveredSig->getMsgHash().ToString(), otherSignHash.ToString());
|
||||
} else {
|
||||
// Looks like we're trying to process a recSig that is already known. This might happen if the same
|
||||
// recSig comes in through regular QRECSIG messages and at the same time through some other message
|
||||
@ -1067,4 +1067,10 @@ bool CSigningManager::VerifyRecoveredSig(Consensus::LLMQType llmqType, int signe
|
||||
return sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash);
|
||||
}
|
||||
|
||||
uint256 CSigBase::buildSignHash() const
|
||||
{
|
||||
return CLLMQUtils::BuildSignHash(llmqType, quorumHash, id, msgHash);
|
||||
}
|
||||
|
||||
|
||||
} // namespace llmq
|
||||
|
@ -32,21 +32,49 @@ using CQuorumCPtr = std::shared_ptr<const CQuorum>;
|
||||
static constexpr int64_t DEFAULT_MAX_RECOVERED_SIGS_AGE{60 * 60 * 24 * 7};
|
||||
|
||||
|
||||
class CRecoveredSig
|
||||
class CSigBase
|
||||
{
|
||||
protected:
|
||||
Consensus::LLMQType llmqType{Consensus::LLMQType::LLMQ_NONE};
|
||||
uint256 quorumHash;
|
||||
uint256 id;
|
||||
uint256 msgHash;
|
||||
|
||||
CSigBase(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash)
|
||||
: llmqType(llmqType), quorumHash(quorumHash), id(id), msgHash(msgHash) {};
|
||||
CSigBase() = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] constexpr auto getLlmqType() const {
|
||||
return llmqType;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto getQuorumHash() const -> const uint256& {
|
||||
return quorumHash;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto getId() const -> const uint256& {
|
||||
return id;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto getMsgHash() const -> const uint256& {
|
||||
return msgHash;
|
||||
}
|
||||
|
||||
[[nodiscard]] uint256 buildSignHash() const;
|
||||
};
|
||||
|
||||
class CRecoveredSig : virtual public CSigBase
|
||||
{
|
||||
public:
|
||||
const Consensus::LLMQType llmqType{Consensus::LLMQType::LLMQ_NONE};
|
||||
const uint256 quorumHash;
|
||||
const uint256 id;
|
||||
const uint256 msgHash;
|
||||
const CBLSLazySignature sig;
|
||||
|
||||
CRecoveredSig() = default;
|
||||
|
||||
CRecoveredSig(Consensus::LLMQType _llmqType, const uint256& _quorumHash, const uint256& _id, const uint256& _msgHash, const CBLSLazySignature& _sig) :
|
||||
llmqType(_llmqType), quorumHash(_quorumHash), id(_id), msgHash(_msgHash), sig(_sig) {UpdateHash();};
|
||||
CSigBase(_llmqType, _quorumHash, _id, _msgHash), sig(_sig) {UpdateHash();};
|
||||
CRecoveredSig(Consensus::LLMQType _llmqType, const uint256& _quorumHash, const uint256& _id, const uint256& _msgHash, const CBLSSignature& _sig) :
|
||||
llmqType(_llmqType), quorumHash(_quorumHash), id(_id), msgHash(_msgHash) {const_cast<CBLSLazySignature&>(sig).Set(_sig); UpdateHash();};
|
||||
CSigBase(_llmqType, _quorumHash, _id, _msgHash) {const_cast<CBLSLazySignature&>(sig).Set(_sig); UpdateHash();};
|
||||
|
||||
private:
|
||||
// only in-memory
|
||||
|
@ -26,14 +26,14 @@ CSigSharesManager* quorumSigSharesManager = nullptr;
|
||||
|
||||
void CSigShare::UpdateKey()
|
||||
{
|
||||
key.first = CLLMQUtils::BuildSignHash(*this);
|
||||
key.first = this->buildSignHash();
|
||||
key.second = quorumMember;
|
||||
}
|
||||
|
||||
std::string CSigSesAnn::ToString() const
|
||||
{
|
||||
return strprintf("sessionId=%d, llmqType=%d, quorumHash=%s, id=%s, msgHash=%s",
|
||||
sessionId, static_cast<uint8_t>(llmqType), quorumHash.ToString(), id.ToString(), msgHash.ToString());
|
||||
sessionId, static_cast<uint8_t>(getLlmqType()), getQuorumHash().ToString(), getId().ToString(), getMsgHash().ToString());
|
||||
}
|
||||
|
||||
void CSigSharesInv::Merge(const CSigSharesInv& inv2)
|
||||
@ -102,15 +102,14 @@ std::string CBatchedSigShares::ToInvString() const
|
||||
return inv.ToString();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void InitSession(CSigSharesNodeState::Session& s, const uint256& signHash, T& from)
|
||||
static void InitSession(CSigSharesNodeState::Session& s, const uint256& signHash, CSigBase from)
|
||||
{
|
||||
const auto& llmq_params = GetLLMQParams((Consensus::LLMQType)from.llmqType);
|
||||
const auto& llmq_params = GetLLMQParams((Consensus::LLMQType)from.getLlmqType());
|
||||
|
||||
s.llmqType = (Consensus::LLMQType)from.llmqType;
|
||||
s.quorumHash = from.quorumHash;
|
||||
s.id = from.id;
|
||||
s.msgHash = from.msgHash;
|
||||
s.llmqType = from.getLlmqType();
|
||||
s.quorumHash = from.getQuorumHash();
|
||||
s.id = from.getId();
|
||||
s.msgHash = from.getMsgHash();
|
||||
s.signHash = signHash;
|
||||
s.announced.Init((size_t)llmq_params.size);
|
||||
s.requested.Init((size_t)llmq_params.size);
|
||||
@ -128,7 +127,7 @@ CSigSharesNodeState::Session& CSigSharesNodeState::GetOrCreateSessionFromShare(c
|
||||
|
||||
CSigSharesNodeState::Session& CSigSharesNodeState::GetOrCreateSessionFromAnn(const llmq::CSigSesAnn& ann)
|
||||
{
|
||||
auto signHash = CLLMQUtils::BuildSignHash(ann.llmqType, ann.quorumHash, ann.id, ann.msgHash);
|
||||
auto signHash = ann.buildSignHash();
|
||||
auto& s = sessions[signHash];
|
||||
if (s.announced.inv.empty()) {
|
||||
InitSession(s, signHash, ann);
|
||||
@ -304,21 +303,21 @@ void CSigSharesManager::ProcessMessage(const CNode* pfrom, const std::string& ms
|
||||
|
||||
bool CSigSharesManager::ProcessMessageSigSesAnn(const CNode* pfrom, const CSigSesAnn& ann)
|
||||
{
|
||||
auto llmqType = ann.llmqType;
|
||||
auto llmqType = ann.getLlmqType();
|
||||
if (!Params().HasLLMQ(llmqType)) {
|
||||
return false;
|
||||
}
|
||||
if (ann.sessionId == UNINITIALIZED_SESSION_ID || ann.quorumHash.IsNull() || ann.id.IsNull() || ann.msgHash.IsNull()) {
|
||||
if (ann.getSessionId() == UNINITIALIZED_SESSION_ID || ann.getQuorumHash().IsNull() || ann.getId().IsNull() || ann.getMsgHash().IsNull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- ann={%s}, node=%d\n", __func__, ann.ToString(), pfrom->GetId());
|
||||
|
||||
auto quorum = quorumManager->GetQuorum(llmqType, ann.quorumHash);
|
||||
auto quorum = quorumManager->GetQuorum(llmqType, ann.getQuorumHash());
|
||||
if (!quorum) {
|
||||
// TODO should we ban here?
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- quorum %s not found, node=%d\n", __func__,
|
||||
ann.quorumHash.ToString(), pfrom->GetId());
|
||||
ann.getQuorumHash().ToString(), pfrom->GetId());
|
||||
return true; // let's still try other announcements from the same message
|
||||
}
|
||||
|
||||
@ -326,10 +325,10 @@ bool CSigSharesManager::ProcessMessageSigSesAnn(const CNode* pfrom, const CSigSe
|
||||
auto& nodeState = nodeStates[pfrom->GetId()];
|
||||
auto& session = nodeState.GetOrCreateSessionFromAnn(ann);
|
||||
nodeState.sessionByRecvId.erase(session.recvSessionId);
|
||||
nodeState.sessionByRecvId.erase(ann.sessionId);
|
||||
session.recvSessionId = ann.sessionId;
|
||||
nodeState.sessionByRecvId.erase(ann.getSessionId());
|
||||
session.recvSessionId = ann.getSessionId();
|
||||
session.quorum = quorum;
|
||||
nodeState.sessionByRecvId.try_emplace(ann.sessionId, &session);
|
||||
nodeState.sessionByRecvId.try_emplace(ann.getSessionId(), &session);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -437,7 +436,7 @@ bool CSigSharesManager::ProcessMessageBatchedSigShares(const CNode* pfrom, const
|
||||
}
|
||||
|
||||
// TODO for PoSe, we should consider propagating shares even if we already have a recovered sig
|
||||
if (quorumSigningManager->HasRecoveredSigForId(sigShare.llmqType, sigShare.id)) {
|
||||
if (quorumSigningManager->HasRecoveredSigForId(sigShare.getLlmqType(), sigShare.getId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -462,11 +461,11 @@ bool CSigSharesManager::ProcessMessageBatchedSigShares(const CNode* pfrom, const
|
||||
|
||||
void CSigSharesManager::ProcessMessageSigShare(NodeId fromId, const CSigShare& sigShare)
|
||||
{
|
||||
auto quorum = quorumManager->GetQuorum(sigShare.llmqType, sigShare.quorumHash);
|
||||
auto quorum = quorumManager->GetQuorum(sigShare.getLlmqType(), sigShare.getQuorumHash());
|
||||
if (!quorum) {
|
||||
return;
|
||||
}
|
||||
if (!CLLMQUtils::IsQuorumActive(sigShare.llmqType, quorum->qc->quorumHash)) {
|
||||
if (!CLLMQUtils::IsQuorumActive(sigShare.getLlmqType(), quorum->qc->quorumHash)) {
|
||||
// quorum is too old
|
||||
return;
|
||||
}
|
||||
@ -481,12 +480,12 @@ void CSigSharesManager::ProcessMessageSigShare(NodeId fromId, const CSigShare& s
|
||||
return;
|
||||
}
|
||||
|
||||
if (sigShare.quorumMember >= quorum->members.size()) {
|
||||
if (sigShare.getQuorumMember() >= quorum->members.size()) {
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- quorumMember out of bounds\n", __func__);
|
||||
BanNode(fromId);
|
||||
return;
|
||||
}
|
||||
if (!quorum->qc->validMembers[sigShare.quorumMember]) {
|
||||
if (!quorum->qc->validMembers[sigShare.getQuorumMember()]) {
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- quorumMember not valid\n", __func__);
|
||||
BanNode(fromId);
|
||||
return;
|
||||
@ -499,7 +498,7 @@ void CSigSharesManager::ProcessMessageSigShare(NodeId fromId, const CSigShare& s
|
||||
return;
|
||||
}
|
||||
|
||||
if (quorumSigningManager->HasRecoveredSigForId(sigShare.llmqType, sigShare.id)) {
|
||||
if (quorumSigningManager->HasRecoveredSigForId(sigShare.getLlmqType(), sigShare.getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -508,7 +507,7 @@ void CSigSharesManager::ProcessMessageSigShare(NodeId fromId, const CSigShare& s
|
||||
}
|
||||
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- signHash=%s, id=%s, msgHash=%s, member=%d, node=%d\n", __func__,
|
||||
sigShare.GetSignHash().ToString(), sigShare.id.ToString(), sigShare.msgHash.ToString(), sigShare.quorumMember, fromId);
|
||||
sigShare.GetSignHash().ToString(), sigShare.getId().ToString(), sigShare.getMsgHash().ToString(), sigShare.getQuorumMember(), fromId);
|
||||
}
|
||||
|
||||
bool CSigSharesManager::PreVerifyBatchedSigShares(const CSigSharesNodeState::SessionInfo& session, const CBatchedSigShares& batchedSigShares, bool& retBan)
|
||||
@ -596,14 +595,14 @@ void CSigSharesManager::CollectPendingSigSharesToVerify(
|
||||
|
||||
for (const auto& [_, vecSigShares] : retSigShares) {
|
||||
for (const auto& sigShare : vecSigShares) {
|
||||
auto llmqType = sigShare.llmqType;
|
||||
auto llmqType = sigShare.getLlmqType();
|
||||
|
||||
auto k = std::make_pair(llmqType, sigShare.quorumHash);
|
||||
auto k = std::make_pair(llmqType, sigShare.getQuorumHash());
|
||||
if (retQuorums.count(k)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CQuorumCPtr quorum = quorumManager->GetQuorum(llmqType, sigShare.quorumHash);
|
||||
CQuorumCPtr quorum = quorumManager->GetQuorum(llmqType, sigShare.getQuorumHash());
|
||||
assert(quorum != nullptr);
|
||||
retQuorums.try_emplace(k, quorum);
|
||||
}
|
||||
@ -629,7 +628,7 @@ bool CSigSharesManager::ProcessPendingSigShares(const CConnman& connman)
|
||||
size_t verifyCount = 0;
|
||||
for (const auto& [nodeId, v] : sigSharesByNodes) {
|
||||
for (const auto& sigShare : v) {
|
||||
if (quorumSigningManager->HasRecoveredSigForId(sigShare.llmqType, sigShare.id)) {
|
||||
if (quorumSigningManager->HasRecoveredSigForId(sigShare.getLlmqType(), sigShare.getId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -641,8 +640,8 @@ bool CSigSharesManager::ProcessPendingSigShares(const CConnman& connman)
|
||||
break;
|
||||
}
|
||||
|
||||
auto quorum = quorums.at(std::make_pair(sigShare.llmqType, sigShare.quorumHash));
|
||||
auto pubKeyShare = quorum->GetPubKeyShare(sigShare.quorumMember);
|
||||
auto quorum = quorums.at(std::make_pair(sigShare.getLlmqType(), sigShare.getQuorumHash()));
|
||||
auto pubKeyShare = quorum->GetPubKeyShare(sigShare.getQuorumMember());
|
||||
|
||||
if (!pubKeyShare.IsValid()) {
|
||||
// this should really not happen (we already ensured we have the quorum vvec,
|
||||
@ -685,7 +684,7 @@ void CSigSharesManager::ProcessPendingSigShares(const std::vector<CSigShare>& si
|
||||
{
|
||||
cxxtimer::Timer t(true);
|
||||
for (auto& sigShare : sigSharesToProcess) {
|
||||
auto quorumKey = std::make_pair(sigShare.llmqType, sigShare.quorumHash);
|
||||
auto quorumKey = std::make_pair(sigShare.getLlmqType(), sigShare.getQuorumHash());
|
||||
ProcessSigShare(sigShare, connman, quorums.at(quorumKey));
|
||||
}
|
||||
t.stop();
|
||||
@ -703,11 +702,11 @@ void CSigSharesManager::ProcessSigShare(const CSigShare& sigShare, const CConnma
|
||||
|
||||
// prepare node set for direct-push in case this is our sig share
|
||||
std::set<NodeId> quorumNodes;
|
||||
if (!CLLMQUtils::IsAllMembersConnectedEnabled(llmqType) && sigShare.quorumMember == quorum->GetMemberIndex(WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) {
|
||||
quorumNodes = connman.GetMasternodeQuorumNodes(sigShare.llmqType, sigShare.quorumHash);
|
||||
if (!CLLMQUtils::IsAllMembersConnectedEnabled(llmqType) && sigShare.getQuorumMember() == quorum->GetMemberIndex(WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) {
|
||||
quorumNodes = connman.GetMasternodeQuorumNodes(sigShare.getLlmqType(), sigShare.getQuorumHash());
|
||||
}
|
||||
|
||||
if (quorumSigningManager->HasRecoveredSigForId(llmqType, sigShare.id)) {
|
||||
if (quorumSigningManager->HasRecoveredSigForId(llmqType, sigShare.getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -731,8 +730,8 @@ void CSigSharesManager::ProcessSigShare(const CSigShare& sigShare, const CConnma
|
||||
auto& nodeState = nodeStates[otherNodeId];
|
||||
auto& session = nodeState.GetOrCreateSessionFromShare(sigShare);
|
||||
session.quorum = quorum;
|
||||
session.requested.Set(sigShare.quorumMember, true);
|
||||
session.knows.Set(sigShare.quorumMember, true);
|
||||
session.requested.Set(sigShare.getQuorumMember(), true);
|
||||
session.knows.Set(sigShare.getQuorumMember(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -743,7 +742,7 @@ void CSigSharesManager::ProcessSigShare(const CSigShare& sigShare, const CConnma
|
||||
}
|
||||
|
||||
if (canTryRecovery) {
|
||||
TryRecoverSig(quorum, sigShare.id, sigShare.msgHash);
|
||||
TryRecoverSig(quorum, sigShare.getId(), sigShare.getMsgHash());
|
||||
}
|
||||
}
|
||||
|
||||
@ -769,7 +768,7 @@ void CSigSharesManager::TryRecoverSig(const CQuorumCPtr& quorum, const uint256&
|
||||
for (auto it = sigSharesForSignHash->begin(); it != sigSharesForSignHash->end() && sigSharesForRecovery.size() < size_t(quorum->params.threshold); ++it) {
|
||||
auto& sigShare = it->second;
|
||||
sigSharesForRecovery.emplace_back(sigShare.sigShare.Get());
|
||||
idsForRecovery.emplace_back(quorum->members[sigShare.quorumMember]->proTxHash);
|
||||
idsForRecovery.emplace_back(quorum->members[sigShare.getQuorumMember()]->proTxHash);
|
||||
}
|
||||
|
||||
// check if we can recover the final signature
|
||||
@ -796,7 +795,7 @@ void CSigSharesManager::TryRecoverSig(const CQuorumCPtr& quorum, const uint256&
|
||||
// however still verify it from time to time, so that we have a chance to catch bugs. We do only this sporadic
|
||||
// verification because this is unbatched and thus slow verification that happens here.
|
||||
if (((recoveredSigsCounter++) % 100) == 0) {
|
||||
auto signHash = CLLMQUtils::BuildSignHash(*rs);
|
||||
auto signHash = rs->buildSignHash();
|
||||
bool valid = recoveredSig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash);
|
||||
if (!valid) {
|
||||
// this should really not happen as we have verified all signature shares before
|
||||
@ -963,7 +962,7 @@ void CSigSharesManager::CollectSigSharesToSend(std::unordered_map<NodeId, std::u
|
||||
// only create the map if we actually add a batched sig
|
||||
sigSharesToSend2 = &sigSharesToSend[nodeId];
|
||||
}
|
||||
(*sigSharesToSend2).try_emplace(signHash, std::move(batchedSigShares));
|
||||
sigSharesToSend2->try_emplace(signHash, std::move(batchedSigShares));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -997,7 +996,7 @@ void CSigSharesManager::CollectSigSharesToSendConcentrated(std::unordered_map<No
|
||||
int64_t waitTime = exp2(signedSession.attempt) * EXP_SEND_FOR_RECOVERY_TIMEOUT;
|
||||
waitTime = std::min(MAX_SEND_FOR_RECOVERY_TIMEOUT, waitTime);
|
||||
signedSession.nextAttemptTime = curTime + waitTime;
|
||||
auto dmn = SelectMemberForRecovery(signedSession.quorum, signedSession.sigShare.id, signedSession.attempt);
|
||||
auto dmn = SelectMemberForRecovery(signedSession.quorum, signedSession.sigShare.getId(), signedSession.attempt);
|
||||
signedSession.attempt++;
|
||||
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- signHash=%s, sending to %s, attempt=%d\n", __func__,
|
||||
@ -1030,7 +1029,7 @@ void CSigSharesManager::CollectSigSharesToAnnounce(std::unordered_map<NodeId, st
|
||||
}
|
||||
|
||||
// announce to the nodes which we know through the intra-quorum-communication system
|
||||
auto quorumKey = std::make_pair(sigShare->llmqType, sigShare->quorumHash);
|
||||
auto quorumKey = std::make_pair(sigShare->getLlmqType(), sigShare->getQuorumHash());
|
||||
auto it = quorumNodesMap.find(quorumKey);
|
||||
if (it == quorumNodesMap.end()) {
|
||||
auto nodeIds = connman.GetMasternodeQuorumNodes(quorumKey.first, quorumKey.second);
|
||||
@ -1055,7 +1054,7 @@ void CSigSharesManager::CollectSigSharesToAnnounce(std::unordered_map<NodeId, st
|
||||
|
||||
auto& inv = sigSharesToAnnounce[nodeId][signHash];
|
||||
if (inv.inv.empty()) {
|
||||
inv.Init(GetLLMQParams(sigShare->llmqType).size);
|
||||
inv.Init(GetLLMQParams(sigShare->getLlmqType()).size);
|
||||
}
|
||||
inv.inv[quorumMember] = true;
|
||||
session.knows.inv[quorumMember] = true;
|
||||
@ -1082,14 +1081,10 @@ bool CSigSharesManager::SendMessages()
|
||||
if (session->sendSessionId == UNINITIALIZED_SESSION_ID) {
|
||||
session->sendSessionId = nodeState.nextSendSessionId++;
|
||||
|
||||
CSigSesAnn sigSesAnn;
|
||||
sigSesAnn.sessionId = session->sendSessionId;
|
||||
sigSesAnn.llmqType = session->llmqType;
|
||||
sigSesAnn.quorumHash = session->quorumHash;
|
||||
sigSesAnn.id = session->id;
|
||||
sigSesAnn.msgHash = session->msgHash;
|
||||
|
||||
sigSessionAnnouncements[nodeId].emplace_back(sigSesAnn);
|
||||
sigSessionAnnouncements[nodeId].emplace_back(
|
||||
CSigSesAnn(/*sessionId=*/session->sendSessionId, /*llmqType=*/session->llmqType,
|
||||
/*quorumHash=*/session->quorumHash, /*id=*/session->id, /*msgHash=*/session->msgHash)
|
||||
);
|
||||
}
|
||||
return session->sendSessionId;
|
||||
};
|
||||
@ -1130,7 +1125,7 @@ bool CSigSharesManager::SendMessages()
|
||||
msgs.reserve(it1->second.size());
|
||||
for (auto& sigSesAnn : it1->second) {
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::SendMessages -- QSIGSESANN signHash=%s, sessionId=%d, node=%d\n",
|
||||
CLLMQUtils::BuildSignHash(sigSesAnn).ToString(), sigSesAnn.sessionId, pnode->GetId());
|
||||
sigSesAnn.buildSignHash().ToString(), sigSesAnn.getSessionId(), pnode->GetId());
|
||||
msgs.emplace_back(sigSesAnn);
|
||||
if (msgs.size() == MAX_MSGS_CNT_QSIGSESANN) {
|
||||
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSESANN, msgs));
|
||||
@ -1240,13 +1235,7 @@ bool CSigSharesManager::GetSessionInfoByRecvId(NodeId nodeId, uint32_t sessionId
|
||||
CSigShare CSigSharesManager::RebuildSigShare(const CSigSharesNodeState::SessionInfo& session, const std::pair<uint16_t, CBLSLazySignature>& in)
|
||||
{
|
||||
const auto& [member, sig] = in;
|
||||
CSigShare sigShare;
|
||||
sigShare.llmqType = session.llmqType;
|
||||
sigShare.quorumHash = session.quorumHash;
|
||||
sigShare.quorumMember = member;
|
||||
sigShare.id = session.id;
|
||||
sigShare.msgHash = session.msgHash;
|
||||
sigShare.sigShare = sig;
|
||||
CSigShare sigShare(session.llmqType, session.quorumHash, session.id, session.msgHash, member, sig);
|
||||
sigShare.UpdateKey();
|
||||
return sigShare;
|
||||
}
|
||||
@ -1267,7 +1256,7 @@ void CSigSharesManager::Cleanup()
|
||||
{
|
||||
LOCK(cs);
|
||||
sigShares.ForEach([&quorums](const SigShareKey&, const CSigShare& sigShare) {
|
||||
quorums.try_emplace(std::make_pair(sigShare.llmqType, sigShare.quorumHash), nullptr);
|
||||
quorums.try_emplace(std::make_pair(sigShare.getLlmqType(), sigShare.getQuorumHash()), nullptr);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1286,7 +1275,7 @@ void CSigSharesManager::Cleanup()
|
||||
LOCK(cs);
|
||||
std::unordered_set<uint256, StaticSaltedHasher> inactiveQuorumSessions;
|
||||
sigShares.ForEach([&quorums, &inactiveQuorumSessions](const SigShareKey&, const CSigShare& sigShare) {
|
||||
if (!quorums.count(std::make_pair(sigShare.llmqType, sigShare.quorumHash))) {
|
||||
if (!quorums.count(std::make_pair(sigShare.getLlmqType(), sigShare.getQuorumHash()))) {
|
||||
inactiveQuorumSessions.emplace(sigShare.GetSignHash());
|
||||
}
|
||||
});
|
||||
@ -1329,7 +1318,7 @@ void CSigSharesManager::Cleanup()
|
||||
|
||||
std::string strMissingMembers;
|
||||
if (LogAcceptCategory(BCLog::LLMQ_SIGS)) {
|
||||
if (const auto quorumIt = quorums.find(std::make_pair(oneSigShare.llmqType, oneSigShare.quorumHash)); quorumIt != quorums.end()) {
|
||||
if (const auto quorumIt = quorums.find(std::make_pair(oneSigShare.getLlmqType(), oneSigShare.getQuorumHash())); quorumIt != quorums.end()) {
|
||||
const auto& quorum = quorumIt->second;
|
||||
for (size_t i = 0; i < quorum->members.size(); i++) {
|
||||
if (!m->count((uint16_t)i)) {
|
||||
@ -1341,7 +1330,7 @@ void CSigSharesManager::Cleanup()
|
||||
}
|
||||
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- signing session timed out. signHash=%s, id=%s, msgHash=%s, sigShareCount=%d, missingMembers=%s\n", __func__,
|
||||
signHash.ToString(), oneSigShare.id.ToString(), oneSigShare.msgHash.ToString(), count, strMissingMembers);
|
||||
signHash.ToString(), oneSigShare.getId().ToString(), oneSigShare.getMsgHash().ToString(), count, strMissingMembers);
|
||||
} else {
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- signing session timed out. signHash=%s, sigShareCount=%d\n", __func__,
|
||||
signHash.ToString(), count);
|
||||
@ -1491,10 +1480,10 @@ void CSigSharesManager::SignPendingSigShares()
|
||||
}
|
||||
|
||||
for (const auto& [pQuorum, id, msgHash] : v) {
|
||||
CSigShare sigShare = CreateSigShare(pQuorum, id, msgHash);
|
||||
|
||||
if (sigShare.sigShare.Get().IsValid()) {
|
||||
auto opt_sigShare = CreateSigShare(pQuorum, id, msgHash);
|
||||
|
||||
if (opt_sigShare.has_value() && opt_sigShare->sigShare.Get().IsValid()) {
|
||||
auto sigShare = *opt_sigShare;
|
||||
ProcessSigShare(sigShare, connman, pQuorum);
|
||||
|
||||
if (CLLMQUtils::IsAllMembersConnectedEnabled(pQuorum->params.type)) {
|
||||
@ -1509,46 +1498,41 @@ void CSigSharesManager::SignPendingSigShares()
|
||||
}
|
||||
}
|
||||
|
||||
CSigShare CSigSharesManager::CreateSigShare(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash) const
|
||||
std::optional<CSigShare> CSigSharesManager::CreateSigShare(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash) const
|
||||
{
|
||||
cxxtimer::Timer t(true);
|
||||
auto activeMasterNodeProTxHash = WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash);
|
||||
|
||||
if (!quorum->IsValidMember(activeMasterNodeProTxHash)) {
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const CBLSSecretKey& skShare = quorum->GetSkShare();
|
||||
if (!skShare.IsValid()) {
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- we don't have our skShare for quorum %s\n", __func__, quorum->qc->quorumHash.ToString());
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
int memberIdx = quorum->GetMemberIndex(activeMasterNodeProTxHash);
|
||||
if (memberIdx == -1) {
|
||||
// this should really not happen (IsValidMember gave true)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
CSigShare sigShare;
|
||||
sigShare.llmqType = quorum->params.type;
|
||||
sigShare.quorumHash = quorum->qc->quorumHash;
|
||||
sigShare.id = id;
|
||||
sigShare.msgHash = msgHash;
|
||||
sigShare.quorumMember = (uint16_t)memberIdx;
|
||||
uint256 signHash = CLLMQUtils::BuildSignHash(sigShare);
|
||||
CSigShare sigShare(quorum->params.type, quorum->qc->quorumHash, id, msgHash, uint16_t(memberIdx), {});
|
||||
uint256 signHash = sigShare.buildSignHash();
|
||||
|
||||
sigShare.sigShare.Set(skShare.Sign(signHash));
|
||||
if (!sigShare.sigShare.Get().IsValid()) {
|
||||
LogPrintf("CSigSharesManager::%s -- failed to sign sigShare. signHash=%s, id=%s, msgHash=%s, time=%s\n", __func__,
|
||||
signHash.ToString(), sigShare.id.ToString(), sigShare.msgHash.ToString(), t.count());
|
||||
return {};
|
||||
signHash.ToString(), sigShare.getId().ToString(), sigShare.getMsgHash().ToString(), t.count());
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
sigShare.UpdateKey();
|
||||
|
||||
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- created sigShare. signHash=%s, id=%s, msgHash=%s, llmqType=%d, quorum=%s, time=%s\n", __func__,
|
||||
signHash.ToString(), sigShare.id.ToString(), sigShare.msgHash.ToString(), static_cast<uint8_t>(quorum->params.type), quorum->qc->quorumHash.ToString(), t.count());
|
||||
signHash.ToString(), sigShare.getId().ToString(), sigShare.getMsgHash().ToString(), static_cast<uint8_t>(quorum->params.type), quorum->qc->quorumHash.ToString(), t.count());
|
||||
|
||||
return sigShare;
|
||||
}
|
||||
@ -1583,7 +1567,7 @@ void CSigSharesManager::ForceReAnnouncement(const CQuorumCPtr& quorum, Consensus
|
||||
void CSigSharesManager::HandleNewRecoveredSig(const llmq::CRecoveredSig& recoveredSig)
|
||||
{
|
||||
LOCK(cs);
|
||||
RemoveSigSharesForSession(CLLMQUtils::BuildSignHash(recoveredSig));
|
||||
RemoveSigSharesForSession(recoveredSig.buildSignHash());
|
||||
}
|
||||
|
||||
} // namespace llmq
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <sync.h>
|
||||
#include <uint256.h>
|
||||
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
@ -31,18 +32,29 @@ using SigShareKey = std::pair<uint256, uint16_t>;
|
||||
|
||||
constexpr uint32_t UNINITIALIZED_SESSION_ID{std::numeric_limits<uint32_t>::max()};
|
||||
|
||||
class CSigShare
|
||||
class CSigShare : virtual public CSigBase
|
||||
{
|
||||
public:
|
||||
Consensus::LLMQType llmqType;
|
||||
uint256 quorumHash;
|
||||
protected:
|
||||
uint16_t quorumMember;
|
||||
uint256 id;
|
||||
uint256 msgHash;
|
||||
public:
|
||||
CBLSLazySignature sigShare;
|
||||
|
||||
SigShareKey key;
|
||||
|
||||
[[nodiscard]] auto getQuorumMember() const {
|
||||
return quorumMember;
|
||||
}
|
||||
|
||||
CSigShare(Consensus::LLMQType llmqType, const uint256 &quorumHash, const uint256 &id, const uint256 &msgHash,
|
||||
uint16_t quorumMember, const CBLSLazySignature &sigShare) :
|
||||
CSigBase(llmqType, quorumHash, id, msgHash),
|
||||
quorumMember(quorumMember),
|
||||
sigShare(sigShare) {};
|
||||
|
||||
// This should only be used for serialization
|
||||
CSigShare() = default;
|
||||
|
||||
|
||||
public:
|
||||
void UpdateKey();
|
||||
const SigShareKey& GetKey() const
|
||||
@ -65,14 +77,22 @@ public:
|
||||
// Nodes will first announce a signing session with a sessionId to be used in all future P2P messages related to that
|
||||
// session. We locally keep track of the mapping for each node. We also assign new sessionIds for outgoing sessions
|
||||
// and send QSIGSESANN messages appropriately. All values except the max value for uint32_t are valid as sessionId
|
||||
class CSigSesAnn
|
||||
class CSigSesAnn : virtual public CSigBase
|
||||
{
|
||||
public:
|
||||
private:
|
||||
uint32_t sessionId{UNINITIALIZED_SESSION_ID};
|
||||
Consensus::LLMQType llmqType{Consensus::LLMQType::LLMQ_NONE};
|
||||
uint256 quorumHash;
|
||||
uint256 id;
|
||||
uint256 msgHash;
|
||||
|
||||
public:
|
||||
CSigSesAnn(uint32_t sessionId, Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id,
|
||||
const uint256& msgHash) : CSigBase(llmqType, quorumHash, id, msgHash), sessionId(sessionId) {};
|
||||
// ONLY FOR SERIALIZATION
|
||||
CSigSesAnn() = default;
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] auto getSessionId() const {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
SERIALIZE_METHODS(CSigSesAnn, obj)
|
||||
{
|
||||
@ -395,7 +415,7 @@ public:
|
||||
void ProcessMessage(const CNode* pnode, const std::string& msg_type, CDataStream& vRecv);
|
||||
|
||||
void AsyncSign(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash);
|
||||
CSigShare CreateSigShare(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash) const;
|
||||
std::optional<CSigShare> CreateSigShare(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash) const;
|
||||
void ForceReAnnouncement(const CQuorumCPtr& quorum, Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash);
|
||||
|
||||
void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override;
|
||||
|
@ -70,13 +70,6 @@ public:
|
||||
static uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash);
|
||||
static uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash);
|
||||
|
||||
// works for sig shares and recovered sigs
|
||||
template<typename T>
|
||||
static uint256 BuildSignHash(const T& s)
|
||||
{
|
||||
return BuildSignHash((Consensus::LLMQType)s.llmqType, s.quorumHash, s.id, s.msgHash);
|
||||
}
|
||||
|
||||
static bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType);
|
||||
static bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType);
|
||||
static uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2);
|
||||
|
@ -461,20 +461,20 @@ static UniValue quorum_sigs_cmd(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "quorum not found");
|
||||
}
|
||||
|
||||
llmq::CSigShare sigShare = llmq::quorumSigSharesManager->CreateSigShare(pQuorum, id, msgHash);
|
||||
auto sigShare = llmq::quorumSigSharesManager->CreateSigShare(pQuorum, id, msgHash);
|
||||
|
||||
if (!sigShare.sigShare.Get().IsValid()) {
|
||||
if (!sigShare.has_value() || !sigShare->sigShare.Get().IsValid()) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "failed to create sigShare");
|
||||
}
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.pushKV("llmqType", static_cast<uint8_t>(llmqType));
|
||||
obj.pushKV("quorumHash", sigShare.quorumHash.ToString());
|
||||
obj.pushKV("quorumMember", sigShare.quorumMember);
|
||||
obj.pushKV("quorumHash", sigShare->getQuorumHash().ToString());
|
||||
obj.pushKV("quorumMember", sigShare->getQuorumMember());
|
||||
obj.pushKV("id", id.ToString());
|
||||
obj.pushKV("msgHash", msgHash.ToString());
|
||||
obj.pushKV("signHash", sigShare.GetSignHash().ToString());
|
||||
obj.pushKV("signature", sigShare.sigShare.Get().ToString());
|
||||
obj.pushKV("signHash", sigShare->GetSignHash().ToString());
|
||||
obj.pushKV("signature", sigShare->sigShare.Get().ToString());
|
||||
|
||||
return obj;
|
||||
}
|
||||
@ -511,7 +511,7 @@ static UniValue quorum_sigs_cmd(const JSONRPCRequest& request)
|
||||
if (!llmq::quorumSigningManager->GetRecoveredSigForId(llmqType, id, recSig)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "recovered signature not found");
|
||||
}
|
||||
if (recSig.msgHash != msgHash) {
|
||||
if (recSig.getMsgHash() != msgHash) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "recovered signature not found");
|
||||
}
|
||||
return recSig.ToJson();
|
||||
|
@ -269,10 +269,10 @@ bool CZMQPublishHashInstantSendDoubleSpendNotifier::NotifyInstantSendDoubleSpend
|
||||
|
||||
bool CZMQPublishHashRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> &sig)
|
||||
{
|
||||
LogPrint(BCLog::ZMQ, "zmq: Publish hashrecoveredsig %s\n", sig->msgHash.ToString());
|
||||
LogPrint(BCLog::ZMQ, "zmq: Publish hashrecoveredsig %s\n", sig->getMsgHash().ToString());
|
||||
char data[32];
|
||||
for (unsigned int i = 0; i < 32; i++)
|
||||
data[31 - i] = sig->msgHash.begin()[i];
|
||||
data[31 - i] = sig->getMsgHash().begin()[i];
|
||||
return SendZmqMessage(MSG_HASHRECSIG, data, 32);
|
||||
}
|
||||
|
||||
@ -398,7 +398,7 @@ bool CZMQPublishRawInstantSendDoubleSpendNotifier::NotifyInstantSendDoubleSpendA
|
||||
|
||||
bool CZMQPublishRawRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig)
|
||||
{
|
||||
LogPrint(BCLog::ZMQ, "zmq: Publish rawrecoveredsig %s\n", sig->msgHash.ToString());
|
||||
LogPrint(BCLog::ZMQ, "zmq: Publish rawrecoveredsig %s\n", sig->getMsgHash().ToString());
|
||||
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << *sig;
|
||||
|
Loading…
Reference in New Issue
Block a user