Skip to content

Commit

Permalink
Merge pull request #5795 from PastaPastaPasta/develop-trivial-2024-01-01
Browse files Browse the repository at this point in the history
backports: trivial 2024 01 01
  • Loading branch information
PastaPastaPasta authored Jan 2, 2024
2 parents 7d9c572 + 2ad5d26 commit 2e4b9e2
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 141 deletions.
14 changes: 7 additions & 7 deletions depends/funcs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -171,40 +171,40 @@ $($(1)_fetched):
mkdir -p $$(@D) $(SOURCES_PATH)
rm -f $$@
touch $$@
cd $$(@D); $(call $(1)_fetch_cmds,$(1))
cd $$(@D); $($(1)_fetch_cmds)
cd $($(1)_source_dir); $(foreach source,$($(1)_all_sources),$(build_SHA256SUM) $(source) >> $$(@);)
touch $$@
$($(1)_extracted): | $($(1)_fetched)
echo Extracting $(1)...
mkdir -p $$(@D)
cd $$(@D); $(call $(1)_extract_cmds,$(1))
cd $$(@D); $($(1)_extract_cmds)
touch $$@
$($(1)_preprocessed): | $($(1)_extracted)
echo Preprocessing $(1)...
mkdir -p $$(@D) $($(1)_patch_dir)
$(foreach patch,$($(1)_patches),cd $(PATCHES_PATH)/$(1); cp $(patch) $($(1)_patch_dir) ;)
cd $$(@D); $(call $(1)_preprocess_cmds, $(1))
cd $$(@D); $($(1)_preprocess_cmds)
touch $$@
$($(1)_configured): | $($(1)_dependencies) $($(1)_preprocessed)
echo Configuring $(1)...
rm -rf $(host_prefix); mkdir -p $(host_prefix)/lib; cd $(host_prefix); $(foreach package,$($(1)_all_dependencies), $(build_TAR) --no-same-owner -xf $($(package)_cached); )
mkdir -p $$(@D)
+cd $$(@D); $($(1)_config_env) $(call $(1)_config_cmds, $(1))
+cd $$(@D); $($(1)_config_env) $($(1)_config_cmds)
touch $$@
$($(1)_built): | $($(1)_configured)
echo Building $(1)...
mkdir -p $$(@D)
+cd $$(@D); $($(1)_build_env) $(call $(1)_build_cmds, $(1))
+cd $$(@D); $($(1)_build_env) $($(1)_build_cmds)
touch $$@
$($(1)_staged): | $($(1)_built)
echo Staging $(1)...
mkdir -p $($(1)_staging_dir)/$(host_prefix)
cd $($(1)_build_dir); $($(1)_stage_env) $(call $(1)_stage_cmds, $(1))
cd $($(1)_build_dir); $($(1)_stage_env) $($(1)_stage_cmds)
rm -rf $($(1)_extract_dir)
touch $$@
$($(1)_postprocessed): | $($(1)_staged)
echo Postprocessing $(1)...
cd $($(1)_staging_prefix_dir); $(call $(1)_postprocess_cmds)
cd $($(1)_staging_prefix_dir); $($(1)_postprocess_cmds)
touch $$@
$($(1)_cached): | $($(1)_dependencies) $($(1)_postprocessed)
echo Caching $(1)...
Expand Down
5 changes: 4 additions & 1 deletion doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,10 @@ A few guidelines for introducing and reviewing new RPC interfaces:

- *Rationale*: Consistency with the existing interface.

- Argument naming: use snake case `fee_delta` (and not, e.g. camel case `feeDelta`)
- Argument and field naming: please consider whether there is already a naming
style or spelling convention in the API for the type of object in question
(`blockhash`, for example), and if so, try to use that. If not, use snake case
`fee_delta` (and not, e.g. `feedelta` or camel case `feeDelta`).

- *Rationale*: Consistency with the existing interface.

Expand Down
29 changes: 12 additions & 17 deletions src/arith_uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,21 @@ double base_uint<BITS>::getdouble() const
template <unsigned int BITS>
std::string base_uint<BITS>::GetHex() const
{
return ArithToUint256(*this).GetHex();
base_blob<BITS> b;
for (int x = 0; x < this->WIDTH; ++x) {
WriteLE32(b.begin() + x*4, this->pn[x]);
}
return b.GetHex();
}

template <unsigned int BITS>
void base_uint<BITS>::SetHex(const char* psz)
{
*this = UintToArith256(uint256S(psz));
base_blob<BITS> b;
b.SetHex(psz);
for (int x = 0; x < this->WIDTH; ++x) {
this->pn[x] = ReadLE32(b.begin() + x*4);
}
}

template <unsigned int BITS>
Expand All @@ -164,7 +172,7 @@ void base_uint<BITS>::SetHex(const std::string& str)
template <unsigned int BITS>
std::string base_uint<BITS>::ToString() const
{
return (GetHex());
return GetHex();
}

template <unsigned int BITS>
Expand All @@ -183,20 +191,7 @@ unsigned int base_uint<BITS>::bits() const
}

