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

Replace some asserts in PeerFinder::Logic with LogicError #4562

Merged
merged 5 commits into from
Oct 18, 2023
Merged
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
35 changes: 27 additions & 8 deletions src/ripple/peerfinder/impl/Logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,9 @@ class Logic
// assert later when erasing the key.
slot->public_key(key);
{
auto const result = keys_.insert(key);
[[maybe_unused]] bool const inserted = keys_.insert(key).second;
// Public key must not already exist
assert(result.second);
(void)result.second;
assert(inserted);
}

// Change state and update counts
Expand All @@ -434,7 +433,11 @@ class Logic
if (slot->fixed() && !slot->inbound())
{
auto iter(fixed_.find(slot->remote_endpoint()));
assert(iter != fixed_.end());
if (iter == fixed_.end())
LogicError(
"PeerFinder::Logic::activate(): remote_endpoint "
"missing from fixed_");

iter->second.success(m_clock.now());
JLOG(m_journal.trace()) << beast::leftw(18) << "Logic fixed "
<< slot->remote_endpoint() << " success";
Expand Down Expand Up @@ -858,7 +861,11 @@ class Logic
{
auto const iter = slots_.find(slot->remote_endpoint());
// The slot must exist in the table
assert(iter != slots_.end());
if (iter == slots_.end())
LogicError(
"PeerFinder::Logic::remove(): remote_endpoint "
"missing from slots_");

// Remove from slot by IP table
slots_.erase(iter);
}
Expand All @@ -867,15 +874,23 @@ class Logic
{
auto const iter = keys_.find(*slot->public_key());
// Key must exist
assert(iter != keys_.end());
if (iter == keys_.end())
LogicError(
"PeerFinder::Logic::remove(): public_key missing "
"from keys_");

keys_.erase(iter);
}
// Remove from connected address table
{
auto const iter(
connectedAddresses_.find(slot->remote_endpoint().address()));
// Address must exist
assert(iter != connectedAddresses_.end());
if (iter == connectedAddresses_.end())
LogicError(
"PeerFinder::Logic::remove(): remote_endpont "
"address missing from connectedAddresses_");

connectedAddresses_.erase(iter);
}

Expand All @@ -894,7 +909,11 @@ class Logic
if (slot->fixed() && !slot->inbound() && slot->state() != Slot::active)
{
auto iter(fixed_.find(slot->remote_endpoint()));
assert(iter != fixed_.end());
if (iter == fixed_.end())
LogicError(
"PeerFinder::Logic::on_closed(): remote_endpont "
"missing from fixed_");

iter->second.failure(m_clock.now());
JLOG(m_journal.debug()) << beast::leftw(18) << "Logic fixed "
<< slot->remote_endpoint() << " failed";
Expand Down
Loading