Skip to content

Commit d01d37b

Browse files
authored
Merge pull request #768 from evoskuil/master
Move milestone set_strong into confirm, fix validate->check.
2 parents 6dfa10d + 5112ce8 commit d01d37b

File tree

9 files changed

+111
-144
lines changed

9 files changed

+111
-144
lines changed

include/bitcoin/node/chase.hpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,25 @@ enum class chase
3030
/// -----------------------------------------------------------------------
3131

3232
/// Chasers directed to start operating (height_t).
33-
/// Issued by 'full_node' and handled by 'validate'.
33+
/// Issued by 'full_node' and handled by 'check', 'validate', 'confirm'.
3434
start,
3535

3636
/// Disk space is limited (count_t).
37-
/// Issued by full_node and handled by 'snapshot' and 'storage'.
37+
/// Issued by 'full_node' and handled by 'snapshot' and 'storage'.
3838
space,
3939

40-
/// Chaser is directed to start when there are no downloads (height_t).
41-
/// Issued by 'organize' and handled by 'validate'.
40+
/// Chaser directed to attempt start from its current position (height_t).
41+
/// Issued by 'organize' and handled by 'check', 'validate', 'confirm'.
4242
bump,
4343

44-
/// Channels (all) directed to stop (channel_t).
44+
/// Channels (all) directed to stop (default).
4545
/// Issued by 'full_node' and handled by 'observer'.
4646
suspend,
4747

48+
/// Chasers (all) directed to resume following suspend (default).
49+
/// Issued by 'full_node' and handled by 'check', 'validate', 'confirm'.
50+
resume,
51+
4852
/// Channel starved for work (object_t).
4953
/// Issued by 'block_in_31800' and handled by 'session_outbound'.
5054
starved,
@@ -69,7 +73,7 @@ enum class chase
6973
/// -----------------------------------------------------------------------
7074

7175
/// A new candidate branch exists from given branch point (height_t).
72-
/// Issued by 'block' and handled by 'confirm'.
76+
/// Issued by 'block' and handled by 'confirm' and 'snapshot'.
7377
blocks,
7478

7579
/// A new candidate branch exists from given branch point (height_t).
@@ -81,59 +85,56 @@ enum class chase
8185
download,
8286

8387
/// The candidate chain has been reorganized (branched below its top).
84-
/// Issued by 'organize' and handled by 'check'.
88+
/// Issued by 'organize' and handled by 'check', 'validate', 'confirm'.
8589
regressed,
8690

8791
/// unchecked, unvalid or unconfirmable was handled (height_t).
88-
/// Issued by 'organize' and handled by 'validate' (disorgs candidates).
92+
/// Issued by 'organize' and handled by 'check', 'validate', 'confirm'.
8993
disorganized,
9094

9195
/// Check/Identify.
9296
/// -----------------------------------------------------------------------
9397

94-
/////// A set of blocks is being checked, top block provided (height_t).
95-
////checking,
96-
9798
/// A block has been downloaded, checked and stored (height_t).
98-
/// Issued by 'block_in_31800' or 'populate' and handled by 'connect'.
99+
/// Issued by 'block_in_31800', handled by 'check', 'validate', 'snapshot'.
99100
/// Populate is bypassed for checkpoint/milestone blocks.
100101
checked,
101102

102103
/// A downloaded block has failed check (header_t).
103-
/// Issued by 'block_in_31800' and handled by 'header'.
104+
/// Issued by 'block_in_31800' and handled by 'organize'.
104105
unchecked,
105106

106107
/// Accept/Connect.
107108
/// -----------------------------------------------------------------------
108109

109110
/// A branch has become valid (height_t).
110-
/// Issued by 'validate' and handled by 'confirm'.
111+
/// Issued by 'validate' and handled by 'check', 'confirm', 'snapshot'.
111112
valid,
112113

113114
/// A checked block has failed validation (header_t).
114-
/// Issued by 'validate' and handled by 'header'.
115+
/// Issued by 'validate' and handled by 'organize'.
115116
unvalid,
116117

117118
/// Confirm (block).
118119
/// -----------------------------------------------------------------------
119120

