Skip to content

Commit 08b22dd

Browse files
Merge pull request dashpay#5770 from vijaydasmp/bp22_26_1
backport: Merge bitcoin#19370, 19562, 19538, 19272, 19214, 19429, 18990, 20927, 20507
2 parents b4cb17f + 18500ea commit 08b22dd

File tree

14 files changed

+129
-80
lines changed

14 files changed

+129
-80
lines changed

src/bench/bench_bitcoin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int main(int argc, char** argv)
4141
{
4242
ArgsManager argsman;
4343
SetupBenchArgs(argsman);
44+
SHA256AutoDetect();
4445
std::string error;
4546
if (!argsman.ParseParameters(argc, argv, error)) {
4647
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error);

src/net.cpp

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,37 +1487,47 @@ void CConnman::CalculateNumConnectionsChangedStats()
14871487
statsClient.gauge("peers.torConnections", torNodes, 1.0f);
14881488
}
14891489

1490-
void CConnman::InactivityCheck(CNode *pnode) const
1490+
bool CConnman::InactivityCheck(const CNode& node) const
14911491
{
1492-
int64_t nTime = GetSystemTimeInSeconds();
1493-
if (nTime - pnode->nTimeConnected > m_peer_connect_timeout)
1494-
{
1495-
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
1496-
{
1497-
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());
1498-
pnode->fDisconnect = true;
1499-
}
1500-
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
1501-
{
1502-
LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
1503-
pnode->fDisconnect = true;
1504-
}
1505-
else if (nTime - pnode->nLastRecv > TIMEOUT_INTERVAL)
1506-
{
1507-
LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
1508-
pnode->fDisconnect = true;
1509-
}
1510-
else if (pnode->nPingNonceSent && pnode->nPingUsecStart + TIMEOUT_INTERVAL * 1000000 < GetTimeMicros())
1511-
{
1512-
LogPrintf("ping timeout: %fs\n", 0.000001 * (GetTimeMicros() - pnode->nPingUsecStart));
1513-
pnode->fDisconnect = true;
1514-
}
1515-
else if (!pnode->fSuccessfullyConnected)
1516-
{
1517-
LogPrint(BCLog::NET, "version handshake timeout from %d\n", pnode->GetId());
1518-
pnode->fDisconnect = true;
1519-
}
1492+
// Use non-mockable system time (otherwise these timers will pop when we
1493+
// use setmocktime in the tests).
1494+
int64_t now = GetSystemTimeInSeconds();
1495+
1496+
if (now <= node.nTimeConnected + m_peer_connect_timeout) {
1497+
// Only run inactivity checks if the peer has been connected longer
1498+
// than m_peer_connect_timeout.
1499+
return false;
15201500
}
1501+
1502+
if (node.nLastRecv == 0 || node.nLastSend == 0) {
1503+
LogPrint(BCLog::NET, "socket no message in first %i seconds, %d %d from %d\n", m_peer_connect_timeout, node.nLastRecv != 0, node.nLastSend != 0, node.GetId());
1504+
return true;
1505+
}
1506+
1507+
if (now > node.nLastSend + TIMEOUT_INTERVAL) {
1508+
LogPrintf("socket sending timeout: %is\n", now - node.nLastSend);
1509+
return true;
1510+
}
1511+
1512+
if (now > node.nLastRecv + TIMEOUT_INTERVAL) {
1513+
LogPrintf("socket receive timeout: %is\n", now - node.nLastRecv);
1514+
return true;
1515+
}
1516+
1517+
if (node.nPingNonceSent && node.nPingUsecStart.load() + TIMEOUT_INTERVAL * 1000000 < GetTimeMicros()) {
1518+
// We use mockable time for ping timeouts. This means that setmocktime
1519+
// may cause pings to time out for peers that have been connected for
1520+
// longer than m_peer_connect_timeout.
1521+
LogPrintf("ping timeout: %fs\n", 0.000001 * (GetTimeMicros() - node.nPingUsecStart));
1522+
return true;
1523+
}
1524+
1525+
if (!node.fSuccessfullyConnected) {
1526+
LogPrint(BCLog::NET, "version handshake timeout from %d\n", node.GetId());
1527+
return true;
1528+
}
1529+
1530+
return false;
15211531
}
15221532

