Skip to content

Commit 28ce2d5

Browse files
committed
Clean up chaser_check a bit, allow sync without outbound.
1 parent 6577153 commit 28ce2d5

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

include/bitcoin/node/chasers/chaser_check.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ class BCN_API chaser_check
9494
bool purging() const NOEXCEPT;
9595

9696
// These are thread safe.
97+
const float allowed_deviation_;
9798
const size_t maximum_concurrency_;
9899
const size_t maximum_height_;
99100
const size_t connections_;
100-
const float allowed_deviation_;
101+
const size_t step_;
101102

102103
// These are protected by strand.
103104
size_t inventory_{};

src/chasers/chaser_check.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,30 @@ BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
4242
BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED)
4343
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
4444

45+
size_t get_target_connections(const network::settings& network) NOEXCEPT
46+
{
47+
// Only divide among manual and target outbound, but will also use inbound.
48+
const auto outgoing = ceilinged_add(network.outbound.connections,
49+
network.manual.peers.size());
50+
51+
// Only divide by inbound config if there are no outgoing connections.
52+
return is_zero(outgoing) ? network.inbound.connections : outgoing;
53+
}
54+
55+
size_t get_step(size_t connections, size_t maximum_concurrency) NOEXCEPT
56+
{
57+
constexpr auto max = messages::peer::max_inventory;
58+
const auto span = ceilinged_multiply(max, connections);
59+
return std::min(maximum_concurrency, span);
60+
}
61+
4562
chaser_check::chaser_check(full_node& node) NOEXCEPT
4663
: chaser(node),
64+
allowed_deviation_(node.node_settings().allowed_deviation),
4765
maximum_concurrency_(node.node_settings().maximum_concurrency_()),
4866
maximum_height_(node.node_settings().maximum_height_()),
49-
connections_(node.network_settings().outbound.connections),
50-
allowed_deviation_(node.node_settings().allowed_deviation)
67+
connections_(get_target_connections(node.network_settings())),
68+
step_(get_step(connections_, maximum_concurrency_))
5169
{
5270
}
5371

@@ -515,18 +533,13 @@ size_t chaser_check::set_unassociated() NOEXCEPT
515533

516534
size_t chaser_check::get_inventory_size() const NOEXCEPT
517535
{
518-
// Either condition means blocks shouldn't be getting downloaded (yet).
519-
const size_t peers = network_settings().outbound.connections;
520-
if (is_zero(peers) || !is_current(false))
536+
if (is_zero(connections_) || !is_current(false))
521537
return zero;
522538

523539
const auto& query = archive();
524540
const auto fork = query.get_fork();
525-
526-
const auto span = ceilinged_multiply(messages::peer::max_inventory, peers);
527-
const auto step = std::min(maximum_concurrency_, span);
528-
const auto inventory = query.get_unassociated_count_above(fork, step);
529-
return ceilinged_divide(inventory, peers);
541+
const auto inventory = query.get_unassociated_count_above(fork, step_);
542+
return ceilinged_divide(inventory, connections_);
530543
}
531544

532545
BC_POP_WARNING()

0 commit comments

Comments
 (0)