Skip to content

Test conflicting / rebase #12

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

Closed
wants to merge 8 commits into from
Closed
70 changes: 18 additions & 52 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,23 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([
)
LDFLAGS="$TEMP_LDFLAGS"

# Check for different ways of gathering OS randomness
dnl check for gmtime_r(), fallback to gmtime_s() if that is unavailable
dnl fail if neither are available.
AC_MSG_CHECKING(for gmtime_r)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
[[ gmtime_r((const time_t *) nullptr, (struct tm *) nullptr); ]])],
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GMTIME_R, 1, [Define this symbol if gmtime_r is available]) ],
[ AC_MSG_RESULT(no);
AC_MSG_CHECKING(for gmtime_s);
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
[[ gmtime_s((struct tm *) nullptr, (const time_t *) nullptr); ]])],
[ AC_MSG_RESULT(yes)],
[ AC_MSG_RESULT(no); AC_MSG_ERROR(Both gmtime_r and gmtime_s are unavailable) ]
)
]
)

dnl Check for different ways of gathering OS randomness
AC_MSG_CHECKING(for Linux getrandom syscall)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
#include <sys/syscall.h>
Expand Down Expand Up @@ -1207,57 +1223,6 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
LIBS="$TEMP_LIBS"
CPPFLAGS="$TEMP_CPPFLAGS"

dnl Boost >= 1.50 uses sleep_for rather than the now-deprecated sleep, however
dnl it was broken from 1.50 to 1.52 when backed by nanosleep. Use sleep_for if
dnl a working version is available, else fall back to sleep. sleep was removed
dnl after 1.56.
dnl If neither is available, abort.
TEMP_LIBS="$LIBS"
LIBS="$BOOST_LIBS $LIBS"
TEMP_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <boost/thread/thread.hpp>
#include <boost/version.hpp>
]],[[
#if BOOST_VERSION >= 105000 && (!defined(BOOST_HAS_NANOSLEEP) || BOOST_VERSION >= 105200)
boost::this_thread::sleep_for(boost::chrono::milliseconds(0));
#else
choke me
#endif
]])],
[boost_sleep=yes;
AC_DEFINE(HAVE_WORKING_BOOST_SLEEP_FOR, 1, [Define this symbol if boost sleep_for works])],
[boost_sleep=no])
LIBS="$TEMP_LIBS"
CPPFLAGS="$TEMP_CPPFLAGS"

if test x$boost_sleep != xyes; then
TEMP_LIBS="$LIBS"
LIBS="$BOOST_LIBS $LIBS"
TEMP_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <boost/version.hpp>
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
]],[[
#if BOOST_VERSION <= 105600
boost::this_thread::sleep(boost::posix_time::milliseconds(0));
#else
choke me
#endif
]])],
[boost_sleep=yes; AC_DEFINE(HAVE_WORKING_BOOST_SLEEP, 1, [Define this symbol if boost sleep works])],
[boost_sleep=no])
LIBS="$TEMP_LIBS"
CPPFLAGS="$TEMP_CPPFLAGS"
fi

if test x$boost_sleep != xyes; then
AC_MSG_ERROR(No working boost sleep implementation found.)
fi

fi

if test x$use_pkgconfig = xyes; then
Expand Down Expand Up @@ -1621,6 +1586,7 @@ AC_SUBST(HAVE_BUILTIN_PREFETCH)
AC_SUBST(HAVE_MM_PREFETCH)
AC_SUBST(HAVE_STRONG_GETAUXVAL)
AC_SUBST(HAVE_WEAK_GETAUXVAL)
AC_SUBST(HAVE_GMTIME_R)
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini])
AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
Expand Down
6 changes: 6 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ BITCOIN_CORE_H = \
netfulfilledman.h \
netmessagemaker.h \
node/coinstats.h \
node/transaction.h \
noui.h \
policy/feerate.h \
policy/fees.h \
Expand Down Expand Up @@ -268,10 +269,12 @@ BITCOIN_CORE_H = \
util/fees.h \
util/system.h \
util/asmap.h \
util/getuniquepath.h \
util/macros.h \
util/memory.h \
util/moneystr.h \
util/serfloat.h \
util/sock.h \
util/string.h \
util/time.h \
util/threadnames.h \
Expand Down Expand Up @@ -367,6 +370,7 @@ libdash_server_a_SOURCES = \
netfulfilledman.cpp \
net_processing.cpp \
node/coinstats.cpp \
node/transaction.cpp \
noui.cpp \
policy/fees.cpp \
policy/policy.cpp \
Expand Down Expand Up @@ -606,6 +610,8 @@ libdash_util_a_SOURCES = \
util/bytevectorhash.cpp \
util/error.cpp \
util/fees.cpp \
util/sock.cpp \
util/getuniquepath.cpp \
util/system.cpp \
util/asmap.cpp \
util/moneystr.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ BITCOIN_TESTS =\
test/sighash_tests.cpp \
test/sigopcount_tests.cpp \
test/skiplist_tests.cpp \
test/sock_tests.cpp \
test/streams_tests.cpp \
test/subsidy_tests.cpp \
test/sync_tests.cpp \
Expand Down
26 changes: 11 additions & 15 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime
return;