120121
/// A connected block has become confirmable (header_t).
121-
/// Issued by 'confirm' and handled by 'transaction'.
122+
/// Issued by 'confirm' and handled by 'snapshot'.
122123
confirmable,
123124

124125
/// A connected block has failed confirmability (header_t).
125-
/// Issued by 'confirm' and handled by 'header' (and 'block').
126+
/// Issued by 'confirm' and handled by 'organize'.
126127
unconfirmable,
127128

128129
/// Confirm (chain).
129130
/// -----------------------------------------------------------------------
130131

131132
/// A confirmable block has been confirmed (header_t).
132-
/// Issued by 'confirm' and handled by 'transaction'.
133+
/// Issued by 'confirm' [and handled by 'transaction'].
133134
organized,
134135

135136
/// A previously confirmed block has been unconfirmed (header_t).
136-
/// Issued by 'confirm' and handled by 'transaction'.
137+
/// Issued by 'confirm' [and handled by 'transaction'].
137138
reorganized,
138139

139140
/// Mining.
@@ -150,7 +151,7 @@ enum class chase
150151
/// Stop.
151152
/// -----------------------------------------------------------------------
152153

153-
/// Service is stopping, accompanied by error::service_stopped (count_t).
154+
/// Service is stopping, accompanied by error::service_stopped (default).
154155
stop
155156
};
156157

include/bitcoin/node/chasers/chaser_confirm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BCN_API chaser_confirm
6565
bool set_reorganized(const database::header_link& link,
6666
height_t confirmed_height) NOEXCEPT;
6767
bool set_organized(const database::header_link& link,
68-
height_t confirmed_height, bool bypassed) NOEXCEPT;
68+
height_t confirmed_height) NOEXCEPT;
6969
bool roll_back(const header_links& popped, size_t fork_point,
7070
size_t top) NOEXCEPT;
7171

include/bitcoin/node/chasers/chaser_organize.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ class chaser_organize
139139
// Setters
140140
// ----------------------------------------------------------------------------
141141

142-
bool set_reorganized(const database::header_link& link,
143-
height_t candidate_height) NOEXCEPT;
142+
bool set_reorganized(height_t candidate_height) NOEXCEPT;
144143
bool set_organized(const database::header_link& link,
145-
height_t candidate_height, bool strong) NOEXCEPT;
144+
height_t candidate_height) NOEXCEPT;
146145

147146
// Move tree Block to database and push to top of candidate chain.
148147
code push_block(const system::hash_digest& key) NOEXCEPT;

include/bitcoin/node/chasers/chaser_validate.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class BCN_API chaser_validate
5454
virtual void do_bumped(height_t height) NOEXCEPT;
5555
virtual void do_bump(height_t height) NOEXCEPT;
5656

