Skip to content

Commit c974029

Browse files
committed
Tight validation coupling.
1 parent d7d76ad commit c974029

File tree

5 files changed

+339
-150
lines changed

5 files changed

+339
-150
lines changed

include/bitcoin/node/chase.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ enum class chase
9191
/// Check/Identify.
9292
/// -----------------------------------------------------------------------
9393

94+
/////// A set of blocks is being checked, top block provided (height_t).
95+
////checking,
96+
9497
/// A block has been downloaded, checked and stored (height_t).
9598
/// Issued by 'block_in_31800' or 'populate' and handled by 'connect'.
9699
/// Populate is bypassed for checkpoint/milestone blocks.

include/bitcoin/node/chasers/chaser_check.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class BCN_API chaser_check
6868
virtual void do_get_hashes(const map_handler& handler) NOEXCEPT;
6969
virtual void do_put_hashes(const map_ptr& map,
7070
const network::result_handler& handler) NOEXCEPT;
71+
virtual void do_confirmable(height_t height) NOEXCEPT;
7172

7273
private:
7374
typedef std::deque<map_ptr> maps;
@@ -89,6 +90,7 @@ class BCN_API chaser_check
8990
// These are protected by strand.
9091
size_t inventory_{};
9192
size_t requested_{};
93+
size_t confirmed_{};
9294
job::ptr job_{};
9395
maps maps_{};
9496
};

include/bitcoin/node/chasers/chaser_confirm.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ class BCN_API chaser_confirm
5050
virtual bool handle_event(const code& ec, chase event_,
5151
event_value value) NOEXCEPT;
5252

53+
////virtual void do_checking(height_t height) NOEXCEPT;
54+
virtual void do_regressed(height_t branch_point) NOEXCEPT;
5355
virtual void do_validated(height_t height) NOEXCEPT;
54-
virtual void do_reorganize(header_links& fork, size_t fork_point) NOEXCEPT;
55-
virtual void do_organize(header_links& fork, const header_links& popped,
56-
size_t fork_point) NOEXCEPT;
56+
virtual void do_bump(height_t branch_point) NOEXCEPT;
57+
58+
////virtual void do_reorganize(header_links& fork, size_t fork_point) NOEXCEPT;
59+
////virtual void do_organize(header_links& fork, const header_links& popped,
60+
//// size_t fork_point) NOEXCEPT;
5761

5862
private:
5963
bool set_organized(const database::header_link& link,

src/chasers/chaser_check.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ bool chaser_check::handle_event(const code&, chase event_,
130130
POST(do_headers, std::get<height_t>(value));
131131
break;
132132
}
133+
case chase::confirmable:
134+
{
135+
BC_ASSERT(std::holds_alternative<height_t>(value));
136+
POST(do_confirmable, std::get<height_t>(value));
137+
break;
138+
}
133139
case chase::stop:
134140
{
135141
return false;
@@ -143,6 +149,15 @@ bool chaser_check::handle_event(const code&, chase event_,
143149
return true;
144150
}
145151

152+
void chaser_check::do_confirmable(height_t height) NOEXCEPT
153+
{
154+
BC_ASSERT(stranded());
155+
confirmed_ = height;
156+
157+
if (confirmed_ == requested_)
158+
do_headers(height_t{});
159+
}
160+
146161
// regression
147162
// ----------------------------------------------------------------------------
148163

@@ -223,7 +238,7 @@ void chaser_check::do_bump(height_t) NOEXCEPT
223238
query.to_candidate(add1(position()))))
224239
set_position(add1(position()));
225240

226-
set_unassociated();
241+
do_headers(height_t{});
227242
}
228243

229244
// add headers
@@ -324,8 +339,10 @@ size_t chaser_check::set_unassociated() NOEXCEPT
324339
if (closed() || purging())
325340
return {};
326341

327-
// Defer new work issuance until all gaps are filled.
328-
if (position() < requested_ || requested_ >= maximum_height_)
342+
// Defer new work issuance until gaps filled and confirmation caught up.
343+
if (position() < requested_ ||
344+
requested_ >= maximum_height_ ||
345+
confirmed_ < requested_)
329346
return {};
330347

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

384+
////notify(error::success, chase::checking, requested_);
367385
return count;
368386
}
369387

0 commit comments

Comments
 (0)