// find a bucket it is in now
int nRnd = RandomInt(ADDRMAN_NEW_BUCKET_COUNT);
int nRnd = insecure_rand.randrange(ADDRMAN_NEW_BUCKET_COUNT);
int nUBucket = -1;
for (unsigned int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) {
int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT;
Expand Down Expand Up @@ -319,7 +319,7 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
int nFactor = 1;
for (int n = 0; n < pinfo->nRefCount; n++)
nFactor *= 2;
if (nFactor > 1 && (RandomInt(nFactor) != 0))
if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0))
return false;
} else {
pinfo = Create(addr, source, &nId);
Expand Down Expand Up @@ -384,37 +384,37 @@ CAddrInfo CAddrMan::Select_(bool newOnly)

// Use a 50% chance for choosing between tried and new table entries.
if (!newOnly &&
(nTried > 0 && (nNew == 0 || RandomInt(2) == 0))) {
(nTried > 0 && (nNew == 0 || insecure_rand.randbool() == 0))) {
// use a tried node
double fChanceFactor = 1.0;
while (1) {
int nKBucket = RandomInt(ADDRMAN_TRIED_BUCKET_COUNT);
int nKBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
int nKBucket = insecure_rand.randrange(ADDRMAN_TRIED_BUCKET_COUNT);
int nKBucketPos = insecure_rand.randrange(ADDRMAN_BUCKET_SIZE);
while (vvTried[nKBucket][nKBucketPos] == -1) {
nKBucket = (nKBucket + insecure_rand.randbits(ADDRMAN_TRIED_BUCKET_COUNT_LOG2)) % ADDRMAN_TRIED_BUCKET_COUNT;
nKBucketPos = (nKBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvTried[nKBucket][nKBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
if (RandomInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
return info;
fChanceFactor *= 1.2;
}
} else {
// use a new node
double fChanceFactor = 1.0;
while (1) {
int nUBucket = RandomInt(ADDRMAN_NEW_BUCKET_COUNT);
int nUBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
int nUBucket = insecure_rand.randrange(ADDRMAN_NEW_BUCKET_COUNT);
int nUBucketPos = insecure_rand.randrange(ADDRMAN_BUCKET_SIZE);
while (vvNew[nUBucket][nUBucketPos] == -1) {
nUBucket = (nUBucket + insecure_rand.randbits(ADDRMAN_NEW_BUCKET_COUNT_LOG2)) % ADDRMAN_NEW_BUCKET_COUNT;
nUBucketPos = (nUBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvNew[nUBucket][nUBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
if (RandomInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
return info;
fChanceFactor *= 1.2;
}
Expand Down Expand Up @@ -510,7 +510,7 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr)
if (vAddr.size() >= nNodes)
break;

int nRndPos = RandomInt(vRandom.size() - n) + n;
int nRndPos = insecure_rand.randrange(vRandom.size() - n) + n;
SwapRandom(n, nRndPos);
assert(mapInfo.count(vRandom[n]) == 1);

Expand Down Expand Up @@ -575,10 +575,6 @@ CAddrInfo CAddrMan::GetAddressInfo_(const CService& addr)
return *pinfo;
}

int CAddrMan::RandomInt(int nMax){
return GetRandInt(nMax);
}

void CAddrMan::ResolveCollisions_()
{
for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) {
Expand Down Expand Up @@ -645,7 +641,7 @@ CAddrInfo CAddrMan::SelectTriedCollision_()
std::set<int>::iterator it = m_tried_collisions.begin();

// Selects a random element from m_tried_collisions
std::advance(it, GetRandInt(m_tried_collisions.size()));
std::advance(it, insecure_rand.randrange(m_tried_collisions.size()));
int id_new = *it;

// If id_new not found in mapInfo remove it from m_tried_collisions
Expand Down
5 changes: 1 addition & 4 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ class CAddrMan
//! Return a random to-be-evicted tried table address.
CAddrInfo SelectTriedCollision_();

//! Wraps GetRandInt to allow tests to override RandomInt and make it determinismistic.
virtual int RandomInt(int nMax);

#ifdef DEBUG_ADDRMAN
//! Perform consistency check. Returns an error code or zero.
int Check_();
Expand Down Expand Up @@ -561,7 +558,7 @@ class CAddrMan
{
LOCK(cs);
std::vector<int>().swap(vRandom);
nKey = GetRandHash();
nKey = insecure_rand.rand256();
for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
vvNew[bucket][entry] = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/bench/bls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static void BLS_Verify_BatchedParallel(benchmark::Bench& bench)
cancel = true;
while (blsWorker.IsAsyncVerifyInProgress())
{
MilliSleep(100);
UninterruptibleSleep(std::chrono::milliseconds{100});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/coinjoin/coinjoin-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void CCoinJoinClientSession::UnlockCoins()
while (true) {
TRY_LOCK(mixingWallet.cs_wallet, lockWallet);
if (!lockWallet) {
MilliSleep(50);
UninterruptibleSleep(std::chrono::milliseconds{50});
continue;
}
for (const auto& outpoint : vecOutPointLocked)
Expand Down
2 changes: 1 addition & 1 deletion src/dash-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ static int CommandLineRPC(int argc, char *argv[])
}
catch (const CConnectionFailed&) {
if (fWait)
MilliSleep(1000);
UninterruptibleSleep(std::chrono::milliseconds{1000});
else
throw;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dashd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void WaitForShutdown()
{
while (!ShutdownRequested())
{
MilliSleep(200);
UninterruptibleSleep(std::chrono::milliseconds{200});
}
Interrupt();
}
Expand Down
2 changes: 1 addition & 1 deletion src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
/* Deter brute-forcing
If this results in a DoS the user really
shouldn't have their RPC port exposed. */
MilliSleep(250);
UninterruptibleSleep(std::chrono::milliseconds{250});

req->WriteHeader("WWW-Authenticate", WWW_AUTH_HEADER_DATA);
req->WriteReply(HTTP_UNAUTHORIZED);
Expand Down
6 changes: 3 additions & 3 deletions src/llmq/quorums_dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void CDKGSessionHandler::WaitForNextPhase(QuorumPhase curPhase,
throw AbortPhaseException();
}
if (!runWhileWaiting()) {
MilliSleep(100);
UninterruptibleSleep(std::chrono::milliseconds{100});
}
}

Expand Down Expand Up @@ -238,7 +238,7 @@ void CDKGSessionHandler::WaitForNewQuorum(const uint256& oldQuorumHash) const
if (p.second != oldQuorumHash) {
break;
}
MilliSleep(100);
UninterruptibleSleep(std::chrono::milliseconds{100});
}

LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - done\n", __func__, params.name);
Expand Down Expand Up @@ -305,7 +305,7 @@ void CDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase,
}
}
if (!runWhileWaiting()) {
MilliSleep(100);
UninterruptibleSleep(std::chrono::milliseconds{100});
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/masternode/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,14 @@ void CActiveMasternodeManager::Init(const CBlockIndex* pindex)

// Check socket connectivity
LogPrintf("CActiveMasternodeManager::Init -- Checking inbound connection to '%s'\n", activeMasternodeInfo.service.ToString());
SOCKET hSocket = CreateSocket(activeMasternodeInfo.service);
if (hSocket == INVALID_SOCKET) {
std::unique_ptr<Sock> sock = CreateSock(activeMasternodeInfo.service);
if (!sock) {
state = MASTERNODE_ERROR;
strError = "Could not create socket to connect to " + activeMasternodeInfo.service.ToString();
LogPrintf("CActiveMasternodeManager::Init -- ERROR: %s\n", strError);
return;
}
bool fConnected = ConnectSocketDirectly(activeMasternodeInfo.service, hSocket, nConnectTimeout, true) && IsSelectableSocket(hSocket);
CloseSocket(hSocket);
bool fConnected = ConnectSocketDirectly(activeMasternodeInfo.service, sock->Get(), nConnectTimeout, true) && IsSelectableSocket(sock->Get());

if (!fConnected && Params().RequireRoutableExternalIP()) {
state = MASTERNODE_ERROR;
Expand Down
Loading