mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Merge pull request #3526 from PastaPastaPasta/backport-14733-14024
Backport 14733 14024
This commit is contained in:
commit
99ecf1d76c
11
src/init.cpp
11
src/init.cpp
@ -533,6 +533,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-seednode=<ip>", _("Connect to a node to retrieve peer addresses, and disconnect"));
|
||||
strUsage += HelpMessageOpt("-socketevents=<mode>", strprintf(_("Socket events mode, which must be one of: %s (default: %s)"), GetSupportedSocketEventsStr(), DEFAULT_SOCKETEVENTS));
|
||||
strUsage += HelpMessageOpt("-timeout=<n>", strprintf(_("Specify connection timeout in milliseconds (minimum: 1, default: %d)"), DEFAULT_CONNECT_TIMEOUT));
|
||||
strUsage += HelpMessageOpt("-peertimeout=<n>", strprintf("Specify p2p connection timeout in seconds. This option determines the amount of time a peer may be inactive before the connection to it is dropped. (minimum: 1, default: %d)", DEFAULT_PEER_CONNECT_TIMEOUT));
|
||||
strUsage += HelpMessageOpt("-torcontrol=<ip>:<port>", strprintf(_("Tor control port to use if onion listening enabled (default: %s)"), DEFAULT_TOR_CONTROL));
|
||||
strUsage += HelpMessageOpt("-torpassword=<pass>", _("Tor control port password (default: empty)"));
|
||||
#ifdef USE_UPNP
|
||||
@ -1020,6 +1021,7 @@ int nMaxConnections;
|
||||
int nUserMaxConnections;
|
||||
int nFD;
|
||||
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK | NODE_NETWORK_LIMITED);
|
||||
int64_t peer_connect_timeout;
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -1264,8 +1266,14 @@ bool AppInitParameterInteraction()
|
||||
}
|
||||
|
||||
nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
|
||||
if (nConnectTimeout <= 0)
|
||||
if (nConnectTimeout <= 0) {
|
||||
nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
|
||||
}
|
||||
|
||||
peer_connect_timeout = gArgs.GetArg("-peertimeout", DEFAULT_PEER_CONNECT_TIMEOUT);
|
||||
if (peer_connect_timeout <= 0) {
|
||||
return InitError("peertimeout cannot be configured with a negative value.");
|
||||
}
|
||||
|
||||
if (gArgs.IsArgSet("-minrelaytxfee")) {
|
||||
CAmount n = 0;
|
||||
@ -2236,6 +2244,7 @@ bool AppInitMain()
|
||||
|
||||
connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe;
|
||||
connOptions.nMaxOutboundLimit = nMaxOutboundLimit;
|
||||
connOptions.m_peer_connect_timeout = peer_connect_timeout;
|
||||
|
||||
for (const std::string& strBind : gArgs.GetArgs("-bind")) {
|
||||
CService addrBind;
|
||||
|
@ -1402,11 +1402,11 @@ void CConnman::NotifyNumConnectionsChanged()
|
||||
void CConnman::InactivityCheck(CNode *pnode)
|
||||
{
|
||||
int64_t nTime = GetSystemTimeInSeconds();
|
||||
if (nTime - pnode->nTimeConnected > 60)
|
||||
if (nTime - pnode->nTimeConnected > m_peer_connect_timeout)
|
||||
{
|
||||
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
|
||||
{
|
||||
LogPrint(BCLog::NET, "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId());
|
||||
LogPrint(BCLog::NET, "socket no message in first %i seconds, %d %d from %d\n", m_peer_connect_timeout, pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId());
|
||||
pnode->fDisconnect = true;
|
||||
}
|
||||
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
|
||||
|
@ -92,6 +92,8 @@ static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
|
||||
static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24;
|
||||
/** Default for blocks only*/
|
||||
static const bool DEFAULT_BLOCKSONLY = false;
|
||||
/** -peertimeout default */
|
||||
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
|
||||
|
||||
static const bool DEFAULT_FORCEDNSSEED = false;
|
||||
static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
|
||||
@ -167,6 +169,7 @@ public:
|
||||
unsigned int nReceiveFloodSize = 0;
|
||||
uint64_t nMaxOutboundTimeframe = 0;
|
||||
uint64_t nMaxOutboundLimit = 0;
|
||||
int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
|
||||
std::vector<std::string> vSeedNodes;
|
||||
std::vector<CSubNet> vWhitelistedRange;
|
||||
std::vector<CService> vBinds, vWhiteBinds;
|
||||
@ -188,6 +191,7 @@ public:
|
||||
m_msgproc = connOptions.m_msgproc;
|
||||
nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
|
||||
nReceiveFloodSize = connOptions.nReceiveFloodSize;
|
||||
m_peer_connect_timeout = connOptions.m_peer_connect_timeout;
|
||||
{
|
||||
LOCK(cs_totalBytesSent);
|
||||
nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
|
||||
@ -554,6 +558,9 @@ private:
|
||||
uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
|
||||
uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent);
|
||||
|
||||
// P2P timeout in seconds
|
||||
int64_t m_peer_connect_timeout;
|
||||
|
||||
// Whitelisted ranges. Any node connecting from these is automatically
|
||||
// whitelisted (as well as those connecting to whitelisted binds).
|
||||
std::vector<CSubNet> vWhitelistedRange;
|
||||
|
@ -96,9 +96,13 @@ class InvalidTxRequestTest(BitcoinTestFramework):
|
||||
|
||||
# restart node with sending BIP61 messages disabled, check that it disconnects without sending the reject message
|
||||
self.log.info('Test a transaction that is rejected, with BIP61 disabled')
|
||||
self.restart_node(0, ['-enablebip61=0','-persistmempool=0'])
|
||||
self.restart_node(0, ['-enablebip61=0', '-persistmempool=0'])
|
||||
self.reconnect_p2p(num_connections=1)
|
||||
node.p2p.send_txs_and_test([tx1], node, success=False, expect_disconnect=True)
|
||||
with node.assert_debug_log(expected_msgs=[
|
||||
"{} from peer=0 was not accepted: mandatory-script-verify-flag-failed (Invalid OP_IF construction) (code 16)".format(tx1.hash),
|
||||
"disconnecting peer=0",
|
||||
]):
|
||||
node.p2p.send_txs_and_test([tx1], node, success=False, expect_disconnect=True)
|
||||
# send_txs_and_test will have waited for disconnect, so we can safely check that no reject has been received
|
||||
assert_equal(node.p2p.reject_code_received, None)
|
||||
|
||||
@ -181,5 +185,6 @@ class InvalidTxRequestTest(BitcoinTestFramework):
|
||||
assert_equal(expected_mempool, set(node.getrawmempool()))
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
InvalidTxRequestTest().main()
|
||||
|
@ -14,11 +14,11 @@
|
||||
- Wait 1 second
|
||||
- Assert that we're connected
|
||||
- Send a ping to no_verack_node and no_version_node
|
||||
- Wait 30 seconds
|
||||
- Wait 1 second
|
||||
- Assert that we're still connected
|
||||
- Send a ping to no_verack_node and no_version_node
|
||||
- Wait 31 seconds
|
||||
- Assert that we're no longer connected (timeout to receive version/verack is 60 seconds)
|
||||
- Wait 2 seconds
|
||||
- Assert that we're no longer connected (timeout to receive version/verack is 3 seconds)
|
||||
"""
|
||||
|
||||
from time import sleep
|
||||
@ -36,6 +36,8 @@ class TimeoutsTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
# set timeout to receive version/verack to 3 seconds
|
||||
self.extra_args = [["-peertimeout=3"]]
|
||||
|
||||
def run_test(self):
|
||||
# Setup the p2p connections and start up the network thread.
|
||||
@ -54,7 +56,7 @@ class TimeoutsTest(BitcoinTestFramework):
|
||||
no_verack_node.send_message(msg_ping())
|
||||
no_version_node.send_message(msg_ping())
|
||||
|
||||
sleep(30)
|
||||
sleep(1)
|
||||
|
||||
assert "version" in no_verack_node.last_message
|
||||
|
||||
@ -65,11 +67,17 @@ class TimeoutsTest(BitcoinTestFramework):
|
||||
no_verack_node.send_message(msg_ping())
|
||||
no_version_node.send_message(msg_ping())
|
||||
|
||||
sleep(32)
|
||||
expected_timeout_logs = [
|
||||
"version handshake timeout from 0",
|
||||
"socket no message in first 3 seconds, 1 0 from 1",
|
||||
"socket no message in first 3 seconds, 0 0 from 2",
|
||||
]
|
||||
|
||||
assert not no_verack_node.connected
|
||||
assert not no_version_node.connected
|
||||
assert not no_send_node.connected
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=expected_timeout_logs):
|
||||
sleep(3)
|
||||
assert not no_verack_node.connected
|
||||
assert not no_version_node.connected
|
||||
assert not no_send_node.connected
|
||||
|
||||
if __name__ == '__main__':
|
||||
TimeoutsTest().main()
|
||||
|
@ -4,6 +4,7 @@
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Class for dashd node under test"""
|
||||
|
||||
import contextlib
|
||||
import decimal
|
||||
import errno
|
||||
import http.client
|
||||
@ -187,6 +188,23 @@ class TestNode():
|
||||
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
|
||||
wait_until(self.is_node_stopped, timeout=timeout)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def assert_debug_log(self, expected_msgs):
|
||||
debug_log = os.path.join(self.datadir, 'regtest', 'debug.log')
|
||||
with open(debug_log, encoding='utf-8') as dl:
|
||||
dl.seek(0, 2)
|
||||
prev_size = dl.tell()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
with open(debug_log, encoding='utf-8') as dl:
|
||||
dl.seek(prev_size)
|
||||
log = dl.read()
|
||||
print_log = " - " + "\n - ".join(log.splitlines())
|
||||
for expected_msg in expected_msgs:
|
||||
if re.search(re.escape(expected_msg), log, flags=re.MULTILINE) is None:
|
||||
self._raise_assertion_error('Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log))
|
||||
|
||||
def node_encrypt_wallet(self, passphrase):
|
||||
""""Encrypts the wallet.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user