Skip to content

Commit

Permalink
Merge pull request #542 from evoskuil/master
Browse files Browse the repository at this point in the history
Improve error logging, style, refactor.
  • Loading branch information
evoskuil authored Feb 24, 2024
2 parents d40c236 + 1ad5cce commit e30e5ff
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 154 deletions.
12 changes: 9 additions & 3 deletions include/bitcoin/node/chasers/chaser_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BCN_API chaser_block
struct validated_block
{
database::context context;
system::chain::block::cptr item;
system::chain::block::cptr block;
};
typedef std::vector<database::header_link> header_links;

Expand Down Expand Up @@ -91,15 +91,21 @@ class BCN_API chaser_block
/// Move tree header to database and push to top of candidate chain.
virtual bool push(const system::hash_digest& key) NOEXCEPT;

/// Populate block prevouts and metadata from block tree.
virtual void populate(const system::chain::block& block) const NOEXCEPT;

/// Validate and organize next block in sequence relative to caller peer.
virtual void do_organize(const system::chain::block::cptr& block,
const network::result_handler& handler) NOEXCEPT;

/// Properties.
/// Given non-current blocks cached in memory, should always be zero/false.
virtual const network::wall_clock::duration& currency_window() const NOEXCEPT;
virtual bool use_currency_window() const NOEXCEPT;

private:
void set_prevout(const system::chain::input& input) const NOEXCEPT;
void do_handle_event(const code& ec, chase event_, link value) 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: 5 additions & 3 deletions include/bitcoin/node/chasers/chaser_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BCN_API chaser_header
struct proposed_header
{
database::context context;
system::chain::header::cptr item;
system::chain::header::cptr header;
};
typedef std::vector<database::header_link> header_links;

Expand Down Expand Up @@ -92,14 +92,16 @@ class BCN_API chaser_header
/// Move tree header to database and push to top of candidate chain.
virtual bool push(const system::hash_digest& key) NOEXCEPT;

/// Validate and organize next header in sequence relative to caller peer.
virtual void do_organize(const system::chain::header::cptr& header,
const network::result_handler& handler) NOEXCEPT;

/// Properties.
virtual const network::wall_clock::duration& currency_window() const NOEXCEPT;
virtual bool use_currency_window() const NOEXCEPT;

private:
void do_handle_event(const code& ec, chase event_, link value) 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
3 changes: 0 additions & 3 deletions include/bitcoin/node/protocols/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ class BCN_API protocol
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
4 changes: 4 additions & 0 deletions include/bitcoin/node/protocols/protocol_block_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class BCN_API protocol_block_in
/// Invoked when initial blocks sync is complete.
virtual void complete() NOEXCEPT;

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

private:
static system::hashes to_hashes(
const network::messages::get_data& getter) NOEXCEPT;
Expand Down
5 changes: 5 additions & 0 deletions include/bitcoin/node/protocols/protocol_block_in_31800.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace libbitcoin {
namespace node {

/// This does NOT inhereit from protocol_block_in.
class BCN_API protocol_block_in_31800
: public node::protocol,
protected network::tracker<protocol_block_in_31800>
Expand Down Expand Up @@ -82,6 +83,10 @@ class BCN_API protocol_block_in_31800
/// Invoked when initial blocks sync is complete.
virtual void complete() NOEXCEPT;

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

private:
static system::hashes to_hashes(
const network::messages::get_data& getter) NOEXCEPT;
Expand Down
4 changes: 4 additions & 0 deletions include/bitcoin/node/protocols/protocol_header_in_31800.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class BCN_API protocol_header_in_31800
/// Invoked when initial headers sync is complete.
virtual void complete() NOEXCEPT;

/// Handle organize result.
virtual void handle_organize(const code& ec,
const system::chain::header::cptr& header_ptr) NOEXCEPT;

private:
network::messages::get_headers create_get_headers() NOEXCEPT;
network::messages::get_headers create_get_headers(
Expand Down
49 changes: 23 additions & 26 deletions include/bitcoin/node/sessions/attach.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,37 @@ class attach
void attach_protocols(
const network::channel::ptr& channel) NOEXCEPT override
{
auto& self = *this;
////const auto version = channel->negotiated_version();
////constexpr auto performance = false;

// Attach appropriate alert, reject, ping, and/or address protocols.
Session::attach_protocols(channel);

auto& self = *this;
const auto version = channel->negotiated_version();

if (version >= network::messages::level::bip130)
{
channel->attach<protocol_header_in_70012>(self)->start();
channel->attach<protocol_header_out_70012>(self)->start();
}
else if (version >= network::messages::level::headers_protocol)
{
channel->attach<protocol_header_in_31800>(self)->start();
channel->attach<protocol_header_out_31800>(self)->start();
}

////if (version >= network::messages::level::headers_protocol)
// Very hard to find < 31800 peer to connect with.
////if (version >= network::messages::level::bip130)
////{
//// // Channels only compete for download rate in outbound session.
//// constexpr auto performance = false;
////
//// // Parallel block download (works with header protocol).
//// channel->attach<protocol_block_in_31800>(self, performance)->start();
//// // Headers-first synchronization (parallel block download).
//// channel->attach<protocol_header_in_70012>(self)->start();
//// channel->attach<protocol_header_out_70012>(self)->start();
//// ////channel->attach<protocol_block_in_31800>(self, performance)->start();
////}
////else
////else if (version >= network::messages::level::headers_protocol)
////{
//// // Blocks-first synchronization (no header protocol).
//// channel->attach<protocol_block_in>(self)->start();
//// // Headers-first synchronization (parallel block download).
//// channel->attach<protocol_header_in_31800>(self)->start();
//// channel->attach<protocol_header_out_31800>(self)->start();
//// ////channel->attach<protocol_block_in_31800>(self, performance)->start();
////}
////else
{
// Blocks-first synchronization (no header protocol).
channel->attach<protocol_block_in>(self)->start();
}

////channel->attach<protocol_block_out>(self)->start();
////channel->attach<protocol_transaction_in>(self)->start();
////channel->attach<protocol_transaction_out>(self)->start();
channel->attach<protocol_block_out>(self)->start();
channel->attach<protocol_transaction_in>(self)->start();
channel->attach<protocol_transaction_out>(self)->start();
}
};

Expand Down
Loading

0 comments on commit e30e5ff

Please sign in to comment.