Skip to content

Commit d09af88

Browse files
committed
Merge #2960: Dash backports2 duddino
33dbf8d Remove unused function (Duddino) 865b841 [trivial] Fix comment for ForceSetArg() (bitcoin#10479) (laanwj) 399ad8a [Consensus] Add constant for maximum stack size (bitcoin#10313) (Pieter Wuille) cc040e2 tests: fix spurious addrman test failure (bitcoin#10429) (laanwj) 74a9381 Bloomfilter: parameter variables made constant (bitcoin#9750) (Wladimir J. van der Laan) 5f84ea2 [net] Added SetSocketNoDelay() utility function (bitcoin#10061) (Pieter Wuille) 2770e5a Output line to debug.log when IsInitialBlockDownload latches to false (bitcoin#10388) (laanwj) 9026e67 tests: Correct testcase in script_tests.json for large number OP_EQUAL (bitcoin#10405) (Wladimir J. van der Laan) 3819bbd Add a Log for when nodestates are cleared for peers (laanwj) Pull request description: Cherry-pick of bitcoin backports, following the order of dashpay#2992. Some commits had already been backported, as such they have been skipped. Refer to the linked bitcoin PR for more information on each commit ACKs for top commit: 33dbf8d Parad0x963: utACK 33dbf8d Liquid369: utACK 33dbf8d Fuzzbawls: utACK 33dbf8d Tree-SHA512: 274a206618f8257c672f73dad7f16741ef0e86e99320a4cb96a9b63a3e157e98a0f8eaede45c26cc35309be4438d4e9a28fd526144b11e023bb2fdf81423987d
2 parents b99b06f + 33dbf8d commit d09af88

File tree

14 files changed

+42
-22
lines changed

14 files changed

+42
-22
lines changed

src/bloom.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455
2020
#define LN2 0.6931471805599453094172321214581765680755001343602552
2121

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

113-
void CBloomFilter::reset(unsigned int nNewTweak)
112+
void CBloomFilter::reset(const unsigned int nNewTweak)
114113
{
115114
clear();
116115
nTweak = nNewTweak;
@@ -232,7 +231,7 @@ void CBloomFilter::UpdateEmptyFull()
232231
isEmpty = empty;
233232
}
234233

235-
CRollingBloomFilter::CRollingBloomFilter(unsigned int nElements, double fpRate)
234+
CRollingBloomFilter::CRollingBloomFilter(const unsigned int nElements, const double fpRate)
236235
{
237236
double logFpRate = log(fpRate);
238237
/* The optimal number of hash functions is log(fpRate) / log(0.5), but

src/bloom.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CBloomFilter
6363
* It should generally always be a random value (and is largely only exposed for unit testing)
6464
* nFlags should be one of the BLOOM_UPDATE_* enums (not _MASK)
6565
*/
66-
CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweak, unsigned char nFlagsIn);
66+
CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweak, unsigned char nFlagsIn);
6767
CBloomFilter() : isFull(true), isEmpty(false), nHashFuncs(0), nTweak(0), nFlags(0) {}
6868

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

7979
void clear();
80-
void reset(unsigned int nNewTweak);
80+
void reset(const unsigned int nNewTweak);
8181

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

118118
void insert(const std::vector<unsigned char>& vKey);
119119
void insert(const uint256& hash);

src/chainparamsbase.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,4 @@ const CBaseChainParams& BaseParams();
5757
/** Sets the params returned by Params() to those for the given network. */
5858
void SelectBaseParams(const std::string& chain);
5959

60-
/**
61-
* Returns the appropriate chain name from the program arguments.
62-
* @return CBaseChainParams::MAX_NETWORK_TYPES if an invalid combination is given. CBaseChainParams::MAIN by default.
63-
*/
64-
std::string ChainNameFromCommandLine();
65-
6660
#endif // PIVX_CHAINPARAMSBASE_H

src/compat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <net/if.h>
4040
#include <netdb.h>
4141
#include <netinet/in.h>
42+
#include <netinet/tcp.h>
4243
#include <sys/fcntl.h>
4344
#include <sys/mman.h>
4445
#include <sys/socket.h>

src/net.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,13 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
11151115
return;
11161116
}
11171117

1118-
if (IsBanned(addr) && !whitelisted) {
1119-
LogPrint(BCLog::NET, "connection from %s dropped (banned)\n", addr.ToString());
1118+
// According to the internet TCP_NODELAY is not carried into accepted sockets
1119+
// on all platforms. Set it again here just to be sure.
1120+
SetSocketNoDelay(hSocket);
1121+
1122+
if (IsBanned(addr) && !whitelisted)
1123+
{
1124+
LogPrintf("connection from %s dropped (banned)\n", addr.ToString());
11201125
CloseSocket(hSocket);
11211126
return;
11221127
}

src/net_processing.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ void PeerLogicValidation::FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTim
487487
nPreferredDownload -= state->fPreferredDownload;
488488

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

492493
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats)

src/netbase.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ SOCKET CreateSocket(const CService& addrConnect)
511511
// Different way of disabling SIGPIPE on BSD
512512
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
513513
#endif
514+
// Disable Nagle's algorithm
515+
SetSocketNoDelay(hSocket);
514516

515517
// Set to non-blocking
516518
if (!SetSocketNonBlocking(hSocket, true)) {
@@ -779,6 +781,13 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
779781
return true;
780782
}
781783

784+
bool SetSocketNoDelay(SOCKET& hSocket)
785+
{
786+
int set = 1;
787+
int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int));
788+
return rc == 0;
789+
}
790+
782791
void InterruptSocks5(bool interrupt)
783792
{
784793
interruptSocks5Recv = interrupt;

src/netbase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ std::string NetworkErrorString(int err);
6262
bool CloseSocket(SOCKET& hSocket);
6363
/** Disable or enable blocking-mode for a socket */
6464
bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking);
65+
/** Set the TCP_NODELAY flag on a socket */
66+
bool SetSocketNoDelay(SOCKET& hSocket);
6567
/**
6668
* Convert milliseconds to a struct timeval for e.g. select.
6769
*/

src/script/interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
988988
}
989989

990990
// Size limits
991-
if (stack.size() + altstack.size() > 1000)
991+
if (stack.size() + altstack.size() > MAX_STACK_SIZE)
992992
return set_error(serror, SCRIPT_ERR_STACK_SIZE);
993993
}
994994
}

src/script/script.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ static const int MAX_PUBKEYS_PER_MULTISIG = 20;
3232
// Maximum script length in bytes
3333
static const int MAX_SCRIPT_SIZE = 10000;
3434

35+
// Maximum number of values on script interpreter stack
36+
static const int MAX_STACK_SIZE = 1000;
37+
3538
// Threshold for nLockTime: below this value it is interpreted as block number,
3639
// otherwise as UNIX timestamp.
3740
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC

0 commit comments

Comments
 (0)