// Explicit instantiations for base_uint<256>
template base_uint<256>::base_uint(const std::string&);
template base_uint<256>& base_uint<256>::operator<<=(unsigned int);
template base_uint<256>& base_uint<256>::operator>>=(unsigned int);
template base_uint<256>& base_uint<256>::operator*=(uint32_t b32);
template base_uint<256>& base_uint<256>::operator*=(const base_uint<256>& b);
template base_uint<256>& base_uint<256>::operator/=(const base_uint<256>& b);
template int base_uint<256>::CompareTo(const base_uint<256>&) const;
template bool base_uint<256>::EqualTo(uint64_t) const;
template double base_uint<256>::getdouble() const;
template std::string base_uint<256>::GetHex() const;
template std::string base_uint<256>::ToString() const;
template void base_uint<256>::SetHex(const char*);
template void base_uint<256>::SetHex(const std::string&);
template unsigned int base_uint<256>::bits() const;
template class base_uint<256>;

// This implementation directly uses shifts instead of going
// through an intermediate MPI representation.
Expand Down
2 changes: 2 additions & 0 deletions src/arith_uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,6 @@ class arith_uint256 : public base_uint<256> {
uint256 ArithToUint256(const arith_uint256 &);
arith_uint256 UintToArith256(const uint256 &);

extern template class base_uint<256>;

#endif // BITCOIN_ARITH_UINT256_H
16 changes: 4 additions & 12 deletions src/crypto/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,17 +586,9 @@ std::string SHA256AutoDetect()
bool have_sse4 = false;
bool have_xsave = false;
bool have_avx = false;
bool have_avx2 = false;
bool have_x86_shani = false;
bool enabled_avx = false;

(void)AVXEnabled;
(void)have_sse4;
(void)have_avx;
(void)have_xsave;
(void)have_avx2;
(void)have_x86_shani;
(void)enabled_avx;
[[maybe_unused]] bool have_avx2 = false;
[[maybe_unused]] bool have_x86_shani = false;
[[maybe_unused]] bool enabled_avx = false;

uint32_t eax, ebx, ecx, edx;
GetCPUID(1, 0, eax, ebx, ecx, edx);
Expand Down Expand Up @@ -641,7 +633,7 @@ std::string SHA256AutoDetect()
ret += ",avx2(8way)";
}
#endif
#endif
#endif // defined(USE_ASM) && defined(HAVE_GETCPUID)

#if defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
bool have_arm_shani = false;
Expand Down
3 changes: 2 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,8 @@ void InitParameterInteraction(ArgsManager& args)
LogPrintf("%s: parameter interaction: -connect set -> setting -listen=0\n", __func__);
}

