Skip to content

Commit

Permalink
Tight validation coupling.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Nov 19, 2024
1 parent d7d76ad commit c974029
Show file tree
Hide file tree
Showing 5 changed files with 339 additions and 150 deletions.
3 changes: 3 additions & 0 deletions include/bitcoin/node/chase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ enum class chase
/// Check/Identify.
/// -----------------------------------------------------------------------

/////// A set of blocks is being checked, top block provided (height_t).
////checking,

/// A block has been downloaded, checked and stored (height_t).
/// Issued by 'block_in_31800' or 'populate' and handled by 'connect'.
/// Populate is bypassed for checkpoint/milestone blocks.
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/node/chasers/chaser_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class BCN_API chaser_check
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;
virtual void do_confirmable(height_t height) NOEXCEPT;

private:
typedef std::deque<map_ptr> maps;
Expand All @@ -89,6 +90,7 @@ class BCN_API chaser_check
// These are protected by strand.
size_t inventory_{};
size_t requested_{};
size_t confirmed_{};
job::ptr job_{};
maps maps_{};
};
Expand Down
10 changes: 7 additions & 3 deletions include/bitcoin/node/chasers/chaser_confirm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ class BCN_API chaser_confirm
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

////virtual void do_checking(height_t height) NOEXCEPT;
virtual void do_regressed(height_t branch_point) NOEXCEPT;
virtual void do_validated(height_t height) NOEXCEPT;
virtual void do_reorganize(header_links& fork, size_t fork_point) NOEXCEPT;
virtual void do_organize(header_links& fork, const header_links& popped,
size_t fork_point) NOEXCEPT;
virtual void do_bump(height_t branch_point) NOEXCEPT;

////virtual void do_reorganize(header_links& fork, size_t fork_point) NOEXCEPT;
////virtual void do_organize(header_links& fork, const header_links& popped,
//// size_t fork_point) NOEXCEPT;

private:
bool set_organized(const database::header_link& link,
Expand Down
24 changes: 21 additions & 3 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ bool chaser_check::handle_event(const code&, chase event_,
POST(do_headers, std::get<height_t>(value));
break;
}
case chase::confirmable:
{
BC_ASSERT(std::holds_alternative<height_t>(value));
POST(do_confirmable, std::get<height_t>(value));
break;
}
case chase::stop:
{
return false;
Expand All @@ -143,6 +149,15 @@ bool chaser_check::handle_event(const code&, chase event_,
return true;
}

void chaser_check::do_confirmable(height_t height) NOEXCEPT
{
BC_ASSERT(stranded());
confirmed_ = height;

if (confirmed_ == requested_)
do_headers(height_t{});
}

// regression
// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -223,7 +238,7 @@ void chaser_check::do_bump(height_t) NOEXCEPT
query.to_candidate(add1(position()))))
set_position(add1(position()));

set_unassociated();
do_headers(height_t{});
}

// add headers
Expand Down Expand Up @@ -324,8 +339,10 @@ size_t chaser_check::set_unassociated() NOEXCEPT
if (closed() || purging())
return {};

// Defer new work issuance until all gaps are filled.
if (position() < requested_ || requested_ >= maximum_height_)
// Defer new work issuance until gaps filled and confirmation caught up.
if (position() < requested_ ||
requested_ >= maximum_height_ ||
confirmed_ < requested_)
return {};

// Inventory size gets set only once.
Expand Down Expand Up @@ -364,6 +381,7 @@ size_t chaser_check::set_unassociated() NOEXCEPT
<< count << ") last ("
<< requested_ << ").");

////notify(error::success, chase::checking, requested_);
return count;
}

Expand Down
Loading

0 comments on commit c974029

Please sign in to comment.