Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backports 0.15 pr5 #2647

Merged
merged 12 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
AX_CHECK_COMPILE_FLAG([-Wformat],[CXXFLAGS="$CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wvla],[CXXFLAGS="$CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wformat-security],[CXXFLAGS="$CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wshadow],[CXXFLAGS="$CXXFLAGS -Wshadow"],,[[$CXXFLAG_WERROR]])

## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
## unknown options if any other warning is produced. Test the -Wfoo case, and
Expand Down
9 changes: 5 additions & 4 deletions contrib/devtools/github-merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ def main():
except subprocess.CalledProcessError as e:
printf("ERROR: Cannot update message.",file=stderr)
exit(4)
second_sha512 = tree_sha512sum()
if first_sha512 != second_sha512:
print("ERROR: Tree hash changed unexpectedly",file=stderr)
exit(4)

print('%s#%s%s %s %sinto %s%s' % (ATTR_RESET+ATTR_PR,pull,ATTR_RESET,title,ATTR_RESET+ATTR_PR,branch,ATTR_RESET))
subprocess.check_call([GIT,'log','--graph','--topo-order','--pretty=format:'+COMMIT_FORMAT,base_branch+'..'+head_branch])
Expand Down Expand Up @@ -258,6 +254,11 @@ def main():
print("ERROR: Merge rejected.",file=stderr)
exit(7)

second_sha512 = tree_sha512sum()
PastaPastaPasta marked this conversation as resolved.
Show resolved Hide resolved
if first_sha512 != second_sha512:
print("ERROR: Tree hash changed unexpectedly",file=stderr)
exit(8)

# Sign the merge commit.
reply = ask_prompt("Type 's' to sign off on the merge.")
if reply == 's':
Expand Down
19 changes: 6 additions & 13 deletions qa/rpc-tests/bip68-sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ def run_test(self):
print("Running test BIP68 not consensus before versionbits activation")
self.test_bip68_not_consensus()

print("Verifying nVersion=2 transactions aren't standard")
self.test_version2_relay(before_activation=True)

print("Activating BIP68 (and 112/113)")
self.activateCSV()

print("Verifying nVersion=2 transactions are now standard")
self.test_version2_relay(before_activation=False)
print("Verifying nVersion=2 transactions are standard.")
print("Note that with current versions of Dash Core software, nVersion=2 transactions are always standard (independent of BIP68 activation status).")
self.test_version2_relay()

print("Passed\n")

Expand Down Expand Up @@ -403,21 +401,16 @@ def activateCSV(self):
assert(get_bip9_status(self.nodes[0], 'csv')['status'] == 'active')
sync_blocks(self.nodes)

# Use self.nodes[1] to test standardness relay policy
def test_version2_relay(self, before_activation):
# Use self.nodes[1] to test that version 2 transactions are standard.
def test_version2_relay(self):
inputs = [ ]
outputs = { self.nodes[1].getnewaddress() : 1.0 }
rawtx = self.nodes[1].createrawtransaction(inputs, outputs)
rawtxfund = self.nodes[1].fundrawtransaction(rawtx)['hex']
tx = FromHex(CTransaction(), rawtxfund)
tx.nVersion = 2
tx_signed = self.nodes[1].signrawtransaction(ToHex(tx))["hex"]
try:
tx_id = self.nodes[1].sendrawtransaction(tx_signed)
assert(before_activation == False)
except:
assert(before_activation)

tx_id = self.nodes[1].sendrawtransaction(tx_signed)

if __name__ == '__main__':
BIP68Test().main()
23 changes: 21 additions & 2 deletions qa/rpc-tests/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import random
import shutil
import subprocess
import tempfile
import time
import re
import errno
Expand Down Expand Up @@ -352,7 +353,7 @@ def _rpchost_to_args(rpchost):
rv += ['-rpcport=' + rpcport]
return rv

def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None, redirect_stderr=False):
def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None, redirect_stderr=False, stderr=None):
"""
Start a dashd and return RPC connection to it
"""
Expand All @@ -367,7 +368,6 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=