15231533
bool CConnman::GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set)
@@ -2036,7 +2046,7 @@ void CConnman::ThreadSocketHandler()
20362046
SocketHandler();
20372047
if (GetTimeMillis() - nLastCleanupNodes > 1000) {
20382048
ForEachNode(AllNodes, [&](CNode* pnode) {
2039-
InactivityCheck(pnode);
2049+
if (InactivityCheck(*pnode)) pnode->fDisconnect = true;
20402050
});
20412051
nLastCleanupNodes = GetTimeMillis();
20422052
}

src/net.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ friend class CNode;
600600
void DisconnectNodes();
601601
void NotifyNumConnectionsChanged();
602602
void CalculateNumConnectionsChangedStats();
603-
void InactivityCheck(CNode *pnode) const;
603+
/** Return true if the peer is inactive and should be disconnected. */
604+
bool InactivityCheck(const CNode& node) const;
604605
bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
605606
#ifdef USE_KQUEUE
606607
void SocketEventsKqueue(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set, bool fOnlyPoll);

src/net_processing.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,7 +2582,10 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
25822582
break;
25832583
} else if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) {
25842584
if (state.IsInvalid()) {
2585-
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s\n", orphanHash.ToString());
2585+
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s from peer=%d. %s\n",
2586+
orphanHash.ToString(),
2587+
orphan_it->second.fromPeer,
2588+
state.ToString());
25862589
// Maybe punish peer that gave us an invalid orphan tx
25872590
MaybePunishNodeForTx(orphan_it->second.fromPeer, state);
25882591
}
@@ -3279,7 +3282,7 @@ void PeerManagerImpl::ProcessMessage(
32793282
vRecv >> vInv;
32803283
if (vInv.size() > MAX_INV_SZ)
32813284
{
3282-
Misbehaving(pfrom.GetId(), 20, strprintf("message inv size() = %u", vInv.size()));
3285+
Misbehaving(pfrom.GetId(), 20, strprintf("inv message size = %u", vInv.size()));
32833286
return;
32843287
}
32853288

@@ -3374,7 +3377,8 @@ void PeerManagerImpl::ProcessMessage(
33743377
vRecv >> vInv;
33753378
if (vInv.size() > MAX_INV_SZ)
33763379
{
3377-
Misbehaving(pfrom.GetId(), 20, strprintf("message getdata size() = %u", vInv.size()));
3380+
3381+
Misbehaving(pfrom.GetId(), 20, strprintf("getdata message size = %u", vInv.size()));
33783382
return;
33793383
}
33803384

@@ -3741,8 +3745,7 @@ void PeerManagerImpl::ProcessMessage(
37413745
// peer simply for relaying a tx that our m_recent_rejects has caught,
37423746
// regardless of false positives.
37433747

3744-
if (state.IsInvalid())
3745-
{
3748+
if (state.IsInvalid()) {
37463749
LogPrint(BCLog::MEMPOOLREJ, "%s from peer=%d was not accepted: %s\n", tx.GetHash().ToString(),
37473750
pfrom.GetId(),
37483751
state.ToString());

src/sync.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void potential_deadlock_detected(const LockPair& mismatch, const LockStac
140140
throw std::logic_error(strprintf("potential deadlock detected: %s -> %s -> %s", mutex_b, mutex_a, mutex_b));
141141
}
142142

143-
static void double_lock_detected(const void* mutex, LockStack& lock_stack)
143+
static void double_lock_detected(const void* mutex, const LockStack& lock_stack)
144144
{
145145
LogPrintf("DOUBLE LOCK DETECTED\n");
146146
LogPrintf("Lock order:\n");
@@ -151,7 +151,9 @@ static void double_lock_detected(const void* mutex, LockStack& lock_stack)
151151
LogPrintf(" %s\n", i.second.ToString());
152152
}
153153
if (g_debug_lockorder_abort) {
154-
tfm::format(std::cerr, "Assertion failed: detected double lock at %s:%i, details in debug log.\n", __FILE__, __LINE__);
154+
tfm::format(std::cerr,
155+
"Assertion failed: detected double lock for %s, details in debug log.\n",
156+
lock_stack.back().second.ToString());
155157
abort();
156158
}
157159
throw std::logic_error("double lock detected");

src/test/fuzz/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class FuzzedFileProvider
409409
return 0;
410410
}
411411
std::memcpy(buf, random_bytes.data(), random_bytes.size());
412-
if (AdditionOverflow(static_cast<size_t>(fuzzed_file->m_offset), random_bytes.size())) {
412+
if (AdditionOverflow(fuzzed_file->m_offset, (int64_t)random_bytes.size())) {
413413
return fuzzed_file->m_fuzzed_data_provider.ConsumeBool() ? 0 : -1;
414414
}
415415
fuzzed_file->m_offset += random_bytes.size();
@@ -421,7 +421,7 @@ class FuzzedFileProvider
421421
FuzzedFileProvider* fuzzed_file = (FuzzedFileProvider*)cookie;
422422
SetFuzzedErrNo(fuzzed_file->m_fuzzed_data_provider);
423423
const ssize_t n = fuzzed_file->m_fuzzed_data_provider.ConsumeIntegralInRange<ssize_t>(0, size);
424-
if (AdditionOverflow(static_cast<ssize_t>(fuzzed_file->m_offset), n)) {
424+
if (AdditionOverflow(fuzzed_file->m_offset, (int64_t)n)) {
425425
return fuzzed_file->m_fuzzed_data_provider.ConsumeBool() ? 0 : -1;
426426
}
427427
fuzzed_file->m_offset += n;

src/test/sync_tests.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ void TestDoubleLock(bool should_throw)
6262
MutexType m;
6363
ENTER_CRITICAL_SECTION(m);
6464
if (should_throw) {
65-
BOOST_CHECK_EXCEPTION(
66-
TestDoubleLock2(m), std::logic_error, [](const std::logic_error& e) {
67-
return strcmp(e.what(), "double lock detected") == 0;
68-
});
65+
BOOST_CHECK_EXCEPTION(TestDoubleLock2(m), std::logic_error,
66+
HasReason("double lock detected"));
6967
} else {
7068
BOOST_CHECK_NO_THROW(TestDoubleLock2(m));
7169
}

src/validation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
648648
std::unique_ptr<CTxMemPoolEntry>& entry = ws.m_entry;
649649
CAmount& nModifiedFees = ws.m_modified_fees;
650650

651-
if (!CheckTransaction(tx, state))
651+
if (!CheckTransaction(tx, state)) {
652652
return false; // state filled in by CheckTransaction
653+
}
653654

654655
assert(std::addressof(::ChainstateActive()) == std::addressof(m_active_chainstate));
655656
if (!ContextualCheckTransaction(tx, state, chainparams.GetConsensus(), m_active_chainstate.m_chain.Tip()))
@@ -761,7 +762,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
761762

762763
assert(std::addressof(g_chainman.m_blockman) == std::addressof(m_active_chainstate.m_blockman));
763764
if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_blockman.GetSpendHeight(m_view), ws.m_base_fees)) {
764-
return error("%s: Consensus::CheckTxInputs: %s, %s", __func__, tx.GetHash().ToString(), state.ToString());
765+
return false; // state filled in by CheckTxInputs
765766
}
766767

767768
// Check for non-standard pay-to-script-hash in inputs

src/wallet/test/wallet_tests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ extern UniValue addmultisigaddress(const JSONRPCRequest& request);
3939

4040
extern RecursiveMutex cs_wallets;
4141

42+
// Ensure that fee levels defined in the wallet are at least as high
43+
// as the default levels for node policy.
44+
static_assert(DEFAULT_TRANSACTION_MINFEE >= DEFAULT_MIN_RELAY_TX_FEE, "wallet minimum fee is smaller than default relay fee");
45+
static_assert(WALLET_INCREMENTAL_RELAY_FEE >= DEFAULT_INCREMENTAL_RELAY_FEE, "wallet incremental fee is smaller than default incremental relay fee");
46+
4247
BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
4348

4449
namespace {

test/functional/p2p_addr_relay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def run_test(self):
4545
addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
4646
msg = msg_addr()
4747

48-
self.log.info('Send too large addr message')
48+
self.log.info('Send too-large addr message')
4949
msg.addrs = ADDRS * 101
5050
with self.nodes[0].assert_debug_log(['addr message size = 1010']):
5151
addr_source.send_and_ping(msg)

0 commit comments

Comments
 (0)