Skip to content

Commit

Permalink
Merge pull request dashpay#4396 from Munkybooty/backports-0.18-pr16
Browse files Browse the repository at this point in the history
Backports 0.18 pr16
  • Loading branch information
PastaPastaPasta authored Sep 14, 2021
2 parents 43183f6 + 7006a38 commit dfea329
Show file tree
Hide file tree
Showing 34 changed files with 166 additions and 122 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,11 @@ after_success:
BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports"
- stage: test
name: 'Win64 [GOAL: deploy] [no gui tests]'
name: 'Win64 [GOAL: deploy] [no gui or functional tests]'
env: >-
HOST=x86_64-w64-mingw32
PACKAGES="python3 nsis g++-mingw-w64-x86-64 wine-binfmt wine64"
RUN_FUNCTIONAL_TESTS=false
GOAL="deploy"
BITCOIN_CONFIG="--enable-reduce-exports --disable-gui-tests"
Expand Down
34 changes: 29 additions & 5 deletions contrib/init/dashd.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,45 @@
# See "man systemd.service" for details.

# Note that almost all daemon options could be specified in
# /etc/dash/dash.conf
# /etc/dash/dash.conf, except for those explicitly specified as arguments
# in ExecStart=

[Unit]
Description=Dash daemon
After=network.target

[Service]
ExecStart=/usr/bin/dashd -daemon -conf=/etc/dash/dash.conf -pid=/run/dashd/dashd.pid
# Creates /run/dash owned by dashcore
RuntimeDirectory=dashd
User=dashcore
ExecStart=/usr/bin/dashd -daemon \
-pid=/run/dashd/dashd.pid \
-conf=/etc/dash/dash.conf \
-datadir=/var/lib/dashd

# Process management
####################

Type=forking
PIDFile=/run/dashd/dashd.pid
Restart=on-failure

# Directory creation and permissions
####################################

# Run as dash:dash
User=dashcore
Group=dashcore

# /run/dashd
RuntimeDirectory=dashd
RuntimeDirectoryMode=0710

# /etc/dash
ConfigurationDirectory=dash
ConfigurationDirectoryMode=0710

# /var/lib/dashd
StateDirectory=dashd
StateDirectoryMode=0710

# Hardening measures
####################

Expand Down
3 changes: 2 additions & 1 deletion doc/REST-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Supported API

Given a transaction hash: returns a transaction in binary, hex-encoded binary, or JSON formats.

For full TX query capability, one must enable the transaction index via "txindex=1" command line / configuration option.
By default, this endpoint will only search the mempool.
To query for a confirmed transaction, enable the transaction index via "txindex=1" command line / configuration option.

#### Blocks
`GET /rest/block/<BLOCK-HASH>.<bin|hex|json>`
Expand Down
18 changes: 17 additions & 1 deletion doc/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ All three configurations assume several paths that might need to be adjusted.
Binary: `/usr/bin/dashd`
Configuration file: `/etc/dashcore/dash.conf`
Data directory: `/var/lib/dashd`
PID file: `/var/run/dashd/dashd.pid` (OpenRC and Upstart) or `/var/lib/dashd/dashd.pid` (systemd)
PID file: `/var/run/dashd/dashd.pid` (OpenRC and Upstart) or `/run/dashd/dashd.pid` (systemd)
Lock file: `/var/lock/subsys/dashd` (CentOS)

The configuration file, PID directory (if applicable) and data directory
Expand All @@ -65,6 +65,22 @@ reasons to make the configuration file and data directory only readable by the
dashcore user and group. Access to dash-cli and other dashd rpc clients
can then be controlled by group membership.

NOTE: When using the systemd .service file, the creation of the aforementioned
directories and the setting of their permissions is automatically handled by
systemd. Directories are given a permission of 710, giving the dashcore user and group
access to files under it _if_ the files themselves give permission to the
dashcore user and group to do so (e.g. when `-sysperms` is specified). This does not allow
for the listing of files under the directory.

NOTE: It is not currently possible to override `datadir` in
`/etc/dash/dash.conf` with the current systemd, OpenRC, and Upstart init
files out-of-the-box. This is because the command line options specified in the
init files take precedence over the configurations in
`/etc/dash/dash.conf`. However, some init systems have their own
configuration mechanisms that would allow for overriding the command line
options specified in the init files (e.g. setting `BITCOIND_DATADIR` for
OpenRC).

### macOS

Binary: `/usr/local/bin/dashd`
Expand Down
17 changes: 17 additions & 0 deletions doc/release-notes/release-notes-pr12255.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
systemd init file
=========

The systemd init file (`contrib/init/dashd.service`) has been changed to use
`/var/lib/dashd` as the data directory instead of `~dash/.dash`. This
change makes Dash Core more consistent with other services, and makes the
systemd init config more consistent with existing Upstart and OpenRC configs.

The configuration, PID, and data directories are now completely managed by
systemd, which will take care of their creation, permissions, etc. See
[`systemd.exec (5)`](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RuntimeDirectory=)
for more details.