# Allow to redirect stderr to stdout in case we expect some non-critical warnings/errors printed to stderr
# Otherwise the whole test would be considered to be failed in such cases
stderr = None
if redirect_stderr:
stderr = sys.stdout

Expand All @@ -385,6 +385,25 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=

return proxy

def assert_start_raises_init_error(i, dirname, extra_args=None, expected_msg=None):
codablock marked this conversation as resolved.
Show resolved Hide resolved
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
try:
node = start_node(i, dirname, extra_args, stderr=log_stderr)
stop_node(node, i)
except Exception as e:
assert 'dashd exited' in str(e) #node must have shutdown
if expected_msg is not None:
log_stderr.seek(0)
stderr = log_stderr.read().decode('utf-8')
if expected_msg not in stderr:
raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr)
else:
if expected_msg is None:
assert_msg = "dashd should have exited with an error"
else:
assert_msg = "dashd should have exited with expected error " + expected_msg
raise AssertionError(assert_msg)

def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None, redirect_stderr=False):
"""
Start multiple dashds, return RPC connections to them
Expand Down
15 changes: 5 additions & 10 deletions qa/rpc-tests/wallet-hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def __init__(self):
super().__init__()
self.setup_clean_chain = True
self.num_nodes = 2
self.node_args = [['-usehd=0'], ['-usehd=1', '-keypool=0']]

def setup_network(self):
self.nodes = start_nodes(2, self.options.tmpdir, [['-usehd=0'], ['-usehd=1', '-keypool=0']], redirect_stderr=True)
self.nodes = start_nodes(2, self.options.tmpdir, self.node_args, redirect_stderr=True)
self.is_network_split = False
connect_nodes_bi(self.nodes, 0, 1)
self.is_network_split=False
Expand All @@ -25,15 +26,9 @@ def run_test (self):
tmpdir = self.options.tmpdir

# Make sure can't switch off usehd after wallet creation
stop_node(self.nodes[1],1)
try:
start_node(1, self.options.tmpdir, ['-usehd=0'], redirect_stderr=True)
raise AssertionError("Must not allow to turn off HD on an already existing HD wallet")
except Exception as e:
assert("dashd exited with status 1 during initialization" in str(e))
# assert_start_raises_init_error(1, self.options.tmpdir, ['-usehd=0'], 'already existing HD wallet')
# self.nodes[1] = start_node(1, self.options.tmpdir, self.node_args[1])
self.nodes[1] = start_node(1, self.options.tmpdir, ['-usehd=1', '-keypool=0'], redirect_stderr=True)
self.stop_node(1)
assert_start_raises_init_error(1, self.options.tmpdir, ['-usehd=0'], 'already existing HD wallet')
self.nodes[1] = start_node(1, self.options.tmpdir, self.node_args[1], redirect_stderr=True)
connect_nodes_bi(self.nodes, 0, 1)

# Make sure we use hd, keep chainid
Expand Down
6 changes: 3 additions & 3 deletions src/arith_uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ unsigned int base_uint<BITS>::bits() const
{
for (int pos = WIDTH - 1; pos >= 0; pos--) {
if (pn[pos]) {
for (int bits = 31; bits > 0; bits--) {
if (pn[pos] & 1 << bits)
return 32 * pos + bits + 1;
for (int nbits = 31; nbits > 0; nbits--) {
if (pn[pos] & 1 << nbits)
return 32 * pos + nbits + 1;
}
return 32 * pos + 1;
}
Expand Down
2 changes: 2 additions & 0 deletions src/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ bool benchmark::State::KeepRunning()

--count;

assert(count != 0 && "count == 0 => (now == 0 && beginTime == 0) => return above");

// Output results
double average = (now-beginTime)/count;
int64_t averageCycles = (nowCycles-beginCycles)/count;
Expand Down
4 changes: 2 additions & 2 deletions src/bench/lockedpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define BITER 5000
#define MSIZE 2048

static void LockedPool(benchmark::State& state)
static void BenchLockedPool(benchmark::State& state)
{
void *synth_base = reinterpret_cast<void*>(0x08000000);
const size_t synth_size = 1024*1024;
Expand Down Expand Up @@ -43,5 +43,5 @@ static void LockedPool(benchmark::State& state)
addr.clear();
}

BENCHMARK(LockedPool);
BENCHMARK(BenchLockedPool);

4 changes: 2 additions & 2 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ class CDiskBlockIndex : public CBlockIndex

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
int nVersion = s.GetVersion();
int _nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH))
READWRITE(VARINT(nVersion));
READWRITE(VARINT(_nVersion));

READWRITE(VARINT(nHeight));
READWRITE(VARINT(nStatus));
Expand Down
2 changes: 1 addition & 1 deletion src/dash-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::string HelpMessageCli()
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
strUsage += HelpMessageOpt("-rpcclienttimeout=<n>", strprintf(_("Timeout during HTTP requests (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT));
strUsage += HelpMessageOpt("-rpcclienttimeout=<n>", strprintf(_("Timeout in seconds during HTTP requests, or 0 for no timeout. (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT));
strUsage += HelpMessageOpt("-stdin", _("Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases)"));

return strUsage;
Expand Down
25 changes: 17 additions & 8 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageGroup(_("RPC server options:"));
strUsage += HelpMessageOpt("-server", _("Accept command line and JSON-RPC commands"));
strUsage += HelpMessageOpt("-rest", strprintf(_("Accept public REST requests (default: %u)"), DEFAULT_REST_ENABLE));
strUsage += HelpMessageOpt("-rpcbind=<addr>", _("Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6. This option can be specified multiple times (default: bind to all interfaces)"));
strUsage += HelpMessageOpt("-rpcbind=<addr>[:port]", _("Bind to given address to listen for JSON-RPC connections. This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost, or if -rpcallowip has been specified, 0.0.0.0 and :: i.e., all addresses)"));
strUsage += HelpMessageOpt("-rpccookiefile=<loc>", _("Location of the auth cookie (default: data dir)"));
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
Expand Down Expand Up @@ -1561,16 +1561,23 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
}
}

// Check for host lookup allowed before parsing any network related parameters
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);

bool proxyRandomize = GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE);
// -proxy sets a proxy for all outgoing network traffic
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
std::string proxyArg = GetArg("-proxy", "");
SetLimited(NET_TOR);
if (proxyArg != "" && proxyArg != "0") {
CService resolved(LookupNumeric(proxyArg.c_str(), 9050));
proxyType addrProxy = proxyType(resolved, proxyRandomize);
CService proxyAddr;
if (!Lookup(proxyArg.c_str(), proxyAddr, 9050, fNameLookup)) {
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
}

proxyType addrProxy = proxyType(proxyAddr, proxyRandomize);
if (!addrProxy.IsValid())
return InitError(strprintf(_("Invalid -proxy address: '%s'"), proxyArg));
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));

SetProxy(NET_IPV4, addrProxy);
SetProxy(NET_IPV6, addrProxy);
Expand All @@ -1587,10 +1594,13 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
if (onionArg == "0") { // Handle -noonion/-onion=0
SetLimited(NET_TOR); // set onions as unreachable
} else {
CService resolved(LookupNumeric(onionArg.c_str(), 9050));
proxyType addrOnion = proxyType(resolved, proxyRandomize);
CService onionProxy;
if (!Lookup(onionArg.c_str(), onionProxy, 9050, fNameLookup)) {
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
}
proxyType addrOnion = proxyType(onionProxy, proxyRandomize);
if (!addrOnion.IsValid())
return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg));
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
SetProxy(NET_TOR, addrOnion);
SetLimited(NET_TOR, false);
}
Expand All @@ -1599,7 +1609,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
// see Step 2: parameter interactions for more information about these
fListen = GetBoolArg("-listen", DEFAULT_LISTEN);
fDiscover = GetBoolArg("-discover", true);
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
fRelayTxes = !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);

if (fListen) {
Expand Down
6 changes: 3 additions & 3 deletions src/script/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,18 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
// get the last item that the scriptSig
// pushes onto the stack:
const_iterator pc = scriptSig.begin();
std::vector<unsigned char> data;
std::vector<unsigned char> vData;
while (pc < scriptSig.end())
{
opcodetype opcode;
if (!scriptSig.GetOp(pc, opcode, data))
if (!scriptSig.GetOp(pc, opcode, vData))
return 0;
if (opcode > OP_16)
return 0;
}

/// ... and return its opcount:
CScript subscript(data.begin(), data.end());
CScript subscript(vData.begin(), vData.end());
return subscript.GetSigOpCount(true);
}

Expand Down
12 changes: 6 additions & 6 deletions src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,16 @@ class CScript : public CScriptBase
else if (b.size() <= 0xffff)
{
insert(end(), OP_PUSHDATA2);
uint8_t data[2];
WriteLE16(data, b.size());
insert(end(), data, data + sizeof(data));
uint8_t _data[2];
WriteLE16(_data, b.size());
insert(end(), _data, _data + sizeof(_data));
}
else
{
insert(end(), OP_PUSHDATA4);
uint8_t data[4];
WriteLE32(data, b.size());
insert(end(), data, data + sizeof(data));
uint8_t _data[4];
WriteLE32(_data, b.size());
insert(end(), _data, _data + sizeof(_data));
}
insert(end(), b.begin(), b.end());
return *this;
Expand Down
6 changes: 3 additions & 3 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,11 @@ class CBufferedFile
readNow = nAvail;
if (readNow == 0)
return false;
size_t read = fread((void*)&vchBuf[pos], 1, readNow, src);
if (read == 0) {
size_t nBytes = fread((void*)&vchBuf[pos], 1, readNow, src);
if (nBytes == 0) {
throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed");
} else {
nSrcPos += read;
nSrcPos += nBytes;
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/support/lockedpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ LockedPool::LockedPageArena::~LockedPageArena()
/*******************************************************************************/
// Implementation: LockedPoolManager
//
LockedPoolManager::LockedPoolManager(std::unique_ptr<LockedPageAllocator> allocator):
LockedPool(std::move(allocator), &LockedPoolManager::LockingFailed)
LockedPoolManager::LockedPoolManager(std::unique_ptr<LockedPageAllocator> allocator_in):
LockedPool(std::move(allocator_in), &LockedPoolManager::LockingFailed)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/coins_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CCoinsViewTest : public CCoinsView
class CCoinsViewCacheTest : public CCoinsViewCache
{
public:
CCoinsViewCacheTest(CCoinsView* base) : CCoinsViewCache(base) {}
CCoinsViewCacheTest(CCoinsView* _base) : CCoinsViewCache(_base) {}

void SelfTest() const
{
Expand Down
14 changes: 7 additions & 7 deletions src/timedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class CMedianFilter
unsigned int nSize;

public:
CMedianFilter(unsigned int size, T initial_value) : nSize(size)
CMedianFilter(unsigned int _size, T initial_value) : nSize(_size)
{
vValues.reserve(size);
vValues.reserve(_size);
vValues.push_back(initial_value);
vSorted = vValues;
}
Expand All @@ -48,14 +48,14 @@ class CMedianFilter

T median() const
{
int size = vSorted.size();
assert(size > 0);
if (size & 1) // Odd number of elements
int vSortedSize = vSorted.size();
assert(vSortedSize > 0);
if (vSortedSize & 1) // Odd number of elements
{
return vSorted[size / 2];
return vSorted[vSortedSize / 2];
} else // Even number of elements
{
return (vSorted[size / 2 - 1] + vSorted[size / 2]) / 2;
return (vSorted[vSortedSize / 2 - 1] + vSorted[vSortedSize / 2]) / 2;
}
}

Expand Down
Loading