Skip to content

Commit b9f1e86

Browse files
committed
addrman: change asserts to Assumes
`Assume` is safer since the checks are non-fatal- errors in these functions should provide feedback in debug builds, but do not need to deter further node operations in production.
1 parent 7687707 commit b9f1e86

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/addrman.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool new_only, std::option
764764
if (node_id != -1) {
765765
if (network.has_value()) {
766766
const auto it{mapInfo.find(node_id)};
767-
assert(it != mapInfo.end());
768-
const auto info{it->second};
769-
if (info.GetNetwork() == *network) break;
767+
if (Assume(it != mapInfo.end()) && it->second.GetNetwork() == *network) break;
770768
} else {
771769
break;
772770
}
@@ -796,15 +794,17 @@ int AddrManImpl::GetEntry(bool use_tried, size_t bucket, size_t position) const
796794
{
797795
AssertLockHeld(cs);
798796

799-
assert(position < ADDRMAN_BUCKET_SIZE);
800-
801797
if (use_tried) {
802-
assert(bucket < ADDRMAN_TRIED_BUCKET_COUNT);
803-
return vvTried[bucket][position];
798+
if (Assume(position < ADDRMAN_BUCKET_SIZE) && Assume(bucket < ADDRMAN_TRIED_BUCKET_COUNT)) {
799+
return vvTried[bucket][position];
800+
}
804801
} else {
805-
assert(bucket < ADDRMAN_NEW_BUCKET_COUNT);
806-
return vvNew[bucket][position];
802+
if (Assume(position < ADDRMAN_BUCKET_SIZE) && Assume(bucket < ADDRMAN_NEW_BUCKET_COUNT)) {
803+
return vvNew[bucket][position];
804+
}
807805
}
806+
807+
return -1;
808808
}
809809

810810
std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const

src/addrman_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class AddrManImpl
255255

256256
/** Helper to generalize looking up an addrman entry from either table.
257257
*
258-
* @return int The nid of the entry or -1 if the addrman position is empty.
258+
* @return int The nid of the entry. If the addrman position is empty or not found, returns -1.
259259
* */
260260
int GetEntry(bool use_tried, size_t bucket, size_t position) const EXCLUSIVE_LOCKS_REQUIRED(cs);
261261

0 commit comments

Comments
 (0)