Skip to content
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
28 changes: 14 additions & 14 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,11 @@ bool CCoinJoinClientSession::SendDenominate(const std::vector<std::pair<CTxDSIn,
std::vector<CTxDSIn> vecTxDSInTmp;
std::vector<CTxOut> vecTxOutTmp;

for (const auto& pair : vecPSInOutPairsIn) {
vecTxDSInTmp.emplace_back(pair.first);
vecTxOutTmp.emplace_back(pair.second);
tx.vin.emplace_back(pair.first);
tx.vout.emplace_back(pair.second);
for (const auto& [txDsIn, txOut] : vecPSInOutPairsIn) {
vecTxDSInTmp.emplace_back(txDsIn);
vecTxOutTmp.emplace_back(txOut);
tx.vin.emplace_back(txDsIn);
tx.vout.emplace_back(txOut);
}

LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::SendDenominate -- Submitting partial tx %s", tx.ToString()); /* Continued */
Expand Down Expand Up @@ -1363,9 +1363,9 @@ bool CCoinJoinClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds, s
return true;
}

for (const auto& pair : vecPSInOutPairsRet) {
mixingWallet.LockCoin(pair.first.prevout);
vecOutPointLocked.push_back(pair.first.prevout);
for (const auto& [txDsIn, txDsOut] : vecPSInOutPairsRet) {
mixingWallet.LockCoin(txDsIn.prevout);
vecOutPointLocked.push_back(txDsIn.prevout);
}

return true;
Expand Down Expand Up @@ -1677,17 +1677,17 @@ bool CCoinJoinClientSession::CreateDenominated(CAmount nBalanceToDenominate, con
}

bool finished = true;
for (const auto it : mapDenomCount) {
for (const auto [denom, count] : mapDenomCount) {
// Check if this specific denom could use another loop, check that there aren't nCoinJoinDenomsGoal of this
// denom and that our nValueLeft/nBalanceToDenominate is enough to create one of these denoms, if so, loop again.
if (it.second < CCoinJoinClientOptions::GetDenomsGoal() && txBuilder.CouldAddOutput(it.first) && nBalanceToDenominate > 0) {
if (count < CCoinJoinClientOptions::GetDenomsGoal() && txBuilder.CouldAddOutput(denom) && nBalanceToDenominate > 0) {
finished = false;
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- 1 - NOT finished - nDenomValue: %f, count: %d, nBalanceToDenominate: %f, %s\n",
__func__, (float) it.first / COIN, it.second, (float) nBalanceToDenominate / COIN, txBuilder.ToString());
__func__, (float) denom / COIN, count, (float) nBalanceToDenominate / COIN, txBuilder.ToString());
break;
}
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- 1 - FINISHED - nDenomValue: %f, count: %d, nBalanceToDenominate: %f, %s\n",
__func__, (float) it.first / COIN, it.second, (float) nBalanceToDenominate / COIN, txBuilder.ToString());
__func__, (float) denom / COIN, count, (float) nBalanceToDenominate / COIN, txBuilder.ToString());
}

