Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate new validation/confirmation settings, clean up #691

Merged
merged 16 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
<<<<<<< HEAD
"cmake.sourceDirectory": "/home/nixmini/Repository/Source/libbitcoin-node/builds/cmake",
"cmake.useCMakePresets": "always"
}
=======
"cmake.sourceDirectory": "${workspaceFolder}/builds/cmake",
"cmake.useCMakePresets": "always"
}
>>>>>>> e3e1a43d (Regenerate artifacts.)
9 changes: 0 additions & 9 deletions builds/vscode/node.code-workspace
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
<<<<<<< HEAD
"folders": [
{
"path": "../../../libbitcoin-system"
Expand All @@ -13,14 +12,6 @@
{
"path": "../../../libbitcoin-node"
}
],
"settings": {}
=======
"folders": [
{
"path": "../../../libbitcoin-node"
}
],
"settings": {}
>>>>>>> e3e1a43d (Regenerate artifacts.)
}
10 changes: 6 additions & 4 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class BCN_API chaser

/// Should be called from node strand.
virtual code start() NOEXCEPT = 0;

/// Override to capture non-blocking stopping.
virtual void stopping(const code& ec) NOEXCEPT;

/// Override to capture blocking stop.
virtual void stop() NOEXCEPT;

protected:
/// Abstract base class protected construct.
Expand All @@ -68,10 +74,6 @@ class BCN_API chaser
/// Methods.
/// -----------------------------------------------------------------------

/// Override to capture node stopping, allow full_node to invoke.
friend full_node;
virtual void stopping(const code& ec) NOEXCEPT;

/// Node threadpool is stopped and may still be joining.
virtual bool closed() const NOEXCEPT;

Expand Down
8 changes: 7 additions & 1 deletion include/bitcoin/node/chasers/chaser_confirm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class BCN_API chaser_confirm
chaser_confirm(full_node& node) NOEXCEPT;

code start() NOEXCEPT override;
void stopping(const code& ec) NOEXCEPT override;
void stop() NOEXCEPT override;

protected:
using header_links = std_vector<database::header_link>;
Expand All @@ -51,7 +53,8 @@ class BCN_API chaser_confirm
virtual void do_validated(height_t height) NOEXCEPT;
virtual void do_reorganize(size_t height) NOEXCEPT;
virtual void do_organize(size_t height) NOEXCEPT;
virtual bool enqueue_block(const database::header_link& link) NOEXCEPT;

virtual void enqueue_block(const database::header_link& link) NOEXCEPT;
virtual void confirm_tx(const database::context& ctx,
const database::tx_link& link, const race::ptr& racer) NOEXCEPT;
virtual void handle_tx(const code& ec, const database::tx_link& tx,
Expand Down Expand Up @@ -82,6 +85,9 @@ class BCN_API chaser_confirm
bool get_is_strong(bool& strong, const uint256_t& fork_work,
size_t fork_point) const NOEXCEPT;

// This is thread safe.
const bool concurrent_;

// These are protected by strand.
network::threadpool threadpool_;
header_links popped_{};
Expand Down
11 changes: 8 additions & 3 deletions include/bitcoin/node/chasers/chaser_snapshot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,31 @@ class BCN_API chaser_snapshot
code start() NOEXCEPT override;

protected:
virtual void do_confirm(height_t height) NOEXCEPT;
virtual void do_archive(height_t height) NOEXCEPT;
virtual void do_valid(height_t height) NOEXCEPT;
virtual void do_confirm(height_t height) NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

private:
bool update_bytes() NOEXCEPT;
bool update_valid(height_t height) NOEXCEPT;
bool update_confirm(height_t height) NOEXCEPT;
void do_snapshot(height_t height) NOEXCEPT;

// These are thread safe.
const size_t top_checkpoint_;
const size_t snapshot_valid_;
const uint64_t snapshot_bytes_;
const bool enabled_valid_;
const size_t snapshot_valid_;
const size_t snapshot_confirm_;
const bool enabled_bytes_;
const bool enabled_valid_;
const bool enabled_confirm_;

// These are protected by strand.
uint64_t bytes_{};
size_t valid_{};
size_t confirm_{};
};

} // namespace node
Expand Down
29 changes: 10 additions & 19 deletions include/bitcoin/node/chasers/chaser_validate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,22 @@ class BCN_API chaser_validate
chaser_validate(full_node& node) NOEXCEPT;

code start() NOEXCEPT override;

/// Validate a populated candidate block.
virtual void validate(const system::chain::block::cptr& block,
const database::header_link& link, size_t height) NOEXCEPT;
void stopping(const code& ec) NOEXCEPT override;
void stop() NOEXCEPT override;

protected:
typedef network::race_unity<const code&, const database::tx_link&> race;

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

virtual void do_validate(const system::chain::block::cptr& block,
database::header_link::integer link, size_t height) NOEXCEPT;

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 bool enqueue_block(const database::header_link& link) NOEXCEPT;
virtual void validate_tx(const database::context& ctx,
const database::tx_link& link, const race::ptr& racer) NOEXCEPT;
virtual void handle_tx(const code& ec, const database::tx_link& tx,
const race::ptr& racer) NOEXCEPT;
virtual void handle_txs(const code& ec, const database::tx_link& tx,
const database::header_link& link,
const database::context& ctx) NOEXCEPT;
virtual void validate_block(const code& ec,
const database::header_link& link,
const database::context& ctx) NOEXCEPT;
virtual void validate_block(const database::header_link& link) NOEXCEPT;
virtual void complete_block(const code& ec,
const database::header_link& link, size_t height) NOEXCEPT;

private:
// neutrino
Expand All @@ -78,12 +65,16 @@ class BCN_API chaser_validate
const system::chain::block& block) NOEXCEPT;

// These are thread safe.
const bool prepopulate_;
const bool concurrent_;
const size_t maximum_backlog_;
const uint64_t initial_subsidy_;
const uint32_t subsidy_interval_blocks_;
const uint32_t subsidy_interval_;

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

} // namespace node
Expand Down
7 changes: 6 additions & 1 deletion include/bitcoin/node/impl/chasers/chaser_organize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ bool CLASS::handle_event(const code&, chase event_, event_value value) NOEXCEPT
if (closed())
return false;

// TODO: allow required messages.
////// Stop generating query during suspension.
////if (suspended())
//// return true;

switch (event_)
{
case chase::unchecked:
Expand Down Expand Up @@ -195,7 +200,7 @@ void CLASS::do_organize(typename Block::cptr block,
bool strong{};
uint256_t work{};
hashes tree_branch{};
size_t branch_point{};
height_t branch_point{};
header_links store_branch{};

if (!get_branch_work(work, branch_point, tree_branch, store_branch, header))
Expand Down
5 changes: 5 additions & 0 deletions include/bitcoin/node/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,20 @@ class BCN_API settings

/// Properties.
bool headers_first;
bool priority_validation;
bool concurrent_validation;
bool concurrent_confirmation;
float allowed_deviation;
uint16_t allocation_multiple;
uint64_t snapshot_bytes;
uint32_t snapshot_valid;
uint32_t snapshot_confirm;
uint32_t maximum_height;
uint32_t maximum_concurrency;
uint16_t sample_period_seconds;
uint32_t currency_window_minutes;
uint32_t threads;
bool prepopulate;

/// Helpers.
virtual size_t maximum_height_() const NOEXCEPT;
Expand Down
4 changes: 4 additions & 0 deletions src/chasers/chaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ void chaser::stopping(const code&) NOEXCEPT
{
}

void chaser::stop() NOEXCEPT
{
}

bool chaser::closed() const NOEXCEPT
{
return node_.closed();
Expand Down
12 changes: 9 additions & 3 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ bool chaser_check::handle_event(const code&, chase event_,
if (closed())
return false;

// TODO: allow required messages.
////// Stop generating query during suspension.
////if (suspended())
//// return true;

switch (event_)
{
// Track downloaded.
Expand Down Expand Up @@ -365,14 +370,15 @@ size_t chaser_check::set_unassociated() NOEXCEPT
size_t chaser_check::get_inventory_size() const NOEXCEPT
{
// Either condition means blocks shouldn't be getting downloaded (yet).
const auto peers = config().network.outbound_connections;
const size_t peers = config().network.outbound_connections;
if (is_zero(peers) || !is_current())
return zero;

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 span = system::ceilinged_multiply(messages::max_inventory, peers);
const auto step = std::min(maximum_concurrency_, span);
const auto inventory = query.get_unassociated_count_above(fork, step);
return system::ceilinged_divide(inventory, peers);
}
Expand Down
Loading
Loading