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

refactor: make Get{Quorum, MinedCommitment, InstantSendLock*, *MN*} and friends return std::optional #6446

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
14 changes: 8 additions & 6 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS

const auto tip_mn_list = m_dmnman.GetListAtChainTip();
if (dsq.masternodeOutpoint.IsNull()) {
if (auto dmn = tip_mn_list.GetValidMN(dsq.m_protxHash)) {
dsq.masternodeOutpoint = dmn->collateralOutpoint;
if (auto dmn_opt = tip_mn_list.GetValidMN(dsq.m_protxHash); dmn_opt.has_value()) {
dsq.masternodeOutpoint = dmn_opt.value()->collateralOutpoint;
} else {
return tl::unexpected{10};
}
Expand Down Expand Up @@ -90,9 +90,10 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS

if (dsq.IsTimeOutOfBounds()) return {};

auto dmn = tip_mn_list.GetValidMNByCollateral(dsq.masternodeOutpoint);
if (!dmn) return {};
auto dmn_opt = tip_mn_list.GetValidMNByCollateral(dsq.masternodeOutpoint);
if (!dmn_opt.has_value()) return {};

auto dmn = dmn_opt.value();
if (dsq.m_protxHash.IsNull()) {
dsq.m_protxHash = dmn->proTxHash;
}
Expand Down Expand Up @@ -1085,14 +1086,15 @@ bool CCoinJoinClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized,
// Look through the queues and see if anything matches
CCoinJoinQueue dsq;
while (m_queueman->GetQueueItemAndTry(dsq)) {
auto dmn = mnList.GetValidMNByCollateral(dsq.masternodeOutpoint);
auto dmn_opt = mnList.GetValidMNByCollateral(dsq.masternodeOutpoint);

if (!dmn) {
if (!dmn_opt) {
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::JoinExistingQueue -- dsq masternode is not in masternode list, masternode=%s\n", dsq.masternodeOutpoint.ToStringShort());
continue;
}

// skip next mn payments winners
auto dmn = dmn_opt.value();
if (dmn->pdmnState->nLastPaidHeight + nWeightedMnCount < mnList.GetHeight() + WinnersToSkip()) {
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::JoinExistingQueue -- skipping winner, masternode=%s\n", dmn->proTxHash.ToString());
continue;
Expand Down
14 changes: 8 additions & 6 deletions src/coinjoin/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode& peer, CDataStream& vRecv)
LogPrint(BCLog::COINJOIN, "DSACCEPT -- nDenom %d (%s) txCollateral %s", dsa.nDenom, CoinJoin::DenominationToString(dsa.nDenom), dsa.txCollateral.ToString()); /* Continued */

auto mnList = m_dmnman.GetListAtChainTip();
auto dmn = mnList.GetValidMNByCollateral(m_mn_activeman->GetOutPoint());
if (!dmn) {
auto dmn_opt = mnList.GetValidMNByCollateral(m_mn_activeman->GetOutPoint());
if (!dmn_opt.has_value()) {
PushStatus(peer, STATUS_REJECTED, ERR_MN_LIST);
return;
}

auto dmn = dmn_opt.value();
if (vecSessionCollaterals.empty()) {
{
TRY_LOCK(cs_vecqueue, lockRecv);
Expand Down Expand Up @@ -129,8 +130,8 @@ PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv

const auto tip_mn_list = m_dmnman.GetListAtChainTip();
if (dsq.masternodeOutpoint.IsNull()) {
if (auto dmn = tip_mn_list.GetValidMN(dsq.m_protxHash)) {
dsq.masternodeOutpoint = dmn->collateralOutpoint;
if (auto dmn_opt = tip_mn_list.GetValidMN(dsq.m_protxHash); dmn_opt.has_value()) {
dsq.masternodeOutpoint = dmn_opt.value()->collateralOutpoint;
} else {
return tl::unexpected{10};
}
Expand All @@ -157,9 +158,10 @@ PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv

if (dsq.IsTimeOutOfBounds()) return {};

auto dmn = tip_mn_list.GetValidMNByCollateral(dsq.masternodeOutpoint);
if (!dmn) return {};
auto dmn_opt = tip_mn_list.GetValidMNByCollateral(dsq.masternodeOutpoint);
if (!dmn_opt.has_value()) return {};

auto dmn = dmn_opt.value();
if (dsq.m_protxHash.IsNull()) {
dsq.m_protxHash = dmn->proTxHash;
}
Expand Down
6 changes: 3 additions & 3 deletions src/evo/assetlocktx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ bool CAssetUnlockPayload::VerifySig(const llmq::CQuorumManager& qman, const uint
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-assetunlock-too-late");
}

const auto quorum = qman.GetQuorum(llmqType, quorumHash);
const auto quorum_opt = qman.GetQuorum(llmqType, quorumHash);
// quorum must be valid at this point. Let's check and throw error just in case
if (!quorum) {
if (!quorum_opt.value()) {
LogPrintf("%s: ERROR! No quorum for credit pool found for hash=%s\n", __func__, quorumHash.ToString());
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-assetunlock-quorum-internal-error");
}

const auto quorum = quorum_opt.value();
const uint256 requestId = ::SerializeHash(std::make_pair(ASSETUNLOCK_REQUESTID_PREFIX, index));

if (const uint256 signHash = llmq::BuildSignHash(llmqType, quorum->qc->quorumHash, requestId, msgHash);
quorumSig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash)) {
return true;
Expand Down
6 changes: 4 additions & 2 deletions src/evo/cbtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,13 @@ auto CachedGetQcHashesQcIndexedHashes(const CBlockIndex* pindexPrev, const llmq:
auto& map_indexed_hashes = qcIndexedHashes_cached[llmqType];
for (const auto& blockIndex : vecBlockIndexes) {
uint256 dummyHash;
llmq::CFinalCommitmentPtr pqc = quorum_block_processor.GetMinedCommitment(llmqType, blockIndex->GetBlockHash(), dummyHash);
if (pqc == nullptr) {
auto pqc_opt = quorum_block_processor.GetMinedCommitment(llmqType, blockIndex->GetBlockHash(), dummyHash);
if (!pqc_opt.has_value()) {
// this should never happen
return std::nullopt;
}

auto pqc = std::move(pqc_opt).value();
auto qcHash = ::SerializeHash(*pqc);
if (rotation_enabled) {
map_indexed_hashes[pqc->quorumIndex] = qcHash;
Expand Down
Loading
Loading