Skip to content

Commit

Permalink
Merge pull request #4742 from vijaydasmp/bp2002
Browse files Browse the repository at this point in the history
Merge bitcoin#17154,16569,17351,13716,17084,18391,16821,17140
  • Loading branch information
PastaPastaPasta authored Apr 3, 2022
2 parents 77e8428 + 106dedb commit 279686f
Show file tree
Hide file tree
Showing 36 changed files with 288 additions and 170 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ source software which enables the use of this currency.
Pre-Built Binary
----------------

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

License
Expand Down
2 changes: 1 addition & 1 deletion contrib/init/dashd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ expect fork

respawn
respawn limit 5 120
kill timeout 60
kill timeout 600

pre-start script
# this will catch non-existent config files
Expand Down
2 changes: 1 addition & 1 deletion contrib/init/dashd.init
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ start() {

stop() {
echo -n $"Stopping $prog: "
killproc $prog
killproc $prog -t600
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
Expand Down
1 change: 1 addition & 0 deletions contrib/init/dashd.service
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ExecStart=/usr/bin/dashd -daemon \
Type=forking
PIDFile=/run/dashd/dashd.pid
Restart=on-failure
TimeoutStopSec=600

# Directory creation and permissions
####################################
Expand Down
3 changes: 1 addition & 2 deletions doc/reduce-memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ The size of some in-memory caches can be reduced. As caches trade off memory usa

## Number of peers

- `-maxconnections=<n>` - the maximum number of connections, this defaults to `125`. Each active connection takes up some memory. Only significant if incoming
connections are enabled, otherwise the number of connections will never be more than `8`.
- `-maxconnections=<n>` - the maximum number of connections, this defaults to `125`. Each active connection takes up some memory. Only significant if incoming connections are enabled, otherwise the number of connections will never be more than `10`. Of the 10 outbound peers, there can be 8 full outgoing connections and 2 -blocksonly peers, in which case they are block/addr peers, but not tx peers.

## Thread configuration

Expand Down
16 changes: 11 additions & 5 deletions doc/reduce-traffic.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ Reduce Traffic

Some node operators need to deal with bandwidth caps imposed by their ISPs.

By default, Dash Core allows up to 125 connections to different peers, 8 of
which are outbound. You can therefore, have at most 117 inbound connections.
By default, Dash Core allows up to 125 connections to different peers, 10 of
which are outbound. You can therefore, have at most 115 inbound connections.
Of the 10 outbound peers, there can be 8 full outgoing connections and 2 with
the -blocksonly mode turned on. You can therefore, have at most 115 inbound connections.

The default settings can result in relatively significant traffic consumption.

Expand All @@ -26,7 +28,7 @@ calculating the target.

## 2. Disable "listening" (`-listen=0`)

Disabling listening will result in fewer nodes connected (remember the maximum of 8
Disabling listening will result in fewer nodes connected (remember the maximum of 10
outbound peers). Fewer nodes will result in less traffic usage as you are relaying
blocks and transactions to fewer nodes.

Expand All @@ -44,7 +46,11 @@ with other peers, you can disable transaction relay.
Be reminded of the effects of this setting.

- Fee estimation will no longer work.
- Not relaying other's transactions could hurt your privacy if used while a
wallet is loaded or if you use the node to broadcast transactions.
- It sets the flag "-walletbroadcast" to be "0", only if it is currently unset.
Doing so disables the automatic broadcasting of transactions from wallet. Not
relaying other's transactions could hurt your privacy if used while a wallet
is loaded or if you use the node to broadcast transactions.
- If a peer is whitelisted and "-whitelistforcerelay" is set to "1" (which will
also set "whitelistrelay" to "1"), we will still receive and relay their transactions.
- It makes block propagation slower because compact block relay can only be
used when transaction relay is enabled.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ endif
libdash_cli_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libdash_cli_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libdash_cli_a_SOURCES = \
compat/stdin.h \
compat/stdin.cpp \
rpc/client.cpp \
$(BITCOIN_CORE_H)

Expand Down
7 changes: 1 addition & 6 deletions src/coinjoin/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <coinjoin/util.h>
#include <consensus/validation.h>
#include <net.h>
#include <policy/fees.h>
#include <policy/policy.h>
Expand Down Expand Up @@ -306,11 +305,7 @@ bool CTransactionBuilder::Commit(std::string& strResult)
return false;
}

CValidationState state;
if (!pwallet->CommitTransaction(tx, {}, {}, state)) {
strResult = state.GetRejectReason();
return false;
}
pwallet->CommitTransaction(tx, {}, {});

fKeepKeys = true;

Expand Down
72 changes: 72 additions & 0 deletions src/compat/stdin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include <config/dash-config.h>
#endif

#include <cstdio> // for fileno(), stdin

#ifdef WIN32
#include <windows.h> // for SetStdinEcho()
#include <io.h> // for isatty()
#else
#include <termios.h> // for SetStdinEcho()
#include <unistd.h> // for SetStdinEcho(), isatty()
#include <poll.h> // for StdinReady()
#endif

#include <compat/stdin.h>

// https://stackoverflow.com/questions/1413445/reading-a-password-from-stdcin
void SetStdinEcho(bool enable)
{
#ifdef WIN32
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin, &mode);
if (!enable) {
mode &= ~ENABLE_ECHO_INPUT;
} else {
mode |= ENABLE_ECHO_INPUT;
}
SetConsoleMode(hStdin, mode);
#else
struct termios tty;
tcgetattr(STDIN_FILENO, &tty);
if (!enable) {
tty.c_lflag &= ~ECHO;
} else {
tty.c_lflag |= ECHO;
}
(void)tcsetattr(STDIN_FILENO, TCSANOW, &tty);
#endif
}

bool StdinTerminal()
{
#ifdef WIN32
return _isatty(_fileno(stdin));
#else
return isatty(fileno(stdin));
#endif
}

bool StdinReady()
{
if (!StdinTerminal()) {
return true;
}
#ifdef WIN32
return false;
#else
struct pollfd fds;
fds.fd = 0; /* this is STDIN */
fds.events = POLLIN;
return poll(&fds, 1, 0) == 1;
#endif
}

NoechoInst::NoechoInst() { SetStdinEcho(false); }
NoechoInst::~NoechoInst() { SetStdinEcho(true); }
18 changes: 18 additions & 0 deletions src/compat/stdin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_COMPAT_STDIN_H
#define BITCOIN_COMPAT_STDIN_H

struct NoechoInst {
NoechoInst();
~NoechoInst();
};

#define NO_STDIN_ECHO() NoechoInst _no_echo

bool StdinTerminal();
bool StdinReady();

#endif // BITCOIN_COMPAT_STDIN_H
33 changes: 32 additions & 1 deletion src/dash-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <support/events.h>

#include <univalue.h>
#include <compat/stdin.h>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

Expand Down Expand Up @@ -55,7 +56,8 @@ static void SetupCliArgs()
gArgs.AddArg("-rpcwait", "Wait for RPC server to start", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-rpcwallet=<walletname>", "Send RPC for non-default wallet on RPC server (needs to exactly match corresponding -wallet option passed to dashd). This changes the RPC endpoint used, e.g. http://127.0.0.1:9998/wallet/<walletname>", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-stdin", "Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases). When combined with -stdinrpcpass, the first line from standard input is used for the RPC password.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-stdinrpcpass", "Read RPC password from standard input as a single line. When combined with -stdin, the first line from standard input is used for the RPC password.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-stdinrpcpass", "Read RPC password from standard input as a single line. When combined with -stdin, the first line from standard input is used for the RPC password. When combined with -stdinwalletpassphrase, -stdinrpcpass consumes the first line, and -stdinwalletpassphrase consumes the second.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-stdinwalletpassphrase", "Read wallet passphrase from standard input as a single line. When combined with -stdin, the first line from standard input is used for the wallet passphrase.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);

SetupChainParamsBaseOptions();

Expand Down Expand Up @@ -441,18 +443,47 @@ static int CommandLineRPC(int argc, char *argv[])
}
std::string rpcPass;
if (gArgs.GetBoolArg("-stdinrpcpass", false)) {
NO_STDIN_ECHO();
if (!StdinReady()) {
fputs("RPC password> ", stderr);
fflush(stderr);
}
if (!std::getline(std::cin, rpcPass)) {
throw std::runtime_error("-stdinrpcpass specified but failed to read from standard input");
}
if (StdinTerminal()) {
fputc('\n', stdout);
}
gArgs.ForceSetArg("-rpcpassword", rpcPass);
}
std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
if (gArgs.GetBoolArg("-stdinwalletpassphrase", false)) {
NO_STDIN_ECHO();
std::string walletPass;
if (args.size() < 1 || args[0].substr(0, 16) != "walletpassphrase") {
throw std::runtime_error("-stdinwalletpassphrase is only applicable for walletpassphrase(change)");
}
if (!StdinReady()) {
fputs("Wallet passphrase> ", stderr);
fflush(stderr);
}
if (!std::getline(std::cin, walletPass)) {
throw std::runtime_error("-stdinwalletpassphrase specified but failed to read from standard input");
}
if (StdinTerminal()) {
fputc('\n', stdout);
}
args.insert(args.begin() + 1, walletPass);
}
if (gArgs.GetBoolArg("-stdin", false)) {
// Read one arg per line from stdin and append
std::string line;
while (std::getline(std::cin, line)) {
args.push_back(line);
}
if (StdinTerminal()) {
fputc('\n', stdout);
}
}
std::unique_ptr<BaseRequestHandler> rh;
std::string method;
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ void SetupServerArgs()
gArgs.AddArg("-blocksdir=<dir>", "Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-blocknotify=<cmd>", "Execute command when the best block changes (%s in cmd is replaced by block hash)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-blockreconstructionextratxn=<n>", strprintf("Extra transactions to keep in memory for compact block reconstructions (default: %u)", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-blocksonly", strprintf("Whether to reject transactions from network peers. Transactions from the wallet or RPC are not affected. (default: %u)", DEFAULT_BLOCKSONLY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-blocksonly", strprintf("Whether to reject transactions from network peers. Automatic broadcast and rebroadcast of any transactions from inbound peers is disabled, unless '-whitelistforcerelay' is '1', in which case whitelisted peers' transactions will be relayed. RPC transactions are not affected. (default: %u)", DEFAULT_BLOCKSONLY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
Expand Down
13 changes: 3 additions & 10 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <amount.h>
#include <coinjoin/client.h>
#include <consensus/validation.h>
#include <interfaces/chain.h>
#include <interfaces/handler.h>
#include <policy/fees.h>
Expand Down Expand Up @@ -289,20 +288,14 @@ class WalletImpl : public Wallet
}
return tx;
}
bool commitTransaction(CTransactionRef tx,
void commitTransaction(CTransactionRef tx,
WalletValueMap value_map,
WalletOrderForm order_form,
std::string& reject_reason) override
WalletOrderForm order_form) override
{
auto locked_chain = m_wallet->chain().lock();
LOCK(m_wallet->cs_wallet);
CReserveKey m_key(m_wallet.get());
CValidationState state;
if (!m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form), state)) {
reject_reason = state.GetRejectReason();
return false;
}
return true;
m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
}
bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
bool abandonTransaction(const uint256& txid) override
Expand Down
5 changes: 2 additions & 3 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,9 @@ class Wallet
std::string& fail_reason) = 0;

//! Commit transaction.
virtual bool commitTransaction(CTransactionRef tx,
virtual void commitTransaction(CTransactionRef tx,
WalletValueMap value_map,
WalletOrderForm order_form,
std::string& reject_reason) = 0;
WalletOrderForm order_form) = 0;

//! Return whether transaction can be abandoned.
virtual bool transactionCanBeAbandoned(const uint256& txid) = 0;
Expand Down
Loading

0 comments on commit 279686f

Please sign in to comment.