0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-09 10:43:19 -05:00

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.
This commit is contained in:
Amiti Uttarwar 2023-04-25 17:04:11 +01:00
parent 768770771f
commit b9f1e86f12
2 changed files with 10 additions and 10 deletions

View file

@ -764,9 +764,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool new_only, std::option
if (node_id != -1) { if (node_id != -1) {
if (network.has_value()) { if (network.has_value()) {
const auto it{mapInfo.find(node_id)}; const auto it{mapInfo.find(node_id)};
assert(it != mapInfo.end()); if (Assume(it != mapInfo.end()) && it->second.GetNetwork() == *network) break;
const auto info{it->second};
if (info.GetNetwork() == *network) break;
} else { } else {
break; break;
} }
@ -796,15 +794,17 @@ int AddrManImpl::GetEntry(bool use_tried, size_t bucket, size_t position) const
{ {
AssertLockHeld(cs); AssertLockHeld(cs);
assert(position < ADDRMAN_BUCKET_SIZE);
if (use_tried) { if (use_tried) {
assert(bucket < ADDRMAN_TRIED_BUCKET_COUNT); if (Assume(position < ADDRMAN_BUCKET_SIZE) && Assume(bucket < ADDRMAN_TRIED_BUCKET_COUNT)) {
return vvTried[bucket][position]; return vvTried[bucket][position];
}
} else { } else {
assert(bucket < ADDRMAN_NEW_BUCKET_COUNT); if (Assume(position < ADDRMAN_BUCKET_SIZE) && Assume(bucket < ADDRMAN_NEW_BUCKET_COUNT)) {
return vvNew[bucket][position]; return vvNew[bucket][position];
}
} }
return -1;
} }
std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const

View file

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