Skip to content

Commit

Permalink
Boss/Mod/ChannelFinderByPopularity.cpp: Propose just one node if we a…
Browse files Browse the repository at this point in the history
…lready have many channels.
  • Loading branch information
ZmnSCPxj committed Nov 3, 2020
1 parent 3053223 commit 168034c
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions Boss/Mod/ChannelFinderByPopularity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ namespace {
* @brief ChannelFinderByPopularity will only
* propose up to this number of nodes.
*/
auto const max_proposals = size_t(4);
auto const max_proposals = size_t(5);

/** min_channels_to_disable
/** min_channels_to_backoff
*
* @brief once we have achieved this number of
* channels, ChannelFinderByPopularity will
* stop making proposals.
* make only one proposal.
*/
auto const min_channels_to_disable = size_t(4);
auto const min_channels_to_backoff = size_t(4);

/** min_nodes_to_process
*
Expand Down Expand Up @@ -79,10 +79,13 @@ class ChannelFinderByPopularity::Impl {
bool running;
/* Set if we are waiting for a while. */
bool try_later;
/* Set if we are in single-proposal mode. */
bool single_proposal_only;

void start() {
running = false;
try_later = false;
single_proposal_only = false;
bus.subscribe<Msg::Init>([this](Msg::Init const& init) {
rpc = &init.rpc;
self = init.self_id;
Expand Down Expand Up @@ -183,11 +186,20 @@ class ChannelFinderByPopularity::Impl {
auto channels = res["channels"];
if (!channels.is_array())
return self_disable();
if (channels.size() >= min_channels_to_disable)
return self_disable();
auto msg = "";
if (channels.size() >= min_channels_to_backoff) {
single_proposal_only = true;
msg = "We seem to have many channels, "
"will find one node only."
;
} else {
single_proposal_only = false;
msg = "Will find nodes.";
}
return Boss::log( bus, Debug
, "ChannelFinderByPopularity: "
"Will find nodes."
"%s"
, msg
).then([this]() {
return continue_solicit();
});
Expand All @@ -197,12 +209,9 @@ class ChannelFinderByPopularity::Impl {
Ev::Io<void> self_disable() {
return Boss::log( bus, Debug
, "ChannelFinderByPopularity: "
"Voluntarily not operating, "
"we seem to have many channels."
"Unexpected result of `listchannels`."
).then([this]() {
/* Do not signal failed, since we successfully
* decided not to do anything. */
return signal_task_completion(false);
return signal_task_completion(true);
});
}

Expand Down Expand Up @@ -319,7 +328,10 @@ class ChannelFinderByPopularity::Impl {
wsum += entry.peers.size();
/* If fewer are selected than max proposals, go extend
* it. */
if (selected.size() < max_proposals) {
auto actual_max_proposals = max_proposals;
if (single_proposal_only)
actual_max_proposals = 1;
if (selected.size() < actual_max_proposals) {
selected.emplace_back(std::move(entry));
return select_by_popularity();
}
Expand Down

0 comments on commit 168034c

Please sign in to comment.