Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
dd02dfd
Use exponential backoff timeouts for recovery (https://github.com/das…
codablock Jun 24, 2020
46e51db
Fix CSigningManager::VerifyRecoveredSig (https://github.com/dashpay/d…
UdjinM6 Jun 24, 2020
902809c
replace `inter-quorum` with `intra-quorum` (https://github.com/dashpa…
PastaPastaPasta Aug 1, 2020
453a74f
Fix two potential issues in the way pending islocks are processed (ht…
UdjinM6 Sep 9, 2020
2f492d4
evo/llmq/spork: Fix various (potential) locking issues (https://githu…
UdjinM6 Nov 28, 2020
595a672
Fix thread names to fit into 15 symbols (https://github.com/dashpay/d…
UdjinM6 Dec 30, 2020
bc35c54
[logging] log system time and mock time (https://github.com/bitcoin/…
laanwj Jan 29, 2025
c279782
tests: Correct testcase in script_tests.json for large number OP_EQUA…
laanwj May 17, 2017
ecd1efe
Output line to debug.log when IsInitialBlockDownload latches to false…
laanwj Jan 29, 2025
4b4b021
[net] Added SetSocketNoDelay() utility function (https://github.com/b…
sipa May 18, 2017
0e8c8bc
Bloomfilter: parameter variables made constant (https://github.com/bi…
laanwj May 18, 2017
a30905b
tests: fix spurious addrman test failure (https://github.com/bitcoin/…
laanwj Jan 29, 2025
4ab50b3
[Consensus] Add constant for maximum stack size (https://github.com/b…
sipa May 23, 2017
e44d024
[trivial] Fix comment for ForceSetArg() (https://github.com/bitcoin/b…
laanwj Jan 29, 2025
2aa1e21
Remove unused function
Duddino Jan 29, 2025
4fde657
Convert 11 enums into scoped enums (C++11) (https://github.com/bitcoi…
Duddino Jan 29, 2025
69f87f7
wallet: Initialize m_last_block_processed to nullptr (https://github.…
Duddino Jan 29, 2025
48dc0e4
wallet: Logprint the start of a rescan (https://github.com/bitcoin/bi…
laanwj Apr 11, 2018
6717891
Fix re-declared scoped enum as unscoped (Causes issues with some comp…
jonasschnelli Jan 30, 2025
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
7 changes: 3 additions & 4 deletions src/bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455
#define LN2 0.6931471805599453094172321214581765680755001343602552


CBloomFilter::CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweakIn, unsigned char nFlagsIn) :
CBloomFilter::CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweakIn, unsigned char nFlagsIn) :
/**
* The ideal size for a bloom filter with a given number of elements and false positive rate is:
* - nElements * log(fp rate) / ln(2)^2
Expand Down Expand Up @@ -110,7 +109,7 @@ void CBloomFilter::clear()
isEmpty = true;
}

void CBloomFilter::reset(unsigned int nNewTweak)
void CBloomFilter::reset(const unsigned int nNewTweak)
{
clear();
nTweak = nNewTweak;
Expand Down Expand Up @@ -232,7 +231,7 @@ void CBloomFilter::UpdateEmptyFull()
isEmpty = empty;
}

CRollingBloomFilter::CRollingBloomFilter(unsigned int nElements, double fpRate)
CRollingBloomFilter::CRollingBloomFilter(const unsigned int nElements, const double fpRate)
{
double logFpRate = log(fpRate);
/* The optimal number of hash functions is log(fpRate) / log(0.5), but
Expand Down
6 changes: 3 additions & 3 deletions src/bloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CBloomFilter
* It should generally always be a random value (and is largely only exposed for unit testing)
* nFlags should be one of the BLOOM_UPDATE_* enums (not _MASK)
*/
CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweak, unsigned char nFlagsIn);
CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweak, unsigned char nFlagsIn);
CBloomFilter() : isFull(true), isEmpty(false), nHashFuncs(0), nTweak(0), nFlags(0) {}

SERIALIZE_METHODS(CBloomFilter, obj) { READWRITE(obj.vData, obj.nHashFuncs, obj.nTweak, obj.nFlags); }
Expand All @@ -77,7 +77,7 @@ class CBloomFilter
bool contains(const uint256& hash) const;

void clear();
void reset(unsigned int nNewTweak);
void reset(const unsigned int nNewTweak);

//! True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash functions is <= MAX_HASH_FUNCS
//! (catch a filter which was just deserialized which was too big)
Expand Down Expand Up @@ -113,7 +113,7 @@ class CRollingBloomFilter
// A random bloom filter calls GetRand() at creation time.
// Don't create global CRollingBloomFilter objects, as they may be
// constructed before the randomizer is properly initialized.
CRollingBloomFilter(unsigned int nElements, double nFPRate);
CRollingBloomFilter(const unsigned int nElements, const double nFPRate);

void insert(const std::vector<unsigned char>& vKey);
void insert(const uint256& hash);
Expand Down
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
6 changes: 0 additions & 6 deletions src/chainparamsbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,4 @@ const CBaseChainParams& BaseParams();
/** Sets the params returned by Params() to those for the given network. */
void SelectBaseParams(const std::string& chain);

/**
* Returns the appropriate chain name from the program arguments.
* @return CBaseChainParams::MAX_NETWORK_TYPES if an invalid combination is given. CBaseChainParams::MAIN by default.
*/
std::string ChainNameFromCommandLine();

#endif // PIVX_CHAINPARAMSBASE_H
1 change: 1 addition & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <sys/socket.h>
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
4 changes: 2 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-checklevel=<n>", strprintf("How thorough the block verification of -checkblocks is (0-4, default: %u)", DEFAULT_CHECKLEVEL));

strUsage += HelpMessageOpt("-conf=<file>", strprintf("Specify configuration file (default: %s)", PIVX_CONF_FILENAME));
if (mode == HMM_BITCOIND) {
if (mode == HelpMessageMode::BITCOIND) {
#if !defined(WIN32)
strUsage += HelpMessageOpt("-daemon", "Run in the background as a daemon and accept commands");
#endif
Expand Down Expand Up @@ -469,7 +469,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += GetWalletHelpString(showDebug);
#endif

if (mode == HMM_BITCOIN_QT) {
if (mode == HelpMessageMode::BITCOIN_QT) {
strUsage += HelpMessageOpt("-windowtitle=<name>", "Wallet window title");
}

Expand Down
6 changes: 3 additions & 3 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ bool AppInitSanityChecks();
bool AppInitMain();

/** The help message mode determines what help message to show */
enum HelpMessageMode {
HMM_BITCOIND,
HMM_BITCOIN_QT
enum class HelpMessageMode {
BITCOIND,
BITCOIN_QT
};

/** Help for options shared between UI and daemon (for -help) */
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
9 changes: 7 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,13 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
return;
}

if (IsBanned(addr) && !whitelisted) {
LogPrint(BCLog::NET, "connection from %s dropped (banned)\n", addr.ToString());
// According to the internet TCP_NODELAY is not carried into accepted sockets
// on all platforms. Set it again here just to be sure.
SetSocketNoDelay(hSocket);

if (IsBanned(addr) && !whitelisted)
{
LogPrintf("connection from %s dropped (banned)\n", addr.ToString());
CloseSocket(hSocket);
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ void PeerLogicValidation::FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTim
nPreferredDownload -= state->fPreferredDownload;

mapNodeState.erase(nodeid);
LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid);
}

bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats)
Expand Down
9 changes: 9 additions & 0 deletions src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ SOCKET CreateSocket(const CService& addrConnect)
// Different way of disabling SIGPIPE on BSD
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
#endif
// Disable Nagle's algorithm
SetSocketNoDelay(hSocket);

// Set to non-blocking
if (!SetSocketNonBlocking(hSocket, true)) {
Expand Down Expand Up @@ -779,6 +781,13 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
return true;
}

bool SetSocketNoDelay(SOCKET& hSocket)
{
int set = 1;
int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int));
return rc == 0;
}

void InterruptSocks5(bool interrupt)
{
interruptSocks5Recv = interrupt;
Expand Down
2 changes: 2 additions & 0 deletions src/netbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ std::string NetworkErrorString(int err);
bool CloseSocket(SOCKET& hSocket);
/** Disable or enable blocking-mode for a socket */
bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking);
/** Set the TCP_NODELAY flag on a socket */
bool SetSocketNoDelay(SOCKET& hSocket);
/**
* Convert milliseconds to a struct timeval for e.g. select.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/pivxd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool AppInit(int argc, char* argv[])
strUsage += LicenseInfo();
} else {
strUsage += "\nUsage: pivxd [options] Start " PACKAGE_NAME " Daemon\n";
strUsage += "\n" + HelpMessage(HMM_BITCOIND);
strUsage += "\n" + HelpMessage(HelpMessageMode::BITCOIND);
}

fprintf(stdout, "%s", strUsage.c_str());
Expand Down
11 changes: 5 additions & 6 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

class CTransaction;

enum SigVersion
{
SIGVERSION_BASE = 0,
SIGVERSION_SAPLING = 1,
enum class SigVersion {
BASE = 0,
SAPLING = 1,
};

/** An outpoint - a combination of a transaction hash and an index n into its vout */
Expand Down Expand Up @@ -346,7 +345,7 @@ class CTransaction
// Ensure that special and sapling fields are signed
SigVersion GetRequiredSigVersion() const
{
return isSaplingVersion() ? SIGVERSION_SAPLING : SIGVERSION_BASE;
return isSaplingVersion() ? SigVersion::SAPLING : SigVersion::BASE;
}

/*
Expand Down Expand Up @@ -449,7 +448,7 @@ struct CMutableTransaction
// Ensure that special and sapling fields are signed
SigVersion GetRequiredSigVersion() const
{
return isSaplingVersion() ? SIGVERSION_SAPLING : SIGVERSION_BASE;
return isSaplingVersion() ? SigVersion::SAPLING : SigVersion::BASE;
}
};

Expand Down
Loading
Loading