When using the provided init files under `contrib/init`, overriding the
`datadir` option in `/etc/dash/dash.conf` will have no effect. This is
because the command line arguments specified in the init files take precedence
over the options specified in `/etc/dash/dash.conf`.
16 changes: 16 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,22 @@ bool AppInitParameterInteraction()
dustRelayFee = CFeeRate(n);
}

// This is required by both the wallet and node
if (gArgs.IsArgSet("-maxtxfee"))
{
CAmount nMaxFee = 0;
if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee))
return InitError(AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", "")));
if (nMaxFee > HIGH_MAX_TX_FEE)
InitWarning(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction."));
maxTxFee = nMaxFee;
if (CFeeRate(maxTxFee, 1000) < ::minRelayTxFee)
{
return InitError(strprintf(_("Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"),
gArgs.GetArg("-maxtxfee", ""), ::minRelayTxFee.ToString()));
}
}

fRequireStandard = !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
if (chainparams.RequireStandard() && !fRequireStandard)
return InitError(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.NetworkIDString()));
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class WalletImpl : public Wallet
}
std::vector<std::string> getDestValues(const std::string& prefix) override
{
LOCK(m_wallet.cs_wallet);
return m_wallet.GetDestValues(prefix);
}
void lockCoin(const COutPoint& output) override
Expand Down
2 changes: 1 addition & 1 deletion src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ bool CNetAddr::IsLocal() const
return true;
}

return false;
return false;
}

bool CNetAddr::IsValid() const
Expand Down
4 changes: 2 additions & 2 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, int heig
clientmodel->cachedBestHeaderHeight = height;
clientmodel->cachedBestHeaderTime = blockTime;
}
// if we are in-sync, update the UI regardless of last update time
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
// if we are in-sync or if we notify a header update, update the UI regardless of last update time
if (fHeader || !initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
//pass an async signal to the UI thread
QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
Q_ARG(int, height),
Expand Down
8 changes: 7 additions & 1 deletion src/qt/modaloverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void ModalOverlay::setKnownBestHeight(int count, const QDateTime& blockDate)
if (count > bestHeaderHeight) {
bestHeaderHeight = count;
bestHeaderDate = blockDate;
UpdateHeaderSyncLabel();
}
}

Expand Down Expand Up @@ -150,11 +151,16 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVeri
if (estimateNumHeadersLeft < HEADER_HEIGHT_DELTA_SYNC && hasBestHeader) {
ui->numberOfBlocksLeft->setText(QString::number(bestHeaderHeight - count));
} else {
ui->numberOfBlocksLeft->setText(tr("Unknown. Syncing Headers (%1)...").arg(bestHeaderHeight));
UpdateHeaderSyncLabel();
ui->expectedTimeLeft->setText(tr("Unknown..."));
}
}

void ModalOverlay::UpdateHeaderSyncLabel() {
int est_headers_left = bestHeaderDate.secsTo(QDateTime::currentDateTime()) / Params().GetConsensus().nPowTargetSpacing;
ui->numberOfBlocksLeft->setText(tr("Unknown. Syncing Headers (%1, %2%)...").arg(bestHeaderHeight).arg(QString::number(100.0 / (bestHeaderHeight + est_headers_left) * bestHeaderHeight, 'f', 1)));
}

void ModalOverlay::toggleVisibility()
{
showHide(layerIsVisible, true);
Expand Down
1 change: 1 addition & 0 deletions src/qt/modaloverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Q_SLOTS:
bool layerIsVisible;
bool userClosed;
bool foreverHidden;
void UpdateHeaderSyncLabel();
};

#endif // BITCOIN_QT_MODALOVERLAY_H
1 change: 1 addition & 0 deletions src/qt/test/addressbooktests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void TestAddAddressesToSendBook()
}

auto check_addbook_size = [wallet](int expected_size) {
LOCK(wallet->cs_wallet);
QCOMPARE(static_cast<int>(wallet->mapAddressBook.size()), expected_size);
};

Expand Down
10 changes: 0 additions & 10 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@
#include <memory>
#include <stdint.h>

unsigned int ParseConfirmTarget(const UniValue& value)
{
int target = value.get_int();
unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
if (target < 1 || (unsigned int)target > max_target) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u - %u", 1, max_target));
}
return (unsigned int)target;
}

/**
* Return average network hashes per second based on the last 'lookup' blocks,
* or from the last difficulty change if 'lookup' is nonpositive.
Expand Down
3 changes: 0 additions & 3 deletions src/rpc/mining.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@
/** Generate blocks (mine) */
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript);

/** Check bounds on a command line confirm target */
unsigned int ParseConfirmTarget(const UniValue& value);

#endif
12 changes: 12 additions & 0 deletions src/rpc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

#include <key_io.h>
#include <keystore.h>
#include <policy/fees.h>
#include <pubkey.h>
#include <rpc/util.h>
#include <tinyformat.h>
#include <util/strencodings.h>
#include <validation.h>