57+
virtual void post_block(const database::header_link& link,
58+
bool bypass) NOEXCEPT;
5759
virtual void validate_block(const database::header_link& link,
5860
bool bypass) NOEXCEPT;
5961
virtual code validate(bool bypass, const system::chain::block& block,

include/bitcoin/node/impl/chasers/chaser_organize.ipp

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ void CLASS::organize(const typename Block::cptr& block,
8585
TEMPLATE
8686
bool CLASS::handle_event(const code&, chase event_, event_value value) NOEXCEPT
8787
{
88-
using namespace system;
89-
9088
if (closed())
9189
return false;
9290

@@ -118,13 +116,11 @@ TEMPLATE
118116
void CLASS::do_organize(typename Block::cptr block,
119117
const organize_handler& handler) NOEXCEPT
120118
{
121-
using namespace system;
122119
BC_ASSERT(stranded());
123120

124121
// shared_ptr copy keeps block ref in scope until completion of set_code.
125122
const auto& hash = block->get_hash();
126123
const auto& header = get_header(*block);
127-
const auto& query = archive();
128124

129125
// Skip existing/orphan, get state.
130126
// ........................................................................
@@ -168,6 +164,7 @@ void CLASS::do_organize(typename Block::cptr block,
168164
// Validation and currency.
169165
// ........................................................................
170166

167+
using namespace system;
171168
if (chain::checkpoint::is_conflict(checkpoints_, hash, height))
172169
{
173170
handler(system::error::checkpoint_conflict, height);
@@ -240,7 +237,7 @@ void CLASS::do_organize(typename Block::cptr block,
240237
auto index = top_candidate;
241238
while (index > branch_point)
242239
{
243-
if (!set_reorganized(query.to_candidate(index), index--))
240+
if (!set_reorganized(index--))
244241
{
245242
handler(fault(error::organize5), height);
246243
return;
@@ -256,7 +253,7 @@ void CLASS::do_organize(typename Block::cptr block,
256253
// Push stored strong headers to candidate chain.
257254
for (const auto& link: std::views::reverse(store_branch))
258255
{
259-
if (!set_organized(link, index, is_under_milestone(index++)))
256+
if (!set_organized(link, index++))
260257
{
261258
handler(fault(error::organize6), height);
262259
return;
@@ -317,8 +314,6 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
317314
{
318315
BC_ASSERT(stranded());
319316

320-
using namespace system;
321-
322317
// Skip already reorganized out, get height.
323318
// ........................................................................
324319

@@ -371,6 +366,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
371366
return;
372367
}
373368

369+
using namespace system;
374370
const auto& header = get_header(*block);
375371
state.reset(new chain::chain_state{ *state, header, settings_ });
376372
cache(block, state);
@@ -383,7 +379,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
383379
const auto top_candidate = state_->height();
384380
for (auto index = top_candidate; index > fork_point; --index)
385381
{
386-
if (!set_reorganized(query.to_candidate(index), index))
382+
if (!set_reorganized(index))
387383
{
388384
fault(error::organize11);
389385
return;
@@ -399,7 +395,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
399395
// Confirmed blocks may or may not be strong, as a branch severs strong
400396
// above the branch point, so as they are copied to the candidate index
401397
// they must be assured to be strong, since the fork point moves up.
402-
if (!set_organized(query.to_confirmed(index), index, true))
398+
if (!set_organized(query.to_confirmed(index), index))
403399
{
404400
fault(error::organize12);
405401
return;
@@ -427,24 +423,12 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
427423
// Private setters
428424
// ----------------------------------------------------------------------------
429425

430-
///////////////////////////////////////////////////////////////////////////////
431-
// BUGBUG: reorganize/organize operations that span a disk full recovery
432-
// BUGBUG: may be inconsistent between set/unset_strong and push/pop_candidate.
433-
///////////////////////////////////////////////////////////////////////////////
434-
435426
TEMPLATE
436-
bool CLASS::set_reorganized(const database::header_link& link,
437-
height_t candidate_height) NOEXCEPT
427+
bool CLASS::set_reorganized(height_t candidate_height) NOEXCEPT
438428
{
439429
BC_ASSERT(stranded());
440-
auto& query = archive();
441-
442-
// Any milestone or confirmable candidate block must be set unstrong.
443-
const auto milestone = is_under_milestone(candidate_height);
444-
const auto strong = milestone || query.is_confirmable(link);
445-
446-
// TODO: disk full race.
447-
if ((strong && !query.set_unstrong(link)) || !query.pop_candidate())
430+
BC_ASSERT(!is_under_checkpoint(candidate_height));
431+
if (!archive().pop_candidate())
448432
return false;
449433

450434
fire(events::header_reorganized, candidate_height);
@@ -454,14 +438,10 @@ bool CLASS::set_reorganized(const database::header_link& link,
454438

455439
TEMPLATE
456440
bool CLASS::set_organized(const database::header_link& link,
457-
height_t candidate_height, bool strong) NOEXCEPT
441+
height_t candidate_height) NOEXCEPT
458442
{
459443
BC_ASSERT(stranded());
460-
auto& query = archive();
461-
462-
// TODO: disk full race.
463-
// Any milestone or previously-confirmed (strong) block must be set strong.
464-
if ((strong && !query.set_strong(link)) || !query.push_candidate(link))
444+
if (!archive().push_candidate(link))
465445
return false;
466446

467447
fire(events::header_organized, candidate_height);
@@ -486,7 +466,7 @@ code CLASS::push_block(const Block& block,
486466
if (ec)
487467
return ec;
488468

489-
if (!set_organized(link, ctx.height, false))
469+
if (!set_organized(link, ctx.height))
490470
return error::organize14;
491471

492472
// events:header_archived | events:block_archived

0 commit comments

Comments
 (0)