Skip to content

Commit

Permalink
Stub in parallel download.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 25, 2024
1 parent e8f8f2a commit 9e42bc0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 240 deletions.
8 changes: 7 additions & 1 deletion include/bitcoin/node/chasers/chaser_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ class BCN_API chaser_check
virtual ~chaser_check() NOEXCEPT;

virtual code start() NOEXCEPT;
virtual void checked(const system::chain::block::cptr& block) NOEXCEPT;

virtual void get_hashes(network::result_handler&& handler) NOEXCEPT;
virtual void put_hashes(network::result_handler&& handler) NOEXCEPT;

protected:
/// Handlers.
virtual void handle_header(height_t branch_point) NOEXCEPT;
virtual void handle_event(const code& ec, chase event_,
link value) NOEXCEPT;

virtual void do_get_hashes(const network::result_handler& handler) NOEXCEPT;
virtual void do_put_hashes(const network::result_handler& handler) NOEXCEPT;

private:
void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT;
};
Expand Down
42 changes: 10 additions & 32 deletions include/bitcoin/node/protocols/protocol_block_in_31800.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,58 +55,36 @@ class BCN_API protocol_block_in_31800
void start() NOEXCEPT override;
void stopping(const code& ec) NOEXCEPT override;

protected:
struct track
{
const size_t announced;
const system::hash_digest last;
system::hashes hashes;
};
/// Check and store any registered block in any order of arrival.
virtual void check(const system::chain::block::cptr& block_ptr,
network::result_handler&& handler) NOEXCEPT;

typedef std::shared_ptr<track> track_ptr;

/// Recieved incoming inventory message.
virtual bool handle_receive_inventory(const code& ec,
const network::messages::inventory::cptr& message) NOEXCEPT;
protected:

/// Recieved incoming block message.
virtual bool handle_receive_block(const code& ec,
const network::messages::block::cptr& message,
const track_ptr& tracker) NOEXCEPT;
const network::messages::block::cptr& message) NOEXCEPT;

/// Handle performance timer event.
virtual void handle_performance_timer(const code& ec) NOEXCEPT;

/// Handle result of performance reporting.
virtual void handle_performance(const code& ec) NOEXCEPT;

/// Invoked when initial blocks sync is complete.
virtual void complete() NOEXCEPT;

/// Handle organize result.
virtual void handle_organize(const code& ec, size_t height,
const system::chain::block::cptr& block_ptr) NOEXCEPT;
/// Handle check result.
virtual void handle_check(const code& ec) NOEXCEPT;

private:
static system::hashes to_hashes(
const network::messages::get_data& getter) NOEXCEPT;

network::messages::get_blocks create_get_inventory() const NOEXCEPT;
network::messages::get_blocks create_get_inventory(
const system::hash_digest& last) const NOEXCEPT;
network::messages::get_blocks create_get_inventory(
system::hashes&& start_hashes) const NOEXCEPT;

network::messages::get_data create_get_data(
const network::messages::inventory& message) const NOEXCEPT;
const system::hashes& hashes) const NOEXCEPT;

void do_handle_performance(const code& ec) NOEXCEPT;

// Thread safe.
// These are thread safe.
const bool report_performance_;
const network::messages::inventory::type_id block_type_;

// Protected by strand.
// These are protected by strand.
uint64_t bytes_{ zero };
system::chain::checkpoint top_{};
network::steady_clock::time_point start_{};
Expand Down
73 changes: 50 additions & 23 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@

namespace libbitcoin {
namespace node {


using namespace network;
using namespace system;
using namespace system::chain;
using namespace std::placeholders;

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

// Requires subscriber_ protection (call from node construct or node.strand).
/// We need to be able to perform block.check(ctx) while we still have the
/// deserialized block, because of the witness commitment check (hash).
/// Requires timestamp (header) height, mtp, flags. These can be cached on the
/// block hash registry maintained by this chaser or queried from the stored
/// header. Caching requries rolling forward through all states as the registry
/// is initialized. Store query is simpler and may be as fast.

chaser_check::chaser_check(full_node& node) NOEXCEPT
: chaser(node)
{
Expand All @@ -43,56 +51,75 @@ chaser_check::~chaser_check() NOEXCEPT
{
}

// TODO: initialize check state.
code chaser_check::start() NOEXCEPT
{
BC_ASSERT_MSG(node_stranded(), "chaser_check");

// get_all_unassociated_above(0)
// TODO: get_all_unassociated_above(0)
BC_ASSERT_MSG(true, "Store not initialized.");

return subscribe(std::bind(&chaser_check::handle_event,
this, _1, _2, _3));
}

// protected
void chaser_check::handle_event(const code& ec, chase event_,
link value) NOEXCEPT
{
boost::asio::post(strand(),
std::bind(&chaser_check::do_handle_event, this, ec, event_, value));
std::bind(&chaser_check::do_handle_event,
this, ec, event_, value));
}

void chaser_check::do_handle_event(const code& ec, chase event_,
// private
void chaser_check::do_handle_event(const code&, chase event_,
link value) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_check");

if (ec)
if (event_ == chase::stop)
return;

switch (event_)
if (event_ == chase::header)
{
case chase::header:
{
BC_ASSERT(std::holds_alternative<height_t>(value));
handle_header(std::get<height_t>(value));
break;
}
default:
return;
BC_ASSERT(std::holds_alternative<height_t>(value));
handle_header(std::get<height_t>(value));
}
}

// TODO: handle the new strong branch (may issue 'checked').
void chaser_check::handle_header(height_t) NOEXCEPT
void chaser_check::get_hashes(result_handler&& handler) NOEXCEPT
{
boost::asio::post(strand(),
std::bind(&chaser_check::do_get_hashes,
this, std::move(handler)));
}

void chaser_check::put_hashes(result_handler&& handler) NOEXCEPT
{
boost::asio::post(strand(),
std::bind(&chaser_check::do_put_hashes,
this, std::move(handler)));
}

// protected
// ----------------------------------------------------------------------------

void chaser_check::do_get_hashes(const result_handler&) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_check");
}

void chaser_check::do_put_hashes(const result_handler&) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_check");
////LOGN("Handle candidate organization above height (" << branch_point << ").");
// get_all_unassociated_above(branch_point)
}

void chaser_check::checked(const block::cptr&) NOEXCEPT
// New branch organized, queue up candidate downloads from branch point.
void chaser_check::handle_header(height_t) NOEXCEPT
{
// Push checked block into store and issue 'checked' event so that connect
// can connect the next blocks in order. Executes in caller thread.
BC_ASSERT_MSG(stranded(), "chaser_check");

// TODO: get_all_unassociated_above(branch_point)
}

BC_POP_WARNING()
Expand Down
Loading

0 comments on commit 9e42bc0

Please sign in to comment.