Skip to content

Commit 1c8f475

Browse files
Merge pull request #3882 from PastaPastaPasta/backports-0.17-pr25
Backports 0.17 pr25
2 parents 94ae63c + 71c49d7 commit 1c8f475

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+253
-133
lines changed

contrib/auto_gdb/dash_dbg.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# use testnet settings, if you need mainnet, use ~/.dashcore/dashd.pid file instead
33
export LC_ALL=C
44

contrib/devtools/gen-manpages.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
export LC_ALL=C
44
TOPDIR=${TOPDIR:-$(git rev-parse --show-toplevel)}

contrib/gitian-descriptors/gitian-linux.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ script: |
8181
8282
function create_global_faketime_wrappers {
8383
for prog in ${FAKETIME_PROGS}; do
84-
echo '#!/bin/bash' > ${WRAP_DIR}/${prog}
84+
echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog}
8585
echo "# GCCVERSION=${GCCVERSION}" >> ${WRAP_DIR}/${prog}
8686
echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog}
8787
echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog}
@@ -95,7 +95,7 @@ script: |
9595
function create_per-host_faketime_wrappers {
9696
for i in $HOSTS; do
9797
for prog in ${FAKETIME_HOST_PROGS}; do
98-
echo '#!/bin/bash' > ${WRAP_DIR}/${i}-${prog}
98+
echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog}
9999
echo "# GCCVERSION=${GCCVERSION}" >> ${WRAP_DIR}/${i}-${prog}
100100
echo "REAL=\`which -a ${i}-${prog} | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog}
101101
echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog}
@@ -127,7 +127,7 @@ script: |
127127
for prog in gcc g++; do
128128
rm -f ${WRAP_DIR}/${prog}
129129
cat << EOF > ${WRAP_DIR}/${prog}
130-
#!/bin/bash
130+
#!/usr/bin/env bash
131131
# GCCVERSION=${GCCVERSION}
132132
REAL="`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1`"
133133
for var in "\$@"

contrib/gitian-descriptors/gitian-osx-signer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ script: |
1919
2020
# Create global faketime wrappers
2121
for prog in ${FAKETIME_PROGS}; do
22-
echo '#!/bin/bash' > ${WRAP_DIR}/${prog}
22+
echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog}
2323
echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog}
2424
echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog}
2525
echo "export FAKETIME=\"${REFERENCE_DATETIME}\"" >> ${WRAP_DIR}/${prog}

contrib/gitian-descriptors/gitian-osx.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ script: |
7474
7575
function create_global_faketime_wrappers {
7676
for prog in ${FAKETIME_PROGS}; do
77-
echo '#!/bin/bash' > ${WRAP_DIR}/${prog}
77+
echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog}
7878
echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog}
7979
echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog}
8080
echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${prog}
@@ -87,7 +87,7 @@ script: |
8787
function create_per-host_faketime_wrappers {
8888
for i in $HOSTS; do
8989
for prog in ${FAKETIME_HOST_PROGS}; do
90-
echo '#!/bin/bash' > ${WRAP_DIR}/${i}-${prog}
90+
echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog}
9191
echo "REAL=\`which -a ${i}-${prog} | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog}
9292
echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog}
9393
echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${i}-${prog}

