Skip to content

Conversation

dergoegge
Copy link
Member

This PR splits off the next couple commits from #25268 that introduce the EvictionManager and use it for the inbound eviction logic.

One instance of the EvictionManager is created at start up and passed as a reference to the connection and peer managers. The connection and peer managers report all eviction relevant information (for inbound connections) to the eviction manager who ultimately suggests nodes to evict as the result of EvictionManager::SelectNodeToEvict.

Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK.

Added a high-level question about NodeEvictionCandidate to kick things off, will continue with review.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 8, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK theuni, jnewbery, naumenkogs

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28222 (Use shared_ptr for CNode inside CConnman by willcl-ark)
  • #28170 (p2p: adaptive connections services flags by furszy)
  • #27912 (net: disconnect inside AttemptToEvictConnection by willcl-ark)
  • #27837 (net: introduce block tracker to retry to download blocks after failure by furszy)
  • #27600 (net: Add new permission forceinbound to evict a random unprotected connection if all slots are otherwise full by pinheadmz)
  • #27509 (Relay own transactions only via short-lived Tor or I2P connections by vasild)
  • #27385 (net, refactor: extract Network and BIP155Network logic to node/network by jonatack)
  • #27213 (p2p: Diversify automatic outbound connections with respect to networks by amitiuttarwar)
  • #26812 (test: add end-to-end tests for CConnman and PeerManager by vasild)
  • #26621 (refactor: Continue moving application data from CNode to Peer by dergoegge)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

return ::SelectNodeToEvict(std::move(candidates));
}

void EvictionManagerImpl::UpdateMinPingTime(NodeId id, std::chrono::microseconds ping_time)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/me idly wonders whether these setters can be templated to avoid repetitive boilerplate code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to come up with a cool way of doing this with templates but didn't end with anything useful.

Copy link
Contributor

@ajtowns ajtowns Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like this would work:

class EvictionManagerImpl
{
    ...
    template <typename Fn>
    auto CandidateOp(NodeId id, Fn&& fn)
    {
        LOCK(m_candidates_mutex);
        auto it = m_candidates.find(offset);
        if (it != m_candidates.end()) {
            return fn(it->second);
        } else {
            // return a dummy value of the right type, including void
            return ([]() -> decltype(fn(it->second)) { return {}; })();
            // EDIT: maybe nicer to write:
            using T = decltype(fn(it->second));
            return T();
        }
    }
    ...
};

void EvictionManager::UpdateLastBlockTime(NodeId id, std::chrono::seconds block_time)
{
    m_impl->CandidateOp(id, [](NodeEvictionCandidate& nec) {
        nec.m_last_block_time = block_time;
    });
}

void EvictionManager::GetLastBlockTime(NodeId id) const
{
    return m_impl->CandidateOp(id, [](const NodeEvictionCandidate& nec) {
        return nec.m_last_block_time;
    });
}

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big concept ACK!

Minor cosmetic comments inline.

@dergoegge
Copy link
Member Author

Rebased.

@maflcko
Copy link
Member

maflcko commented Jul 21, 2023

Needs rebase if still relevant

@dergoegge dergoegge force-pushed the 2022-07-evictionman-2ofN branch from ac60275 to 108e7a0 Compare July 24, 2023 12:40
@dergoegge dergoegge force-pushed the 2022-07-evictionman-2ofN branch from 108e7a0 to a7a5b4e Compare July 26, 2023 12:47
dergoegge added 10 commits July 26, 2023 15:01
We temporarily introduce a method to get a specific
NodeEvictionCandidate from the eviction manager for use in
`CConnman::AttemptToEvictConnection()`. `EvictionManager::GetCandidate`
is removed once we are done moving the remaining eviction state from
`CNode` to the eviction manager.
Now that the eviction manager is aware of the keyed net group and
whether or not a peer is prefered for eviction, we can get rid of the
corresponding CNode members, since they are not used elsewhere.
@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 6, 2023

🐙 This pull request conflicts with the target branch and needs rebase.

@achow101 achow101 marked this pull request as draft September 20, 2023 16:19
@fanquake
Copy link
Member

@instagibbs

@dergoegge dergoegge closed this Sep 28, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Sep 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants