Skip to content

Commit

Permalink
Merge pull request #640 from evoskuil/master
Browse files Browse the repository at this point in the history
Pass bypass from check chaser to protocol via get_hashes handler.
  • Loading branch information
evoskuil authored Jun 7, 2024
2 parents 6c9d69b + dbf92c0 commit 6fa4518
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 218 deletions.
12 changes: 8 additions & 4 deletions include/bitcoin/node/chase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@ enum class chase
/// Candidate Chain.
/// -----------------------------------------------------------------------

/// Legacy: A new strong branch exists (height_t).
/// A candidate header has been disassociated due to malleation (header_t).
/// Issued by 'header' and handled by 'check'.
header,

/// A new candidate branch exists from given branch point (height_t).
/// Issued by 'block' and handled by 'confirm'.
block,
blocks,

/// A new candidate branch exists (height_t).
/// A new candidate branch exists from given branch point (height_t).
/// Issued by 'header' and handled by 'check'.
header,
headers,

/// New candidate headers without txs exist (count_t).
/// Issued by 'check' and handled by 'block_in_31800'.
Expand Down
16 changes: 12 additions & 4 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,23 @@ class BCN_API chaser
/// Header timestamp is within configured span from current time.
bool is_current(uint32_t timestamp) const NOEXCEPT;

/// Position keeping.
/// Bypass (requires strand).
/// -----------------------------------------------------------------------

size_t& position() NOEXCEPT;
size_t bypass() const NOEXCEPT;
void set_bypass(size_t height) NOEXCEPT;
bool is_bypassed(size_t height) const NOEXCEPT;

/// Position (requires strand).
/// -----------------------------------------------------------------------

size_t position() const NOEXCEPT;
void set_position(size_t height) NOEXCEPT;

private:
// This is protected by strand.
size_t position_;
// These are protected by strand.
size_t bypass_{};
size_t position_{};

// These are thread safe (mostly).
full_node& node_;
Expand Down
18 changes: 14 additions & 4 deletions include/bitcoin/node/chasers/chaser_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define LIBBITCOIN_NODE_CHASERS_CHASER_CHECK_HPP

#include <deque>
#include <memory>
#include <bitcoin/network.hpp>
#include <bitcoin/node/chasers/chaser.hpp>
#include <bitcoin/node/define.hpp>
Expand All @@ -46,6 +47,7 @@ class BCN_API chaser_check

/// Initialize chaser state.
code start() NOEXCEPT override;
void stopping(const code& ec) NOEXCEPT override;

/// Interface for protocols to obtain/return pending download identifiers.
/// Identifiers not downloaded must be returned or chain will remain gapped.
Expand All @@ -54,14 +56,16 @@ class BCN_API chaser_check
network::result_handler&& handler) NOEXCEPT;

protected:
virtual void handle_purged(const code& ec) NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

virtual void do_bump(height_t branch_point) NOEXCEPT;
virtual void do_header(height_t branch_point) NOEXCEPT;
virtual void do_bump(height_t height) NOEXCEPT;
virtual void do_header(header_t height) NOEXCEPT;
virtual void do_checked(height_t height) NOEXCEPT;
virtual void do_headers(height_t branch_point) NOEXCEPT;
virtual void do_regressed(height_t branch_point) NOEXCEPT;
virtual void do_malleated(header_t link) NOEXCEPT;
virtual void do_handle_purged(const code& ec) NOEXCEPT;
virtual void do_get_hashes(const map_handler& handler) NOEXCEPT;
virtual void do_put_hashes(const map_ptr& map,
const network::result_handler& handler) NOEXCEPT;
Expand All @@ -70,8 +74,13 @@ class BCN_API chaser_check
typedef std::deque<map_ptr> maps;

map_ptr get_map() NOEXCEPT;
size_t get_unassociated() NOEXCEPT;
size_t set_unassociated() NOEXCEPT;
size_t get_inventory_size() const NOEXCEPT;
bool set_map(const map_ptr& map) NOEXCEPT;

void start_tracking() NOEXCEPT;
void stop_tracking() NOEXCEPT;
bool purging() const NOEXCEPT;

// These are thread safe.
const size_t maximum_concurrency_;
Expand All @@ -81,6 +90,7 @@ class BCN_API chaser_check
// These are protected by strand.
size_t inventory_{};
size_t requested_{};
job::ptr job_{};
maps maps_{};
};

Expand Down
6 changes: 0 additions & 6 deletions include/bitcoin/node/chasers/chaser_confirm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class BCN_API chaser_confirm
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

virtual void do_bypass(size_t height) NOEXCEPT;
virtual void do_validated(height_t height) NOEXCEPT;

private:
Expand All @@ -57,11 +56,6 @@ class BCN_API chaser_confirm
height_t fork_top) const NOEXCEPT;
bool get_is_strong(bool& strong, const uint256_t& fork_work,
size_t fork_point) const NOEXCEPT;

bool is_under_bypass(size_t height) const NOEXCEPT;

// This is protected by strand.
size_t bypass_{};
};

} // namespace node
Expand Down
17 changes: 7 additions & 10 deletions include/bitcoin/node/chasers/chaser_organize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ class chaser_organize
virtual bool handle_event(const code&, chase event_,
event_value value) NOEXCEPT;

/// Reorganize following Block unconfirmability.
virtual void do_disorganize(header_t header) NOEXCEPT;

/// Reorganize following strong branch discovery.
virtual void do_organize(typename Block::cptr& block_ptr,
const organize_handler& handler) NOEXCEPT;

/// Reorganize following Block unconfirmability.
virtual void do_disorganize(header_t header) NOEXCEPT;

/// Disassociate malleated block and notify repeat header in current job.
virtual void do_malleated(header_t link) NOEXCEPT;

/// Store Block to database and push to top of candidate chain.
virtual database::header_link push(const Block& block,
const system::chain::context& context) const NOEXCEPT;

/// Height represents a candidate block covered by checkpoint or milestone.
virtual inline bool is_under_bypass(size_t height) const NOEXCEPT;

/// Height represents a candidate block covered by active milestone.
virtual inline bool is_under_milestone(size_t height) const NOEXCEPT;

Expand All @@ -130,7 +130,7 @@ class chaser_organize
}
static constexpr auto chase_object() NOEXCEPT
{
return is_block() ? chase::block : chase::header;
return is_block() ? chase::blocks : chase::headers;
}

// Chain methods.
Expand Down Expand Up @@ -159,9 +159,6 @@ class chaser_organize
// Bypass methods.
// ------------------------------------------------------------------------

// The current bypass height.
inline size_t bypass_height() const NOEXCEPT;

// Set milestone cache if exists in candidate chain, send chase::bypass.
bool initialize_bypass() NOEXCEPT;

Expand Down
7 changes: 1 addition & 6 deletions include/bitcoin/node/chasers/chaser_validate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class BCN_API chaser_validate
virtual void do_regressed(height_t branch_point) NOEXCEPT;
virtual void do_checked(height_t height) NOEXCEPT;
virtual void do_bump(height_t height) NOEXCEPT;
virtual void do_bypass(size_t height) NOEXCEPT;

virtual bool enqueue_block(const database::header_link& link) NOEXCEPT;
virtual void validate_tx(const database::context& context,
Expand All @@ -68,23 +67,19 @@ class BCN_API chaser_validate
#endif // UNDEFINED

// neutrino
void update_position(size_t height) NOEXCEPT;
system::hash_digest get_neutrino(size_t height) const NOEXCEPT;
bool update_neutrino(const database::header_link& link) NOEXCEPT;
bool update_neutrino(const database::header_link& link,
const system::chain::block& block) NOEXCEPT;

// positions
void update_position(size_t height) NOEXCEPT;
bool is_under_bypass(size_t height) const NOEXCEPT;

// These are thread safe.
const uint64_t initial_subsidy_;
const uint32_t subsidy_interval_blocks_;

// These are protected by strand.
network::threadpool threadpool_;
system::hash_digest neutrino_{};
size_t bypass_{};
};

} // namespace node
Expand Down
6 changes: 4 additions & 2 deletions include/bitcoin/node/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ typedef std::function<void(const code&, size_t)> organize_handler;
typedef database::store<database::map> store;
typedef database::query<store> query;

/// Hash accumulator.
/// Work types.
typedef network::race_all<const code&> job;
typedef std::shared_ptr<database::associations> map_ptr;
typedef std::function<void(const code&, const map_ptr&)> map_handler;
typedef std::function<void(const code&, const map_ptr&, const job::ptr&,
size_t)> map_handler;

/// Node events.
typedef uint64_t object_key;
Expand Down
Loading

0 comments on commit 6fa4518

Please sign in to comment.