contrib/gitian-descriptors/gitian-win.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ script: |
7373
7474
function create_global_faketime_wrappers {
7575
for prog in ${FAKETIME_PROGS}; do
76-
echo '#!/bin/bash' > ${WRAP_DIR}/${prog}
76+
echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog}
7777
echo "# GCCVERSION=${GCCVERSION}" >> ${WRAP_DIR}/${prog}
7878
echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog}
7979
echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog}
@@ -87,7 +87,7 @@ script: |
8787
function create_per-host_faketime_wrappers {
8888
for i in $HOSTS; do
8989
for prog in ${FAKETIME_HOST_PROGS}; do
90-
echo '#!/bin/bash' > ${WRAP_DIR}/${i}-${prog}
90+
echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog}
9191
echo "# GCCVERSION=${GCCVERSION}" >> ${WRAP_DIR}/${i}-${prog}
9292
echo "REAL=\`which -a ${i}-${prog} | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog}
9393
echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog}
@@ -105,7 +105,7 @@ script: |
105105
for i in $HOSTS; do
106106
mkdir -p ${WRAP_DIR}/${i}
107107
for prog in collect2; do
108-
echo '#!/bin/bash' > ${WRAP_DIR}/${i}/${prog}
108+
echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}/${prog}
109109
echo "# GCCVERSION=${GCCVERSION}" >> ${WRAP_DIR}/${i}/${prog}
110110
REAL=$(${i}-gcc -print-prog-name=${prog})
111111
echo "export MALLOC_PERTURB_=255" >> ${WRAP_DIR}/${i}/${prog}
@@ -114,7 +114,7 @@ script: |
114114
touch -d "${REFERENCE_DATETIME}" ${WRAP_DIR}/${i}/${prog}
115115
done
116116
for prog in gcc g++; do
117-
echo '#!/bin/bash' > ${WRAP_DIR}/${i}-${prog}
117+
echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog}
118118
echo "# GCCVERSION=${GCCVERSION}" >> ${WRAP_DIR}/${i}-${prog}
119119
echo "REAL=\`which -a ${i}-${prog}-posix | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog}
120120
echo '# Add the gcc version to the wrapper so that ccache takes this into account (we use CCACHE_COMPILERCHECK=content)' >> ${WRAP_DIR}/${i}-${prog}

contrib/init/dashd.init

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#
33
# dashd The Dash Core server.
44
#

contrib/macdeploy/extract-osx-sdk.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# Copyright (c) 2016 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

contrib/verify-commits/pre-push-hook.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# Copyright (c) 2014-2015 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

contrib/verifybinaries/verify.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# Copyright (c) 2016 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

src/bench/bench_dash.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ void InitBLSTests();
2929
void CleanupBLSTests();
3030
void CleanupBLSDkgTests();
3131

32-
int
33-
main(int argc, char** argv)
32+
static fs::path SetDataDir()
33+
{
34+
fs::path ret = fs::temp_directory_path() / "bench_dash" / fs::unique_path();
35+
fs::create_directories(ret);
36+
gArgs.ForceSetArg("-datadir", ret.string());
37+
return ret;
38+
}
39+
40+
int main(int argc, char** argv)
3441
{
3542
gArgs.ParseParameters(argc, argv);
3643

@@ -49,6 +56,9 @@ main(int argc, char** argv)
4956
return 0;
5057
}
5158

59+
// Set the datadir after parsing the bench options
60+
const fs::path bench_datadir{SetDataDir()};
61+
5262
SHA256AutoDetect();
5363

5464
RegisterPrettySignalHandlers();
@@ -82,6 +92,8 @@ main(int argc, char** argv)
8292

8393
benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);
8494

95+
fs::remove_all(bench_datadir);
96+
8597
// need to be called before global destructors kick in (PoolAllocator is needed due to many BLSSecretKeys)
8698
CleanupBLSDkgTests();
8799
CleanupBLSTests();

src/dash-tx.cpp

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2009-2015 The Bitcoin Core developers
1+
// Copyright (c) 2009-2018 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -190,18 +190,18 @@ static CAmount ExtractAndValidateValue(const std::string& strValue)
190190

191191
static void MutateTxVersion(CMutableTransaction& tx, const std::string& cmdVal)
192192
{
193-
int64_t newVersion = atoi64(cmdVal);
194-
if (newVersion < 1 || newVersion > CTransaction::MAX_STANDARD_VERSION)
195-
throw std::runtime_error("Invalid TX version requested");
193+
int64_t newVersion;
194+
if (!ParseInt64(cmdVal, &newVersion) || newVersion < 1 || newVersion > CTransaction::MAX_STANDARD_VERSION)
195+
throw std::runtime_error("Invalid TX version requested: '" + cmdVal + "'");
196196

197197
tx.nVersion = (int) newVersion;
198198
}
199199