// Converts a hex string to a public key if possible
CPubKey HexToPubKey(const std::string& hex_in)
Expand Down Expand Up @@ -92,6 +94,16 @@ UniValue DescribeAddress(const CTxDestination& dest)
return boost::apply_visitor(DescribeAddressVisitor(), dest);
}

unsigned int ParseConfirmTarget(const UniValue& value)
{
int target = value.get_int();
unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
if (target < 1 || (unsigned int)target > max_target) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u - %u", 1, max_target));
}
return (unsigned int)target;
}

std::string RPCHelpMan::ToString() const
{
std::string ret;
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey

UniValue DescribeAddress(const CTxDestination& dest);

//! Parse a confirm target option and raise an RPC error if it is invalid.
unsigned int ParseConfirmTarget(const UniValue& value);

struct RPCArg {
enum class Type {
OBJ,
Expand Down
20 changes: 4 additions & 16 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ class CVectorWriter
{
return nType;
}
void seek(size_t nSize)
{
nPos += nSize;
if(nPos > vchData.size())
vchData.resize(nPos);
}
size_t size() const
{
return vchData.size() - nPos;
Expand Down Expand Up @@ -157,9 +151,11 @@ class VectorReader
* @param[in] pos Starting position. Vector index where reads should start.
*/
VectorReader(int type, int version, const std::vector<unsigned char>& data, size_t pos)
: m_type(type), m_version(version), m_data(data)
: m_type(type), m_version(version), m_data(data), m_pos(pos)
{
seek(pos);
if (m_pos > m_data.size()) {
throw std::ios_base::failure("VectorReader(...): end of data (m_pos > m_data.size())");
}
}

/**
Expand Down Expand Up @@ -202,14 +198,6 @@ class VectorReader
memcpy(dst, m_data.data() + m_pos, n);
m_pos = pos_next;
}

void seek(size_t n)
{
m_pos += n;
if (m_pos > m_data.size()) {
throw std::ios_base::failure("VectorReader::seek(): end of data");
}
}
};

/** Double ended buffer combining vector and stream-like interfaces.
Expand Down
10 changes: 5 additions & 5 deletions src/test/streams_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader)
BOOST_CHECK_THROW(reader >> d, std::ios_base::failure);

// Read a 4 bytes as a signed int from the beginning of the buffer.
reader.seek(-6);
reader >> d;
VectorReader new_reader(SER_NETWORK, INIT_PROTO_VERSION, vch, 0);
new_reader >> d;
BOOST_CHECK_EQUAL(d, 67370753); // 1,255,3,4 in little-endian base-256
BOOST_CHECK_EQUAL(reader.size(), 2);
BOOST_CHECK(!reader.empty());
BOOST_CHECK_EQUAL(new_reader.size(), 2);
BOOST_CHECK(!new_reader.empty());

// Reading after end of byte vector throws an error even if the reader is
// not totally empty.
BOOST_CHECK_THROW(reader >> d, std::ios_base::failure);
BOOST_CHECK_THROW(new_reader >> d, std::ios_base::failure);
}

BOOST_AUTO_TEST_CASE(streams_vector_reader_rvalue)
Expand Down
2 changes: 1 addition & 1 deletion src/test/txvalidationcache_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
// should fail.
// Capture this interaction with the upgraded_nop argument: set it when evaluating
// any script flag that is implemented as an upgraded NOP code.
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache)
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
PrecomputedTransactionData txdata(tx);
// If we add many more flags, this loop can get too expensive, but we can
Expand Down
15 changes: 0 additions & 15 deletions src/wallet/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,6 @@ bool WalletInit::ParameterInteraction() const
InitWarning(AmountHighWarn("-minrelaytxfee") + " " +
_("The wallet will avoid paying less than the minimum relay fee."));

if (gArgs.IsArgSet("-maxtxfee"))
{
CAmount nMaxFee = 0;
if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee))
return InitError(AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", "")));
if (nMaxFee > HIGH_MAX_TX_FEE)
InitWarning(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction."));
maxTxFee = nMaxFee;
if (CFeeRate(maxTxFee, 1000) < ::minRelayTxFee)
{
return InitError(strprintf(_("Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"),
gArgs.GetArg("-maxtxfee", ""), ::minRelayTxFee.ToString()));
}
}

if (gArgs.IsArgSet("-walletbackupsdir")) {
if (!fs::is_directory(gArgs.GetArg("-walletbackupsdir", ""))) {
InitWarning(strprintf(_("Warning: incorrect parameter %s, path must exist! Using default path."), "-walletbackupsdir"));
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
* @param ret The UniValue into which the result is stored.
* @param filter The "is mine" filter bool.
*/
static void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const std::string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, const std::string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pwallet->cs_wallet)
{
CAmount nFee;
std::string strSentAccount;
Expand Down
Loading

0 comments on commit dfea329

Please sign in to comment.