Skip to content

Commit

Permalink
Merge pull request dashpay#5529 from vijaydasmp/bp22_13
Browse files Browse the repository at this point in the history
backport: Merge bitcoin#21187, 21342,17350,19238,21210,21274,(partial)21053,20370,20437,21388
  • Loading branch information
PastaPastaPasta authored Aug 28, 2023
2 parents 54e0e0f + 7bd149f commit 4ce7ed8
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 117 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Dash Core staging tree 18.0

https://www.dash.org

For an immediately usable, binary version of the Dash Core software, see
https://www.dash.org/downloads/.

Further information about Dash Core is available in the [doc folder](/doc).

What is Dash?
-------------
Expand All @@ -17,11 +21,8 @@ to operate with no central authority: managing transactions and issuing money
are carried out collectively by the network. Dash Core is the name of the open
source software which enables the use of this currency.

Pre-Built Binary
----------------

For more information, as well as an immediately usable, binary version of
the Dash Core software, see https://www.dash.org/downloads/.
For more information read the original Dash whitepaper.

License
-------
Expand Down Expand Up @@ -55,7 +56,7 @@ submit new unit tests for old code. Unit tests can be compiled and run
and extending unit tests can be found in [/src/test/README.md](/src/test/README.md).

There are also [regression and integration tests](/test), written
in Python, that are run automatically on the build server.
in Python.
These tests can be run (if the [test dependencies](/test) are installed) with: `test/functional/test_runner.py`

The Travis CI system makes sure that every pull request is built for Windows, Linux, and macOS, and that unit/sanity tests are run automatically.
Expand All @@ -78,5 +79,3 @@ Translations are periodically pulled from Transifex and merged into the git repo

**Important**: We do not accept translation changes as GitHub pull requests because the next
pull from Transifex would automatically overwrite them again.

Translators should also follow the [forum](https://www.dash.org/forum/topic/dash-worldwide-collaboration.88/).
2 changes: 1 addition & 1 deletion doc/build-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Then build using:
cd depends
make HOST=i686-w64-mingw32
cd ..
./autogen.sh # not required when building from tarball
./autogen.sh
CONFIG_SITE=$PWD/depends/i686-w64-mingw32/share/config.site ./configure --prefix=/
make
sudo bash -c "echo 1 > /proc/sys/fs/binfmt_misc/status" # Enable WSL support for Win32 applications.
Expand Down
30 changes: 29 additions & 1 deletion src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, in
if (!discriminatePorts) {
addr2.SetPort(0);
}
AssertLockHeld(cs);

int nId = nIdCount++;
mapInfo[nId] = CAddrInfo(addr, addrSource);
Expand All @@ -145,6 +146,8 @@ CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, in

void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
{
AssertLockHeld(cs);

if (nRndPos1 == nRndPos2)
return;

Expand All @@ -165,6 +168,8 @@ void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)

void CAddrMan::Delete(int nId)
{
AssertLockHeld(cs);

assert(mapInfo.count(nId) != 0);
CAddrInfo& info = mapInfo[nId];
assert(!info.fInTried);
Expand All @@ -184,6 +189,8 @@ void CAddrMan::Delete(int nId)

void CAddrMan::ClearNew(int nUBucket, int nUBucketPos)
{
AssertLockHeld(cs);

// if there is an entry in the specified bucket, delete it.
if (vvNew[nUBucket][nUBucketPos] != -1) {
int nIdDelete = vvNew[nUBucket][nUBucketPos];
Expand All @@ -199,6 +206,8 @@ void CAddrMan::ClearNew(int nUBucket, int nUBucketPos)

void CAddrMan::MakeTried(CAddrInfo& info, int nId)
{
AssertLockHeld(cs);

// remove the entry from all new buckets
for (int bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
int pos = info.GetBucketPosition(nKey, true, bucket);
Expand Down Expand Up @@ -247,6 +256,8 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)

void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime)
{
AssertLockHeld(cs);

int nId;

nLastGood = nTime;
Expand Down Expand Up @@ -317,6 +328,8 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime

bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
{
AssertLockHeld(cs);

if (!addr.IsRoutable())
return false;

Expand Down Expand Up @@ -390,6 +403,8 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP

void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
{
AssertLockHeld(cs);

CAddrInfo* pinfo = Find(addr);

// if not found, bail out
Expand All @@ -412,7 +427,9 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)

CAddrInfo CAddrMan::Select_(bool newOnly)
{
if (size() == 0)
AssertLockHeld(cs);

if (vRandom.empty())
return CAddrInfo();

if (newOnly && nNew == 0)
Expand Down Expand Up @@ -460,6 +477,7 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
#ifdef DEBUG_ADDRMAN
int CAddrMan::Check_()
{
AssertLockHeld(cs);
std::set<int> setTried;
std::map<int, int> mapNew;

Expand Down Expand Up @@ -537,6 +555,8 @@ int CAddrMan::Check_()

void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network)
{
AssertLockHeld(cs);

size_t nNodes = vRandom.size();
if (max_pct != 0) {
nNodes = max_pct * nNodes / 100;
Expand Down Expand Up @@ -569,6 +589,8 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size

void CAddrMan::Connected_(const CService& addr, int64_t nTime)
{
AssertLockHeld(cs);

CAddrInfo* pinfo = Find(addr);

// if not found, bail out
Expand All @@ -589,6 +611,8 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)

void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
{
AssertLockHeld(cs);

CAddrInfo* pinfo = Find(addr);

// if not found, bail out
Expand Down Expand Up @@ -624,6 +648,8 @@ CAddrInfo CAddrMan::GetAddressInfo_(const CService& addr)

void CAddrMan::ResolveCollisions_()
{
AssertLockHeld(cs);

for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) {
int id_new = *it;

Expand Down Expand Up @@ -683,6 +709,8 @@ void CAddrMan::ResolveCollisions_()

CAddrInfo CAddrMan::SelectTriedCollision_()
{
AssertLockHeld(cs);

if (m_tried_collisions.size() == 0) return CAddrInfo();

std::set<int>::iterator it = m_tried_collisions.begin();
Expand Down
74 changes: 40 additions & 34 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class CAddrMan
*/
template <typename Stream>
void Serialize(Stream& s_) const
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);

Expand Down Expand Up @@ -301,10 +302,11 @@ class CAddrMan

template <typename Stream>
void Unserialize(Stream& s_)
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);

Clear();
assert(vRandom.empty());

Format format;
s_ >> Using<CustomUintFormatter<1>>(format);
Expand Down Expand Up @@ -467,6 +469,7 @@ class CAddrMan
}

void Clear()
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
std::vector<int>().swap(vRandom);
Expand Down Expand Up @@ -503,26 +506,15 @@ class CAddrMan

//! Return the number of (unique) addresses in all tables.
size_t size() const
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs); // TODO: Cache this in an atomic to avoid this overhead
return vRandom.size();
}

//! Consistency check
void Check()
{
#ifdef DEBUG_ADDRMAN
{
LOCK(cs);
int err;
if ((err=Check_()))
LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
}
#endif
}

//! Add a single address.
bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0)
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
bool fRet = false;
Expand All @@ -537,6 +529,7 @@ class CAddrMan

//! Add multiple addresses.
bool Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty = 0)
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
int nAdd = 0;
Expand All @@ -552,6 +545,7 @@ class CAddrMan

//! Mark an entry as accessible.
void Good(const CService &addr, bool test_before_evict = true, int64_t nTime = GetAdjustedTime())
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
Check();
Expand All @@ -561,6 +555,7 @@ class CAddrMan

//! Mark an entry as connection attempted to.
void Attempt(const CService &addr, bool fCountFailure, int64_t nTime = GetAdjustedTime())
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
Check();
Expand All @@ -570,6 +565,7 @@ class CAddrMan

//! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
void ResolveCollisions()
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
Check();
Expand All @@ -579,29 +575,25 @@ class CAddrMan

//! Randomly select an address in tried that another address is attempting to evict.
CAddrInfo SelectTriedCollision()
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
CAddrInfo ret;
{
LOCK(cs);
Check();
ret = SelectTriedCollision_();
Check();
}
LOCK(cs);
Check();
const CAddrInfo ret = SelectTriedCollision_();
Check();
return ret;
}

/**
* Choose an address to connect to.
*/
CAddrInfo Select(bool newOnly = false)
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
CAddrInfo addrRet;
{
LOCK(cs);
Check();
addrRet = Select_(newOnly);
Check();
}
LOCK(cs);
Check();
const CAddrInfo addrRet = Select_(newOnly);
Check();
return addrRet;
}

Expand All @@ -613,19 +605,19 @@ class CAddrMan
* @param[in] network Select only addresses of this network (nullopt = all).
*/
std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network)
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
Check();
std::vector<CAddress> vAddr;
{
LOCK(cs);
GetAddr_(vAddr, max_addresses, max_pct, network);
}
GetAddr_(vAddr, max_addresses, max_pct, network);
Check();
return vAddr;
}

//! Outer function for Connected_()
void Connected(const CService &addr, int64_t nTime = GetAdjustedTime())
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
Check();
Expand All @@ -634,6 +626,7 @@ class CAddrMan
}

