Skip to content

Commit

Permalink
Merge pull request #655 from evoskuil/master
Browse files Browse the repository at this point in the history
Use ASIO concurrency for parallel confirmation by tx.
  • Loading branch information
evoskuil authored Jun 26, 2024
2 parents 94fbdea + 1dabc1c commit 56a97aa
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 147 deletions.
14 changes: 9 additions & 5 deletions include/bitcoin/node/chasers/chaser_confirm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <bitcoin/node/chasers/chaser.hpp>
#include <bitcoin/node/define.hpp>

////#define SEQUENTIAL

namespace libbitcoin {
namespace node {

Expand All @@ -47,7 +49,9 @@ class BCN_API chaser_confirm
event_value value) NOEXCEPT;

virtual void do_validated(height_t height) NOEXCEPT;
#if defined(UNDEFINED)
#if defined(SEQUENTIAL)
virtual void do_organize(size_t height) NOEXCEPT;
#else
virtual void do_organize(size_t height) NOEXCEPT;
virtual bool enqueue_block(const database::header_link& link) NOEXCEPT;
virtual void confirm_tx(const database::context& ctx,
Expand All @@ -58,7 +62,8 @@ class BCN_API chaser_confirm
const database::header_link& link, size_t height)NOEXCEPT;
virtual void confirm_block(const code& ec,
const database::header_link& link, size_t height) NOEXCEPT;
#endif // UNDEFINED
virtual void next_block(size_t height) NOEXCEPT;
#endif // SEQUENTIAL

private:
bool set_organized(const database::header_link& link,
Expand All @@ -67,9 +72,8 @@ class BCN_API chaser_confirm
height_t height) NOEXCEPT;
bool set_reorganized(const database::header_link& link,
height_t height) NOEXCEPT;
bool roll_back(const header_links& popped,
const database::header_link& link, size_t fork_point,
size_t top) NOEXCEPT;
bool roll_back(header_links& popped, const database::header_link& link,
size_t fork_point, size_t top) NOEXCEPT;

bool get_fork_work(uint256_t& fork_work, header_links& fork,
height_t fork_top) const NOEXCEPT;
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node/impl/chasers/chaser_organize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ void CLASS::do_organize(typename Block::cptr block_ptr,
// Checking currency before notify also avoids excessive work backlog.
if (is_block() || is_current(header.timestamp()))
{
// TODO: this should probably be sent only once for the process.
// If at start the fork point is top of both chains, and next candidate
// is already downloaded, then new header will arrive and download will
// be skipped, resulting in stall until restart at which time the start
Expand Down
16 changes: 7 additions & 9 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,8 @@ size_t chaser_check::set_unassociated() NOEXCEPT

// Inventory size gets set only once.
if (is_zero(inventory_))
{
inventory_ = get_inventory_size();
if (is_zero(inventory_)) return zero;
}
if (is_zero((inventory_ = get_inventory_size())))
return zero;

// Due to previous downloads, validation can race ahead of last request.
// The last request (requested_) stops at the last gap in the window, but
Expand Down Expand Up @@ -394,11 +392,11 @@ size_t chaser_check::get_inventory_size() const NOEXCEPT
if (is_zero(peers) || !is_current())
return zero;

const auto step = config().node.maximum_concurrency_();
const auto fork = archive().get_fork();
const auto scan = archive().get_unassociated_count_above(fork, step);
const auto span = std::min(step, scan);
const auto inventory = std::min(span, messages::max_inventory);
const auto& query = archive();
const auto fork = query.get_fork();
const auto window = config().node.maximum_concurrency_();
const auto step = std::min(window, messages::max_inventory);
const auto inventory = query.get_unassociated_count_above(fork, step);
return system::ceilinged_divide(inventory, peers);
}

Expand Down
Loading

0 comments on commit 56a97aa

Please sign in to comment.