if (finished) break;
Expand Down Expand Up @@ -1757,8 +1757,8 @@ bool CCoinJoinClientSession::CreateDenominated(CAmount nBalanceToDenominate, con

LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- 3 - nBalanceToDenominate: %f, %s\n", __func__, (float) nBalanceToDenominate / COIN, txBuilder.ToString());

for (const auto it : mapDenomCount) {
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- 3 - DONE - nDenomValue: %f, count: %d\n", __func__, (float) it.first / COIN, it.second);
for (const auto [denom, count] : mapDenomCount) {
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- 3 - DONE - nDenomValue: %f, count: %d\n", __func__, (float) denom / COIN, count);
}

// No reasons to create mixing collaterals if we can't create denoms to mix
Expand Down
7 changes: 2 additions & 5 deletions src/coinjoin/coinjoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ bool CCoinJoinBaseSession::IsValidInOuts(const std::vector<CTxIn>& vin, const st
}

auto checkTxOut = [&](const CTxOut& txout) {
int nDenom = CCoinJoin::AmountToDenomination(txout.nValue);
if (nDenom != nSessionDenom) {
if (int nDenom = CCoinJoin::AmountToDenomination(txout.nValue); nDenom != nSessionDenom) {
LogPrint(BCLog::COINJOIN, "CCoinJoinBaseSession::IsValidInOuts -- ERROR: incompatible denom %d (%s) != nSessionDenom %d (%s)\n",
nDenom, CCoinJoin::DenominationToString(nDenom), nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom));
nMessageIDRet = ERR_DENOM;
Expand Down Expand Up @@ -364,9 +363,7 @@ bool CCoinJoin::IsCollateralValid(const CTransaction& txCollateral)

std::string CCoinJoin::DenominationToString(int nDenom)
{
CAmount nDenomAmount = DenominationToAmount(nDenom);

switch (nDenomAmount) {
switch (CAmount nDenomAmount = DenominationToAmount(nDenom)) {
case 0: return "N/A";
case -1: return "out-of-bounds";
case -2: return "non-denom";
Expand Down
19 changes: 10 additions & 9 deletions src/evo/simplifiedmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,27 @@ bool CSimplifiedMNListDiff::BuildQuorumsDiff(const CBlockIndex* baseBlockIndex,

std::set<std::pair<Consensus::LLMQType, uint256>> baseQuorumHashes;
std::set<std::pair<Consensus::LLMQType, uint256>> quorumHashes;
for (const auto& p : baseQuorums) {
for (const auto& p2 : p.second) {
baseQuorumHashes.emplace(p.first, p2->GetBlockHash());
for (const auto& [llmqType, vecBlockIndex] : baseQuorums) {
for (const auto& blockindex : vecBlockIndex) {
baseQuorumHashes.emplace(llmqType, blockindex->GetBlockHash());
}
}
for (const auto& p : quorums) {
for (const auto& p2 : p.second) {
quorumHashes.emplace(p.first, p2->GetBlockHash());
for (const auto& [llmqType, vecBlockIndex] : quorums) {
for (const auto& blockindex : vecBlockIndex) {
quorumHashes.emplace(llmqType, blockindex->GetBlockHash());
}
}

for (auto& p : baseQuorumHashes) {
for (const auto& p : baseQuorumHashes) {
if (!quorumHashes.count(p)) {
deletedQuorums.emplace_back((uint8_t)p.first, p.second);
}
}
for (auto& p : quorumHashes) {
for (const auto& p : quorumHashes) {
const auto& [llmqType, hash] = p;
if (!baseQuorumHashes.count(p)) {
uint256 minedBlockHash;
llmq::CFinalCommitmentPtr qc = quorum_block_processor.GetMinedCommitment(p.first, p.second, minedBlockHash);
llmq::CFinalCommitmentPtr qc = quorum_block_processor.GetMinedCommitment(llmqType, hash, minedBlockHash);
if (qc == nullptr) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/signing_shares.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class CSigSharesNodeState
// Used to avoid holding locks too long
struct SessionInfo
{
Consensus::LLMQType llmqType;
Consensus::LLMQType llmqType{Consensus::LLMQType::LLMQ_NONE};
uint256 quorumHash;
uint256 id;
uint256 msgHash;
Expand Down
10 changes: 5 additions & 5 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

std::unique_ptr<CSporkManager> sporkManager;

std::optional<int64_t> CSporkManager::SporkValueIfActive(SporkId nSporkID) const
std::optional<SporkValue> CSporkManager::SporkValueIfActive(SporkId nSporkID) const
{
AssertLockHeld(cs);

Expand All @@ -39,7 +39,7 @@ std::optional<int64_t> CSporkManager::SporkValueIfActive(SporkId nSporkID) const
}

// calc how many values we have and how many signers vote for every value
std::unordered_map<int64_t, int> mapValueCounts;
std::unordered_map<SporkValue, int> mapValueCounts;
for (const auto& [_, spork] : mapSporksActive.at(nSporkID)) {
mapValueCounts[spork.nValue]++;
if (mapValueCounts.at(spork.nValue) >= nMinSporkKeys) {
Expand Down Expand Up @@ -188,7 +188,7 @@ void CSporkManager::ProcessGetSporks(CNode& peer, CConnman& connman)
}


bool CSporkManager::UpdateSpork(SporkId nSporkID, int64_t nValue, CConnman& connman)
bool CSporkManager::UpdateSpork(SporkId nSporkID, SporkValue nValue, CConnman& connman)
{
CSporkMessage spork(nSporkID, nValue, GetAdjustedTime());

Expand Down Expand Up @@ -229,7 +229,7 @@ bool CSporkManager::IsSporkActive(SporkId nSporkID) const
}
}

int64_t nSporkValue = GetSporkValue(nSporkID);
SporkValue nSporkValue = GetSporkValue(nSporkID);
// Get time is somewhat costly it looks like
bool ret = nSporkValue < GetAdjustedTime();
// Only cache true values
Expand All @@ -240,7 +240,7 @@ bool CSporkManager::IsSporkActive(SporkId nSporkID) const
return ret;
}

int64_t CSporkManager::GetSporkValue(SporkId nSporkID) const
SporkValue CSporkManager::GetSporkValue(SporkId nSporkID) const
{
LOCK(cs);

Expand Down
15 changes: 8 additions & 7 deletions src/spork.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ namespace std
};
}

using SporkValue = int64_t;
struct CSporkDef
{
SporkId sporkId{SPORK_INVALID};
int64_t defaultValue{0};
SporkValue defaultValue{0};
std::string_view name;
};

Expand Down Expand Up @@ -99,10 +100,10 @@ class CSporkMessage

public:
SporkId nSporkID{0};
int64_t nValue{0};
SporkValue nValue{0};
int64_t nTimeSigned{0};

CSporkMessage(SporkId nSporkID, int64_t nValue, int64_t nTimeSigned) :
CSporkMessage(SporkId nSporkID, SporkValue nValue, int64_t nTimeSigned) :
nSporkID(nSporkID),
nValue(nValue),
nTimeSigned(nTimeSigned)
Expand Down Expand Up @@ -167,7 +168,7 @@ class CSporkManager
mutable std::unordered_map<const SporkId, bool> mapSporksCachedActive GUARDED_BY(cs_mapSporksCachedActive);

mutable Mutex cs_mapSporksCachedValues;
mutable std::unordered_map<SporkId, int64_t> mapSporksCachedValues GUARDED_BY(cs_mapSporksCachedValues);
mutable std::unordered_map<SporkId, SporkValue> mapSporksCachedValues GUARDED_BY(cs_mapSporksCachedValues);

mutable Mutex cs;

Expand All @@ -182,7 +183,7 @@ class CSporkManager
* SporkValueIfActive is used to get the value agreed upon by the majority
* of signed spork messages for a given Spork ID.
*/
std::optional<int64_t> SporkValueIfActive(SporkId nSporkID) const EXCLUSIVE_LOCKS_REQUIRED(cs);
std::optional<SporkValue> SporkValueIfActive(SporkId nSporkID) const EXCLUSIVE_LOCKS_REQUIRED(cs);

public:

Expand Down Expand Up @@ -254,7 +255,7 @@ class CSporkManager
* UpdateSpork is used by the spork RPC command to set a new spork value, sign
* and broadcast the spork message.
*/
bool UpdateSpork(SporkId nSporkID, int64_t nValue, CConnman& connman) LOCKS_EXCLUDED(cs);
bool UpdateSpork(SporkId nSporkID, SporkValue nValue, CConnman& connman) LOCKS_EXCLUDED(cs);

/**
* IsSporkActive returns a bool for time-based sporks, and should be used
Expand All @@ -270,7 +271,7 @@ class CSporkManager
* GetSporkValue returns the spork value given a Spork ID. If no active spork
* message has yet been received by the node, it returns the default value.
*/
int64_t GetSporkValue(SporkId nSporkID) const LOCKS_EXCLUDED(cs);
SporkValue GetSporkValue(SporkId nSporkID) const LOCKS_EXCLUDED(cs);

/**
* GetSporkIDByName returns the internal Spork ID given the spork name.
Expand Down