void SetServices(const CService &addr, ServiceFlags nServices)
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
Check();
Expand All @@ -660,8 +653,8 @@ class CAddrMan
FastRandomContext insecure_rand;

private:
//! critical section to protect the inner data structures
mutable RecursiveMutex cs;
//! A mutex to protect the inner data structures.
mutable Mutex cs;

//! Serialization versions.
enum Format : uint8_t {
Expand Down Expand Up @@ -754,6 +747,19 @@ class CAddrMan
//! Return a random to-be-evicted tried table address.
CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs);

//! Consistency check
void Check()
EXCLUSIVE_LOCKS_REQUIRED(cs)
{
#ifdef DEBUG_ADDRMAN
AssertLockHeld(cs);
const int err = Check_();
if (err) {
LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
}
#endif
}

#ifdef DEBUG_ADDRMAN
//! Perform consistency check. Returns an error code or zero.
int Check_() EXCLUSIVE_LOCKS_REQUIRED(cs);
Expand Down
14 changes: 5 additions & 9 deletions src/compat/assumptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@
# error "Dash Core cannot be compiled without assertions."
#endif

// Assumption: We assume a C++11 (ISO/IEC 14882:2011) compiler (minimum requirement).
// Example(s): We assume the presence of C++11 features everywhere :-)
// Note: MSVC does not report the expected __cplusplus value due to legacy
// reasons.
#if !defined(_MSC_VER)
// ISO Standard C++11 [cpp.predefined]p1:
// "The name __cplusplus is defined to the value 201103L when compiling a C++
// Assumption: We assume a C++17 (ISO/IEC 14882:2017) compiler (minimum requirement).
// Example(s): We assume the presence of C++17 features everywhere :-)
// ISO Standard C++17 [cpp.predefined]p1:
// "The name __cplusplus is defined to the value 201703L when compiling a C++
// translation unit."
static_assert(__cplusplus >= 201103L, "C++11 standard assumed");
#endif
static_assert(__cplusplus >= 201703L, "C++17 standard assumed");

// Assumption: We assume the floating-point types to fulfill the requirements of
// IEC 559 (IEEE 754) standard.
Expand Down
Loading

0 comments on commit 4ce7ed8

Please sign in to comment.