Skip to content

Commit

Permalink
Pass result handler to organize methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 22, 2024
1 parent 12fe58d commit be1b43c
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 114 deletions.
7 changes: 3 additions & 4 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class BCN_API chaser
chaser(full_node& node) NOEXCEPT;
~chaser() NOEXCEPT;

/// Node is closed.
bool closed() const NOEXCEPT;

/// Node configuration settings.
const node::configuration& config() const NOEXCEPT;

Expand All @@ -120,15 +123,11 @@ class BCN_API chaser
/// Set chaser event (does not require network strand).
void notify(const code& ec, chase event_, link value) NOEXCEPT;

/// Close the node in case of failure.
void stop(const code& ec) NOEXCEPT;

private:
void do_notify(const code& ec, chase event_, link value) NOEXCEPT;

// These are thread safe (mostly).
full_node& node_;
const node::configuration& config_;
network::asio::strand strand_;

// This is protected by the network strand.
Expand Down
8 changes: 4 additions & 4 deletions include/bitcoin/node/chasers/chaser_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class BCN_API chaser_block
virtual code start() NOEXCEPT;

/// Validate and organize next block in sequence relative to caller peer.
/// Causes a fault/stop if preceding blocks have not been stored.
virtual void organize(
const system::chain::block::cptr& block_ptr) NOEXCEPT;
virtual void organize(const system::chain::block::cptr& block_ptr,
network::result_handler&& handler) NOEXCEPT;

protected:
struct validated_block
Expand Down Expand Up @@ -99,7 +98,8 @@ class BCN_API chaser_block

private:
void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT;
void do_organize(const system::chain::block::cptr& block) NOEXCEPT;
void do_organize(const system::chain::block::cptr& block,
const network::result_handler& handler) NOEXCEPT;

// These are thread safe.
const system::chain::checkpoints& checkpoints_;
Expand Down
8 changes: 4 additions & 4 deletions include/bitcoin/node/chasers/chaser_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ class BCN_API chaser_header
virtual code start() NOEXCEPT;

/// Validate and organize next header in sequence relative to caller peer.
/// Causes a fault/stop if preceding headers have not been stored.
virtual void organize(
const system::chain::header::cptr& header_ptr) NOEXCEPT;
virtual void organize(const system::chain::header::cptr& header_ptr,
network::result_handler&& handler) NOEXCEPT;

protected:
struct proposed_header
Expand Down Expand Up @@ -99,7 +98,8 @@ class BCN_API chaser_header

private:
void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT;
void do_organize(const system::chain::header::cptr& header) NOEXCEPT;
void do_organize(const system::chain::header::cptr& header,
const network::result_handler& handler) NOEXCEPT;

// These are thread safe.
const system::chain::checkpoints& checkpoints_;
Expand Down
13 changes: 9 additions & 4 deletions include/bitcoin/node/full_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,19 @@ class BCN_API full_node
/// Close the node.
void close() NOEXCEPT override;

/// The node is closed.
bool closed() const NOEXCEPT override;

/// Chasers.
/// -----------------------------------------------------------------------

/// Organize a validated header, failures stop the node.
virtual void organize(const system::chain::header::cptr& header) NOEXCEPT;
/// Organize a validated header.
virtual void organize(const system::chain::header::cptr& header,
network::result_handler&& handler) NOEXCEPT;

/// Organize a validated block, failures stop the node.
virtual void organize(const system::chain::block::cptr& block) NOEXCEPT;
/// Organize a validated block.
virtual void organize(const system::chain::block::cptr& block,
network::result_handler&& handler) NOEXCEPT;

/// Properties.
/// -----------------------------------------------------------------------
Expand Down
13 changes: 9 additions & 4 deletions include/bitcoin/node/protocols/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ class BCN_API protocol
virtual void performance(uint64_t channel, uint64_t speed,
network::result_handler&& handler) const NOEXCEPT;

/// Organize a validated header, failures stop the node.
virtual void organize(const system::chain::header::cptr& header) NOEXCEPT;
/// Organize a validated header.
virtual void organize(const system::chain::header::cptr& header,
network::result_handler&& handler) NOEXCEPT;

/// Organize a validated block, failures stop the node.
virtual void organize(const system::chain::block::cptr& block) NOEXCEPT;
/// Organize a validated block.
virtual void organize(const system::chain::block::cptr& block,
network::result_handler&& handler) NOEXCEPT;

/// Handle organize result.
virtual void handle_organize(const code& ec) NOEXCEPT;

/// Configuration settings for all libraries.
const configuration& config() const NOEXCEPT;
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/node/protocols/protocol_header_in_31800.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class BCN_API protocol_header_in_31800
void start() NOEXCEPT override;

protected:
/// Invoked when initial headers sync is complete.
virtual void complete() NOEXCEPT;

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

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

private:
network::messages::get_headers create_get_headers() NOEXCEPT;
network::messages::get_headers create_get_headers(
Expand Down
10 changes: 6 additions & 4 deletions include/bitcoin/node/sessions/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ class BCN_API session
virtual void performance(uint64_t channel, uint64_t speed,
network::result_handler&& handler) NOEXCEPT;

/// Organize a validated header, failures stop the node.
virtual void organize(const system::chain::header::cptr& header) NOEXCEPT;
/// Organize a validated header.
virtual void organize(const system::chain::header::cptr& header,
network::result_handler&& handler) NOEXCEPT;

/// Organize a validated block, failures stop the node.
virtual void organize(const system::chain::block::cptr& block) NOEXCEPT;
/// Organize a validated block.
virtual void organize(const system::chain::block::cptr& block,
network::result_handler&& handler) NOEXCEPT;

/// Configuration settings for all libraries.
const configuration& config() const NOEXCEPT;
Expand Down
14 changes: 6 additions & 8 deletions src/chasers/chaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

chaser::chaser(full_node& node) NOEXCEPT
: node_(node),
config_(node.config()),
strand_(node.service().get_executor()),
subscriber_(node.event_subscriber()),
reporter(node.log)
Expand All @@ -45,9 +44,14 @@ chaser::~chaser() NOEXCEPT
{
}

bool chaser::closed() const NOEXCEPT
{
return node_.closed();
}

const node::configuration& chaser::config() const NOEXCEPT
{
return config_;
return node_.config();
}

chaser::query& chaser::archive() const NOEXCEPT
Expand Down Expand Up @@ -90,12 +94,6 @@ void chaser::do_notify(const code& ec, chase event_, link value) NOEXCEPT
subscriber_.notify(ec, event_, value);
}

void chaser::stop(const code& ec) NOEXCEPT
{
LOGF("Chaser fault, " << ec.message());
node_.close();
}

BC_POP_WARNING()

} // namespace database
Expand Down
Loading

0 comments on commit be1b43c

Please sign in to comment.