200200
static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal)
201201
{
202-
int64_t newLocktime = atoi64(cmdVal);
203-
if (newLocktime < 0LL || newLocktime > 0xffffffffLL)
204-
throw std::runtime_error("Invalid TX locktime requested");
202+
int64_t newLocktime;
203+
if (!ParseInt64(cmdVal, &newLocktime) || newLocktime < 0LL || newLocktime > 0xffffffffLL)
204+
throw std::runtime_error("Invalid TX locktime requested: '" + cmdVal + "'");
205205

206206
tx.nLockTime = (unsigned int) newLocktime;
207207
}
@@ -225,10 +225,10 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
225225
static const unsigned int maxVout = MaxBlockSize() / minTxOutSz;
226226

227227
// extract and validate vout
228-
std::string strVout = vStrInputParts[1];
229-
int vout = atoi(strVout);
230-
if ((vout < 0) || (vout > (int)maxVout))
231-
throw std::runtime_error("invalid TX input vout");
228+
const std::string& strVout = vStrInputParts[1];
229+
int64_t vout;
230+
if (!ParseInt64(strVout, &vout) || vout < 0 || vout > static_cast<int64_t>(maxVout))
231+
throw std::runtime_error("invalid TX input vout '" + strVout + "'");
232232

233233
// extract the optional sequence number
234234
uint32_t nSequenceIn=std::numeric_limits<unsigned int>::max();
@@ -433,10 +433,9 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
433433
static void MutateTxDelInput(CMutableTransaction& tx, const std::string& strInIdx)
434434
{
435435
// parse requested deletion index
436-
int inIdx = atoi(strInIdx);
437-
if (inIdx < 0 || inIdx >= (int)tx.vin.size()) {
438-
std::string strErr = "Invalid TX input index '" + strInIdx + "'";
439-
throw std::runtime_error(strErr.c_str());
436+
int64_t inIdx;
437+
if (!ParseInt64(strInIdx, &inIdx) || inIdx < 0 || inIdx >= static_cast<int64_t>(tx.vin.size())) {
438+
throw std::runtime_error("Invalid TX input index '" + strInIdx + "'");
440439
}
441440

442441
// delete input from transaction
@@ -446,10 +445,9 @@ static void MutateTxDelInput(CMutableTransaction& tx, const std::string& strInId
446445
static void MutateTxDelOutput(CMutableTransaction& tx, const std::string& strOutIdx)
447446
{
448447
// parse requested deletion index
449-
int outIdx = atoi(strOutIdx);
450-
if (outIdx < 0 || outIdx >= (int)tx.vout.size()) {
451-
std::string strErr = "Invalid TX output index '" + strOutIdx + "'";
452-
throw std::runtime_error(strErr.c_str());
448+
int64_t outIdx;
449+
if (!ParseInt64(strOutIdx, &outIdx) || outIdx < 0 || outIdx >= static_cast<int64_t>(tx.vout.size())) {
450+
throw std::runtime_error("Invalid TX output index '" + strOutIdx + "'");
453451
}
454452

455453
// delete output from transaction
@@ -547,7 +545,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
547545

548546
uint256 txid = ParseHashStr(prevOut["txid"].get_str(), "txid");
549547

550-
int nOut = atoi(prevOut["vout"].getValStr());
548+
const int nOut = prevOut["vout"].get_int();
551549
if (nOut < 0)
552550
throw std::runtime_error("vout must be positive");
553551

src/keystore.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ class CKeyStore : public SigningProvider
3939
virtual bool HaveWatchOnly() const =0;
4040
};
4141

42-
typedef std::map<CKeyID, CKey> KeyMap;
43-
typedef std::map<CKeyID, CPubKey> WatchKeyMap;
44-
typedef std::map<CScriptID, CScript > ScriptMap;
45-
typedef std::set<CScript> WatchOnlySet;
46-
4742
/** Basic key store, that keeps keys in an address->secret map */
4843
class CBasicKeyStore : public CKeyStore
4944
{
5045
protected:
5146
mutable CCriticalSection cs_KeyStore;
5247

48+
using KeyMap = std::map<CKeyID, CKey>;
49+
using WatchKeyMap = std::map<CKeyID, CPubKey>;
50+
using ScriptMap = std::map<CScriptID, CScript>;
51+
using WatchOnlySet = std::set<CScript>;
52+
5353
KeyMap mapKeys GUARDED_BY(cs_KeyStore);
5454
WatchKeyMap mapWatchKeys GUARDED_BY(cs_KeyStore);
5555
ScriptMap mapScripts GUARDED_BY(cs_KeyStore);
@@ -77,7 +77,4 @@ class CBasicKeyStore : public CKeyStore
7777
virtual bool GetHDChain(CHDChain& hdChainRet) const;
7878
};
7979

80-
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
81-
typedef std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char> > > CryptedKeyMap;
82-
8380
#endif // BITCOIN_KEYSTORE_H

src/merkleblock.h

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ class CPartialMerkleTree
115115
* returns the merkle root, or 0 in case of failure
116116
*/
117117
uint256 ExtractMatches(std::vector<uint256> &vMatch, std::vector<unsigned int> &vnIndex);
118+
119+
/** Get number of transactions the merkle proof is indicating for cross-reference with
120+
* local blockchain knowledge.
121+
*/
122+
unsigned int GetNumTransactions() const { return nTransactions; };
123+
118124
};
119125

120126

src/rpc/mining.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,6 @@ UniValue submitblock(const JSONRPCRequest& request)
757757
}
758758

759759
uint256 hash = block.GetHash();
760-
bool fBlockPresent = false;
761760
{
762761
LOCK(cs_main);
763762
const CBlockIndex* pindex = LookupBlockIndex(hash);
@@ -768,18 +767,18 @@ UniValue submitblock(const JSONRPCRequest& request)
768767
if (pindex->nStatus & BLOCK_FAILED_MASK) {
769768
return "duplicate-invalid";
770769
}
771-
// Otherwise, we might only have the header - process the block before returning
772-
fBlockPresent = true;
773770
}
774771
}
775772

773+
bool new_block;
776774
submitblock_StateCatcher sc(block.GetHash());
777775
RegisterValidationInterface(&sc);
778-
bool fAccepted = ProcessNewBlock(Params(), blockptr, true, nullptr);
776+
bool accepted = ProcessNewBlock(Params(), blockptr, /* fForceProcessing */ true, /* fNewBlock */ &new_block);
779777
UnregisterValidationInterface(&sc);
780-
if (fBlockPresent) {
781-
if (fAccepted && !sc.found) {
782-
return "duplicate-inconclusive";
778+
if (!new_block) {
779+
if (!accepted) {
780+
// TODO Maybe pass down fNewBlock to AcceptBlockHeader, so it is properly set to true in this case?
781+
return "invalid";
783782
}
784783
return "duplicate";
785784
}

src/rpc/rawtransaction.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ UniValue verifytxoutproof(const JSONRPCRequest& request)
337337
"\nArguments:\n"
338338
"1. \"proof\" (string, required) The hex-encoded proof generated by gettxoutproof\n"
339339
"\nResult:\n"
340-
"[\"txid\"] (array, strings) The txid(s) which the proof commits to, or empty array if the proof is invalid\n"
340+
"[\"txid\"] (array, strings) The txid(s) which the proof commits to, or empty array if the proof can not be validated.\n"
341341

342342
"\nExamples:\n"
343343
+ HelpExampleCli("verifytxoutproof", "\"proof\"")
@@ -358,12 +358,17 @@ UniValue verifytxoutproof(const JSONRPCRequest& request)
358358
LOCK(cs_main);
359359

360360
const CBlockIndex* pindex = LookupBlockIndex(merkleBlock.header.GetHash());
361-
if (!pindex || !chainActive.Contains(pindex)) {
361+
if (!pindex || !chainActive.Contains(pindex) || pindex->nTx == 0) {
362362
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain");
363363
}
364364

365-
for (const uint256& hash : vMatch)
366-
res.push_back(hash.GetHex());
365+
// Check if proof is valid, only add results if so
366+
if (pindex->nTx == merkleBlock.txn.GetNumTransactions()) {
367+
for (const uint256& hash : vMatch) {
368+
res.push_back(hash.GetHex());
369+
}
370+
}
371+
367372
return res;
368373
}
369374

0 commit comments

Comments
 (0)