Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dash backports #2956

Merged
merged 6 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/bls/bls_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ void CBLSWorker::Start()
int workerCount = GetNumCores() / 2;
workerCount = std::max(std::min(1, workerCount), 4);
workerPool.resize(workerCount);

RenameThreadPool(workerPool, "pivx-bls-worker");
RenameThreadPool(workerPool, "pivx-bls-work");
}

void CBLSWorker::Stop()
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct LLMQParams {
// Number of quorums to consider "active" for signing sessions
int signingActiveQuorumCount;

// Used for inter-quorum communication. This is the number of quorums for which we should keep old connections. This
// Used for intra-quorum communication. This is the number of quorums for which we should keep old connections. This
// should be at least one more then the active quorums set.
int keepOldConnections;

Expand Down
1 change: 1 addition & 0 deletions src/evo/evodb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void CEvoDB::RollbackCurTransaction()

bool CEvoDB::CommitRootTransaction()
{
LOCK(cs);
assert(curDBTransaction.IsClean());
rootDBTransaction.Commit();
bool ret = db.WriteBatch(rootBatch);
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ typedef std::shared_ptr<const CQuorum> CQuorumCPtr;
* The quorum manager maintains quorums which were mined on chain. When a quorum is requested from the manager,
* it will lookup the commitment (through CQuorumBlockProcessor) and build a CQuorum object from it.
*
* It is also responsible for initialization of the inter-quorum connections for new quorums.
* It is also responsible for initialization of the intra-quorum connections for new quorums.
*/
class CQuorumManager
{
Expand Down
5 changes: 4 additions & 1 deletion src/llmq/quorums_chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ void CChainLocksHandler::TrySignChainTip()
// This should also not be called from validation signals, as this might result in recursive calls
void CChainLocksHandler::EnforceBestChainLock()
{
AssertLockNotHeld(cs);
AssertLockNotHeld(cs_main);

CChainLockSig clsig;
const CBlockIndex* pindex;
const CBlockIndex* currentBestChainLockBlockIndex;
Expand Down Expand Up @@ -481,4 +484,4 @@ void CChainLocksHandler::Cleanup()
lastCleanupTime = GetTimeMillis();
}

}
}
2 changes: 1 addition & 1 deletion src/llmq/quorums_dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void CDKGSessionHandler::StartThread()
throw std::runtime_error("Tried to start an already started CDKGSessionHandler thread.");
}

std::string threadName = strprintf("quorum-phase-%d", params.type);
std::string threadName = strprintf("llmq-%d", (uint8_t)params.type);
phaseHandlerThread = std::thread(&TraceThread<std::function<void()> >, threadName, std::function<void()>(std::bind(&CDKGSessionHandler::PhaseHandlerThread, this)));
}

Expand Down
30 changes: 10 additions & 20 deletions src/llmq/quorums_signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,18 +764,12 @@ bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, const uint
}
}

int tipHeight;
{
LOCK(cs_main);
tipHeight = chainActive.Height();
}