if (args.IsArgSet("-proxy")) {
std::string proxy_arg = args.GetArg("-proxy", "");
if (proxy_arg != "" && proxy_arg != "0") {
// to protect privacy, do not listen by default if a default proxy server is specified
if (args.SoftSetBoolArg("-listen", false))
LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
Expand Down
28 changes: 8 additions & 20 deletions src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ enum class IntrRecvError {
*
* @see This function can be interrupted by calling InterruptSocks5(bool).
* Sockets can be made non-blocking with SetSocketNonBlocking(const
* SOCKET&, bool).
* SOCKET&).
*/
static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, const Sock& sock)
{
Expand Down Expand Up @@ -514,7 +514,7 @@ std::unique_ptr<Sock> CreateSockTCP(const CService& address_family)
SetSocketNoDelay(hSocket);

// Set the non-blocking option on the socket.
if (!SetSocketNonBlocking(hSocket, true)) {
if (!SetSocketNonBlocking(hSocket)) {
CloseSocket(hSocket);
LogPrintf("Error setting socket to non-blocking: %s\n", NetworkErrorString(WSAGetLastError()));
return nullptr;
Expand Down Expand Up @@ -711,28 +711,16 @@ bool LookupSubNet(const std::string& strSubnet, CSubNet& ret, DNSLookupFn dns_lo
return false;
}

bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking)
bool SetSocketNonBlocking(const SOCKET& hSocket)
{
if (fNonBlocking) {
#ifdef WIN32
u_long nOne = 1;
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) {
u_long nOne = 1;
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) {
#else
int fFlags = fcntl(hSocket, F_GETFL, 0);
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
int fFlags = fcntl(hSocket, F_GETFL, 0);
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
#endif
return false;
}
} else {
#ifdef WIN32
u_long nZero = 0;
if (ioctlsocket(hSocket, FIONBIO, &nZero) == SOCKET_ERROR) {
#else
int fFlags = fcntl(hSocket, F_GETFL, 0);
if (fcntl(hSocket, F_SETFL, fFlags & ~O_NONBLOCK) == SOCKET_ERROR) {
#endif
return false;
}
return false;
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/netbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
*/
bool ConnectThroughProxy(const proxyType& proxy, const std::string& strDest, uint16_t port, const Sock& sock, int nTimeout, bool& outProxyConnectionFailed);

/** Disable or enable blocking-mode for a socket */
bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking);
/** Enable non-blocking mode for a socket */
bool SetSocketNonBlocking(const SOCKET& hSocket);
/** Set the TCP_NODELAY flag on a socket */
bool SetSocketNoDelay(const SOCKET& hSocket);
void InterruptSocks5(bool interrupt);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public Q_SLOTS:
/** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */
void showNormalIfMinimized() { showNormalIfMinimized(false); }
void showNormalIfMinimized(bool fToggleHidden);
/** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */
/** Simply calls showNormalIfMinimized(true) */
void toggleHidden();

/** called by a timer to check if ShutdownRequested() has been set **/
Expand Down
6 changes: 0 additions & 6 deletions src/support/lockedpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,6 @@ PosixLockedPageAllocator::PosixLockedPageAllocator()
#endif
}

// Some systems (at least OS X) do not define MAP_ANONYMOUS yet and define
// MAP_ANON which is deprecated
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif

void *PosixLockedPageAllocator::AllocateLocked(size_t len, bool *lockingSuccess)
{
void *addr;
Expand Down
2 changes: 1 addition & 1 deletion src/util/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void assertion_fail(const char* file, int line, const char* func, const char* as

/** Helper for Assert()/Assume() */
template <bool IS_ASSERT, typename T>
T&& inline_assertion_check(T&& val, const char* file, int line, const char* func, const char* assertion)
T&& inline_assertion_check(T&& val, [[maybe_unused]] const char* file, [[maybe_unused]] int line, [[maybe_unused]] const char* func, [[maybe_unused]] const char* assertion)
{
if constexpr (IS_ASSERT
#ifdef ABORT_ON_FAILED_ASSUME
Expand Down
4 changes: 3 additions & 1 deletion src/util/threadnames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <config/bitcoin-config.h>
#endif

#include <string>
#include <thread>
#include <utility>

#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
#include <pthread.h>
Expand All @@ -16,7 +18,7 @@
#include <util/threadnames.h>

#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h> // For prctl, PR_SET_NAME, PR_GET_NAME
#include <sys/prctl.h>
#endif

//! Set the thread's name at the process level. Does not affect the
Expand Down
28 changes: 28 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ how many jobs to run, append `--jobs=n`
The individual tests and the test_runner harness have many command-line
options. Run `test/functional/test_runner.py -h` to see them all.

#### Speed up test runs with a ramdisk

If you have available RAM on your system you can create a ramdisk to use as the `cache` and `tmp` directories for the functional tests in order to speed them up.
Speed-up amount varies on each system (and according to your ram speed and other variables), but a 2-3x speed-up is not uncommon.

To create a 4GB ramdisk on Linux at `/mnt/tmp/`:

```bash
sudo mkdir -p /mnt/tmp
sudo mount -t tmpfs -o size=4g tmpfs /mnt/tmp/
```

Configure the size of the ramdisk using the `size=` option.
The size of the ramdisk needed is relative to the number of concurrent jobs the test suite runs.
For example running the test suite with `--jobs=100` might need a 16GB ramdisk, but running with `--jobs=4` will only need a 4GB ramdisk.

To use, run the test suite specifying the ramdisk as the `cachedir` and `tmpdir`:

```bash
test/functional/test_runner.py --cachedir=/mnt/tmp/cache --tmpdir=/mnt/tmp
```

Once finished with the tests and the disk, and to free the ram, simply unmount the disk:

```bash
sudo umount /mnt/tmp
```

#### Troubleshooting and debugging test failures

##### Resource contention
Expand Down
72 changes: 72 additions & 0 deletions test/lint/lint-python-mutable-default-parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python3
#
# Copyright (c) 2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

"""
Detect when a mutable list or dict is used as a default parameter value in a Python function.
"""

import subprocess
import sys


def main():
command = [
"git",
"grep",
"-E",
r"^\s*def [a-zA-Z0-9_]+\(.*=\s*(\[|\{)",
"--",
"*.py",
]
output = subprocess.run(command, stdout=subprocess.PIPE, universal_newlines=True)
if len(output.stdout) > 0:
error_msg = (
"A mutable list or dict seems to be used as default parameter value:\n\n"
f"{output.stdout}\n"
f"{example()}"
)
print(error_msg)
sys.exit(1)
else:
sys.exit(0)


def example():
return """This is how mutable list and dict default parameter values behave:
>>> def f(i, j=[], k={}):
... j.append(i)
... k[i] = True
... return j, k
...
>>> f(1)
([1], {1: True})
>>> f(1)
([1, 1], {1: True})
>>> f(2)
([1, 1, 2], {1: True, 2: True})
The intended behaviour was likely:
>>> def f(i, j=None, k=None):
... if j is None:
... j = []
... if k is None:
... k = {}
... j.append(i)
... k[i] = True
... return j, k
...
>>> f(1)
([1], {1: True})
>>> f(1)
([1], {1: True})
>>> f(2)
([2], {2: True})"""


if __name__ == "__main__":
main()
Loading

0 comments on commit 2e4b9e2

Please sign in to comment.