// This might end up giving different results on different members
// This might happen when we are on the brink of confirming a new quorum
// This gives a slight risk of not getting enough shares to recover a signature
// But at least it shouldn't be possible to get conflicting recovered signatures
// 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
CQuorumCPtr quorum = SelectQuorumForSigning(llmqType, tipHeight, id);
CQuorumCPtr quorum = SelectQuorumForSigning(llmqType, id);
if (!quorum) {
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- failed to select quorum. id=%s, msgHash=%s\n", __func__, id.ToString(), msgHash.ToString());
return false;
Expand Down Expand Up @@ -835,27 +829,25 @@ bool CSigningManager::GetVoteForId(Consensus::LLMQType llmqType, const uint256&
return db.GetVoteForId(llmqType, id, msgHashRet);
}

std::vector<CQuorumCPtr> CSigningManager::GetActiveQuorumSet(Consensus::LLMQType llmqType, int signHeight)
CQuorumCPtr CSigningManager::SelectQuorumForSigning(Consensus::LLMQType llmqType, const uint256& selectionHash, int signHeight, int signOffset)
{
auto& llmqParams = Params().GetConsensus().llmqs.at(llmqType);
size_t poolSize = (size_t)llmqParams.signingActiveQuorumCount;

CBlockIndex* pindexStart;
{
LOCK(cs_main);
int startBlockHeight = signHeight - SIGN_HEIGHT_OFFSET;
if (signHeight == -1) {
signHeight = chainActive.Height();
}
int startBlockHeight = signHeight - signOffset;
if (startBlockHeight > chainActive.Height()) {
return {};
}
pindexStart = chainActive[startBlockHeight];
}

return quorumManager->ScanQuorums(llmqType, pindexStart, poolSize);
}

CQuorumCPtr CSigningManager::SelectQuorumForSigning(Consensus::LLMQType llmqType, int signHeight, const uint256& selectionHash)
{
auto quorums = GetActiveQuorumSet(llmqType, signHeight);
auto quorums = quorumManager->ScanQuorums(llmqType, pindexStart, poolSize);
if (quorums.empty()) {
return nullptr;
}
Expand All @@ -875,15 +867,13 @@ CQuorumCPtr CSigningManager::SelectQuorumForSigning(Consensus::LLMQType llmqType

bool CSigningManager::VerifyRecoveredSig(Consensus::LLMQType llmqType, int signedAtHeight, const uint256& id, const uint256& msgHash, const CBLSSignature& sig)
{
auto& llmqParams = Params().GetConsensus().llmqs.at(Params().GetConsensus().llmqTypeChainLocks);

auto quorum = SelectQuorumForSigning(llmqParams.type, signedAtHeight, id);
auto quorum = SelectQuorumForSigning(llmqType, id, signedAtHeight);
if (!quorum) {
return false;
}

uint256 signHash = llmq::utils::BuildSignHash(llmqParams.type, quorum->qc.quorumHash, id, msgHash);
uint256 signHash = llmq::utils::BuildSignHash(llmqType, quorum->qc.quorumHash, id, msgHash);
return sig.VerifyInsecure(quorum->qc.quorumPublicKey, signHash);
}

} // namespace llmq
} // namespace llmq
4 changes: 2 additions & 2 deletions src/llmq/quorums_signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class CSigningManager
bool GetVoteForId(Consensus::LLMQType llmqType, const uint256& id, uint256& msgHashRet);

std::vector<CQuorumCPtr> GetActiveQuorumSet(Consensus::LLMQType llmqType, int signHeight);
CQuorumCPtr SelectQuorumForSigning(Consensus::LLMQType llmqType, int signHeight, const uint256& selectionHash);
CQuorumCPtr SelectQuorumForSigning(Consensus::LLMQType llmqType, const uint256& selectionHash, int signHeight = -1 /*chain tip*/, int signOffset = SIGN_HEIGHT_OFFSET);
// Verifies a recovered sig that was signed while the chain tip was at signedAtTip
bool VerifyRecoveredSig(Consensus::LLMQType llmqType, int signedAtHeight, const uint256& id, const uint256& msgHash, const CBLSSignature& sig);
};
Expand All @@ -174,4 +174,4 @@ extern std::unique_ptr<CSigningManager> quorumSigningManager;

} // namespace llmq

#endif // PIVX_LLMQ_QUORUMS_SIGNING_H
#endif // PIVX_LLMQ_QUORUMS_SIGNING_H
6 changes: 4 additions & 2 deletions src/llmq/quorums_signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,15 +1014,17 @@ void CSigSharesManager::CollectSigSharesToSend(std::unordered_map<NodeId, std::v
proTxToNode.emplace(pnode->verifiedProRegTxHash, pnode);
}

auto curTime = GetTime();
auto curTime = GetTime<std::chrono::milliseconds>().count();

for (auto& p : signedSessions) {
if (p.second.attempt >= p.second.quorum->params.recoveryMembers) {
continue;
}

if (curTime >= p.second.nextAttemptTime) {
p.second.nextAttemptTime = curTime + SEND_FOR_RECOVERY_TIMEOUT;
int64_t waitTime = exp2(p.second.attempt) * EXP_SEND_FOR_RECOVERY_TIMEOUT;
waitTime = std::min(MAX_SEND_FOR_RECOVERY_TIMEOUT, waitTime);
p.second.nextAttemptTime = curTime + waitTime;
auto dmn = SelectMemberForRecovery(p.second.quorum, p.second.sigShare.id, p.second.attempt);
p.second.attempt++;

Expand Down
3 changes: 2 additions & 1 deletion src/llmq/quorums_signing_shares.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ class CSigSharesManager : public CRecoveredSigsListener
// 400 is the maximum quorum size, so this is also the maximum number of sigs we need to support
const size_t MAX_MSGS_TOTAL_BATCHED_SIGS = 400;

const int64_t SEND_FOR_RECOVERY_TIMEOUT = 1;
const int64_t EXP_SEND_FOR_RECOVERY_TIMEOUT = 2000;
const int64_t MAX_SEND_FOR_RECOVERY_TIMEOUT = 10000;
const size_t MAX_MSGS_SIG_SHARES = 32;

private:
Expand Down
8 changes: 1 addition & 7 deletions src/rpc/rpcquorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,9 @@ UniValue quorumselectquorum(const JSONRPCRequest& request)

uint256 id = ParseHashV(request.params[1], "id");

int tipHeight;
{
LOCK(cs_main);
tipHeight = chainActive.Height();
}

UniValue ret(UniValue::VOBJ);

auto quorum = llmq::quorumSigningManager->SelectQuorumForSigning(llmqType, tipHeight, id);
auto quorum = llmq::quorumSigningManager->SelectQuorumForSigning(llmqType, id);
if (!quorum) {
throw JSONRPCError(RPC_MISC_ERROR, "no quorums active");
}
Expand Down
Loading